Step 1 Create the Salary Command Handler

VLF Windows Application Development

Step 1. Create the Salary Command Handler

VFW126 – Using Space Objects (Optional)

1.  Create a new Reusable Part / Panel:

     Name: iiiVFW42

     Description: Salary Command Handler for Reports

2.  Give the reusable part an ancestor of VF_AC010

3.  Use the Design ribbon to give iiiVFW40 an Attachment manager

4.  Drop a Panel component onto the bottom of the main panel. Change the Name to BOTTOM_PANEL.

5.  Drop a List View into the center of the main panel, so that it occupies the rest of the space.

6.  If necessary use the Layout Helper tab to confirm the position of the child panel and list view.

7.  Save the design.

8.  If field TOTSALARY does not already exist, create a new Packed Decimal field, with a length of 15 and 2 decimal places. Give it an Edit Code of 2. Drag and drop field TOTSALARY onto the right hand side of BOTTOM_PANEL. Resize the field as necessary.

9.  Locate the file PSLMST in the Repository and drag and drop fields EMPNO, SURNAME, GIVENAME and SALARY into the List View. Finally drop field STD_TEXTS onto the list view.

10. Change the Caption for the STD_TEXTS column to Selected and change CaptionType to Caption.

11. Create an Initialize event for the list view.

12. Save the design.

13. Switch to the Source tab.

14. Add the following code to the list view Initialize event handling routine to define the space object:

#std_text := IIIVFW42
* Create Space with the name entered in std_texts field
Use Builtin(CREATE_SPACE) With_Args(#std_text) To_Get(#STD_CMPAR)
* Define Space Cells
Use Builtin(DEFINE_SPACE_CELL) With_Args(#STD_TEXT DEPTMENT KEY)
Use Builtin(DEFINE_SPACE_CELL) With_Args(#STD_TEXT EMPNO KEY)
Use Builtin(DEFINE_SPACE_CELL) With_Args(#STD_TEXT GIVENAME)
Use Builtin(DEFINE_SPACE_CELL) With_Args(#STD_TEXT SURNAME)
Use Builtin(DEFINE_SPACE_CELL) With_Args(#STD_TEXT SECTION)
Use Builtin(DEFINE_SPACE_CELL) With_Args(#STD_TEXT SALARY)

 

     The code above has created a space object with same name as this component. The name can be any alphanumeric value, but must be unique within the Windows process (that is, within the job).

     Hint: Type Use Builtin(DEFINE_SPACE_CELL) and then press F4 to display the Command Assistant.

     Expand the WITH_ARGS parameter and note that the editor shows the details for the parameters required.

     That is, Space Object Name and so on.

15. Define a Group_By for all the employee fields required. Different fields are required for the list view and the space object.

Group_By Name(#empdata) Fields(#EMPNO #SURNAME #GIVENAME #DEPTMENT #SECTION #salary)

 

16. Complete the LTVW_1.Initialize event routine by populating the list view and inserting each employee into the space object:

#std_texts := *blanks
Clr_List Named(#LTVW_1)
#std_count := *zeroes
Select Fields(#empdata) From_File(pslmst)
Add_Entry To_List(#LTVW_1)
* Add to Space object
Use Builtin(INSERT_IN_SPACE) With_Args(#STD_TEXT #DEPTMENT #EMPNO #GIVENAME #SURNAME #SECTION #salary) To_Get(#STD_CMPAR)
#std_count += 1
Endselect
Message Msgtxt('Space object IIIVFW42 created with ' + #std_count.asstring + ' entries')

 

17. The command handler should display the Total Salary for currently selected entries in the list view.

     Create ItemGotSelection and ItemLostSelection event routines for the list view and add appropriate logic in each to maintain TOTSALARY.

     The STD_TEXTS column should contain YES when the row is selected.

     Your code should look like the following:

Evtroutine Handling(#LTVW_1.ItemGotSelection) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
#std_texts := 'YES'
Upd_Entry In_List(#LTVW_1)
#TOTSALARY := #TOTSALARY + #salary
Endroutine
Evtroutine Handling(#LTVW_1.ItemLostSelection) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
#std_texts := *blanks
Upd_Entry In_List(#LTVW_1)
#TOTSALARY := #TOTSALARY - #salary
Endroutine

 

18. Compile the new command handler.

19. Execute the Framework as Designer.

a.  Open the Properties dialog for the Reports business object.

b.  Select the Commands Enabled tab, select the Salary action and plug in the Salary command handler, iiiVFW42.

c.  Use the Find dialog, so that the plug in uses the Identifier.

20. Save and Restart the Framework.

21. Select the Reports business object. Right click on the Weekly command handler and select Salary from the context menu.

22. Test the Salary command handler by selecting a number of employees, while holding down the Control key. Note Total Salary shows the total for selected employees.

23. Change the selected employees and ensure that the Total Salary is recalculated.