Page History
7.128.2 VALUECHECK Examples
Structuring Functions for Inline Validation
Structuring Functions to Use a Validation Subroutine
Using the VALUECHECK Command for Inline Validation
Using the VALUECHECK Command for Validation with a Subroutine
| Anchor | ||||
|---|---|---|---|---|
|
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 >>
...
<< 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.
| Anchor | ||||
|---|---|---|---|---|
|
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
...
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 >>
...
<< 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.
| Anchor | ||||
|---|---|---|---|---|
|
This example demonstrates how to use the VALUECHECK command within the main program block to check that a department code is one of a set of values.
DEF_LIST NAME(#EMPBROWSE) FIELDS(#EMPNO #DEPTMENT)
...
BEGIN_LOOP
REQUEST FIELDS(#EMPNO #DEPTMENT) BROWSELIST(#EMPBROWSE)
...
BEGINCHECK
...
BEGINCHECK
VALUECHECK FIELD(#DEPTMENT) WITH_LIST(ADM AUD FLT GAC) MSGTXT('The department code entered is not valid')
ENDCHECK
...
ADD_ENTRY TO_LIST(#EMPBROWSE)
END_
...
LOOP If the value of #DEPTMENT is not in the list of values specified with the 'WITH_LIST' parameter the message defined in the VALUECHECK command is issued and program control returns to the last screen displayed. In this case the last screen displayed is the REQUEST screen.
| Anchor | ||||
|---|---|---|---|---|
|
This example demonstrates how to use the VALUECHECK command inside a subroutine to check a department code is in a set of values.
After the user enters the requested details the VALIDATE subroutine is called. It checks that the value of #DEPTMENT is in the set of values specified with the 'WITH_LIST' parameter. If it is not the message defined in the VALUECHECK command is given and the DOUNTIL loop executes again. When a value for # DEPTMENT is entered that is in the set of specified values 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 #DEPTMENT)
...
BEGIN_LOOP
DOUNTIL COND(*NOERRORS)
REQUEST FIELDS(#EMPNO #DEPTMENT) BROWSELIST(#EMPBROWSE)
EXECUTE SUBROUTINE(VALIDATE)
ENDUNTIL
ENDUNTIL
ADD_ENTRY TO_LIST(#EMPBROWSE)
END_LOOP
...
...
SUBROUTINE NAME(VALIDATE)
CHANGE FIELD(#ERRORCNT) TO(0)
...
...
BEGINCHECK KEEP_COUNT(#ERRORCNT)
VALUECHECK FIELD(#DEPTMENT) WITH_LIST(ADM AUD FLT GAC) MSGTXT('The department code entered is not valid')
ENDCHECK IF_ERROR(*NEXT)
...
ENDROUTINE