Tip: How to use Inline ABAP

Advanced Business Application Programming language, or ABAP in short form, is used in SAP environments. ABAP is used to get or processing information in an SAP ERP system. It is only available in SAP application server backend systems. You can’t use ABAP outside an SAP system. In this post I show how you could use inline ABAP with UiPath. This means you store your ABAP code outside an SAP system, transfer and execute it on demand.

Important Hint
Never use this method in productive environments. It is for development and test systems only.

Use Cases

  • Generating test data with all ABAP possiblities
  • Execution of non remote enabled function modules
  • Check data with SAP Open SQL statements

Hint
This method uses the function module RFC_ABAP_INSTALL_AND_RUN. To use this remote enable function module (RFM) you need a lot of authorization objects like S_ADMI_FCD, S_RFCRAIAR, S_TCODE and S_DEVELOP. The hurdle to use this RFM is very high and that’s a good thing, because it can also be used to destroy a lot.

Preparation

Here now the function module:

FUNCTION Z_RFC_ABAP_INSTALL_AND_RUN.
    *"----------------------------------------------------------------------
    *"*"Local Interface:
    *"  IMPORTING
    *"     VALUE(MODE) TYPE  SY-MSGTY DEFAULT 'F'
    *"     VALUE(PROGRAMNAME) TYPE  SOBJ_NAME DEFAULT '<<RFC1>>'
    *"  EXPORTING
    *"     VALUE(ERRORMESSAGE) TYPE  SY-MSGV1
    *"  TABLES
    *"      PROGRAM STRUCTURE  PROGTAB
    *"      WRITES STRUCTURE  LISTZEILE
    *"----------------------------------------------------------------------

      DATA lv_role TYPE cccategory.

      CALL FUNCTION 'TR_SYS_PARAMS'
        IMPORTING
          SYSTEM_CLIENT_ROLE = lv_role
        EXCEPTIONS
          OTHERS             = 1.
      IF sy-subrc <> 0.
        ERRORMESSAGE = 'Error at detection of the global system parameters'.
        EXIT.
      ENDIF.
      IF lv_role = 'P'.
        ERRORMESSAGE = 'Client role is production, execution not allowed'.
        EXIT.
      ENDIF.

      CALL FUNCTION 'RFC_ABAP_INSTALL_AND_RUN'
        EXPORTING
          MODE         = MODE
          PROGRAMNAME  = PROGRAMNAME
        IMPORTING
          ERRORMESSAGE = ERRORMESSAGE
        TABLES
          PROGRAM      = PROGRAM
          WRITES       = WRITES.

    ENDFUNCTION.

Puh, that is a lot of stuff. :sweat:

Usage
Now we can use this possibilities in UiPath. :slightly_smiling_face:
The approach is the same as I described here about via Invoke Code activity.
Here the VB code:

'-Begin-----------------------------------------------------------------

Dim cfgParams As SAP.Middleware.Connector.RfcConfigParameters
Dim destination As SAP.Middleware.Connector.RfcDestination
Dim rfcFunction As SAP.Middleware.Connector.IRfcFunction
Dim tblReport As SAP.Middleware.Connector.IRfcTable
Dim ABAPLine As String
Dim ABAPLines As String()
Dim tblReturn As SAP.Middleware.Connector.IRfcTable
Dim retLine As SAP.Middleware.Connector.IRfcStructure

cfgParams = New SAP.Middleware.Connector.RfcConfigParameters
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.Name, "Test" )
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.AppServerHost, AppServerHost)
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.SystemNumber, SystemNumber)
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.Client, Client)
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.User, User)
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.Password, Password)

destination = SAP.Middleware.Connector.RfcDestinationManager.GetDestination(cfgParams)

rfcFunction = destination.Repository.CreateFunction("Z_RFC_ABAP_INSTALL_AND_RUN")

Try

  tblReport = rfcFunction.GetTable("PROGRAM")
  ABAPLines = ABAPCode.Split(New String() { Environment.NewLine }, StringSplitOptions.None)
  For Each ABAPLine In ABAPLines
    If String.IsNullOrEmpty(ABAPLine) Then
      Continue For
    End If
    tblReport.Append()
    tblReport.SetValue("LINE", ABAPLine)
  Next

  rfcFunction.Invoke(destination)

  tblReturn = rfcFunction.GetTable("WRITES")
  ABAPResult = ""
  For Each retLine In tblReturn
    ABAPResult += retLine.GetValue("ZEILE").ToString() & vbCrLf
  Next

Catch e As Exception
  Console.WriteLine(e.Message)
End Try

'-End-------------------------------------------------------------------


On this way we can use inline ABAP easily.


At first it is necessary to define the ABAP code and with a multi assign activity to set the connection parameters. Then the code is executed, the result is returned and displayed.

In my demo I used a very simple example which delivers only a “Hello” and the SystemID of the SAP backend system.

ABAP Code
005
And it works, great. :grinning:

What else needs to be considered

  • Each line of the ABAP code must not exceed 72 characters in length.
  • It is of course much easier to read the ABAP code from a file.

Another Example
Here an ABAP report with an open SQL statement. In SAP looks like this:

Example in SAP
In UiPath Studio it looks like this:

Example in UiPath
And this example delivers this result:


It seems that for this kind of data another type is better, string is here not the best choice - but it is a show case.

Conclusion
As I have shown here, it is possible to run inline ABAP with UiPath. This opens many new opportunities. Adjustments are certainly necessary in individual cases and restrictions have to be accepted, but it is a powerful combination of UI automation, the using of BAPIs, RFMs and ABAP in SAP context.

Enjoy it :wink:

Last but not least here the workflow
ABAPInlineSequence.xaml (9.6 KB)

3 Likes