Step 1. Create WAM iiiEmpMaint – Employee Maintenance
WAM060 - Employee Maintenance using Advanced Weblets
1. Create a new WAM:
Name: iiiEmpMaint
Description: Employee Maintenance
Layout Weblet: iiilay01
2. Begin by defining the lists needed to support the main page WebRoutine, ShowPage.
- Define a working list, DEPTS for fields in the file DEPTAB
- Define a working list, SECTS for section code and description from file SECTAB
These lists will support Dynamic Select Box weblets for department and section codes.
- Define a working list, EMPLOYS for fields EMPNO, FULLNAME, POSTCODE, PHONEBUS, and PHONEHME. All fields should be defined with an output attribute. This list of employees will be displayed on the left hand side of the vertical splitter weblet.
- Define a Group_by, EMPS for fields EMPNO, SURNAME, GIVENAME, POSTCODE, PHONEBUS, PHONEHME
- Map the field STDRENTRY for both, as a hidden field
Your code should look like the following:
Function Options(*direct)
Begin_Com Role(*EXTENDS #PRIM_WAM) Layoutweblet('iiilay01')
* Support web page ShowPage
Def_List Name(#depts) Fields(#deptment #deptdesc) Type(*Working)
Def_List Name(#sects) Fields(#section #secdesc) Type(*Working)
Def_List Name(#employs) Fields((#empno *out) (#fullname *out) (#postcode *out) (#PHONEHME *out) (#PHONEBUS *out)) Type(*Working)
Group_by Name(#emps) Fields(#empno #surname #givename #postcode #phonebus #phonehme)
Web_Map For(*both) Fields((#stdrentry *hidden))
End_Com
3. Define a ShowPage WebRoutine.
- Define a web_map for output for lists DEPTS, SECTS, mapped as JSON data and list EMPLOYS.
- Define a web_map for both, for fields DEPTMENT and SECTION
- Define a CASE loop for field STDRENTRY
- When = S
- End Case
Your code should look like the following:
WebRoutine Name(ShowPage)
Web_Map For(*output) Fields((#depts *json) (#sects *json) #employs)
Web_Map For(*both) Fields(#deptment #section)
Case (#stdrentry)
When (= S)
Clr_list #EMPLOYS
Select Fields(#emps) From_File(pslmst1) With_Key(#deptment #section)
#fullname := #surname + ', ' + #givename
Add_Entry To_List(#employs)
Endselect
Endcase
Endroutine
4. Define a method routine BuildDepts to populate list DEPTS.
The routine should:
5. Define a method routine BuildSects to populate list SECTS.
The routine should:
Your new code should look like the following:
Mthroutine Name(BuildDepts)
Define_Map For(*input) Class(#deptment) Name(#i_dept)
Clr_List Named(#depts)
Select Fields(#depts) From_File(deptab)
Add_Entry To_List(#depts)
Endselect
If (#i_dept = *blanks)
Get_Entry Number(1) From_List(#depts)
Else
#deptment := #i_dept
Endif
Endroutine
Mthroutine Name(BuildSects)
Define_Map For(*input) Class(#deptment) Name(#i_dept)
Clr_List Named(#sects)
Select Fields(#sects) From_File(sectab) With_Key(#i_dept)
Add_Entry To_List(#sects)
Endselect
Get_Entry Number(1) From_List(#sects)
Endroutine
6. Invoke these method routines at the end of the WebRoutine ShowPage
Your code should look like the following. New code is shown in red.
. . . . .
#com_owner.BuildDepts I_Dept(#deptment)
#com_owner.buildsects I_Dept(#deptment)
Endroutine
7. The Dynamic Select Box weblet will be set up to invoke a response WebRoutine to re-populate the list SECTS when field DEPTMENT changes.
This will require a WebRoutine, UpdSects defined as follows:
Your code should look like the following:
WebRoutine Name(updsects) Response(*JSON)
Web_Map For(*input) Fields(#deptment)
Web_Map For(*output) Fields((#sects *json))
#com_owner.BuildSects I_Dept(#deptment)
Endroutine
8. Compile your WAM.