Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

SAP NW RFC SDK 7.10 (Linux IA 32 bit) + python sapnwrfc-0.04 problem

I’ve developed a CGI-python web-based application running on Fedora Core 5 (IA 32 bit) Linux that makes RFC calls to a SAP ERP R/3 version 4.7 DB. The Linux system has SAP NW RFC SDK 7.10 and sapnwrfc-0.04 python RFC connector installed.

The NW RFC SDK and python connector work great except when encountering one string record among many thousands in the SAP ERP DB. Here is the error my application reports:

<b>RFCCommunicationError: RFC FUNCTION CALL ERROR: RfcSetChar string too long: IDNLF</b>

The error message is displayed by the python RFC connector shared library C source function set_char_value in sapnwrfc-0.04/src/nwsaprfcutil.c. I found prior to the error message, set_table_line() is called which calls RfcGetFieldDescByName(). RfcGetFieldDescByName() returns an incorrect field descriptor nucLength value for a string record: 30 instead of 31. I explain below how I know 30 is wrong and 31 is correct. PyString_Size() returns the value 31, but the returned nucLength is 30 which results in the set_char_value() error message and exit later.

The raw string record that causes this problem is shown in the strace output below. I’ve put in bold the actual bytes in the string. If you count them you will find there are 31 bytes in the record. However, RfcGetFieldDescByName() returns nucLength of 30 and PyString_Size() returns the correct value of 31.

31129 write(2, "SMART RfcSetChar: name=\'IDNLF\'\n", 31) = 31

00000 53 4d 41 52 54 20 52 66 63 53 65 74 43 68 61 72 SMART Rf cSetChar

00010 3a 20 6e 61 6d 65 3d 27 49 44 4e 4c 46 27 0a : name=' IDNLF'.

31129 write(2, "SMART RfcSetChar: value=\'RK73B1E"..., 58) = 58

00000 53 4d 41 52 54 20 52 66 63 53 65 74 43 68 61 72 SMART Rf cSetChar

00010 3a 20 76 61 6c 75 65 3d 27 <b>52 4b 37 33 42 31 45 </b> : value= 'RK73B1E

00020 <b>54 54 50 31 30 34 4a <u>c2 a0</u> 20 20 20 20 20 20 20 </b> TTP104J. .

00030 <b>20 20 20 20 20 20 20 20 </b> 27 0a '.

31129 write(2, "SMART RfcSetChar: max=30\n", 25) = 25

00000 53 4d 41 52 54 20 52 66 63 53 65 74 43 68 61 72 SMART Rf cSetChar

00010 3a 20 6d 61 78 3d 33 30 0a : max=30 .

31129 write(2, "SMART RfcSetChar: length=31\n", 28) = 28

00000 53 4d 41 52 54 20 52 66 63 53 65 74 43 68 61 72 SMART Rf cSetChar

00010 3a 20 6c 65 6e 67 74 68 3d 33 31 0a : length =31.

I’m surmising that RfcGetFieldDescByName() is confused by the non-ASCII characters 0xC2 and 0xA0 (bold and underlined) which are embedded in the string record. I believe this is a record entry error in our ERP DB. It is the only instance of this problem (non-ASCII characters embedded in a string record) I have found in searching thousands of records in the MRP DB.

I believe this is an NW RFC SDK problem and not a problem with the python connector problem, but given I don’t have source code to NW RFC SDK, I have changed the python connector to work-around this problem. In set_table_line() after the call to RfcGetFieldDescByName(), I added the following code.

          if (fieldDesc.nucLength < PyString_Size(val))
          {
            fprintf(stderr, "SMART set_table_line: RfcGetFieldDescByName %s changing fieldDesc.nucLength %d to actual strlen of %dn", PyString_AsString(key), fieldDesc.nucLength, PyString_Size(val));
            fieldDesc.nucLength = PyString_Size(val);
          }

This change “fixes” the problem. I have no other issues at this time using the NW RFC SDK and and python connector. Using python to interface to our SAP DB records is a great application for python and a lot of fun to program.

My questions are:

1) Is this above change to the python RFC connector a safe a workaround or might this change possibly lead to unexcpected/incorrect behavior due to memory corruption or some other side-effect?

2) Where is the real problem causing the incorrect field length error? Is this an NW RFC SDK problem? What is the correct solution for this problem?

Former Member
Not what you were looking for? View more on this topic or Ask a question