Skip to Content

About author:

I am Vijay Suman from Accenture Services Pvt Ltd working as Lead for  SAP-ABAP, ABAP-BI, ABAP-HR.

This document explains implementation of SAP TREX using custom BW extractor. Earlier I searched for this kind of document to implement SAP-TREX for our Client requirement but I didnot find it anywhere which led me to do R&D and find out how we can achieve this.

SAP TREX development using custom BW Extractor:

This document explains and helps step-by-step process to create and configure custom TREX development using BW Function module extractor.

For TREX development using BW Datasource, we create a BW Datasource having Function Module extractor. We need to assign this Datasource to Template Modeler in TREX. Upon executing TREX, this BW datasource extracts the data from DB using our custom logic in function module and displays the results in TREX through the Template Modeler created.

Create an extract structure for BW Extractor function module same as that of TREX results’ structure. ZV_TEST_TAB1 view is our extract structure. We use Function Module extractor for our DataSource, so, no need to worry about view output.

Pic1.png

Create custom function module ZTEST_FM_TRAINING1 for extraction with importing and tables parameters as follows:

Pic2.png

Pic3.png

Let us consider a simple example to extract Employment status, First name and Last name of an employee to show in TREX.

We don’t need to use CURSOR logic in this case, but as a standard practice in BW extractors I have used CURSOR technique here, otherwise we can write simple logic to fill output internal table E_T_DATA.

The logic is as follows:

FUNCTION ZTEST_FM_TRAINING1.

*”———————————————————————-

*”*”Local Interface:

*”  IMPORTING

*”     VALUE(I_REQUNR) TYPE  SBIWA_S_INTERFACE-REQUNR

*”     VALUE(I_DSOURCE) TYPE  SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL

*”     VALUE(I_MAXSIZE) TYPE  SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL

*”     VALUE(I_INITFLAG) TYPE  SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL

*”     VALUE(I_READ_ONLY) TYPE  SRSC_S_IF_SIMPLE-READONLY OPTIONAL

*”     VALUE(I_REMOTE_CALL) TYPE  SBIWA_FLAG DEFAULT SBIWA_C_FLAG_OFF

*”  TABLES

*”      I_T_SELECT TYPE  SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL

*”      I_T_FIELDS TYPE  SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL

*”      E_T_DATA STRUCTURE  ZV_TEST_TAB1 OPTIONAL

*”———————————————————————-

  TYPE-POOLS srsc.

* INCLUDE LZHCM_02D…                       ” Local class definition

  TYPE-POOLS:

    rsaot,

    rsazt,

    sbiwa.

  RANGES:

     g_r_OBJID           FOR ZV_TEST_TAB1-OBJID,

     g_r_OTYPE           FOR ZV_TEST_TAB1-OTYPE,

     g_r_OTJID           FOR ZV_TEST_TAB1-OTJID,

     g_r_FOREMP           FOR ZV_TEST_TAB1-FOREMPLOYE.

  DATA: gt_e_t_data TYPE STANDARD TABLE OF  ZV_TEST_TAB1,

        gt_e_t_data_temp TYPE STANDARD TABLE OF  ZV_TEST_TAB1.

DATA: L_S_SELECT TYPE SRSC_S_SELECT.

STATICS: S_COUNTER_DATAPAKID LIKE SY-TABIX,

         S_S_IF TYPE SRSC_S_IF_SIMPLE,

         S_CURSOR1 TYPE CURSOR,

         S_CURSOR2 TYPE CURSOR,

         S_CURSOR3 TYPE CURSOR.

  Types: BEGIN OF gty_HRP1000,

          OTYPE TYPE OTYPE,

          objid   TYPE HROBJID,

         END OF gty_HRP1000,

         BEGIN OF gty_HRP1002,

          OTYPE TYPE OTYPE,

          objid   TYPE HROBJID,

          OTJID TYPE OTJID,

         END OF gty_HRP1002,

         BEGIN OF gty_HRP9305,

          OTYPE TYPE OTYPE,

          objid   TYPE HROBJID,

          FOREMPLOYE TYPE ZPFOREMPLOYE,

         END OF gty_HRP9305,

         BEGIN OF gty_FINAL,

          OTYPE TYPE OTYPE,

          objid   TYPE HROBJID,

          OTJID TYPE OTJID,

          FOREMPLOYE TYPE ZPFOREMPLOYE,

         END OF gty_FINAL.

  DATA: gt_HRP1000 TYPE STANDARD TABLE OF  gty_HRP1000,

    gt_HRP1002 TYPE STANDARD TABLE OF  gty_HRP1002,

    gt_HRP9305 TYPE STANDARD TABLE OF  gty_HRP9305,

    gt_FINAL TYPE STANDARD TABLE OF  gty_FINAL,

    WA_HRP1002 TYPE GTY_HRP1002,

    WA_HRP9305 TYPE GTY_HRP9305,

    WA_FINAL TYPE GTY_FINAL.

*ranges: r_objid for HROBJID.

IF I_INITFLAG = SBIWA_C_FLAG_ON.

  APPEND LINES OF I_T_SELECT TO S_S_IF-T_SELECT.

*Fill parameter buffer for data extraction calls

  S_S_IF-REQUNR = I_REQUNR.

  S_S_IF-DSOURCE = I_DSOURCE.

  S_S_IF-MAXSIZE = I_MAXSIZE.

  APPEND LINES OF I_T_FIELDS TO S_S_IF-T_FIELDS.

  1. ELSE.

  IF S_COUNTER_DATAPAKID = 0.

    LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = ‘OBJID’.

      MOVE-CORRESPONDING L_S_SELECT TO g_r_OBJID.

      APPEND g_r_OBJID.

    ENDLOOP.

    OPEN CURSOR WITH HOLD S_CURSOR1 FOR

    select OTYPE OBJID from HRP1000 WHERE OBJID IN G_R_OBJID.

  ENDIF.

  FETCH NEXT CURSOR S_CURSOR1

      APPENDING CORRESPONDING FIELDS

              OF TABLE GT_HRP1000 PACKAGE SIZE S_S_IF-MAXSIZE.

  IF SY-SUBRC <> 0.

    CLOSE CURSOR: S_CURSOR1. “S_CURSOR2, S_CURSOR3.

    RAISE NO_MORE_DATA.

  ELSEIF GT_HRP1000 IS NOT INITIAL.

    SORT GT_HRP1000 by OTYPE OBJID.

    delete ADJACENT DUPLICATES FROM gt_hrp1000.

    select OTYPE OBJID OTJID from HRP1002 INTO TABLE GT_HRP1002

        FOR ALL ENTRIES IN GT_HRP1000

         WHERE OTYPE = GT_HRP1000-OTYPE AND OBJID = GT_HRP1000-OBJID.

      IF GT_HRP1002 IS NOT INITIAL.

        delete ADJACENT DUPLICATES FROM gt_hrp1002.

        select OTYPE OBJID FOREMPLOYE from HRP9305 INTO TABLE GT_HRP9305

          FOR ALL ENTRIES IN GT_HRP1002

                 WHERE OTYPE = GT_HRP1002-OTYPE AND OBJID = GT_HRP1002-OBJID.

        IF SY-SUBRC = 0.

          LOOP AT GT_HRP9305 INTO WA_HRP9305.

            READ TABLE GT_HRP1002 INTO WA_HRP1002 WITH KEY

                            OTYPE = WA_HRP9305-OTYPE

                            OBJID = WA_HRP9305-OBJID.

            IF SY-SUBRC = 0.

              WA_FINAL-OTYPE = WA_HRP1002-OTYPE.

              WA_FINAL-OBJID = WA_HRP1002-OBJID.

              WA_FINAL-OTJID = WA_HRP1002-OTJID.

              WA_FINAL-FOREMPLOYE = WA_HRP9305-FOREMPLOYE.

              APPEND WA_FINAL TO GT_FINAL.

              SORT GT_FINAL.

              delete ADJACENT DUPLICATES FROM GT_FINAL.

              e_t_data[] = GT_FINAL.

              refresh GT_FINAL.

            ENDIF.

          ENDLOOP.

        ENDIF.

      ENDIF.

  ENDIF.

  S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.

  1. ENDIF.
  1. ENDFUNCTION.

Now create Generic DataSource in RSO2 with function module extractor. As we are going to extract training related data, ‘LSO’ is taken as application Component.

Pic4.png

Check OTYPE and OBJID as selection variables for extraction.

Pic5.png

After DataSource creation, it has to be activated in RSA6 as shown below.

Pic6.png

Now datasource is ready for extraction. This can be tested in RSA3.

The next step is to integrate this BW Datasource with TREX. This datasource does the extraction for TREX having custom logic. So, we can implement any logic with respect to our requirement.

Now, we have to create a Software Component in TREX for our development assign our custom Template to it.

Go to ESH_MODELER and Software Component.

Pic7.png

Pic8.png

Now create Template Modeler by choosing “Create” button by Choosing SW Component ZSWC_HR_TEST1.

Pic9.png

Now ZTEMPLT_TRAINING2 is the Template Modeler created and there are several steps to prepare our TREX selection parameters and output settings, parameters.

In the Template Modeler edit screen, choose ‘Business Template’ in the first step. In the second step

Select “Based on BW DataSource” checkbox.

Create node to declare our field structure by clicking on “Create Node” and give DataSource name ZTEST_TRAINING1 which we created previously. Now click on ENTER to reflect DataSource description and Node values. We can see the extract structure fields reflected in the lower sub-screen.

Pic10.png

We don’t need to populate anything in “Define Structure” and “Define Analytical Settings”. In “Define Search Settings” step, declare attributes (fields) to be displayed in the TREX Search results. Here fields which have to be displayed in the basic search results and interactive screen can be selected.

Now, click on “Add” button and select “Attribute/Groups from Node” as to declare fields wise. If we have already created a group of fields, we can directly give that group here so that we don’t need to take field by field. But here as we have very less fields we have not created any group.

Pic11.png

A pop-up appears to select fields to be declared in this step. As we require all fields in this scenario, all fields are selected.

As shown below, respective parameters have to be set for each field.

Eg: “Title” displays OTYPE info in the title of the search results. “Summary” displays OTYPE value in the initial screen of search results. “Details” displays OTYPE values in interactive detailed information for selected record.

Pic12.png

In our case, OTYPE and OBJID are selected for Summary and OTYPE, OBJID, OTJID and FOREMPLOYE are selected for Details screen.

“Save” actions in each step of this configuration.

“Define Search Requests” step is to create selection criteria for TREX search. As shown below, select ZSR_TEST1 Search request as “Default request”.

Pic13.png

Next select fields required to be put in the selection-screen from “Add” button. This time, only PERNR is taken for selection-screen.

Pic14.png

Now Save and click on Finish.

In the Template Modeler screen, select our template ZTEMPLT_TRAINING2, click on “Actions”-> “Create Connector” to create Connector.

Pic15.png

Connected will be created in the background.

Pic16.png

To see the Connector, go to transaction ESH_COCKPIT. The initial status of Connector for ZTEMPLT_TRAINING2 template shows as “Prepared”. 

We need to perform indexing to make data ready from TREX extraction. Indexing eases data ready for TREX extraction. Click on Actions->Schedule Indexing

Pic17.png

Select “Start Immediate” and Ok.

Pic18.png

Now the status changes to “Scheduled for Indexing”. Now indexing runs in the background.

Pic19.png

Once Indexing is completed, the status changes to “Active” once you REFRESH it. Now, ZTEMPLT_TRAINING2 Template Modeler is ready for search.

Pic20.png

Now, to start search, go to transaction ESH_SEARCH. It gives list of all Template Modelers ready for search. Select our ZTEMPLT_TRAINING2 (Test-2) template modeler.

Once we add it in our favorites, it appears in the drop-down list as well (In Advance Search option).

Pic21.png

Pic22.png

We get the below selection-screen with OTYPE and OBJID selections.

Pic23.png

Now select the values from search-help.

Pic24.png

Pic25.png

Now click on “Search” button to get the results. This basic list displays OTYPE and OBJID only as we selected in Template Modeler configuration.

Pic26.png

“Details” button gives us interactive report as defined in Template Modeler configuration.

Pic27.png

The results are displayed as configured.

Thank you,

Vijay Suman

Accenture Services Pvt Ltd.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply