Example 1: Request that the user input a product number, an order number and a quantity then perform validation checks against the fields:
REQUEST FIELDS(#PRODNO #ORDNUM #QUANTITY)
BEGINCHECK
FILECHECK FIELD(#PRODNO) USING_FILE(PRODUCT) MSGTXT('Product number not found in product master')
RANGECHECK FIELD(#ORDNUM) RANGE(A000000 Z999999) MSGTXT('Order number is not in range A000000 - Z999999')
RANGECHECK FIELD(#QUANTITY) RANGE(1 9999) MSGTXT('Quantity ordered must be in range 1 - 9999')
ENDCHECK
is identical to the following example, because of the default value IF_ERROR(*LASTDIS) on the ENDCHECK command:
REQUEST FIELDS(#PRODNO #ORDNUM #QUANTITY)
L1:
BEGINCHECK
FILECHECK FIELD(#PRODNO) USING_FILE(PRODUCT) MSGTXT('Product number not found in product master')
RANGECHECK FIELD(#ORDNUM) RANGE(A000000 Z999999) MSGTXT('Order number is not in range A000000 - Z999999')
RANGECHECK FIELD(#QUANTITY) RANGE(1 9999) MSGTXT('Quantity ordered must be in range 1 - 9999')
ENDCHECK IF_ERROR(L1)
Example 2: The *LASTDIS default value actually means the "last display at this nesting level (or higher)" as is indicated in the following example:
REQUEST FIELDS(#FIELD01) <-----------------------------
IF COND('#FIELD01 *LT 10') |
REQUEST FIELDS(#FIELD02) <------------ |
BEGINCHECK | |
RANGECHECK FIELD(#FIELD01) RANGE(5 9) | |
RANGECHECK FIELD(#FIELD02) RANGE(10 20) | |
ENDCHECK --------------------------------- |
ELSE |
BEGINCHECK |
RANGECHECK FIELD(#FIELD01) RANGE(15 19) |
ENDCHECK --------------------------------------
ENDIF
The arrows indicate where control is passed if either of the ENDCHECK commands find a validation error in their respective validation blocks.
If this example was coded it may be hard to use because the user does not get a chance to correct an error in FIELD01 if the value specified is less than 10 but not in the range 5 to 9. In this case the error message would appear on line 22/24 of the screen but the FIELD01 would not be on the display and thus could not be corrected.
This example might be better coded as:
REQUEST FIELDS(#FIELD01) <----------------
BEGINCHECK |
IF COND('#FIELD01 *LT 10') |
RANGECHECK FIELD(#FIELD01) RANGE(5 9) |
ELSE |
RANGECHECK FIELD(#FIELD01) RANGE(15 19) |
ENDIF |
ENDCHECK --------------------------------------
IF COND('#FIELD01 *LT 10')
REQUEST FIELDS(#FIELD02) <-------------
BEGINCHECK |
RANGECHECK FIELD(#FIELD02) RANGE(10 20) |
ENDCHECK ----------------------------------
ELSE
ENDIF