cancel
Showing results for 
Search instead for 
Did you mean: 

Code Generator for the Code Stage to use SAP RFC Function Modules Easily

StefanSchnell1
Level 7
Hello Community,

Remote Function Calls (RFC), also known as Remote Procedure Calls (RPC) or Remote-Enabled Function Modules (RFM), is the standard SAP interface for technical communication between SAP systems. RFC calls a function to be executed in a remote system. On an SAP back-end system exists many RFMs which offers an incredible scope of possibilities. Likewise on the  Business Application Programming Interface (BAPI), which is a formal defined interface to the business object model which uses RFC. To use this kind interface SAP offers the dotNET Connector, called NCo. You can download it explicit or you can use it with your SAP GUI for Windows installation.

To use this connector I programmed an RFM Code Generator. With this tool you can generate C# or VB.NET code to use RFMs of an SAP back-end system. You can easily detect and select the RFM you need. With a few mouse clicks you can generate the code to call the RFM. All descriptions and interfaces, with its technical details, are visible and you can put together exactly what you need. To use this code with BP, transfer it easily to a Code Stage.

Here are some pictures with explanations.

After starting the generator, the connection data must be entered first at the Connection tab.
11661.png

After the connection has been successfully established, you can switch to the Search tab. Enter a pattern or the name of the RFM you want to use, in our example RFC*, and press the button Search to get the RFMs.

11662.png

You will be automatically redirected to the Selections tab. Here the desired function module can be easily selected and the code generated in a few steps.

11663.png

  1. Double click on the RFM name you want to use. In this example RFC_SYSTEM_INFO.
  2. You see the name of the RFM which was selected and the available descriptions in all languages.
  3. The RFM interface, in our case it contains only export parameters. Here you can find Import, Export, Exception and Changing parameters of the RFM.
  4. Select the programming language in which the code is to be generated. In this example VB.NET.
  5. Press the Generate Code button to generate the code in the Code tab

If a function documentation is available, you can find it in the tab of the same name. But in the most cases RFMs are not documented.

With five tiny clicks you generate code to call an RFM in an SAP system.
11664.png

With a double click on a structure you jump into the Structure Definition tab and you can see all details, in this example RFCSI_EXPORT.
11665.png

This can be used to generate code for deeper structures.

  1. Select the fields you are interested in. In this example RFCHOST, RFCSYSID, RFCDBHOST and RFCDBSYS.
  2. Select Set, if you want to set the content of the fields, or Get, if you want to get the content of the fields. In this example Get.
  3. Press Generate Code to Clipboard button. The additional VB.NET code to get the content of the selected fields is now in the clipboard available
11666.png

Paste it into your code.
11667.png

Now the code can be copied into the Code Stage.
11668.png

Add the SAP Connector libraries to the references, in this case from the Global Assembly Cache (GAC) from the SAP GUI for Windows installation, and the namespace SAP.Middleware.Connector.
11669.png

After this steps you can execute your object.
11670.png

With this RFM Code Generator you can create C# or VB.NET code sequences, to call SAP RFMs, easily. You very quickly gain an overview of the technical interface and can just as quickly create the basis for use. However, you must also know exactly what you are doing. The generated code can be easily transfer and use in a Code Stage. This approach should reduce development times.

You can find the RFM Code Generator at my homepage, with a detailed user manual.

Enjoy it.

Best regards
Stefan


------------------------------
Stefan Schnell
Senior Systems Engineer at BWI GmbH
------------------------------
4 REPLIES 4

Hi, Stefan, 

excellent work. However, what permissions you have to have as a user when you want to invoke this? This would be probably crucial for widespread usage.

Regards,

------------------------------
Zdeněk Kabátek
Head of Professional Services
NEOOPS
http://www.neoops.com/
Europe/Prague
------------------------------

Hello Zdeněk,

thank you very much for your reply.

In my opinion are the permissions not a problem for an RPA developer in an SAP development environment.
Authorization object S_RFC: RFC_TYPE = *, RFC_NAME = *, ACTVT 16
Authorization object S_TABU_DIS: DICBERCLS = *, ACTVT 03
Authorization Object S_CTS_ADMI: CTS_ADMFCT = TABL
If there are any problems just call the transaction code SU53.

Best regards
Stefan



------------------------------
Stefan Schnell
Senior Systems Engineer at BWI GmbH
------------------------------

AbarnaAnbu
Level 2
Hi stefan,

 While running the RFM code generator application, after providing Connection details, if prompt as "connection successful".
But while search with keyword eg., RFC* giving exception as"Option_Not_Valid". Please help me on this.

Thanks 
abarna

------------------------------
Abarna Anbu
------------------------------

@Abarna Anbu

Hello Abarna,

I tried it and it works without any problems, mmmh...

11657.png


To find the reason please open in your SAP system the TAC SE37 and open the RFM RFC_READ_TABLE. In the field QUERY_TABLE enter TFDIR and add in the table options FMODE = 'R' AND FUNCNAME = 'BAPI%'

11658.png

11659.png


Execute the RFM and in a normal case you should see the same result.

11660.png


In your case an exception raises. I tested RFM Code Generator with and without OSS 2246160 successfully.

Please replace the asterisk * with an percent % and try it again. Maybe an unicode character error.
Or it is possible that your system blocks the clause as insecure, if the allowlist RFC_READ_TABLE_TABL has been activated in TAC SLDW. 

Thanks and best regards
Stefan




------------------------------
Stefan Schnell
Senior Systems Engineer at BWI GmbH
------------------------------