7 16 3 DATECHECK Examples

LANSA Technical

7.16.3 DATECHECK Examples

Structuring Functions for Inline Validation

Structuring Functions to Use a Validation Subroutine

Using the DATECHECK Command for Inline Validation

Using the DATECHECK 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 DATECHECK Command for Inline Validation

This example demonstrates how to use the DATECHECK command within the main program block to check the validity of date fields.

DEF_LIST   NAME(#EMPBROWSE) FIELDS(#EMPNO #GIVENAME #SURNAME)
          
BEGIN_LOOP 
REQUEST    FIELDS(#EMPNO #STARTDTE) BROWSELIST(#EMPBROWSE)
           
BEGINCHECK 
DATECHECK  FIELD(#STARTDTE) IN_FORMAT(*DDMMYY) BEFORE(30) AFTER(0) MSGTXT('Start date is not in the right format or not in the last month')
ENDCHECK   
           
ADD_ENTRY  TO_LIST(#EMPBROWSE)
END_LOOP
 

If the value of #STARTDTE is not in format of DDMMYY, is more than 30 days in the past or is in the future the message defined with the DATECHECK 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 DATECHECK Command for Validation with a Subroutine

This example demonstrates how to use the DATECHECK command inside a subroutine to check the validity of date fields.

After the user enters the requested details the VALIDATE subroutine is called. It checks that the value of #STARTDTE is in the DD/MM/YY format, is 0 days in the future and is not more than 30 days in the past. If this is not true the message defined in the DATECHECK command is given and the DOUNTIL loop executes again. When #STARTDTE is the correct format and value 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 #STARTDTE)
           
BEGIN_LOOP 
DOUNTIL    COND(*NOERRORS)
REQUEST    FIELDS(#EMPNO #STARTDTE) 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)
DATECHECK  FIELD(#STARTDTE) IN_FORMAT(*DDMMYY) BEFORE(30) AFTER(0) MSGTXT('Start date is not in the right format or not in the last month')
ENDCHECK   IF_ERROR(*NEXT)
           
ENDROUTINE