7 78 2 RANGECHECK Examples

LANSA Technical

7.78.2 RANGECHECK Examples

Structuring Functions for Inline Validation

Structuring Functions to Use a Validation Subroutine

Using the RANGECKECK Command for Inline Validation

Using the RANGECHECK Command for Validation with a Subroutine

Structuring Functions for Inline Validation

Typically functions using validation commands (e.g.: CONDCHECK, DATECHECK, FILECHECK, RANGECHECK and VALUECHECK) are structured for inline validation like this:

BEGIN_LOOP 
REQUEST    << INPUT >>
BEGINCHECK 
           << USE CHECK COMMANDS TO VALIDATE INPUT HERE >>
ENDCHECK   
           << PROCESS THE VALIDATED INPUT HERE >>
END_LOOP
 

If a validation command inside the BEGINCHECK / ENDCHECK command block detects a validation error control is passed back to the REQUEST command. This happens because of the default IF_ERROR(*LASTDIS) parameter on the ENDCHECK command.  

Structuring Functions to Use a Validation Subroutine

Typically functions using validation commands (e.g.: CONDCHECK, DATECHECK, FILECHECK, RANGECHECK and VALUECHECK) are structured for subroutine validation like this:

DEFINE     FIELD(#ERRORCNT) REFFLD(#STD_NUM)
DEF_COND   NAME(*NOERRORS) COND('#ERRORCNT = 0')
           
BEGIN_LOOP 
DOUNTIL    COND(*NOERRORS)
REQUEST    << INPUT >>
EXECUTE    SUBROUTINE(VALIDATE)
ENDUNTIL   
           << PROCESS THE VALIDATED INPUT HERE >>
END_LOOP   
           
SUBROUTINE NAME(VALIDATE)
CHANGE     FIELD(#ERRORCNT) TO(0)
BEGINCHECK KEEP_COUNT(#ERRORCNT)
           << USE CHECK COMMANDS TO VALIDATE INPUT HERE >>
ENDCHECK   IF_ERROR(*NEXT)
ENDROUTINE
 

If a validation command inside the BEGINCHECK / ENDCHECK command block detects a validation error control is returned to the main function loop with #ERRORCNT > 0. 

Using the RANGECKECK Command for Inline Validation

This example demonstrates how to use the RANGECHECK command within the main program block to check that an employee number is within a range of values.

DEF_LIST   NAME(#EMPBROWSE) FIELDS(#EMPNO #GIVENAME #SURNAME)
*           
BEGIN_LOOP 
REQUEST    FIELDS(#EMPNO #GIVENAME #SURNAME) BROWSELIST(#EMPBROWSE)
*           
BEGINCHECK 
RANGECHECK FIELD(#EMPNO) RANGE((A0000 A9999)) MSGTXT('Employee number has to be in the range A0000 - A9999')
ENDCHECK   
*           
ADD_ENTRY  TO_LIST(#EMPBROWSE)
END_LOOP 
 

If the value of #EMPNO is outside the range of A0000 to A9999 the message defined with the RANGECHECK command is issued and program control returns to the last screen displayed. In this case the last screen displayed is the REQUEST screen.

Using the RANGECHECK Command for Validation with a Subroutine

This example demonstrates how to use the RANGECHECK command inside a subroutine to check an employee number is within a range of values.

After the user enters the requested details the VALIDATE subroutine is called. It checks that the value of #EMPNO is within the range of A0000 to A9999. If this is not true the message defined in the RANGECHECK command is given and the DOUNTIL loop executes again. When a value for #EMPNO is entered that is within the specified range the DOUNTIL loop ends and processing of the verified input is done.

DEFINE     FIELD(#ERRORCNT) TYPE(*DEC) LENGTH(3) DECIMALS(0) DEFAULT(0)
DEF_COND   NAME(*NOERRORS) COND('#ERRORCNT = 0')
DEF_LIST   NAME(#EMPBROWSE) FIELDS(#EMPNO #GIVENAME #SURNAME)
*           
BEGIN_LOOP 
DOUNTIL    COND(*NOERRORS)
REQUEST    FIELDS(#EMPNO #GIVENAME #SURNAME) BROWSELIST(#EMPBROWSE)
EXECUTE    SUBROUTINE(VALIDATE)
ENDUNTIL   
*           
ADD_ENTRY  TO_LIST(#EMPBROWSE)
END_LOOP   
*           
SUBROUTINE NAME(VALIDATE)
CHANGE     FIELD(#ERRORCNT) TO(0)
*           
BEGINCHECK KEEP_COUNT(#ERRORCNT)
RANGECHECK FIELD(#EMPNO) RANGE((A0000 A9999)) MSGTXT('Employee number has to be in the range A0000 - A9999')
ENDCHECK   IF_ERROR(*NEXT)
*           
ENDROUTINE