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.

%ACTIVATE
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.
 
ALLOCATE
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.
 
assignment
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.
 
%assignment
evaluates a preprocessor expression and assigns the result to a preprocessor variable.
 
BEGIN
along with a corresponding END statement delimits a begin-block.
 
CALL
invokes the specified procedure and transfers control to a specified entry point of that procedure.
 
CLOSE
dissociates the internal file declaration from the physical dataset with which it was associated when the file was opened.
 
%DEACTIVATE
makes an identifier inactive.
 
DECLARE
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.
 
%DECLARE
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.
 
DEFAULT
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.
 
DELAY
suspends execution of a task for a specified period of time up to a maximum wait time of 23 hours and 59 minutes.
 
DELETE
deletes a record from a file opened for update.
 
DISPLAY
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.
 
DO
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.
 
%DO
along with its corresponding %END statement, delimit a preprocessor do-group, and can also specify repetitive execution of that do-group.
 
END
ends one or more blocks or groups. Every block or group must have an END statement.
 
%END
is used in conjunction with %DO or %PROCEDURE statements to delimit preprocessor do-groups or preprocessor procedures.
 
ENTRY
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.
 
EXIT
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.
 
FETCH
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.
 
FORMAT
specifies a format list that can be used by edit-directed data transmission statements to control the format of the data being transmitted.
 
FREE
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.
 
GET
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.
 
GO TO
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.
 
%GO TO
causes the preprocessor to continue its scan at the specified label.
 
IF
evaluates an expression and controls the flow of execution according to the result of that evaluation. The IF statement provides a conditional branch.
 
%IF
controls the flow of the scan according to the bit value of a preprocessor expression.
 
%INCLUDE
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.
 
LEAVE
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.
 
LOCATE
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.
 
%NOPRINT
causes printing of the source and insource listings to be suppressed until a %PRINT statement is encountered.
%NOTE
generates a preprocessor diagnostic message with the specified text and severity.
 
null
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.
 
%null
does nothing and does not modify sequential statement execution.
 
ON
establishes the action that is to be executed whenever the enabling condition is subsequently raised while within the cope of the ON condition.
 
OPEN
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).
 
OTHERWISE
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.
 
%PAGE
will skip the printout of the program source to the top of the next page.
 
%PRINT
causes printing of the source and insource listings to be resumed if it was previously suppressed by %NOPRINT.
 
PROCEDURE
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.
 
%PROCEDURE
is used in conjunction with a %END statement to delimit a preprocessor procedure.
 
%PROCESS or *PROCESS
is used to override compile-time options.
 
PUT
is a stream output data transmission statement that can either transmit values to a stream output file or assign values to a character variable.
 
READ
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.
 
RELEASE
frees for other purposes main storage occupied by procedures identified by the specified entry constants.
 
RETURN
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.
 
REVERT
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.
 
REWRITE
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.
 
SELECT
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.
 
SIGNAL
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.
 
%SKIP
The specified number of lines following a %SKIP statement in the program listing are left blank.
 
STOP
immediately terminates the program, including all concurrent tasks.
 
UNLOCK
makes the specified locked record available to other programs.
 
WAIT
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.
 
WHEN
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.
 
WRITE
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
Donate