PLI Hand Book

Embed Size (px)

Text of PLI Hand Book

PL/I FOUNDATION COURSE

INDUS PL/I CLASS MATERIAL Page:-152 /152

CONTENTS

SECTION NO.

TOPIC

PAGE

SECTION 1

BASIC STRUCTURE OF PL/I PROGRAMS

3

SECTION 2

COMPILING UNDER MVS

8

SECTION 3

DATA TYPES AND DATA MANIPULATION

13

SECTION 4

PROCEDURES, FUNCTIONS

22

SECTION 5

SUBROUTINES AND FUNCTIONS

36

SECTION 6

CONTROL STATEMENTS

50

SECTION 7

CONDITIONS AND ON UNITS

54

SECTION 8

ARRAYS

69

SECTION 9

STRUCTURES AND PICTURES

72

SECTION 10 STORAGE CONTROL

81

SECTION 11

FILE PROCESSING

101

SECTION 11-A

STREAM ORIENTED DATA TRANSMISSION

105

SECTION 11-B

RECORD I/O

117

SECTION 11-C

DEFINING AND USING VSAM DATA SETS

123

SECTION 11-D

DEFINING AND USING REGIONAL DATA SETS134

SECTION 12

CICS/DB2

145

SECTION 13

EXERCISES

149

References:-

1) IBM PL/I for MVS and VM Programming Guide

2) IBM PL/I for MVS and VM Language Reference

3) PL/I Structured Programming by Joan.K.Hughes. SECTION 1 BASIC STRUCTURE OF PL/I PROGRAMS

Basic Program Shell

MYPROG:PROCEDURE OPTIONS(MAIN);

.

.

/* this is a comment */

.

END MYPROG;

Note:-

1. MYPROG: is a label

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 user source code

7. Column 73 to 80 may contain program ID or sequence code. It is not checked by the compiler.

A first simple program

MYPROG:PROCEDURE OPTIONS(MAIN);

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

SUM = A + B + C + D + E;

AVERAGE_GRADE = SUM / 5;

PUT LIST('AVERAGE GRADE IS =',AVERAGE_GRADE);

END MYPROG;

A = 8.50000E+01;

/* Input thru GET LIST */

B =7.60000E+01;

/* Input thru GET LIST */

C=9.50000E+01;

/* Input thru GET LIST */

D=8.80000E+01;

/* Input thru GET LIST */

E=9.80000E+01;

/* Input thru GET LIST */

SUM=4.42000E+02;

AVERAGE_GRADE=8.83999E+01;

AVERAGE_GRADE IS=8.83999E+01 /* printed thru put list */

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

=A greater than or equal to 3

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

IDENTIFIERS

Variable names, Procedure names, Statement Labels, keywords (e.g. PUT, GET),

File names etc.

Consists of 1 to 31 alphabetic characters made up of (A-Z,!,#,$,0-9,_).

First character must be a Alphabet.

Example

MY_LABEL_1

CLIENT_NAME

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

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 by O/S.

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 CONSTANTSDecimal Fixed Point

12.30 , 180, +10.23 , -1.12, 0.03

Decimal Floating Point

0.1234E+2X.XXXXXE+XX, X.XXXXXE-XX

Exponent range 10**-78 to 10**+75

Character String

'ABCDE'

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

Bit String Constant

'11011'B, (16)'0'B

Binary Fixed Point

1011B

Binary Floating Point

0.11011011E+48B

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;

SUBPROC_1: PROCEDURE;

.

.

END SUBPROC_1;

SUBPROC_2: PROCEDURE;

.

.

END SUBPROC_2;

END MNPROC;

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;

//SYSIN DD *

FIELD2=1.23,FIELD1=3.45;

/*

//

Example to demonstrate scope of variables 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(FIELD1,FIELD2);

PUT SKIP LIST(SUM);

PUT SKIP DATA;

/* Procedure ADD */

ADD:PROCEDURE (A,B);

DCL A FIXED DECIMAL(7,2);

DCL B FIXED DECIMAL(7,2);

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

Cataloged Procedure IEL1CLG for compile link and go

//IEL1CLG PROC LNGPRFX='IEL.V1R1M1',LIBPRFX='CEE.V1R4M0',

// SYSBLK=3200,GOPGM=GO

//PLI

EXEC PGM=IEL1AA,PARM='OBJECT,NODECK',REGION=512K

//STEPLIBDD DSN=&LNGPRFX..SIELCOMP,DISP=SHR

//

DDDSN=&LIBPRFX..SCEERUN,DISP=SHR

//SYSPRINTDDSYSOUT=*

//SYSLINDDDSN=&&LOADSET,DISP=(MOD,PASS),UNIT=SYSDA,

//SPACE=(80,(250,50)),DCB=(BLKSIZE=&SYSBLK)

//SYSUT1DDDSN=&&SYSUT1,UNIT=SYSDA,

//SPACE=(1024,(200,50),,CONTIG,ROUND),DCB=BLKSIZE=1024

//LKED

EXECPGM=IEWL,PARM='XREF,LIST',COND=(9,LT,PLI),

//REGION=512K

//SYSLIBDDDSN=&LIBPRFX..SCEELKED,DISP=SHR

//SYSPRINTDDSYSOUT=*

//SYSLINDDDSN=&&LOADSET,DISP=(OLD,DELETE)

//

DDDDNAM