Step 2 Add RDMLX code to the new WAM

LANSA WAM

Step 2. Add RDMLX code to the new WAM

WAM020 - WAM Navigation

In this step, you will add RDMLX code, defining three WebRoutines.

1.  Immediately following the BEGIN_COM, insert the following RDML code to create three new WebRoutines named NavMain, NavCall and NavTrans:

Webroutine Name(NavMain) Desc('Navigation Home')

Endroutine

Webroutine Name(NavCall) Desc('Navigation CALL')

Endroutine

Webroutine Name(NavTrans) Desc('Navigation TRANSFER')

EndroutineWebRoutineWebRoutine 

2.  Define a List containing EMPNO in WebRoutine NavMain. This list will hold all of the valid employee numbers from the personnel master. You will use this list to populate a dropdown list, so you will only be able to search for an employee that exists. Add the following code in the WebRoutine:

Def_List Name(#EMPLST) Fields(#EMPNO) Type(*WORKING) Entrys(*MAX)

Clr_List Named(#EMPLST)

Select Fields(#EMPNO) From_File(PSLMST)

Add_Entry To_List(#EMPLST)

Endselect 

3.  Add a GROUP_BY immediately following the BEGIN_COM. This will be used in each WebRoutine's WEB_MAP and FETCH commands and to re-set field values to default values.

Group_By Name(#empdata) Fields(#surname #givename #address1 #address2 #address3 #postcode #phonehme #phonebus #deptment #section #salary #startdte #termdate)

 

     Hint: Use the F4 Command Assistant  to define the Group_By. Use the Fields in File tab to select fields from file PSLMST.

4.  All fields in the WebRoutine NavMain will be both incoming and outgoing, so they will be specified FOR(*BOTH). All of the fields from PSLMST will be used.

     By default, all the fields will be displayed as input fields.

     The EMPLST list should be mapped with a *PRIVATE attribute, because it will be used to populate the combo box weblet for EMPNO.

     Add the following  WEB_MAP statement to the WebRoutine NavMain:

WEB_MAP FOR(*BOTH) FIELDS(#EMPNO #EMPDATA (#EMPLST *PRIVATE))

 

  • Fields and lists with a *PRIVATE attribute will not be shown on the page and will not be mapped back into the WebRoutine.
  • The fields defined in the Group_by will be used to output the data that was retrieved from the file.
  • 5.  The field STDRENTRY will be used to determine which logic to execute. It should be mapped as a hidden field into and out of each WebRoutine.

         Immediately below the BEGIN_COM add the following WEB_MAP. This is a global WEB_MAP which applies to all WebRoutines

    Web_Map For(*both) Fields((#stdrentry *hidden))

     

    6.  In WebRoutine NavMain set up a CASE loop using the field STDRENTRY which will determine how to perform the search. Add this code before the CLR_LIST and SELECT logic you added earlier.

    Case Of_Field(#STDRENTRY)
    When Value_Is('= A')
    Fetch Fields(#EMPDATA) From_File(PSLMST) With_Key(#EMPNO)
    Message Msgtxt("Logic executed within this WebRoutine.")
    When Value_Is('= B')
    Transfer Toroutine(NavTrans)
    Message Msgtxt("This message will not be displayed.")
    When Value_Is('= C')
    Call Webroutine(NavCall)
    Message Msgtxt("Back from the CALL.")
    When Value_Is('= D')
    Message Msgtxt("Back from the TRANSFER.")
    When Value_Is('= E')
    #EMPDATA := *DEFAULT
    EndcaseWebRoutine

     

    7.  Extend your logic for handling the list of employees, EMPLIST. The list needs to be built every time WebRoutine NavMain executes, but also needs to preserve the current value of employee number, EMPNO.

    a.  Define a work field EMPNOW based on EMPNO

    b.  Save current value of EMPNO in EMPNOW

    c.  After the list is built restore EMPNO to EMPNOW, provided EMPNOW is not blank.

         Your code should look like the following:

    Define Field(#empnow) Reffld(#empno)
    #empnow := #empno
    Clr_List Named(#EMPLST)
    Select Fields(#EMPNO) From_File(PSLMST)
    Add_Entry To_List(#EMPLST)
    Endselect
    If (#empnow *NE *blanks)
    #empno := #empnow
     
    Endif

     

         Your WAM at this stage should appear as follows:

    Function Options(*DIRECT)
    Begin_Com Role(*EXTENDS #PRIM_WAM)
    Web_Map For(*both) Fields((#stdrentry *hidden))
    Group_By Name(#empdata) Fields(#surname #givename #address1 #address2 #address3 #postcode #phonehme #phonebus #deptment #section #salary #startdte #termdate)
    Webroutine Name(NavMain) Desc('Navigation Home')
    Web_Map For(*both) Fields(#empdata (#emplst *private))
    Def_List Name(#EMPLST) Fields(#EMPNO) Type(*WORKING) Entrys(*MAX)
    Case Of_Field(#STDRENTRY)
    When Value_Is('= A')
    Fetch Fields(#EMPDATA) From_File(PSLMST) With_Key(#EMPNO)
    Message Msgtxt("Logic executed within this WebRoutine.")
    When Value_Is('= B')
    Transfer Toroutine(NavTrans)
    Message Msgtxt("This message will not be displayed.")
    When Value_Is('= C')
    Call Webroutine(NavCall)
    Message Msgtxt("Back from the CALL.")
    When Value_Is('= D')
    Message Msgtxt("Back from the TRANSFER.")
    When Value_Is('= E')
    #EMPDATA := *DEFAULT
    Endcase
    *
    Define Field(#empnow) Reffld(#empno)
    #empnow := #empno
    Clr_List Named(#EMPLST)
    Select Fields(#EMPNO) From_File(PSLMST)
    Add_Entry To_List(#EMPLST)
    Endselect
    If (#empnow *NE *blanks)
    #empno := #empnow
    Endif
    Endroutine
    Webroutine Name(NavCall) Desc('Navigation CALL')
    Endroutine
    Webroutine Name(NavTrans) Desc('Navigation TRANSFER')
    Endroutine

    End_ComWebRoutineWebRoutineWebRoutineWebRoutine

     

    Note: It is necessary to rebuild the list of employees (EMPLST) every time the NavMain WebRoutine is executed in order to populate the dropdown list of employee numbers. There are better ways to handle this, which will be covered in later exercises.

    10. Create the WEB_MAP for NavCall.

         The WEB_MAP will be very similar to the one in NavMain:

    • However EMPNO is the only field that needs to be taken as input.
    • All the employee fields need to be output from the WebRoutine. Use the GROUP_BY to map the employee fields.
    • Note that you have a global WEB_MAP for the field STDRENTRY which applies to every WebRoutine.
    • The field's display modes do not matter since this WebRoutine will not actually display anything.

         Add the following WEB_MAP statements to the WebRoutine:

    Web_Map For(*BOTH) Fields(#EMPNO)
    Web_Map For(*OUTPUT) Fields(#EMPDATA)

     

    11. Add the FETCH to NavCall.

    Fetch Fields(#EMPDATA) From_File(PSLMST) With_Key(#EMPNO)

     

         Your finished NavCall WebRoutine should appear as follows:

    Webroutine Name(NavCall) Desc('Navigation CALL')
    Web_Map For(*BOTH) Fields(#EMPNO)
    Web_Map For(*OUTPUT) Fields(#EMPDATA)
    Fetch Fields(#EMPDATA) From_File(PSLMST) With_Key(#EMPNO)
    Endroutine 

    12.  Create the WEB_MAP for WebRoutine NavTrans. These WEB_MAPs will be identical to NavCall.

    Web_Map For(*BOTH) Fields(#EMPNO)
    Web_Map For(*OUTPUT) Fields(#EMPDATA)

     

    13. Add the FETCH, set STDRENTRY to 'D' and TRANSFER back to NavMain.

    Fetch Fields(#EMPDATA) From_File(PSLMST) With_Key(#EMPNO)
    #STDRENTRY := 'D'
    Transfer Toroutine(NavMain)

     

         Your finished NavTrans WebRoutine should appear as follows:

    Webroutine Name(NavTrans) Desc('Navigation TRANSFER')
    Web_Map For(*BOTH) Fields(#EMPNO)
    Web_Map For(*OUTPUT) Fields(#EMPDATA)
    Fetch Fields(#EMPDATA) From_File(PSLMST) With_Key(#EMPNO)
    #STDRENTRY := 'D'
    Transfer Toroutine(NavMain)
    Endroutine

     

    14. Save and compile the WAM.