Step 2. Create Departments Test Form

In this step, you will create a form that searches the Department table by the department description. This will use the index you just created, which is keyed by the department description.

1.  Create a New / Basic Form with the following characteristics (where iii=your initials):




Search by Department Description


2.  Next add the fields iiiDeptCode and the iiiDeptDescription to your form:

a.  Display the iiiLIST tab.

b.   Drag and drop the iiiDeptCode and iiiDeptDescription fields onto the form:

3.  Next, add a button to the form:

a.  Locate the Controls tab. If this tab is not open, open it from the Home ribbon, Tabs menu.

b.  On the Controls tab select the LANSA controls (highlighted button). Select the Push button control and drag and drop it onto the form:

c.  Double-click the button on the form to display the Details tab. The Details tab then shows the Properties, Events and Methods for the Push Button.

d.  In the Caption property enter Find Department Code.

e.  Adjust the width of the push button to display the Caption.

f.  Adjust the height and width of the form.

4.  Now add some code that will search the index and return a department based on the department description:

a.  Select the Events tab on the Details tab. Double click on the Click event to create a Click event routine for the push button. Your code will look like the following:

b.  Select the Source tab. Your code will look like the following:




c.  Complete the push button click event routine, by adding a Fetch statement. Your new code should look like the following:

Fetch FIELDS(#iiiDeptcode) from_file(iiiDeptsByDesc) with_key(#iiiDeptDescription)


     Change the iii in the code to use your initials.

     Your complete source code should now look like this:

Evtroutine Handling(#Button1.Click)

Fetch Fields(#iiiDeptCode) From_File(iiiDeptbyDesc) With_Key(#iiiDeptDescription)


5.  Compile your form. Check that it compiled successfully.

     The Fetch button will now process the iiiDepartments table using the index in description sequence.