Sample CMS EXEC Language Program

The following CMS EXEC program, called RUNCOB2 EXEC, compiles, loads, and executes a VS COBOL II source file:
*  RUNCOB2 EXEC  *
&CONTROL OFF NOMSG
&IF &INDEX LT 1 &GOTO -ERR1
COBOL2 &1
&IF &RETCODE NE 0 &EXIT
GLOBAL TXTLIB VSC2LTXT CMSLIB
&IF &RETCODE NE 0 &EXIT
LOAD &1 (START
&IF &RETCODE NE 0 &EXIT
&TYPE RUNCOB2 EXEC FINISHED
&EXIT
-ERR1
&TYPE PROGRAM NAME NOT GIVEN
&EXIT
RUNCOB2 EXEC works as follows:
  • The control statement &CONTROL sets the type of execution information displayed at the console. No execution messages or return codes are to be displayed here.
  • The control statement &INDEX is a special variable that contains the number of arguments entered by the caller. If no arguments are supplied, execution goes to label -ERR1.
  • COBOL2 &1 compiles the source program, specified by &1. If the COBOL2 command does not complete successfully, &RETCODE is nonzero and &EXIT is processed causing an immediate exit from the exec. The special variable &RETCODE contains the return code from the most recently executed CMS command. If &RETCODE is zero, the source program compiled successfully.
  • If the GLOBAL command fails, &RETCODE is nonzero and &EXIT is processed causing an immediate exit from the exec. If &RETCODE is zero, the TXTLIBs are successfully found and identified.
  • LOAD &1 (START loads the compiled program and executes it. If the LOAD command fails, &RETCODE is nonzero and &EXIT is processed causing an immediate exit from the exec. If &RETCODE is zero, the program was loaded and executed and the RUNCOB2 EXEC FINISHED message is displayed.
  • If too few arguments are supplied, execution is routed to the label -ERR1, where the warning message is typed. No &EXIT is required here, because processing ends at the end of the exec.

For information on the formats for the CMS EXEC control statements, use the HELP facility by using the HELP command.