Step 4. Complete Code for By Location Filter

In this step, you will complete the code for the By Location filter. The Skeleton Filter generates most of the required code. The SELECT statement must be completed to perform the required search.

1.  Switch to the Source tab.

2.  Below the Define_Com statements, define a working list with one entry called Save_Keys containing the fields xDepartmentCode. Your new code should now look like the following:

Def_List Name(#Save_Keys) Fields(#xDepartmentCode) Type(*Working) Entrys(1)

3.  Examine the SEARCH_BUTTON_1.Click event routine. Note that this routine invokes the required List Manager methods, BeginListUpdate, ClearList, AddToList and EndListUpdate.

     We will complete the SELECT statement in a later step.

4.  At the beginning of the Search_Button_1.Click event routine add code to initialize the Save_Keys working list. This will save the search value.

Inz_List Named(#Save_keys)

5.  The By Location filter needs to read the Employee file using the logical xDepartmentsByDepartment which is keyed on xDepartmentCode and xEmployeeIdentification. The search will require department code only and support a generic search when a partial department code is specified.

     Complete the Select statement:

a.  Add the logical file name in the File parameter

b.  Remove the comment text from the Fields parameter

c.  Specify the With_Key parameter

d.  Add suitable Nbr_Keys and Generic parameters.

Your code should look like the following:

Select Fields(#xEmployeeIdentification #xEmployeeSurname #xEmployeeGivenNames) From_File(xEmployeeByDepartment) With_Key(#xDepartmentCode) Nbr_Keys(*COMPUTE) Generic(*YES)

6.  Locate this statement:


     Add an IF condition which tests the check box Clear_List.ButtonState is Checked:

If Cond(#Clear_List.ButtonState = checked)



7.  Note that the visual identifier fields (UF_VISID1u and UF_VISID2u) are already setup correctly and the AddToList has the required parameters. You could improve the Full Name instance list column by replacing this statement:

#UF_VISID2u := #xEmployeeSurname

     With the following:

#UF_VISID2u := #xEmployeeSurname + ', ' + #xEmployeeGivenNames

8.  After the EndSelect, add a Get_Entry number statement for the Save_Keys list. This will restore the search keys after the file read.

Get_Entry Number(1) From_List(#save_keys)

9.  Also add code to set the Search_Button_1.Enabled to False, after the EndSelect:

#SEARCH_BUTTON_1.enabled := false

10. Complete the xDepartmentCode.Changed event routine. Add code to enable the Search_Button_1.

Evtroutine Handling(#xDepartmentCode.Changed) Options(*NOCLEARMESSAGES *NOCLEARERRORS)

#SEARCH_BUTTON_1.Enabled := true


11. Your Search_Button_1.Click event, should look like the following:


Inz_List Named(#save_keys)

* Indicate that _Employees  instance list updating is about to start


* Clear the current _Employees  business object instance list (optional)

If Cond(#Clear_List.ButtonState = checked)



*  Select appropriate instances of _Employees

Select Fields(#xEmployeeIdentification #xEmployeeSurname #xEmployeeGivenNames) From_File(xEmployeeByDepartment) With_Key(#xDepartmentCode) Nbr_Keys(*COMPUTE) Generic(*YES)

* Set up the visual Identifier(s)

#UF_VISID1u := #xEmployeeIdentification

#UF_VISID2u := #xEmployeeSurname + ', ' + #xEmployeeGivenNames

* Add instance details to the instance list

#avListManager.AddtoList Visualid1(#UF_VISID1u) Visualid2(#UF_VISID2u) Akey1(#xEmployeeIdentification) Acolumn1(#xEmployeeGivenNames)


Get_Entry Number(1) From_List(#save_keys)

* Indicate that _Employees  instance list updating is now complete



#SEARCH_BUTTON_1.enabled := false


12. Compile your By Location filter.

13. With the framework open as a Designer:

a.  Double click the _Employees business object to open the Business Object Properties dialog.

b.  Select the Filters tab and then select the Filter Snap-In Settings tab.

c.  Select the By Location filter.

d.  Select the Component Identifier radio button.

e.  Use the Search button for the VLF-WIN input field.

f.  Enter a search value of III and select your IIIFILT04, which will return the Identifier and close the Find dialog.

14. Save and Restart the framework and test the By Location filter. Test using a Department Code  such as 100, 200, 1000 or 1200. Searching with a value of "1" will return all employees for all department codes starting with "1".

     Note: This is a simple solution. In practice, you would probably implement a dropdown for department code, which lists department descriptions. You would also add an instance list column for the department description, so that the user can see which departments have been selected.