Академический Документы
Профессиональный Документы
Культура Документы
Applies to:
This Article applies to Web Dynpro ABAP, ABAP HR, and Enterprise Portal 7.0.
Summary
This document describes about how to use the Tree UI element with recursive node by addressing a Real time Business Scenario in which the Organization Structure is displayed in a tree format with expanding and collapsing nodes (Organization Units and Sub Organization Units) and the employees under selected in Organization/Sub Organization Unit in Table of Web Dynpro for ABAP View. Author: Jhansi Rani Miryala
th
Author Bio
Jhansi Rani Miryala is working as EP Consultant in Intelligroup. She has experience of working on Web Dynpro Java, Web Dynpro ABAP, EP, Adobe Print/Interactive Forms and PDK (Portal Development Kit). She has completed her Master of Computer Applications.
Table of Contents
Introduction ......................................................................................................................................................... 3 Scenario .............................................................................................................................................................. 3 Procedure ........................................................................................................................................................... 3 Steps to create a dynamically structured Recursive Tree Web Dynpro Application ...................................... 3
1) Create the Web Dynpro Component ........................................................................................................................ 3 2) Create the context in the view .................................................................................................................................. 4 3) Define the Supply function(s) ................................................................................................................................... 6
Sample Output: ................................................................................................................................................. 25 Related Content ................................................................................................................................................ 26 Disclaimer and Liability Notice .......................................................................................................................... 27
Introduction
This article explains about the necessary steps to build a simple recursive tree structure with TREE UI element available in Web Dynpro ABAP. Tree UI element will be useful if you want to display the data in some hierarchy format. The hierarchy to be displayed is defined in the context in 2 ways: 1) Recursive Node: Number of elements is not known at design time 2) Non-recursive Node: Certain number of levels can be specified at design time The Tree UI element is bound against the top-level context node to be displayed and TreeNodeType and TreeItemType are used to specify which sub nodes under the tree to be displayed. TreeItemType elements cannot have children; therefore, they are always displayed as leaves. It is used if we know at design time that the corresponding node does not have children. When using TreeNodeType elements, the decision of whether to use children is dynamically made at runtime. I have considered the Organization Units hierarchy which people may come across at different scenarios with HR based applications in Web Dynpro ABAP with SAP HCM implementation. I thought of sharing this with the community through this article. So, I would like to present the Dynamic Organization Unit Structure in tree format with Organizational Units and corresponding Sub Organization Units of the logged in user, by capturing the data for the tree from ABAP HR. I used the tree element with the recursive node option to attain the organization hierarchy structure. The Organization Units and Sub Organization units are dynamic; that is, it depends on the user who logged into the portal/SAP. To enable this I have provided an Organization Tree structure with expanding and collapsing nodes by providing the facility to display the employees in a table format for selected Org Unit.
Scenario
Organization Structure is shown as Tree and whenever the user selects the Organization/Sub Organization Unit then corresponding employees are displayed in table format. The Tree data is dynamically populated at run time depending on logged in user.
Procedure
Steps to create a dynamically structured Recursive Tree Web Dynpro Application 1) Create the Web Dynpro Component Go to the transaction SE80 and choose Web Dynpro Comp. / Intf. In the list, give a name and press Enter.
Youd be asked to enter the description. Enter the description and press enter.
2) Create the context in the view Go to the WDC (Web Dynpro Component) you just created and add the context to the view MAIN as mentioned below.
The context I have used in this example is: Context Node ND_TREE ORGUNITS ORGEH STEXT SUB_ORGS ORGEH STEXT ORGEH STEXT Recursive SUB_ORGS_R EMPS NAME POSITION LOCATION PERNR PAD_CNAME HRP1000STEXT T500PNAME1 PERSNO EMPS EMPS EMPS EMPS Node SUB_ORGS 0..n 0..n No No SUB_ORGS ORGEH STEXT Parent Node Rootnode ND_TREE ORGUNITS ORGUNITS ORGUNITS SUB_ORGS SUB_ORGS 0..n 0..1 No No Initialization Lead Selection Yes No Repeat Node
Attribute
Type
Singleton No No
Note: 1) Node SUB_ORGS_R is the recursive node, which will be used to store the sub organization units. 2) All nodes that are not directly below the context root node must be non-singleton nodes, because all elements should be displayed in a tree regardless of the lead selection.
Now we define the methods to process and code to retrieve the Organization Units and Sub Organization Units. 3) Define the Supply function(s) Define a Supply Function S_ORGUNITS on ORGUNITS node and S_SUB_ORGS on SUB_ORGS node. a) Define a Supply Function S_ORGUNITS on ORGUNITS node as shown below.
Note: To simplify this article I am showing the business logic in the Web Dynpro component.
Now go to the Methods tab of the view and write the following code in the supply function method S_ORGUNITS to get Organization Units of logged in user. Code Block - 1 METHOD s_orgunits . * TYPES declaration TYPES : BEGIN OF ty_orgunits, pernr TYPE persno, orgeh TYPE orgeh, END OF ty_orgunits. * DATA declaration DATA : lo_nd_tree_nd TYPE REF TO if_wd_context_node, lo_nd_orgunits TYPE REF TO if_wd_context_node, ls_org_units TYPE wd_this->element_orgunits, lt_org_units TYPE wd_this->elements_orgunits, lv_pernr TYPE persno, it_orgunits TYPE TABLE OF ty_orgunits. * Navigate to the <ND_TREE> node lo_nd_tree_nd = wd_context->path_get_node( path = 'ND_TREE' ). * Navigate to the <ORGUNITS> node lo_nd_orgunits = lo_nd_tree_nd->path_get_node( path = 'ORGUNITS' ). * Get PERNR based on userid CLEAR : lv_pernr. SELECT SINGLE pernr FROM pa0105 INTO lv_pernr WHERE subty = '0001' AND endda GE sy-datum AND begda LE sy-datum AND usrid EQ sy-uname. *Get Org Units for PERNR CLEAR: it_orgunits. SELECT pernr orgeh FROM pa0001 INTO TABLE it_orgunits WHERE pernr EQ lv_pernr AND sprps EQ space AND endda GE sy-datum AND begda LE sy-datum AND persg NE '6'. IF NOT it_orgunits IS INITIAL. DELETE ADJACENT DUPLICATES FROM it_orgunits COMPARING orgeh. *Get Org Units Texts for Org Units SELECT objid stext FROM hrp1000 INTO TABLE lt_org_units FOR ALL ENTRIES IN it_orgunits WHERE plvar = '01' AND otype = 'O' AND objid = it_orgunits-orgeh AND istat = '1' AND begda <= sy-datum AND endda >= sy-datum. ENDIF. * Bind the <LT_ORG_UNITS> to context node
lo_nd_orgunits->bind_table( lt_org_units ).
ENDMETHOD.
Now go to the Methods tab of the view and write the following code in the supply function method S_SUB_ORGS to get Sub Organization Units under the Org. Unit.
Code Block - 2 METHOD s_sub_orgs. * TYPES declaration TYPES: BEGIN OF ty_subids, objid TYPE hrobjid, sobid TYPE sobid, END OF ty_subids. * Data declaration DATA: suborg_node TYPE REF TO if_wd_context_node, lv_orgunit TYPE orgeh, lt_suborg_units TYPE wd_this->elements_sub_orgs, ls_suborg_units TYPE wd_this->element_sub_orgs, it_subids TYPE TABLE OF ty_subids, wa_subids TYPE ty_subids, wa_suborgs TYPE ty_subids, it_suborgs TYPE TABLE OF ty_subids. * Get Org Unit from parent node
parent_element->get_attribute(EXPORTING name = 'ORGEH' IMPORTING value = lv_orgunit). IF NOT lv_orgunit IS INITIAL.
* get suborgs SELECT objid sobid FROM hrp1001 INTO TABLE it_subids WHERE otype = 'O' AND objid = lv_orgunit AND plvar = '01' AND rsign = 'B' AND relat = '002' AND istat = '1' AND begda <= sy-datum AND endda >= sy-datum. * Pupulate the <SOBID> as <OBJID> IF NOT it_subids IS INITIAL. LOOP AT it_subids INTO wa_subids.
wa_suborgs-objid = wa_subids-sobid. APPEND wa_suborgs TO it_suborgs. CLEAR: wa_suborgs. ENDLOOP. ELSE. EXIT. ENDIF. IF NOT it_suborgs IS INITIAL.
*Get SubOrg Units Texts for SubOrg Units SELECT objid stext FROM hrp1000 INTO TABLE lt_suborg_units FOR ALL ENTRIES IN it_suborgs WHERE objid = it_suborgs-objid AND begda <= sy-datum AND endda >= sy-datum AND langu = sy-langu. ENDIF. ENDIF. * Bind the table to the node
node->bind_table( lt_suborg_units ).
ENDMETHOD.
4) Design the Layout a) In the view MAIN insert the UI element Tree by selecting an Insert Element from the context menu of ROOTUIELEMENTCONTAINER.
Now bind the dataSource to the node ND_TREE and give the required text to rootText property.
The screen shot below shows the bounded attributes dataSource, rootText highlighted.
b) After inserting the Tree UI element, a NodeType should be placed for the Tree UI element to display the entries. Select the Insert Node Type option from the context menu of the tree, which will be used to display the Organization Units.
Give some ID (Ex: ORGUNITS) and select the TreeNodeType from the Typ list.
After inserting the TreeNodeType bind the text property of TreeNodeType(Orgunits) to the context attribute STEXT under ORGUNITS node declared.
The screen shot below shows the bounded attribute text highlighted.
Now bind the dataSource of the NodeType(ORGUNITS) to the context node ORGUNITS.
c) Now insert one more NodeType under UI element named SUBORGS and bind its text to STEXT under SUB_ORGS node and its dataSource to SUB_ORGS node. It is used to display the Sub Organization Units.
d) After inserting the Tree UI element, create the table to display the employees under the selected Org Unit/Sub Org Unit. Bind the table to the context node EMPS as shown below.
5) Define the Actions for ORGUNITS TreeNodeType a) Define the Action to get the Employees under the selected Org Unit/Sub Org Unit. Create an action GET_ORG_EMPS on onAction of the ORGUNITS (TreeNodeType UI element) to get the employees under the selected Org. Unit.
Code Block 3 METHOD onactionget_org_emps . * Data declaration DATA: lo_nd_orgunit TYPE REF TO if_wd_context_node, lo_el_orgunit TYPE REF TO if_wd_context_element, ls_orgunit TYPE wd_this->element_orgunits, lo_nd_emps TYPE REF TO if_wd_context_node, lt_emp_list TYPE if_main=>elements_emps, lv_orgunit TYPE orgeh, lt_hrpernr TYPE TABLE OF hrpernr, lt_pa0002 TYPE TABLE OF pa0002, lt_pa0001 TYPE TABLE OF pa0001, lt_hrp1000 TYPE TABLE OF hrp1000, lt_t500p TYPE TABLE OF t500p, wa_emp_list LIKE LINE OF lt_emp_list, wa_hrpernr TYPE hrpernr, wa_pa0002 TYPE pa0002, wa_pa0001 TYPE pa0001, wa_hrp1000 TYPE hrp1000, wa_t500p TYPE t500p. CLEAR: lv_orgunit. * Navigate to ORGUNIT Node lo_nd_orgunit = wd_context->path_get_node( path = `ND_TREE.ORGUNITS` ). * Navigate to EMPS node
lo_nd_emps = wd_context->get_child_node( name = wd_this->wdctx_emps ).
* Get the Employees under Org Unit REFRESH : lt_hrpernr, lt_pa0002, lt_pa0001, lt_hrp1000, lt_t500p,lt_emp_list. IF NOT lv_orgunit IS INITIAL. * Get the <PERNR> for the given ORG Unit CALL FUNCTION 'HRCM_ORGUNIT_EMPLOYEE_LIST_GET' EXPORTING plvar = '01' otype = 'O'
objid begda endda = lv_orgunit = sy-datum = sy-datum = lt_hrpernr
TABLES
pernr_table
EXCEPTIONS
path_error = 1 root_error = 2 no_employees_found = 3 OTHERS = 4. IF NOT lt_hrpernr[] IS INITIAL.
Get the Names from PA0000 SELECT * FROM pa0002 INTO TABLE lt_pa0002 FOR ALL ENTRIES IN lt_hrpernr
WHERE pernr = lt_hrpernr-pernr AND endda GE sy-datum AND begda LE sy-datum. * Get the Position from PA0001 SELECT * FROM pa0001 INTO TABLE lt_pa0001 FOR ALL ENTRIES IN lt_hrpernr WHERE pernr = lt_hrpernr-pernr AND endda GE sy-datum AND begda LE sy-datum. IF lt_pa0001[] IS NOT INITIAL. **Get Position Text from HRP1000 SELECT * FROM hrp1000 INTO TABLE lt_hrp1000 FOR ALL ENTRIES IN lt_pa0001 WHERE plvar = '01' AND otype = 'S' AND objid = lt_pa0001-plans AND istat = '1' AND begda LE sy-datum AND endda GE sy-datum AND langu EQ sy-langu. SELECT * FROM t500p INTO TABLE lt_t500p FOR ALL ENTRIES IN lt_pa0001 WHERE persa = lt_pa0001-werks. ENDIF. ENDIF. ENDIF. LOOP AT lt_hrpernr INTO wa_hrpernr.
wa_emp_list-pernr = wa_hrpernr-pernr.
Prepare the Full Name READ TABLE lt_pa0002 INTO wa_pa0002 WITH KEY pernr = wa_hrpernr-pernr. IF sy-subrc = 0. CONCATENATE wa_pa0002-nachn wa_pa0002-vorna INTO wa_emp_list-name SEPARATED BY space. ENDIF. READ TABLE lt_pa0001 INTO wa_pa0001 WITH KEY pernr = wa_hrpernr-pernr.
IF sy-subrc = 0. *Position Title READ TABLE lt_hrp1000 INTO wa_hrp1000 WITH KEY objid = wa_pa0001-plans. IF sy-subrc = 0. wa_emp_list-position = wa_hrp1000-stext. ENDIF. *Work location READ TABLE lt_t500p INTO wa_t500p WITH KEY persa = wa_pa0001-werks. IF sy-subrc = 0.
wa_emp_list-location = wa_t500p-name1.
EXPORTING
new_items = lt_emp_list set_initial_elements = abap_true. ENDIF. ENDMETHOD.
6) Define the Actions for SUBORGS TreeNodeType a) Before creating an action for SUBORGS node, create an attribute ND_SUBORG_REF to store the reference to the SUB_ORGS context node as show below which is used to retain the reference for the dynamic recursive nodes. Otherwise we get the exception when we click on the sub organization for the second time.
b) Define the action GET_SUB_ORG_EMPS on onAction of the SUBORGS (TreeNodeType UI element) to get the employees under the selected Sub Org. Unit.
Write the following code on the action GET_SUB_ORG_EMPS. Code Block - 4 METHOD onactionget_sub_org_emps. * Data declaration DATA: lo_nd_suborg TYPE REF TO if_wd_context_node, lo_el_suborg TYPE REF TO if_wd_context_element, ls_suborg TYPE wd_this->element_orgunits, lo_nd_emps TYPE REF TO if_wd_context_node, lt_emp_list TYPE if_main=>elements_emps, lv_orgunit TYPE orgeh, lt_hrpernr TYPE TABLE OF hrpernr, lt_pa0002 TYPE TABLE OF pa0002, lt_pa0001 TYPE TABLE OF pa0001, lt_hrp1000 TYPE TABLE OF hrp1000, lt_t500p TYPE TABLE OF t500p, wa_emp_list LIKE LINE OF lt_emp_list, wa_hrpernr TYPE hrpernr, wa_pa0002 TYPE pa0002, wa_pa0001 TYPE pa0001, wa_hrp1000 TYPE hrp1000, wa_t500p TYPE t500p. * Navigate to SUB_ORGS Node
lo_nd_suborg = wd_context-> path_get_node( path = `ND_TREE.ORGUNITS.SUB_ORGS` ).
wdctx_emps ).
ENDIF. IF NOT
* Get the Employees under Org Unit REFRESH : lt_hrpernr, lt_pa0002, lt_pa0001, lt_hrp1000,
lt_t500p,lt_emp_list.
IF NOT lv_orgunit IS INITIAL. Get the <PERNR> for the given Org. Unit CALL FUNCTION 'HRCM_ORGUNIT_EMPLOYEE_LIST_GET' EXPORTING plvar = '01' otype = 'O'
objid begda endda = lv_orgunit = sy-datum = sy-datum = lt_hrpernr
TABLES
pernr_table
EXCEPTIONS
path_error = 1 root_error = 2 no_employees_found = 3 OTHERS = 4. IF NOT lt_hrpernr[] IS INITIAL.
Get the Names SELECT * FROM pa0002 INTO TABLE lt_pa0002 FOR ALL ENTRIES IN lt_hrpernr WHERE pernr = lt_hrpernr-pernr AND endda GE sy-datum AND begda LE sy-datum. SELECT * FROM pa0001 INTO TABLE lt_pa0001 FOR ALL ENTRIES IN lt_hrpernr WHERE pernr = lt_hrpernr-pernr AND endda GE sy-datum AND begda LE sy-datum. IF lt_pa0001[] IS NOT INITIAL. **Get Position Text from HRP1000 SELECT * FROM hrp1000 INTO TABLE lt_hrp1000 FOR ALL ENTRIES IN lt_pa0001 WHERE plvar = '01' AND otype = 'S' AND objid = lt_pa0001-plans
SELECT * FROM t500p INTO TABLE lt_t500p FOR ALL ENTRIES IN lt_pa0001 WHERE persa = lt_pa0001-werks. ENDIF. ENDIF. ENDIF. LOOP AT lt_hrpernr INTO wa_hrpernr.
wa_emp_list-pernr = wa_hrpernr-pernr.
* Prepare the Full Name READ TABLE lt_pa0002 INTO wa_pa0002 WITH KEY pernr = wa_hrpernr-pernr. IF sy-subrc = 0. CONCATENATE wa_pa0002-nachn wa_pa0002-vorna INTO wa_emp_list-name SEPARATED BY space. ENDIF. READ TABLE lt_pa0001 INTO wa_pa0001 WITH KEY pernr = wa_hrpernr-pernr. IF sy-subrc = 0. *Position Title READ TABLE lt_hrp1000 INTO wa_hrp1000 WITH KEY objid = wa_pa0001-plans. IF sy-subrc = 0. wa_emp_list-position = wa_hrp1000-stext. ENDIF. *Work location READ TABLE lt_t500p INTO wa_t500p WITH KEY persa = wa_pa0001-werks. IF sy-subrc = 0.
wa_emp_list-location = wa_t500p-name1.
ENDIF. ENDIF. APPEND wa_emp_list TO lt_emp_list. CLEAR : wa_emp_list, wa_hrpernr, wa_pa0002, wa_pa0001, wa_hrp1000, wa_t500p. ENDLOOP. SORT lt_emp_list BY pernr. IF NOT lt_emp_list[] IS INITIAL. * Bind the Employees table to the node CALL METHOD lo_nd_emps->bind_table EXPORTING
new_items = lt_emp_list set_initial_elements = abap_true.
ENDIF. ENDIF. ENDMETHOD. We are done with the processing logic, and we have to create the application and run it to see the result.
Sample Output:
Related Content
For more information, visit the Tree UI Element Help For more information, visit the Web Dynpro ABAP Home Page