PL-1 - Cobol Learning Mainframe
PL-1 - Cobol Learning Mainframe
.........
PL/1 statement
.........
end examp;
Declaring Data Items
DECLARE Statement
• DCL is the statement after proc which means DECLARE and
is used to reserve storage for data or variables
indicating the attributes of a variable.
• ASTERISK * - multiplication
Difference between a binary
number & a bit string
• a binary number has a value and is treated like a
number.
WHOLE='1000111010'B;
• e.g. :- x, y = 1;
if a > b then do;
x = 100;
y = 50;
end;
NOT ¬ alt-170
AND &
OR |
• Concatenation character is ||
DO groups
DO group statement
• iterative do group used in an IF statement is also used
to put several PL/1 statements together,but in this type
of do group these statements are as a rule executed
several times over a group.
• e.g. :- do i = 1 to 10;
........
........
end;
e.g. :- do count = 1 to 20 by 2;
e.g. :- do i = 25 to 1 by -1;
• e.g. :- outer : do i = 1 to 5;
inner : do j = 1 to 3;
.....
end inner;
end outer;
DO group statement
• e.g. :- to leave an iterative do group.
do i = 1 to 100;
.....
if x > y then leave;
.....
end;
GOTO statement
• with goto statement you can jump to any statement
which has a label, except an iterative do group.
• e.g. :- i = 1;
a:if i > 10 then goto b;
......
i = i + 1;
goto a;
b: .....
Data Aggregates & Arrays
Data Aggregates
• two types of data aggregates are there :-
- arrays
- structures
countynm = countytab(2);
e.g. :- cost(i+j)
numbers(i+2)
numbers(costs(i))
costs(i+j*2)
Data Aggregates (Arrays)
• Built-in functions :-
------------------
• a built-in function replaces a number of statements
which the programmer would otherwise have to write
himself.
do j = 1 to 3;
do k = 1 to 5;
tab(j,k) = 2;
end;
end;
x = sum(tab);
x(1) = figures(2,1);
x(2) = figures(2,2);
x(3) = figures(2,3);
Data Aggregates (Structures)
• Simple Structures :-
-----------------
• when you would like to put unequal data elements
together in an aggregate, you should use a structure.
new.name = old.name;
new.payment.gross = old.payment.gross;
new.payment.net = old.payment.net;
Introduction to
Input/Output
Basic features of Input/Output
• GET :- transmits or gets data from external medium
to internal storage.
• standard files for stream i/o :- the get and the put
statements not having data file declarations are
linked with standard files for which there are
prescribed file names.
• on endpage(sysprint) begin;
n = n + 1;
put edit('PG-NO', n) (page, X(110), A, P'ZZ9');
: : : :
: : :print N’s value
: : print char string
skip a page : 'PG-NO'
leave 110 blank spaces
• write can also be used and the new records added are always
added at the end.
relrecno = '00000005';
read file(rrds) into(area) key(relrecno);
......
delete file(rrds) key(relrecno);
......
write file(rrds) from(area)
keyfrom(relrecno);
Processing of String Data
SUBSTR (Built-in Function)
• substr is used to access a part of a string.
• form :- verify(x,y);
• form :- length(x)
/* soln is 'ABCDEABCDE' */
1. Procedures
2. Begin-blocks
1. External Procedures
2. Internal Procedures
• form :- A:proc;
......
begin;
......
......
end;
......
end A;
Scope of Declaration
• Variables which are declared have two scope attributes :-
1. Internal
2. External
the variable 'X' has attribute internal and hence you are
dealing with 2 variables that are known within their blocks.
srou1:proc; srou2:proc
dcl ......; dcl ......;
...… ......
end srou1; end srou2;
Arguments
• when a procedure is invoked using a call, it is possible
to pass variables which are called as arguments.
• e.g.:- srou:proc(a,b);
dcl a char(100);
dcl 1 b,
2 b1 char(10),
2 b2 fixed dec(7,2);
proc5:proc(x,y);
......
ent1:entry(m);
......
ent2:entry(x,y,m);
......
end prog5;
Exit from Procedures
• normal exit for a procedure is END.
• e.g. :- srou:proc(x,y);
......
ent2:entry(m,n,o);
......
if x = 0 then return;
......
end srou;
Functions
• functions are always a part of an expression. a function
is replaced by its result after execution.
• e.g. :- calc:proc(a,b,c);
......
if x > y then return(x*y);
else return(z);
......
end calc;
(ON-UNIT)
• on ENDPAGE and on ENDFILE are some important conditions
which can be forseen.
alpha = 100;
beta = alpha + 200;
counter=0;
total=0;
read:
get file(sysin) list(number);
total = total + number;
counter = counter + 1;
goto read;
finish:
put file(sysprint) list(counter,total);
end p1m0;
Sample Program 3
P3M0:proc options(main);
dcl (countin, countout) fixed dec(3) init(0);
dcl (totalin, totalout) fixed dec(7,2) init (0);
dcl (averagein, averageout) fixed dec(5,2);
dcl number fixed dec(5,2);
end;
Sample Program 4
P6M0:proc options(main);
dcl temp(7,2) fixed dec(3), da(7) fixed dec(3);
dcl wa fixed dec(3), i fixed bin(15), eof bit(1) init('0'B);
on endfile(sysin) eof='1'B;
close file(E1);
end P9M0;
Sample Program 6
p11m0:
proc options(main);
dcl 1 indet,
2 intype char(1),
2 itemno char(5),
2 uprice fixed dec(3,2),
2 qty fixed dec(3),
2 deptno char(3),
2 code1 fixed dec(3),
2 code2 fixed dec(3),
2 code3 fixed dec(3),
2 iname char(23),
2 dname char(27);
Sample Program 6 Contd …..
dcl ab char(40);
dcl 1 sta based(addr(ab)),
2 rectype char(4),
2 itemno char(4),
2 uprice fixed dec(3,2),
2 qty fixed dec(3),
2 totval fixed dec(7,2),
2 iname char(23);
do until (eof);
read file(sysin) into(ca);
if ªeof then do;
del1=index(ca,',');
del2=index(substr(ca,del1+1),',') + del1;
del3=index(substr(ca,del2+1),',') + del2;
Sample Program 7 Contd …..
sn=1;
ss=del1+1;
st=del2+1;
ln = del1 - sn;
ls = del2 - ss;
lt = del3 - st;
name = substr(ca,sn,ln);
street = substr(ca,ss,ls);
town = substr(ca,st,lt);
prline.text = name;
write file(a1) from(prline);
prline.text = street;
write file(a1) from(prline);
Sample Program 7 Contd …..
if verify(town,'.-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') ª= 0
then prline.text = '*****';
else prline.text = town;
P16M2:proc(number,pvalue);
dcl (number,pvalue) fixed decimal(5,2);
if number >= 100
then pvalue = number * 0.05;
else pvalue = number * 0.03;
end;