Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Supplying Export parameters as Import parameters to a Remote Enabled Function Module

Waelf
Explorer
0 Likes
1,516

Dear community, 

I am trying to figure out a way to call a function module remotely with a client program (either with .NET RFC connector or with PyRFC). For now both do not work for me as I am unable to find the correct solution to my requirement.

Below is my issue : I need to call a remote enabled function module, let's say /MYFM. 
When calling it from ABAP for example the program looks like follow : 

DATA : lt_param1        TYPE xstring,
       lv_param2 TYPE  xstring,
       lv_devclass    TYPE  xstring.


lt_param1 = 'test'.
lv_param2 = 'test'.
lv_param3 = 'test'. 

CALL FUNCTION '/MYFM'
  EXPORTING
    lt_param1        = lt_param1
    lv_param2 = lv_param2
    lv_param2    =  lv_param3 .

  WRITE: / 'Function module called successfully.' .

 However if I try for example to call it remotely (FM is remotely enabled so that is not the issue) I get the error lt_param1 not found (RFC error: 20 (rc=20): key=RFC_INVALID_PARAMETER). 

The import parameters of my RFM are it_param1, iv_param2 and iv_param3.
Below is how the FM is called for example using PyRFC 

val1 = 'test'
val2 = 'test'
val3 = 'test'

params = {
            'it_param1': val1,
            'iv_param2': va2,
            'iv_param3"': val3
        }

result = connection.call('/MYRFM', **params)

Can you please advise ? 
Many thanks in advance. 


Dear community, 

I am trying to figure out a way to call a function module remotely with a client program (either with .NET RFC connector or with PyRFC). For now both do not work for me as I am unable to find the correct solution to my requirement.

Below is my issue : I need to call a remote enabled function module, let's say /MYFM. 
When calling it from ABAP for example the program looks like follow : 

DATA : lt_param1        TYPE xstring,
       lv_param2 TYPE  xstring,
       lv_devclass    TYPE  xstring.


lt_param1 = 'test'.
lv_param2 = 'test'.
lv_param3 = 'test'. 

CALL FUNCTION '/MYFM'
  EXPORTING
    lt_param1        = lt_param1
    lv_param2 = lv_param2
    lv_param2    =  lv_param3 .

  WRITE: / 'Function module called successfully.' .

 However if I try for example to call it remotely (FM is remotely enabled so that is not the issue) I get the error lt_param1 not found (RFC error: 20 (rc=20): key=RFC_INVALID_PARAMETER). 

The import parameters of my RFM are it_param1, iv_param2 and iv_param3.
Below is how the FM is called for example using PyRFC 

val1 = 'test'
val2 = 'test'
val3 = 'test'

params = {
            'it_param1': val1,
            'iv_param2': va2,
            'iv_param3"': val3
        }

result = connection.call('/MYRFM', **params)

Can you please advise ? 
Many thanks in advance. 


3 REPLIES 3
Read only

Ulrich_Schmidt1
Product and Topic Expert
Product and Topic Expert
0 Likes
1,442

I can see two problems here:

  1. Your ABAP test code does not make an RFC call, but a "local" call. If you want a real test, add DESTINATION 'NONE' and the usual SYSTEM_FAILURE & COMMUNICATION_FAILURE exceptions to your CALL FUNCTION statement, then you are performing a real RFC call including the serialization & deserialization of the FM parameters (where the error seems to happen).
  2. In your ABAP test code, you call the importing parameter lt_param1, but in Python you call it it_param1?! One of them must be wrong...
Read only

Waelf
Explorer
0 Likes
1,378

Hello Ulrich, 

Thanks for getting back. Yes my bad it is indeed a typo from my part. The correct import parameter defined in the RFM is it_param1. 
So I implemented your changes to make a real RFC call and it still works correctly. 
Below is the code I tested for the ABAP report. For the python call I tried both a synchronous and transactional RFC and still getting the same error (I don't know if that makes any difference but I was out of solutions so I tried it anyway). 
Below is the exact RFM I am trying to call (populated data is irrelevant in this case only serving to chedk if the parameters are recognized or not).

For my client script as it is based on the RFCSDK are there specific modifications I should make in my code to correctly perform the call ? I can switch to a C based client script to use directly the RFCSDK and its proposed features.

REPORT ZTEST.
DATA : lt_code        TYPE /sloap/t_char72, "#EC NEEDED
       lv_report_name TYPE  progname,
       lv_devclass    TYPE  devclass,
       lv_line        TYPE  CHAR72,
       lv_line1       TYPE  CHAR72.


lv_report_name = 'zwa'.
lv_devclass = 'zwa'.

lv_line = 'FUNCTION test test'.
APPEND lv_line TO lt_code.

*lv_line = 'REPORT'.
*APPEND lv_line TO lt_code.
*
*lv_line = 'test test'.
*APPEND lv_line TO lt_code.


CALL FUNCTION '/SLOAP/GEN_MODULE_REPORT' DESTINATION 'NONE'
  EXPORTING
    it_code        = lt_code
    iv_report_name = lv_report_name
    iv_devclass    =  lv_devclass
  EXCEPTIONS
      SYSTEM_FAILURE = 1
      COMMUNICATION_FAILURE = 2
      OTHERS = 3.

  WRITE: / 'Function module called successfully.' .

From what I read in your article RFC Client Programming I understand that when using the function RfcCreateFunction() the RFC data container I am sending to the remote backend is filled based on the function metadata returned with RfcGetFunctionDesc()

Therefore I understand that if I invoke the function RfcCreateStructure()  I can then supply the metadata definition for my RFC function, which may explain why I have the issue as the metadata returned from the RfcGetFunctionDesc() is empty ? 

Many thanks in advance ! 

Read only

Ulrich_Schmidt1
Product and Topic Expert
Product and Topic Expert
0 Likes
1,185

Usually, you don't need to deal with low level things like RfcCreateStructure() yourself, this is done automatically for you, when you create the "Function".

But I think, I now understand what's going wrong here: ABAP is case-insensitive, while programming languages like Python and C are case-sensitive. Therefore, specifying the RFM parameters in lower-case works in your ABAP report, but when you try the same in your Python client code, it doesn't recognize the function module parameter name ("RFC_INVALID_PARAMETER").

If this is the problem here, then changing your Python code sample to upper-case should fix it:

params = {
            'IT_CODE': val1,
            'IV_REPORT_NAME': val2,
            'IV_DEVCLASS': val3
        }

(Try it first with plain CHAR-type parameters. -- Structures will then be the next step, once this works...)