cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in ISapRfcConnection/ISapRfcFunction interface and how to fix it

Former Member
0 Kudos

I found out that when trying to call RFC function from plugin I made ISapRfcConnection->InitFunction does only initialize import parameters that are type using structure (or table) field. If RFC function has import parameter type directly with data element, using the parameter does not work or even crash the application. Example:

ISapRfcFunctionPtr l_RFC = m_RFC->GetFunction(L"RHF4_RFC_SELECT_GENERIC",VARIANT_FALSE);

l_RFC->Field("TABNAME")->String = L"T002";

l_RFC->Field("FIELDNAME")->String = L"SPRAS";

l_RFC->Field("SORT")->String = L"X"; <--this will crash the application.

The reason for this is that EasyDMS uses function RFC_GET_FUNCTION_INTERFACE to initialize function interface. If we look at what this function returns:

                                                                                
P PARAMETER                      TABNAME                        FIELDNAME                      E POSITION                                                                                
E MAXROWS_EXCEEDED               BOOLE_D                                                       C         0  
 I FIELDNAME                      DD03V                          FIELDNAME                      C         2  
 I MAXROWS                        SYINDEX                                                       I         0  
 I SORT                           BOOLE_D                                                       C         0  
 I TABNAME                        DD02V                          TABNAME                        C         1  

We can see that this standard sap function return the dataelement in the TABNAME field. I did wild guess that EasyDMS checks the fieldname to determine if parameter is single field or structure (which is not the case, EXID field is "u" when field is structure). So I put a break point in the RFC_GET_FUNCTION_INTERFACE and reseted the rfc cache. When retrieving the interface for the RHF4_RFC_SELECT_GENERIC, I set also the FIELDNAME as BOOLE_D.

After this trick, code above worked..So there is bug at least in the 6.0.0.0: SP14 Patch 02 (Non-Unicode) and some 7.0 versions.

So how then use the parameter when referring using field is impossible? EasyDMS thinks that parameter is a structure so it can be accessed as structure data:

l_RFC->Struct("SORT")->GetDataChunk()->Data = L"X";

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

HI,

did u try with

l_RFC->Field("SORT")->Boolean

you should be able to use following types for l_RFC->Field("")->

Boolean, Long, Date and String.

Regards

Surjit

Former Member
0 Kudos

Type used has nothing to do with it, the part that fails is ptr->Field("fieldname"), ->Boolean is just a way to map C++ boolean to string " " "X" values of ABAP boolean.

Here is another example


FUNCTION ZZZDMS_BUG_DEMO.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(MATERIAL) TYPE  MARA-MATNR
*"     REFERENCE(MATERIAL2) TYPE  MATNR
*"  EXPORTING
*"     REFERENCE(EXT_MATERIAL) TYPE  MARA-MATNR
*"     REFERENCE(EXT_MATERIAL2) TYPE  MATNR
*"----------------------------------------------------------------------
  EXT_MATERIAL = MATERIAL.
  EXT_MATERIAL2 = MATERIAL2.
ENDFUNCTION.

First field typed as field of structure (db table) and second as data type. Let's call this with


Rfc->InitFunction(L"ZZZDMS_BUG_DEMO",VARIANT_FALSE);
Rfc->Field("MATERIAL")->String = "012345678901234567";
Rfc->Field("MATERIAL2")->String = "012345678901234567";
Rfc->Call();

Referring to MATERIAL2 fails. It actually generates popup with unspecified error. It can be accessed using struct but of course there ain't any field and that's why raw datachuck must be used:

This works for input and function get called (actually, there is some unicode related problems with string literals):

Rfc->Struct("MATERIAL2")->GetDataChunk()->Data = "012345678901234567";