Section No. Topicpage

PL/I 23/01/2006 Page:- 1 / 123

CONTENTS

SECTION NO. TOPICPAGE

SECTION 1BASIC STRUCTURE OF PL/I PROGRAMS3

SECTION 2COMPILING UNDER MVS8

SECTION 3DATA TYPES AND DATA MANIPULATION12

SECTION 4PROCEDURES, FUNCTIONS21

SECTION 5SUBROUTINES AND FUNCTIONS32

SECTION 6CONTROL STATEMENTS44

SECTION 7CONDITIONS AND ON UNITS47

SECTION 8ARRAYS60

SECTION 9STRUCTURES AND PICTURES63

SECTION 10 STORAGE CONTROL69

SECTION 11FILE PROCESSING GENERAL82

SECTION 12STREAM ORIENTED DATA TRANSMISSION85

SECTION 13RECORD I/O93

SECTION 14DEFINING AND USING VSAM DATA SETS96

SECTION15PL/I and DB2 102

SECTION 16PREPROCESSOR110

SECTION 17PL/I AND CICS121

SECTION 1 BASIC STRUCTURE OF PL/I PROGRAMS back

Simple Program Skeleton

MYPROG:PROCEDURE OPTIONS(MAIN);

.

.

/* this is a comment */

.

END MYPROG;

Note:-

  1. MYPROG: is an identifier ( otherwise known as Label name, variable name, function / procedure name etc in the non PL/I context)
  2. Comments are encased in /* */
  3. OPTIONS(MAIN) indicates entry point of program and must be indicated only for one procedure in the program.
  4. Columns start at 2 and end at 72.
  5. Free form of writing
  6. Column 2 to 72 may be used for source code
  7. Column 73 to 80 may contain program ID or sequence code. It is not checked by the compiler.
  8. Column 1 controls compilation listing like skip to next page, double space etc(ASA Character)

A first simple program

CONPL01: PROC OPTIONS(MAIN);

DCL BUFFER CHAR(80) INIT('HELLO FROM CONSPL01');

PUT SKIP LIST(BUFFER);

GET LIST(BUFFER);

PUT SKIP LIST(BUFFER);

END CONPL01;

PL/I on your system may be either OS PL/I or PL/I for MVS and VM. See the system for the IEL1CL procedure (PL/I for MVS and VM) and IBMZ( OS PL/I) and theJCL to prepare and run the above program.

Character Sets

$@#

ABCDEFGHIJKLMNOPQRDSTUVWXYZ

0123456789

blank

=Equal / assignment symbol

+Plus sign

-Minus sign

*Asterisk / multiply symbol

/Slash / divide symbol

( ) Parenthesis

,Comma

.Point or period

'Single quotation mark or apostrophe

%Percent symbol

;Semicolon

:Colon

NOT symbol

AND symbol

|OR symbol

Greater than symbol

Less than symbol

_Break (underscore)

?Question mark

A combination of symbols may be used , e.g.

A**3 A power 3

A >=A greater than or equal to 3

'A' || 'B'A concatenated with B

IDENTIFIERS

Variable names, Procedure names, Statement Labels, File names etc.

Consists of 1 to 31 (or more depending on the version of PL/I) alphabetic characters made up of (A - Z, ! , # , $ , 0 - 9, _). First character must be a Alphabet (A - Z, # , @ , $ or _).

You can use upper or lower case. In identifiers and key words lower case is folded to upper case.

Example

MY_LABEL_1

CLIENT_NAME

A procedure with OPTIONS(MAIN) is an external procedure . External procedure names can be maximum of seven characters only. This is also true of a file name.

KEYWORDS

Words that have special meaning to PL/I like GET, PUT etc

STATEMENT FORMAT

LABEL: KEYWORD STATEMENT OPTIONS;

Example

READ_STMT:GET LIST(A,B,C);

Free form statement which can contain as many blanks as felt necessary by programmer.

Position 1 reserved for use for controlling compilation listing.

Position 2 to 72 may contain one or more PL/I statement each separated by ' ; '

GET LIST (A,B); GET LIST (C,D);

Alternately one statement may be continued across several lines e.g.;

GET LIST

(A,B);

Position 73 to 80 may contain sequence number maintained by editor.

PL/I CONSTANTS

Decimal Fixed Point12.30 , 180, +10.23 , -1.12, 0.03

Maximum precision is 15

Decimal Floating Point0.1234E+2X.XXXXXE+XX, X.XXXXXE-XX

Maximum Precision is 33

Character String'ABCDE'

'ABCD''EF', (2)'ABCD'

Maximum length is 32767

Bit String Constant'11011'B, (16)'0'B

Maximum length is 32767

Binary Fixed Point1011B

Binary Floating Point0.11011011E+48B

Maximum Precision is 109

LIST DIRECTED I/O

INPUT

GET LIST (A,B,C,D,E);/*Reads from SYSIN*/

GET FILE(SYSIN) LIST (A,B,C,D,E);/*explicit form*/

OR

OR

In List Directed I/O no record boundaries are considered. Items are either separated by a blank or a comma

GET LIST (A,B) COPY;/* additionally copies the data to SYSPRINT */

Example of Input 12.90,.04E+3,'ABCD','1010'B

Example

DECLARE DATA1CHAR(12);

GET LIST (DATA1);

OUTPUT

PUT LIST (50,'ABC',123,127);

PUT LIST (23,86,87);

PUT LIST (A,5,C*D);/* note use of an expression C*D */

PUT PAGE LIST ('ABC');/* ABC prints in next page*/

PUT SKIP LIST(123);/* Skip one line before print*/

PUT SKIP(0) LIST (123);/* Print without spacing*/

PUT SKIP(2) LIST (123);/* Skip two lines before print*/

PUT PAGE LINE (10) LIST (123);/* Skip to line 10 of new page and print */

PUT PAGE LIST ((100)'-');/* new page and 100 dashes*/

PROGRAM STRUCTURE

MNPROC: PROCEDURE OPTIONS(MAIN);

.

.

CALL SUBPROC_1;

CALL SUBPROC_2;

.

RETURN;

*PROCESS;

SUBPROC_1: PROCEDURE;

.

.

END SUBPROC_1;

*PROCESS;

SUBPROC_2: PROCEDURE;

.

.

END SUBPROC_2;

END MNPROC;

Example of simple nested procedure

//USERAA1 JOB MSGCLASS=A,NOTIFY=USERAA

//MYSTEP EXEC PROC=IEL1CLG,REGION.PLI=1M

//PLI.SYSIN DD *

MYPROG: PROCEDURE OPTIONS(MAIN);

DCL FIELD1 FIXED DECIMAL(7,2);

DCL FIELD2 FIXED DECIMAL(7,2);

GET DATA (FIELD1,FIELD2);

PUT SKIP LIST(SUM(FIELD1,FIELD2));

SUM:PROCEDURE (A,B) RETURNS(FIXED DECIMAL(7,2));

DCL A FIXED DECIMAL(7,2);

DCL B FIXED DECIMAL(7,2);

RETURN (A+B);

END SUM;

END MYPROG;

/*

//GO.SYSIN DD *

FIELD2=1.23,FIELD1=3.45;

/*

//

Example to demonstrate scope of variables

//USERAA1 JOB MSGCLASS=A,NOTIFY=USERAA

//MYSTEP EXEC PROC=IEL1CLG,REGION.PLI=1M

//PLI.SYSIN DD *

MYPROG: PROCEDURE OPTIONS(MAIN);

DCL FIELD1 FIXED DECIMAL(7,2);

DCL FIELD2 FIXED DECIMAL(7,2);

DCL SUM FIXED DECIMAL(7,2);

GET DATA (FIELD1,FIELD2);

CALL ADD;

PUT SKIP LIST(SUM);

PUT SKIP DATA;

/* Procedure ADD */

ADD:PROCEDURE;

SUM=A+B;

END ADD;

/* End of Procedure ADD */

END MYPROG;

/*

//GO.SYSIN DD *

FIELD2=1.23,FIELD1=3.45;

/*

//

SECTION 2 COMPILING UNDER MVS back

See the Catalogued Procedures below in the system.

  1. IEL1CCompile only (PL/I for MVS and VM)
  2. IEL1CLCompile and Link Edit (PL/I for MVS and VM)
  3. IBMZCCompile only (ZOS PL/I)
  4. IBMZCBCompile and Bind (ZOS PL/I)

DD names (PL/I for MVS and VM)

PLI.SYSINSOURCE

PLI.SYSLIBCOPY BOOKS

PLI.STEPLIBLOADLIB WHERE COMPILER RESIDES

PLI.SYSPRINTCOMPILATION LISTING

PLI.SYSLINCOMPILED OBJECT CODE

PLI.SYSUT1COMPILER WORK FILE

LKED.STEPLIBLOADLIB WHERE LINKAGE EDITOR RESIDES

LKED.SYSLINPRIMARY INPUT FOR LINKAGE EDITOR

LKED.SYSLMODOUTPUT OF LINKAGE EDITOR, THE LOAD MODULE

LKED.SYSINSECONDARY INPUT FOR LINKAGE EDITOR

LKED.SYSLIBLINK LIBRARY OF PRECOMPILED OBJECT CODE

LKED.SYSUT1LINKAGE EDITOR WORK FILE

LKED.SYSPRINTLINKAGE EDITOR LISTING

INVOCATION WITH INLINE SOURCE

//MYPROGJOB

//STEP1EXEC IEL1CLG,REGION.PLI=1M

//PLI.SYSLIBDDDSN=MY.SOURCE.LIB,DISP=SHR

//PLI.SYSINDD*

.

Put your source here

.

/*

//

INVOCATION WITH SOURCE IN A PDS MEMBER

//MYPROGJOB

//STEP1EXEC IEL1CLG,REGION.PLI=1M

//PLI.SYSLIBDDDSN=MY.SOURCE.LIB,DISP=SHR

//PLI.SYSINDDDSN=MY.SOURCE.LIB(PROG1),DISP=SHR

//

EXAMPLE

//USERAA1 JOB MSGCLASS=A,NOTIFY=USERAA

//MYSTEP EXEC PROC=IEL1CLG,REGION.PLI=1M

//PLI.SYSIN DD *

MYPROG: PROCEDURE OPTIONS(MAIN);

DCL FIELD CHAR(20) INIT('HELLO WORLD');

PUT LIST (FIELD);

END MYPROG;

//

EXAMPLE OF SEPARATE COMPILATIONSIN ONE JOB

//USERAA1 JOB MSGCLASS=A,NOTIFY=USERAA

//STEP1 EXEC PROC=IEL1C,REGION.PLI=1M

//PLI.SYSIN DD *

SUM: PROCEDURE(A,B) RETURNS(FIXED DEC(3));

DCL (A,B) FIXED DEC(3);

RETURN(A+B);

END SUM;

/*

//STEP2 EXEC PROC=IEL1CLG,REGION.PLI=1M

//PLI.SYSIN DD *

MYPROG: PROCEDURE OPTIONS(MAIN);

DCL SUM ENTRY(FIXED DEC(3),FIXED DEC(3)) RETURNS(FIXED DEC(3));

DCL (A,B) FIXED DEC(3);

A=2;B=3;

PUT LIST(SUM(A,B));

END MYPROG;

//

EXAMPLE OF SEPARATE COMPILATIONSIN SEPARATE JOBS(PART A)

//USERAA1 JOB MSGCLASS=A,NOTIFY=USERAA

//MYSTEP EXEC PROC=IEL1C

//PLI.SYSIN DD *

SUM: PROCEDURE (A,B);

DCL (A,B) FIXED DECIMAL(6,2);

DCL RESULT FIXED DECIMAL(6,2) EXTERNAL;

RESULT=A+B;

END SUM;

/*

//PLI.SYSLIN DD DSN=USERAA.PLICLASS.OBJ(SUM),DISP=(NEW,KEEP),

// UNIT=SYSDA,SPACE=(TRK,(1,,1))

//

(PART B)

//USERAA1 JOB MSGCLASS=A,NOTIFY=USERAA

//MYSTEP EXEC PROC=IEL1CLG

//PLI.SYSIN DD *

MYPROG: PROCEDURE OPTIONS(MAIN);

DCL SUM ENTRY(FIXED DECIMAL(6,2),FIXED DECIMAL(6,2));

DCL RESULT FIXED DECIMAL(6,2) EXTERNAL;

DCL X FIXED DECIMAL(6,2);

DCL Y FIXED DECIMAL(6,2);

X=123.45;

Y=111.11;

CALL SUM(X,Y);

PUT SKIP EDIT('RESULT IS:',RESULT)(A,F(6,2));

END MYPROG;

/*

//LKED.SYSLIB DD DSN=USERAA.PLICLASS.OBJ,DISP=OLD

// DD DSN=CEE.SCEELKED,DISP=SHR

//

EXAMPLE OF SEPARATE COMPILATIONS AND CREATION OF A LOAD MODULE

//USERAA1 JOB MSGCLASS=A,NOTIFY=USERAA

//MYSTEP EXEC PROC=IEL1CL

//PLI.SYSIN DD *

MYPROG: PROCEDURE OPTIONS(MAIN);

DCL SUM ENTRY(FIXED DECIMAL(6,2),FIXED DECIMAL(6,2));

DCL RESULT FIXED DECIMAL(6,2) EXTERNAL;

DCL X FIXED DECIMAL(6,2);

DCL Y FIXED DECIMAL(6,2);

X=123.45;

Y=111.11;

CALL SUM(X,Y);

PUT SKIP EDIT('RESULT IS:',RESULT)(A,F(6,2));

END MYPROG;

/*

//LKED.SYSLIB DD DSN=USERAA.PLICLASS.OBJ,DISP=OLD

// DD DSN=CEE.SCEELKED,DISP=SHR

//LKED.SYSLMOD DD DSN=USERAA.ASMCLASS.LOADLIB(PLI252),DISP=OLD

//

EXAMPLE OF RUNNING A PREVIOUSLY CREATED LOAD MODULE

//USERAA1 JOB MSGCLASS=A,NOTIFY=USERAA

//MYSTEP EXEC PGM=PLI252

//STEPLIB DD DSN=USERAA.ASMCLASS.LOADLIB,DISP=SHR

//SYSPRINT DD SYSOUT=*

//CEEDUMPDDSYSOUT=*

//SYSUDUMPDDSYSOUT=*

//

SOME IMPORTANT COMPILER OPTIONS

ESD | NOESDListing of external symbol dictionary

FLAG(I)List all messages

FLAG(W)List all except information messages

FLAG(E)list all except warning and information messages

FLAG(S)list only severe error messages

DECK | NODECKDeck specifies that the object module is written in card image

form onto SYSPCH

[NO]AGGREGATEcontrols listing of lengths of arrays and structures in program listing

[NO]ATTRIBUTES (FULL | SHORT)

controls listing of all source program identifiers with their attributes in the program listing. In SHORT un-referenced identifiers are omitted.

NOT('not character')Defines new NOT character

[NO]GONUMBERcontrols whether the compiler produces code which will give line number from the source program to be included in run time messages

[NO]GOSTMTStatement numbers will be included in run time messages

[NO]OBJECTcontrols whether the compiler produces a object module on SYSLIN. Always let the default OBJECT hold.

[NO]OPTIONScontrols whether the compiler prints the options in effect in the program listing

[NO]SOURCEcontrols whether the compiler lists the source program in the program listing.

[NO]MACROMACRO invokes the MACRO pre-processor before the compilation process. Specify MACRO if you have coded macros in your source.

[NO]MAPMAP produces information on data items to locate them in a dump.

[NO]LISTThe compiler generates the Assembly code generated for every line of your source program.

[NO]OFFSETThe compiler prints the offset of the object code for every line relative to the entry point of the procedure. It is an alternative way of identifying the failing line in your program from run time error messages.

SYSTEM (MVS|CMS|TSO|CICS..)

Specifies the format in which parameters are passed to the main PLI procedure (this is system dependent)

[NO]XREF(FULL|SHORT) Controls inclusion of cross reference table in the listing

These options can be set in the source by the

%PROCESS option,option,…..;

or

*PROCESS option,option,….;

You can look at the PL/I programmers guide for meaning of all options.

Exercise 1:-

Create the following data sets

Userid.PLI.SOURCEFBPDS80/800

Userid.PLI.OBJECTFBPDS80/3200

Userid.PLI.JCLFBPDS80/800

Userid.PLI.PROCLIBFBPDS80/800

Userid.PLI.LOADLIBUPDS-/32760

1.Set up the compilation, link edit and run JCL on your system. Tailor the IEL1CL or IBMZCB after copying them to your own procedure library.

2.Write a program that reads your name from SYSIN and outputs it on SYSPRINT in the form ‘Welcome your-name to the PL/I class !.’
SECTION 3 DATA TYPES AND DATA MANIPULATION back

PL/I Data TypeIBM Data FormatStorageBasic Usage

FIXED DECIMALPacked Decimal4 bits / decimalArithmetic

digit, signOperations

FIXED BINARYFixed PointHalfword orArithmetic

FullwordOperations

FLOAT DECIMALFloating Point32 | 64 | 128 BitsArithmetic

FLOAT BINARYOperations

PICTUREZoned Decimal8 bits per digitNumeric

Character

CHARACTERCharacter8 bits per CharAlphabetic

Character

BITBitOne byte minLogical

Data

DECLARE PRICE DECIMAL FIXED(5,2);

Precision of five digits of which two

are decimal fraction

Scale Attribute

Base attribute

Identifier (variable)

PL/I Keyword

DECLARE PRICE FLOAT DECIMAL(6);

PRICE = 3.12345

DECLARE PRICE DECIMAL FIXED(6,2);

PRICE = 1234.56;

DECLARE PRICE FIXED BINARY(15);/* 15 bits + sign bit */

PRICE = 123456;

DECLARE PRICE FIXED BINARY(31);/* 31 bits + sign bit */

PRICE = 123456;

DECLARE PRICE FIXED BINARY(15,2);/* 15 bits + sign. implied 2 bits fraction

1111111111111.11 fraction max .75 decimal*/

MODE ATTRIBUTE

DCL COMPLEX_VARFLOAT DECIMAL (6) COMPLEX;

Both Real and imaginary component have FLOAT DECIMAL (6) base Scale and Precision.

PL/I allows partial declarations for computational data items. The attributes for a computational data item are shown below with the defaults underlined.

MODEBASESCALEPRECISION

REALDECIMALFLOAT**SEE TABLE BELOW

COMPLEXBINARYFIXED

If the precision is not explicitly defined it defaults as below:-

FIXEDBINARY15

FIXEDDECIMAL(5,0)

FLOATBINARY21

FLOATDECIMAL6

Partial Declarations will therefore resolve as below:-

DCL A DECIMAL; /* only base defined*/

/* scale and precision default to FLOAT (6)*/

DCL A BINARY/* only base defined*/

/*scale and precision default to FLOAT(21)*/

DCL A FIXED; /* only scale defined*/

/* base and precision default to DECIMAL (5,0)*/

DCL A FLOAT/* only scale defined*/

/* base and precision default to DECIMAL (6)*/

Examples of the default mechanism.

Declared AttributesDefault Attributes

DECIMAL FIXED(5,0)

DECIMAL FLOAT(6)

BINARY FIXED(15,0)

BINARY FLOAT(21)

DECIMALFLOAT (6)

BINARYFLOAT (21)

FIXEDDECIMAL (5,0)

FLOATDECIMAL (6)

PL/I may also implicitly define a variable when you have used it without a definition. In this event, PL/I tries to determine in the context of the usage, the data type. If it cannot do such a determination, the attributes default as below:-

Variable name begins with I-NBINARY FIXED (15)

Other namesDECIMAL FLOAT (6)

Note that you can alter the defaulting mechanism above by use of the PL/I DEFAULT statement which is described later in this document.

Bit Data

DCL END_OF_FILEBIT(1);

DCL NOBIT(1) INIT('0'B);

DCL YESBIT(1) INIT('1'B);

.

.

END_OF_FILE = NO;

ON ENDFILE(SYSIN) END_OF_FILE = YES;

DO WHILE(END_OF_FILE);

.

.

END;

Character Data

DCL CHAR_DATACHAR(20) INIT('ABCDEFGH');

/* Left Justified and padded on right with blanks*/

Varying attribute

DCL CHAR_DATACHAR(20)VARYING;

/* This is a two byte length field followed */

/* by a 20 byte field for data */

CHAR_DATA = 'MY NAME';

CHAR_DATA ='';/* null string*/

DCL BIT_DATABIT(8) VARYING;

Defined attribute

DCLACHAR(20);

DCLBCHAR(5) DEF A;/* overlay on A*/

DCLCCHAR(10) DEF A;/* overlay on A*/

DCLDCHAR(10) DEF C;/* ERROR !, not allowed*/

Permitted Redefines

Base IdentifierDefined Item

Coded Arithmetic variablecoded arithmetic variable with same BASE, SCALE,

PRECISION

Character StringCharacter string or Bit String

Bit StringCharacter string or Bit string

Position Attribute

DCL CHAR_LISTCHAR(20);

DCLACHAR(10) DEFINED CHAR_LIST;

/* overlays first ten positions*/

DCL BCHAR(10) DEFINED CHAR_LIST POSITION(10);

/* overlays next 10 positions*/

Initial Attribute

Use this to initialise variables

DCLAFIXED DECIMAL (7,2) INITIAL(24.50);

DCLBCHAR(10) INIT((10)'A');

DCLCBIT(2) INIT('00'B);

DCLDFIXED BINARY(15) INIT (0);

same effect can also be achieved by an assignment statement. Note that the INIT clause performs the initialisation even before the first statement in the procedure is executed.

PL/I Data Attributes

FIXED DECIMAL ( Also represented as FIXED, DECIMAL FIXED)

Data FormatPacked Decimal

Type of DataCoded arithmetic

Default Precision5 Decimal DigitsS99,999

Maximum Precision15 Decimal digitsS999,999,999,999,999

Used for monetary calculations

Example:

DCLAFIXED DECIMAL (5,2) INIT (123.45);

FIXED BINARY

Data FormatFixed point signed binary (Halfword or Fullword)

Type of DataCoded arithmetic

Default Precision15 Bits plus sign bit(Decimal 32,767)

Maximum Precision31 Bits plus sign bit(Decimal 2,147,483,647)

Used for fast computations, usually for integers

Variables beginning I-N default to fixed Binary unless explicitly defined otherwise

Can be used for representing fractions, but fractions do not have exact representation

in Binary .

Example:

DCLAFIXED BINARY (31) INIT(2147483647);

FLOAT DECIMAL (Also represented as DECIMAL)

Data Format Floating Point, 32bit, 64 bit or 128 bit representation

Type of dataCoded Arithmetic

Default precision6 Decimal digits

Maximum precision33 Decimal digits

Examples:

DCL AFLOAT DEC(6);

DCLADEC (6);/* Defaults to FLOAT */

DCL AFLOAT DEC(6) INIT(6.0E+12);

Note that in storage there is no difference between FLOAT BINARY and FLOAT DECIMAL data representation. They are both represented as E, D and L format floating point data, depending on the precision.

BIT

Data Formatbit (8 bits per byte)

Type of DataLogical

Default lengthNone

Maximum Length32767 bits

Examples

DCLFLAGSBIT(8) INIT('11100001'B);

DCLFLAGSBIT(32) INIT((32)'0'B);

Note that bit strings are (like character strings ) assigned left to right. If a smaller bit string is assigned to a larger string, padding with binary zeroes takes place on the vacant right positions. If the assigned bit string is larger than the receiving field then truncation takes place on the right.

CHARACTER

Data FormatCharacter

Type of dataAlphanumeric (anything goes)

Default lengthNone

Maximum Length32767 characters

On assignment data is left aligned and vacant positions on right are padded with spaces. If the receiving field is smaller, then truncation takes place on the right.

Example:

DCLACHAR(20) INIT('ABCDEF');

DCLACHAR(10) INIT((10)' ');

DATA DECLARATION

Explicit Declaration

The scope of an explicit declaration of a name is that block to which the declaration is internal, including all contained blocks, except those blocks (and any blocks contained within them) to which another explicit declaration of the same name is internal.

A block in PL/I can be a Procedure block or Begin block. Begin blocks are delimited by BEGIN and END keywords.

P: PROC;

DCL A, B;

Q: PROC;

DCL B, C;/* b of proc p is now hidden by this b */

/* a of proc p is still visible*/

/* c of proc q is visible*/

R: PROC

DCL C, D/* c of proc q is now hidden by this c*/

/* a of proc p is still visible*/

/* b of proc q is still visible*/

/* d of proc r is visible*/

END R;

/* now c of proc q is visible*/

/* b of proc q is visible*/

/* a of proc p is visible*/

END Q;

/* Now B of PROC P is visible*/

/* A of PROC P is visible*/

END P;

DECLARE Statement

The DECLARE statement specifies attributes of a name and its position determines the scope of the declaration of the name.

DECLARE [level] name [attribute] , [level] name [attribute]

Factoring of Attributes

Attributes common to several names can be factored to eliminate repeated specification of the same attribute.

DECLARE (A,B,C,D) BINARY FIXED (31);

DECLARE (E DECIMAL(6,5), F CHARACTER(10)) STATIC;

DECLARE ((A,B) FIXED(10),C FLOAT(5)) EXTERNAL;

Implicit Declaration of Names

If a name appears in a program and is not explicitly declared, it is implicitly declared.

PROC1: PROC;

/*implicit declaration takes place here in the outer most containing block*/

PROC1A;

X=4; /* Not declared explicitly, so an implicit declaration takes place*/

END PROC1A;

END PROC1;

Implicit declaration takes place in the outer most containing block ( external procedure). Consequently, the name is known throughout the entire external procedure, except for any blocks in which the name is explicitly declared.

If the attributes for a name declared implicitly can be determined from the context in which the name appears, then the compiler uses these. These are known as contextual declarations. For example,

  • A name that appears in a CALL statement, in a CALL option, or is followed by an argument list is given the BUILTIN and INTERNAL attributes.
  • A name that appears in a FILE or COPY option, or a name that appears in an ON, SIGNAL statement for a condition that requires a file name is given a FILE attribute.

(You will get a detailed explanation of FILE attribute in the section on I/O).

  • A name that appears in an ON CONDITION or SIGNAL CONDITION statement is given the CONDITION attribute. (You will get a detailed explanation of CONDITION attribute in the section on ONUNITS).
  • A name that appears in the BASED attribute, in a SET option, or on the left-hand side of a locator qualification symbol is given the POINTER attribute. (You will get a detailed explanation of BASED and POINTER attribute in the section on Storage Management).
  • A name that appears in an IN option, or in the OFFSET attribute, is given the AREA attribute. (You will get a detailed explanation of BASED and POINTER attribute in the section on Storage Management).

Note:-Come back to review the above bullets after you complete the course and you should be able to understand what they mean. For now just keep in mind that sometimes the PL/I compiler can understand from the context of usage what data type the implicit declaration should be.