Sample EXEC 2 Language Program
The following exec, called ADD, asks you for three numbers that you want to add, determines if you entered numeric data, and adds the three numbers you entered.
ADD EXEC contains the following:
&TRACE
&ERROR &EXIT &RETCODE
&TYPE Enter three numbers you want to add:
&READ ARGS
&IF &N = 3 &GOTO -ADDNUMS
&TYPE You must enter three numbers
&READ ARGS
&IF &N = 3 &GOTO -ADDNUMS
&GOTO -ERROR
-ADDNUMS
&TYPE1 = &DATATYPE OF &1
&TYPE2 = &DATATYPE OF &2
&TYPE3 = &DATATYPE OF &3
&IF &TYPE1 NE NUM &GOTO -ERROR
&IF &TYPE2 NE NUM &GOTO -ERROR
&IF &TYPE3 NE NUM &GOTO -ERROR
&SUM = &1 + &2 + &3
&TYPE The sum of &1 &2 and &3 is &SUM
&EXIT
-ERROR
&TYPE You did not enter three valid items. This program is ending.
&EXIT The following describes the sequence of execution:
- The
&TRACEindicates to the system that this exec is written in the EXEC 2 language. - The
&ERRORcontrol statement specifies that if a z/VM command results in a nonzero return code, the&EXITstatement is executed. In this example, the return code, indicated by the control word&RETCODE, is passed upon exit. - The
&TYPEstatement asks you to enter three numbers. The&READ ARGSstatement reads the items you enter and assigns them to the variables&1,&2, and&3. - The
&IFstatement checks to see if you entered three items. If you did not, you are asked again to enter three numbers. If you still do not enter three items, an error message is displayed and the program ends. - If you entered three items, execution flows to
-ADDNUMS. The next six lines check to see if you entered only numbers and not any other characters. The&DATATYPE OFfunction yields a value ofNUM
if&1,&2, or&3is a valid number and yields a value ofCHAR
if&1,&2, or&3is anything else. If&TYPE1,&TYPE2, or&TYPE3does not containNUM
, execution flows to-ERRORand the program ends. - If
&TYPE1,&TYPE2, or&TYPE3containsNUM
, then&1,&2, and&3are added together and the sum is displayed.
Many EXEC 2 facilities are similar to CMS EXEC facilities. Some control statements and special variables have not been covered here. For full details on the EXEC 2 processor facilities, see the VM/SP: EXEC 2 Reference.