WRITE and WRITE SYS

WRITE and WRITE SYS$OUTPUT

The examples in this book make extensive use of the DCL command WRITE SYS$OUTPUT value, where value is some datum we'd like to examine.

The WRITE command instructs DCL to perform an output operation, and SYS$OUTPUT represents the location to which the output should be sent. SYS$OUTPUT is an OpenVMS-supplied logical name that usually equates to the user's terminal. So, WRITE SYS$OUTPUT value means "put this value on my screen."

For more information on the WRITE command, see "Reading And Writing Files" in Chapter 9, "Command Procedures."

Lexical Functions

DCL provides a set of lexical functions that perform a wide variety of tasks, such as returning information about processes, files, devices, and queues and manipulating character strings along with other useful tasks.

Lexical functions can be used on the command line in much the same way as symbols. Lexical functions are easily recognized: Their names begin with "f$" and end with a pair of parentheses containing various elements of information (arguments) the functions may require.

start sidebar
Why Are They Called Lexical Functions?

Lexical functions are so named because they are performed during the lexical phase of command processing. This occurs early enough in command processing that the results of lexical functions may be used in many of the same ways a symbol can.

end sidebar

To use a lexical function, you must supply the name of the function you wish to use and any arguments the function requires. Once executed, the return value of the function (the result of the operation) is substituted into the command as if you had typed the return value directly.

To illustrate this concept, a lexical function will be used here to determine the length of a string of text. The f$length() function performs this task. Its argument is the string of text to examine, and its return value is the length of the piece of text (in this case, 20):

     $ WRITE SYS$OUTPUT F$LENGTH("This is the argument")     20 

During the processing of the command above, the lexical function is evaluated at an early stage, and its return value is substituted into the command. In effect, DCL changes the command line to the following before continuing:

     $ WRITE SYS$OUTPUT 20 

To illustrate the usefulness of lexical functions, consider the following example. It demonstrates how to use the convert time lexical function f$cvtime() to determine on which day of the week a given date will fall:

     $ WRITE SYS$OUTPUT F$CVTIME("17-MAR-2003,","WEEKDAY")     Monday 

The next example uses get job and process information function f$getjpi() to determine which account you are logged into:

     $ WRITE SYS$OUTPUT "My username is ''F$GETJPI(0,"USERNAME")'"     My username is BENNY 

Lexical functions may, of course, be used in command procedures. This line, when executed in a procedure, will cause the command procedure to terminate if the process is not a BATCH process (this type of comparison is described later):

     $ IF F$MODE() .NES. "BATCH" THEN $ EXIT 

This example shows how to create a symbol containing the username you are logged in under:

     $ MY_USERNAME = F$GETJPI(0,"USERNAME")     $ SHOW SYMBOL MY_USERNAME       MY_USERNAME = "MIKE       " 

Notice that the username MIKE has some extra spaces at the end, as returned by f$getjpi() (the extra spaces take into account the maximum length of an OpenVMS username). The next example shows how to get rid of the extra spaces by using the f$edit() function. You will notice that the f$getjpi() function itself may be used as an argument to f$edit():

     $ MY_USERNAME = F$EDIT(F$GETJPI(0,"USERNAME"),"TRIM")     $ SHOW SYMBOL MY_USERNAME       MY_USERNAME = "MIKE" 

Many lexical functions return information that is otherwise available via the SHOW command, but lexical functions allow specific bits of information to be assigned to symbols or to be acted on by a procedure. This makes lexical functions of considerable use inside command procedures.

For a complete list of lexical functions and their usage, use the HELP LEXICAL command.



Getting Started with OpenVMS(c) A Guide for New Users
Getting Started with OpenVMS: A Guide for New Users (HP Technologies)
ISBN: 1555582796
EAN: 2147483647
Year: 2005
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net