Revised - Intro. To PL1
Revised - Intro. To PL1
Revised - Intro. To PL1
OBJECTIVES :
Understand the PL/I language features Coding ,
debugging and testing the PL/I programs
PREREQUISITES :
The participants should be familiar with
IBM Main Frame skills like JCL, VSAM etc.
TARGET AUDIENCE : ELTP Trainees
METHODOLOGY :
Usage of slides
Exercises to be solved in class room
Exercises to be solved in Lab
Assignments and Quizzes
2
COURSE CONTENTS :
Unit Wise / Day Wise
1) Introduction to PL/I:
Features of PL/I
Comparison with other Languages.
Structured Programming
Character Set
Data Structures
Data Types & Data Manipulation
4
5) Storage Classes
Automatic Storage
Prologue, Epilogue
Static Storage
Based Storage
ADDR Built-in Function
Pointers
Processing Data in Buffers
Move and Locate mode & Stack Concept
Controlled Storage
6) Sorting & Merging Data
PLISORTX Built-in Subroutine
DURATION : 6 Days @ 3 hours per day
TOTAL : 36 hours
THEORY : 18 hours
EXERCISES : 15
5
LAB : 18 hours
Survey of some widely used computer languages:
Language
Approximate date of Introduction
General Application Areas
1. FORTRAN 1957
Numerically oriented language (NOL) Scientific,
Mathematical & Statistical very widely used.
2.ALGOL 1960
Also NOL, but with new language features widely
used in Europe.
3. COBOL 1960
Most widely used Business-oriented language. 6
4. LIST 1961
.Special purpose language developed primarily
for list processing & symbolic manipulation
widely used in the area of AI.
5. SNOBOL 1962
Special Purpose language developed primarily
for character string processing. This includes
applications like TEXT editors, language
processors and bibliographic work
6. BASIC 1965
A simple interactive language widely used to 7
8
*POINTER data allows list data structures to be built
during program run-time.
*STRUCTURES, Arrays of Structures, Structures of
Arrays can be declared in the program.
*PL/I can handle bit strings.
*EXTINSIVE set of Built-in functions.
*SUPPORTS Structured and Modular programming.
*It is single language useful for both scientific and
business-type problems.
*It is more “English-like” and thus easier to learn
9
*It is a “commonsense” language. If, for instance, the
programmer fails to get explicit instructions, the
compiler will make a reasonable decision on
programmer’s intentions.
*It is richer, more powerful, and better suited for
solution of all types problems than all the three
previous languages combined.
*It is modular. This means that a programmer can
write useful programs knowing just a fraction(that is,
small module) of the total language.
*It is a forerunner of a new generation of languages:
the PL/II, the PL/III and other such languages. 10
INTRODUCTION TO PL/I
* BURROUGHS
* CDC
* DIGITAL
* HONEY WELL
* IBM
12
STRUCTURED PROGRAMMING
13
DATA TYPES AND STRUCTURES
Syntax:
DECLARE name attributes
Base attribute
Function To specify the base type of an identifier
Options BINARY, DECIMAL
Default Depends on the prefix of an
identifier and scale attribute
Example DCL EX_1 DECIMAL FIXED(5,2);
16
Scale attribute
Function To specify the scale of an identifier
Options FIXED, FLOAT
Default Depends on the prefix of an identifier
and base attribute
Example DCL EX_1 DECIMAL FIXED(5,2);
Precision attribute
Function: To specify the no.of significant digits and /or the
decimal or binary point alignment of an identifier
Options (p,q) or (p)
Default Depends on the base and scale
attributes
Example DCL EX_1 DECIMAL FIXED(5,2);
Note For floating point data declare only the no.of
significant digits 17
e.g. DCL EX_1 FLOAT DEC(9,6) ; /* INVALID */
Default attributes
INITIAL attribute
Function To set an identifier to an initial value
Example DCL EX_1 CHAR(14) INIT(‘PL/I
TRAINING’);
FIXED DECIMAL
Data Format Packed Decimal
Type of Data Coded Arithmetic
Default Precision 5 decimal digits
Max. Precision 15 decimal digits
21
Examples
DECLARE EXAMPLE_1 FIXED DEC(7);
DECLARE EXAMPLE_2 FIXED DEC(9,2) INIT
(24.00);
DECLARE EXAMPLE_3 FIXED DEC;
FIXED BINARY
Data format Fixed-point
Type of Data Coded arithmetic
Default Precision 15bits(32,767 in decimal)
Max. Precision 31bits(2,147,483,647 in
decimal)
Examples
DCL EXAMPLE_1 FIXED BIN(15);
DCL EXAMPLE_2 FIXED BIN(31) INIT(2147483647);
DCL EXAMPLE_3 FIXED BIN(31,6);
22
FLOAT DECIMAL
Data Format Floating-point
Type of Data Coded arithmetic
Default Precision 6 decimal digits
Max Precision 16 decimal digits
-76 +75
Range of Exponent 10 to 10
Examples
DCL EX_1 FLOAT DEC(6);
DCL EX_2 DEC(6);
DCL EX_3 FLOAT(6);
DCL EX_4 FLOAT DEC(16) INIT(6E+12);
DCL EX_5 FLOAT DEC INIT(5280);
23
SUBROUTINES AND FUNCTIONS :
There are four types of procedures:
1. Main procedures
2. Subroutine Procedures
3. Function Procedures
4. Recursive Procedures (earlier not mentioned here)
Main Procedures
Every PL/I program starts with a line
PROCEDURE OPTIONS(MAIN);
indicating the beginning of the PL/I program.
The PROCEDURE statement must always be labelled.
A subroutine procedure is invoked by a call.
CALL SUMPROC (A,B,C);
SUMPROC ==> Subroutine Name
A,B,C ==> Arguments List
24
Parameters must be declared in a parenthesised list
in the procedure statement of invoked procedure.
For e.g., SUMPROC : PROC(X,Y,Z);
CALL VALID(NAME,ADDRESS,ERROR);
IF ERROR THEN
PUT LIST(‘ERROR IN THE DATA’);
25
CURRENT_TIME = TIME;
HOURS = SUBSTR(CURRENT_TIME,1,2);
MINUETS = SUBSTR(CURRENT_TIME,3,2);
IF HOURS > 0 & HOURS < 12 THEN
SUBSTR(CONVERTED_TIME,7,2) = ‘AM’;
ELSE
IF HOURS > 12 & HOURS < 24 THEN
DO;
SUBSTR(CONVERTED_TIME,7,2) = ‘PM’;
HOURS = HOURS - 12;
END
ELSE
IF HOURS = 0 | HOURS = 24 THEN
DO;
IF MINUETS = 0 THEN 26
SUBSTR(CONVERTED_TIME,7,8_ = ‘MIDNIGHT’;
ELSE
SUBSTR(CONVERTED_TIME,7,2) = ‘AM’
HOURS = 12;
END
ELSE
IF HOURS = 12 THEN
IF MINUETS = 0 THEN
SUBSTR(CONVERTED_TIME,7,4) = ‘NOON’;
ELSE
SUBSTR(CONVERTED_TIME,7,2) = ‘PM’;
SUBSTR(CONVERTED_TIME,1,2) = HOURS;
SUBSTR(CONVERTED_TIME,4,2)
= MINUETS;
RETURN(CONVERTED_TIME);
END TIMEX;
27
FUNCTION PROCEDURES:
A function is a procedure that returns a single value to the
invoking procedure.
Z = CALC(X,Y);
CALC ===> A function procedure name.
X,Y ====> Argument List
Result is assigned to Z.
I = 4;
RUSULT = N_FACTORIAL(I);
N_FACTORIAL : PROCEDURE(N);
K = 1;
DO I = 1 TO N;
K = K * I;
END;
RUTURNS(K);
END N_FACTORIAL; 29
Example :-
N_FACTORIAL : PROC(N) RECURSIVE;
K = N -1;
IF K = 1 THEN
I = N;
ELSE
I = N * N_FACTORIAL(K);
RUTURNS(I);
END N_FACTORIAL;
Advantages
Saves coding effort
Reduces total programming time
Improves program readability
Facilitates program maintenance
Types
Main procedures
Subroutine procedures
Function Procedures
31
SUBROUTINE PROCEDURES
32
ARGUMENTS AND PARAMETERS
36
PSEUDO VARIABLES :
A pseudo variable is a built in function name appearing
as a receiving field.
Example :
DCL EDIT_DATE CHAR(14) INIT(‘DATE:
03/14/88’);
SUBSTR(EDIT_DATE,7,2) = ‘12’ /*
CHANGE MONTH 03 TO 12 */
A : PROC REORDER ;
38
CONDITIONS AND ON-UNITS
Syntax: ON condition on-unit;
Types of Conditions
I/O Conditions
ENDFILE(filename)
ENDPAGE(filename)
RECORD(filename)
TRANSMIT(filename)
CONVERSION
SIZE
Arithmetic Conditions
CONVERSION
FIXEDOVERFLOW
OVERFLOW
UNDERFLOW
ZERODIVIDE 39
SIZE
Types of Actions
System Action
Program specified Action
Null Action (e.g. ON ENDPAGE (PRINTR); )
40
Condition When it Raises Example
ENDFILE
Raises during GET or READ operation. It is caused by reading the past of
the last record
ON ENDFILE(TRAN)
MORE_REC = NO;
ENDPAGE
Raises when a PUT stmt results in an attempt to start a new line beyond the
limit specified for PAGESIZE
ON ENDPAGE(PRINTR)
BEGIN ......
END;
TRANSMIT
Raises when an input or output device did not transmit data correctly
41
ARITHMETIC CONDITIONS
Condition When it raises Example
CONVERSION
Occurs whenever a conversion is attempted on char data containing chars that are
invalid
DCL X BIT(4);
X=‘10A1’;
FIXED OVERFLOW
Occurs whenever a result exceeds the fixed point limit declared
DCL (A,B,C) FIXED DEC (15);
A=40000000;
B=80000000;
C=A*B;
OVERFLOW
Occurs when the magnitude of a floating point number exceeds the maximum
A=55E71;B=23E11;
C=A*B; /* THE MAX IS 75 */ 42
Condition When it raises Example
UNDERFLOW
Occurs when the magnitude of a floating point number less than permitted
minimum
A=23E-71;B=3E-9;
C=A*B; /* THE MIN IS -78 */
ZERODIVIDE
Occurs when an attempt is made to divide by zero A=10;
B=0;
C=A/B;
Note:
1. Conditions are enabled or disabled through prefix. The
prefix NO is used for disable a condition.
e.g. (NOOVERFLOW):PROG1:PROC OPTIONS(MAIN)
2. We can simulate the occurrence of a condition through the
use of SIGNAL statement. 43
Syntax: SIGNAL condition;
BUILT-IN FUNCTIONS FOR ON-UNITS
Function Purpose Example
ONCODE
To determine the type of interrupt that caused the on-unit to become
active
ON ERROR
PUT LIST (ONCODE);
ONLOC
To determine the entry point of the procedure in which the condition was
raised
ONCHAR
Extracts the char that caused the CONVERSION condition to be raised
CHAR=ONCHAR;
ONSOURCE
Extracts the contents of the field that was being processed when a
CONVERSION was raised 44
SOURCE=ONSOURCE;
REPETITIVE STRUCTURES
Types:
DO-WHILE
DO-UNTIL
DO-LOOP or iterative DO
45
DO-WHILE
Syntax: DO WHILE(expression)
...........
END;
Termination When the expression becomes false
Example ON ENDFILE(INFILE)
MORE_RECORDS=NO;
READ FILE(INFILE) INTO(IN_REC);
DO WHILE (MORE_RECORDS)
READ FILE(INFILE) INTO(IN_REC);
END;
46
DO-UNTIL
Syntax: DO UNTIL(expression)
..........
END;
Termination When the expression becomes true
Example ON ENDFILE(INFILE)
EOF=YES;
READ FILE(INFILE) INTO(IN_REC);
IF EOF=NO
CALL NO_REC_IN_FILE;
ELSE
DO UNTIL (EOF)
CALL PROCESS_DATA;
READ FILE(INFILE) INTO(IN_REC);
47
END;
PROB6 : PROC OPTIONS(MAIN);
/* DETERMINE THE TYPE OF A TRIANGLE */
/* EQUILATERAL, ISOSCELES, OR SCALENE */
DCL (S1, S2, S3) FIXED;
ON ENDFILE(SYSIN) STOP;
READ3 : GET LIST(S1, S2, S3);
PUT SKIP(3) LIST(S1, S2, S3);
/* NESTED IF USED TO SELECT ONE CASE */
IF (S1 = S2) & (S2 = S3)
THEN PUT LIST(‘EQUILATERIAL’);
ELSE IF ((S1 = S2) | (S2= S3) | (S1 = S3))
THEN PUT LIST(‘ISOSCELES’);
ELSE PUT LIST(‘SCALENE’);
GO TO READ3;
END PROB6;
48
BUILT-IN - FUNCTIONS :
TYPES :
Arithmetic
Mathematical
String Handling
Array Handling
Condition Handling
Storage Control
Other Functions
49
ARITHMETIC BUILT-IN FUNCTIONS :
CEIL
Finds smallest integer greater than or equal to argument
X=3.32; Y=CEIL(X); /* Y=4.00 */
FLOOR
Finds largest integer that does not exceed the argument
X=3.32;Y=FLOOR(X); /* Y=3.00 */
MAX
Finds the largest value from two or more arguments
X=100;Y=32.76;Z= -8;
Z=MAX(X,Y,Z); /* Z = 100 */ 50
Function Purpose Example(s)
MIN
Finds the smallest value from two or more arguments
X=100;Y=32.76;Z= -8;
Z=MIN(X,Y,Z); /* Z = -8 */
MOD(m,n)
Extracts the remainder resulting from the division of the
first argument by second argument
X=29;
Y=MOD(X,6);/* Y=5 */
51
Function Purpose Example(s)
ROUND(m,n)
Rounds a given value at a specified digit and pads spare digit positions
with zeros
X=123.7261; Y=ROUND(X,3);/* Y=123.7260 */
Y=ROUND(X,1);/* Y=123.7000 */
SIGN
Determines the sign of a value and returns a result of
1 for positive
0 for zero
-1 for negative
X=123; I=SIGN(X); /* I=1 */
TRUNC
Changes fractional part of an argument to zero
X=3.32;Y=TRUNC(X); /* Y=3.00 */
52
MATHEMATICAL BUILT-IN FUNCTIONS:
ACOS(X)
ASIN(X)
ATAN(X)
ATAN(X,Y)
ATAND(X)
ATAND(X,Y)
ATANH(X)
COS(X)
COSD(X)
COSH(X)
ERF(X)
ERFC(X)
EXP.(X)
LOG(X)
LOG10(X)
LOG2(X)
SIN(X)
SIND(X)
SINH(X)
SQRT(X)
TAN(X)
TAND(X)
TANH(X) 53
STRING HANDLING FUNCTIONS:
Function Purpose Example(s)
1.CHAR
2.CHAR(x,n)
n is the length of the result Converts a given value to a
character string
DCL A FIXED DEC (5);
DCL B CHAR(5);
A=175;
B=CHAR(A); /* B=‘ 175’ */
BIT
Converts a coded arithmetic data item or char string to a bit-
string
X=BIT(NUMBER);
54
/* X=BIT STRING */
Function Purpose Example(s)
INDEX
Searches a string for a specified bit or char string
NAME=‘PL/I LANG’;
IND=INDEX(NAME,’PL/I’); /* IND=1 */
LENGTH
Finds the length of a given char string or bit string DCL
NAME CHAR(20) VARYING;
NAME = ‘PL/I’;
LTH=LENGTH(NAME); /* LTH=4 */
REPEAT(m,n)
Concatenates the given string itself a specified no. of times
55
NAME=REPEAT(‘PL/I’,2); /* NAME=‘PL/IPL/I’ */
Function Purpose Example(s)
SUBSTR(NAME,I,J)
To manipulate smaller part of larger char or bit string X=‘PL/I
LANGUAGE’;
Y=SUBSTR(X,1,4); /* Y=‘PL/I’ */
TRANSLATE(s,r,p)
Substitutes one char with another
NAME=‘ABCD’;
NAME=TRANSLATE(NAME,’X’,1);
/* NAME=‘XBCD’ */
VERIFY
Examines two strings to verify that each char or bit of the first string is
represented in the second string DIGITS=‘0123456789’;
X=‘01234’;
RESULT=VERIFY(X,DIGITS); /* RESULT = 0 */
56
DATE and TIME BUILT-IN FUNCTIONS:
Format
DATE YYMMDD
TIME HHMMSSTTT
57
ARRAYS:
An array is a table of data items in which each item
has the same attribute as every other item in the
array.
e. g.,
DCL EX_1(365) FIXED DEC(4,1);
DCL EX_2(0:11) FIXED DEC(5);
DCL EX_3(-5 : +5) FLOAT DEC(6);
DCL EX_4(-2:6) FIXED BIN(15,0)
INIT(10,20,30,40,50,60,70,80);
-2 is lower bound and 6 is upper bound of
that array.
58
DIMENSIONS :
59
SUBSCRIPTS :
e.g., I = 3;
J = 2;
T = EX_1(I,J); /* variable subscripts */
T = TEMP(I - J + K);
/* subscript expressions */
I = 3;
Z = X(Y(I)); /* Subscript Subscripts */ 60
ARRAY BUILT-IN FUNCTIONS:
Function Purpose
DIM Provides the current extent for a specified dimension
in a given array
LBOUND Finds the current lower boundary
HBOUND Finds the current higher boundary
SUM Finds the sum of all elements in a given array
PROD Finds the product of all elements in a given array
POLY Used to form a polynomial expansion from two
arguments
ANY Used to test any bit(s) of a given bit-string array
ALL Used to test all bits of a given bit-string array
61
ARRAY ASSIGNMENTS:
Scalar-to-Array:
Entire array is assigned a single scalar value
DCL EX_1(12) FIXED DEC(4,1); EX_1=0;
Array-to-Array:
Prefix Operators
Each element is effected by this operation.
e.g. A = -A;
Infix Operators
Each element is effected by this operation
e.g. B = A * 5; B = A * A(1,2); A = A + B;
Cross section
A subscript may also be an asterisk , in which case it
specifies
the entire extent of the dimension.
Types:-
EDIT-DIRECTED I/O
DATA-DIRECTED I/O
65
I/O PROGRAMMING STEPS :-
66
3. Process information in the file
READ or WRITE or REWRITE 4
I/O Statements for RECORD files
GET or PUT I/O Statements for STREAM files
67
EDIT-DIRECTED I/O:
Example:
GET EDIT (EMP#,NAME,RATE,HOURS,DEDUCTIONS)
(COLUMN (1),A(6),A(20),F(4,2),F(3,1),F(5,2));
Format items
Data format items
Control format items (line,page,space control)
Remote format items
68
DATA FORMAT ITEMS:
A(w)
A
B(w)
B
C
E(w,d)
E(w,d,s)
F(w)
F(w,d)
F(w,d,p)
X(w)
P ‘picture specification’
69
w Total no of chars/digits
d No.of fractional decimal places
s No.of significant digits ( d + 1)
p Scaling factor
A Character notation
B Bit string notation
C Complex variables
E Floating point notation
F Fixed point notation
P Picture definition
70
CONTROL FORMAT ITEMS
COLUMN(n)
LINE(n)
PAGE
SKIP
71
DATA DIRECTED I/O
72
COUNT BUILT-IN FUNCTION
73
FILE DECLARATION:
FILE
This key word although optional must follow the file name if
specified. Other attributes, however, may be in any sequence
INPUT
Direction of Transmission
STREAM
Type of Transmission
ENVIRONMENT
May be abbreviated ENV
74
/* CREATE A NAME AND ADDRESS FILE AT
THE TERMINAL */
/* PROGRAM NAME : CREATE */
/* DESCRIPTION : This program creates a name
and address file in a disk file whose name is selected
by the data entry operator. Data is input from the
terminal and written to the disk file as well as the
printer in the form of an “ADDRESS LABEL”
suitable for mailing. */
ON ENDFILE(SYSIN)
MORE_RECORDS = NO;
PUT SKIP FILE(SYSPRINT) LIST(‘ENTER
THE NAME OF THE OUTPUT FILE’);
GET FILE(SYSIN) LIST (FILE_NAME);
76
OPEN FILE(DISKFILE) TITLE(FILENAME);
OPEN FILE(LABEL) PAGESIZE(7) INESIZE(39);
DO WHILE(MORE_RECORDS);
PUT SKIP FILE(SYSPRINT) LIST(‘NAME:’);
GET FILE(SYSIN) LIST(NANE);
IF NAME = ‘EOF’ THEN
SIGNAL ENDFILE(SYSIN);
ELSE DO;
DATA_OK = ‘NO’;
DO UNTIL(DATA_OK);
PUT SKIP FILE(SYSPRINT) LIST(‘ ADDRESS:’);
GET FILE(SYSIN) LIST(ADDR);
PUT SKIP FILE(SYSPRINT)
LIST(‘CITY/STATE/ZIP:’);
GET FILE (SYSIN) LIST(CITY_ST_ZIP); 77
PUT SKIP FILE(SYSPRINT) LIST(‘IS DATA OK ? (Y/N):’);
GET FILE(SYSIN) LIST(RESPONSE);
IF RESPONSE = ‘Y’ THEN
DATA_OK = YES;
END;
PUT FILE(DISKFILE) LIST(NAME,ADDR,CITY_ST_ZIP);
PUT PAGE FILE(LABEL) LIST(NAME);
PUT SKIP FILE(LABEL) LIST(ADDR);
PUT SKIP FILE(LABEL) LIST(CITY_ST_ZIP);
END;
END;
CLOSE FILE(DISKFILE);
END CREATE;
78
/* GENERATE THE INVENTORY AUDIT REPORT */
/* PROGRAM NAME : AUDIT */
/* DESCRIPTION : This program reads the entire file of
inventorying records and computes the value of the items on
hand. */
/* INPUT : INVENTORY FILE */
/* OUTPUT : INVENTORY AUDIT REPORT */
/* PROGRAM NUCLEUS */
CALL PRINT_HEADING;
GET LIST(ITEM, COST, QUANTITY);
DO WHILE(MORE_RECORDS);
COUNT = COUNT + 1;
TOTAL_COST = COST + QUANTITY;
TOTAL = TOTAL + TOTAL_COST;
PUT SKIP LIST(ITEM,COST, QUANTITY,
TOTAL_COST);
GET LIST(ITEM, COST, QUANTITY);
END;
80
PUT SKIP(2) LIST(‘ ‘,’ TOTAL VALUE OF
INVENTORY : ‘, TOTAL);
PUT SKIP(2) LIST(‘ ‘,’NUMBER OF RECORDS
PROCESSED:’, COUNT);
82
INPUT/OUTPUTATTRIBUTES: -
83
STREAM Attribute :
84
ENVIRONMENT Attribute :
For line printer output, the record type can be variable
(V instead of F)
PRINT Attribute :
Print attribute is added to the file declaration for
stream files associated with a line printer so that the
carriage control options such as PAGE and LINE
may be specified in the PUT statement. The PRINT
attribute applies only to files with the STREAM and
OUTPUT attributes.
85
DEFAULT or PREDEFINED FILES :
For Example :
ON END FILE(SYSIN)
MORE_RECORDS = NO;
Thus we may take program specified action on the end-of-file
condition without having to declare explicitly the SYSIN file.
Here are the file attributes and options that apply to SYSIN and
SYSPRINT for IBM implementations of PL/I.
89
REMOTE FORMAT ITEM :
GET
EDIT(EMP#,NAME,RATE,HOURS,DEDUCTIONS)
(R(RFMT1));
...
...
...
RFMT1 : FORMAT
(COLUMN(1),A(6),A(20),F(4,2),F(3,1),F(5,2));
90
RECORD I/O :
As a means of introducing the concepts of record
I/O programming, an 80/80 list program will be
illustrated.
ON ENDFILE more_records=no
more_records = yes
READ first record
DO WHILE more records
WRITE record
READ next record
END DO
91
The declaration may be coded as follows :
Here is the recording I/O coding for the 80/80 list program:
ON ENDFILE (DATA)
MORE_RECORDS = NO;
MORE_RECORDS = YES;
READ FILE(DATA) INTO (DATA_AREA);
DO WHILE(MORE_RECORDS);
WRITE FILE(PRINTER) FROM(DATA_AREA);
READ FILE(DATA) INTO (DATA_AREA);
END;
92
/* SKIP TO A NEW PAGE */
/* PROGRAM NAME : LINECNT */
/* DESCRIPTION : This program reads an input file and lists
the data records on the printer. The line counter is checked and a
skip to a new page is forced with carriage control characters if the
line number exceeds 55. */
/* INPUT : DETAIN */
/* OUTPUT : PRINTER */
94
A STRUCTURE is a collection of data items whose
locations relative to one another are critical. Usually
the data items that appear in a structure have a logical
relationship to each other. To describe the layout the
following structure could be coded:
DCL 1 NAME_AND_ADDR,
2 NAME CHAR(20),
2 STREET CHAR(25),
2 CITY_STATE CHAR(25),
2 ZIP CHAR(9),
2 REST_OF_RECORD CHAR(1);
95
RECORD STREAM
1. Respects physical record boundaries
1. Ignores physical boundaries. I/O is considered to be a continuous
stream.
2. Stores data in exactly same form as input, no conversion or validity
checks.
2. Converts character data in input stream to the attributes of the declared
identifiers.
3. Outputs data in exactly the same from as internally stored.
3. Converts and edits internally stored data to character format.
4. Input and output may be any data type(packed decimal, fixed point,
binary, etc.,)
4. Input and output are a stream of characters.
5. Keywords : READ, WRITE
5. Keywords : GET, PUT
6. May be used with any data set organisation(sequential, indexed
sequential, VSAM, direct)
6. May only be used for sequential data sets
96
A BUILT-IN FUNCTION FOR STRUCTURES:
The STRING function concatenates all the elements in an array or a
structure into a single character or bit string element.
EXAMPLES :
DCL 1 STRUCTURE,
2 ELEMENT1 CHAR(5) INIT(‘ABCDE’),
2 ELEMENT2 CHAR(3) INIT(‘123’),
2 ELEMENT3 CHAR(7) INIT(‘XYZXYZX’);
DCL ITEM CHAR(15);
ITEM = STRUCTURE; /* ILLEGAL MORE */
ITEM = STRING(STRUCTURE);
/* ITEM = ABCDE123XYZXYZX*/
STRUCTURE=ITEM;
/* STRUCTURE.ELEMENT1=‘ABCDE’*/
/* STRUCTURE.ELEMENT2=‘ABC’*/
/* STRUCTURE.ELEMENT3= ‘ABCDE12’*/
STRING(STRUCTURE)=ITEM;
/* STRUCTURE.ELEMENT1=‘ABCDE’*/
/* STRUCTURE.ELEMENT2=‘123’*/
/* TRUCTURE.ELEMENT3=‘XYZXYZX’*/
97
THE LIKE ATTRIBUTE :
DCL 1 BUDGET,
2 RENT FIXED DEC(5,2),
2 FOOD,
3 MEAT FIXED DEC(5,2),
3 DAIRY FIXED DEC(4,2),
3 PRODUCE FIXED DEC(5,2),
2 TRANSPORTATION FIXED DEC(7,2),
2 ENTERTAINMENT FIXED DEC(5,2);
DCL 1 COST_OF_LIVING LIKE BUDGET;
This declaration for COST_OF_LIVING is the same as if it
had been declared :
DCL 1 COST_OF_LIVING,
2 RENT FIXED DEC(5,2),
2 FOOD,
3 MEAT FIXED DEC(5,2),
3 DAIRY FIXED DEC(4,2),
3 PRODUCE FIXED DEC(5,2),
2 TRANSPORTATION FIXED DEC(7,2),
98
2 ENTERTAINMENT FIXED DEC(5,2);
STRUCTURE ASSIGNMENT:
Structure to Structure :
EXAMPLE1:
DCL 1 INPUT_REC,
2 KEY_FIELD CHAR(10),
2 OTHER CHAR(70);
DCL 1 DISK_REC,
2 DELETE_FLAG CHAR(1),
2 DISK_MASTER,
3 KEY CHAR(10),
3 OTHER CHAR(70);
DISK_MASTER = INPUT_REC;
/* STRUCTURE ASSIGNMENT */
99
EXAMPLE2 :
DCL 1 A,
2B FIXED DEC(5),
2C FIXED BIN(31),
2D CHAR(20),
2E FIXED BIN(15),
2F FLOAT DEC(5);
DCL 1 AA,
2 BB FIXED BIN(15),
2 CC FIXED DEC(5),
2 DD CHAR(10),
2 EE FIXED DEC(4),
2 FF FIXED DEC(6);
A = AA; /* STRUCTURE ASSIGNMENT */
100
STORAGE CLASSES
Types
AUTOMATIC
STATIC
BASED
CONTROLLED
101
AUTOMATIC STORAGE