tree with table in web dynpro abap

Download Tree with Table in Web Dynpro ABAP

Post on 28-Apr-2015

218 views

Category:

Documents

5 download

Embed Size (px)

DESCRIPTION

Tree with Table in Web Dynpro ABAP

TRANSCRIPT

Displaying Dynamic Recursive Tree with Table in Web Dynpro ABAP

Applies to:This Article applies to Web Dynpro ABAP, ABAP HR, and Enterprise Portal 7.0.

SummaryThis 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 Miryalath

Company: Intelligroup Inc Created on: 26 February 2010

Author BioJhansi 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.

SAP DEVELOPER NETWORK | sdn.sap.com 2008 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 1

Displaying Dynamic Recursive Tree with Table in Web Dynpro ABAP

Table of ContentsIntroduction ......................................................................................................................................................... 3 Scenario .............................................................................................................................................................. 3 Procedure ........................................................................................................................................................... 3 Steps to create a dynamically structured Recursive Tree Web Dynpro Application ...................................... 31) Create the Web Dynpro Component ........................................................................................................................ 3 2) Create the context in the view .................................................................................................................................. 4 3) Define the Supply function(s) ................................................................................................................................... 6

Code Block - 1................................................................................................................................................. 7 Code Block - 2................................................................................................................................................. 94) Design the Layout .................................................................................................................................................. 10 5) Define the Actions for ORGUNITS TreeNodeType ................................................................................................ 16

Code Block 3 .............................................................................................................................................. 176) Define the Actions for SUBORGS TreeNodeType ................................................................................................. 19

Code Block - 4............................................................................................................................................... 207) Create a WebDynrpo Application ........................................................................................................................... 23 8) Test the application to see the output .................................................................................................................... 24

Sample Output: ................................................................................................................................................. 25 Related Content ................................................................................................................................................ 26 Disclaimer and Liability Notice .......................................................................................................................... 27

SAP DEVELOPER NETWORK | sdn.sap.com 2009 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2

Displaying Dynamic Recursive Tree with Table in Web Dynpro ABAP

IntroductionThis 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.

ScenarioOrganization 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.

ProcedureSteps 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.

SAP DEVELOPER NETWORK | sdn.sap.com 2009 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 3

Displaying Dynamic Recursive Tree with Table in Web Dynpro ABAP

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.

SAP DEVELOPER NETWORK | sdn.sap.com 2009 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 4

Displaying Dynamic Recursive Tree with Table in Web Dynpro ABAP

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

Cardinality 1..1 0..n

Selection 0..1 0..1

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.

SAP DEVELOPER NETWORK | sdn.sap.com 2009 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 5

Displaying Dynamic Recursive Tree with Table in Web Dynpro ABAP

The context looks like as shown below.

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.

SAP DEVELOPER NETWORK | sdn.sap.com 2009 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 6

Displaying Dynamic Recursive Tree with Table in Web Dynpro ABAP

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 node lo_nd_tree_nd = wd_context->path_get_node( path = 'ND_TREE' ). * Navigate to the 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 org