7.75.3 IF_STATUS Examples

Example 1: Use the IF_STATUS command to trap a record not found condition and abort the function with an error:

   FETCH     FIELDS(#NAMEINFO) FROM_FILE(NAMES) WITH_KEY(#CUSTNO)
IF_STATUS IS_NOT(*OKAY)
ABORT     MSGTXT('Customer name details not found')
ENDIF

which is identical to the following:

   FETCH     FIELDS(#NAMEINFO) FROM_FILE(NAMES) WITH_KEY(#CUSTNO)
IF        COND('#IO$STS *NE OK')
ABORT     MSGTXT('Customer name details not found')
ENDIF

Example 2: Modify the previous example to display the details (if found) else to abort the function:

   FETCH     FIELDS(#NAMEINFO) FROM_FILE(NAMES) WITH_KEY(#CUSTNO)
IF_STATUS IS(*OKAY)
DISPLAY   FIELDS(#NAMEINFO)
ELSE
ABORT     MSGTXT('Customer name details not found')
ENDIF

which is identical to the following:

   FETCH     FIELDS(#NAMEINFO) FROM_FILE(NAMES) WITH_KEY(#CUSTNO)
IF        COND('#IO$STS = OK')
DISPLAY   FIELDS(#NAMEINFO)
ELSE
ABORT     MSGTXT('Customer name details not found')
ENDIF
  • No labels