Professional Documents
Culture Documents
SC20-1651-1 A Guide To PL I For Commercial Programmers Apr68
SC20-1651-1 A Guide To PL I For Commercial Programmers Apr68
---
-- - -
-- --
- -
--- A Guide to PL/I for
-
--_.-
--- ---
- ---
-- Commercial Programmers
Student Text
----
-- -
- --
----
-- . -_ -
-
-
-.....-
- A Guide to PL/I for
-- -- -
--- _.- - ---
-- Commercial Programmers
Student Text
Revision of Form SC20-1651-1 (April 1968)
Requests for copies of IBM publications should be made to your IBM representative or
to the IBM branch office serving your locality. Address comments concerning the
contents of this publication to IBM Corporation, DPD Education Development -
Publications Services, Education Center, South Road, Poughkeepsie, New York 12602.
PLjI is a multipurpose, high-level programming lan- that the commercial programmer occaSionally is con-
guage that enables the programming not only of com- cerned with the scientific aspects of data processing;
mercial and scientific applications but also of real-time he may be required to process binary data and to
and systems applications. It also permits a programmer perform arithmetic calculations in a floating-pOint for-
to use the full power of his computer in an efficient mat. Such considerations are discussed in this publi-
manner and to program applications in a relatively cation but are not developed in detail; the intent is
machine-independent fashion. Because PLjI has a to make the commercial programmer familiar with
modular deSign, it provides facilities for programmers those features of PLjI that apply to advanced com-
at all levels of experience. The novice need learn only mercial applications.
those features of the language that satisfy his needs. This publication consists of five chapters and an
The experienced programmer may use more advanced appendix. Chapter 1 discusses language notations and
features and take advantage of the subtler aspects of deals with such matters as the language character set
the language so that he can program more efficiently and the rules for forming identifiers. Chapter 2 de-
and with greater ease than in other programming scribes the various types of data that are processed by
languages. PLjI programs. Chapter 3 contains a discussion of
This publication presents those features of PLjI that input and output. The structure of a PLjI program
apply to commercial data processing. It does not re- and the control -of statement execution are presented
strict itself to a particular aspect of commercial data in Chapter 4. Data manipulation and data editing are
processing but attempts to discuss all features of PLjI developed in Chapter 5. Appendix A contains sample
that may be used in the full spectrum of commercial PLjI programs.
applications. The nature of commercial data processing
has become more complex in recent years. In the past, Because of the many similarities between PLjI and
as business operations grew in size and complexity, COBOL (Common Business Oriented Language),
commercial data processing problems were character- each chapter in this publication concludes with a sec-
tion showing comparisons of the two languages. These
ized by piecemeal solutions, such as the addition of
more personnel to handle a problem or the increased comparisons do not form a necessary part of this
use of equipment. Within the past few years, however, publication and may be skipped by those readers who
it has become apparent that total-systems methods, do not have a knowledge of COBOL.
formal long-range planning, and scientific techniques The material in this publication is quite compre-
are required to solve commercial data processing prob- hensive, but by no means is it a complete description
lems, in somewhat the same way as they have been of PLjI nor does it represent the definitive treatment
required to solve production problems. Consequently, of any language feature. A full description of PLjI
the role of the commercial programmer has grown. is given in the publication IBM Operating Systemj
Besides being responsible for such activities as de- 360, PLjI: Language Specifications, Form C28-6571.
signing reports, producing payrolls, and solving ac- Other publications which may be of interest to the
counting problems, the commercial programmer is reader are A PLjI Primer, Form C28-6808; A Guide
becoming increasingly involved with more sophisti- to PLjI {or FORTRAN Users, Form C20-1637, and
cated problems, such as decision making, linear pro- PLjI Reference Data, Keywords and Character Sets,
gramming, and production forecasting. This means Form X20-1744.
Contents
And symbol
Or symbol
&
I
"
Identifiers
Greater Than symbol > An identifier can be a word created by the user to
Less Than symbol < identify a file, a data item, or all or any part of his'
Break character program; or it can be one of the words used to identify
Question mark ? entities in the PL/I language, such as statements, attri-
butes, and options. This latter type of identifier is
called a keyword. An example of a keyword would be
the word DECLARE when it is written as the, first
Delimiters
word in a DECLARE statement, because, as the first
There are two classes of delimiters: separators and word, it identifies the statement as a DECLARE state-
operators. ment.
The separators, their use in PL/I, and the graphics Throughout the remainder of this publication, key-
by which they are represented are: words will be printed entirely in capital letters; iden-
Name tifiers assigned by the programmer will be printed in
of Separator Graphic Use small capital letters.
comma separates elements of a list Words used as keywords may also be used by the
semicolon terminates statements programmer to identify files, data items, or all or any
part of his program. For example, one could write a
colon follows statement labels
DECLARE statement that specified within it a data
and condition prefixes item named DECLARE.
period separates name qualifiers All identifiers, whether used' as keywords or not,
parentheses () used in expressions and for must be written according to the following rules:
enclosing lists and speci- 1. An identifier can be composed of alphabetic
fying information associ- characters, digits, and the break character. An
ated with certain key- identifier must begin within an alphabetic char-
words acter.
The operators are divided into four classes: arith- 2. Any number of break characters (-) are allowed
metic operators, comparison operators, logical opera- within an identifier; consecutive break characters
tors, and the concatenation operator. The operators are are permitted.
identified below; their use is discussed in Chapter 5. 3. Identifiers must be composed of not more than
31 characters.
The arithmetic operators are:
+ denoting addition or a positive quantity Statements
denoting subtraction or a negative quantity
In PL/I the words, delimiters, blanks, and comments
~ denoting multiplication
that have been discussed up to now are used to form
/ denoting division
statements. Statements are the basic program elements
~~ denoting exponentiation
used to construct a PL/I program. They are used for
The comparison operators are: the description of data, for the actual processing of
> denoting greater than data, and for the control of the execution sequence of
I> denoting not greater than other statements. All statements in PL/I terminate
> == denoting greater than or equal to with a semicolon. Except for the Assignment state-
denoting equal to ment discussed in Chapter 5 and the Null statement
1== denoting not equal to discussed in Chapter 4, all statements in PL/I begin
< == denoting less than or equal to with a keyword.
8
PL/I and COBOL Comparison: permits PL/I programs to be treated as long strings
Language Notation of characters and to be transmitted to a computer by
means of almost any input medium.
The following discussion compares the language nota-
3. In COBOL, blank characters must surround arith-
tions of PL/I and COBOL. In general, both languages
metic operators; this is not required in PL/I. In PL/I,
employ similar notations: programmer-defined words
blank characters are only required between successive
use alphabetical characters and decimal digits; ex-
words that are not separated by special characters
pressions consist of sequences of names, constants, and
such as parentheses, operators, and punctuation char-
operators; keywords identify language elements; punc-
acters.
tuation characters separate elements; statements have
4. COBOL restricts comments to the Procedure Divi-
an English-like appearance. However, the notation
sion and requires that they be written in a NOTE
rules of both languages do differ; the following list
statement. PL/I allows comments to appear through-
contains some of the more significant differences.
out the entire program and permits them to be used
1. In both PL/I and COBOL, keywords have pre- wherever blank characters may appear (except in a
assigned meanings. In COBOL, keywords are reserved character-string constant or in a picture specification;
for their intended purpose and cannot be used for these language features are discussed in Chapter 2).
other purposes. In PL/I, however, keywords are not 5. The COBOL character set consists of 51 charac-
reserved for special purposes and may appear wher- ters; PL/I uses 60 characters.
ever a programmer-defined word is permitted; for The following points show some of the less signifi-
example,·the keyword READ may be used in a PL/I cant differences:
program as the name of a file. In PL/I, different mean- 1. PL/I terminates all statements with a semicolon;
ings for the same word are determined from context. COBOL terminates statements with either a period,
This permits keywords to be created for new language a comma, or a semicolon.
features. It also avoids having to reprogram old source 2. Programmer-defined words in COBOL must not
programs in which programmer-defined words might be longer than 30 characters; in PL/I, the limit is 31
conflict with new keywords. characters.
2. COBOL requires a programming form, PL/I does 3. PL/I uses the break character (an underscore)
not. In PL/I, punctuation characters determine the within programmer-defined words to improve read-
significance and grouping of language elements. This ability; COBOL uses the hyphen.
10
alter the sequence of statement execution. A label may '$123.45'
be used as a data item in certain statements (the use 'JOHN JONES'
of label data items is discussed in Chapter 4, "Program '45.62'
Structure"). The value of a label is the location in a The quotation mark is not part of the constant. If it
program of the statement that the label identifies. is desired to represent a quotation mark as part of the
constant, a double quotation mark must be used. For
example:
Names of Data Items
'IT' 's'
In a program, it is often necessary to use a name to
identify data items to be processed. A name that Repetition of a character-string constant may be in-
identifies a data item is called a data name. Data dicated by preceding the constant specification with
names conform to the rules established in Chapter 1 a decimal integer (enclosed in parentheses) indicating
for forming identifiers. the number of repetitions. For example:
At any specific time during the course of program (3)'~-~'
execution, a data name has a value; that is, it identi-
is equivalent to writing
fies a data item that represents a value.
,~ ~ ~ ~ ~ ~,
The different data items that may be identified by - - -
the same data name must have the same data char-
acteristics. These characteristics are associated with the Bit-String Constants
data name by writing the data name and the associated Bit-string constants consist of a sequence of the digits
characteristics in a DECLARE statement (see "DE- 1 or 0, enclosed in single quotation marks and im-
CLARE Statement" in this chapter). mediately followed by the letter B. For example:
'OlOO'B
Constants Repetition may be specified for bit-string constants
In a PL/I program it is not always necessary to in the same manner as for character-string constants.
name every data item. Data items may actually appear Thus,
within a PL/I program and, consequently, are im- ( 10)'I'B
mediately available for use in the program. is equivalent to writing
A data item that appears in a PL/I program is called
'1111111111'B
a constant because the information it represents, that
is, its value, cannot change. The characteristics of a
constant are inherent in the representation of the con- Decimal Fixed-Point Constants
stant. For example, in a PL/I program, the constant A decimal fixed-point constant is composed of one or
98.6 is a data item that represents a numeric value. more digits (0 through 9) and may contain a decimal
This constant specifies that the data item is a decimal point. For example,
data item with two digits to the left of the decimal 72.192
point and one digit to the right of the decimal point. .308
For each type of data permitted in a PL/I program 1965
there is a corresponding type of constant available for
use in the program. Note that decimal fixed-point constants are not en-
The following discussion describes the types of con- closed in quotation marks.
stants that may appear· in a PL/I program and the
manner in which they are written. Following the dis- Binary Fixed-Point Constants
cussion of constants, there is a discussion of the DE- A binary fixed-point constant is composed of one or
CLARE statement and the way in which it is used more of the digits 1 or 0 and may contain a binary
to describe data. point (discussed above); it is followed immediately
by the letter B. For example:
Character-String Constants 11011B
Character-string constants may contain any character 11.1101B
that can be recognized by a particular computer. .OOIB
Character-string constants are enclosed in single quo- Note that binary fixed-point constants are not en-
tation marks. For example: closed in quotation marks.
12
DECIMAL, BINARY, FIXED, or FLOAT. Only DECLARE HEADER CHARACTER(80),
blanks may intervene. TITLE CHARACTER(40) VARYING;
For a floating-point data item, only a single integer specifies that the character-string data item called
is written in the precision attribute. It indicates the HEADER is of fixed length and consists of 80 characters,
number of digits appearing before the E in the data and that the number of characters in the character-
item. For a fixed-point data item, two integers are string data item called TITLE may vary from 0 to 40.
usually written; the first indicates the number of digits
appearing in the data item, the second indicates the SIT Attribute
number of digits to the right of the decimal or binary The BIT attribute specifies that the data item named
point. If there are to be no digits to the right of the in the DECLARE statement is represented as a bit
point, that is, the second integer is zero, only the first string consisting of a certain number of bits. The BIT
integer need be written. Thus, the attribute (6,0) is attribute may appear in two forms:
equivalent to the attribute (6).
Consider the following DECLARE statement: BIT( length)
BIT(length) VARYING
DECLARE DECIMAL FIXED (7,2),
SALARY
ESTIMATEFLOAT DECIMAL (10), The length specification and VARYING attribute have
COUNTER FIXED (5) BINARY,
the same meaning as described for the attribute
MEAN BINARY (10) FLOAT;
CHARACTER, except that "length" indicates the num-
ber of bits in the bit-string data item.
A data item assigned to SALARY would be a decimal
fixed-point data item, composed of seven digits, with PICTURE Attribute
two of these digits assumed to be to the right of the The PICTURE attribute is used to specify the detailed
decimal point (for example, 78921.43). characteristics of string data items and frequently is
A data item assigned to ESTIMATE would be a deci- used to edit the format of character-string data items
mal floating-point data item, with ten digits preceding that are to be printed. The editing of a character-string
the E (for example, .4325437894E5). data item may involve replacing certain characters,
A data item assigned to COUNTER would be a binary such as leading zeros, with other characters, and in-
fixed-point data item, composed of five digits, with serting, within the character string, characters such as
none of these digits assumed to be to the right of the bi- the dollar sign and the period.
nary point (for example, 11001.B). The PICTURE attribute is written in the following
A data item assigned to MEAN would be a binary way:
floating-point data item, with 10 digits preceding the PICTURE 'picture-specification'
E (for example, 1000111011E-3B).
As indicated, the picture specification must be enclosed
String Attributes in quotation marks; it consists of a sequence of char-
The string attributes specify either character-string acters called picture characters. The following discus-
data items or bit-string data items. These attributes sion deals only with those picture characters that allow
are: CHARACTER and BIT. the PICTURE attribute to serve as an alternative for
the arithmetic attributes and for the string attributes;
CHARACTER Attribute these characters are: A, X, 9, V, K, S. The remain-
The CHARACTER attribute specifies that the data ing picture characters are for editing (see Chapter 5,
name in the DECLARE statement represents charac- "Data Editing").
ter strings. The attribute is written in the following Although the PICTURE attribute may serve as an
form: alternative for the arithmetic attributes and, thereby,
CHARACTER ( length) specify the representation of a numeric value, the data
item described by the PICTURE attribute is a char-
The length specification is a decimal integer constant acter-string data item and not an arithmetic data
that specifies the number of characters in the data item. Consequently, the efficiency of computer opera-
items. tions may be affected when performing arithmetic
When the character string is of varying length, the calculations on data items described by the PICTURE
following is written: attribute. In most computers, this lack of efficiency re-
CHARACTER ( length) VARYING sults from being unable to perform arithmetic calcu-
The length specification indicates the maximum num- lations directly on character-string data items. Conver-
ber of characters in a varying-length character string. sion from character string representation to arithmetic
The following statement: representation is required before arithmetic calcula-
14
Exclusivity of Attributes a bit string, the DEFINED attribute is written with
The following rules apply to the attributes described the following attribute:
thus far: POSITION (decimal-integer-constant)
BIT, CHARACTER, and PICTURE must not be
The decimal integer constant in the POSITION attri-
used to describe the same data item. An item described
bute specifies the starting position of that portion of
with BIT, CHARACTER, or PICTURE must not also
the string data item to which the new name refers.
be described with FIXED, FLOAT, BINARY, or
When the starting position is the first position of the
DECIMAL.
string, the POSITION attribute is not required. Con-
sider the following statement:
The DEFINED Attribute
It is often convenient to be able to refer to the same DECLARE DATE CHARACTER(6),
MONTH CHARACTER(2) DEFINED DATE,
data item by different names, particularly when several
programmers are involved with the same program and DAY CHARACTER(2) DEFINED DATE
each is using a different name for the same data item. POSITION (3),
The DEFINED attribute may be used for that pur- YEAR CHARACTER (2) DEFINED DATE
16
Consider another example. This is one portion of assigned to a structure that contains the pre-
a payroll record: ceding data name, MIDDLE. The data name AD-
DRESS could not be assigned the level number 1
DECLARE
1 PAYROLL-RECORD,
because it is not a major structure. RATE-OF-PAY
3 MAN-NUMBER CHARACTER (6), could be assigned one of two level numbers, 3
3 NAME,
or 4, because the data name YR is contained in
27 LAST CHARACTER (15), two structures, one with the level number 4 and
the other with the level number' 3. However,
27 FIRST CHARACTER (15),
if it were assigned the level number 4, it would
27 MIDDLE CHARACTER (10),
3 ADDRESS,
be treated as part of the structure called DATE-
HIRED, which would probably not be the pro-
12 STREET CHARACTER (20),
grammer's intent.
12 CITY CHARACTER (15),
12 ZONE CHARACTER (5),
12 STATE CHARACTER (15),
3 DATE-HIRED, Qualified Names
4 MONTH FIXED (2), When specifying names of elementary items or of
4 DAY FIXED (2), minor structures, it is often convenient to use the same
4 YEAR, data name for items in different parts of the structure
FIXED
14 DECADE (1), or to use the same data name for items in two differ-
FIXED (1),
14 YR ent structures. For example, two major (level 1)
3 RATE-OF-PAY FIXED (7,2); structures called CARDIN and CARDOUT could each have
The principal rules for assigning level numbers are an elementary item called P ARTNO. If the item named
illustrated in this example and may be summarized P ARTNO were referred to in the body of a PL/I pro-
as follows: gram, it would be a non-unique reference; that is to
say, it would not be clear whether PARTNO was the
1. Level 1 is reserved to identify a major structure.
elementary item in the structure CARDIN or the ele-
2. A level with the name B is contained in a level mentary item in the structure CARDOUT. Therefore,
with the name A if all of the following conditions whenever a non-unique data name is used, it must
are met: be associated with one or more of the names in the
a. B follows A. structure containing it in order to make the reference
b. B has been assigned a level number higher to it unique.
than that assigned to A.
In PL/I, making a name unique is called qualifica-
c. A name with a level number equal to or
tion.
lower than that for A does not appear between
A and B. Thus, even though DECADE has a high-
The name of an elementary item or of a minor
er level number than STATE, it is not part of (not level 1) structure is qualified by preceding it
STATE, because data names with level num-
with the name of the structure to which the item
bers lower than 12 (for example, DATE_HIRED) belongs. These names are arranged, from left to right,
appear between STATE and DECADE. in the order of increasing level number and are sepa-
rated from one another, and from the name they
3. Level numbers need not be assigned consecu-
tively. Thus, MONTH, DAY, and YEAR could be qualify, by ,periods. The periods may be surrounded
assigned any level number higher than that as- by blanks. The name of a major structure cannot be
signed to DATE-HIRED and lower than that as- qualified.
signed to DECADE. For exampie, consider the following structures:
4. A structure may include more than one level. DECLARE
However, all data names that make up a level 1 CARDIN, 2PARTNO, 2DESCRIPTION,
within the same structure (for example, MONTH, 1 CARDOUT,2PARTNO, 2DESCRIPTION;
DAY, and YEAR) must have the same level number.
5. When a data name is to have a lower level num- The elementary data items can be referred to by the
ber than the one immediately preceding it, the following qualified names:
level number must be chosen from the level num- CARDIN.PARTNO
bers of the structures that include the preceding CARDIN . DESCRIPTION
data name. Thus, ADDRESS must be assigned CARDOUT.PARTNO
level 3, because that is the only level number CARDOUT.DESCRIPTION
BIRTH. WOMAN
18
The grouping of items within the array CHECK- This structure could be expressed as an array, thus:
RECORDcould be visually represented as follows:
g
CHECK-RECORD
1 U 1 g
13:
( g
2 U CHECK-RECORD
1 g
The way in which items are grouped in an array
2 2 g
is analogous to the levels used in specifying a structure. 11
Thus, in the example above, the groups of three items 3
t2
in the array are analogous to level 3 in the structure;
the group of two items in the array is analogous to
level two; and th~ single item CHECK-RECORD which is This array would be specified in a DECLARE state-
the name of the array is analogous to level 1 in the ment as follows:
structure. DECLARE CHECK-RECORD( 2,3,2)
Just as the structure CHECK-RECORD could be ex- CHARACTER ( 15);
panded to contain another level, so also the array
The parenthesized integers following CHECK-RECORD
CHECK-RECORD could be expanded to contain another
would indicate that there were two major groups in
grouping. Consider the following expansion of the
the array; that each major group was divided into
structure CHECK-RECORD.
three minor groups and that each minor group con-
tained two elementary items (a total of twelve ele-
Level 1 Level 2 Level 3 Level 4 mentary items). Each set of groups is called a dimen-
sion. In this example, there is a set of major, a set
FmST {INITIAL
FULL of minor, and a set of elementary groups; that is, a
major, minor, and an elementary dimension.
NAME LAST { INITIAL In PL/I, arrays may have any number of dimen-
FULL sions. Thus, in the example above, the array CHECK-
RECORD (2, 3, 2) could be expanded beyond the three
MIDDLE { INITIAL
FULL dimensions specified by the parenthesized integers.
CHECK-RECORD Expressions can be used instead of integers to indi-
cate the number of items in a dimension. For example,
{ NUMBER
20
ALIGNED and PACKED Attributes lx,
The ALIGNED and PACKED attributes are used 2FmLDl,
only for structures or arrays composed of string data. 3suBFmLDl,
They specify the arrangement in core storage of all 4DTLI PICTURE 'AA',
of the character-string or bit-string elements that com- 4DTL2 CHARACTER (10),
pose a particular array or structure. The PACKED 2FIELD2,
attribute indicates that there is to be no unused core 3DTLI PICTURE 'AA',
storage between any two elements of an array or be- 3DTL2 CHARACTER (10),
tween any two bit-string elements or any two charac- 2FIELD3 CHARACTER (5);
ter-string elements of a structure. The ALIGNED The following should be noted:
attribute indicates that the elements of an array or l. The difference between the level number of the
structure are to start at a particular core storage structure name following LIKE and the level
boundary and that there may, consequently, be numbers of items subordinate to structure name
unused core storage between the elements. The is maintained.
ALIGNED attribute often results in more efficient
2. The names and attributes of items subordinate to
processing, particularly when a great deal of packing
the structure name become subordinate to the
and unpacking of data would be required. (The stor-
item with the LIKE attribute.
age boundary is defined individually for each imple-
mentation. ) 3. The level numbers of any items following the
When these attributes are specified, they apply to item with the LIKE attribute must be less than
all the elements in a major structure or in an array. or equal to the level number of the item with
When they are written for a structure, they must be the LIKE attribute.
written for the data name level number 1. When they 4. The structure name following LIKE may be
are written for an array, that array may not be part qualified but may not be subscripted.
of a structure. 5. Neither the structure name .following LIKE, nor
These attributes may be written in a DECLARE any item subordinate to it may be described with
statement as follows: the LIKE attribute.
DECLARE lSTRUCTURE PACKED, 2SUBSTRI
BIT (4), 2SUBSTR2 BIT (5); LABEL Attribute
DECLARE ARRAY (4,2,4) ALIGNED; The keyword LABEL may be used to specify that a
name is a label name, representing a value that is a
label constant. For example, the statement:
LIKE Attribute DECLARE POINTER LABEL;
The LIKE attribute specifies that the name being de- specifies that the value of the label name POINTER is a
clared is a structure with a substructure having ele- label constant.
ments with attributes and names identical to the A label name may also identify an array of label
names and attributes of the elements of the named constants. Consider the f<;>llowing statement:
structure. The attribute has the following format:
LIKE structure-name DECLARE SWITCH (10) LABEL;
Consider, for example, the major structures A and This statement specifies that SWITCH is the name of
x, described with the following DECLARE statement. a 10-element array and that each element of the array
DECLARE lA, is a label constant. The use of label names is discussed
2FIELDl, in Chapter 4, "GO TO Statement."
3DTLI PICTURE 'AA',
3DTL2 CHARACTER (10), INITIAL Attribute
2FmLD2 CHARACTER (12), The INITIAL attribute specifies constants that are
lx, assigned to data names when computer storage is
2FmLDl, allocated (see "Storage Allocation" in Chapter 4). The
3suBFmLDl LIKE A.FmLDl, INITIAL attribute may be written in the following
2FmLD2 LIKE A.FmLDl form:
2FmLD3 CHARACTER (5); INITIAL (constant)
This specification of a major structure x is equiva- A constant appearing in the INITIAL attribute must
lent to writing: conform to the rules established earlier in this chap-
22
4. Bit strings and label data are PL/I data types three dimensions, and a group ( the COBOL
not contained in COBOL. equivalent to a PL/I structure) to a maximum of
5. COBOL uses figurative constants; PL/I does not. 49 levels.
6. PL/I imposes no limit on the number of dimen- 7. The order of name qualifiers in COBOL is the
sions in an array or on the number of levels in reverse of the order used in PL/I. COBOL uses
a structure. COBOL limits a table (the COBOL the keywords IN and OF as qualification opera-
equivalent of a PL/I array) to a maximum of tors; PL/I uses the period.
24
ENVIRONMENT (option-list) header label record to be written, or it is a character-
The option list will be defined individually for each string constant that is to be written as the header
PL/I compiler. Information such as file media, physi- label record. For an update file, the IDENT option
cal record format, buffering, and file disposition may specifies label reading but does not specify label
be specified with the option list. writing.
The format of label records is defined by the com-
Opening and Closing of Files
piler for each implementation of PL/1. If the IDENT
option is not specified, no label operations are per-
Before a file is processed by a data transmission
formed.
statement, certain file preparation activities must oc-
Consider the following statement:
cur, such as checking for the availability of external
storage media, positioning the media, and allocating OPEN INPUT FILE (TABLES) IDENT (SERIAL);
appropriate programming support. This activity is This statement opens the input file called TABLES,
known as opening a file. Similarly, when processing is positions the file at its logical beginning, and reads
completed, the file must be closed. Closing a file con- the header label record into the character string iden-
sists of releasing the facilities that were established tified by SERIAL.
during the opening of the file. PL/I provides two
PAGESIZE( w) Option
statements, OPEN and CLOSE, to perform these
functions. These statements, however, are optional. The PAGESIZE option specifies the depth of a
If an OPEN statement is not executed for a file, the printed page. w indicates the number of lines, includ-
file is opened antomatically when the first data trans- ing skipped lines, that are contained on a page. For
mission statement for that file is executed; in this case, example, the specification PAGESIZE( 45) means that
the automatic file preparation consists of standard no more than 45 lines are to be printed or skipped on
system procedures and uses information about the file a page. If an attempt is made to start a new line be-
contained in a DECLARE statement. Similarly, if a yond line 45, a new page is started unless the pro-
file has not been closed before completion of a pro- grammer has specified another action inan ON state-
gram, the file is closed automatically upon completion ment (the ON statement is discussed in Chapter 4;
of the program. also see the ENDPAGE condition in Chapter 4, "ON-
Conditions" ) .
The PAGESIZE option can be specified only for
OPEN Statement
files that have the PRINT attribute.
The OPEN statement acquires and prepares files for
subsequent input/output operations. An OPEN state- LINESIZE ( w) Option
ment has the following form: The LINE SIZE option specifies the maximum length
OPEN FILE ( filename) options; of the lines on a printed page; w indicates the number
of character positions available on a line. For example,
Options may occur in any order and may be placed the specification LINESIZE ( 120) means that a line
before and after the specification FILE (filename). extends from character position 1 to character posi-
Options include any of the external storage attributes tion 120. If an attempt is made to place data to the
(except the FILE and ENVIRONMENT attributes) right of character position 120, the data in question
that are discussed in Chapter 2; the IDENT option, is placed on the next line, starting at character posi-
which regulates the reading and writing of header tion 1.
label records; and the PAGESIZE and LINESIZE op- The LINESIZE option can be specified only for
tions, which control the overall layout of each page files that have the PRINT attribute.
in a PRINT file. A discussion of the IDE NT, PAGE- If an OPEN statement is encountered for a file al-
SIZE, and LINESIZE options follows. ready opened, the statement is ignored.
IDE NT (label information) Option
CLOSE Statement
The IDENT option in an OPEN statement for an
output file specifies that a header label record is to be The CLOSE statement releases facilities that were es-
placed in the file. For an input file, IDENT provides tablished during the opening of a file, repositions the
information for reading a header label record. file to its logical beginning, and causes proper disposi-
The label information, for an input file, is the name tion of the file. A CLOSE statement has the following
of a character string into which the header label is to form:
be read. For an output file, the label information is CLOSE FILE (filename) IDENT (label
either the name of a character string containing the information) ;
Chapter 3: Input/Output 25
The meaning of the IDENT option is the same as The WRITE statement has the format:
that for the OPEN statement, except that it handles WRITE FILE (filename) FROM (data name);
trailer label records rather than header label records. When a READ statement is executed, causing a rec-
If a CLOSE statement is encountered and the file ord to be read, there is no conversion of data types to
has not been opened, or has already been closed, the conform to the attributes declared for the names.
statement is ignored. The data in the record should exactly match the dec-
laratio.n of the name to which it is assi'gned. Similarly,
a record that is written has the same form externally
as its internal representation.
Data Transmission When records are to be read into and written out
of buffers instead of being directly assigned to data
The basic function of input and output is data trans-
names, the READ statement has a different form:
mission, getting the data items into the computer for
processing and placing the results of the processing READ FILE (filename)
on external storage media. In PL/I two types of data SET (pointer-variable);
transmission are available: record-oriented data trans- The pointer variable is a name that is used to point
mission and stream-oriented data transmission. With to the location of the buffer. It is associated with a
record-oriented transmission, the data on the external data name by means of a DECLARE statement. Such
medium is considered as a collection of physically a data name is called a based variable. For e,xample,
separate records, each of which consists of one or consider the following statement:
more data items in any form. Data is transmitted,
one record at a time, in the same form as it is re- DECLARE 1 DETAIL BASED (N),
corded, either internally or externally; no conversion 2 ACCT-# CHARACTER (7),
is performed. With stream-oriented transmission, the 2 PAYMENT DECIMAL FIXED (6,2),
data on the external medium is considered as one 2 NAME CHARACTER (40);
continuous stream of data items in character form. In this statement, DETAIL is a based variable and N
Each data item is converted, if necessary, to and from is a pointer variable associated with DETAIL. As a
its appropriate internal form, which is determined based variable, DETAIL must be declared to have the
by the attributes of the data name to which a data BASED attribute (see Chapter 4, "Storage Alloca-
item is assigned. tion," for a discussion of the BASED attribute). The
DECLARE statement indicates that N will point to
a buffer into which and from which records will be
Record-Oriented Transmission read or written and that each record will consist of
Record-oriented data transmission deals with files that three data items with the same attributes as those de-
are composed of a series of physically separate records. clared for ACCT-#, PAYMENT, and NAME. The follow-
Each record is read or written as an entity, either in- ing READ statement, when executed, causes a record
to or from an addressable buffer or into or from a to be read into this buffer:
location specified by a data name (usually the name READ FILE (MASTER) SET (N);
of a structure or an array).
In record-oriented transmission the principal state- The pointer variable N now points to the beginning
ments used to transmit data to and from input and of the record (in effect, the value of N is the address
output files are the READ statement and the WRITE of the first storage location of the buffer). It is as
statement. if the record were assigned directly to DETAIL; a ref-
Files referred to in READ and WRITE statements erence to ACCT-# becomes a reference to the first data
must be declared to have the RECORD attribute. item in the buffer, a reference to PAYMENT becomes a
This specifies that the file is to be used with record- reference to the second data item in the buffer, a ref-
oriented statements. The UNBUFFERED attribute erence to NAME becomes a reference to the third data
specifies that the data in the records does not go into item in the buffer.
an addressable buffer, but is assigned directly to or A record is written from this buffer (the buffer into
from the data name specified in the READ or WRITE which it was read) when the following WRITE state-
statement. ment is executed:
For an unbuffered file, the READ statement has WRITE FILE (OUTPUT) FROM (DETAIL);
the following format:
A record can also be written from a buffer created
READ FILE (filename) INTO (data name); by a LOCATE statement. This statement has the form:
26
LOCATE based-variable FILE (filename) SET If the update file is buffered, that is, records are read
(pointer-variable) ; into and written out of buffers, only the following
The LOCATE statement does not immediately cause statement is needed to cause a record to be written:
data to be written. It indicates that a buffer, having REWRITE FILE (filename);
the same attributes as the specified based variable, is There is no need to specify a data name because the
to be allocated. The specified pointer variable will REWRITE statement always refers to the buffer into
point to the buffer. Data is subsequently placed in the which the record was read.
buffer to form a record. The record is written into the
specified output file immediately before the next LO- Stream-Oriented Transmission
CA TE statement or WRITE statement before the same Stream-oriented data transmission deals with files that
file is executed or immediately before the specified file are considered as one continuous stream of data in
is closed. character form. Data items are assigned from the
For example, assume that a record containing an ac- stream to data names or from data names into the
count number, the amount of payment, and a customer stream. Stream-oriented transmission implies data con-
name has been read as described above. A record that version. All of the data items in the stream are in
contains only the customer name and the amount of character form. On input, they are converted auto-
payment is to be written in the output file. The fol- matically to conform to the attributes of the data name
lowing statements would be needed to set up a based to which they are assigned; on output, data items are
variable and to allocate a new buffer: converted, if necessary, to characters. Of course, only
DECLARE 1 BILL-RECORD BASED (p), valid data conversions can be performed (see Chapter
2 CUSTOMER CHARACTER (40), 5, "Conversion Between Data Types").
2 AMOUNT DECIMAL FIXED (6,2),
There are three modes of stream-oriented transmis-
LOCATE BILL-RECORD FILE (OUTPUT); sion: edit-directed transmission, list-directed transmis-
The output record is created when the appropriate sion, and data-directed transmission. All three modes
data items (referred to as NAME and PAYMENT) in the use the same statements for input and output, the
input buffer are moved into the output buffer (here GET statement and the PUT statement, respectively.
they are referred to as CUSTOMER and AMOUNT). The Whichever mode is used, the following information is
move is accomplished by using the following assign- required for each GET or PUT statement:
ment statements (the exact statements are shown here l. The name of the file from which data is to be
for the sake of example; the assignment statement is obtained or to which data is to be assigned.
discussed fully in Chapter 5) :
2. A list of data names representing storage areas to
CUSTOMER = NAME; which data items are to be assigned during in-
AMOUNT = PAYMENT; put, or from which data items are to be obtained
Once the record has been created, it remains in the during output. Such a list is known as a data list.
output buffer until the next LOCATE statement or 3. The format of each data item.
WRITE statement for the file OUTPUT is about to be In certain circumstances, all of this required in-
executed or until the file OUTPUT is about to be closed. formation can be implied; in other cases, only a por-
The LOCATE statement does not require the SET tion of it need be stated explicitly. If the file name is
(pOinter variable) option because the BASED attri- not specified, standard system files will be assumed;
bute for BILL-RECORD specifies a pointer variable (p), this applies to any of the three modes of stream trans-
which is associated with the based variable. mission. In list-directed and data-directed transmission,
Record-oriented transmission permits the use of up- the format of the d~ta items is not specified. In data-
date files. An update file is one that is both read from directed input, not even the data list need be specified.
and written into. Data is written into an update file
by means of the REWRITE statement. Each record Edit-Directed Data Transmission
that is read is rewritten into the update file, with or Edit-directed transmission specifies an explicit descrip-
without change, before another record is read. If the tion of data items as they exist or are about to exist in
update file is unbuffered, that is, if records from the the data stream. This explicit description is contained
file are assigned directly to data names, the REWRITE in a GET or PUT statement. The GET statement is
statement has the following form: used to transmit data from external to internal storage
REWRITE FILE (filename) FROM (data and the PUT statement to transmit data from internal
name); to external storage. When used for edit-directed trans-
Chapter 3: Input/Output 27
mission, the GET and PUT statements have the fol- Data Format Descriptions
lowing form: Data format descriptions are used to describe the rep-
GET FILE (filename) EDIT (data list) resentation and characteristics of data items in the
. (format list); data stream .
PUT FILE (filename) EDIT (data list)
(format list); Character-String Format Descriptions
The data list in an edit-directed GET or PUT state- • A( tV)
ment is a list of data names to which or from which The format description A ( tV) indicates that the value
data items in external storage are to be assigned. The of the item in the data list with which A( tV) is associ-
data names in a data list are separated by commas. ated is represented in the data stream as a character
The format list is a list of format descriptions sep- string. The specificatio~ tv indicates the number of
arated by commas. There are two types of format characters in the string.
descriptions: data format descriptions and control for- Consider a data item called UNIT declared with the
mat descriptions. Data format descriptions describe attribute CHARACTER (20), meaning that its inter-
data items in the data stream; control format descrip- nal representation is a sequence of 20 characters. The
tions specify page, line, and spacing operations. value of UNIT may be written in a file called UNIT_FILE
When an edit-directed GET or PUT statement is as a string consisting of 20 characters by using the
executed, the data names in the data list are paired following statement:
with the data format descriptions in the format list. PUT FILE (UNIT-FILE) EDIT (UNIT) (A (20) );
Data is transmitted in the following fashion:
1. If the statement is a GET statement, the data In this statement, the A indicates that the data is to
item described by the format description is as- be written as a character string, and the integer 20
signed to the area identified by the data name specifies the length in characters of the string. If the
with which the format description is paired. For format description A(2S) had been used, S blank
example, in the statement: characters would have been added to the value of UNIT
making the length of the item written 25 characters.
GET FILE (FILE-A) EDIT (FIRST)
Similarly, if the format description were A( 15), then
(A(20) );
only 15 characters would be written. These 15 char-
the data name FIRST is paired with the format acters would contain the value of the first IS characters
description A (20). The data item described by of UNIT.
A( 20) is assigned to an area in internal storage For output, the length of the character string need
identified by FIRST. not be specified with the A format. If omitted, the
2. If the statement is a PUT statement, the data item length is determined from the declared attributes of
assigned to the area identified by the data name the name with which the format description is paired.
in the data list is placed into the data stream. The Thus, the PUT statement above could have been
representation of this value in the data stream written as follows:
depends on the format description with which
PUT FILE (UNIT-FILE) EDIT (UNIT) (A);
the data name is paired. For example, in the state-
ment Had UNIT been declared with the attribute BIT(20),
PUT FILE (FILE-A) EDIT (FIRST) the value of UNIT would be converted from a 20-posi-
(A(20) ); tion bit string to a 20-position character string com-
posed of the numeric characters zero and one and
the data name FIRST is paired with the format
written out as 20 characters. Similar conversions apply
description A( 20). The data item identified by
to internally stored fixed-point and floating-point data
FIRST is placed into the data stream. The format
items. If UNIT had been declared with the attribute
description A(20) indicates that the data item
FIXED ( 10), the value of UNIT would be converted
is represented in the data stream as a character
from internal fixed point to external character-string
string 20 characters long.
form and extended on the right with blanks, if neces-
Note that there is no necessary correlation between
sary, before being written out as a 10-position charac-
the way in which the same value is represented in in-
ter string.
ternal storage and in the data stream. The representa-
The statement:
tion of a value in internal storage depends on the
attributes of the data name for which it is a value; GET FILE (UNIT-FILE) EDIT (UNIT) (A( 20) );
the representation of a value in the data stream de- causes the next 20 characters in the file called UNIT-
pends on its format description. FILEto be aSSigned to UNIT. The value is automatically
28
transformed from its character representation specified If AMOUNT, as described above, were used in the
by the format A( 20), to whatever representation is statement:
specified by the attributes declared for UNIT. GET EDIT (AMOUNT) (F(6,2));
• F( w,d) the next six characters from a standard input file would
The fixed-point format description F ( w,d) indicates be scanned for a fixed-pOint decimal number with two
that the value of the item in the data list with which decimal places. When located, the number would be
F( w,d) is associated is represented in the data stream converted to a form compatible with the declared
as a string of characters, with a decimal value and attributes of AMOUNT.
containing an assumed or actual decimal point. If AMOUNT had the attributes FIXED BINARY(24,7)
The specification w indicates the number of charac- indicating a 24-bit fixed-pOint binary number with
terpositions in the string. The d specification indicates seven binary places, the statement:
that an assumed or actual decimal point appears d
characters before the end of the string. PUT EDIT (AMOUNT) (F(6,2));
When a data item is written from inside the com- would produce, in a standard output file, six char-
puter, its value is right-adjusted in the field specified acters containing the value of AMOUNT converted from
by w in the format description. If d is greater than internal fixed-point binary representation to a decimal
zero, an actual decimal point will appear in the field number and represented as a string of decimal char-
before the last d characters. If, in the data item being acters with a decimal point two characters before the
written, the number of significant characters to the end of the item. A GET statement would reverse the
right of the decimal point is less than d, trailing conversion. Similar conversions would apply if the at-
zeros will be supplied. tributes of AMOUNT were either floating-point decimal
When the value of an item being written is less than or floating-point binary. If AMOUNT had the CHAR-
zero, a minus sign character will be prefixed to the ACTER attribute or a picture specification of a char-
external character representation of the value. acter string, conversion would still apply, provided,
No sign appears when the value is greater than or in the case of output, the character string represented
equal to zero and, therefore, the first position on the a numeric value.
left will be a blank. The w specification must include a If the BIT attribute were declared for AMOUNT, the
position for the minus sign and a position for the bit-string data would be treated as a binary integer,
decimal point. Should the value of the item being which would be converted to a decimal integer and
written contain leading zeros, these will be changed represented as a string of decimal characters.
to leading blanks; should the value of the item not fill
• E( w,d)
the field specified by the format description, leading
blanks will be supplied. The floating-point format description E (w,d) in-
When a data item is being read into the computer, dicates that the value of the item in the data list with
the value transmitted may appear anywhere in the which E( w,d) is associated is represented in the data
field specified by w. A decimal point is assumed to stream as a character string. This string has a decimal
appear in the field before the last d characters. The value and contains both an assumed or actual decimal
specification d need not be written if the value to be point and a signed exponent preceded by the character
read is to have no decimal places. However, if an ac- E.
tual decimal point appears in the value read, and its The interpretation of wand d is the same as that for
position contradicts the position specified by d, the d wand d in the format description F ( w,d) with the
specification will be ignored and the position of the following exceptions:
actual decimal point will be used. The specification w must include the number of
Consider a data item called AMOUNT which has the characters occupied by the following:
attribute FIXED( 4,2) meaning that it is a four-digit, 1. The exponent and its sign
fixed-point decimal number with two decimal places. 2. E
It can be written in a standard output file by the fol- 3. A sign for the value, should it be negative
lowing statement: 4. An actual decimal point, if present
PUT EDIT (AMOUNT) (F(6,2)); When this format description is used, d indicates
(6,2) specifies that a decimal point is to appear before the total number of characters between the decimal
the last two numeric characters and that the number point and E. On output an actual decimal point will
be right-adjusted in a field of six characters. Leading appear to the left of the significant digits. In the
zeros are changed to blanks, and, if necessary, a minus statement:
sign is placed to the left of the first numeric character. GET EDIT (GROSS-ESTIMATE) (E(8,2));
Chapter 3: Input/Output 29
the value of the item in the data stream is assigned to cate the number of times that format description is to
GROSS-ESTIMATE and is automatically converted to the be used before the next format description is selected.
internal form specified by the attributes for GROSS- The statement:
ESTIMATE. GET EDIT (UNIT,ITEM,COST) (2A( 10) ,F( 4,2) );
has the same effect as the statement:
Bit-String Format Descriptions GET EDIT (UNIT, ITEM, COST) (A(10), A(10),
• B(w) F( 4, 2»;
The bit-string format description B ( w) indicates that An expression enclosed in parentheses immediately
the value of the item in the data list with which B ( w ) before a format description can also be used to specify
is associated is represented in the data stream as a the number of times the format description is to be
character-string containing only the characters 1 and O. used. When the expression has a zero or negative
The specification w indicates the number of char- value, the format description associated with it is not
acters in the string. used.
Consider a data item called CODE which has the attri- A repetition factor may be applied to more than one
bute BIT ( 40). The value of CODE may be written in a format description by enclosing the format descriptions
.file called CODE-FILE as a string of 40 characters that in parentheses and preceding the left parenthesis with
represent bits by using the following statement: the repetition factor.
PUT ;FILE (CODE-FILE) EDIT (CODE) (B ( 40 ) ); Thus the statement:
If the format description B ( 120) had been used in PUT EDIT (UNIT, COST, ITEM, RATE)
the above statement, 80 zero characters would be ap- ( 2 ( A ( 10), F (4, 2»);
pended to the right of the string. produces the same result as the statement:
For output, the length of the string need not be spec- PUT EDIT (UNIT, COST, ITEM, RATE) (A(10),
ified with the B format. If omitted, the length is deter- F( 4, 2), A( 10), F( 4, 2»;
mined from the declared attributes of the name with
which the format description is paired. Thus, the PUT
statement above could have been written as follows: Multiple Data Specifications
PUT FILE (CODE-FILE) EDIT (CODE) (B); In a GET or PUT statement, a data list and the for-
mat list associated with it are called an edit-directed
Picture Format Description data specification. Up to now, examples of GET and
PUT statements have each contained one data specifi-
The picture format description has the following form:
cation. More than one data specification can be writ-
P , picture-specification' ten in a GET or PUT statement. More than one is
The picture-specification is described in Chapter 2. usually written in order to simplify the writing of state-
Editing by means of a picture specification is discussed ments employing long data lists and format lists. The
in Chapter 5. relationship between a format item and a data name
The P format description may be used to describe is more evident when data lists and format lists are
data values that are represented in the data stream in short. Successive data specifications are separated by
an edited or unedited character format. Consider the commas.
following statement: For example, the statement:
GET EDIT (TITLE,COUNT) (P'AAAAA',P'9999'); PUT EDIT (UNIT, COST, ITEM, RATE) (A(10),
When this statement is executed, the next nine char- F( 4, 2), A( 10), F( 4, 2»;
acters in a standard input file are transmitted, and the might be more easily read as:
first five (alphabetic) characters are assigned to TITLE; PUT EDIT (UNIT, COST)(A(10), F(4, 2»
the integer located in the next four (numeric) charac-
(ITEM, RATE)(A( 10), F( 4, 2»;
ter positions is assigned to COUNT. The internal repre-
sentation of the data will conform to the attributes of
TITLE and COUNT. Data Specifications for Structures and Arrays
The names in a data list may be the names of struc-
Repetition of Format Description tures and arrays. A structure or array name in a data
For abbreviation purposes a decimal integer can ap- list serves as a concise representation of all the elemen-
pear immediately before a format description to indi- tary items in the structure or array.
30
Consider the following structure: ters are spaced over and ignored, and the remaining
DECLARE 1 BILL, five characters are assigned to DEDUCfION.
2 ITEM CHARACTER ( 10), The statement:
2 NUMBER FIXED(5), PUT EDIT (ITEM, TOTAL) (A(4), X(2), F(5»;
2 COST FIXED ( 5,2); places, in a standard output file, four characters that
The use of BILL in the statement: contain the value of ITEM, followed by two blank char-
PUT EDIT(BILL)(A(10), F(5), F(5,2»; acters, followed by five characters that contain the
is equivalent to writing the following statement: value of TOTAL.
PUT EDIT (ITEM, NUMBER, COST) (A(10),
F ( 5 ), F ( 5,2) ); Printing Format Descriptions
In the foregoing example, when the structure BILL The following format descriptions control printing
is written, format descriptions are required for each operations. They are used only with files that have the
elementary item in BILL, because GET and PUT PRINT attribute and, consequently, appear only in a
statements transmit successive elementary items. PUT statement.
On output, a data list may specify expressions, in- • PAGE
cluding structure and array expressions. (Expressions
The format description PAGE specifies that the next
are discussed in Chapter 5.) Each expression, when
data item written is to appear on a new page. For
evaluated, is written in a format specified by an asso-
example:
ciated format item. For example, the statement:
PUT EDIT ('TOTAL IS ' II 2 0 SUM) (A(15»; PUT EDIT ('CONTINUED ON NEXT PAGE')
(A(22» ('MONTHLY SALES REPORT')
will convert the value of 2 0 SUM to a character string, (PAGE, A(20»;
append the string to the right of the constant 'TOTAL IS',
and write the result as a I5-position character string This PUT statement causes the phrase CONTINUED ON
in a standard output file. NEXT PAGE to be written on the current page and the
heading MONTHLY SALES REPORT to be written on a
Control Format Descriptions new page.
The format descriptions discussed up to now are • SKIP( w)
used to describe data items as they exist in the data The format description SKIP (w) specifies that one
stream. The format descriptions discussed below are or more lines are to be skipped before the next data
not descriptions of data items; they describe spacing item is written. w indicates the position of the next
and printing operations. These control format descrip- line relative to the current line. The number of lines
tions are written in the format list of a GET or PUT skipped is equal to w-l. For example, the format de-
statement together with the data format descriptions scription SKIP(5) means that four lines are to be
discussed previously. They are not, however, asso- skipped and the next data item is to be written on the
ciated with a data name in the data list of the GET fifth line following the current line.
or PUT statement.
• LINE( w)
Spacing Format Description The format description LINE (w) specifies that the
next data item is to be written on a particular line. w
The following format description is used in a format
indicates the number of the line on the page. For
list to indicate spacing.
example, the format description LINE (20) means
• X(w) that the next data item is to, be written on line 20
On input, the X format item specifies that the next of the page.
w characters of the data in the stream are to be spaced
• COLUMN(w)
over and not to be transmitted. On output, the X for-
mat specifies that w blank characters are to be in- The format description COLUMN( w) specifies hor-
serted into the stream. For example, the statement: izontal positioning, giving the character position at
which the next data item is to begin. w is the number
GET EDIT (COUNT, DEDUCfION) (A(5), X(5), of the character position for the first character of the
A(5) ); data item. For example, the format description COL-
specifies that the next 15 characters from a standard UMN (35) means that the first character of the next
input file are to be treated as follows: the first five data item is to appear in character position 35 of the
characters are assigned to COUNT, the next five charac- line.
Chapter 3: Input/Output 31
Among the· printing format descriptions, the SKIP by commas. An example of a list-directed GET state-
format description specifies relative positioning, while ment follows:
LINE and COLUMN specify absolute positioning. GET FILE (MASTER) LIST
The following example shows the use of printing for- (LOAN-#, PRINCIPAL, RATE);
mat descriptions in combination with each other.
The GET statement in the above example causes three
PUT EDIT ('MONTHLY BANK LOAN REPORT') data items from MASTER file to be assigned to the vari-
(PAGE, LINE(2), A(24)); ables of the data list in the sequence in which they are
PUT EDIT (LOAN-#, PRINCIPAL, INTEREST, listed; that is, the first data item is assigned to LOAN-#,
PAYMENT, BALANCE) (SKIP(3), A(7), the second to PRINCIPAL, and the third to RATE. Assign-
COLUMN(15), F(8,2), COLUMN(35), ment stops at this point because the data list has
F(3,3), COLUMN( 45), F(6,2,) been exhausted.
COLUMN(65), F(8,2)); The data list in a list-directed PUT statement differs
from that of a GET statement only in that a data item
The first PUT statement specifies that the heading
MONTHLY BANK LOAN REPORT is to be written on line may be represented by an expression other than its
name, for example, an arithmetic expression whose
two of a new page. The second statement specifies
value is the item to be written. Once evaluated, the
that two lines are to be skipped and the value of
value represented by an expression is transmitted in
LOAN_# is to be written, beginning at the first char-
the same way that the value represented by a variable
acter of the fifth line; the value of PRINCPAL, begin-
is transmitted. Items in the data list (including expres-
ning at charac~er position 15; the value of INTEREST at
sions, if any) are separated by commas. An example of
character position 35; the value of PAYMENT at charac-
a list-directed PUT statement follows:
ter position 45; and the value of BALANCE at character
position 65. PUT FILE (OUT)
LIST (NAME,6.3~RATE;,NUMBER-10);
List-Directed Data Transmission
The PUT statement in the above example causes three
List-directed data transmission permits the program- data items to be written in the file named OUT. The se-
mer to specify the variables to which data is to be as- quence in which the data items are written follows the
signed (or from which data is to be acquired) without sequence of the items in the data list; that is, the first
specifically stating a format for the data. The format is data item is the value represented by the variable
a standard one and is supplied by the compiler. List- NAME, the second is the value resulting from the eval-
directed transmission provides easy input/output oper-
uation of the expression 6.3~RATE, the third is the value
ations for programmers who do not require a special
resulting from the evaluation of the expression NUM-
format either on input or output, and who are inter-
BER-10. Writing stops at this point.
ested only in a list of the results of the processing.
Note that in list-directed input/output or in any
The elementary form of the GET and PUT state-
form of stream-oriented transmission, it is the data list
ments, when used for list-directed input and output, is:
that determines the number of data· items obtained
GET FILE (filename) LIST (data list); from the stream or inserted into the stream.
PUT FILE (filename) LIST (data list);
The FILE (filename) is the file specification; LIST Format of List-Directed Data
( data list) is the data specification. The file name and In list-directed input, successive data items on the ex-
the data list must each be enclosed in parentheses. The ternal medium must be separated either by commas or
two specifications need not appear in a particular or- blanks. On output, blanks are supplied between items
der. If the file specification is omitted, it is assumed automatically.
that one of the standard files is to be used. In list-
directed transmission, the keyword, LIST, must always List-Directed Data Representation
head the data specification. The internal and external representation of a data item
in list-directed transmission is determined by the attri-
butes declared for it by the programmer. For example,
List-Directed Data Lists a data item for which the attributes CHARACTER
The data list in a list-directed GET statement is a list ( 10) have been declared would be recorded internally
of variables (representing internal storage areas) to as a character string of 1ength 10. On output, it would
which data items in the data stream are to be assigned. be written the same way. To better understand how
The variables (data names) in a data list are separated this applies to list-directed GET and PUT statements,
32
assume that the standard input file contains the follow- assigned. The data in the input stream might look like
ing data: this:
'NEW YORK', 'JANUARY', -6.5, 72.6
A == 7.3 B == 'ABCDE' c(4,2) == 9876;
Assume, further, that the following two statements ap-
pear in the program: The data name, followed by an assignment symbol,
followed by the value that is to be assigned, is called
DECLARE CITY CHARACTER (12), MONTH
an assignment. The assignmeIJ,ts in the input stream
CHARACTER (9), MINTEM FIXED
can be separated by commas or by blanks. The last
DECIMAL (4,2), MAXTEM FIXED
assignment to be obtained by a single GET statement
DECIMAL (5,2); must be followed by a semicolon. If the above stream
GET LIST (CITY, MONTH, MINTEM, MAXTEM); were part of the standard system input file, the state-
The GET statement would cause the data items to be ment:
assigned as follows: GET DATA;
1. CITY is assigned the character string NEW YORK,
left adjusted and padded on the right with four blanks. would cause values to be assigned to A, B, and c.
2. MONTH is assigned the character string JANUARY, On output, the data list must appear to specify
left adjusted and padded on the right with two blanks. which data items are to be written into the stream.
3. MINTEM is assigned the value -06.50. The PUT statement referring to the data items could
4. MAXTEM is assigned the value 072.60. be:
The character strings are padded on the right with PUT FILE (OUT) DATA (A, B, c( 4,2));
blanks to conform with the declared length of the
strings; quotation marks are not maintained internally. The assignments are separated by blanks in the out-
put stream and a semicolon is written after the last
The decimal fixed-point numbers are aligned on the as-
sumed decimal point, to conform with the declared item specified in the data list.
precision. Consider the result of the following PUT
statement:
The STRING Option
PUT, LIST (CITY, MONTH, MAXTEM,
MINTEM, 'RANGE:', MAXTEM-MINTEM); One feature of stream-oriented data transmission is
concerned with internal data transmission, rather than
The record would be printed as: input and output. In either the GET statement or the
NEW YORK JANUARY 72.6 -6.5 RANGE: 79.1 PUT statement, the FILE (filename) option can be
Note that if a character string is printed, the single replaced by the STRING (string name) option. When
quotation marks are not written, whether the string is the string option is specified, the statement has nothing
specified as the value of a variable (CITY and MONTH) to do with a file. In a GET statement, it indicates that
or is specified as a character constant ('RANGE:'). If a the designated string is to be considered as a stream
character string is written in a file that does not have of input characters; in a PUT statement, it indicates
the PRINT attribute, the enclOSing quotation marks that the designated string is to be considered as the
are supplied, if necessary, and are written.! output stream.
Although the string option can be used with any of
the three modes of stream-oriented transmission, it is
Data-Directed Data Transmission most practical in association with a format list since
The elementary forms of the GET and PUT state- individual items in the string need not be separated by
ments in data-directed transmission are written as commas or blanks.
follows: Consider the following example:
GET FILE (filename) DATA;
GET STRING (RECORD) EDIT (NAME, PAY-NO,
PUT FILE (filename) DA TA (data list);
HOURS, RATE) (A( 12), A(7), F(2),
The data list need not be included in the GET state- F(4,2»);
ment because data items in the stream are accom-
This statement specifies that the character string
panied by the data names to which they are to be
having the name RECORD, which is recorded in the in-
ternal storage area, is to be scanned. The first 12 char-
1 When a bit string is written by a list-directed PUT statement, acters of the string are to be assigned to NAME, the
the single quotation marks do appear, as does the letter B,
even in a PRINT file. The binary digits are converted to the next 7 characters are to be assigned to PAY-NO, the
characters, 1 and O. next 2 characters are to be converted to decimal fixed-
Chapter 3: Input/Output 33
point representation and assigned to HOURS, and the displays the message: WHICH IS THE NEXT FILE?, and
last 4 characters specified are to be converted to a causes the computer to wait for the operator's reply.
fixed-point decimal number (with two digits after the The operator's reply is assigned to NEXT-FILE.
decimal point) and assigned to RATE. If any charac- The statement:
ters remain in the string, they are to be ignored.
DISPLAY ('END OF PHASE-2');
The PUT statement with a string option produces
the reverse effect. Consider the statement: displays the indicated message but does not interrupt
PUT STRING (RECORD) EDIT (NAME, PAY-NO, computer execution.
HOURSORATE) (A( 12), A(7), P '$$99.99');
This statement specifies that the character value of
NAME is to be assigned to the first 12 character posi- PL/I and COBOL Comparison: Input/Output
tions of the string named RECORD, and that the charac- The following discussion compares the input/output
ter value of PAY-NO is to be assigned to the next 7 features of PL/I and COBOL. Both languages employ
character positions of RECORD. The value of HOURS is similar methods for transmitting data between internal
to be multiplied by the value of RATE and the product and external storage areas to the extent that input/
is to be converted to a character string and assigned output statements process files and identification rec-
to the next 7 character positions of RECORD. ords (label records) in files may be processed both on
input and on output. The languages differ, however, in
DISPLAY Statement input/ output capabilities; the following points cover
The DISPLAY statement causes a message to be dis- some of the more Significant differences.
played to the machine operator. A response may be 1. In COBOL, data transmission implies files that
requested. The device upon which the message is dis- are composed of logical records. One or more data
played will be specified for each implementation of items form a logical record; data is transmitted one
PL/I. logical record at a time.
The form of the DISPLAY statement is: PL/I provides two types of data transmission. Rec-
ord-oriented transmission, like COBOL, deals with
DISPLA Y (expression) REPLY (data name);
logical records. Stream-oriented transmission handles
Execution of the DISPLA Y statement causes the individual data items; a file is thought of as one con-
expression to be evaluated and, when necessary, con- tinuous stream of data items rather than as a collection
verted to a character string. This character string is of logical records.
the message that is displayed. The data name in the 2. PL/I provides control format specifications that
REPLY option must be declared as a character string. regulate printing and spacing operations.
This data name receives the message supplied by the 3. In PL/I, identification records (label records) are
operator of the computer. Execution of the program read or written as a result of the IDE NT option in an
is suspended until the operator's message is received, OPEN or CLOSE statement. In COBOL, label rec-
or, if the EVENT option is specified, execution con- ords are specified by a file description entry in the
tinues and the reply is considered complete only after Data Division, and special label procedures are speci-
an associated WAIT statement specifying the event fied ina USE statement.
name is executed. 4. COBOL permits a filename to be used as a name
The REPLY specification is optional; when not used, qualifier; PL/I does not.
execution continues without interruption. 5. In PL/I, the characteristics ofa file are specified
The following statement: in a DECLARE statement or an OPEN statement. In
DISPLAY ('WHICH IS THE NEXT FILE?') REPLY COBOL, file characteristics are specified in a file de-
( NEXT-FILE) ; scription entry in the Data Division.
34
Chapter 4: Program Structure
executed is by means of a CALL statement. The ele- gin block internal to PAYROLL. The data name TAX is
mentary form of a CALL statement is: described differently in each of these blocks. TAX, with
the attribute CHARACTER (5) applies to the entire
CALL entry name; PAYROLL procedure except for the begin block REPORT.
"Entry name" is the label of a PROCEDURE state- In REPORT, the data name TAX has another meaning
ment and, consequently, the name of a procedure. The and applies to a different data item.
CALL statement causes control of program How to be The region of a program within which the descrip-
transferred to the procedure named by "entry name." tion of a name applies is called the scope of the decla-
A CALL statement in a procedure or begin block ration or the scope of the name established by the
that causes control of program How to be transferred declara tion.
to another procedure is known as an "activating" In the above example, the scope of the declaration:
CALL statement. The procedure to which control has DECLARE TAX CHARACTER (5);
been transferred is known as an "activated" procedure.
When execution of an activated procedure is com- extends throughout the PAYROLL procedure but does
pleted, control is sent to the statement following the not include the REPORT block. The scope of the declara-
activating CALL statement. Because a procedure can tion:
be activated only by using the name of the procedure DECLARE TAX FIXED (4, 2);
as an entry name in an activating CALL statement, is limited to the REPORT block.
every PROCEDURE statement must have a label. In general, separate declarations of the same name
In the previous example, statement 1 could be a imply unique names with distinct scopes that do not
CALL statement that activated procedure C; it would overlap.
be written as: It may be necessary, however, to use the same data
CALL C; item in different blocks. PLjI provides several ways
36
of accomplishing this: by nesting blocks, by using the EXTERNAL and INTERNAL Attributes
EXTERNAL attribute, and by employing names as If procedure X and procedure y in the previous ex-
parameters and arguments. Each of these methods will ample had not been nested, and the same values of
be discussed in turn. NUMBER and COST were to be used in both procedures,
then the means of indicating this would be to declare
Nested Blocks NUMBER and COST in both procedures with the attri-
The same data item may be used in different blocks bute EXTERNAL. This is illustrated by rewriting the
if the blocks are nested. When a data name is declared previous example as follows:
in an outer block by means of a DECLARE statement X: PROCEDURE;
and is not redeclared in an internal block, the scope DECLARE NUMBER FIXED (3)
of the declaration includes the internal block. EXTERNAL, COST EXTERNAL
Consider the following example: FIXED (4, 2);
x: PROCEDURE;
DECLARE NUMBER FIXED (3), COST
FIXED (4, 2);
GET LIST (NUMBER, COST);
END X;
y:PROCEDURE;
DECLARE TITLE CHARACTER (10),
CALL Y;
NUMBER EXTERNAL FIXED (3), COST
Y: PROCEDURE;
FIXED (4, 2) EXTERNAL;
DECLARE TITLE CHARACTER (10);
END Y; END y;
This example has the same effect with respect to
NUMBER and COST as did the previous example which
employed nesting.
END X; If the EXTERNAL attribute had not been used
When procedure x is executed, NUMBER and COST with NUMBER in both of the above procedures, then
are established as fixed point decimals and are assigned the NUMBER in procedure X and the NUMBER in pro-
values by the GET statement. The scope of NUMBER cedure y would refer to two separate and distinct data
and COST includes procedure Y. The references to these items.
two data names in the PUT statement employ the When the same data name is employed in two or
declaration established in procedure x. The scope of more external procedures to refer to the same data
TITLE, however, is limited to procedure Y; when con- item, the data name must be declared with the EX-
trolleaves procedure Y, the data of TITLE is not acces- TERNAL attribute in each procedure. In all such
sible by statements in procedure x. Consequently, declarations for the same data name, the attributes
TITLE in procedure Y must not be used by statements declared must be consistent, since the declarations in-
in procedure x. volve a single data item.
Transfer of control from procedure x to procedure The use of the EXTERNAL attribute is not re-
y must be made by means of a CALL statement. If stricted to procedure blocks; it may also appear in
procedure y had been written as a begin block, no begin blocks that are external with respect to each
CALL statement would be necessary; sequential flow other.
of control would be allowed to proceed through the When the EXTERNAL attribute is not declared for
BEGIN statement of block y. a data name, the INTERNAL attribute is assumed.
38
When control is sent to the OUTPUT procedure by the TAX-TABLE becomes the length of WORK-TABLE, which
CALL statement in the PROCESS procedure, the values in this case is 100, and the values of WORK-TABLE be-
of the arguments NAME, COUNT, and PRICE become come the values of TAX-TABLE.
the values of the corresponding parameters TITLE, Each time the PRINT procedure is activated, TAX-
NUMBER, and COST. When the OUTPUT procedure is TABLE can be associated with an argument of different
completed, control returns to the statement following size. However, the array named by the argument must
the CALL statement in the PROCESS procedure. be qne-dimensional and the elements in the array must
When an argument is tbe name of an array, the have the attribute FIXED (4,2);
number of dimensions and the number of items in each In addition to data names, file names, and entry
dimension of the array must correspond to those of the names, arguments may also be expressions. (Expres-
associated parameter. When an argument is the name sions are discussed in Chapter 5.) For example, the
of a character or bit string, the length of the string following statement:
must be the same as that of the corresponding param- CALL TAX ( 12° MON1'H-SALARY ) ;
eter. However, the number of items in the dimen-
sions of an array and the length of a string may not be could be used to execute a procedure called TAX that
known at the time a procedure is written. When this employed a parameter representing an annual salary.
is the case, an asterisk (0) may be used for each di- The value of the expression:
mension or for the string length in the declaration of 12° MONTHLY-SALARY
.the parameter. The asterisk then indicates that the
string length or number of items in a dimension is the would then become the value of the parameter em-
same as for the corresponding argument. ployed by the TAX procedure.
Consider the following example:
PRINT: PROCEDURE (TAX-TABLE)
DECLARE TAX-TABLE(O) FIXED Entry-Name Parameters and the ENTRY Attribute
(4, 2); An entry-name has been defined as a label constant
directly following the word CALL in a CALL state-
• ment. Entry-names may also be used in parameter
lists and in argument lists. When an entry name is
PUT LIST (TAX-TABLE); used as an entry-name in a CALL statement it is
considered to be contextually declared as an entry
name; when it is used in an argument list of a CALL
statement, it is not considered to be contextually de-
END PRINT; clared. (Contextual description is discussed in Chap-
ter 2 under Default Attributes.) For example, consider
This procedure contains one parameter, TAX-TABLE,
the following procedure:
which is the name of a one-dimensional array. The
asterisk in the declaration indicates that the size of the ROUTINE: PROCEDURE (x, Y, z);
array is unspecified and will assume the size of the cor- DECLARE X FIXED DECIMAL
responding argument in a CALL statement. Assume (4), z LABEL;
that the PRINT procedure is activated from the follow-
ing block:
BEGIN; •
DECLARE WORK-TABLE (100) FIXED (4, 2); CALL Y;
• •
•
CALL PRINT (WORK-TABLE); END ROUTINE;
RETURN;
CALL ROUTINE (COUNT, EDIT, L5);
END TEST;
END PROCESS;
In the PROCESS procedure, the name ROUTINE is de- Whenever either of the RETURN statements or the
fined contextually as an entry name because it im- END statement is encountered in this procedure, con-
mediately follows the keyword CALL. trol returns to the statement following the CALL
statement that activated the TEST procedure.
Sequence of Control
When a program is being executed, its sequence of
control determines the order of execution of the state- Activation and Termination of Blocks
ments. A begin block is said to be activated when control
Within a block, control normally passes sequentially passes through the BEGIN statement for the block.
from one statement to the next. If a DECLARE A procedure block is said to be activated when a
statement is encountered, control passes over it to the CALL statement transfers control to the PROCE-
next statement. Sequential execution of' statements is DURE statement for the block.
modified, however, by the following statements:
There are several ways to terminate an active block:
CALL, PROCEDURE, END, RETURN, GOTO, IF,
DO, and ON. The first three of these statements have 1. A begin block is terminated when control passes
been introduced. RETURN will be discussed in the through the END statement for the block.
following text. Then a discussion dealing with the ac- 2. A procedure block is terminated on execution of
tivation and termination of blocks will follow, after a RETURN statement or an END statement for
which the GOTO, IF, DO, and ON statements will be the block.
discussed. Because the allocation of core storage is 3. A block is terminated on execution of a GO TO
influenced by the sequence of control in a program, statement which transfers control to a paint not
this chapter also includes, at the end, a discussion of contained in the block. (The GO TO statement is
storage allocation. discussed later in this chapter).
40
Dynamic Descendance of Blocks GO TO Statement
When a block is terminated, all the dynamic descend- The GO TO statement transfers control to a specified
ants of that block are terminated. statement. There are two forms of the GO TO state-
In the discussion that follows, consider the two ment:
blocks: block A and block B. GO TO label constant;
Block B is said to be an immediate dynamic descend- GO TO label name;
ant of block A if B is activated by a statement inter-
nal to A. A statement is internal to block A if it is con- In the first form control is sent to the statement that
tained in A but it is not contained in any other block has the label constant as its label. In the second form
which is itself contained in A. the GO TO statement has the effect of a multi-way
Consider the following example: switch; control is transferred to the statement iden-
tified by the current value of the label name. Because
the label name may have different values at each exe-
R: PROCEDURE; cution of the GO TO statement, control may not al-
statement 1 ways pass to the same statement. The label name may
statement 2 also be the name of an array of labels. The following
s: PROCEDURE; example illustrates the use of a GO TO statement
statement 3 that effectively is a multi-way switch.
statement 4
T:" BEGIN; SWITCH: PROCEDURE;
statement 5
END T;
statement 6
END S; DECLARE L LABEL (L1, L2)
Comparison Expressions
SECOND: BEGIN; Comparison expressions use the following comparison
operators:
(greater than)
THIRD: BEGIN; (not greater than)
( greater than or equal to)
(equal to)
1= ( not equal to)
(less than)
CALL FOURTH;
( not less than)
(less than or equal to)
•
FOURTH: PROCEDURE; These operators are used with data names and con-
stants to form comparison expressions. For example,
the expression:
COUNT> 10
GO TO SECOND; is a comparison expression in which the numeric value
of COUNT is compared with the constant 10. If the
value of COUNT is greater than 10 the expression is
true; otherwise it is false.
END FOURTH; In addition to numeric data items, character-string
data items may appear in comparison expressions. The
expression:
NAME < 'ROBERT'
END THIRD;
is true when the character-string value of NAME is less
than the character-string constant 'ROBERT; otherwise
it is false. Character strings are compared from left to
END SECOND;
right, character by character. The comparison is based
on an implementation-defined collating sequence. If
the character strings are of different lengths, the
shorter string is extended on the right with blanks.
END FmST;
Bit strings are permitted in comparison expressions.
The following expression:
the statement GO TO SECOND; sends control to the
begin block called SECOND, and terminates the blocks MASK 1='1010101'B
FOURTH and THmD.
is true when the bit-string value of MASK does not
equal the bit-string constant '1010101'B. The expression
IF Statement in~olves a left-to-right comparison of binary digits.
It is often desirable to execute a statement or a series The binary digit zero is lower in comparison to the
of statements only under certain circumstances. In binary digit one. If the bit strings are of different
such a situation, it might be convenient to evaluate lengths, the shorter is extended on the right with zero
an expression and, on the basis of this evaluation, se- bits.
lect or reject the statement or statements to be exe- A more detailed discussion of comparison expres-
cuted. PLjI provides the IF statement for this purpose. sions appears in Chapter 5.
It also provides eight comparison operators that are The result of a comparison is a bit string of length
used to construct comparison expressions that may be one; the value of a true comparison is the constant '1'
either true or false. These expressions are used in the B; a false comparison has the value '0' B.
42
Comparison Expressions in an IF Statement When the numeric value of SALES is greater than 1000
An IF statement can assume one of 2 forms: the begin block after the THEN is executed and the
DO group after the ELSE is skipped; otherwise the
IF comparison expression THEN unit
DO group is executed and the begin block is skipped.
IF comparison expression THEN unit 1 ELSE
In an IF statement the units following THEN and
unit 2
ELSE may also contain one or more IF statements.
Each "unit" is either a single statement, a begin When this is the case, the units following THEN and
block, or a group. A group consists of a sequence of ELSE are treated as pairs. Each ELSE unit 2 is paired
statements and/or blocks preceded by a DO statement with the immediately preceding unpaired THEN
and terminated by an END statement. An example of unit 1. It is, therefore, necessary to specify an ELSE
a group is the following sequence of statements: unit 2 for each THEN unit l. In this case, unit 2 can be
DO; GET LIST (GROSS, NET); a "null" ELSE statement, that is, the word ELSE fol-
CALL PROFIT; END; lowed by a semicolon.
The following example illustrates the use of nested
This group may appear in an IF statement as fol-
IF statements, one of which employs a null ELSE
lows:
clause.
IF SALES == 22500 THEN DO; GET LIST (GROSS,
IF AGE> 21
NET); CALL PROFIT; END;
THEN
In this example, if the numerical value of SALES is IF WEIGHT < 150
equal to the constant 22500, the group of statements THEN IF HAIR == 'BROWN'
following the keyword THEN is executed; otherwise THEN GO TO TYPE1;
the group is skipped and control passes to the state- ELSE GO TO TYPE2;
ment after the END statement of the group. ELSE;
When the unit is a single statement, the DO and ELSE GO TO TYPE3;
END statements need not be specified unless iteration
In this example, the effect of the null ELSE state-
by means of the DO statement (discussed later) is
ment is to execute nothing, and to transfer control to
desired. The following statement is an example of a
the statement following GO TO TYPE3 should WEIGHT
single statement "unit."
< 150 be false and AGE > 21 be true.
IF PROFIT < 0 THEN GO TO LOSS;
statement n statement n
END; END;
The expressions in this form of the DO statement When specified this way, the sequence of state-
are arithmetic expressions and represent numeric ments is executed repeatedly until one of the follow-
values. (Arithmetic expressions are discussed in de- ing takes place: either the value of the data name falls
tail in Chapter 5.) When the DO statement is first outside the specified range, or the comparison expres-
encountered, data name is initialized to this value of sion associated with the WHILE becomes false.
expression 1, and this value is compared to the value of The following example illustrates the combined
expression 2; if the result of the comparison falls inside form of the DO statement:
the range of values of expression 1 and expression 2,
the sequence of statements is executed. The END DO INDEX == 10 TO 1 BY - 1
statement then returns control to the DO statement WHILE (DEDUCTION < ESTIMATE);
where the value of data name is incremented by the
value of expression 3. If the new value of data name
falls outside the limit specified by expression 2, con-
trol is sent to the statement following the END state- END;
ment; otherwise the sequence of statements is executed
and the END statement again transfers control to the In this example the value of INDEX goes from 10 to
DO statement. 1 in decrements of 1. When either the value of INDEX
The following example illustrates this form of the falls outside the range 10 to 1 or the comparison ex-
DO statement: pression DEDUCTION < ESTIMATE proves false, control
is sent to the statement following the END statement.
DO COUNTER == 1 TO 10 BY 1; Control may transfer into a DO group from outside
GET FILE· (MASTER) EDIT (ITEM( COUNTER)) the DO group only if the DO group is delimited by a
(A( 80) ); DO statement that does not specify repeated execu-
END; tion.
44
ON Statement of the statements executed after the execution of the
During the course of program execution anyone of a ON statement and before termination of block B (in-
certain set of conditions may occur that can result cluding execution of statements in all dynamic descend-
in an interruption. An interruption causes the suspen- ants of block B) is interrupted by the occurrence of
sion of normal program activities, in order to permit the condition specified in the ON statement, the state-
the execution of a special action. When the special ment or begin block appearing in the ON statement
action has been performed, program execution may is executed as though it were activated as a procedure
or may not resume at the point where it was sus- block. Control normally will be returned to the point
pended. The place in a program where an interruption following the interruption.
may occur is generally unpredictable. If, after a given action is established by execution
For most conditions that can cause an interruption, of an ON statement, and while this action specification
the programmer may specify the special action to be is still effective, another ON statement specifying the
performed. To do this, he may specify the condition same condition is executed, then the latter ON state-
in an ON statement; therefore these conditions are ment will take effect as described above, so that its
called ON-conditions. A discussion of individual ON- specified action will determine the interruption action
conditions appears later. Each ON-condition is given for the given condition. If both of these ON state-
a unique name suggestive of the condition. For ex- ments (old and new) are internal to the same block,
ample, ZERODIVIDE names the condition resulting the effect of the old ON statement is completely nulli-
from an attempt to divide by zero. These names (here- fied. When the new ON statement is in a block dy-
after called ON-conditions) are an intrinsic part of namically descended from the block containing the
the language, but the programmer may also use them old ON statement; the effect of the old ON statement
for other purposes (such as file names, data names, is temporarily suspended. The effect of the old ON
and label names) so long as no ambiguity exists. statement is restored upon termination of the block
The general forms of an ON statement are: containing the new ON statement.
The standard system action for ON conditions is
ON condition SNAP unit;
established automatically. In some situations, the pro-
ON condition SYSTEM;
grammer may want to specify his own action for a
The first form allows the programmer to state what given condition, for part of the execution of the pro-
action is to be performed when the specified condition gram, and then to have this specification nullified
occurs. The action is specified in the "unit"; it is writ- and allow the standard system action to occur.
ten either as an unlabeled single statement or an un- The following example illustrates how this may be
labeled begin block. Note that a RETURN statement done.
may not appear in the unit. The keyword SNAP is A: PROCEDURE;
optional; if specified, it produces a listing of informa-
tion relevant to the status of the program when the
specified condition occurs.
The second form specifies that a standard system ON ZERODIVIDE CALL ANALYSIS;
action is to be performed. (The standard system action
for each condition is discussed later.)
The following example:
ON ZERODIVIDE CALL ANALYSIS; ON ZERODIVIDE;
specifies that the statement:
CALL ANALYSIS;
be executed when division by zero is attempted. H
a standard system action is to be performed when divi- ON ZERODIVIDE SYSTEM;
sion by zero is attempted, the following statement
may be employed:
ON ZERODIVIDE SYSTEM;
ENDA;
Use of the ON Statement When control is transferred to procedure A, the
The ON statement is an executable statement. When ZERODIVIDE condition is enabled by the system;
executed, an ON statement internal to a block (for any ZERODIVIDE condition that occurs before the
example, block B) establishes an ON-action. Hany first ON ZERODIVIDE statement is executed will
46
error occurs during any calculation in procedure A, an ON Conditions
interruption is to take place. The following discussion presents some of the condi-
The prefix (SIZE, NOOVERFLOW) for procedure tion names used to identify ON-conditions and ex-
B specifies the same requirement with respect to a plains the circumstances under which the conditions
SIZE error for procedure B; in addition,· it specifies occur, the standard system action specified by PL/I
for procedure B that any interruption that might that would be taken in the absence of a programmer-
be caused by an OVERFLOW condition is to be specified action and, where applicable, the result of
suppressed. any calculation affected by a condition.
After the beginning of execution of procedure A,
and before the execution of the first ON statement, • CONVERSION
any size error will result in an interruption with stand- This condition occurs when conversion (either inter-
ard system action. After execution of the first ON nal or during input/output) from one data type to
statement, and before execution of the ON statement another causes erroneous results; no assumption should
in the activated procedure B, any SIZE error will result be made about the result of the conversion; the stand-
in an interruption with execution of the statement GO ard system action is to list a comment and cause the
TO A-ERROR;. After execution of the ON statement iIi ERROR condition to occur.
procedure B, the statement GO TO B-ERROR; becomes • ENDFILE (filename)
established for the SIZE condition, but the effect of This condition occurs during a GET or READ opera-
the previous ON statement is suspended only tem- tion when an attempt is made to read past the file
-porarily. After the RETURN statement in procedure B delimiter of the specified file; the standard system
is executed, the effect of the previous ON statement is action is to list a comment and cause the ERROR
reinstated, so that SIZE errors occurring after this point condition. If the EVENT option has been specified,
result again in the execution of the statement GO TO the interrupt awaits execution of the associated WAIT
A-ERROR;.
statement.
If any overflow condition occurs during the ex-
ecution of procedure A, an interruption will result • ENDPAGE(filename)
with the standard system action for the OVERFLOW This condition occurs during a PUT operation when
condition. However, for any occurrence of an overflow an attempt is made to start a new line beyond the
condition during the execution of procedure B, the limit specified by the PAGESIZE option in the OPEN
interrupt will be suppressed. statement; the condition occurs only once per page
so that additional lines can be printed on the page
In the following example: as a result of a programmer-specified action; the
standard system action is to start a new page and con-
tinue processing.
(NOOVERFLOW): A: PROCEDURE;
• • ERROR
This condition occurs when an error situation forces
processing to terminate; the standard system action
is to cause the FINISH condition to occur.
(OVERFLOW): B: BEGIN;
• • FINISH
• This condition occurs immediately before processing
• reaches its normal termination; the standard system
END B; action is to terminate processing.
• • FIXEDOVERFLOW
• This condition occurs when the result of a fixed-point
• arithmetic operation exceeds the maximum size de-
END A; fined by the implementation; the result is undefined;
the standard system action is to list a comment and
cause the ERROR condition to occur.
interruptions will be suppressed for overflow condi-
tions occurring during execution of that part of pro- • OVERFLOW
cedure A that is not included in block B. Overflow This condition occurs when the exponent of a float-
conditions occurring during execution of block B will ing-point number exceeds the maximum size defined
result in an interruption. by the implementation; the result is undefined; the
• SUBSCRIPTRANGE
This condition occurs when a subscript is evaluated
and found to lie outside its specified bounds; no as-
sumption should be made about the result of the
evaluation; the standard system action is to list a
comment and cause the ERROR condition to occur.
Static Storage
• TRANSMIT (filename) Storage for a data name with the STATIC attribute
This condition occurs when a permanent transmission is allocated before execution of the program and is
error is detected on the specified file; the standard never released during execution. A data name de-
system action is to list a comment and cause the clared with the STATIC attribute may be declared
ERROR condition to occur. If the EVENT Qption has with either the EXTERNAL or INTERNAL scope
been specified, the interrupt awaits execution of the attribute (discussed earlier in this chapter). An EX-
associated WAIT statement. TERNAL data name with an unspecified storage class
has, by default, the STATIC attribute .
• UNDERFLOW
This condition occurs when the exponent of a Hoating-
point number is smaller than the permitted minimum
defined by the implementation; the result is undefined.
The standard system action is to list a comment and
cause the ERROR condition to occur.
Automatic Storage
• ZERODIVIDE
This condition occurs when division by zero is at- If a data name has the attribute AUTOMATIC, the
tempted; no assumption should be made about the block in which this data name is declared determines
result of the division; the standard system action is the dynamic allocation for the data name. When this
to list a comment and cause the ERROR condition block is activated during execution of a program,
to occur. storage is allocated to the data name, and remains
allocated until termination of the block.
Note that termination of a block by means of a
GO TO statement may cause simultaneous termination
of other blocks and, consequently, simultaneous re-
Storage Allocation
lease of storage for all data names declared in these
Because the internal storage of a computer is limited blocks with the AUTOMATIC attribute.
in size, the efficient use of this storage during the The scope attribute of a data name declared with
execution of a program is frequently a crucial con- the APTOMATIC attribute must be INTERNAL.
sideration. PL/I provides several methods for control- The INTERNAL attribute may be explicitly declared
ling the allocation of storage to the values of a par- or may apply by default. A data name declared with
ticular data name in a program. the INTERNAL attribute but with an unspecified
48
storage class has, by default, the AUTOMATIC attri- otherwise, no attributes are needed. Because the attri-
bute. If both the storage and scope attributes are not butes FIXED, FLOAT, DECIMAL, and BINARY are
specified for a data name, AUTOMATIC storage is not permitted in an ALLOCATE statement, it is not
assumed to apply to it. possible to alter the storage size allocated to data
items described with these attributes.
When the length of a string or the number of items
Controlled Storage
in a dimension of an array is specified in an ALLO-
When a data name has the attribute CONTROLLED, CATE statement, it overrides similar information given
storage allocation must be specified for the data name in a DECLARE statement. If the length of a string or
with the ALLOCATE and FREE statements. CON- the number of items in a dimension of an array is not
TROLLED data names may be declared with either specified in an ALLOCATE statement, it must be
the EXTERNAL or INTERNAL scope attribute. specified in a DECLARE statement.
Asterisks may be used in place of the string length
or the number of items in a dimension for a data name
Based Storage specified in an ALLOCATE statement. The asterisks
The BASED attribute relates to list processing and indicate that the string length or dimension limits are
RECORD transmission. The BASED attribute can the same as those of the most recent allocation for the
establish a pointer variable that automatically main- data name.
tains the storage address of the data associated with Consider the following example:
the based variable. A: PROCEDURE;
A data name having the BASED attribute may iden- DECLARE PRICE (100) FIXED (4, 2)
tify and describe data having any storage class, but CONTROLLED, COUNT FIXED (2)
the EXTERNAL attribute cannot be associated with INITIAL (50);
it. The default storage class for the pointer variable is
AUTOMATIC. •
ALLOCATE PRICE;
ALLOCATE Statement
The ALLOCATE statement, when executed, causes
storage to be allocated to a specified data name de-
ALLOCATE PRICE. (75);
clared with either the CONTROLLED or BASED
attribute. An ALLOCATE statement may have the
following form:
ALLOCATE data name attribute 1 • • • attribute ALLOCATE PRICE ( ~ );
n;
The data name in an ALLOCATE statement may
be the name of an array or of a major structure. If
storage is to be allocated for a major structure, then ALLOCATE PRICE ( COUNT);
the entire structure, including all level numbers and
identifiers, must be included in the ALLOCATE state-
ment in the same manner as they appear in the DE-
CLARE statement. The ALLOCATE statement may END A;
allocate to a structure an amount of storage that dif- The array called PRICE is declared to consist of 100
fers from the amount of storage specified for the positions. The attribute CONTROLLED, however, in-
structure in a DECLARE statement. When this oc- dicates that storage for PRICE will be allocated only
curs, attributes are required in the ALLOCATE state- when an ALLOCATE statement is executed for
ment only for those elementary items in the structure PRICE. The first ALLOCATE statement in the example
that require a new size. uses the number 100 specified in the DECLARE
The only attribute names permitted in an ALLO- statement as the number of positions in PRICE. When
CATE statement are BIT, CHARACTER, and INI- the second ALLOCATE statement is executed, only
TIAL. These attributes are required only to indicate 75 array positions are allocated to PRICE. The third
a change in the length of a string or to specify a new ALLOCA TE statement uses the number of positions
initial value to be assigned when allocation occurs; established in the most recent allocation to PRICE.
52
When this statement is executed, a data item equiv- Bit-String Data to Character-String Data
alent in value to the data item currently assigned to A character string is created that contains 1 charac-
COST is created and stored in the storage area asso- ters and 0 characters. The 1 characters in the charac-
ciated with PRICE. The data item associated with COST ter string correspond to the 1 bits in the bit string. The
remains unmodified. The conversion techniques dis- o characters correspond to the 0 bits.
cussed for constants also apply to this statement. For
example, if the attributes of PRICE specify a fixed-point
decimal number, and the attributes of COST specify Character-String Data to Bit-String Data
a floating-point binary number, the creation of the A bit string is created that contains 1 bits and 0 bits.
data item for PRICE will involve a conversion from The 1 and 0 bits in the bit string correspond, respec-
floating-point binary representation to fixed-point deci- tively, to the 1 and 0 characters in the character string.
mal representation. No characters other than 1 and 0 characters are per-
Label names are also permitted as expressions in mitted in the character string; otherwise, the CON-
an assignment statement. If the names SWITCH and VERSION error-condition will occur (see "ON-Con-
POINTER are declared with the LABEL attribute, then
ditions" in Chapter 4).
execution of the following assignment statement:
POINTER == SWITCH;
Bit-String Data to Arithmetic Data
assigns to POINTER the current location identified by
The value of the bit string is interpreted as an un-
SWITCH.
signed fixed-point binary integer and is represented as
an arithmetic data item. This data item has the attri-
Conversion Between Data Types butes of the data name for which it is created (for
example, floating-point decimal, fixed-point binary,
Data names and expressions of unlike data type can
etc.). When the length of a varying-length bit string is
be used in assignment statements. For example, if
zero, the value of the bit string (and of the arithmetic
CODE is declared with the attribute CHARACTER
data item) is zero.
( 10) and MASK with an attribute BIT (10), the fol-
lowing assignment statement:
CODE == MASK; Character-String Data to Arithmetic Data
will create, as a data item for CODE; a string of ten The character string must have the form of a PLjI
characters that contains only the characters 1 and O. arithmetic constant, otherwise the CONVERSION
The 1 bits in MASK become the 1 characters in CODE, error-condition will occur (see the ON statement in
and the 0 bits in MASK become the 0 characters in CODE. Chapter 4). The value of this arithmetic constant is
If the character length specified for CODE exceeds the used to create an arithmetic data item. The attributes
bit length specified for MASK, the data item created of the data name for which the arithmetic data item
for CODE is extended on the right-hand side with blank is created determine the representation of the data
characters. Truncation of excess characters on the item (for example, fixed-point decimal, floating-point
right of the data item created for CODE occurs when binary, etc.). When the length of a varying-length
the bit length specified for MASK exceeds the character character string is zero, the value of the character
length specified for CODE. string (and of the arithmetic data item) is zero.
The example above illustrates how an assignment
statement may convert the bit-string representation
of a value to the equivalent character-string represen- Arithmetic Data to Character-String Data
tation. In an assignment statement, there are six ways The value of the arithmetic data item i~ represented
in which data values can be converted from one repre- as a character string. The format of this character
sentation to another. string is determined by the rules for list-directed out-
1. Bit-string Data to Character-String Data put discussed in Chapter 3.
2. Character-String Data to Bit-String Data
3. Bit-String Data to Arithmetic Data
4. Character-String Data to Arithmetic Data Arithmetic Data to Bit-String Data
5. Arithmetic Data to Character-String Data The value of the arithmetic data item is represented
6. Arithmetic Data to Bit-String Data as a fixed-point binary number. The integral portion
The following discussion states the rules employed of this number is then used to create the bit-string
by PLjI for each of these conversions. data item.
54
Conversion of Arithmetic Data times during the execution of a program. When effi-
Arithmetic operators in an expression may be used ciency is desired, string data should be converted to
with data names and constants that possess different an arithmetic representation before it is employed in
data characteristics. When the value of a decimal arithmetic expressions.
number and the value of a binary number are joined
by an arithmetic operator, the value of the decimal
Comparison Expressions
number is converted to a binary value. Similarly, the
value of a fixed-point data item is converted to a A brief description of comparison expressions appears
floating-point value, except when the fixed-point item in Chapter 4. The following discussion presents a more
is a positive exponent, that is, a positive integer ap- detailed description of the various types of comparison
pearing to the right of an exponentiation operator. In expressions, and shows how comparison expressions
the latter case, the fixed-point value is not converted may be used for purposes other than that of controlling
to floating-point. the sequence of execution within an IF statement.
When floating-point data appears on the left of an The eight comparison operators are:
arithmetic operator, the result of the arithmetic oper- > (greater than)
ation is in floating-point format, and the accuracy of ,> (not greater than)
the result is the greater accuracy of the two numbers > == (greater than or equal to)
involved in the operation. (equal to)
Fixed-point data on the left of an arithmetic opera- ,== (not equal to)
tor causes the result to be in fixed-point format. How- < (less than)
ever, if the operation is exponentiation and if the fixed- , < (not less than)
point item on the right is not a positive integer, both < == (less than or equal to)
numbers involved in the exponentiation are converted They may be used to form three types of comparison
to floating-point format and the result is in Hoating- expressions: arithmetic, character, and bit. The values
point format. of arithmetic data items are compared algebraically;
Conversion from floating-point format to fixed-point negative values compare lower than positive values.
format occurs only when explicitly required, as in the Character strings are compared character by character
case of an assignment statement that has a data name from left to right. When the character strings differ in
described as fixed-point to the left of the equal sign. length, both lengths are made equal by appending
If this name cannot accommodate the converted float- blank characters to the right of the shorter string. An
ing-point value with full accuracy, truncation will oc- implementation-defined collating sequence specifies
cur as required on both sides of the decimal point, the order of character comparison. Bit strings involve
and the SIZE error-condition may be produced (see the left-to-right comparison of binary digits. When
"ON Statement" in Chapter 4). the bit strings differ in length, the shorter string is
After conversions have occurred, the arithmetic extended on the right with zero bits. A zero bit com-
operation is performed. The accuracy of intermediate pares lower than a one bit.
arithmetic results occurring in the evaluation of an The value of a comparison expression is represented
expression is automatically accounted for; however, by a bit string of length one. The bit constant 'l'B
each implementation of PLjI may restrict the accuracy represents the value of a true comparison; the bit con-
of intermediate results to a specified maximum. stant 'O'B represents the value of a false comparison.
Arithmetic expressions are permitted as subscripts Consider the following comparison expression:
(see Chapter 2). When a subscript expression is eval-
uated, the result is converted, if necessary, to fixed- HOURS> 40
point binary and truncated, if necessary, to an integer. This expression is true when the numeric value of
A maximum subscript value is specified for each PL/I HOURS is greater than 40; when this occurs, the value
implementation. of the comparison expression is the bit constant 'l'B;
String data may also be employed in an arithmetic otherwise, the value is 'O'B.
operation; when this occurs the string data is converted The data names and constants used in a comparison
to arithmetic data. The conversion satisfies the rules expression may be of different d.at~ types. A priority
discussed earlier in this chapter under "Conversion on data types is used to convert tM values involved in
Between Data Types." The use of string data in arith- a comparison expression fropI/ "one data type to an-
metic expressions may result in the inefficient execu- other. Arithmetic data has "the highest priority; char-
tion of a compiled program; this is particularly true acter-string data, the next; and bit-string data, the
when the same expression must be evaluated many lowest priority. Conversion of data types in a com-
56
A>B&C<D converted to character string, and the result is a char-
is equivalent to acter string. Consider the following expression:
(A>B)&(C<D) , l0101'B II 'Z9X8Y7'
A+B<c-DIE>F When evaluated, this expression is equivalent to the
is equivalent to following character string:
((A+B)«C-D) )I(E>F)
, lO101Z9X8Y7'
'A<B&C==D
is equivalent to Execution of the following statement:
( ( 'A) < B) & (C==D) LABEL == NAME II ADDRESS;
A& ' B I'C > D causes the values of NAME and ADDRESS to be converted,
is equivalent to if necessary, to character strings. The character string
( A& ( 'B) ) I( ('C) > D) representing the value of ADDRESS is then appended to
A+B & C~D the right end of the character string associated with
is equivalent to NAME. The resulting character string is assigned to
(A+B )&( C~D) LABEL in conformity with the attributes of LABEL.
When expressions are evaluated, intermediate re- The concatenation operator may appear with arith-
sults are converted from one data representation to metic, comparison, and bit-string expressions; when
another as required by each operator. In the last ex- so employed, this concatenation operator has the low-
ample above, the arithmetic results of the expressions est priority of all operators.
A+ Band C~ D are converted to bit strings before the Consider the following statement:
operator & is carried out. COMMENT == 'SALARY IS $'1 IBASE + COMMISSION;
Bit-string expressions can be used as well as com-
The arithmetic expression BASE + COMMISSION is
parison expressions in an IF statement. In an IF
evaluated and the result is converted to a character
statement, when a bit-string expression is evaluated
string. This string is then appended to the character-
and this resulting bit string contains one or more 1
string constant 'SALARY IS $', and the result is assigned
bi~s, the expression is considered to be true; otherwise,
to COMMENT.
it is considered to be false. In the following example:
IF, (A&B) THEN GO TO REORDER;
ELSE GO TO INVENTORY; Array Expressions
when the bit string resulting from the evaluation of The data names permitted in an assignment statement
the bit-string expression' (A&B) contains one or more may be subscripted names. Consider the following
1 bits, the statement GO TO REORDER is executed; declaration, where TAX, TAXABLE, and RATE are the
otherwise, the statement GO TO INVENTORY is per- names of three arrays:
formed. DECLARE TAX (100) FIXED (4,2),
TAXABLE (100) FIXED (5,2), RATE (100)
Concatenation Expressions FIXED (2,2);
The concatenation operator II enables one bit or char- The following assignment statement:
acter string to be appended to the right end of another.
For example, the following concatenation expression: TAX (1) == TAXABLE (1) ~ RATE (1)
,1234' II ' ABCD' multiplies the first value in the TAXABLE array by the
first value in the RATE array and stores the result in
is equivalent to the character-string constant: the first position of the TAX array. If similar calcula-
'1234ABCD' tions are to be performed for all positions in these
When bit strings are concatenated, the result is a arrays, a DO statement may be employed as follows:
bit string. The value of the following concatenation DO I == 1 TO 100 BY 1 ;
expression: TAX (I) == TAXABLE (I) ~ RATE (I) ;
'l1l1'B II 'oooo'B II 'l1l1'B END;
is equivalent to the bit-string constant: When this group of statements is executed, the data
name I is initially set to .1, and the assignment state-
'111100001111'B ment is executed. Control then returns to the DO
When one of the data items in a concatenation statement; the value of I is increased to 2, and the
operation is not a character string, the data item is assignment statement is executed again. This cycle of
58
Because subscripts may be moved to the right end assignment statement that uses the BY NAME op-
of a qualified name, the above statements may be tion. Consider the following structures:
written: 1 TOTAL, 2 GROSS, 2 NET, 2 TAX,
+
TOTAL. GROSS ( I ) == OLD. GROSS ( J) 1 OLD, 2 DATE, 2 GROSS, 2 NET,
N~W .GROSS ( K) ; 1 NEW, 2 DATE, 2 NET, 2 GROSS,
TOTAL.NET(I) == OLD.NET(J) + NEW.NET(K); The following assignment statement:
+
TOTAL. TAX ( I) ==OLD. TAX ( J ) NEW. TAX ( K);
TOTAL == OLD + NEW, BY NAME;
is equivalent to the following sequence of statements:
TOTAL.GROSS == OLD.GROSS + NEW.GROSS;
Assignment BY NAME TOTAL. NET == OLD.NET + NEW.NET;
An assignment statement involving structures may per- Although DATE appears in both the OLD and the NEW
form element-by-element assignment on the basis of structures, no addition is carried out for DATE because
corresponding names rather than on the basis of cor- this name is not part of the structure TOTAL.
responding positions in the structures. This type of
assignment is called assignment by name and is indi-
cated by appending BY NAME (with a separating
comma) to the right of the structure expression in the Data Editing
assignment statement, thus: The previous discussions in this chapter have con-
structure-name==structure-expression, BY sidered those aspects of data manipulation that involve
NAME; the evaluation of expressions and the assignment of
values to names. The following discussion presents
When structures are used with the BY NAME option an additional type of data manipulation that permits
in an assignment statement, corresponding data names the detailed editing of data items for printing pur-
must be contained in their respective structures in the poses. Editing may be described as an alteration of the
following manner: any names by which corresponding format and/or punctuation of a character-string data
data names may be qualified must be identical, except item, usually for such purposes as improving read-
for the name written in the assignment statement. ability or, as with paychecks, protecting the data item
Thus, the following structures could be used in an against unauthorized alteration. Editing involves the
assignment statement with the BY NAME option: addition of characters to the data item and/or the
1 MASTER,2NAME,3FIRST,3LAST,2ADDRESS, replacement of specified characters with other char-
1DETAIL,2ADDRESS,2NAME,3FIRST,3MIDDLE, acters. For example, in a payroll application, the digits
3LASI', representing an employee's salary might be 0015089.
These digits would be much more meaningful on a
The corresponding names in these structures are NAME,
paycheck in an edited form, such as $ <1- <1-150.89; the
FIRST, LAST, and ADDRESS. This example shows that the
asterisks would also hamper an attempt to alter the
declared order of the items within structures used in
amount.
an assigmnent statement with the BY NAME option
Editing is specified by a picture specification in
need not be the same. This example also shows that it
either a PICTURE attribute (discussed in Chapter 2)
is not necessary for structures to have identical struc-
or a P format description (discussed in Chapter 3).
turing when used in an assignment statement with the
The' PICTURE attribute appearing with a data name
BY NAME option.
in a DECLARE statement determines how data items
Using the structures described above, consider the
are edited when they are assigned to that data name.
following statement:
Data items may be assigned to data names by either
MASTER == DETAIL, BY NAME; the assignment statement, the GET statement, or the
This statement is equivalent to the following sequence READ statement. The P format description is used
of statements: to specify data editing during the execution of an
edit-directed PUT statement.
MASTER. NAME. FIRST == DETAIL.NAME.FIRST;
The following discussion describes the picture char-
MASTER.NAME.LAST == DETAIL.NAME.LAST;
acters that may be used to edit a character-string data
MASTER.ADDRESS == DETAIL. ADDRESS;
item. Examples are used to illustrate the effect of each
Expressions are also evaluated on the basis of corre- picture character and to show its relationship with the
sponding names when the expressions appear in an other picture characters.
The decimal point may be used only once in a picture speci- 12345 ZZZV.9 2345.0
fication of numeric data. It indicates that the corresponding
position in the character string contains a decimal point.
+ The + picture character is used the same way the $ picture 123 +999 +123
character is used, except that a + sign will appear when the 012 ++99 b+12
numeric value of the character string is greater than or -12 +999 bb12
equal to zero; otherwise no sign will appear. 000 +999 bOOO
$ The $ picture character, when used once in a picture speci- 123 $999 $123
fication, must appear at either the left or the right end of 123 999$ 123$
the picture specification. It indicates that a $ is present in 012 999$ 012$
the corresponding position of the character string. A se- 012 $999 $012
quence of $ picture characters may appear at the left end 123 $$99 $123
of the picture specification to indicate a drifting $ ; this 012 $$99 b$12
specifies that leading zeros be changed to blanks and that
the right-most leading zero be changed to a $. When all
numeric positions in the picture specification contain the $ 000 $$$.$ bbbbb
picture character and the numeric value of the character
string is zero, all positions of the character string are
changed to blank even if a decimal point is present.
~
The ~ picture character is similar to the Z picture character 00100 ~0099 ~0100
except that the 0 character is used instead of a blank char- 00000 000 ~~ ~oo ~o
acter to replace a leading zero. The 0 picture character must 00123 $00,999 $0~0123
/ The / picture character is used the same way the comma 12345 99/99/9 12/34/5
picture character is used, except that a / is present in the
corresponding position of the character string.
The comma picture character specifies that a comma is 1234 9,999 1,234
present in the corresponding position of the character string. 00123 $$$,999 bbb$123
If zero suppression occurs, the comma will appear only if
there is an unsuppressed digit to the left of the comma. If
there is no unsuppressed digit to the left of the comma, then
three possibilities arise:
a. The preceding character is ~ ; then the comma position 00123 ~,999 0~123
B The B picture character specifies that a blank character be 12345 ZZB999 12b345
inserted in the corresponding position of a character string.
60
Source Picture Edited
Data Specific a tion Data
CR The CR character pair may appear only at the right end of -123 $Z.99CR $1.23CR
a picture specification. It indicates that the chani.cter string 1234 $ZZ.99CR $12.34bb
contains CR if the numeric value of the character string is
less than zero; otherwise, blank characters are used instead
of the CR characters.
DB The DB character pair is used in the same way as the char- -1234 $ZZ.99DB $12.34DB
acter pair CR, except that the characters DB are used when 1234 $ZZ.99DB $12.34bb
the numeric value of the character string is less than zero. I
I The I picture character specifies that the corresponding 1021 Z99I
position in the character string contains a digit with an over-
punched + sign when the numeric value of the character 010000)
I 1 3 4 5 6t
string is greater than or equal to zero.
1"1"
221222)
R The R picture character is similar to the I picture char- -1021 Z99R
acter except that a - sign is overpunched when the numeric I
value of the character string is less than zero. 01 0000
I 1 3 • 5 6
1"111
1"111
221222
V The V picture character is used only once in a picture speci- 12345 ZZZV99 34500
fication of numeric data. It specifies that a decimal point 123.4 ZV999 3400
should be assumed at the corresponding position in the 123.4 ZV.999 3.400
character string. No decimal point is actually present in the
character string. Aligns on decimal point present in data
item.
Y The Y picture character specifies a conditional digit posi- 01020 Y9Y9Y b1b2b
tion. When the corresponding position in a character string
contains a zero (leading or non-leading), the zero will be
changed to a blank character; otherwise a non-zero digit
will remain.
Z The Z picture character specifies a conditional digit position. 12345 ZZZZZ 12345
When the corresponding position in a character string con- 01234 ZZZZZ b1234
tains a leading zero, the zero will be changed to a blank
character; otherwise a non-zero digit will remain. When all 00000 ZZZ.Z bbbbb
digits in the character string are changed to blank char- 0123 ZZZZ$ b123$
acters, a decimal point, if present, will also be changed to 0123 $ZZZZ $b123
a blank character. In a picture specification, the Z picture 0000 $ZZZZ bbbb
character must not be used to the right of the 9 picture 0000 ZZZ.9 bbbbb
character or to the right of a drifting picture character.
9 The 9 picture character indicates that the corresponding 12345 99999 12345
position in a character string always contains a decimal digit 123 $$99 $123
(0 through 9).
Chapter 5: Data Manipulation 61
PL/I and COBOL Comparison: without regard to the level structure of the
Data Manipulation groups, and data conversion, if specified, is ig-
The following discussion compares the data manipula- nored. When the assignment statement in PL/I
tion features of PL/I and COBOL. Both languages is applied to structures, the assignment is per-
use expressions to specify data calculations and the formed elementary item by elementary item and
picture specification to edit data. However, PL/I uses all data conversion is done as specified.
a single statement for all types of data manipulation, 2. The BY NAME option in PL/I is similar to the
whereas COBOL uses several different statements. The CORRESPONDING option in COBOL.
following list contains some of the more significant dif- 3. PL/I permits expressions to use data items that
ferences in the data manipulation features of both contain edit characters. COBOL does not pro-
languages: vide this feature.
1. The effects of the COBOL statements MOVE, 4. The bit string operators in PL/I are similar to
COMPUTE, ADD, SUBTRACT, MULTIPLY, the logical operators in COBOL. However, CO-
and DIVIDE are achieved in PL/I with the as- BOL has no data type that corresponds to the
signment statement. However, when the MOVE bit string data type of PL/I.
statement in COBOL is used with groups (the 5. The concatenation operator of PL/I is not avail-
equivalent of PL/I structures), data is moved able in COBOL.
62
Appendix
The following pages contain sample problems that quantity ordered, unit price, and total price appear
demonstrate some of the ways in which PL/I may be in that order on each line, and are placed at the follow-
used to solve data processing problems. The solution ing character positions: 10, 52, 59, 91, 97, and 104.
to each problem is by no means unique and makes no Actual decimal points, but no dollar signs, are to be
attempt at being optimum. Although these problems printed in the unit price and total price. Leading zeros
illustrate some concepts and uses of PL/I, they are in these amounts are to be changed to blanks. The
not intended to teach programming or programming- total price will always be less than $10,000.00
systems design.
Solution to Problem 1
BOOK-PRICING: PROCEDURE OPTIONS (MAIN);
Problem I - A Boole. Pricing Problem DECLARE
The catalog number, unit price, and title of each book 1 MASTER,
stocked by a book distributor are kept on a master 2 CATALOG-NO CHARACTER (5),
file. The file is arranged in sequence according to the 2 UNIT-PRICE FIXED (4,2),
catalog number of each book. The file is on tape and 2 TITLE CHARACTER (30),
has a standard end-of-file mark. A transaction file, 1 TRANSACTION,
also on tape, contains orders for books that specify the 2 CATALOG-NO CHARACTER (5),
catalog number, quantity of the book ordered, and the 2 QUANTITY FIXED (4),
customer making the order. The orders are arranged 2 CUSTOMER CHARACTER (40),
according to catalog number in the same sequence as 1 REPORT,
the master file. The last order in the transaction file 2 CUSTOMERCHARACTER (40),
contains the dummy catalog number 99999, and indi- 2 CHARACTER (5),
CATALOG-NO
cates the end of the file. The total- price of each trans- 2
TITLE CHARACTER (30),
action is to be calculated; a 3% discount is given for 2
QUANTITY FIXED (4),
orders over $150.00. A report is to be printed showing 2
UNIT-PRICE FIXED (4,2),
the customer, catalog number, hook title, quantity 2
TOTAL-PRICE FIXED (6,2),
ordered, unit price, and total price. PAGE-COUNT FIXED (2) INITIAL (0);
In the master file the information for each book has OPEN
the following format: the first five characters are alpha- FILE (MASTER-FILE) INPUT,
meric and represent the catalog number; the next four FILE (TRANSACTION-FILE) INPUT,
are decimal digits and represent the unit price - a FILE (REPORT-FILE) PRINT P AGESIZE (50)
decimal point is assumed before the last two digits; LINESIZE( 115);
the next 30 character positions contain alphameric ON ENDPAGE (REPORT-FILE) GO TO HEADING;
data representing the book title. ON ENDFILE (MASTER-FILE) GO TO ERROR;
The orders in the transaction file have the following HEADING: PAGE-COUNT == PAGE-COUNT 1; +
format: the first five character positions contain an PUT FILE (REPORT-FILE) EDIT
alphameric catalog number; the next five positions are ('BOOKS ORI?ERED', 'PAGE', PAGE-COUNT)
blank; a numeric integer representing the quantity (PAGE, COLUMN(10), A(13),
occupies the next four positions; then five blanks fol- COLUMN( 104),
low; the next 40 alphameric positions represent the A(4), COLUMN(109), P'Z9');
customer.
The report is to have 50 lines per page and is to be IF PAGE-COUNT > 1
double-spaced. The first line of each page is to con- THEN GO TO PRINT;
tain the heading BOOKS ORDERED, and each page GET FILE (MASTER-FILE) EDIT (MASTER)
is to be numbered in sequence, beginning with 1. The ( A ( 5), F ( 4,2 ), A ( 30) );
information printed on each line is to begin at charac- TRANSACTION-READ: GET. FILE
ter position 10 and is not to extend beyond character (TRANSACTION_FILE) EDIT (TRANSACTION)
position 115. The customer, catalog number, book title, (A( 5), X( 5), F( 4), X(5), A( 40»;
Appendix 63
IF TRANSACTION .CATALOG-NO == '99999' Solution to Problem 2
THEN GO TO FINISH; WORK-CARD: PROCEDURE OPTIONS(MAIN);
COMPARE: IF TRANSACTION.CATALOG-NO-'== DECLARE N FIXED ( 1), WORK-FILE FILE,
MASTER. CATALOG-NO NEW-WORK-FILE FILE, NAME CHARACTER
THEN DO; ( 15), DEPT CHARACTER (5),
GET FILE (MASTER-FILE) EDIT TIME (5) PICTURE '99.99',
(MASTER) (A( 5), F( 4,2), A( 30) ); TOTAL-TIME PICTURE '99V99',
GO TO COMPARE; AVERAGE-TIME PICTURE '99V99';
END; OPEN FILE (WORK-FILE) INPUT, FILE
TOTAL-PRICE == TRANSACTION. QUANTITY ~ (NEW-WORK-FILE) OUTPUT;
MASTER. UNIT-PRICE; ON ENDFILE (WORK-FILE) GO TO CLOSE;
IF TOTAL-PRICE > 150.00 THEN TOTAL-PRICE == READ: GET FILE (WORK-FILE) LIST (NAME,
0.97 ~ TOTAL-PRICE; DEPT, TIME);
TOTAL-TIME == 0;
DO N == 1 TO 5 BY 1;
REPORT == TRANSACTION, BY NAME; TOTAL-TIME == TIME (N) +
TOTAL-TIME;
REPORT == MASTER, BY NAME; END;
PRINT: PUT FILE (REPORT-FILE) EDIT (REPORT) AVERAGE-TIME == TOTAL-TIME / 5;
(SKIP(2), COLUMN(10), A(40), PUT FILE (NEW-WORK-FILE)
COLUMN(52), A(5), COLUMN(59), A(30), LIST (NAME,DEPT,TIME,TOTAL-TIME,
COLUMN(91), F( 4), COLUMN(97), AVERAGE-TIME) ;
P'ZZ.99', COLUMN(104), P'ZZZZ.99') GO TO READ;
GO TO TRANSACTION-READ; CLOSE: CLOSE FILE (WORK-FILE), FILE
ERROR: DISPLAY ('END OF FILE ON MASTER ( NEW-WORK-FILE) ;
BEFORE TRANSACTIONS FINISHED'); END WORK-CARD;
FINISH: CLOSE FILE (MASTER-FILE),
FILE (TRANSACTION-FILE), Problem 3 - A File Searcli
FILE (REPORT-FILE);
This example illustrates a type of analysis often re-
END BOOK-PRICING;
quired in marketing research and similar studies. A
personnel file is searched to find all records containing
certain specified data. Each record found is written
in a separate file and, when finished, a count of the
Problem 2 - A Work Card Study number of records found is displayed on a standard
The computer is directed to read a series of work display device.
cards showing the hours worked by employees and Each record consists of a 16-character name followed
then to compute the daily average for each employee. by a 24-bit code-string. Each bit position within the·
Each card contains several fields, one field for each code-string represents specific personnel data.
data item; a comma separates fields. The first data
item on each card is a name consisting of 15 alpha- Format of Code-String
meric characters. The next item is five alphameric Bit
Items Characteristics Positions
characters representing a department number. The
next five items are numeric and consist of five charac-
Sex Male 1
ters each with an actual decimal point in the third Female 2
character position. These are daily time items, repre- Age Less than 20 3
senting the hours worked on each of five workdays. At least 20 but not
An output file is to be created according to the con- over 50 4
ventions of list-directed output. The data items on Over 50 5
the input cards are to be duplicated in the output file. Height Over six feet 6
The data for each card is to be followed by the total At least five feet,
time and the average daily time. six inches, but not
In the actual processing the five daily time items are over six feet 7
treated as an array and a subscript N is used to ob- Less than five feet,
tain each time value in turn. six inches 8
64
Weight Over 185 pounds 9 3 HEIGHT
At least 120 pounds, (4 OVER-B,
but not over 185 4 FIVE-AND-A-HALF-To-B,
pounds 10 4 UNDER-FIVE--AND-A-HALF) BIT (1),
Less than 120 pounds 11 3 WEIGHT,
(4 OVER-I85,
Eyes Blue 12
4 BETWEEN_I85-AND_I20,
Brown 13
Hazel 14
4 UNDER-I20) BIT ( 1 ) ,
3 EYES,
Grey 15
(4 BLUE,
Hair Brown 16
4 BROWN,
Black 17 4 HAZEL,
Grey 18
4 GREY) BIT (1),
Red 19 3 HAIR,
Blond 20 (4 BROWN,
Bald 21 4 BLACK,
Education College 22 4 GREY,
High School 23 4 RED,
Grammar School 24 4 BLOND,
4 BALD) BIT (1),
The presence of a characteristic is indicated by a 3 EDUCATION,
one bit in the corresponding bit position of the code- (4 COLLEGE,
string. A zero bit indicates the absence of a character- 4 HIGH-SCHOOL,
istic. 4 GRAMMAR-SCHOOL)BIT (1),
A search is made to obtain the records of all persons COUNT FIXED (5),
having the following characteristics: (RESULT-FILE FILE OUTPUT,
1. Females under 20 years of age, five feet six inches PERSONNEL-FILE FILE INPUT) RECORD;
and over in height, from 120 to 185 pounds in OPEN FILE (PERSONNEL-FILE),
weight, with either hazel or brown eyes, not bald, FILE (RESULT-FILE);
having a high school education. ON ENDFILE (PERSONNEL-FILE) GO TO FINISH;
2. Males over 50 years of age, over six feet in height, COUNT = 0;
over 185 pounds in weight, and college-educated. INPUT: READ FILE (PERSONNEL-FILE) SET (p);
IF (FEMALE & AGE. UNDER--20
& 'HEIGHT. UNDER-FIVE--AND-A-HALF
& WEIGHT.BETWEEN-I85--AND-I20
Solution to Problem 3 & (EYES.HAZEL , EYES.BROWN)
FILE-SEARCH : PROCEDURE OPTIONS (MAIN); & 'HAIR. BALD & EDUCATION. HIGH-SCHOOL )
DECLARE I (MALE & AGE. OVER-50 & HEIGHT.OVER-B
1 PERSONNEL-RECORD BASED (P), & WEIGHT.OVER-I85 & EDUCATION.COLLEGE)
2 NAME CHARACTER (16), THEN DO; COUNT = COUNT + 1;
2 CODE-STRING, WRITE FILE (RESULT-FILE) FROM
3 SEX, ( PERSONNEL-RECORD) ;
(4 MALE, END
4 FEMALE) BIT (1), GO TO INPUT;
3 AGE, FINISH: DISPLAY ('COUNT IS ' " COUNT);
(4 UNDER-20, CLOSE FILE (PERSONNEL-FILE), FILE
4 TWENTY-TO_50, ( RESULT-FILE) ;
4 OVER-50) BIT (1), END FILE-SEARCH;
Appendix 65
Index
66
ELSE clause ............................................................................ 43 list-directed
enable ........................................................................................ 46 data specification .................................................................. 32
END statement ........................................................................... 35 input ...................................................................................... 32
use of ......................................................................................•35 output .................................................................................... 32
ENDFILE condition ................................................................ 47 transmission ....... .. ... .... .. ... ..... ...... ..... ..... ...... .. .. ... ...... .. .... .... ... 32
ENDPAGE condition .............................................................. 47 LOCATE statement ............................................................ 26, 27
ENTRY attribute ...................................................................... 39 multiplication .................................................................... :....... 54
entry name ................................................................................ 39 names .................................................................................... 8,11
ENVIRONMENT attribute .................................... ................. 24 qualified ... ..... ... .. .. .. .. .. ... ... .. ... ........ ... ... ... .. ...... ...... ..... .. .... 17, 27
ERROR condition .................................................................... 47 subscripted ...................................................................... 20, 27
exponentiation .......................................................... :................. 54 use of ................................................................................ 8,45
expressions nesting ........................................................................................ 37
arithmetic ..... .. ..... ....... 54 NO prefix .................................................................................. 46
array . '" .. .. ...... ... ... ... .. ... .... ........ ....... ......... ... .. ........ ... .. .. ..... 54, 57
evaluation of .......................................................................... 51 ON statement ............................................................................ 45
structure .. ... .. .. .. ... .. .. ...... .... ... .. ... .... .. .. ........ .. ..... .... .. . .. ... ..... .... 58 use of .................................................................................... 45
subscripts .......................................................................... 20,55 ON-conditions ...................................................................... 45,47
nullification of ........................................................................ 46
EXTERNAL attribute .............................................................. 37
prefixes used with .................................................................. 46
external declarations .................... '" .. .... ... ..... .... ......... .. ..... ....... 37
external procedure . .................................................................. 35 programmer-defined .............................................................. 45
OPEN statement ........................................................................ 25
factoring .................................................................................. " 22 operations
file arithmetic .. " ........................................................ ,....... .. .. ... ... 54
attributes ................................................................................ 24 array-array ............................................................................ 57
closing .................................................................................... 25 bit string ................................................................................ 56
names .................................................................................... 25 comparison ... ... .. ... . .... ... ... ... .. ... .. ..... .. ......... ........ ..... .... ... .. ...... 55
opening .................................................................................. 25 concatenation ....................................................................... 57
FILE attribute .......................................................................... 24 priority of .............................................................................. 54
FINISH condition .................................................................... 47 string ..................................................................................... 57
FIXED attribute ..... .................................................................. 12 operators
FIXEDOVERFLOW condition ................................................ 47 arithmetic ............................................ '" .. .. ... ...... ... ... .. .. ... ..... 54
fixed-point ............. ................... 11 bit string ................................................................................ 56
FLOAT attribute ...................................................................... 12 comparison ............................................................................ 55
floating-point ............................................................................ 12 infix ....................................................................................... 54
form, coding .............................................................................. 7 prefix ...................................................................................... 54
format string ...................................................................................... 57
of data-directed output ........................................................ 33 output ........................................................................................ 24
of list-directed I/O ................................................................ 32 OUTPUT attribute .................................................................. 24
format items OVERFLOW condition ............................................................ 47
control .................................................................................... 31 PACKED attribute .................................................................. 21
data ........................................................................................ 28 PAGE format item ......................................................... ............ 31
format list ......... :; .......... ,.......................................................... 28 PAGESIZE option .................................................................... 25
FREE statement ........................................................................ 50 parameters .... '" ... ...... .... ..... .. ..... ........ ........ ... ... .. ..... ... ......... .... ... 38
FROM option ............................................................................ 26 PICTURE attribute ...................................................... 13, 30, 59
GET statement .................................. :....................................... 27 with numeric data .......................................................... 14,60
GO TO statement .................................................................... 41 specification ............................................................................ 60
with string data .............................................. ................ 14, 61
IDENT option .......................................................................... 25 picture format items ..... .. ........................................................ 60
identifiers ................................................. '" ..... .. ......... .. ..... .. ..... 8 pointer ................................................................................ 26
length of ................................................................................ 8 POSITION attribute ................................................................ 15
keywords ................................................................................ 8 precision ........ ,....................... ,................. '" ..... .... .. ..... .... ... .... .... 12
IF statement .............................................................................. 42 prefix .......................................................................................... 46
infix operators ............................................................................ 54 operators .............................................. '" .... .................... .. ..... 54
INITIAL attribute .................................................................... 21 PRINT attribute ........................................................................ 24
INPUT attribute ........................................................................ 24 printing format items ............................................................ 31
input/output .............................................................................. 24 priority of operations ............................................................ 54
INTERNAL attribute .............................................................. 37 procedure ...... " ... .... .. .... ........ .. .. ........ ...... ............. ............ ..... ..... 35
internal procedure .................................................................... 35 external .................................................................................. 35
internal to .................................................................................. 41 internal ..... '" .... ... .. .. .... ... ..... .. ... ......... ... ....... ... ............ .. ....... ... 35
name ...................................................................................... 35
keyword ...................................................................................... 8 termination of ........................................................................ 35
label .................................................................................. 8, 12, 53 PROCEDURE statement ........................................................ 35
LABEL attribute ................ ...................................................... 21 program structure .... ... .. ... ......... ........ .. .. .... ... .. .. .. .. . .... ... .. .... 35, 20
length PUT statement .......................................................................... 27
data item ............................................................................... 51 qualified names .... .... ... .. ........ ....... ....... .. ......... .. .............. .......... 17
identifiers ................. '" ...... ...... ..... ... ................ ... .. ... .. ... . .. ...... 8 quotation marks ........................................................................ 11
strings ................................................................................... 52 READ statement ...................................................................... 26
level numbers ................................................ ............................. 16 RECORD
also see structures attribute ................................................................................ 24
LIKE attribute .......................................................................... 21 transmission statements ........................................................ 26
LINE format item .................................................................... 31 repetition ..... ............................. ................ ... 11, 14,30
LINE SIZE option ...................................................... .............. 25 REPLY option ...................................................................... 34
Index 67
RETURN statement .................................................................. 40 data-directed .................................................................... 33
REWRITE statement .............................................................. 27 edit-directed ...................................................................... 27
scope list-directed ...................................................................... 32
of declarations ....... ..... ...... .......... ..... ............... ...................... 36 string
of condition prefixes ............................................................ 46 assignment ............................................................................ 52
scope attributes .... ....... .... ..... ........ ..... ..... ............... ... .............. .. 37 attributes .............. ........... ................... ............. ... .................. 13
sequence data ........................................................................................ 10
collating ................................................................................ 55 STRING option ........................................................................ 33
of control ................................................................................ 40 structure .................................................................................... 16
~T ~
assignment ............................................................................ 58
sign pi~·t~~~··~h~~~~t~~~·· ............................................................................................................................ 60 BY NAME ............................................................................ 59
SIZE condition .......................................................................... 48 declarations and attributes .................................................. 16
SKIP format item ...................................................................... 31 with LIKE attribute ............................................................ 21
SNAP option ............................................................................ 45 level numbers ........................................................................ 17
spacing, printing ...................................................................... 31 SUBSCRIPTRANGE condition .............................................. 48
specification .............................................................................. 30 subscripts ............ ................................. ..................................... 20
statements .................................................................................. 8 subtraction ................... ,... ..................................................... 54
STATIC attribute .................................................................... 48 SYSTEM option ........................................................................ 45
storage TO and By ................................................................................ 44
also see allocation TRANSMIT condition .............................................................. 48
ALLOCATE statement .................................................... 49 truncation on assignment ........................................................ 51
automatic ............................................................................ 48 UNBUFFERED attribute ....................................................... 24
controlled ........ ..... .... ... .. .. .... ... .. .... ....... .. .. ..... ....... ... ... ..... ... 49 UNDEFINEDFILE condition ................................................ 48
FREE statement ................................................................ 50 UNDERFLOW condition ........................................................ 48
static .................................................................................. 48 UPDATE attribute ................................ .. ..................... 24
storage class attributes ................. '" .................................... ,... 48 variables, based .. ....... ........... .................... ................................ 26
default for .............................................................................. 48 VARYING ................................................................................ 13
restrictions .............................................................................. 48
with structures ...................................................................... 49 WHILE clause .......................................................................... 43
STREAM WRITE statement .................................................................... 26
attribute ................................................................................ 24 ZERODIVIDE condition .......................................................... 48
transmission modes .. .. .... ... ... .. .... .. ... ... .. .... ... ....... .......... ..... ... 27 zero suppression .... ............................................................ 48, 60,
68
--
-- -- --
-- -
- - -
- -
--- International Business Machines Corporation
Data Processing Division
- -
---·T
-
-
---
---
- - 112 East Post Road, White Plains , New York 10601
(USA only)
SC2G-1651·2