HP OpenVMS Systems Documentation
OpenVMS User's Manual
17.4.3 Deleting Old Versions of Files
If a command procedure creates files that you do not need after the procedure terminates, delete or purge these files before you exit from the procedure. Use the PURGE command to delete all versions except the most recent one. Use the DELETE command with a version number to delete a specific version of the file or with a wildcard character in the version field to delete all versions of the file.
To avoid error messages when using the DELETE command within a command procedure, use the F$SEARCH function to verify that a file exists before you try to delete it. For example, you can write a command procedure that creates a file named TEMP.DAT only if certain modules are executed. The following line issues the DELETE command only if TEMP.DAT exists:
17.5 Translating Logical Names
In some situations, you may want to use logical names rather than symbols as variables in command procedures. Programs can access logical names more easily than they can access DCL symbols. Therefore, to pass information to a program that you run from a command procedure, obtain the information using a symbol. Then use the DEFINE or ASSIGN command to equate the value of the symbol to a logical name.
You can also use the F$TRNLNM function to determine the value of a logical name and then assign the value to a symbol.
The following example tests whether the logical name NAMES has been defined. If it has, the procedure runs PAYROLL.EXE. Otherwise, the procedure obtains a value for the symbol FILE and uses this value to create the logical name NAMES. PAYROLL.EXE uses the logical name NAMES to refer to the file of employee names.
This command procedure defines a logical name that is used in the program PAYROLL:
At the end of the procedure, the WRITE command displays a message
indicating that the file was processed.
17.6.1 Determining Presence of Strings or Characters
One common reason for examining strings is to determine whether a character (or substring) is present within a character string. To do this, use the F$LENGTH and the F$LOCATE functions. If the value returned by the F$LOCATE function equals the value returned by the F$LENGTH function, then the character you are looking for is not present.
The following procedure requires a file name that includes the version number. To determine whether a version number is present, the procedure tests whether a semicolon (;), which precedes a version number in a file name, is included in the file name that the user enters.
The F$LOCATE function returns the offset for the semicolon. Offsets
start with 0; thus, if the semicolon were the first character in the
string, the F$LOCATE function would return the integer 0. If the
semicolon is not present within the string, the F$LOCATE function
returns an offset that is one more than the offset of the last
character in the string. This value is the same as the length returned
by F$LENGTH, which measures the length of the string starting with the
To extract a portion of a string, use either the F$EXTRACT function or the F$ELEMENT function. Use the F$EXTRACT function to extract a substring that starts at a defined offset. Use the F$ELEMENT function to extract part of a string between two delimiters. In order to use either of these functions, you must know the general format of the string you are parsing. Note that you do not need to use F$EXTRACT or F$ELEMENT to parse file specifications or time strings. Instead, use F$PARSE or F$CVTIME to extract the desired portions of file specifications or time strings.
You can also determine the length of the group name at the same time you extract it.
If a string contains a delimiter that separates different parts of the string, use the F$ELEMENT function to extract the part that you want. You can use F$ELEMENT to obtain different types of access by extracting the portions of the string between the commas. To determine system access, obtain the first element; to determine owner access, obtain the second element; and so on. Note that when you use the F$ELEMENT function, element numbers start with zero. For this reason, use the integer 3 to specify the fourth element.
The following command procedure uses the F$EXTRACT function to extract the group portion of the UIC. This allows the procedure to execute a different set of commands depending on the user's UIC group.
First, the procedure determines the UIC with the F$USER function. Next, the procedure determines the length of the group name by using F$LOCATE to locate the offset of the comma. The comma separates the group from the user portion of a UIC. Everything between the left bracket and the comma is part of the group name. For example, the group name from the UIC [WRITERS,SMITH] is WRITERS.
After determining the length, the procedure extracts the name of the group with the F$EXTRACT function. The name starts with offset 1 and ends with the character before the comma. Finally, the procedure directs execution to the appropriate label.
The following example shows how to determine the length of a group name at the same time it is being extracted:
The following example shows how each type of access in a protection code is separated by a comma:
The commands in this example extract the world access portion (the fourth element) from the default protection code:
The F$ELEMENT function returns everything between the third comma and the end of the string. Thus, if your default protection allowed read access for world users, the string "WORLD=R" would be returned.
After you obtain the world access string, you may need to examine it further. For example:
17.6.3 Formatting Output Strings
You can use the WRITE command to write a string to a record. To line up columns in a record, you can use the F$FAO function to define record fields and place the process name and user name in these fields. When you use the F$FAO function, use a control string to define the fields in the record; then specify the values to be placed in these fields.
Another way to format fields in a record is to use a character string overlay. Note, however, that the F$FAO function is more powerful than a character string overlay. You can perform a wider range of output operations with the F$FAO function.
The command procedure shown in the following example uses the WRITE command to display the process name and PID number for processes on the system:
Note that the output from the WRITE command inserts five spaces between the process name and the user name but the columns do not line up:
The command procedure in this example uses the F$FAO function to define a 16-character field and a 12-character field. The F$FAO function places the process name in the first field, skips a space, and then places the PID number in the second field:
Now when you execute the procedure, the columns will align:
The following example uses an overlay to place the process name in the first 16 characters (starting at offset 0) of the symbol RECORD. Then the PID number is placed in the next 12 characters (starting at offset 17).
This procedure produces the same type of formatted columns you created with the F$FAO function:
17.7 Manipulating Data Types
You can use the following lexical functions to convert data from strings to integers and from integers to strings:
17.7.1 Converting Data Types
Use the F$INTEGER and F$STRING functions to convert between integers and strings. For example, the following command procedure converts data types. If you enter a string, the command procedure shows the integer equivalent. If you enter an integer, the command procedure shows the string equivalent. Note how the F$TYPE function is used to form a label name in the GOTO statement; F$TYPE returns "STRING" or "INTEGER" depending on the data type of the symbol.
17.7.2 Evaluating Expressions
Some commands, such as INQUIRE and READ, accept only string data. If you use these commands to obtain data that you want to evaluate as an integer expression, use the F$INTEGER function to convert and evaluate this data.
Note that you must place apostrophes (' ') around the symbol EXP when you use it as an argument for the F$INTEGER function. This causes DCL to substitute the value for EXP during the first phase of symbol substitution.
In the following example, the F$INTEGER function is used to evaluate an integer expression:
The output from this command procedure would be as follows:
The value "9 + 7" is substituted. When the F$INTEGER function
processes the argument "9 + 7," it evaluates the expression
and returns the correct result.
Use the F$TYPE function to determine whether a symbol exists. The F$TYPE function returns a null string if a symbol is undefined. For example:
This procedure tests whether the symbol TEMP has been previously defined. If it has, then the current value of TEMP is retained. If TEMP is not defined, then the IF statement assigns the value "YES" to TEMP.
11-DEC-1999 13:30:37.12 (1) User: CLEAVER (2) Process ID: 24E003DC (3) Node: ZEUS Process name: CLEAVER_1 Terminal: (4) User Identifier: [DOC,CLEAVER] (5) Base priority: 4 (6) Default file spec: DISK1:[CLEAVER] (7) Process Quotas: (8) Account name: DOC CPU limit: Infinite Direct I/O limit: 18 Buffered I/O byte count quota: 31808 Buffered I/O limit: 25 Timer queue entry quota: 10 Open file quota: 57 Paging file quota: 22276 Subprocess quota: 4 Default page fault cluster: 64 AST quota: 38 Enqueue quota: 600 Shared file limit: 0 Max detached processes: 0 Max active jobs: 0 Accounting information: (9) Buffered I/O count: 140 Peak working set size: 383 Direct I/O count: 7 Peak virtual size: 2336 Page faults: 304 Mounted volumes: 0 Images activated: 1 Elapsed CPU time: 0 00:00:00.55 Connect time: 0 00:00:22.76 Process privileges: (10) GROUP may affect other processes in same group TMPMBX may create temporary mailbox OPER operator privilege NETMBX may create network device Process rights identifiers: (11) INTERACTIVE LOCAL SYS$NODE_ZEUS Process Dynamic Memory Area (12) Current Size (bytes) 25600 Current Total Size (pages) 50 Free Space (bytes) 19592 Space in Use (bytes) 6008 Size of Largest Block 19520 Size of Smallest Block 24 Number of Free Blocks 3 Free Blocks LEQU 32 Bytes 1 Processes in this tree: (13) CLEAVER CLEAVER_1 (*)