7 56 2 IF_MODE Examples

LANSA Technical

7.56.2 IF_MODE Examples

The following example applies to the IF_MODE command.

Create a simple inquire/add/update/delete function on a file called NAMES. Use the IF_MODE command to test the mode that the screen was in at the time the enter key was pressed:

     GROUP_BY NAME(#NAMEINFO) FIELDS(#CUSTNO #NAME #ADD1 #ADD2 #POSTCD)
 
L10: CHANGE   FIELD(#CUSTNO) TO(*DEFAULT)
 
    MESSAGE  MSGTXT('Specify customer to review or use ADD key to add one')
 
L15: SET_MODE TO(*DISPLAY)
    REQUEST  FIELDS(#CUSTNO) ADD_KEY(*YES)
    *
    * Add a new customer to the file ......
    *
    IF_MODE  IS(*ADD)
         REQUEST  FIELDS(#NAMEINFO)
         INSERT   FIELDS(#NAMEINFO) TO_FILE(NAMES)
    *
    * Else review / change / delete an existing customer
    *
    ELSE
         FETCH    FIELDS(#NAMEINFO) FROM_FILE(NAMES) WITH_KEY(CUSTNO) NOT_FOUND(L15) ISSUE_MSG(*YES)
 
         DISPLAY  FIELDS(#NAMEINFO) CHANGE_KEY(*YES) DELETE_KEY(*YES)
 
         IF_MODE  IS(*CHANGE)
         UPDATE   FIELDS(#NAMEINFO) IN_FILE(NAMES)
         ENDIF
 
         IF_MODE  IS(*DELETE)
         DELETE   FROM_FILE(NAMES)
         ENDIF
 
    ENDIF
    *
    * Go back and request next customer
    *
    GOTO     LABEL(L10)