PL/1 Statement Reference

In PL/1 the compiler can determine from context if an identifier is a keyword and you can therefore use any identifier as a programmer-defined name. There are no reserved words in PL/I only keywords which are identified as such only when used in the proper context. Keywords can be used as programmer assigned variable names and whether each reference is the keyword or the variable can be determined from the context in which the word is used. Despite this ability to use keywords as variable names, I recommend that you do not do so as the code will be much harder to understand if keywords are also used as variable names.

All statements in PL/1 except the assignment statement start with a keyword. All statements end with a semi-colon. Those keywords that start with % are instructions for the preprocessor. The following is a list of the keywords that identify each of the different statements that you can code in a PL/1 program.

makes an identifier active and eligible for replacement. Any subsequent encounter of that identifier in the input text while the identifier is active starts replacement activity.
allocates storage for controlled variables that are independent of procedure block boundaries. The bounds of controlled arrays, the lengths of controlled strings, and the size of controlled areas, as well as their initial values, can also be specified at the time the ALLOCATE statement is executed.
This statement can also be used to allocate storage for based variables.
statements evaluate expressions and assign values to one or more variables. The variables to which the value is to be assigned can be an element, array, or structure variables, or pseudovariables. The assignment statement is used for both computations and data movement. Since the attributes of the variable or pseudovariable on the left can be different from the attributes of the result of the expression (or of the variable or constant), the assignment statement may require conversions.
evaluates a preprocessor expression and assigns the result to a preprocessor variable.
along with a corresponding END statement delimits a begin-block.
invokes the specified procedure and transfers control to a specified entry point of that procedure.
dissociates the internal file declaration from the physical dataset with which it was associated when the file was opened.
makes an identifier inactive.
defines a variable field as well as specifying its attributes. The position of the declaration determines the scope of the field. Attributes not specified will be determined by default. Any number of fields can be declared in one DECLARE statement. DECLARE can be abbreviated to DCL.
establishes an identifier as a preprocessor name, specifies attributes of the name, and establishes the scope of the name. A %DECLARE statement behaves as a %ACTIVATE statement when it is encountered outside a preprocessor procedure, and activates, with the RESCAN option, all identifiers declared in the %DECLARE statement.
specifies data-attribute defaults (for declared fields where all attributes are not specified). Any attributes not specified on the DECLARE or DEFAULT statement will used the PL/1 defaults. Structure elements are given default attributes according to the name of the element, not the qualified structure element name. The DEFAULT statement cannot be used to create a structure.
suspends execution of a task for a specified period of time up to a maximum wait time of 23 hours and 59 minutes.
deletes a record from a file opened for update.
displays a message on the user's terminal or on the system console. A response might be requested from the operator but only in exceptional circumstances.
along with its corresponding END statement, delimit a group of statements collectively called a do-group, and can also specify repetitive execution of that do-group.
along with its corresponding %END statement, delimit a preprocessor do-group, and can also specify repetitive execution of that do-group.
ends one or more blocks or groups. Every block or group must have an END statement.
is used in conjunction with %DO or %PROCEDURE statements to delimit preprocessor do-groups or preprocessor procedures.
specifies a secondary entry point of a procedure. The ENTRY statement must be internal to the procedure for which it defines a secondary entry point and cannot be either within a do-group that specifies repetitive execution nor within an ON-unit. When an ENTRY statement is encountered in sequential program flow, control passes around it.
immediately terminates the program or the task that contains the statement and all tasks attached by this task. If executed in a major task, EXIT raises the FINISH condition in that task. On normal return from the FINISH ON-unit, the task executing the statement and all of its descendant tasks are terminated. EXIT executed in a major task is equivalent to a STOP statement.
checks main storage for the named procedures which must not be internal procedures. If the procedures are not already in main storage they are loaded from auxiliary storage.
specifies a format list that can be used by edit-directed data transmission statements to control the format of the data being transmitted.
frees the storage allocated for controlled and based variables. The storage can then be used for other allocations. For controlled variables, the next most recent allocation in the task is made available, and subsequent references in the task refer to that allocation.
is a stream input data transmission statement that can either assign data values from a data set to one or more variables or assign data values from a string to one or more variables.
transfers control to the statement identified by the specified label reference. The GO TO statement is an unconditional branch. Use of GO TO statements result in poor coding and use of this statement should therefore be avoided.
causes the preprocessor to continue its scan at the specified label.
evaluates an expression and controls the flow of execution according to the result of that evaluation. The IF statement provides a conditional branch.
controls the flow of the scan according to the bit value of a preprocessor expression.
includes the specified external text member into the preprocessor input at the point at which the %INCLUDE statement is executed. Such text can include preprocessor statements, listing control statements, and PL/I source.
transfers control from within a do-group to the statement immediately following the END statement that delimits the group and terminates the do-group. If the LEAVE statement is contained within a complex statement, control is transferred to the first statement following the termination of the complex statement. LEAVE is valid only within a do-group.
can be used only with an output sequential buffered file for locate mode processing. It allocates storage within an output buffer for a based variable and sets a pointer to the location in the buffer.
causes printing of the source and insource listings to be suppressed until a %PRINT statement is encountered.
generates a preprocessor diagnostic message with the specified text and severity.
does nothing and does not modify sequential statement execution. It can be used to denote null action for THEN and ELSE clauses and WHEN and OTHERWISE statements. A null statement consists of a semi-colon by itself.
does nothing and does not modify sequential statement execution.
establishes the action that is to be executed whenever the enabling condition is subsequently raised while within the cope of the ON condition.
associates a logical file within the program with a physical file or terminal. It also can complete the specification of attributes for the file, if a complete set of attributes has not been previously declared (in the physical file attributes or in the JCL).
specifies the unit to be executed when every preceding WHEN test within the current SELECT statement fails. If the OTHERWISE statement is omitted and execution of the select-group does not result in the selection of a unit, the ERROR condition is raised. The OTHERWISE statement must not have a label prefix.
will skip the printout of the program source to the top of the next page.
causes printing of the source and insource listings to be resumed if it was previously suppressed by %NOPRINT.
with the corresponding END statement delimits a procedure. A PROCEDURE statement defines the primary entry point to the procedure as well as any optional secondary entry points. It also defines any parameters being passed to the procedure along with the attributes of the value to be returned by the procedure if it is invoked as a function.
is used in conjunction with a %END statement to delimit a preprocessor procedure.
is used to override compile-time options.
is a stream output data transmission statement that can either transmit values to a stream output file or assign values to a character variable.
can be used with any input or update file. It retrieves a record from the physical file into the program, either directly to a variable or to a buffer. In blocked records, a READ statement with the appropriate option transfers a record from a buffer to the variable or sets a pointer to the record in a buffer, therefore not every READ statement retrieves data from an input device.
frees for other purposes main storage occupied by procedures identified by the specified entry constants.
terminates execution of the procedure that contains the RETURN statement. If the procedure has not been invoked as a task, the RETURN statement returns control to the invoking procedure. The RETURN statement can also return a value.
cancels the action specification of any specified ON statement within the current block and reestablishes the action specification that was in force at the time of activation of the block. It can affect only ON statements that are internal to the block in which the REVERT statement occurs and which have been executed during the same invocation of that block.
replaces a record in an file that is open for update. For sequential update files the REWRITE statement specifies that the last record read from the file is to be rewritten and therefore a record must first have been read before it can be rewritten. For direct update files, and for keyed sequential update files associated with a VSAM file, any record can be rewritten regardless of whether or not it has first been read.
provides a multi-way conditional branch. A select-group contains a SELECT statement, optionally one or more WHEN statements, optionally an OTHERWISE statement, and an END statement.
You can raise a condition by means of the SIGNAL statement. The established action is taken unless the condition is disabled in which case the SIGNAL statement becomes equivalent to a null statement.
This statement should be used in program testing to verify the action of an ON-unit and to determine whether the correct action is associated with the condition.
The specified number of lines following a %SKIP statement in the program listing are left blank.
immediately terminates the program, including all concurrent tasks.
makes the specified locked record available to other programs.
The execution of a WAIT statement within an activation of a block retains control for that activation of that block within the WAIT statement until specified events have completed. Control for a given block activation remains within the statement until, at possibly separate times during the execution of the statement, the completion value has been set complete for some or all of the event-variables in the list. If an ON-unit entered due to the WAIT is terminated abnormally, control might not pass to the statement following the WAIT.
specifies an expression or expressions that are evaluated and compared with the saved value from the SELECT statement. If an expression is found that is equal to the saved value, the code associated with that WHEN statement is executed and control then passes to the end of the SELECT statement. If no WHEN condition is satisfied then the code associated with the OTHERWISE statement is executed. The WHEN statement must not have a label prefix.
can be used with any output file or direct update file, and also with sequential update files associated with VSAM files. It adds the identified record to the file. For unblocked records, writing can be directly from a variable or from a buffer. For blocked records, the WRITE statement places a logical record into a buffer; only when the blocking of the records is complete is the record actually written to the output device.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow