Skip to Content

Recently we had a requirement of creating the organizational unit hierarchy using Webdynpro abap .  While navigating through SDN i found this post and  Amy King has clearly articulated the way org unit hierarchy can be build in Webdynpro keeping in mind the way SAP has built using the search help HRBAS00OBJID2 . I followed the post and it worked wonders !!

But it can lead to performance problem due to deep org unit hierarchy as the search help or Function module RH_STRUC_GET basically gets list of the all org unit at one execution and builds the hierarchy.

In this blog I am going to discuss ( steps for Webdynpro abap are not detailed out ) on how alternatively we can use of table ui element and create a org unit hierarchy without using function module RH_STRUC_GET . The code constructs a tree like structure and only when the leaf is opened it fetches the rest of org unit below the selected org unit.


  • Created a Function Module Z_GETORGUNIT with below details
Parameter Type Associated type Default Value /Description
ORG_UNIT Import HROBJID Org Unit

BEGDA

Import DATUM SY-DATUM ( begin Date )
ENDDA Import DATUM SY-DATUM ( End Date )
ORG_LIST Tables

ORG_ID – HROBJID

ORG_NAME – STEXT

NO_SUB_ORGS – FLAG

List of org unit below , with a flag whether

it has any below

org unit or not

Sample code listed below

DATA it_hrp1001 LIKE hrp1001 OCCURS 0 WITH HEADER LINE.
DATA : temp_org LIKE hrp1001-sobid .
SELECT * FROM hrp1001 INTO it_hrp1001
                                            WHERE plvar = '01'
                                                 AND otype = 'O'
                                                 AND objid = org_unit
                                                 AND rsign = 'B'
                                                 AND relat = '002'
                                                 AND sclas = 'O'
                                                 AND begda <= begda
                                                 AND endda >= endda.
     org_list-org_id = it_hrp1001-sobid.
     SELECT SINGLE stext FROM hrp1000 INTO tstext WHERE plvar = '01'
                                              AND objid = it_hrp1001-sobid
                                              AND otype = 'O'
                                              AND begda <= begda
                                              AND endda >= endda.
     org_list-org_name = tstext.
     SELECT SINGLE sobid FROM hrp1001 into temp_org WHERE plvar = '01'
                                               AND otype = 'O'
                                               AND objid = it_hrp1001-sobid
                                               AND rsign = 'B'
                                               AND relat = '002'
                                               AND sclas = 'O'
                                               AND begda <= begda
                                               AND endda >= endda.
     IF sy-subrc <> 0.
       org_list-no_sub_orgs = 'X'.
     ENDIF.
     APPEND org_list.
    clear org_list .
ENDSELECT.

  • In the webdynpro abap component create node ( as shown below ) , with cardinality 0…n and Selection 0…n

Node.GIF  

  • Insert a table in the view layout with two columns with cell editor as
    • text View
    • A row arrangement with a link to action as the cell editor
    • Mapping details :
      • Table Data Source : Mn_ORG
      • RowArrangement (TreeByNestingTableColumn) CHILDRENLOADED : Mn_ORG-CHILDREN_LOADED (WDY_BOOLEAN)
      • RowArrangement EXPANDED : Mn_ORG-IS_EXPANDED (WDY_BOOLEAN)
      • RowArrangement isLeaf : Mn_ORG-IS_LEAF (WDY_BOOLEAN)
      • RowArrangement , Link to Action , on Events onLoadChildren create action LoadOrgunit
  • Details of LoadOrgUnit

OrgUnit.GIF

DATA element  TYPE REF TO if_wd_context_element.
  DATA context_node TYPE REF TO if_wd_context_node.
  DATA orgunit_entry TYPE wd_this->element_mn_org.
  DATA lv_org TYPE hrobjid.
  DATA lv_table_row TYPE integer.
  lv_table_row = 0.
* Get Element whose children shall be loaded
  element = wd_context->path_get_element( path ).
* Set Children loaded for this tree node
  element->set_attribute( EXPORTING name = 'CHILDREN_LOADED'
                                    value = abap_true ).
  element->get_attribute( EXPORTING name = 'ORG_ID'
                        IMPORTING value = lv_org ).
* Get children node
  context_node = element->get_child_node( 'MN_ORG_CHAIN' ).
  DATA: sub_org_tb TYPE TABLE OF ORG_LIST,
        ls_sub_org_tb TYPE ORG_LIST.
  CALL FUNCTION  'Z_GETORGUNITS'
    EXPORTING
      in_org   = lv_org
      begda    = sy-datum
      endda    = sy-datum
    TABLES
      sub_orgs = sub_org_tb.
  LOOP AT sub_org_tb INTO ls_sub_org_tb.
    lv_table_row = lv_table_row + 1.
    orgunit_entry-org_id = ls_sub_org_tb-org_id.
    orgunit_entry-org_name = ls_sub_org_tb-org_name .
    IF ls_sub_org_tb-no_sub_orgs EQ 'X'.
      orgunit_entry-is_expanded = abap_false.
      orgunit_entry-is_leaf = abap_true.
    ELSE.
      orgunit_entry-is_expanded = abap_false.
      orgunit_entry-is_leaf = abap_false.
    ENDIF.
    context_node->bind_structure( new_item = orgunit_entry
                                set_initial_elements = abap_false ).
  ENDLOOP.
  wd_this->table_count = wd_this->table_count + lv_table_row .
* set single attribute
  wd_context->set_attribute(
    name =  `VA_TABLE_ROW`
    value = wd_this->table_count

Done , activate and execute the application will render the org unit hierarchy .

Note : Do not customize unless it is required , always tend to use the standard provided by SAP . Comments and feedback are welcome.

To report this post you need to login first.

2 Comments

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

  1. Egor Malov

    Pankaj,

    I would like to note that RH_STRUC_GET doesn’t nesessarily read all the structure. There is an importing parameter that allows to limit the depth. Also, another evaluation path might do the trick.

    I tried to find an example of a good usage of this FM in the standard code behind HRBAS00OBJID2. Surprisingly, this FM is not used there. Some similar FMs are used. Probably they are even more appropriate for the task.

    (0) 
    1. Former Member Post author

      Hello Egor,

      Thanks for the comment , true FM RH_STRUC_GET with import parameter tdepth  = 1  can do the trick .

      In the post i was just trying to explore various option which we can have to perform the same task using webdynpro abap.

      Appreciate your note.

      Regards

      Pankaj Prasoon

      (0) 

Leave a Reply