Front-end prompting verifies input data before the CLIST uses it
in other statements. For example, the CALC CLIST in Figure 1 assumed that &FVALUE and &LVALUE
represented valid numeric values or variables containing valid numeric
values. It also assumed that &OPER represented a valid arithmetic
operator.
In CALCFTND, shown in The CALCFTND CLIST, the CLIST
first ensures that &FVALUE is numeric, not character data. The
WRITE statement message is tailored to address the possibility that
the invoker is including decimal points in the value. The CLIST views
such a value as character data, not numeric data. The DO-WHILE-END
sequence executes until the invoker supplies a valid numeric value.
A similar DO-WHILE-END sequence is provided for &LVALUE;
The verification of &OPER is somewhat more involved. &OPER
must be a valid arithmetic operator, one of the following symbols: +,
-, *, /, **, //. Therefore, the condition for the corresponding
DO-WHILE-END sequence requires a logical ANDing of comparative expressions.
Each expression is true when &OPER does not equal the operator
in the expression. When all of the expressions are true, &OPER
is not a valid arithmetic operator. To ensure that the CLIST views &OPER
and the valid arithmetic operators as character data, enclose them
in &STR built-in functions.
The CALCFTND CLIST
PROC 0 FVALUE( ) OPER( ) LVALUE( )
/**********************************************************************/
/* IF &FVALUE IS NOT VALID, CONTINUE PROMPTING THE USER TO ENTER */
/* AN ACCEPTABLE VALUE. */
/**********************************************************************/
CONTROL ASIS /* Allow upper and lower case WRITE statements */
SET &NULL =
DO WHILE &DATATYPE(&FVALUE) ¬= NUM
IF &STR(&FVALUE) = &NULL THEN +
WRITE Please enter a first value without decimal points &STR(-)
ELSE +
DO
WRITENR Your first value is not numeric. Reenter a number without
WRITE decimal points &STR(-)
END
READ &FVALUE
END
/**********************************************************************/
/* IF &OPER IS NOT VALID, CONTINUE PROMPTING THE USER TO ENTER */
/* AN ACCEPTABLE VALUE. */
/**********************************************************************/
DO WHILE &STR(&OPER)¬=&STR(+) AND &STR(&OPER)¬=&STR(-) AND +
&STR(&OPER)¬=&STR(*) AND &STR(&OPER)¬=&STR(/) AND +
&STR(&OPER)¬=&STR(**) AND &STR(&OPER)¬=&STR(//)
IF &STR(&OPER) = &NULL THEN +
DO
WRITE Please enter a valid arithmetic operator (+,-,*,/,**,//)
WRITE enclosed in parentheses, for example, (+) or (-).
END
ELSE +
DO
WRITE Your second value is not a valid operator (+,-,*,/,**,//).
WRITE Reenter this value, using one of the valid arithmetic
WRITE operators enclosed in parentheses, for example, (+) or (-).
END
READ &OPER
END
/**********************************************************************/
/* IF &LVALUE IS NOT VALID, CONTINUE PROMPTING THE USER TO ENTER */
/* AN ACCEPTABLE VALUE. */
/**********************************************************************/
DO WHILE &DATATYPE(&LVALUE) ¬= NUM
IF &STR(&LVALUE) = &NULL THEN +
WRITE Please enter a second value without decimal points &STR(-)
ELSE +
DO
WRITENR Your last value is not numeric. Reenter a number without
WRITE decimal points &STR(-).
END
READ LVALUE
END
/**********************************************************************/
/* ONCE THE OPERANDS HAVE BEEN VERIFIED, EVALUATE THE EXPRESSION AND */
/* DISPLAY THE RESULT AT THE TERMINAL. */
/**********************************************************************/
WRITE &FVALUE&OPER&LVALUE = &EVAL(&FVALUE&OPER&LVALUE)