Step 3. Add Logic to the Employee Query Command Handler
VFW126 – Using Space Objects (Optional)
1. Select the
tab.2. Complete the
event routine to:Initialize work fields and use the SPACE_OPERATION BIF and CHECKEXISTENCE to ensure the space object exists.
Add an If / Else / Endif for STD_CMPAR = OK
Issue an error message if the space object is not found.
Evtroutine Handling(#PHBN_SELECT.Click)
#std_text := IIIVFW41
#TOTSALARY := *zeroes
* Check Space exists
Use Builtin(SPACE_OPERATION) With_Args(#std_text CHECKEXISTENCE) To_Get(#std_cmpar)
If (#std_cmpar = OK)
* Populate list view form space object
Else
Message Msgtxt('Space object IIIVFW42 does not exist')
Endif
Endroutine
3. To populate the list view, add the logic:
- Clear the list view
- Use SELECT_IN_SPACE to retrieve entries using DEPT_IN as key.
- Return the SELECT_IN_SPACE status into field STD_CMPAR.
- While STD_CMPAR is equal to OK
- Add an entry to the list view
- Retrieving all space object entries for the department code = DEPT_IN, must be achieved by then using the SELECT_NEXT_IN_SPACE. Note this also returns status as STD_CMPAR.
Your code should now look like the following. New code is highlighted in red.
Evtroutine Handling(#PHBN_SELECT.Click)
#std_text := IIIVF31
#TOTSALARY := *zeroes
* Check Space exists
Use Builtin(SPACE_OPERATION) With_Args(#std_text CHECKEXISTENCE) To_Get(#std_cmpar)
If (#std_cmpar = OK)
Clr_List Named(#LTVW_1)
Use Builtin(SELECT_IN_SPACE) With_Args(#STD_TEXT #DEPT_IN) To_Get(#STD_CMPAR #DEPTMENT #EMPNO #GIVENAME #SURNAME #SECTION #salary)
Dowhile ('#STD_CMPAR *EQ OK')
Add_Entry To_List(#LTVW_1)
Use Builtin(SELECTNEXT_IN_SPACE) With_Args(#STD_TEXT #DEPT_IN) To_Get(#STD_CMPAR #DEPTMENT #EMPNO #GIVENAME #SURNAME #SECTION #salary)
Endwhile
Else
Message Msgtxt('Space object IIIVFW31 does not exist')
Endif
Endroutine
4. Complete the Reports Employee Query command handler logic by making the List View
and event routines maintain Total Salary.Your code should look like the following:
Evtroutine Handling(#LTVW_1.ItemGotSelection) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
#TOTSALARY := #TOTSALARY + #salary
Endroutine
Evtroutine Handling(#LTVW_1.ItemLostSelection) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
#TOTSALARY := #TOTSALARY - #salary
Endroutine
5. Compile the Reports Employee Query command handler.
6. Execute the Framework as Designer.
7. Open the
dialog for the Reports business object.8. Select the
tab, select the Employee Query action and plug in the command handler iiiVFW43. Use the dialog so that the plug in uses the Identifier name.9.
the Framework.10. Select the
business object. Right click on the tab and run the command handler.11. Again, use the right mouse menu to run the
command handler and display employees from the space object for department ADM.12. Restart the Framework and this time run the
command handler immediately. The "Space object does not exist" error message should be shown in the Frameworks status bar.13. Based on what you've learnt in an earlier exercise, you should appreciate that if required you could add framework switch logic to Employee Query, to run the Salary command handler automatically, when the space object does not exist.