7 7 3 CALLCHECK Examples

LANSA Technical

7.7.3 CALLCHECK Examples

Structuring Functions for Inline Validation

Structuring Functions to Use a Validation Subroutine

Using the CALLCHECK Command for Inline Validation

Using the CALLCHECK Command for Validation with a Subroutine

Structuring Functions for Inline Validation

Typically functions using validation commands (eg: 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 (eg: 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 CALLCHECK Command for Inline Validation

This example demonstrates how to use the CALLCHECK command within the main program block with an RDML function as the validation program.

After the user enters the requested details, the start date is checked to make sure it falls on a working day by calling the WORKDAY RDML program. If the WORKDAY program returns a negative response the defined message is given and program control returns to the last screen displayed, the Request screen in this case.

DEF_LIST   NAME(#EMPBROWSE) FIELDS(#EMPNO #STARTDTE)
           
BEGIN_LOOP 
REQUEST    FIELDS(#EMPNO #STARTDTE) BROWSELIST(#EMPBROWSE)
           
BEGINCHECK 
CALLCHECK  FIELD(#STARTDTE) BY_CALLING(WORKDAY) PROG_TYPE(FUN) MSGTXT('The supplied date is not a working day.')
ENDCHECK   
           
ADD_ENTRY  TO_LIST(#EMPBROWSE)
END_LOOP
 

The WORKDAY function is defined as follows;

FUNCTION   OPTIONS(*DIRECT *LIGHTUSAGE *MLOPTIMISE *NUM_FIELD_VALIDATE)
           
DEFINE     FIELD(#TESTDATEC) TYPE(*CHAR) LENGTH(6)
DEFINE     FIELD(#TESTDATEN) LENGTH(6) DECIMALS(0) REFFLD(#DATE) EDIT_CODE(4) DEFAULT(0) TO_OVERLAY(#TESTDATEC)
DEFINE     FIELD(#DAYOFWEEK) TYPE(*CHAR) LENGTH(3)
           
CHANGE     FIELD(#TESTDATEN) TO(#VALFLD$NV)
USE        BUILTIN(CONVERTDATE) WITH_ARGS(#TESTDATEC B R) TO_GET(#DAYOFWEEK)
CASE       OF_FIELD(#DAYOFWEEK)
WHEN       VALUE_IS('= MON' '= TUE' '= WED' '= THU' '= FRI')
CHANGE     FIELD(#VALFLD$RT) TO('''1''')
OTHERWISE  
CHANGE     FIELD(#VALFLD$RT) TO('''0''')
ENDCASE    
           
RETURN
 

For more information related to creating complex logic validation functions see the technical notes for *ALP_FIELD_VALIDATE and *NUM_FIELD_VALIDATE in the parameters section for the FUNCTION command.

Using the CALLCHECK Command for Validation with a Subroutine

This example demonstrates how to use the CALLCHECK command inside a subroutine with an RDML function as the validation program.

After the user enters the requested input code the VALIDATE subroutine is called. It checks that the input code is in the correct format by calling the ANUMBER RDML program. If the ANUMBER program returns a negative response the message defined in the CALLCHECK command is given and the DOUNTIL loop executes again. When the ANUMBER program returns a positive response the DOUNTIL loop ends and processing of the verified input is done.

DEFINE     FIELD(#ERRORCNT) REFFLD(#STD_NUM)
DEF_COND   NAME(*NOERRORS) COND('#ERRORCNT = 0')
DEFINE     FIELD(#INPUT) TYPE(*CHAR) LENGTH(7)
DEF_LIST   NAME(#EMPBROWSE) FIELDS(#INPUT)
           
BEGIN_LOOP 
DOUNTIL    COND(*NOERRORS)
REQUEST    FIELDS(#INPUT) 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)
CALLCHECK  FIELD(#INPUT) BY_CALLING(ANUMBER) PROG_TYPE(FUN) MSGTXT('The input code format must be Annnnnn.')
ENDCHECK   IF_ERROR(*NEXT)
           
ENDROUTINE
 

The ANUMBER program is defined as follows:

FUNCTION   OPTIONS(*DIRECT *LIGHTUSAGE *MLOPTIMISE *ALP_FIELD_VALIDATE)
DEFINE     FIELD(#INPUT) TYPE(*CHAR) LENGTH(7)
DEFINE     FIELD(#INPUTA1) TYPE(*CHAR) LENGTH(1) TO_OVERLAY(#INPUT) 
DEFINE     FIELD(#INPUTA6) TYPE(*CHAR) LENGTH(6) TO_OVERLAY(#INPUT 2) 
DEFINE     FIELD(#DECIMAL) TYPE(*DEC) LENGTH(1) DECIMALS(1)
DEFINE     FIELD(#RTN_CODE) TYPE(*CHAR) LENGTH(1)
           
CHANGE     FIELD(#INPUT) TO(#VALFLD$AV)
USE        BUILTIN(CHECKNUMERIC) WITH_ARGS(#INPUTA6 6 0) TO_GET(#STD_NUM #DECIMAL #RTN_CODE)
           
IF         COND('(#INPUTA1 = A) and (#RTN_CODE = Y)')
CHANGE     FIELD(#VALFLD$RT) TO('''1''')
ELSE       
CHANGE     FIELD(#VALFLD$RT) TO('''0''')
ENDIF      
           
RETURN
 

For more information related to creating complex logic validation functions see the technical notes for *ALP_FIELD_VALIDATE and *NUM_FIELD_VALIDATE in the parameters section for the FUNCTION command.