Step 2. Complete the Command Handler logic
VFW056 – Process a List in Sorted Order
1. Add code to the PHBN_LOADED click event routine, which:
a. Clears the list view LIST_2
b. Selects all items in LIST_1 using SELECTLIST
c. If LIST_1 current item, selected is true, add an entry to LIST_2
For example:
Evtroutine Handling(#PHBN_LOADED.Click)
Clr_List Named(#LIST_2)
Selectlist Named(#LIST_1)
If (#LIST_1.currentItem.selected)
Add_Entry To_List(#LIST_2)
Endif
Endselect
Endroutine
2. Add code to the PHBN_SORTED
event routine which:a. Clears the list LIST_2
b. Processes all items in LIST_1 using a FOR/ENDFOR loop. For example:
Evtroutine Handling(#PHBN_SORTED.Click)
Clr_List Named(#LIST_2)
For Each(#row) In(#LIST_1.items)
. . . .
Endfor
Endroutine
LIST_1.Items returns a reference to the collection in the list view component.
Within the FOR/ENDFOR loop, each item will be referred to as #ROW
c. Retrieve each list item using GET_ENTRY. For example
Evtroutine Handling(#PHBN_SORTED.Click)
Clr_List Named(#LIST_2)
For Each(#row) In(#LIST_1.items)
Get_Entry Number(#row.entry) From_List(#LIST_1)
Endfor
Endroutine
Row.Entry is the entry number for each list item
d. If the item is selected, add an entry to LIST_2. For example
Evtroutine Handling(#PHBN_SORTED.Click)
Clr_List Named(#LIST_2)
For Each(#row) In(#LIST_1.items)
Get_Entry Number(#row.entry) From_List(#LIST_1)
If (#row.Selected)
Add_Entry To_List(#LIST_2)
Endif
Endfor
Endroutine
3. Compile your command handler.
4. Execute the
and open the properties dialog for the business object and select the tab.Select the
action and define its component as iiiVFW09.5.
the Framework.6. Test the
command handler for the business object.a. Right click on the
command tab and select the action from the context menu.Note that initially the left hand employee list is displayed in its loaded order.
b. Without sorting on a column in the left hand list, select some entries and use the
button. The right hand list should now contain the selected entries as they are displayed on the left, which is their loaded order.c. Test the results using the
and buttons. The right hand list should contain the same selected entries in each case.d. Sort the left hand list on Surname. Select entries and test the
button. Note that the right hand list contains entries from their loaded position, which is no longer the same as the displayed list.e. Now try the
button and note that the right hand list now contains the same entries as displayed and selected in the left hand list. The list has been processed in its sorted order.