Step 1. Create WAM iiiEmpSearch – Employee Search
WAM065 - Controlling List Output
1. Create a new WAM
Name: iiiEmpSearch
Description: Employee Search
Weblet Template: iiilay01
2. Define the following work fields:
* Fields
Define Field(#empnof) Reffld(#empno) Desc('First entry on current page')
Define Field(#empnow) Reffld(#empno) Desc('Last entry on current page')
Define Field(#cur_page) Reffld(#std_num) Desc('Current page number')
Define Field(#empfrom) Reffld(#empno) Desc('From Employee')
Define Field(#empto) Reffld(#empno) Desc('To Employee')
Define Field(#total) Reffld(#std_count) Desc('Total entries this search ')
3. Define the following working lists:
* lists
Def_List Name(#emplist) Fields((#empno *out) (#surname *out) (#givename *out) (#postcode *out) (#phonehme *out)) Counter(#std_count) Type(*Working) Entrys(*max)
Def_List Name(#emps) Fields(#empno) Counter(#total) Type(*Working) Entrys(*max)
4. Define the following global map.
* Global Maps
Web_Map For(*both) Fields((#stdrentry *hidden))
Many weblets return a value in the field STDRENTRY, so it usually needs to be mapped as a hidden field. You will add other fields to this web_map as you develop this WAM.
5. Create a WebRoutine search using the following code.
WebRoutine Name(search)
Web_Map For(*both) Fields(#empfrom #empto #emplist)
Case (#stdrentry)
When (= s)
#com_owner.browse I_Empfrom(#empfrom) I_Empto(#empto)
Endcase
Endroutine
EMPFROM and EMPTO will provide search values for employee number. The current page of results will be displayed by the list EMPLIST. A push button will return a STDRENTRY value of S, which will perform the method routine browse.
Ignore the error Feature name browse is not a member…... This routine is defined in the next step.
Important Note: This WAM, when completed, will comprise around 130 statements. To save time, much of this code is provided. Make sure you review each section of code as it is added, either at the time you are doing it or later. As with all programming tasks, you should approach WAM development a stage at a time, and test your initial code, before moving on to add additional logic.
6. Create the browse method routine using the following code:
Mthroutine Name(browse)
Define_Map For(*input) Class(#empno) Name(#i_empfrom)
Define_Map For(*input) Class(#empno) Name(#i_empto)
Clr_List Named(#emplist)
Select Fields(#emplist) From_File(pslmst) Where((#std_count <= 10) And (#empno < #i_empto)) With_Key(#i_empfrom) Val_Error(*next) Options(*startkey *endwhere)
Add_Entry To_List(#emplist)
If (#std_count = 1)
#empnof := #EMPNO
Endif
#empnow := #EMPNO
Endselect
#cur_page += 1
Endroutine
You will add more logic to this routine in a later step.
Review the browse routine, which:
- Accepts two input values for EMPNO.
- Clears the working list EMPLIST. Note that STD_COUNT is the Counter() value for this list.
- Selects records from file PSLMST while STD_COUNT is less than or equal to 10 and the employee number is less than I_EMPTO.
- Reads the file using a startkey and an endwhere. The read will end when the Where() condition is false.
- The SELECT reads the next 10 records or stops when the end value for the search is reached.
- Adds entries to list EMPLIST
- Maintains EMPNOF as the first entry in the current list and EMPNOW as the last entry in the current list
- Increments current page (CUR_PAGE)
7. Add the following as hidden fields in the global web_map:
EMPNOF, EMPNOW and CUR_PAGE.
Note that this web_map maps the fields for *both. Their current value will be mapped back into each WebRoutine that is invoked from the web page.
8. Compile your WAM and open the search WebRoutine in the Design view. It should look like the following:
9. Select the employee number input box in the table containing employee numbers, and use the context menu Table Items / Add Columns… to add one column to the table.
10. Drop a Push button with image into the new top cell. Remove the placeholder characters.
11. Select the push button and set up the push button as follows, using the Details tab:
|
12. Set the tab_index for the push button and employee number fields as follows
|
13. Save your changes. Your web page should look like the following:
14. Execute your WAM in the browser. Enter search values for employee number such as A0070 and A2000. Your results should look like the following: