HP OpenVMS Systems Documentation

Content starts here

OpenVMS User's Manual


Previous Contents Index

13.6.3.1 Restrictions

The following restrictions apply when executing command procedures:

  • You cannot include a space before an execute procedure command (@) when the command procedure begins with a qualifier name.
  • You must precede the execute procedure command (@) with a space when the command procedure begins with a parameter.

13.6.4 Executing Command Procedures Interactively

To execute a command procedure interactively, enter an execute procedure command (@) followed by the file specification of the command procedure.

For example, this command executes the procedure SETD.COM in the [MAINT.PROCEDURES] directory on the WORKDISK: disk:


$ @WORKDISK:[MAINT.PROCEDURES]SETD [Return]

You can define a symbol name to represent long command lines. You can then use the symbol to execute a command procedure.

To use a symbol to execute the command procedure shown in the previous example, include this line in your login command procedure:


$ SETD == "@WORKDISK:[MAINT.PROCEDURES]SETD"

Then, to execute the procedure SETD.COM, enter the symbol name as you would any command:


$ SETD [Return]

By default, when you execute a command procedure interactively, the operating system displays output at your terminal. However, you can redirect output to a file by using the /OUTPUT qualifier to the execute command.

When you redirect command procedure output to a file, the procedure sends any error messages to the terminal and to the file that is receiving the output.

This command writes the output from SETD.COM to the file RESULTS.TXT instead of to the terminal:


$ @SETD/OUTPUT=RESULTS.TXT

Always place the /OUTPUT qualifier immediately after the command procedure name, with no intervening spaces. Otherwise, DCL interprets the qualifier as a parameter to be passed to the procedure.

13.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))

13.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.

13.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:

  • $RESTART
    A global symbol whose value is true if the batch job has been started at least once before this execution. Do not specify a value for $RESTART; the system will assign the appropriate value.
  • BATCH$RESTART
    A global symbol whose value you specify using the SET RESTART_VALUE command.

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.

13.6.6 Executing Command Procedures on Disk and Tape Volumes

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

13.6.6.1 Executing on Private Disks

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 that is mounted with the /SHARE qualifier.

13.6.6.2 Executing on Tape Volumes

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

  • The procedure does not invoke any other procedures.
  • The procedure does not issue any GOTO commands that refer to labels in the procedure preceding the GOTO command.

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.

13.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.

13.7.1 Methods of Exiting

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

  • Place an EXIT command in the command procedure
  • Place a STOP command in the command procedure
  • Enter Ctrl/Y during the execution of the program

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]
$

13.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.

13.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

13.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.

13.9 Other Methods of Error Handling

The following sections describe other methods of handling errors.

13.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:

  • Performs the action specified by the ON command.
  • Sets $STATUS and $SEVERITY to indicate the result of the specified ON action. In general, they are set to success.
  • Resets the default error action (to exit if an error or severe error occurs).

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 includes 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 13-1 illustrates ON command actions.

Figure 13-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 B also illustrate the use of the ON command to establish error handling.

13.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.

13.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.

13.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:

  • If the command is executed by the command interpreter itself (for example, IF, GOTO, or an assignment statement), the command completes execution before the command interpreter prompts for a command at the Ctrl/Y level.
  • If the command or program is a separate image (that is, an image other than the command interpreter), the command is interrupted and the command interpreter prompts for a command at the Ctrl/Y level.

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:

  • Enter a DCL command that is executed within the command interpreter.
    Among these commands are the SET VERIFY, SHOW TIME, SHOW TRANSLATION, ASSIGN, EXAMINE, DEPOSIT, SPAWN and ATTACH commands. After you enter one or more of these commands, you can resume the execution of the procedure with the CONTINUE command. See Section 14.7.2 for a complete list of commands that are executed within the command interpreter.
    When you enter the CONTINUE command, the command procedure resumes execution with the interrupted command or program or with the line after the most recently completed command.
  • Enter a DCL command that executes another image.
    When you enter any command that invokes a new image, the command interpreter returns to command level 0 and executes the command. This terminates the command procedure's execution. Any exit handlers declared by the interrupted image are allowed to execute before the new image is started.
  • Enter the EXIT or STOP command to terminate the command procedure's execution.
    If you use the EXIT command, exit handlers declared by the interrupted image are allowed to execute. However, the STOP command does not execute these routines.

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.


Previous Next Contents Index