mydoghasworms/nwrfc — Issue #1: Truncation when handling RAW data
Author: nmonkee
Created: 2012-03-07 17:27:51+00:00
State: open

The nwrfc SDK wrapper and also Piers Harding's don't appear to handle RAW data.

The following two scripts attempt to call RFC_READ_TABLE and return the users password hash from the BCODE RAW field.

As is clear from the output the return data is truncated (can be confirmed by using SE37 to open USR02).

I found this explanation and fix for a Java connector http://www.benx.ch/benx(bD1lbiZjPTAwMQ==)/de/index.do?onInputProcessing(brai_thread)&001_thread_id=62197 may help with the issue.

$ ruby SE11.rb
[x] ADSUSER |7FE24F53
[x] ADS_AGENT |8C323693
[x] DDIC |61D26428
[x] DEVELOPER |C4C768AE
[x] J2EE_ADMIN |6C1541BC
[x] J2EE_GUEST |00000000
[x] SAP* |D0BFF427
[x] SAPCPIC |7D806C24
[x] SAPJSF |7D6762BF

$ cat SE11.rb

require 'rubygems'
require 'nwrfc'

include NWRFC

ashost = "172.16.252.135"
sysnr = "42"
client = "001"
user = "SAP*"
passwd = "06071992"

auth_hash = {"user" => user, "passwd" => passwd, "client" => client, "ashost" => ashost, "sysnr" => sysnr}

connection = Connection.new(auth_hash)

function = connection.get_function("RFC_READ_TABLE")

fc = function.get_function_call

fc[:DELIMITER] = '|'

fc[:QUERY_TABLE] = 'USR02'

fc[:FIELDS].new_row {|row|
row[:FIELDNAME] = "BNAME"
}

fc[:FIELDS].new_row {|row|
row[:FIELDNAME] = "BCODE"
}

begin
fc.invoke
rescue NWError => e
$stderr.print "FunctionCallException: #{e.inspect}\n"
raise "gone"
end

data_length = fc[:DATA].size

for i in 0...data_length
data = fc[:DATA][i][:WA]
data.to_str
puts "[x] #{data}"
end

$ ruby SE11.rb
row: {"WA"=>"7FE24F53"}
row: {"WA"=>"8C323693"}
row: {"WA"=>"61D26428"}
row: {"WA"=>"C4C768AE"}
row: {"WA"=>"6C1541BC"}
row: {"WA"=>"00000000"}
row: {"WA"=>"D0BFF427"}
row: {"WA"=>"7D806C24"}
row: {"WA"=>"7D6762BF"}

$ cat SE11.rb

require 'sapnwrfc'

TEST_FILE = 'ubuntu.yml'

SAPNW::Base.config_location = TEST_FILE
SAPNW::Base.load_config

conn = SAPNW::Base.rfc_connect

attrib = conn.connection_attributes

f = conn.discover("RFC_READ_TABLE")

fc = f.new_function_call

fc.QUERY_TABLE = "USR02"

fc.FIELDS = [{'FIELDNAME' => 'BCODE'}]

begin
fc.invoke
rescue SAPNW::RFC::FunctionCallException => e
$stderr.print "FunctionCallException: #{e.error.inspect}\n"
raise "gone"
end
fc.DATA.each do |row|
$stderr.print "row: #{row.inspect}\n"
end
conn.close

$ ./startrfc -h 172.16.252.135 -s 42 -c 001 -u SAP* -p 06071992 -i
SAP System ID: NPL
SAP System Number: 42
Partner Host: nplhost
Own Host: bt
Partner System Release: 702
Partner Kernel Release: 720
Own Release: 720
Partner Codepage: 4103
Own Codepage: 4103
User: SAP*
Client: 001
Language: E

$ ./startrfc -v
NW RFC Library Version: 720 Patch 7
Compiler Version:
4.1.2 20070115 (SAP release 20090902, based on SUSE release)