Kednos PL/I for UNIX

Reference Manual

April 1996

This manual defines Kednos PL/I for UNIX. It includes the keywords
and the semantic and syntax rules of PL/I programming language
statements, attributes, built-in functions, and other language elements.

 

 

 

Operating System and Version: Digital UNIX Version 3.2 or
higher

Software Version: Kednos PL/I for UNIX
Version 1.3



 

Kednos Corporation
Pebble Beach, California
Second Printing (Update), April 1996

Kednos Systems, Inc., makes no representations that the use of its products in the manner described in this publication will not infringe on existing or future patent rights, nor do the descriptions contained in this publication imply the granting of licenses to make, use, or sell equipment or software in accordance with the description.

Possession, use, or copying of the software described in this publication is authorized only pursuant to a valid written license from Kednos or an authorized sublicensor.

No responsibility is assumed for the use or reliability of software on equipment that is not listed as supported in the Product Description.

Restricted Rights: Use, duplication or disclosure by the U.S. Government is subject to restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227-7013.

© Kednos Corporation, 1995, 1996, All Rights Reserved.

Kednos, Kednos PL/I, and Kednos VPO are trademarks of Kednos Corporation.

Alpha AXP, CDD, DEC,DEC 4000, DECwindows, Digital, OpenVMS AXP, ULTRIX, VAX, OpenVMS, VT102, VT220, VT240, VT320, VT330, VT340, and the DIGITAL logo are trademarks of Digital Equipment Corporation.

SAA and IBM are trademarks of International Business Machine Inc.

Stratus is a trademark of Stratus Computer Inc.

Kednos PL/I for UNIX includes the GNU readline and assembler software. See the Kednos PL/I for UNIX User's Manual for the entire text of the Free Software Foundation's GNU Copyleft.

Portions Copyright 1984-1990 FairCom Corporation. All Rights Reserved.

Kednos requests your critical evaluation to assist in preparing future documentation. Please send any comments to comments@Kednos.com or by physical mail to:

Kednos Corporation
1051 Rodeo Road
Pebble Beach, CA  93953

Preface xxiii

Intended Audience xxiii

Associated Documents xxiii

Conventions xxiv

Technical Assumptions xxv

Terminological Conventions xxv

Chapter 1 --

Program Structure and Content 1-1

Lexical Elements 1-1

Keywords 1-2

Punctuation 1-2

Identifiers 1-5

Comments 1-5

Statements 1-6

Statement Formats 1-7

Condition Prefixes (IBM Dialect Only) 1-7

Statement Labels 1-8

Simple Statements 1-8

Compound Statements 1-9

Preprocessor Statements 1-9

Summary of Statements by Function 1-9

Program Format 1-12

Blocks 1-13

Begin Blocks 1-15

Procedure Blocks 1-16

Containment 1-16

Block Activation 1-17

Relationship of Block Activations 1-17

Block Termination 1-20

Data and Variables 1-20

Preprocessor 1-21

Chapter 2 --

Declarations 2-1

DECLARE Statement 2-2

Simple Declarations 2-2

Declarations Outside Procedures 2-3

Multiple Simple Declarations 2-4

Factored Simple Declarations 2-4

Array Declarations 2-5

Structure Declarations 2-6

Attributes 2-7

ALIGNED Attribute 2-15

ANY Attribute 2-15

AREA Attribute 2-16

AUTOMATIC Attribute 2-17

BASED Attribute 2-17

BINARY Attribute 2-18

BIT Attribute 2-19

BUFFERED and UNBUFFERED Attributes (IBM Dialect Only) 2-20

BUILTIN Attribute 2-21

CHARACTER Attribute 2-22

CONDITION Attribute 2-23

CONTROLLED Attribute 2-23

DECIMAL Attribute 2-24

DEFINED Attribute 2-25

DIMENSION Attribute 2-26

DIRECT Attribute 2-27

ENTRY Attribute 2-28

ENVIRONMENT Attribute 2-30

EXTERNAL Attribute 2-33

FILE Attribute 2-34

FIXED Attribute 2-34

FLOAT Attribute 2-36

GLOBALDEF Attribute 2-36

GLOBALREF Attribute 2-37

INITIAL Attribute 2-37

INPUT Attribute 2-41

INTERNAL Attribute 2-42

KEYED Attribute 2-42

LABEL Attribute 2-43

LIKE Attribute 2-43

MEMBER Attribute 2-44

NONVARYING Attribute 2-44

OFFSET Attribute 2-44

OPTIONAL Attribute (Dec and Ansi Dialects Only) 2-45

OUTPUT Attribute 2-45

PARAMETER Attribute 2-46

PICTURE Attribute 2-46

POINTER Attribute 2-47

POSITION Attribute 2-47

PRECISION Attribute 2-48

PRINT Attribute 2-49

READONLY Attribute 2-49

RECORD Attribute 2-50

REFER Attribute 2-50

REFERENCE Attribute 2-50

RETURNS Attribute 2-51

SEQUENTIAL Attribute 2-52

STATIC Attribute 2-53

STREAM Attribute 2-53

STRUCTURE Attribute 2-54

TYPE Attribute 2-54

TRUNCATE Attribute 2-56

UNALIGNED Attribute 2-57

UNBUFFERED Attribute (IBM Dialect Only) 2-57

UNION Attribute 2-57

UPDATE Attribute 2-58

VALUE Attribute 2-59

VARIABLE Attribute 2-60

VARYING Attribute 2-60

Chapter 3 --

Data Types 3-1

Summary of Data Types 3-1

Declarations 3-2

Default Attributes 3-3

Attributes of Constants 3-4

Arithmetic Operands 3-5

Compatible Data Types 3-6

Arithmetic Data 3-8

Precision and Scale of Arithmetic Data Types 3-8

Fixed-Point Binary Data 3-9

Internal Representation of Fixed-Point Binary Data 3-10

Fixed-Point Decimal Data 3-11

Fixed-Point Decimal Constants 3-11

Fixed-Point Decimal Variables 3-12

Use in Expressions 3-12

Internal Representation of Fixed-Point Decimal Data 3-13

Floating-Point Data 3-13

Floating-Point Constants 3-14

Floating-Point Variables 3-14

Using Floating-Point Data in Expressions 3-15

Floating-Point Data Formats 3-15

IEEE S_floating Format 3-16

IEEE T_floating Format 3-17

Character Pictured Data 3-17

Character Picture Characters 3-18

Examples of Character Picture Variable Definitions 3-18

Numeric Pictured Data 3-19

Picture Characters 3-20

Picture Syntax 3-28

Examples 3-31

Assigning Values to Pictured Variables 3-32

Extracting Values from Pictured Data 3-33

Editing by Picture 3-34

The Internal Representation of Pictured Variables 3-34

Character String Data 3-36

Character String Constants 3-36

Replication of String Constants 3-37

Character-String Variables 3-37

Fixed-Length Character String Variables 3-38

Internal Representation of Fixed-Length Character Data 3-39

Varying-Length Character String Variables 3-39

Internal Representation of Varying Character Data 3-40

Alignment of Character Strings 3-40

Bit-String Data 3-40

Bit-String Constants 3-41

Replication Factor for Bit-String Constants 3-42

Bit-String Variables 3-43

Alignment of Bit-String Data 3-44

Internal Representation of Bit Data 3-45

Bit Strings and Integers 3-48

Pointer Data 3-49

Pointer Variables in Expressions 3-50

Internal Representation of Pointer Data 3-50

Offset Data 3-50

Label Data 3-51

Label Array Constants 3-52

Label Values 3-54

Label Variables 3-55

Internal Representation of Label Variables 3-56

Entry Data 3-57

Entry Constants 3-57

Entry Values 3-58

Entry Variables 3-58

Internal Representation of Entry Variables 3-59

File Data 3-60

File Constants 3-60

File Values 3-61

File Variables 3-61

Area Data 3-62

Area Variables in Expressions 3-63

Reading and Writing Areas 3-63

Internal Representation of Area Data 3-63

Condition Data 3-64

Chapter 4 --

Aggregates 4-1

Arrays 4-1

Array Declarations 4-1

References to Individual Elements 4-5

Initializing Arrays 4-6

Assigning Values to Array Variables 4-10

Order of Assignment and Output for Multidimensional Arrays 4-11

Using GET and PUT Statements with Array Variables 4-12

Passing Arrays as Arguments 4-12

Built-In Functions Providing Array Dimension Information 4-13

Structures 4-14

Structure Declarations and Attributes 4-14

Using The UNION Attribute On Structure Declarations 4-16

Initializing Structures 4-17

Using Structure Variables in Expressions 4-17

Passing Structure Variables as Arguments 4-18

Member Attributes 4-18

Using the TYPE Attribute 4-18

Using the LIKE Attribute 4-21

Using the REFER Option 4-23

Structure-Qualified References 4-27

Arrays of Structures 4-28

Arrays of Structures that Contain Arrays 4-29

Connected and Unconnected Arrays 4-30

Internal Representation of Aggregate Data 4-32

Chapter 5 --

Storage Classes 5-1

Automatic Variables 5-2

Static Variables 5-2

Internal Variables 5-3

External Variables 5-3

Based Variables 5-5

Data Types Used with Based Variables 5-6

Allocation in Areas 5-6

Referring to Based Variables 5-8

Based Variables and Dynamic Storage Allocation 5-10

Using the ADDR Built-in Function 5-13

Data-Type Matching for Based Variables 5-14

Matching by Overlay Defining 5-14

Matching by Left-to-Right Equivalence 5-15

Nonmatching Based Variable References 5-16

Examples of Based Variables 5-16

Controlled Variables 5-19

Using the ALLOCATION Built-In Function 5-20

Using the ADDR Built-In Function 5-21

Dynamically Allocated Variables 5-22

ALLOCATE Statement 5-22

FREE Statement 5-23

Other Mechanisms for Dynamic Storage Allocation 5-25

Defined Variables 5-25

String Overlay Defining 5-26

Rules for Overlay Defining 5-28

Storage Sharing 5-28

Chapter 6 --

Expressions and Data Type Conversions 6-1

Assignment Statement 6-1

Operators and Operands 6-4

Arithmetic Operators 6-5

Logical Operators 6-6

NOT 6-8

AND 6-8

OR 6-9

EXCLUSIVE OR 6-10

AND THEN 6-10

OR ELSE 6-11

Relational Operators 6-12

Arithmetic Comparisons 6-12

Bit-String Comparisons 6-13

Character-String Comparisons 6-13

Comparing Noncomputational Data 6-13

Concatenation Operator 6-14

Precedence of Operators and Expression Evaluation 6-15

Data Type Conversion of Operands and Expressions 6-17

Contexts in which PL/I Converts Data 6-18

Derived Data Types for Arithmetic Operations 6-21

Conversion of Operands in Nonarithmetic Operations 6-22

Built-In Conversion Functions 6-23

Implicit Conversion During Assignment 6-24

Assignment to Arithmetic Variables 6-25

Arithmetic to Arithmetic Conversions 6-25

Pictured to Arithmetic Conversions 6-27

Bit-String to Arithmetic Conversions 6-27

Character-String to Arithmetic Conversions 6-29

Assignments to Bit-String Variables 6-30

Arithmetic to Bit-String Assignments 6-30

Pictured to Bit-String Conversions 6-32

Character-String to Bit-String Conversions 6-33

Assignments to Character-String Variables 6-33

Arithmetic to Character-String Conversions 6-34

Pictured to Character-String Conversion 6-37

Bit-String to Character-String Conversion 6-37

Assignments to Pictured Variables 6-37

Conversions Between Offsets and Pointers 6-38

Chapter 7 --

Procedures 7-1

PROCEDURE Statement 7-2

Functions and Function References 7-4

ENTRY Statement 7-5

Specifying Entry Points 7-7

Multiple Entry Points 7-8

CALL Statement 7-9

Parameters and Arguments 7-10

Rules for Specifying Parameters 7-13

Argument Passing 7-15

Calling External and Internal Procedures 7-18

Terminating Procedures 7-20

Passing Arguments to Non-PL/I Procedures 7-22

Passing Arguments by Immediate Value 7-22

Passing Arguments by Reference 7-23

Chapter 8 --

Program Control 8-1

DO Groups and Statements 8-1

Simple DO 8-2

DO WHILE 8-3

DO UNTIL 8-4

DO REPEAT 8-6

Controlled DO 8-9

BEGIN Statement 8-13

END Statement 8-15

IF Statement 8-16

Nested IF Statements 8-17

SELECT Statement 8-18

The Two Forms of the SELECT Statement 8-19

OTHERWISE Clause 8-21

Nested SELECT Statements 8-21

GOTO Statement 8-22

LEAVE Statement 8-26

STOP Statement 8-28

Null Statement 8-29

Condition Handling 8-30

ON Statement 8-30

SIGNAL Statement 8-31

REVERT Statement 8-32

Summary of ON Conditions 8-34

ANYCONDITION Condition 8-37

AREA Condition 8-37

ATTENTION Condition (IBM Dialect Only) 8-37

CHECK Condition (IBM Dialect Only) 8-38

CONDITION Condition 8-39

CONVERSION Condition 8-39

ENDFILE Condition 8-42

ENDPAGE Condition 8-43

ERROR Condition 8-45

FINISH Condition 8-45

FIXEDOVERFLOW Condition 8-46

KEY Condition 8-47

NAME Condition (IBM Dialect Only) 8-49

OVERFLOW Condition 8-50

RECORD Condition (IBM Dialect Only) 8-50

SIZE Condition (IBM Dialect Only) 8-51

STRINGRANGE Condition 8-53

STRINGSIZE Condition (IBM Dialect Only) 8-55

SUBSCRIPTRANGE Condition 8-55

STORAGE Condition 8-56

TRANSMIT Condition (IBM Dialect Only) 8-56

UNDEFINEDFILE Condition 8-57

UNDERFLOW Condition 8-59

VAXCONDITION Condition 8-60

ZERODIVIDE Condition 8-60

Default PL/I ON-Unit 8-60

Using Condition Prefixes (IBM Dialect Only) 8-61

Scope of Condition Prefixes 8-61

Default Status of Conditions 8-62

Establishing ON-Units 8-63

Contents of an ON-Unit 8-64

Search Path for ON-Units 8-65

Completion of ON-Units 8-65

Chapter 9 --

Input and Output 9-1

Opening and Closing Files 9-1

File Declarations 9-2

File Variables 9-2

Opening a File 9-3

OPEN Statement Options 9-5

Effects of Opening a File 9-6

Establishing the File's Attributes 9-7

Determining the File Specification 9-8

Accessing an Existing File 9-9

Creating a File 9-9

File Positioning 9-10

File Description Attributes and Options 9-10

Closing a File 9-11

Stream I/O 9-12

Processing and Positioning of Stream Files 9-14

Input by the GET Statement 9-16

Syntax Summary of the GET Statement 9-16

GET EDIT 9-19

GET LIST 9-20

GET SKIP 9-23

Execution of the GET Statement 9-23

Output by the PUT Statement 9-26

Syntax Summary of the PUT Statement 9-26

PUT EDIT 9-29

PUT LINE 9-30

PUT LIST 9-31

PUT PAGE 9-32

PUT SKIP 9-32

Execution of the PUT Statement 9-33

Format Items 9-34

A Format Item 9-35

B Format Items 9-37

COLUMN Format item 9-41

E Format Item 9-42

F Format Item 9-46

LINE Format Item 9-49

P Format Item 9-50

PAGE Format Item 9-52

R Format Item 9-52

SKIP Format Item 9-55

TAB Format Item 9-55

X Format Item 9-57

Format Specifications 9-59

Processing and Positioning of Character Strings 9-67

Terminal I/O 9-68

Simple Input from a Terminal 9-68

Simple Output to a Terminal 9-69

Print File 9-70

Record I/O 9-73

READ Statement 9-75

File Positioning Following a READ Statement 9-77

WRITE Statement 9-79

File Positioning Following a WRITE Statement 9-80

DELETE Statement 9-83

File Positioning Following a DELETE Statement 9-84

REWRITE Statement 9-84

File Positioning Following a REWRITE Statement 9-85

LOCATE Statement (IBM Dialect Only) 9-87

File Positioning Following a LOCATE Statement 9-89

Position Information for a Record File 9-89

Chapter 10 --

Preprocessor 10-1

Preprocessor Compilation Control 10-2

Preprocessor Statements 10-3

%Assignment Statement 10-5

% (Null) 10-6

%ACTIVATE 10-6

%DEACTIVATE 10-8

%DECLARE 10-9

%DO 10-10

%END 10-11

%ERROR 10-11

%FATAL 10-12

%GOTO 10-12

%IF 10-14

%INCLUDE 10-14

%INFORM 10-17

%PROCEDURE 10-17

%REPLACE Statement 10-25

%RETURN Statement 10-26

%WARN 10-26

User-Generated Diagnostic Messages 10-27

Preprocessor Built-In Functions 10-29

Chapter 11 --

Built-In Functions, Subroutines, and Pseudovariables 11-1

Built-In Function Arguments 11-1

Conditions Signaled 11-2

Summary of Built-In Functions 11-2

Descriptions of Built-In Functions 11-9

ABS 11-9

ACOS 11-10

ADD 11-10

ADDR 11-11

ALL 11-11

ALLOCATION 11-12

ANY 11-13

ASIN 11-13

ATAN 11-13

ATAND 11-14

ATANH 11-14

BINARY 11-15

BIT 11-16

BOOL 11-16

BYTE 11-18

BYTESIZE 11-18

CEIL 11-18

CHARACTER 11-19

COLLATE 11-20

COPY 11-20

COS 11-21

COSD 11-21

COSH 11-21

CURRENTSTORAGE 11-21

DATE 11-22

DATETIME 11-23

DECIMAL 11-23

DECODE 11-24

DIMENSION 11-25

DIVIDE 11-26

EMPTY 11-26

ENCODE 11-27

ERF 11-27

ERFC 11-28

ERROR 11-28

EVERY 11-28

EXP 11-29

FIXED 11-29

FLOAT 11-30

FLOOR 11-30

HBOUND 11-31

HIGH 11-31

INDEX 11-32

INFORM 11-33

INT 11-33

LBOUND 11-35

LENGTH 11-36

LINE 11-36

LINENO 11-36

LOG 11-36

LOG10 11-37

LOG2 11-37

LOW 11-37

MAX 11-38

MAXLENGTH 11-38

MIN 11-39

MOD 11-40

MULTIPLY 11-42

NULL 11-43

OFFSET 11-44

ONCHAR 11-44

ONCODE 11-45

ONFILE 11-45

ONKEY 11-46

ONLOC 11-46

ONSOURCE 11-47

PLIRETV 11-47

POINTER 11-47

POSINT 11-48

PRECISION 11-50

PROD 11-50

RANK 11-51

REPEAT 11-51

REVERSE 11-52

ROUND 11-53

SEARCH 11-55

SIGN 11-56

SIN 11-57

SIND 11-57

SINH 11-57

SIZE 11-57

SOME 11-61

SQRT 11-61

STORAGE 11-61

STRING 11-62

SUBSTR 11-63

SUBTRACT 11-64

SUM 11-65

TAN 11-66

TAND 11-66

TANH 11-66

TIME 11-66

TRANSLATE 11-67

TRIM 11-69

TRUNC 11-71

UNSPEC 11-71

VARIANT 11-72

VERIFY 11-73

WARN 11-74

Built-In Subroutines 11-75

Pseudovariables 11-76

INT Pseudovariable 11-77

ONCHAR Pseudovariable 11-79

ONSOURCE Pseudovariable 11-80

PAGENO Pseudovariable 11-80

POSINT Pseudovariable 11-80

STRING Pseudovariable 11-82

SUBSTR Pseudovariable 11-83

UNSPEC Pseudovariable 11-84

Appendix A --

Alphabetic Summary of Keywords A-1

Appendix B --

Dialect Differences B-1

Data Declarations B-1

Data Types B-1

Condition Handling B-1

Condition Prefixes B-2

ON Conditions B-2

Return Values for Condition Signals B-2

Sort Support B-2

Record and Stream I/O B-2

Built-in Functions B-3

Built-in Subroutines B-3

Appendix C --

Compatibility with PL/I Standards B-1

Relation to the 1981 PL/I General-Purpose Subset B-1

Program Structure B-2

Program Control B-2

Storage Control B-2

Input/Output B-2

Attributes and Pictures B-3

Built-In Functions and Pseudovariables B-3

Expressions B-3

198x PL/I General-Purpose Subset Features Supported B-4

Lexical Constructs B-4

Program Control B-4

Storage Control B-4

Input/Output B-5

Attributes and Pictures B-5

Built-In Functions and Pseudovariables B-5

Expressions B-6

Full PL/I Features Supported B-6

Program Structure B-6

Program Control B-6

Storage Control B-6

Attributes and Pictures B-6

Built-In Functions and Pseudovariables B-7

Expressions B-7

Nonstandard Features from Other Implementations B-7

Preprocessor B-7

Program Control B-8

IBM Dialect I/O Features and Other IBM Dialect Features B-8

Built-In Functions B-8

LIKE Extension B-8

Declarations B-8

PL/I-Specific Extensions for the Digital Unix Platform B-8

Procedure-Calling and Condition-Handling Extensions B-8

Miscellaneous Extensions B-9

Implementation-Defined Values and Features B-10

Appendix D --

Migration Notes C-1

Keywords Not Supported C-1

Differences Between Kednos PL/I for UNIX Digital's PL/I and Other Digital-Compatible Versions of PL/I C-7

Statements C-7

Data Type Attributes C-7

Default Values for Data Type Attributes C-7

Floating Point Data Types C-8

Scale Factors C-8

Procedures and Entries Specified with the Returns Option C-8

Passing Arguments to Non-PL/I Procedures C-8

GOTO Statement C-9

Condition Handling C-9

File Handling C-9

Preprocessor C-9

Built-in Functions and Subroutines C-10

Appendix E --

Language Summary D-1

Statements D-1

Attributes D-9

Statement Format D-11

Expressions and Data Conversions D-12

Pseudovariables D-15

Built-In Subroutines D-16

Figure 1-1. Relationship of Block Activations 1-18

Figure 3-1. Internal Representation of Fixed-Point Binary Data 3-11

Figure 3-2. Fixed-Point Decimal Data Representation 3-13

Figure 3-3. IEEE S_floating Data Representation 3-16

Figure 3-4. IEEE T_floating Data Representation 3-17

Figure 3-5. Internal Representation of a Pictured Variable 3-35

Figure 3-6. Internal Representation of a Pictured Variable 3-35

Figure 3-7. Unaligned Bit String Storage 3-46

Figure 3-8. Sample Unaligned Bit String Storage 3-46

Figure 3-9. Aligned Bit String Storage 3-47

Figure 3-10. Sample Aligned Bit String Storage 3-47

Figure 3-11. Variable Label Data Representation 3-56

Figure 3-12. Entry Variable Data Representation 3-59

Figure 4-1. Specifying Elements of an Array 4-8

Figure 4-2. Storage of Structure with REFER Option 4-25

Figure 4-3. Remapped Storage of Structure with REFER Option 4-26

Figure 4-4. Connected and Unconnected Arrays 4-31

Figure 5-1. External Variables 5-4

Figure 5-2. Using the ALLOCATE Statement 5-11

Figure 5-3. Using the READ Statement with a Based Variable 5-13

Figure 5-4. Using the ADDR Built-In Function 5-14

Figure 5-5. An Overlay Defined Variable 5-27

Figure 11-1. Example of the BOOL Built-In Function 11-17

Table Pref-1. Documentation Conventions Table xxiv

Table 1-1. Punctuation Marks Recognized by PL/I 1-3

Table 1-2. Summary of PL/I Statements 1-10

Table 2-1. Alphabetic Summary of PL/I Attributes   2-10

Table 2-2. Default Values for BINARY Attribute 2-19

Table 2-3. Default Values for the DECIMAL Attribute. 2-25

Table 2-4. Default Values for Unspecified FIXED Attributes 2-35

Table 2-5. Default Values for Unspecified FLOAT Attributes 2-36

Table 3-1. Implied Attributes for Computational Data 3-3

Table 3-2. Default Values for Precision 3-9

Table 3-3. Ranges of Floating-Point Formats 3-15

Table 3-4. Ranges of Precision for Floating-Point Types 3-16

Table 3-5. Floating-Point Types Used by PL/I 3-16

Table 3-6. Picture Characters 3-20

Table 3-7. ASCII Representation of Encoded-Sign Characters 3-24

Table 4-1. Specifying Array Dimensions 4-3

Table 4-2. Natural Alignment for Structure Members 4-33

Table 6-1. Data Types for Assignment Statement 6-2

Table 6-2. Infix Arithmetic Operators 6-5

Table 6-3. Logical Operators 6-6

Table 6-4. Precedence of Operators 6-15

Table 6-5. Contexts in Which PL/I Converts Data 6-20

Table 6-6. Derived Data Types 6-21

Table 6-7. Converted Precision as a Function of Target and Source Attributes 6-22

Table 6-8. Built-In Functions for Conversions Between Arithmetic and Nonarithmetic Types 6-23

Table 6-9. Conversion from Fixed Binary 6-26

Table 8-1. Summary of ON Conditions 8-36

Table 8-2. Values of ONCODE Raised by RECORD 8-51

Table 8-3. Values of ONCODE Raised by SIZE 8-52

Table 8-4. Values of ONCODE Raised by STRINGRANGE 8-53

Table 8-5. Values of ONCODE Raised by STRINGSIZE 8-55

Table 8-6. Values of ONCODE Raised by TRANSMIT 8-57

Table 8-7. Conditions Enabled by Default 8-62

Table 8-8. Conditions Disabled by Default 8-62

Table 8-9. Conditions That Cannot be Disabled 8-62

Table 9-1. File Description Attributes Implied when a File is Opened 9-7

Table 9-2. Summary of File Description Attributes 9-10

Table 9-3. Attributes and Access Modes for Stream Files 9-12

Table 9-4. Input String Formatting 9-36

Table 9-5. Output String Formatting 9-37

Table 9-6. Input with the B Format Item 9-40

Table 9-7. Output with the B Format Item 9-40

Table 9-8. Representation of Floating-Point Values 9-43

Table 9-9. Input with the E Format Item 9-45

Table 9-10. Output with the E Format Item 9-45

Table 9-11. Input with the F Format Item 9-48

Table 9-12. Output with the F Format Item 9-48

Table 9-13. Input with the P Format Item 9-51

Table 9-14. Output with the P Format Item 9-52

Table 9-15. Attributes and Access Modes for Record Files 9-73

Table 9-16. Position Information for a Record File 9-89

Table 10-1. Summary of PL/I Preprocessor Statements 10-4

Table 10-2. Implied Attributes for Variables 10-9

Table 10-3. Summary of PL/I Preprocessor Built-In Functions 10-29

Table 11-1. Summary of PL/I Built-In Functions 11-3

Table 11-2. Summary of PL/I Built-In Subroutines 11-75

Table 11-3. Pseudovariables by Dialect 11-77

Table A-1. PL/I Keywords A-1

Table D-1. PL/I Keywords Not Supported C-1

Table D-2. Summary of Unsupported IBM I/O Features C-5

Table D-3. Digital Default Values for Data Type Attribute C-7

Table E-1. Operators D-12

Table E-2. Precedence of Operators D-13

Table E-3. Contexts in Which PL/I Converts Data D-14

Table 11-4. Summary of PL/I Built-In Subroutines D-16

Preface

Kednos PL/I for UNIX is a strict superset of the ANSI X3.74-1981 PL/I General Purpose Subset and provides most of the features of the new ANSI X3.74-1987 PL/I General Purpose Subset and many of the features of the ANSI X3.53-1976 (full) PL/I language standard.

Intended Audience

This manual is intended for programmers using PL/I to design or implement applications on UNIX systems. A prerequisite for attaining optimal benefit from the manual is that its users understand the concepts of programming in PL/I and are familiar with the keywords and topics that will be searched for information.

This manual is not suitable for use as a tutorial document.

Associated Documents

The Kednos PL/I for UNIX User's Manual provides information on program development with the system-specific command language, the extensive I/O capabilities provided in PL/I, and programming techniques available to PL/I programs executing under the exclusive control of the operating system.

For information on installing PL/I, see the Kednos PL/I for UNIX Installation Guide.

Conventions

. Documentation Conventions Table

Conventions

Meaning

 

This symbol represents a single stroke of the RETURN key on the keyboard.

 

This symbol represents a control key combination. The letter X can be any keyboard character. To generate a control key combination, hold down the CTRL key while pressing the specified letter.

command

System text and code in examples and in text appears in the Courier typeface. Since the UNIX operating system differentiates between lowercase and uppercase characters, literal strings in examples and text must be entered exactly as shown.

bold

User input in interactive examples appears in the bold Courier typeface.

bold

Bold words in text indicate the first use of a new term.

italic

File and variable names appear in italics.

 

Vertical ellipses indicate that irrelevant parts of the program text or program output have been omitted.

quotation mark
apostrophe

The term quotation mark is used only to refer to the double quotation mark character ("). The term apostrophe is used to refer to the single quotation mark character (').

#

A # symbol is used in some contexts to indicate a single ASCII space character.)

pl1(1)

Specifies a manual page. For more information, type:
man section page

 

This margin icon indicates that the paragraph contains important information to which you should pay close attention.

SYNTAX

Syntax (format) diagrams appear in the Helvetica typeface.

. . .

Horizontal ellipses indicate that additional parameters, options, or values can optionally be entered. When a comma precedes an ellipsis, it indicates that successive items must be separated by commas. Used in syntax diagrams.

[ ]

Square brackets indicate that a syntactic element is optional and you need not specify it. Used in syntax diagrams

 

Brackets surrounding two or more stacked items indicate conflicting options, one of which can optionally be chosen. Used in syntax diagrams

 

Braces surrounding two or more stacked items indicate conflicting options, one of which must be chosen. Used in syntax diagrams

FILE (file-reference)

An uppercase word or phrase indicates a keyword that must be entered as shown; a lowercase word or phrase indicates an item for which a variable value must be supplied. This convention applies to syntax diagrams, not to code examples.

Technical Assumptions

All descriptions of the effects of executing statements and evaluating expressions assume that the initial procedure activation of the program is through an entry point with OPTIONS(MAIN).

It is further assumed that any non-PL/I procedures called by the program follow all PL/I calling conventions and all conventions of the PL/I run-time environment. Except as explicitly noted, descriptions of I/O statements do not cover the effects of system-specific options.

For details on mixed-language programming and system-specific options, see the Kednos PL/I for UNIX User's Manual.

Terminological Conventions

Information in this manual applies to the use of Kednos PL/I for UNIX on the Digital UNIX Operating System unless otherwise indicated.

The term PL/I refers to Kednos PL/I for UNIX.

The terms "full PL/I" and "standard PL/I" refer to the ANSI standard PL/I, X3.53--1976.

 

Program Structure and Content

This chapter introduces the following elements of a PL/I program:

Future chapters discuss these topics in more detail.

Lexical Elements

This section describes the following topics:

Keywords

A keyword is a name that has a special meaning to PL/I when used in a specific context. In context, keywords identify statements, attributes, options, and other program elements. PL/I keywords are not reserved words, so it is possible to use them in a program in other than their keyword context.

PL/I has numerous keywords. See , See Alphabetic Summary of Keywords describes the PL/I keywords, including brief identifications of their uses and valid abbreviations for the keywords that can be abbreviated.

Punctuation

PL/I recognizes punctuation marks in statements. The punctuation marks serve the following two functions:

  • They specify arithmetic or other operations to be performed on expressions.
  • They delimit and separate identifiers, keywords, constants, and statements.

For example:

A = B + C;

 

In this statement, the equal sign (=), the addition operator (+), and the semicolon (;) delimit the identifiers A, B, and C, as well as define the operation to be performed. ( See , See Expressions and Data Type Conversions describes the effect of the various operators in expressions.)

Whenever you use a punctuation mark in a PL/I statement, you can precede or follow the character with any number of spaces (except in the case of an operator consisting of two characters, like >= or **, which you must enter without a space between the two characters). For example, the following two statements are equivalent:

DECLARE ( A, B ) FIXED DECIMAL ( 7, 0 ) ;

DECLARE(A,B)FIXED DECIMAL(7,0);

 

In the second statement, all nonessential spaces are omitted; the parentheses and commas are sufficient to distinguish elements in the statement. The only space required in this statement is the space that separates the two keywords FIXED and DECIMAL.

See . Punctuation Marks Recognized by PL/I lists all the punctuation marks recognized by PL/I.

 

. Punctuation Marks Recognized by PL/I

Category

Symbol

Meaning

Arithmetic operators

+

Addition or unary plus

-

Subtraction or unary minus

/

Division

*

Multiplication

**

Exponentiation

Relational (or comparison) operators

>

Greater than

<

Less than

=

Equal to

^>

Not greater than

^<

Not less than

^=

Not equal to

>=

Greater than or equal to

<=

Less than or equal to

Logical operators

^

Logical NOT (unary) and

EXCLUSIVE OR (binary)

&

Logical AND

&:

Logical AND THEN

| or !

Logical OR

|: or !:

Logical OR ELSE

Concatenation operator

|| or !!

String concatenation

Separators

,

Delimits elements in a list

;

Terminates a PL/I statement

.

Separates identifiers in a structure name; specifies a decimal point

:

Terminates a procedure name or a statement label

()

Encloses lists and extents; defines the order of evaluation of expressions; separates statement and option names from specific keywords; specifies a parameter list

'

Delimits character strings and bit strings

Locator qualifier

->

Pointer resolution

The tilde (~) is equivalent to the circumflex (^), and the exclamation point (!) is equivalent to the vertical bar (|).

Spaces, Tabs, and Line-End Characters

In addition to punctuation marks, PL/I accepts spaces, tabs, and line-end characters between identifiers, constants, and keywords.

The rules for entering spaces are:

  • Between any identifiers, keywords, or constants
  • Preceding or following punctuation marks that normally serve as delimiters, for example, tabs or commas

The line-end character is a valid punctuation mark between items in a PL/I statement except when it is embedded in a string constant. In a string constant, the line-end character is ignored. For example:

A = 'THIS IS A VERY LONG STRING THAT MUST BE CONTI

NUED ON MORE THAN ONE LINE IN THE SOURCE FILE';

 

This assignment statement gives the variable A the value of the specified character-string constant. (The line-end character in the constant is ignored.) Note that any tabs or spaces preceding NUED in the previous example will be included in the string.

Identifiers

An identifier is a user-supplied name for a procedure, a statement label, or a variable that represents a data item. The rules for forming identifiers are:

  • An identifier can have from 1 to 31 characters.
  • An identifier can consist of any of the following characters:
  • The alphabetic letters A through Z and a through z. PL/I converts all lowercase letters to uppercase when it compiles a source program. The identifiers abc, ABC, Abc, and so on, all refer to the same object.
  • The numeric digits 0 through 9.
  • The underscore character (_).
  • The dollar sign character ($).
  • The pound sign character (#).
  • The at sign character (@).
  • An identifier cannot contain any blanks, spaces, or hyphens.
  • An identifier must begin with an alphabetic letter, a dollar sign ($), or an underscore (_). It cannot begin with a numeral.

Examples of valid identifiers are:

STATE

total

FICA_PAID_YEAR_TO_DATE

ROUND1

PAYMENTS_IN_$S

 

Comments

A comment is an informational tool for documenting a PL/I program. To insert a comment in a program, enclose it within the character pairs /* and */. For example:

/* This is a comment ... */

 

Wherever the starting characters (/*) appear in a program, the compiler ignores all text until it encounters the ending characters (*/). A comment can span several lines.

The rules for entering comments are:

  • A comment can appear anywhere that a space can appear.
  • A comment can contain any character except the pair */; comments cannot be nested.

The following are examples of comments:

A = B + C ; /* Add B and C */

 

/* ********* START OF SECOND PHASE ********* */

 

DECLARE/*COUNTER*/A FIXED BINARY (7);

 

/* This module performs the following steps:

1. Initializes all arrays and data structures.

2. Establishes default condition handlers.

*/

 

Although complete comments cannot be nested, you can comment out a statement such as the following:

DECLARE EOF BIT(1); /* end-of-file */

 

To do this, precede the DECLARE statement with another /* pair, as follows:

/* DECLARE EOF BIT(1); /* end-of-file */

 

The compiler will then ignore all text, including the DECLARE statement and the second /*, until it reaches the */.

Statements

A statement is the basic element of a PL/I procedure. Statements are used to do the following:

See . Summary of PL/I Statements and See . Summary of PL/I Preprocessor Statements provide summaries of PL/I statements. Detailed descriptions of these statements appear throughout this manual.

Statement Formats

The general format of a PL/I statement consists of an optional condition prefix, an optional statement label, the body of the statement, and the required semicolon terminator. The format of a statement is:

[ ( condition-prefix [ ,condition-prefix ] ... ) : ] [ label: ] statement-body;

 

The body of the statement consists of user-specified identifiers, literal constants, or PL/I keywords. Each element must be properly separated, either by special characters that punctuate the statement or by spaces or comments.

Condition Prefixes (IBM Dialect Only)

The optional condition prefix specifies a PL/I condition to enable or disable for the statement. If you disable a condition, no program interrupt results if the condition occurs during execution of the statement.

The condition prefix precedes the statement label, if you specify a label, and the statement body. It consists of any valid condition or list of conditions, or the negated version of the condition or conditions, enclosed in parentheses, terminated by a colon. For example:

(ERROR,NOENDFILE): NEWREC: READ FILE (INFILE) INTO (INREC);

 

Any statement except precompiler statements (statements beginning with the % character), and the DECLARE, DEFAULT, or ENTRY statements can have condition prefixes.

If you use a condition prefix on a FORMAT statement, it must be the same prefix used on the referring GET or PUT statement.

Statement Labels

The optional statement label identifies a statement so that it can be referred to elsewhere in the program, for example, as the target of a GOTO statement. A label precedes a statement; it consists of any valid identifier terminated by a colon. For example:

TARGET: A = A + B;

READ_LOOP: READ FILE (TEXT) INTO (TEMP);

A statement cannot have more than one label. See See Identifiers for more information on identifier format.

Simple Statements

A simple statement contains only one action to be performed. There are three types of simple statements:

  • Keyword statements
  • Assignment statements
  • Null statements
Keyword Statements

Keyword statements are identified by the PL/I keyword that requests a specific action. Examples of keyword statements are:

READ FILE (A) INTO (B);

GOTO LOOP;

DECLARE COUNTER FIXED BINARY (7);

 

In these examples, READ, GOTO, and DECLARE are keywords that identify these statements to PL/I.

Assignment Statements

PL/I identifies an assignment statement by syntax: an assignment statement consists of an identifier followed by an equal sign (=) , followed by an identifier or expression. For example:

A = B;

TOTAL = TOTAL + PRICE;

COUNTER = 0;

 

Null Statements

A null statement consists of only a semicolon (;). It indicates that PL/I is to perform no operation. For example:

IF A < B THEN GOTO COMPUTE;

ELSE;

 

This IF statement shows a common use of the null statement: as the target of an ELSE clause.

Compound Statements

A compound statement contains more than one PL/I statement within the statement body. It is terminated by the semicolon that terminates the final statement. The IF and ON statements are examples of compound statements.

Preprocessor Statements

Preprocessor statements start with a percent sign (%). They can be simple or compound, as described in the preceding sections. For a full description of preprocessor statements, see See , See Preprocessor .

Summary of Statements by Function

You can group PL/I statements by function into the following categories.

Data Definition and Assignment Statements

The DECLARE statement defines variable names:

DECLARE identifier [attribute ...];

 

The assignment statement gives a value to a variable:

reference = expression;

 
Input/Output Statements

These statements identify files and data formats and perform input and output operations:

CLOSE

GET

READ

DELETE

OPEN

REWRITE

FORMAT

PUT

WRITE

Program Structure Statements

These statements define the organization of the program into procedures, blocks, and groups:

BEGIN

END

PROCEDURE

DO

ENTRY

null

Flow Control Statements

These statements change or interrupt the normal sequential flow of execution in a PL/I program:

CALL

ON

SIGNAL

GOTO

RETURN

STOP

IF

REVERT

 

LEAVE

SELECT

 

Storage Allocation Statements

These statements acquire and control the use of storage in a PL/I program:

ALLOCATE

FREE

 

See . Summary of PL/I Statements gives a summary of the PL/I statements and their uses.

. Summary of PL/I Statements

Statement

Use

Assignment

Evaluates an expression and gives its value to an identifier

Null

Specifies no operation

ALLOCATE

Allocates storage for a based or controlled variable

BEGIN

Denotes the beginning of a block of statements to be executed as a unit

CALL

Transfers control to a subroutine or external procedure

CLOSE

Terminates association of a file control block with an input or output file

DECLARE

Defines the variable names and identifiers to be used in a PL/I program and specifies the data attributes associated with them

DELETE

Removes an existing record from a file

DO

Denotes the beginning of a group of statements to be executed as a unit

END

Denotes the end of a block or group of statements begun with a BEGIN, DO, or PROCEDURE statement

ENTRY

Specifies an alternative point at which a procedure can be invoked

FORMAT

Specifies the format of data that is being read or written with GET EDIT and PUT EDIT statements and defines the conversion, if any, to be performed

FREE

Releases storage of a based or controlled variable

GET

Obtains data from an external stream file or from a character-string expression

GOTO

Transfers control to a labeled statement

IF

Tests an expression and establishes actions to be performed based on the result of the test

LEAVE

Transfers control out of a DO group

LOCATE

Allocates storage in an output buffer. Used with the BUFFERED environment option. (ibm dialect only)

ON

Establishes the action to be performed when a specified condition is signaled

OPEN

Establishes the association between a file control block and an external file

PROCEDURE

Specifies the point of invocation for a program, subroutine, or user-defined function

PUT

Transfers data to an external stream file or to a character-string variable

READ

Obtains a record from a file

RETURN

Gives back control to the procedure from which the current procedure was invoked

REVERT

Cancels the effect of the most recently established ON unit

REWRITE

Replaces a record in an existing file

SELECT

Tests a series of expressions and establishes the action to be performed based on the result of the test

SIGNAL

Causes a specific condition to be signaled

STOP

Halts the execution of the current program

WRITE

Copies data from the program to an external record file

Program Format

A PL/I program consists of a series of statements, which perform the following tasks:

A statement comprises user-specified identifiers, constants, and PL/I keywords, separated by blanks, comments, and punctuation marks. You can organize statements into structural sequences of groups or blocks. See . Structure of a PL/I Program shows the structure of a PL/I program.

. Structure of a PL/I Program

SAMPLE: PROCEDURE OPTIONS (MAIN);

 

DECLARE (X,Y,Z) FIXED, À

MESSAGE CHARACTER(80) INITIAL ('HELLO'),

CALC ENTRY (FLOAT) RETURNS (FLOAT),

TOTAL FLOAT;

 

X = 0; Ã

PUT SKIP LIST(MESSAGE);

 

FINISH: PROCEDURE; Õ

DECLARE TEXT (5) CHARACTER (20);

END FINISH;

 

END SAMPLE;

 

Key to See . Structure of a PL/I Program :

A PROCEDURE is the basic executable program unit.

À The declarations of variables in a procedure are usually, but not necessarily, placed at the beginning of the procedure.

à Executable statements are placed following variable declarations.

Õ Internal procedures may be placed anywhere.

All procedures must terminate with END statements.

The source text of a PL/I program is freeform. As long as you terminate every statement with a semicolon (;), individual statements can begin in any column, be on additional lines, or be written with more than one statement to a line.

Individual keywords or identifiers of a statement, however, must be confined to one line. Only a character-string constant (which must be enclosed in apostrophes) can be on more than one line.

PL/I programs are easier to read and comprehend if you follow a standard pattern in formatting. For example:

  • Write source statements with no more than one statement per line.
  • Use indention to show the nesting level of blocks and DO-groups.

Blocks

PL/I is a block-structured language with each block composed of a sequence of PL/I statements. There are two types of blocks:

Scope of Names

The scope of a declaration of a name is that region of the program in which the name has meaning. A name has meaning in the following locations:

  • The block in which it is declared
  • Any blocks contained within the declaring block, as long as the name is not redeclared in the contained block
  • Any procedure contained in the program, if the name is declared outside a procedure

Two or more declarations of the same name are not allowed in a single block unless one or more of the declarations are of structure members.

Two declarations of the same name in different blocks denote distinct objects unless both specify the EXTERNAL attribute. All EXTERNAL declarations of a particular name denote the same variable or constant, and all must agree as to the properties of the variable or constant, otherwise unpredictable results will occur. Note that EXTERNAL is the default for declarations of ENTRY and FILE constants. It must be specified explicitly for variables.

The following example shows the scope of internal names:

 

NAME

SCOPE

DECLARE Q STATIC FIXED;

Q

MAINP, ALPHA, BETA, and CALC

MAINP: PROCEDURE OPTIONS (MAIN);

MAINP

MAINP, ALPHA, BETA, and CALC

DECLARE (X, Y, Z) FIXED;

X, Y

MAINP, ALPHA, BETA, and CALC

 

Z in MAINP

MAINP, ALPHA, and CALC

 

 

 

ALPHA: PROCEDURE;

ALPHA

MAINP, ALPHA, BETA, and CALC

BETA: BEGIN;

BETA

ALPHA, BETA

DECLARE Z FLOAT;

Z in BETA

BETA

GOTO ERROR;

 

 

END BETA;

 

 

ERROR:

ERROR

ALPHA, BETA

END ALPHA;

 

 

 

 

 

CALC: PROCEDURE;

CALC

MAINP, ALPHA, and CALC

DECLARE (SUM, TOTAL) FLOAT;

SUM, TOTAL

CALC

END CALC;

 

 

END MAINP;

 

 

Declarations can appear outside procedures and, if contained within the same block, have meaning throughout all procedures contained in the block. However, if there are multiple blocks, declarations outside procedures must have the EXTERNAL attribute if they are to be recognized by all blocks and procedures in the program. For example:

File A.PLI

DECLARE X FIXED EXTERNAL STATIC;

A: PROCEDURE OPTIONS(MAIN);

DECLARE B ENTRY;