7.48.3 FILECHECK Examples
Structuring Functions for Inline Validation
Structuring Functions to Use a Validation Subroutine
Using the FILECHECK Command for Inline Validation
Using the FILECHECK 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 FILECHECK Command for Inline Validation
This example demonstrates how to use the FILECHECK command within the main program block to check an employee number against entries in a personnel file.
DEF_LIST NAME(#EMPBROWSE) FIELDS(#EMPNO #GIVENAME #SURNAME)
BEGIN_LOOP
REQUEST FIELDS(#EMPNO #GIVENAME #SURNAME) BROWSELIST(#EMPBROWSE)
BEGINCHECK
FILECHECK FIELD(#EMPNO) USING_FILE(PSLMST) FOUND(*ERROR) NOT_FOUND(*NEXT) MSGTXT('Employee number supplied already exists')
ENDCHECK
ADD_ENTRY TO_LIST(#EMPBROWSE)
END_LOOP
If the value of #EMPNO is found in the file PSLMST the message defined with the FILECHECK 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 FILECHECK Command for Validation with a Subroutine
This example demonstrates how to use the FILECHECK command inside a subroutine to check an employee number against entries in a personnel file.
After the user enters the requested details the VALIDATE subroutine is called. It checks that the value of #EMPNO is not already present in the PSLMST file. If this is true the message defined in the FILECHECK command is given and the DOUNTIL loop executes again. When a #EMPNO value is entered that is not found in the file 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)
FILECHECK FIELD(#EMPNO) USING_FILE(PSLMST) FOUND(*ERROR) NOT_FOUND(*NEXT) MSGTXT('Employee number supplied already exists')
ENDCHECK IF_ERROR(*NEXT)
ENDROUTINE