In this recipe, we will see how we can display data in the form of a navigation list. The navigation list is similar to a tree. However, the nodes appear in expanded form when displayed and may not be compressed. The entire navigation list may be expanded and compressed (however, not the data nodes within it).
We assume that we have an internal DATA_TAB
table comprising of three fields, department
, pernr
, and sname
, containing the department name, employee number, and the employee names respectively in sorted order according to the department name.
We will now see the steps required to create a navigation list:
NAVLIST
.No
(since, in this case, we do not require lead selection and its initialization). The Singleton property of the node must be set as No
. The Cardinality field is set as 0..n
.NAVLIST
, namely DISPLAYED_ TEXT
, PERNR
, and IF_SELECTED
based on the type STRING
, PERSNO
, and WDY_BOOLEAN
, respectively.NAVLIST
context node and name it NAVLISTREC
. Right-click on the NAVLIST
context node and from the context menu that appears, navigate to Create | Recursive Node.NAVLIST
from the component controller to the relevant view controller (define the mapping).Navigation
in the ID field and choose the type NavigationList in the pop up that appears.Department Wise List
in the title property.MAIN.NAVLIST
context node defined earlier. For the itemText property, we set the value as the DISPLAYEDTEXT
attribute of the context node.NODE_NAVLIST
) and the navigation list recursive context node (RECNODE
).ELEMENT_NAVLIST
is defined as a reference to a context element using interface IF_WD_CONTEXT_ELEMENT
.DATA_TAB
internal table that contains data of the department and the personnel number and names.AT NEW DEPARTMENT
statement to add data to the context node NAVLIST
.GET_CHILD_NODE
method is called to get a reference to the NAVLIST
context node; the reference is stored in the NODE_NAVLIST
navigation list node. The NAVLIST
structure is assigned the department name. The IS_SELECTABLE
property is kept as false
.BIND_STRUCTURE
node is then used to add the department name to the NAVLIST
context node element collection. The reference to the added element is returned and stored in ELEMENT_NAVLIST
. The GET_CHILD_NODE
method is then called to get the reference to the NAVLISTREC
recursion node for the element referred to by the ELEMENT_NAVLIST
variable (this reference is stored in RECNODE
) to be used later.AT .. ENDAT
block is the area that is executed for all rows in the data internal table DATA_TAB
. This area pertains to the employee data (employee name and employee). We use the NAVLIST
structure in this block.ABAP_TRUE
and the name and employee number to the IS_SELECTABLE
property to be displayed in the DISPLAYED_TEXT
field. The BIND_STRUCTURE
node is then used for adding the employee data to the NAVLISTREC
recursive node using the RECNODE
reference variable.We first created a NAVLIST
context node containing a NAVLISTREC
recursion node. We then inserted a navigation list UI element on the view layout. Appropriate binding between the navigation list UI element and the context nodes was defined. In the code, we formed the higher nodes in the navigation list displaying departments (at the beginning of a new department within the data table DATA_TAB
). We then added child nodes (to the department nodes) displaying the employee names and number contained within the department.
The employee names within the department are selectable but may not be compressed (the IS_SELECTABLE
property is set to TRUE
in the code). This navigation list is displayed as shown in the following screenshot:
We can further enhance the application by activating the selection feature of the selectable nodes, that is, displaying the details of an employee selected on the user's screen. For this, we first need to enter a suitable name in the Onselect
property of the navigation list in the layout editor. Then double-click in order to write the code. The GET_CHILD_NODE
method will be called when a particular selectable row is clicked by the user. The handler method will be called when the SELECT
event is raised.
This handler method contains one parameter, WDEVENT
. In order to determine which employee number and name has been selected, we will add a new parameter, SEL_NODE
, having type IF_WD_CONTEXT_ELEMENT
. We then need to call the GET_STATIC_ATTRIBUTES
method for the SEL_NODE
parameter in order to retrieve the details of the selected node (including the employee number pernr
).
18.226.82.253