zoukankan      html  css  js  c++  java
  • Generating Custom Hierarchies in SAP BI BW using Custom DataSource

     

    Summary

    Standard Business Content extractors support main hierarchies but it does not support all the hierarchies. SAP does not provide a standard DataSource to extract Employee-Supervisor Hierarchies to BW. This article explains the procedure of how to generate custom Employee-Supervisor hierarchy in SAP BI / BW for HR Module (SAP Business Warehouse).

     

    Author: Raj Kumar Rai 

     

    Company: Cognizant Technology Solutions

     

    Created on:  19th Sept 2012

     

    Table of Contents

    1. Introduction
    2. Scenario
    3. Enhancing 0EMPLOYEE to bring supervisor information
      1. Code to bring supervisor / super-supervisor information
    4. Storing Employee-Supervisor information in a DSO
      1. DTP Filters
    5. Custom Hierarchies – Steps & Workaround
      1. DSO Containing Hierarchy Data
      2. InfoObject for activating hierarchy
      3. Activating hierarchy by creating a dummy node
      4. Generating Export DataSource
      5. Creating an InfoPackage
      6. Enhancing the Export DataSource
      7. Code to enhance the hierarchy DataSource
      8. Loading the Hierarchy and structure generated

     

     

    Introduction

    Standard Business Content extractors support main hierarchies but it does not support all the hierarchies. SAP does not provide a standard DataSource to extract Employee-Supervisor Hierarchies from ECC to BW. This becomes even more complicated when this hierarchy is not existent at ECC side & you have to generate the hierarchical structure of all the employees in an organization at BW side. This article explains the procedure of how to generate custom Employee-Supervisor hierarchy in SAP BI / BW (SAP Business Warehouse).

     

    Scenario

    For a reporting requirement we need all the employees and its supervisor information in a hierarchical structure. InfoObject 0employee is a master data object with all the employee related information present in its master data table. But the twist was that those employees who do not have any active immediate supervisor, should be assigned to their respective super-supervisors (supervisor of supervisor). Let’s take a simple example to understand the relation –

     

    1. P - Employee Id
    2. S - Position in an Organization

     

    1. P1 - S1: Every employee (P1) assigned to a position (S1)
    2. S1 - S2: Every position (S1) would have a reporting parent position (S2)
    3. S2 - P2: Every parent position (S2) will have an active employee (P2) assigned to it, which in turn would be the supervisor (P2) for employee (P1)

     

    Case1: There is no valid employee (P2) assigned to position (S2), we need to find the super supervisor with following logic:

     

    1. S2 - P2: No active employee (P2)
    2. S2 - S3: super supervisor position (S3) of supervisor position (S2)
    3. S3 - P3: P3 is the active super supervisor assigned to super supervisor position S3

    Above steps are to be repeated as many times until we get an active employee (P) assigned to the supervisor position (S).

     

     

    Important HR relations to be noted:

    HRP1001 is standard sap HR table which have diff Sub Types connecting OBJID & SOBID fields signifying different relations. Few important relations we would require are explained below -

    SUB Type -     Relation

         A002      –   Reports To    

         A004      –   Is Sub-Ordinate To

         A008      –   Holder

         B005      –   Is Supervisor Of

     

     

    Now we have employee supervisor relation data in place. But to create the hierarchy structure we require the employee-supervisor information in a specific format which requires following information for each entry.

    1. Node Id
    2. Node Name
    3. Infoobject Name
    4. TLevel
    5. Parent Id

     

    So this is what we intend to achieve and understand by the detailed steps in this document.

     

    Enhancing 0EMPLOYEE to bring supervisor information:

      Go to transaction RSA2 in ECC side. Enter the datasource name and click Display.

     

    a1.png

     

    Go to extraction tab and double click the extract structure

     

    a2.png

     

    Click on append structure option and add the new InfoObjectZZXXXXXX to the extract structure

     

    a3.png

     

    Go to transaction CMOD in R/3 side and enhance the extractor 0employee_attr for filling the ZZXXXXXX field which was a custom field added to the original extract structure.

     

    a4.png

     

    Enhance the code for 0employee_attr in the above highlighted SAP Exit

     

     

    Code to bring supervisor / super-supervisor information

     

    TYPES:BEGIN OF s_pa0001, pernr TYPE pa0001-pernr, plans TYPE pa0001-plans, begda TYPE pa0001-begda, endda TYPE pa0001-endda, END OF s_pa0001.

     

    DATA: l_s_hrms_biw_io_occupancyLIKE hrms_biw_io_occupancy.

     

    DATA: it_pa0001TYPE STANDARD TABLE OF s_pa0001.

    DATA: lit_lead_posTYPE STANDARD TABLE OF hrobject, lwa_lead_pos TYPE hrobject.
    DATA: var_posTYPE hrp1001-sobid.
    REFRESH lit_lead_pos[].

      SELECT pernr plans begda enddaFROM pa0001INTO TABLE it_pa0001 WHERE begda <= sy-datum AND endda >= sy-datum.
    IF sy-subrcEQ 0. SORT it_pa0001BY pernr plans. DELETE ADJACENT DUPLICATES FROM it_pa0001COMPARING ALL FIELDS. ENDIF.

    var_pos = l_s_hrms_biw_io_occupancy-plans.
    CALL FUNCTION 'RH_GET_LEADING_POSITION'EXPORTING plvar             = '01' otype             = 'S' sobid             = var_pos date              = sy-datum auth              = 'X' buffer_mode       = ' ' consider_vac_pos  = ' 'TABLES leading_pos       = lit_lead_pos EXCEPTIONS no_lead_pos_found = 1OTHERS            =2.
    IF sy-subrcEQ 0. CLEAR: lwa_lead_pos.
    READ TABLE lit_lead_posINTO lwa_lead_posINDEX 1.
    READ TABLE it_pa0001ASSIGNING <fs_pa0001>WITH KEY plans = lwa_lead_pos-objid.
    IF sy-subrcEQ 0.
    l_s_hrms_biw_io_occupancy-zzxxxxxx = <fs_pa0001>-pernr. *      S
    tart of code for calculating super supervisor (Raj Kumar Rai), Infosys Pune          

        ELSE.   " This portion of code executes when there is no active supervior for sup pos v_flag = 0.
    WHILE ( v_flag =0 ).
    CLEAR var_pos. CLEAR lit_lead_pos. var_pos = lwa_lead_pos-objid.
    CALL FUNCTION 'RH_GET_LEADING_POSITION'EXPORTING plvar             = '01' otype             = 'S' sobid             = var_pos date              = sy-datum auth              = 'X' buffer_mode       = ' ' consider_vac_pos  = ' 'TABLES leading_pos       = lit_lead_pos EXCEPTIONS no_lead_pos_found = 1OTHERS            =2.
    IF sy-subrcEQ 0. CLEAR: lwa_lead_pos.
    READ TABLE lit_lead_posINTO lwa_lead_posINDEX 1.
    READ TABLE it_pa0001ASSIGNING <fs_pa0001>WITH KEY plans = lwa_lead_pos-objid.
    IF sy-subrcEQ 0.
    l_s_hrms_biw_io_occupancy-zzxxxxxx = <fs_pa0001>-pernr. v_flag =
    1. " Setting flag to 1 in case there exist an active supervisor for supervisor position.
    ENDIF.
    ELSE. EXIT.
    ENDIF.
    ENDWHILE.

              ENDIF.

          ENDIF.

     

     

     

    Function ModuleRH_GET_LEADING_POSITION is used to arrive to position of supervisor.

     

    1. FM RH_GET_LEADING_POSITION takes position of an employee as input (import parameter).
    2. Table lit_lead_pos is filled with supervisor positionafter completion of this FM.
    3. Supervisor position returned by this standard FM is then used to calculate supervisor employee id from PA0001 table.

     

     

    Storing Employee-Supervisor information in a DSO

    Creating hierarchy structure was a challenging requirement, so we decided to have the most critical Employee-Supervisor information in a write-optimized DSO. This was required to facilitate the dynamic access of this WDSO to create Supervisor hierarchy structure rather than focusing on establishing employee-supervisor relation at run time.

     

    a5.png

     

    In WDSO we needed Employee & Supervisor information. Since Supervisor is a time dependent attribute of 0employee master data so VALIDFROM & VALIDTO dates becomes critical and was thus included in the WDSO.

     

    Direct mapping was done between Attribute of 0employee and WDSO ZWDSO08.

     

    a6.png

     

    DTP Filters

    Employment Status and Employee Group are two important attributes in term of reducing the no of records loaded to DSO ZWDSO08.

    1.     Employee Group = 5 signifies retired employees & they could be excluded to reduce the record count to this DSO.

     

    2.     Employment Status = 1(inactive) & 3(active) employees. We can restrict Employment Status to either 1 or 2, as these are the two employment status we         are interested in.

     

    3.     VALIFROM <= sy-datum

           A dynamic DTP filter routine is written to implement this.

     

    4.     VALIDTO >= sy-datum

           A dynamic DTP filter routine is written to implement this.

     

     

    a7.png

     

    Now we have employee-supervisor information in active table of a DSO and we can utilize it to establish the hierarchy structure.

     

    Custom Hierarchies – Steps & Workaround

    When you have to load non-standard SAP hierarchies or hierarchies from other source systems, you come across certain bottlenecks. As a standard practice SAP BW only allows standard hierarchy datasource or flat file based hierarchy datasources. To load any kind of hierarchy we require a datasource of type hierarchy to insert data into a desired Infoobject hierarchy table. So to conclude we do not have a standard way to load custom hierarchy from a source system. Next few steps are work around this problem to create and load custom hierarchies.

     

    DSO Containing Hierarchy Data

    In the initial stages we already learnt that how we are enhancing the 0employee extractor to bring the additional employee-supervisor information and storing it in a DSO ZWDSO08 for deriving the hierarchy structure. For a similar requirement you can use a master or transaction datasource and get data in a DSO of your choice. Data can be loaded to this DSO from a simple flat file as well.

     

     

    a8.png

     

    A dummy data set to show the kind of data this DSO ZWDSO08 holds

     

    a9.png

     

    InfoObject for activating hierarchy

     

    a10.png

     

     

    Properties of this InfoObject needs to be edited to suit for this particular requirement. Check for following settings:-

    • Maintain the InfoObject as an ‘InfoSource with Direct Update'.
    • Choose an application component after enabling corresponding check box.
    • Mark the InfoObject as an InfoProvider and assign it to an InfoArea. Now the InfoObject would be visible in InfoProvider tree in Data Warehousing Workbench.
    • Enable the InfoObject as an export data source. This allows the extraction of the InfoObject data using data mart interface.
    • Check the hierarchy’s check box to specify that InfoObject contains hierarchies.

     

     

    a11.png

     

    Activating hierarchy by creating a dummy node

    InfoObject settings are correctly maintained and activated. To activate the hierarchy we need to create a dummy hierarchy node which would be the first step towards generating custom hierarchy. Creation of dummy node would have to be done only once manually.

     

    Right Click on the hierarchies and choose the Maintain Hierarchy option

     

    a12.png

     

    Click on create button to create a dummy hierarchy with requisite description.

     

    a13.png

     

     

    Create a simple text node by choosing text node out of available options at the top.

     

    a14.png

     

    A dummy hierarchy is created and it looks like this

     

    a15.png

     

    Generating Export DataSource

    Next step is to generate an export datasource for this InfoObject. Go to the ‘Data Warehousing Workbench' – RSA1 and right-click on the InfoObject. In the menu, choose ‘Additional Functions'à ‘Generate Export DataSource' option.

     

    An export datasource typically gets a technical name‘8<InfoObject Name><H, T, M>’ depending on whether the datasource is generated for hierarchy, Text or Attribute. This new export datasource can be found in application componentData Marts Master Data (DM-IO), after we choose source system as BW and replicate this application component. In case the above application component is not active this DataSource would by default go to‘Unassigned Nodes’.

     

    Now we have a hierarchy DataSource and we can link it to the InfoObject hierarchy via transfer rules. Hierarchy datasources are not yet supported in SAP BW 7.0 version and therefore we still need to use a SAP BW 3.5 datasource and transfer rules to build the connection. To create transfer rules, right-click on the hierarchy and use the context menu to go to ‘Additional Functions'à ‘Create transfer rules'. Select the correct source system (SAP BI i.e. BW in this case and not ECC) & choose the Export DataSource we created from the list displayed. The transfer rules are generated and they link the Export DataSource and the InfoObject hierarchy named Employee-Supervisor.

     

     

    Creating an InfoPackage

      Create a new InfoPackage for the hierarchy datasource by right-clicking on the datasource and selecting ‘Create InfoPackage' option. Refresh the ‘available hierarchies from OLTP'. This will load all hierarchies that are available in the source. As we only created a dummy hierarchy, this will be the only hierarchy we can extract. Select this dummy hierarchy and save the InfoPackage

     

    a16.png

     

    Enhancing the Export DataSource

      Till now we have built a data flow that allows the extraction of a dummy hierarchy into a new hierarchy. Now we still need to insert the hierarchy data that is currently residing in the DSO ZWDSO08. This can be done in a user exit, an enhancement of the generated hierarchy datasource.

     

    a17.png

     

    Go to transaction CMOD, give your project name and choose the‘Components’ radio button and click on Display

     

    a18.png

     

    Hierarchy datasources can be enhanced like any other type of datasource. Enhancement "RSAP0001 - Customer function calls in the service API” is called automatically during extraction. We have different exits for Transaction, Master & Text, Hierarchies.

    • EXIT_SAPLRSAP_001: Transactional data
    • EXIT_SAPLRSAP_002: Master data attributes or texts
    • EXIT_SAPLRSAP_004: Hierarchies

     

    If enhancement RSAP0001 is not yet active in your system, it can be activated and assigned to a project.

     

    a19.png

     

    The function module ‘EXIT_SAPLRSAP_004' is called every time a hierarchy datasource is executed. This function module contains an include  ‘ZXRSAU04'. This include can be enhanced using ABAP code to fetch the data from the DSO we loaded earlier. The most important table in this exit is table C_T_HIENODE which should be filled with the actual hierarchy data. Do not forget to refresh the C_T_HIENODE before inserting any data to delete the text node created for activating the Hierarchy.

     

    Assumptions:

    • An employee with neither a parent nor a child shall be put under Unassigned Nodes.

     

    • An employee with no immediate supervisor active on immediate supervisor position, the super supervisor be assigned as its parent.

     

     

     

     

     

    Code to enhance the hierarchy DataSource:

     

    *&---------------------------------------------------------------------**&  Include           ZXRSAU04*&---------------------------------------------------------------------*
    * Global variable declaration

    data: wa_hienodeTYPE ROSHIENODE. data : it_emp_superTYPE STANDARD TABLE OF /BIC/AZWDSO0800,"table to select nodes it_temp TYPE STANDARDTABLE OF /BIC/AZWDSO0800," table to select child it_emp_unassg TYPE STANDARDTABLE OF /BIC/AZWDSO0800, wa_emp_super TYPE /BIC/AZWDSO0800 , v_count TYPE n LENGTH8 VALUE 1 , v_level TYPE n LENGTH8 VALUE 1 , v_flag type n LENGTH1 VALUE 1.
    FIELD-SYMBOLS : < fs_emp_super> TYPE /BIC/AZWDSO0800 .
    CASE i_datasource.
    WHEN '80EMPLOYEEH'.

    REFRESH c_t_hienode.
    "Select all level 1 nodesselect *from /BIC/AZWDSO0800 into table it_emp_super where /bic/zsupvsr = '  'or /bic/zsupvsr = 0.
    "Select all level 1 node who have at least 1 childselect *from /BIC/AZWDSO0800 into table it_emp_unassg where /bic/zsupvsr IN ( select EMPLOYEEfrom /BIC/AZWDSO0800 where /bic/zsupvsr = '  'or /bic/zsupvsr = 0 ).
    "Appending UNASSIGNED NODE wa_hienode-nodename = 'UNASSIGN' . wa_hienode-nodeid = 99999999. wa_hienode-iobjnm = '0EMPLOYEE'. wa_hienode-tlevel = v_level. wa_hienode-parentid =  '  ' .

    append wa_hienodeto c_t_hienode . v_count = v_count + 1 . clear : wa_hienode .
    " For level 1 Nodes & Nodes with no child or parent

    LOOP at it_emp_superinto wa_emp_super.
    wa_hienode-nodename = wa_emp_super-employee . wa_hienode-nodeid = wa_emp_super-employee. wa_hienode-iobjnm =
    '0EMPLOYEE'. wa_hienode-tlevel = v_level. wa_hienode-parentid =  '  ' .
    read table it_emp_unassgassigning <fs_emp_super> with key /bic/zsupvsr = wa_emp_super-employee.
    if sy-subrc <>0.       "If NO CHILD NODE       wa_hienode-tlevel = 2 .       wa_hienode-parentid = 99999999. endif.

    append wa_hienodeto c_t_hienode . v_count = v_count + 1 . clear : wa_hienode .
    ENDLOOP.
    R
    efresh : it_emp_unassg .
    W
    hile ( v_flagne 0 ).
         
    refresh : it_temp .       select *from /BIC/AZWDSO0800       into table it_temp       for all entriesin it_emp_super       where /bic/zsupvsr =  it_emp_super-employee  .
          I
    f sy-subrc =0.            v_level = v_level + 1.            refresh : it_emp_super .            it_emp_super[] = it_temp[] .
               L
    oop at it_emp_superinto wa_emp_super.
               wa_hienode-nodename = wa_emp_super-employee .            wa_hienode-nodeid = wa_emp_super-employee.            wa_hienode-iobjnm =
    '0EMPLOYEE'.            wa_hienode-tlevel = v_level.            wa_hienode-parentid = wa_emp_super-/bic/zsupvsr .            append wa_hienodeto c_t_hienode .            v_count = v_count + 1 .            clear : wa_hienode .
               E
    ndloop.       Else.

          v_flag = 0.

          Endif.
    E
    ndwhile.
    ENDCASE.

     

     

    Loading the Hierarchy and structure generated

     

    a20.png

     

    Once the InfoPackage completes successfully following hierarchy tree structure would be generated

     

    a21.png

    http://blog.csdn.net/you_tube/article/details/8463904

  • 相关阅读:
    【LuoguP4156】论战捆竹竿
    各种需要背记的图论知识
    SSD:TensorFlow中的单次多重检测器
    YOLO: 3 步实时目标检测安装运行教程 [你看那条狗,好像一条狗!]
    Tensorflow 基于分层注意网络的文件分类器
    StarSpace是用于高效学习实体向量的通用神经模型
    vrn:基于直接体积回归的单幅图像大姿态三维人脸重建
    TensorFlow官方文档
    Machine Learning From Scratch-从头开始机器学习
    Awesome-Text-Classification:文本分类资源合集
  • 原文地址:https://www.cnblogs.com/hanmos/p/2943991.html
Copyright © 2011-2022 走看看