process-mining
2021.10
true
UiPath logo, featuring letters U and I in white
Process Mining
Automation CloudAutomation Cloud Public SectorAutomation SuiteStandalone
Last updated Sep 2, 2024

Installing the Z_XTRACT_IS_TABLE Function Module on Your SAP System

Introduction

To use the native SAP extraction from UiPath Process Mining, you must add the Z_XTRACT_IS_TABLE Function module to your SAP system.
Note: When setting up a native SAP extraction the SAP Z_XTRACT_IS_TABLE Function Module is required. If, for example, the Function Module is renamed in your SAP system, you can specify the correct name in the (optional) FunctionModule parameter in the SAP connection string.

Prerequisite

To be able to install the Custom Function Module on your SAP system you must have the credentials of an SAP user with a development key.

Adding a New Function Group

Note: It is recommended to add a new Function group to add the function module.

Follow these steps to add a new Function group.

Step

Action

1

Open the SAP GUI.

2

Enter SE37 in the command field in the top left.

3

Go to the Goto menu and select Function group -> Create group.

4

Enter a name for the Function group.

Note: the name must start with Z, for example Z_PM_DATA_EXTRACTION.

5

Enter a description for the Function group in the Short Text field, for example ProcessMining Data Extraction.

6

Click on Save.

Activating the Function Group

Follow these steps to activate the Function group.

Step

Action

1

Select Function Group.

2

Search for the Function group you created, for example PM_DATA_EXTRACTION.

3

Right-click on the top object of the Function group and select Activate it from the context menu.

Adding the Function Module

Once the Function group is created, you can add the Function module from the SE37 GUI window.

Follow these steps to install the Z_XTRACT_IS_TABLE Function module.

Step

Action

1

Enter Z_XTRACT_IS_TABLE in the Function Module field and click on Create.

2

Go to the Attributes tab and select the Remote-Enabled Module option in the Processing Type options list.

3

Go to the Import tab and define the import parameters as listed below.

Note: you might get a warning that the LIKE operator is obsolete. You can ignore the warning and go through the list. Click ENTER to acknowledge that you still want to use it. Once you went through the entire list the code is accepted.

4

Go to the Tables tab and define the tables parameters as listed below.

Note: you might get a warning that the LIKE operator is obsolete. You can ignore the warning and go through the list. Click ENTER to acknowledge that you still want to use it. Once you went through the entire list the code is accepted.

5

Go to the Exceptions tab to define the exceptions as listed below.

6

Go to the Source code tab and enter the ABAP code for the Z_XTRACT_IS_TABLE.
Note: you can copy and paste the code displayed below.

7

Save the Function module and activate it.

Import Parameters

See illustration below for an overview of the import parameters to be defined in the Import tab.



Tables Parameters

See illustration below for an overview of the tables parameters to be defined in the Tables tab.



Exceptions

See illustration below for an overview of the Exceptions to be defined in the Exceptions tab.



ABAP Code

See code text below for the ABAP code to be pasted in the Source code tab.

FUNCTION Z_XTRACT_IS_TABLE.
*"
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(QUERY_TABLE) LIKE  DD02L-TABNAME
*"     VALUE(DELIMITER) LIKE  SONV-FLAG DEFAULT SPACE
*"     VALUE(NO_DATA) LIKE  SONV-FLAG DEFAULT SPACE
*"    VALUE(ROWSKIPS) LIKE  SOID-ACCNT DEFAULT 0
*"     VALUE(ROWCOUNT) LIKE  SOID-ACCNT DEFAULT 0
*"  TABLES
*"      OPTIONS STRUCTURE  RFC_DB_OPT
*"      FIELDS STRUCTURE  RFC_DB_FLD
*"     DATA STRUCTURE  CHAR8000
*"  EXCEPTIONS
*"      TABLE_NOT_AVAILABLE
*"      TABLE_WITHOUT_DATA
*"     OPTION_NOT_VALID
*"     FIELD_NOT_VALID
*"     NOT_AUTHORIZED
*"      DATA_BUFFER_EXCEEDED
*"-------------------------------------------
"
CALL FUNCTION 'VIEW_AUTHORITY_CHECK'
     EXPORTING
          VIEW_ACTION                    = 'S'
          VIEW_NAME                      = QUERY_TABLE
     EXCEPTIONS
          NO_AUTHORITY                   = 2
          NO_CLIENTINDEPENDENT_AUTHORITY = 2
          NO_LINEDEPENDENT_AUTHORITY     = 2
          OTHERS                         = 1.
IF SY-SUBRC = 2.
  RAISE NOT_AUTHORIZED.
ELSEIF SY-SUBRC = 1.
  RAISE TABLE_NOT_AVAILABLE.
ENDIF.
* -------------------------------------------- 
*  find out about the structure of QUERY_TABLE
* --------------------------------------------
DATA BEGIN OF TABLE_STRUCTURE OCCURS 10.
        INCLUDE STRUCTURE DFIES.
DATA END OF TABLE_STRUCTURE.
"DATA TABLE_HEADER LIKE X030L.
DATA TABLE_TYPE TYPE DD02V-TABCLASS.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
  EXPORTING
    TABNAME              = QUERY_TABLE
*   FIELDNAME            = ' '
*   LANGU                = SY-LANGU
*   LFIELDNAME           = ' '
*   ALL_TYPES            = ' '
*   GROUP_NAMES          = ' '
  IMPORTING
*   X030L_WA             =
    DDOBJTYPE            = TABLE_TYPE
*   DFIES_WA             =
*   LINES_DESCR          =
  TABLES
    DFIES_TAB            = TABLE_STRUCTURE
*   FIXED_VALUES         =
  EXCEPTIONS
    NOT_FOUND            = 1
    INTERNAL_ERROR       = 2
    OTHERS               = 3
          .
IF SY-SUBRC <> 0.
  RAISE TABLE_NOT_AVAILABLE.
ENDIF.
IF TABLE_TYPE = 'INTTAB'.
  RAISE TABLE_WITHOUT_DATA.
ENDIF.
* -------------------------------------------
*  isolate first field of DATA as output field
*  (i.e. allow for changes to structure DATA!)
* -------------------------------------------
DATA LINE_LENGTH TYPE I.
FIELD-SYMBOLS <D>.
ASSIGN COMPONENT 0 OF STRUCTURE DATA TO <D>.
* If this line leads to a syntax error
* please just delete the 'in character mode'
DESCRIBE FIELD <D> LENGTH LINE_LENGTH in character mode.
* -------------------------------------------
*  if FIELDS are not specified, read all available fields
* -------------------------------------------
DATA NUMBER_OF_FIELDS TYPE I.
DESCRIBE TABLE FIELDS LINES NUMBER_OF_FIELDS.
IF NUMBER_OF_FIELDS = 0.
  LOOP AT TABLE_STRUCTURE.
    MOVE TABLE_STRUCTURE-FIELDNAME TO FIELDS-FIELDNAME.
    APPEND FIELDS.
  ENDLOOP.
ENDIF.
* -------------------------------------------
*  for each field which has to be read, copy structure information
*  into tables FIELDS_INT (internal use) and FIELDS (output)
* -------------------------------------------
DATA: BEGIN OF FIELDS_INT OCCURS 10,
        FIELDNAME  LIKE TABLE_STRUCTURE-FIELDNAME,
        TYPE       LIKE TABLE_STRUCTURE-INTTYPE,
        DECIMALS   LIKE TABLE_STRUCTURE-DECIMALS,
        LENGTH_SRC LIKE TABLE_STRUCTURE-INTLEN,
        LENGTH_DST LIKE TABLE_STRUCTURE-LENG,
        OFFSET_SRC LIKE TABLE_STRUCTURE-OFFSET,
        OFFSET_DST LIKE TABLE_STRUCTURE-OFFSET,
      END OF FIELDS_INT,
      LINE_CURSOR TYPE I.
LINE_CURSOR = 0.
*  for each field which has to be read ...
LOOP AT FIELDS.
  READ TABLE TABLE_STRUCTURE WITH KEY FIELDNAME = FIELDS-FIELDNAME.
  IF SY-SUBRC NE 0.
    RAISE FIELD_NOT_VALID.
  ENDIF.
* compute the place for field contents in DATA rows:
* if not first field in row, allow space for delimiter
  IF LINE_CURSOR <> 0.
    IF NO_DATA EQ SPACE AND DELIMITER NE SPACE.
      MOVE DELIMITER TO DATA+LINE_CURSOR.
    ENDIF.
    LINE_CURSOR = LINE_CURSOR + STRLEN( DELIMITER ).
  ENDIF.
* ... copy structure information into tables FIELDS_INT
* (which is used internally during SELECT) ...
  FIELDS_INT-FIELDNAME  = TABLE_STRUCTURE-FIELDNAME.
  FIELDS_INT-LENGTH_SRC = TABLE_STRUCTURE-INTLEN.
*  FIELDS_INT-LENGTH_DST = TABLE_STRUCTURE-LENG.
* modified by Theobald, 2007-11-20
  FIELDS_INT-LENGTH_DST = TABLE_STRUCTURE-OUTPUTLEN.
  FIELDS_INT-OFFSET_SRC = TABLE_STRUCTURE-OFFSET.
  FIELDS_INT-OFFSET_DST = LINE_CURSOR.
  FIELDS_INT-TYPE       = TABLE_STRUCTURE-INTTYPE.
  FIELDS_INT-DECIMALS   = TABLE_STRUCTURE-DECIMALS.
* compute the place for contents of next field in DATA rows
*  LINE_CURSOR = LINE_CURSOR + TABLE_STRUCTURE-LENG.
* modified by Theobald, 2007-11-20
LINE_CURSOR = LINE_CURSOR + TABLE_STRUCTURE-OUTPUTLEN.
  IF LINE_CURSOR > LINE_LENGTH AND NO_DATA EQ SPACE.
    RAISE DATA_BUFFER_EXCEEDED.
  ENDIF.
  APPEND FIELDS_INT.
* ... and into table FIELDS (which is output to the caller)
  FIELDS-FIELDTEXT = TABLE_STRUCTURE-FIELDTEXT.
  FIELDS-TYPE      = TABLE_STRUCTURE-INTTYPE.
  FIELDS-LENGTH    = FIELDS_INT-LENGTH_DST.
  FIELDS-OFFSET    = FIELDS_INT-OFFSET_DST.
  MODIFY FIELDS.
ENDLOOP.
* end of loop at FIELDS
* -------------------------------------------
*  read data from the database and copy relevant portions into DATA
* -------------------------------------------
* output data only if NO_DATA equals space (otherwise the structure
* information in FIELDS is the only result of the module)
IF NO_DATA EQ SPACE.
DATA: BEGIN OF WORK, BUFFER(30000), F TYPE F, END OF WORK.
FIELD-SYMBOLS: <WA> TYPE ANY, <COMP> TYPE ANY.
ASSIGN WORK TO <WA> CASTING TYPE (QUERY_TABLE).
IF ROWCOUNT > 0.
  ROWCOUNT = ROWCOUNT + ROWSKIPS.
ENDIF.
  SELECT * FROM (QUERY_TABLE) INTO <WA> WHERE (OPTIONS).
    IF SY-DBCNT GT ROWSKIPS.
*   copy all relevant fields into DATA (output) table
      LOOP AT FIELDS_INT.
        IF FIELDS_INT-TYPE = 'P'.
        ASSIGN COMPONENT FIELDS_INT-FIELDNAME
            OF STRUCTURE <WA> TO <COMP>
            TYPE     FIELDS_INT-TYPE
            DECIMALS FIELDS_INT-DECIMALS.
        ELSE.
        ASSIGN COMPONENT FIELDS_INT-FIELDNAME
            OF STRUCTURE <WA> TO <COMP>
            TYPE     FIELDS_INT-TYPE.
        ENDIF.
        MOVE <COMP> TO
            <D>+FIELDS_INT-OFFSET_DST(FIELDS_INT-LENGTH_DST).
      ENDLOOP.
*   end of loop at FIELDS_INT
      APPEND DATA.
      IF ROWCOUNT > 0 AND SY-DBCNT GE ROWCOUNT. EXIT. ENDIF.
    ENDIF.
  ENDSELECT.
ENDIF.
ENDFUNCTION.FUNCTION Z_XTRACT_IS_TABLE.
*"
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(QUERY_TABLE) LIKE  DD02L-TABNAME
*"     VALUE(DELIMITER) LIKE  SONV-FLAG DEFAULT SPACE
*"     VALUE(NO_DATA) LIKE  SONV-FLAG DEFAULT SPACE
*"    VALUE(ROWSKIPS) LIKE  SOID-ACCNT DEFAULT 0
*"     VALUE(ROWCOUNT) LIKE  SOID-ACCNT DEFAULT 0
*"  TABLES
*"      OPTIONS STRUCTURE  RFC_DB_OPT
*"      FIELDS STRUCTURE  RFC_DB_FLD
*"     DATA STRUCTURE  CHAR8000
*"  EXCEPTIONS
*"      TABLE_NOT_AVAILABLE
*"      TABLE_WITHOUT_DATA
*"     OPTION_NOT_VALID
*"     FIELD_NOT_VALID
*"     NOT_AUTHORIZED
*"      DATA_BUFFER_EXCEEDED
*"-------------------------------------------
"
CALL FUNCTION 'VIEW_AUTHORITY_CHECK'
     EXPORTING
          VIEW_ACTION                    = 'S'
          VIEW_NAME                      = QUERY_TABLE
     EXCEPTIONS
          NO_AUTHORITY                   = 2
          NO_CLIENTINDEPENDENT_AUTHORITY = 2
          NO_LINEDEPENDENT_AUTHORITY     = 2
          OTHERS                         = 1.
IF SY-SUBRC = 2.
  RAISE NOT_AUTHORIZED.
ELSEIF SY-SUBRC = 1.
  RAISE TABLE_NOT_AVAILABLE.
ENDIF.
* -------------------------------------------- 
*  find out about the structure of QUERY_TABLE
* --------------------------------------------
DATA BEGIN OF TABLE_STRUCTURE OCCURS 10.
        INCLUDE STRUCTURE DFIES.
DATA END OF TABLE_STRUCTURE.
"DATA TABLE_HEADER LIKE X030L.
DATA TABLE_TYPE TYPE DD02V-TABCLASS.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
  EXPORTING
    TABNAME              = QUERY_TABLE
*   FIELDNAME            = ' '
*   LANGU                = SY-LANGU
*   LFIELDNAME           = ' '
*   ALL_TYPES            = ' '
*   GROUP_NAMES          = ' '
  IMPORTING
*   X030L_WA             =
    DDOBJTYPE            = TABLE_TYPE
*   DFIES_WA             =
*   LINES_DESCR          =
  TABLES
    DFIES_TAB            = TABLE_STRUCTURE
*   FIXED_VALUES         =
  EXCEPTIONS
    NOT_FOUND            = 1
    INTERNAL_ERROR       = 2
    OTHERS               = 3
          .
IF SY-SUBRC <> 0.
  RAISE TABLE_NOT_AVAILABLE.
ENDIF.
IF TABLE_TYPE = 'INTTAB'.
  RAISE TABLE_WITHOUT_DATA.
ENDIF.
* -------------------------------------------
*  isolate first field of DATA as output field
*  (i.e. allow for changes to structure DATA!)
* -------------------------------------------
DATA LINE_LENGTH TYPE I.
FIELD-SYMBOLS <D>.
ASSIGN COMPONENT 0 OF STRUCTURE DATA TO <D>.
* If this line leads to a syntax error
* please just delete the 'in character mode'
DESCRIBE FIELD <D> LENGTH LINE_LENGTH in character mode.
* -------------------------------------------
*  if FIELDS are not specified, read all available fields
* -------------------------------------------
DATA NUMBER_OF_FIELDS TYPE I.
DESCRIBE TABLE FIELDS LINES NUMBER_OF_FIELDS.
IF NUMBER_OF_FIELDS = 0.
  LOOP AT TABLE_STRUCTURE.
    MOVE TABLE_STRUCTURE-FIELDNAME TO FIELDS-FIELDNAME.
    APPEND FIELDS.
  ENDLOOP.
ENDIF.
* -------------------------------------------
*  for each field which has to be read, copy structure information
*  into tables FIELDS_INT (internal use) and FIELDS (output)
* -------------------------------------------
DATA: BEGIN OF FIELDS_INT OCCURS 10,
        FIELDNAME  LIKE TABLE_STRUCTURE-FIELDNAME,
        TYPE       LIKE TABLE_STRUCTURE-INTTYPE,
        DECIMALS   LIKE TABLE_STRUCTURE-DECIMALS,
        LENGTH_SRC LIKE TABLE_STRUCTURE-INTLEN,
        LENGTH_DST LIKE TABLE_STRUCTURE-LENG,
        OFFSET_SRC LIKE TABLE_STRUCTURE-OFFSET,
        OFFSET_DST LIKE TABLE_STRUCTURE-OFFSET,
      END OF FIELDS_INT,
      LINE_CURSOR TYPE I.
LINE_CURSOR = 0.
*  for each field which has to be read ...
LOOP AT FIELDS.
  READ TABLE TABLE_STRUCTURE WITH KEY FIELDNAME = FIELDS-FIELDNAME.
  IF SY-SUBRC NE 0.
    RAISE FIELD_NOT_VALID.
  ENDIF.
* compute the place for field contents in DATA rows:
* if not first field in row, allow space for delimiter
  IF LINE_CURSOR <> 0.
    IF NO_DATA EQ SPACE AND DELIMITER NE SPACE.
      MOVE DELIMITER TO DATA+LINE_CURSOR.
    ENDIF.
    LINE_CURSOR = LINE_CURSOR + STRLEN( DELIMITER ).
  ENDIF.
* ... copy structure information into tables FIELDS_INT
* (which is used internally during SELECT) ...
  FIELDS_INT-FIELDNAME  = TABLE_STRUCTURE-FIELDNAME.
  FIELDS_INT-LENGTH_SRC = TABLE_STRUCTURE-INTLEN.
*  FIELDS_INT-LENGTH_DST = TABLE_STRUCTURE-LENG.
* modified by Theobald, 2007-11-20
  FIELDS_INT-LENGTH_DST = TABLE_STRUCTURE-OUTPUTLEN.
  FIELDS_INT-OFFSET_SRC = TABLE_STRUCTURE-OFFSET.
  FIELDS_INT-OFFSET_DST = LINE_CURSOR.
  FIELDS_INT-TYPE       = TABLE_STRUCTURE-INTTYPE.
  FIELDS_INT-DECIMALS   = TABLE_STRUCTURE-DECIMALS.
* compute the place for contents of next field in DATA rows
*  LINE_CURSOR = LINE_CURSOR + TABLE_STRUCTURE-LENG.
* modified by Theobald, 2007-11-20
LINE_CURSOR = LINE_CURSOR + TABLE_STRUCTURE-OUTPUTLEN.
  IF LINE_CURSOR > LINE_LENGTH AND NO_DATA EQ SPACE.
    RAISE DATA_BUFFER_EXCEEDED.
  ENDIF.
  APPEND FIELDS_INT.
* ... and into table FIELDS (which is output to the caller)
  FIELDS-FIELDTEXT = TABLE_STRUCTURE-FIELDTEXT.
  FIELDS-TYPE      = TABLE_STRUCTURE-INTTYPE.
  FIELDS-LENGTH    = FIELDS_INT-LENGTH_DST.
  FIELDS-OFFSET    = FIELDS_INT-OFFSET_DST.
  MODIFY FIELDS.
ENDLOOP.
* end of loop at FIELDS
* -------------------------------------------
*  read data from the database and copy relevant portions into DATA
* -------------------------------------------
* output data only if NO_DATA equals space (otherwise the structure
* information in FIELDS is the only result of the module)
IF NO_DATA EQ SPACE.
DATA: BEGIN OF WORK, BUFFER(30000), F TYPE F, END OF WORK.
FIELD-SYMBOLS: <WA> TYPE ANY, <COMP> TYPE ANY.
ASSIGN WORK TO <WA> CASTING TYPE (QUERY_TABLE).
IF ROWCOUNT > 0.
  ROWCOUNT = ROWCOUNT + ROWSKIPS.
ENDIF.
  SELECT * FROM (QUERY_TABLE) INTO <WA> WHERE (OPTIONS).
    IF SY-DBCNT GT ROWSKIPS.
*   copy all relevant fields into DATA (output) table
      LOOP AT FIELDS_INT.
        IF FIELDS_INT-TYPE = 'P'.
        ASSIGN COMPONENT FIELDS_INT-FIELDNAME
            OF STRUCTURE <WA> TO <COMP>
            TYPE     FIELDS_INT-TYPE
            DECIMALS FIELDS_INT-DECIMALS.
        ELSE.
        ASSIGN COMPONENT FIELDS_INT-FIELDNAME
            OF STRUCTURE <WA> TO <COMP>
            TYPE     FIELDS_INT-TYPE.
        ENDIF.
        MOVE <COMP> TO
            <D>+FIELDS_INT-OFFSET_DST(FIELDS_INT-LENGTH_DST).
      ENDLOOP.
*   end of loop at FIELDS_INT
      APPEND DATA.
      IF ROWCOUNT > 0 AND SY-DBCNT GE ROWCOUNT. EXIT. ENDIF.
    ENDIF.
  ENDSELECT.
ENDIF.
ENDFUNCTION.

Checking and Activating the Function Module

After you pasted the ABAP code it is recommend to check your code for syntax errors before you activate the Function module.

Checking the Function Module

Follow this step to check the ABAP code.

Step

Action

1

Press CTRL+F2 in the SAP Source code tab.

If there are no errors, you can activate the Function module.

Activating the Function Module

Follow these steps to activate the Function module.

Step

Action

1

Enter SE80 in the command field in the top left.

2

Select Function Module.

3

Search for Z_XTRACT_IS_TABLE.

4

Right-click on the top object of Z_XTRACT_IS_TABLE and select Activate it from the context menu.

Connecting to the SAP Datasource From UiPath Process Mining

At this point it is possible to extract data from the SAP system using the native SAP connection. You can connect to the SAP datasource by creating a new input table using an SAP connection string table and defining a query to extract the data. See illustration below.



Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.