[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
OpenVMS User's Manual
13.5.3 Step 3: Add LoopsA loop is a group of statements that execute repeatedly until a condition is met. A loop works as follows:
To write a loop, follow this procedure:
The following example shows the usage of loops in the CLEANUP.COM command procedure:
Once a command executes, control is passed back to the GET_COM_LOOP
label until a user enters the EXIT command. When an EXIT command is
entered, the procedure outputs a message stating that the directory has
been cleaned.
To end a command procedure, follow this procedure:
13.5.4.1 Using the EXIT CommandYou can put an EXIT command in your command procedure to:
The following is an example of using an EXIT command to avoid executing an error handling routine that is located at the end of a procedure:
The following is an example of using the EXIT command to end a procedure that has more than one execution path:
The commands following each of the labels (TAPE and DISK) provide different paths though the procedure. The EXIT command before the DISK label ensures that the commands after the DISK label do not execute unless the procedure branches explicitly to the label.
The EXIT command is not required at the end of procedures because the
end-of-file of the procedure causes an implicit EXIT command. However,
Compaq recommends use of the EXIT command.
You can use the STOP command in a command procedure to ensure that the procedure terminates if a severe error occurs. If the STOP command is in a command procedure that is executed interactively, control is returned to the DCL level. If a command procedure is being executed in batch mode, the batch job terminates. This command line tells the procedure to stop if a severe error occurs:
13.5.5 Step 5: Test and Debug the Program LogicOnce you have written the code using program stubs, you should test the overall logic of the command procedure. You should test all possible paths of execution. Follow this procedure to test and debug command procedures:
The following example shows how to test the command procedure by entering and executing every possible command, an invalid command, and then exiting:
13.5.5.1 Debugging Command ProceduresYou can use the following commands to help debug command procedures:
Example: Debugging Using the SET VERIFY Command
In the following example, the label END_LOP is spelled incorrectly. You can see exactly where the error is because verification is turned on:
To correct the error, change the label to END_LOOP.
Example: Debugging Using the SET PREFIX Command
The following example illustrates the use of time-stamping:
Example: Debugging Using the SHOW SYMBOL Command
The following example shows how the SHOW SYMBOL command is used to determine how the symbol COMMAND is defined:
The SHOW SYMBOL command reveals that the symbol COMMAND has the value
"EXIT". Because the INQUIRE command automatically converts input to
uppercase and the IF statement that tests the command uses lowercase
characters in the string "exit", DCL determines that the strings are
not equal. To correct the error, make sure that the quoted string in
the IF statement is written in capital letters. The rest of the string
can use either uppercase or lowercase letters.
You can also interrupt a command procedure while it is executing to enable verification. As long as the command procedure does not contain the SET VERIFY command or a Ctrl/Y key sequence, you can enable verification by following these steps:
13.5.6 Step 6: Add Cleanup TasksIn general, execution of a command procedure should not change the user's process state. Therefore, a command procedure should include a set of commands that return the process to its original state. This set of commands is usually part of a subroutine that is labeled "CLEAN_UP". Common cleanup operations include closing files and resetting the default device and directory. Follow this procedure to add cleanup tasks to your command procedure:
13.5.6.1 Closing FilesIf you have any open files, make sure that they are closed before the procedure exits. You can use the lexical function F$GETJPI to examine the remaining open file quota (FILCNT) for the process. If FILCNT is the same at the beginning and end of the command procedure, you know that no files have been left open. These are the commands that you would use to warn a user that a file has been left open:
13.5.6.2 Deleting Temporary or Extraneous FilesIf you have created temporary files, delete them. In general, if you have updated any files, you should purge them to delete the previous copies. Before you delete files you have not created, make sure you want to delete them. For example, if you have updated a file that contains crucial data, you might want to make the purging operation optional. If you change the default device, the directory, or both, reset the original defaults before the command procedure exits. To save the name of the original default directory, use the DEFAULT keyword of the F$ENVIRONMENT lexical function. At the end of the command procedure, include a SET DEFAULT command that restores the saved device and directory. The command lines shown in this example save and restore the device and directory defaults:
13.5.6.3 Commonly Changed Process CharacteristicsThe following table lists other commonly changed process characteristics, the lexical functions used to save them, and the lexical function or command used to restore them:
For complete descriptions of these lexical functions, refer to the
OpenVMS DCL Dictionary.
To ensure that cleanup operations are performed even if the command procedure is aborted, begin each command level in the command procedure with the following statement:
For additional information on using the ON CONTROL_Y command, see
Chapter 14.
When your general design works correctly, follow these steps to complete your command procedure:
Example: Replacing a Program Stub with Commands
The following example shows the code for the TYPE section of CLEANUP.COM:
This would replace the existing code:
Example: CLEANUP.COM Command Procedure
Following is an example of the completed CLEANUP.COM command procedure:
13.6 Executing Command ProceduresTo make a command procedure run, you must execute it. You can execute command procedures:
The following sections describe each of these methods.
You can execute another command procedure from within a command procedure by including an execute procedure (@) command . The following command procedure, WRITEDATE.COM, invokes the command procedure GETDATE.COM:
13.6.2 Executing Command Procedures on Remote NodesYou can use the TYPE command to execute command procedures in the top-level directory of another account on a remote node. You can execute command procedures that:
Enter the TYPE command followed by an access control string. Use the following format:
The variables username and password are the user name and password for the account on the remote node. This command procedure displays the users logged in to the remote node on which the command procedure resides:
In the following example, SHOWUSERS.COM is located in the top-level directory of BIRD's account on node ORIOLE, and the password is BOULDER. SHOWUSERS.COM executes the DCL command SHOW USERS on the remote node ORIOLE. The TYPE command displays the output from SHOWUSERS.COM on the local node; that is, on the terminal from which you enter the type command:
13.6.2.1 Security Note
Your password will be visible on your terminal when you use the TYPE
command with an access control string. Take the appropriate security
precautions as described in Chapter 18.
You can create a command procedure that specifies DCL command parameters or qualifiers. This type of command procedure is useful when there is a set of parameters or qualifiers that you use frequently with one or more commands. Enter the execute procedure command (@) in a command line where you would normally specify qualifiers or parameters. This command procedure can be used to enter a set of qualifiers to the LINK command:
This command line links an object named SYNAPSE.OBJ, using the qualifiers specified in DEFLINK.COM:
This command procedure can be used to enter the parameters CHAP1.TXT, CHAP2.TXT, and CHAP3.TXT with a DCL command:
This command line specifies the command procedure PARAM in place of a list of parameters. In the following example, the parameters are the file names listed in PARAM.COM:
|