Step 1. Create WAM iiiEmpUpdate – Employee Update

WAM035 - An Employee Update WAM

1.  Select WAM iiiEmpEnquiry – Employee Enquiry on your Favorites / Last Opened tab and use the context menu to Copy it to create iiiEmpUpdate – Employee Update.

     On the Active Designs dialog, select only the Begin WebRoutine:

     In the Active Designs you selected only the BEGIN WebRoutine. This will copy the XML and XSL for this WebRoutine only. In the new WAM iiiEmpUpdate you are redesigning the DETAILS web page, making most of the fields input capable. When you compile iiiEmpUpdate having made your RDMLX changes to the DETAILS WebRoutine, the correct start position will be generated for the new DETAILS web page.

2.  Change the GROUP_BY so that all fields are input capable except for EMPNO, currently they are all displayed for output only.  Once again use the F4 Command Assistant to make these changes.

3.  You need to ensure that the fields are both sent to the web page and received back from it, since this time you are displaying and updating employee fields. Remember that fields in a WEB_MAP are by default mapped with an *INPUT attribute. In order to display and update employee data, your fields will need to be mapped For(*both).

4.  The Details WebRoutine now needs to performs two roles. It FETCHs a record when invoked from the Begin WebRoutine, and UPDATEs the record when re-entered via an Update button. The field STDRENTRY will be used to control which logic to perform.

     Note #1: STDRENTRY is a single character field which is defined as the default field returned by a number of weblets. This is simply a convention and you may prefer to replace it with a longer field which supports a more meaningful input values such as, ENQUIRE, UPDATE or DELETE.    

      Note #2: You should now map field STDRENTRY For(*both) as a hidden field.

5.  Modify the Details WebRoutine using a CASE / ENDCASE loop for field STDRENTRY, so that when the Details WebRoutine is called from the Begin WebRoutine (returning a STDRENTRY value of M) the employee record is fetched. When the Details WebRoutine is re-entered from the Details web page a value of U should perform an UPDATE to the employee file. The Update push button will return STDRENTRY with a value of 'U'.

     The Employee Number (EMPNO) should be output on the Details page so that the key field cannot be changed. An output field on the web page cannot be mapped back into the next WebRoutine. Of course the WAM needs the Employee Number to perform the update.

     This is a common situation with all web applications. One solution is to output a hidden work field containing the Employee Number and use this to perform the update.

6.  Define a work field EMPNOW based on EMPNO. Map field EMPNOW for *both as a *hidden field. You could map both STDRENTRY and EMPNOW for all WebRoutines by defining this map at the WAM level (that is immediately following the Define_Com). WEB_MAPs defined at the WAM level are global and apply to all WebRoutines.

7.In the Details webroutine, when called from the Begin webroutine, set EMPNOW to the value of EMPNO.

8.When the Details WebRoutine is called by the Update button, set EMPNO to the value of  EMPNOW.

9.  Consider how to add logic to the Details WebRoutine to return to the Begin page if the update is successful.
Hint: remember the TRANSFER command that you implemented in an earlier exercise.

10.  Your WAM should now look something like the example following. The changed and new code compared with iiiEmpEnquiry is shown in red.

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_WAM) Layoutweblet('iiilay01')
Define Field(#EMPNOW) Reffld(#EMPNO)

WebRoutine Name(begin)
Web_Map For(*output) Fields(#empno)
WebRoutine Name(Details) Desc('Employee Details')
Web_Map For(*BOTH) Fields(#EMPDATA)
When (
'= M')
Fetch Fields(#EMPDATA) From_File(PSLMST) With_Key(#EMPNO) Val_Error(*NEXT)
If_Status Is_Not(*OKAY)
Message Msgtxt('Employee not found')
Transfer Toroutine(Begin)
Change Field(#EMPNOW) To(#EMPNO)
When (
'= U')

Update Fields(#EMPDATA) In_File(PSLMST) With_Key(#EMPNO) Val_Error(*NEXT)

If_Status Is(*OKAY)

Transfer Toroutine(Begin)