Example of using remote function call in SAP
- Updated: 2022/08/04
Example of using remote function call in SAP
This example describes how to build a bot that will create a document in SAP using the remote function call method.
Prerequisites
Download the SAP Java connector package and DLL from the SAP website.
Procedure
-
Open a new bot:
- On the left panel, click Automation.
- Click Create new > Bot.
- In the Create Task Bot window, enter a bot name.
- Click Create and edit.
-
Establish a connection with the SAP application using the
Connect
action.
- In the SAP BAPI Session field, enter Default.
-
Select the Desktop option, then browse and select the
SAP Java connector package available on your device.
Example: F:\SAP \SAP JCo 3.1.3\Microsoft Windows and Windows Server\64-bit\sapjco3.jar
-
Select the Desktop option, then browse and select the
SAP Java connector DLL available on your device.
Example: F:\SAP \SAP JCo 3.1.3\Microsoft Windows and Windows Server\64-bit\sapjco3.dll
- Select the Group/Server option as the connection type.
- Select Insecure string and enter AWINAAWO12.bcone.com to specify the hostname for the SAP message server.
- Enter AWINAAWO12.bcone.com in the Gateway host field to connect to the server.
-
Enter the following values:
Field Value Logon group Public System number 01 SAP instance system ID AAI Client number 800 Logon language code EN Router string /H/115.112.148.66/S/3299 - Select Insecure string and enter ISR3 to specify the username you want to use to connect to the SAP server.
- Select Insecure string and enter Automation@123 to specify the password you want to use to connect to the SAP server.
-
Use the Create function action to create a function for the SAP
BAPI function.
- Create an alias for an SAP BAPI function and save it with an alias name.
- In the Session name field, enter Default.
- In the Function alias name field, enter BAPI_Post.
-
In the BAPI name field, enter
BAPI_ACC_DOCUMENT_POST.
Note: The SAP BAPI function name and other parameters are specific to the customer environment while creating the Automation 360 bot.
-
To create BAPI_ACC_DOCUMENT_POST in SAP, you must first
create a structure and tables. Select Get structure to obtain
data from a structure using the function alias.
- In the BAPI function alias field, enter BAPI_POST (the alias you provided for SAP BAPI function using the Create function action).
- In the Structure name field, enter DOCUMENTHEADER (the name of the structure from which you want to get data).
- In the SAP BAPI session field, enter Default (the session name you used to connect to the SAP application in the Connect action).
- Select the Alias option to save the data retrieved from the structure and enter Doc in the Create structure alias field.
-
Select the Get table
action to get tabular data from a table using the function
alias.
- In the BAPI function alias field, enter BAPI_Post (the alias you provided for the SAP BAPI function using the Create function action).
- In the Table name field, enter ACCOUNTGL (the name of the table from which you want to obtain data).
- In the SAP BAPI session field, enter Default (the session name you used to connect to the SAP application in the Connect action).
- Select the Alias option to save the data retrieved from the table and enter GL in the Create table alias field.
- Repeat step 5. In step 5(b), enter the value CURRENCYAMOUNT in the Table name field and in step 5(d) enter the value Currency in the Create table alias field.
-
Select the Set field value
action to set data into the empty structure and table created
previously.
- In the BAPI function alias field, enter BAPI_Post.
- From the Source field, select Structure.
- Enter DOC in the Structure alias field.
- In the Field name field, enter USERNAME (the name of the field in which you want to set data).
- In the Field value field, enter sy-uname( the value that you want to set).
- In the SAP BAPI session field, enter Default.
-
Repeat step 7 seven times
and input the same values as you previously entered in steps 7(a,) 7(b), 7(c), and
7(f). Enter the following values for steps 7(d) and 7(e).
Field name Field value BUS_ACT RFBU HEADER_TXT TEST BOC BAPI POSTING COMP_CODE 1000 DOC_DATE 20210127 PSTNG_DATE 20210127 DOC_TYPE SA FIS_PERIOD 00 -
Select the Get structure
action.
- In the BAPI function alias field, enter BAPI_POST.
- In the Structure name field, enter DOCUMENTHEADER.
- In the SAP BAPI session field, enter Default.
- Select the Variable option to store the data retrieved from the structure in a table variable. Create table variable Sap-Bapi-Table.
-
Double-click or drag the Data table > Write to file
action.
- Select the Table variable Sap-Bapi-Table that contains the data to write from the Data table name list.
- Specify the location of the file in which to write the data in the Enter file name field. For example, D:/user defined/My Desktop/SAP Test/DOCUMENTHEADER.csv.
- Select the Create folders/files if it doesn't exist check box.
- Select the Override existing file option when writing data in an existing file.
- Select the new line option from the Row delimiter field.
- Select the comma option from the Column delimiter field.
- Select the ANSI option from the Encoding list.
-
Double-click or drag the Set field value
action to set data into table.
- In the BAPI function alias field, enter BAPI_POST.
- From the Source field, select Table.
- Enter GL in the Table alias field.
- In the Field name field, enter ITEMNO_ACC (the name of the field in which you want to set data).
- In the Field value field, enter 2 (the value that you want to set).
- In the SAP BAPI session field, enter Default (the session name you used to connect to the SAP application in the Connect action).
-
Repeat step 11, seven times
to set data into a table.
While setting values in the table, retain the same value as you previously entered in steps 11(a), 11(b), 11(c), and 11(f). Change the following values for steps 11(d) and 11(e):
Field value Field name GL_ACCOUNT 0000078310 PSTNG_DATE 20210127 ITEM_TEXT TEST POSTING DEBIT ITEM QUANTITY 1000 BASE_UOM EA COMP_CODE 1000 DOC_TYPE SA -
Select the Set value field action.
- In the BAPI function alias field, enter BAPI_POST.
- From the Source field, select Table.
- Enter GL in the Table alias field.
- Select the Create new row check box to enter data in the next row.
- In the Field name field, enter ITEMNO_ACC (the name of the field in which you want to set data).
- In the Field value field, enter 1 (the value that you want to set).
- In the SAP BAPI session field, enter Default (the session name you used to connect to the SAP application in the Connect action).
-
Select the Get table
action.
- In the BAPI function alias field, enter BAPI_POST.
- In the Table name field, enter ACCOUNTGL.
- In the SAP BAPI session field, enter Default.
- Select the Variable option to store the data retrieved from the table in a table variable. Create table variable Sap-Bapi-Table.
-
Double-click or drag the Data table > Write to file
option.
- Select the Table variable Sap-Bapi-Table that contains the data to write from the Data table name list.
- Specify the location of the file in which to write the data in the Enter file name field. For example, D:/user defined /My Desktop/SAP Test/ACCOUNTGL.csv.
- Select the Create folders/files if it doesn't exist check box.
- Select the Override existing file option when writing data in an existing file.
- Select the new line option from the Row delimiter field.
- Select the comma option from the Column delimiter field.
- Select the ANSI option from the Encoding list.
-
Double-click or drag the Set field value
action to set data into a table.
- In the BAPI function alias field, enter BAPI_POST.
- From the Source field, select Table.
- Enter CURRENCY in the Table alias field.
- In the Field name field, enter ITEMNO_ACC (the name of the field in which you want to set data).
- In the Field value field, enter 2 (the value that you want to set).
- In the SAP BAPI session field, enter Default (the session name you used to connect to the SAP application in the Connect action).
-
Repeat step 16, seven times
to set data into a table.
While setting values in the table, retain the same value as you previously entered in steps 16(a), 16(b), 16(c), and 16(f). Change the following values for steps 16(d) and 16(e):
Field name Field value CURRENCY USD AMT_DOCCUR -2000 ITEMNO_ACC 1 CURRENCY USD (repeated) line 43 AMT_DOCCUR 2000 - Repeat step 14 and enter CURRENCYAMOUNT in the Table name field.
- Repeat step 15 and specify the location of the file, for example D:/user defined /My Desktop/SAP Test/CURRENCYAMOUNT.csv.
-
Select the Run function
action to run the SAP BAPI function.
- In the BAPI function alias field, enter BAPI_POST.
- Select the End sequence option to mark the end of a process and the Commit transaction option to commit the changes made during the process.
- In the SAP BAPI session field, enter Default.
-
Select the Get table
action.
- In the BAPI function alias field, enter BAPI_POST.
- In the Table name field, enter RETURN.
- In the SAP BAPI session field, enter Default.
- Select the Variable option to store the data retrieved from the table in a table variable. Create table variable Sap-Bapi-Table.
- Repeat step 15 and specify the location of the file, for example D:/user defined /My Desktop/SAP Test/Return.csv.
-
Select the Get field value
action to obtain data of a specified field from a function.
- In the BAPI function alias field, enter BAPI_POST.
- Select the Function tab from Source field.
- In the Field name field, enter OBJ_KEY.
- In the SAP BAPI session field, enter Default.
- Select Prompt-Assignment in the Save the output to a variable field.
-
Double-click or drag the Message box
action.
- Enter Automation Anywhere Enterprise Client in the Enter the message box window title field.
- Enter $Prompt-Assignment$.
- Enter 30 in the Scroll bar after lines field to show a scroll bar.
- Repeat step 23 and step 24 (In step 23(c), enter the value OBJ_SYS).
- Repeat step 23 and step 24 (In step 23(c), enter the value OBJ_TYPE).
- Click Save and Run.