[OpenVMS documentation]
[Site home] [Send comments] [Help with this site] [How to order documentation] [OpenVMS site] [Compaq site]
Updated: 11 December 1998

OpenVMS User's Manual


Previous Contents Index

15.6.5 Executing Command Procedures as Batch Jobs

If you use command procedures that require lengthy processing time (for example, compiling or assembling large programs), submitting these procedures as batch jobs will allow you to continue using your terminal interactively.

To execute a command procedure in batch mode, submit your command procedure to a batch queue (a list of batch jobs waiting to execute) by entering the DCL command SUBMIT. When you submit a job, it is directed to the default batch queue SYS$BATCH where it is added to the end of the queue of jobs waiting to be executed. When the jobs preceding yours are completed, your job is executed. On OpenVMS systems, the number of batch jobs that can execute simultaneously is specified when the batch queue is created by the system manager.

The following example shows how to execute the command procedure named JOB1.COM. The SUBMIT command uses the default file type .COM; therefore you do not have to enter the file type if your command procedure has the file type .COM:


$ SUBMIT JOB1 
Job JOB1 (queue SYS$BATCH, entry 651, started on SYS$BATCH)) 

15.6.5.1 Remote Batch Jobs

If your system is part of a network, you can submit a command procedure as a batch job on a remote node. Within a command procedure, you can use DCL commands to open and close files on remote notes and to read and write records in those files, using the same commands and qualifiers for local files.

15.6.5.2 Restarting Batch Jobs

By default, if the system fails before the job is finished, batch jobs are reexecuted beginning with the first line. However, you can use the following symbols in your command procedure to specify a different restarting point:

Using $RESTART and BATCH$RESTART

The following procedure describes how to use the $RESTART and the BATCH$RESTART symbols:
Step Action
1 Begin each possible starting point of the procedure with a label.
2 As the first step in each section, equate the value of BATCH$RESTART to the label using the SET RESTART_VALUE command.
3 At the beginning of the procedure, test $RESTART.
4 If $RESTART is true, issue a GOTO statement using BATCH$RESTART as the transfer label.

The following command procedure extracts a number of modules from a library, concatenates those modules, and then sorts the resulting file:


$! SORT_MODULES.COM 
! 
$! Set default to the directory containing 
$! the library whose modules are to be sorted 
$ SET DEFAULT WORKDISK:[ACCOUNTS.DATA83] 
$! 
$! Check for restarting 
$ IF $RESTART THEN GOTO "BATCH$RESTART" 
$! 
$ EXTRACT_LIBRARIES: 
$ SET RESTART_VALUE=EXTRACT_LIBRARIES 
   .
   .
   .
$ CONCATENATE_LIBRARIES: 
$ SET RESTART_VALUE=CONCATENATE_LIBRARIES 
   .
   .
   .
$ SORT_FILE: 
$ SET RESTART_VALUE=SORT_FILE 
   .
   .
   .
$ EXIT 

If this command procedure aborts, it reexecutes from the beginning of the file, from the statement labeled CONCATENATE_LIBRARIES, or from the statement labeled SORT_FILE, depending on the value of BATCH$RESTART. If you were extracting a number of separate modules, you could make each extraction a separate section.

15.6.6 Executing Command Procedures on Disk and Tape Volumes

The following sections describe how to execute command procedures on disk and tape volumes.

15.6.6.1 Executing on Private Disk Volumes

When you submit a command procedure with the SUBMIT command, you cannot access files on allocated devices. You can, however, execute a command procedure that is located on a private disk volume if the volume is mounted with the /SHARE qualifier.

15.6.6.2 Executing on Tape Volumes

You can execute command procedures that reside on tape volumes if:

If either of these conditions occur, you can execute the command procedure by doing the following:
Step Action
1. Copy the command procedure to a shared disk volume.
2. Execute the command procedure on the shared disk volume.

15.7 Exiting and Interrupting Command Procedures

When you use any of the methods described in this section to exit from a command procedure, you need to be aware of command levels.

A command level is an input stream for the DCL level interpreter. When you enter commands at your terminal, you are entering commands at command level 0. A simple interactive command procedure (such as CLEANUP.COM) executes at command level 1. When the procedure terminates and the DCL prompt reappears on your screen, you are back at command level 0.

15.7.1 Methods of Exiting

There are three ways to exit from a command procedure while it is executing:

Exiting with the EXIT Command

If an exit is caused by the end of the procedure or an EXIT command, control returns to the next higher command level. You can return a status value to the next higher command level by specifying the value as the parameter of the EXIT command.

If you invoke the command procedure called SUB at the DCL level and SUB calls the subroutine SUB1, the following occurs:

  1. Exiting from SUB1 returns you to SUB at the command line following the call to SUB1.
  2. Exiting from SUB returns you to DCL command level.

Exiting with the STOP Command

If an exit is caused by a STOP command, control always returns to DCL command level, regardless of the command level in which the STOP command executes.

If you execute the STOP command in a batch job, the batch job terminates.

Exiting with Ctrl/Y

You can interrupt a command procedure by pressing Ctrl/Y and then using the EXIT or STOP command to terminate the procedure. In this case, both the EXIT and STOP command return you to the DCL level.

In the following example, the TESTALL procedure is interrupted by pressing Ctrl/Y. The EXIT command terminates processing of the procedure and returns you to DCL level. (Note that you can also enter the STOP command after you interrupt the procedure.)


$ @TESTALL[Return]
[Ctrl/Y]
$ EXIT[Return]
$ 

15.7.2 Exit-Handling Routines

When you interrupt a command procedure, if the command (or image) that you interrupt declares any exit-handling routines, the EXIT command gives these routines control. However, the STOP command does not execute these routines.

15.8 Handling Errors

By default, the command interpreter executes an EXIT command when a command results in an error or severe error. This causes the procedure to exit to the previous command level. For other severity levels (success, warning, and informational), the command procedure continues.

There is one exception to the way that the command interpreter handles errors. If you reference a label in a command procedure and the label does not exist (for example, if you include the command GOTO ERR1 and ERR1 is not used as a label in the procedure), the GOTO command issues a warning and the command procedure exits.

When the system issues an EXIT command as part of an error-handling routine, it passes the value of $STATUS back to the previous command level, with one change. The command interpreter sets the high-order digit of $STATUS to 1 so that the command interpreter does not redisplay the message associated with the status value.

In the following example, the command procedure TEST.COM contains an error in the output file specification:


$ CREATE DUMMY.DAT\
THIS IS A TEST FILE 
$ SHOW TIME 

When you execute this procedure, the CREATE command returns an error in $STATUS and displays the corresponding message. The command interpreter then examines the value of $STATUS, determines that an error occurred, issues an EXIT command, and returns the value of $STATUS. When the procedure exits, the error message is not redisplayed because the CREATE command already displayed the message once. At DCL command level, you can see that $STATUS contains the error message but the high-order digit has been set to 1. For example:


$ @TEST 
%CREATE-E-OPENOUT, error opening DUMMY.DAT as output 
-RMS-F-SYN, file specification syntax error 
%DCL-W-SKPDAT, image data (records not beginning with "$") ignored 
$ SHOW SYMBOL $STATUS 
  $STATUS = "%X109110A2" 
$ WRITE SYS$OUTPUT F$MESSAGE(%X109110A2) 
  %CREATE-E-OPENOUT, error opening !AS as output 

15.8.1 Default Error Actions

The following table describes the default action taken when an error condition or a Ctrl/Y interruption occurs while a command procedure is executing. You can override these default actions with the ON, SET [NO]ON, and SET [NO]CONTROL=Y commands.
Interrupt Default Action
Error or severe error Procedure exits to the next command level.
Ctrl/Y at DCL command level or command level 1 Procedure is interrupted; the procedure can continue if no other image forces it to exit.
Ctrl/Y at command level lower than level 1 Procedure exits to the next higher command level.

15.9 Other Methods of Error Handling

The following sections describe other methods of handling errors.

15.9.1 ON Command

The ON command specifies an action to be performed if an error of a certain severity or greater severity occurs. If such an error occurs, the system takes the following actions:

An ON command action is executed only once. Therefore, after a command procedure performs the action specified in an ON command, the default error action is reset.

The action specified by an ON command applies only within the command level in which the command is executed. Therefore, if you execute an ON command in a procedure that invokes another procedure, the ON command action does not apply to the nested procedure.

The format of the ON command is as follows:

ON condition THEN [$] command 

Where "condition" is one of the following keywords:
ON Keyword Action Taken
WARNING Command procedure performs the specified action if a warning, error, or severe error occurs.
ERROR Command procedure performs the specified action if an error or severe error occurs. The procedure continues if a warning occurs.
SEVERE_ERROR Command procedure performs the specified action if a severe (fatal) error occurs. The procedure continues if a warning or error occurs.

If an ON command action is established for a specific severity level, the command interpreter performs the specified action when errors of the same or worse severity occur. When less severe errors occur, the command interpreter continues processing the file.

Example: Using the ON Command

This command can be used to override the default error handling so that a procedure exits when warnings, errors, or severe errors occur:


$ ON WARNING THEN EXIT 

Example: Resuming After an Error

If your command procedure incudes this command, the command procedure executes normally until an error or severe error occurs:


$ ON ERROR THEN GOTO ERR1 

If such an error occurs, then the procedure resumes executing at ERR1. $STATUS and $SEVERITY are set to success and the default error action is reset. If a second error occurs before another ON or SET NOON command is executed, the procedure exits to the previous command level. The action specified by an ON command applies only within the command level in which the command is executed. Therefore, if you execute an ON command in a procedure that invokes another procedure, the ON command action does not apply to the nested procedure.

Figure 15-1 illustrates ON command actions.

Figure 15-1 ON Command Actions


  1. This ON command overrides the default command action (on warning, continue; on error or severe error, exit). If an error or severe error occurs while A.FOR is being compiled, the command procedure continues with the next command.
  2. The default command action is reset if the previous ON command takes effect. Thus, if an error or severe error occurs while both A.FOR and B.FOR are being compiled, the command procedure exits.
  3. If a warning, error, or severe error occurs while C.FOR is being compiled, the command procedure exits.
  4. If the command procedure does not exit before a command is executed, the command action takes effect.

The sample command procedures FORTUSER.COM and CALC.COM in Appendix C also illustrate the use of the ON command to establish error handling.

15.10 Using the SET NOON Command

You can prevent the command interpreter from checking the status returned from commands by using the SET NOON command in your command procedure, which sets the ON command to NO status. When you use the SET NOON command, the command interpreter continues to place values in $STATUS and $SEVERITY but does not perform any error checking. You can restore error checking with the SET ON command or with an ON command.

When a procedure disables error checking, it can explicitly check the value of $STATUS following the execution of a command or program.

In the following example, the SET NOON command preceding the RUN commands ensures that the command procedure continues if either of the programs TESTA or TESTB return an error condition. The SET ON command restores the default error checking by the command interpreter.


$ SET NOON 
$ RUN TESTA 
$ RUN TESTB 
$ SET ON 

In the following example, the first IF command checks whether $STATUS has a true value (that is, if it is an odd numeric value). If so, the FORTRAN command was successful and the LINK command executes. After the LINK command executes, $STATUS is tested again. If $STATUS is odd, the RUN command executes; otherwise, the RUN command does not execute. The SET ON command restores the current ON condition action; that is, whatever condition was in effect before the SET NOON command was executed:


$ SET NOON 
$ FORTRAN MYFILE 
$ IF $STATUS THEN LINK MYFILE 
$ IF $STATUS THEN RUN MYFILE 
$ SET ON 

The SET ON or SET NOON command applies only at the current command level; that is, the command level at which the command is executed. If you use the SET NOON command in a command procedure that calls another command procedure, the default error-checking mechanism will be in effect within the nested procedure. Note that SET NOON has no meaning when entered interactively at DCL level.

15.11 Handling Ctrl/Y Interruptions

By default, when you press Ctrl/Y while a command procedure is executing, the command interpreter prompts for command input at a special command level called Ctrl/Y command level. From Ctrl/Y command level, you can enter DCL commands that are executed within the command interpreter and then resume execution of the command procedure with the CONTINUE command. In addition, you can stop the procedure by entering a DCL command that forces the command procedure to stop executing.

This section describes methods of overriding the way that command procedures process Ctrl/Y interruptions by using the ON command.

15.11.1 Stopping Command Procedures

You can interrupt a command procedure that is executing interactively by pressing Ctrl/Y. When you press Ctrl/Y, the command interpreter establishes a new command level, called the Ctrl/Y level, and prompts for command input. When the interruption occurs depends on the command or program that is executing:

At the Ctrl/Y level, the command interpreter stores the status of all previously established command levels so that it can restore the correct status after any Ctrl/Y interrupt.

After you interrupt a procedure, you can do the following:

Note

If you do not exit from a command procedure (either explicitly from the command level or as part of an ON routine) following a Ctrl/Y, the next command you enter is interpreted in the context of the command procedure. For example, suppose you define the following symbol at the interactive level:


$ MAIL = "mail/edit=(send,reply,forward)" 

If you enter Ctrl/Y to interrupt a command procedure that does not include this definition and then enter the command MAIL to send a message, your editor is not invoked automatically.

15.11.2 Stopping Privileged Images

If you interrupt the execution of a privileged image, you can enter only the CONTINUE, SPAWN, or ATTACH commands if you want to save the context of the image. If you enter any other commands (except from within a subprocess that you have spawned or attached to), the privileged image is forced to exit.

15.12 Setting Ctrl/Y Action Routines

The following sections describe how to set Ctrl/Y action routines.

15.12.1 Using the ON Command

The ON command, which defines an action to be taken in case of error conditions, also provides a way to define an action routine for a Ctrl/Y interruption that occurs during execution of a command procedure. The action that you specify overrides the default Ctrl/Y action (that is, to prompt for command input at the Ctrl/Y command level). For example:


$ ON CONTROL_Y THEN EXIT 

If a procedure executes this ON command, a subsequent Ctrl/Y interruption during the execution of the procedure causes the procedure to exit. Control is passed to the previous command level.

When you press Ctrl/Y to interrupt a procedure that uses ON CONTROL_Y, the following actions are taken:


Previous Next Contents Index

[Site home] [Send comments] [Help with this site] [How to order documentation] [OpenVMS site] [Compaq site]
[OpenVMS documentation]

Copyright © Compaq Computer Corporation 1998. All rights reserved.

Legal
6489PRO_039.HTML