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
- Download and installation of Microsoft Visual C++ 2010 SP1 Redistributable Package (x86).
- Add SAP dotNET Connector (NCo) as I described here.
- Coding of an individually RFM wrapper around RFC_ABAP_INSTALL_AND_RUN in the SAP system. This has two reasons: The first is to check additional if the ERP system is non productive. RFC_ABAP_INSTALL_AND_RUN checks on the same way different options. The second is a problem between NCo and RFC_ABAP_INSTALL_AND_RUN. The import parameter PROGRAMNAME is from the type SY-REPID and NCo can’t handle this type. That’s why it is changed to SOBJ_NAME.
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.
Usage
Now we can use this possibilities in UiPath.
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.
And it works, great.
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:
In UiPath Studio it looks like this:
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
Last but not least here the workflow
ABAPInlineSequence.xaml (9.6 KB)