Step 2. Add WebRoutines to the new WAM
WAM010 - Using WEB_MAPs
In this step, you will add the RDMLX code consisting of multiple WebRoutines to the newly created WAM.
1. Immediately following the BEGIN_COM, insert the following RDMLX code to create a WebRoutine named WMdemo:
Webroutine Name(WMdemo) Desc('WEB_MAP WR1')
Endroutine
2. All fields in the WebRoutine will be both incoming and outgoing, so they will be specified FOR(*BOTH). By default, all of the fields will be displayed as input fields. You could write the following WEB_MAP statement for the WebRoutine:
WEB_MAP FOR(*BOTH) FIELDS(#EMPNO #GIVENAME #SURNAME #ADDRESS1 #POSTCODE (#STDRENTRY *HIDDEN))
However, a GROUP_BY may be used in a WEB_MAP, so you will use the following code:
Begin_Com Role(*EXTENDS #PRIM_WAM)
Group_By Name(#Empdata) Fields(#empno #surname #givename #address1 #postcode)
Webroutine Name(WMdemo) Desc('WEB_MAP WR1')
Web_Map For(*BOTH) Fields(#empdata (#stdrentry *hidden))
. . . WebRoutine
Note: A WEB_MAP statement with Keyword FOR(*BOTH) specifies that the fields listed in the WEB_MAP are both input to and output from the WebRoutine.
In the Fields() keyword of WEB_MAP, the fields are specified with their display mode. The display mode attribute only plays a role for fields that are FOR(*OUTPUT) or FOR(*BOTH).
By default, all fields are displayed on the web page as input fields. To change the way the fields display on the web page, the display mode can be set to *INPUT, *OUTPUT, *HIDDEN, or *PRIVATE.
*HIDDEN fields are included in the page as hidden fields. That is, their values are mapped but they are not shown on the web page.
*PRIVATE fields are not shown on the web page but are available in the XML for use in weblets such as a dropdown lists.
3. Add the code to initialize the fields in the WebRoutine. Since EMPNO is both incoming to and outgoing from the WebRoutine, its value should never be lost. If EMPNO is blank, that means it is the first time entering the WebRoutine. You will retrieve a valid employee number by simply reading the first record from the Personnel Master.
If Cond(#empno = *blanks)
Select Fields(#empdata) From_File(pslmst)
Leave
Endselect
Endif
Note the following about this code:
The SELECT loop with an unconditional LEAVE, will return values for the first record read. Typically you should not rely on values returned outside a SELECT loop because the returned values may be unpredictable. This technique has been used for the sake of simplicity. An alternative could be:
Fetch Fields(#EMPDATA) From_file(PSLMST)
With no key specified, the FETCH will return the first record in the file.
4. A
button will be required to read data from the Personnel Master file when an Employee Number has been entered on the web page. The read will do a FETCH on the Personnel Master, using EMPNO as the key and will be triggered by a button calling the WebRoutine with a STDRENTRY value of 'R'.If Cond(#stdrentry = R)
Fetch Fields(#empdata) From_File(pslmst) With_Key(#empno)
Endif
Your finished WebRoutine should appear as follows:
Group_By Name(#Empdata) Fields(#empno #surname #givename #address1 #postcode)
Webroutine Name(WMdemo) Desc('WEB_MAP WR1')
Web_Map For(*BOTH) Fields(#empdata (#stdrentry *hidden))
If Cond(#empno = *blanks)
Select Fields(#empdata) From_File(pslmst)
Leave
Endselect
Endif
If Cond(#stdrentry = R)
Fetch Fields(#empdata) From_File(pslmst) With_Key(#empno)
Endif
EndroutineWebRoutine