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

  1. Open a new bot:
    1. On the left panel, click Automation.
    2. Click Create new > Bot.
    3. In the Create Task Bot window, enter a bot name.
    4. Click Create and edit.
  2. Establish a connection with the SAP application using the Connect action.
    1. In the SAP BAPI Session field, enter Default.
    2. 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
    3. 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
    4. Select the Group/Server option as the connection type.
    5. Select Insecure string and enter AWINAAWO12.bcone.com to specify the hostname for the SAP message server.
    6. Enter AWINAAWO12.bcone.com in the Gateway host field to connect to the server.
    7. 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
    8. Select Insecure string and enter ISR3 to specify the username you want to use to connect to the SAP server.
    9. Select Insecure string and enter Automation@123 to specify the password you want to use to connect to the SAP server.
  3. Use the Create function action to create a function for the SAP BAPI function.
    1. Create an alias for an SAP BAPI function and save it with an alias name.
    2. In the Session name field, enter Default.
    3. In the Function alias name field, enter BAPI_Post.
    4. 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.
  4. 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.
    1. In the BAPI function alias field, enter BAPI_POST (the alias you provided for SAP BAPI function using the Create function action).
    2. In the Structure name field, enter DOCUMENTHEADER (the name of the structure from which you want to get data).
    3. In the SAP BAPI session field, enter Default (the session name you used to connect to the SAP application in the Connect action).
    4. Select the Alias option to save the data retrieved from the structure and enter Doc in the Create structure alias field.
  5. Select the Get table action to get tabular data from a table using the function alias.
    1. In the BAPI function alias field, enter BAPI_Post (the alias you provided for the SAP BAPI function using the Create function action).
    2. In the Table name field, enter ACCOUNTGL (the name of the table from which you want to obtain data).
    3. In the SAP BAPI session field, enter Default (the session name you used to connect to the SAP application in the Connect action).
    4. Select the Alias option to save the data retrieved from the table and enter GL in the Create table alias field.
  6. 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.
  7. Select the Set field value action to set data into the empty structure and table created previously.
    1. In the BAPI function alias field, enter BAPI_Post.
    2. From the Source field, select Structure.
    3. Enter DOC in the Structure alias field.
    4. In the Field name field, enter USERNAME (the name of the field in which you want to set data).
    5. In the Field value field, enter sy-uname( the value that you want to set).
    6. In the SAP BAPI session field, enter Default.
  8. 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
  9. Select the Get structure action.
    1. In the BAPI function alias field, enter BAPI_POST.
    2. In the Structure name field, enter DOCUMENTHEADER.
    3. In the SAP BAPI session field, enter Default.
    4. Select the Variable option to store the data retrieved from the structure in a table variable. Create table variable Sap-Bapi-Table.
  10. Double-click or drag the Data table > Write to file action.
    1. Select the Table variable Sap-Bapi-Table that contains the data to write from the Data table name list.
    2. 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.
    3. Select the Create folders/files if it doesn't exist check box.
    4. Select the Override existing file option when writing data in an existing file.
    5. Select the new line option from the Row delimiter field.
    6. Select the comma option from the Column delimiter field.
    7. Select the ANSI option from the Encoding list.
  11. Double-click or drag the Set field value action to set data into table.
    1. In the BAPI function alias field, enter BAPI_POST.
    2. From the Source field, select Table.
    3. Enter GL in the Table alias field.
    4. In the Field name field, enter ITEMNO_ACC (the name of the field in which you want to set data).
    5. In the Field value field, enter 2 (the value that you want to set).
    6. In the SAP BAPI session field, enter Default (the session name you used to connect to the SAP application in the Connect action).
  12. 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
  13. Select the Set value field action.
    1. In the BAPI function alias field, enter BAPI_POST.
    2. From the Source field, select Table.
    3. Enter GL in the Table alias field.
    4. Select the Create new row check box to enter data in the next row.
    5. In the Field name field, enter ITEMNO_ACC (the name of the field in which you want to set data).
    6. In the Field value field, enter 1 (the value that you want to set).
    7. In the SAP BAPI session field, enter Default (the session name you used to connect to the SAP application in the Connect action).
  14. Select the Get table action.
    1. In the BAPI function alias field, enter BAPI_POST.
    2. In the Table name field, enter ACCOUNTGL.
    3. In the SAP BAPI session field, enter Default.
    4. Select the Variable option to store the data retrieved from the table in a table variable. Create table variable Sap-Bapi-Table.
  15. Double-click or drag the Data table > Write to file option.
    1. Select the Table variable Sap-Bapi-Table that contains the data to write from the Data table name list.
    2. 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.
    3. Select the Create folders/files if it doesn't exist check box.
    4. Select the Override existing file option when writing data in an existing file.
    5. Select the new line option from the Row delimiter field.
    6. Select the comma option from the Column delimiter field.
    7. Select the ANSI option from the Encoding list.
  16. Double-click or drag the Set field value action to set data into a table.
    1. In the BAPI function alias field, enter BAPI_POST.
    2. From the Source field, select Table.
    3. Enter CURRENCY in the Table alias field.
    4. In the Field name field, enter ITEMNO_ACC (the name of the field in which you want to set data).
    5. In the Field value field, enter 2 (the value that you want to set).
    6. In the SAP BAPI session field, enter Default (the session name you used to connect to the SAP application in the Connect action).
  17. 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
  18. Repeat step 14 and enter CURRENCYAMOUNT in the Table name field.
  19. Repeat step 15 and specify the location of the file, for example D:/user defined /My Desktop/SAP Test/CURRENCYAMOUNT.csv.
  20. Select the Run function action to run the SAP BAPI function.
    1. In the BAPI function alias field, enter BAPI_POST.
    2. 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.
    3. In the SAP BAPI session field, enter Default.
  21. Select the Get table action.
    1. In the BAPI function alias field, enter BAPI_POST.
    2. In the Table name field, enter RETURN.
    3. In the SAP BAPI session field, enter Default.
    4. Select the Variable option to store the data retrieved from the table in a table variable. Create table variable Sap-Bapi-Table.
  22. Repeat step 15 and specify the location of the file, for example D:/user defined /My Desktop/SAP Test/Return.csv.
  23. Select the Get field value action to obtain data of a specified field from a function.
    1. In the BAPI function alias field, enter BAPI_POST.
    2. Select the Function tab from Source field.
    3. In the Field name field, enter OBJ_KEY.
    4. In the SAP BAPI session field, enter Default.
    5. Select Prompt-Assignment in the Save the output to a variable field.
  24. Double-click or drag the Message box action.
    1. Enter Automation Anywhere Enterprise Client in the Enter the message box window title field.
    2. Enter $Prompt-Assignment$.
    3. Enter 30 in the Scroll bar after lines field to show a scroll bar.
  25. Repeat step 23 and step 24 (In step 23(c), enter the value OBJ_SYS).
  26. Repeat step 23 and step 24 (In step 23(c), enter the value OBJ_TYPE).
  27. Click Save and Run.