pl1 doc1
TRANSCRIPT
-
8/13/2019 pl1 doc1
1/32
PL / I
GRAVITYLimitedBAS Group
PL/1
Programming Language / 1
PL/1 Statements & Programs
FORMAT OF A PL/1 STATM!T
" #o$umn % to % are used 'or #oding PL/1 statements( ea#) statement s)ou$d end *it) a
semi#o$on(
" 'irst statement o' a program s)ou$d +e PRO,-.R or PRO,( ea#) pro#edurestatement must +egin *it) a $a+e$ 1 to 01 #)ars(
" t)e 'irst #)ara#ter o' a $a+e$ s)ou$d a$*as +e an a$p)a+et and t)e $a+e$ s)ou$d +e
'o$$o*ed + a #o$on(
" $ast statement o' a pro#edure a$*as ends *it) !-( !- ends t)e program and passes
t)e #ontro$ to t)e operating sstem(
FORMAT OF A PL/1 Statement" 'orm 23 $a+e$2pro#edure options4main56
" e(g( 23 run%%1a2pro# options4main56
" 'orm 23 $a+e$2end des#riptor6
" e(g( 23 'ini2end run%%1a6
" des#riptor s)ou$d +e same as t)e $a+e$ at t)e 'ront o' t)e pro#edure statement o' t)is
pro#edure(
" e(g( 23 e7amp 2 pro#edure options4main56(((((((((
PL/1 statement
(((((((((
end e7amp6
-e#$aring -ata Items
-,LAR Statement
" -,L is t)e statement a'ter pro# *)i#) means -,LAR and is used to reser8e storage'or data or 8aria+$es indi#ating t)e attri+utes o' a 8aria+$e(
http://mainframebooks.blogspot.com/%3CBlogItemTitle%3Ehttp://mainframebooks.blogspot.com/%3CBlogItemTitle%3E -
8/13/2019 pl1 doc1
2/32
" in PL/1 t)ere are % +asi# data tpes 23
arit)meti# data and string data 4#)ar strings5-,L Arit)meti# data items
" 'orm 23 -,L 8aria+$e9name mode s#a$e +ase pre#ision
" mode o' an arit)meti# item is eit)er rea$ or #omp$e7( de'au$t is rea$(
" s#a$e is eit)er 'i7ed or '$oat(
" +ase is eit)er de#ima$ or +inar(
" pre#ision means num+er o' 'igures t)at a 'i7ed point data item #an )o$d or in #ase o''$oating point t)e minimum num+er o' 8a$id digits to +e regarded as signi'i#ant(
-,L Arit)meti# data items
" e(g( 23 1:%(0: de#ima$ 'i7ed point
1%;(0; de#ima$ '$oating point
" a '$oating point num+er #onsists o' % parts 'ra#tion and e7ponent(
e(g( 23 1 1
-
8/13/2019 pl1 doc1
3/32
-,L String data items
" to repeat a #)ara#ter string use 4n5E#)ar stringE
" e(g( 23 4=:5ERAE 4RA *i$$ +e repeated =: times(5
" de#$aration o' #)ara#ter string 8aria+$e is done as -,L name ,AR41;5
" to 8ar not on$ t)e #onte7t +ut a$so t)e $engt) o' a #)ara#ter 8aria+$e use t)e attri+ute
VARYI!G or VAR(
" e(g( 23 -,L addr ,AR4005 VARYI!G6
" t)e $engt) #an 8ar 'rom 1 to 00 and no padding o' spa#es is done i' t)e $engt) is $esst)an 00(
BIT strings
" +it strings are $iDe #)ar strings e7#ept t)at t)e digits represent one +it 4: and 15( +it
stringsmust +e en#$osed in Cuotation marDs(
" +it strings ma too )a8e 8aring attri+utes(
" e(g( o' +it string #onstants E1:111:1::1EBE111EB
4%H5E:EB
" e(g( o' +it string 8aria+$es
-,L s*it#) BIT415
-,L +itstr BIT40%:5 VARYI!G67p$anation o' some sm+o$s used in P$/1 program
" ,OLO! 2 3 'o$$o*s a $a+e$
" ,OMMA 3 separates $ist items
" SMI,OLO! 6 3 ends a statement
" PAR!TSS 45 3 en#$oses $ist items
" ASTRIS " 3 mu$tip$i#ation-i''eren#e +et*een a +inar num+er & a +it string
" a +inar num+er )as a 8a$ue and is treated $iDe a num+er(
" a +it string )as no 8a$ue and is treated $iDe a string o' +its(
-FI!- or -F attri+ute
" it is use'u$ to re'er to same pie#es o' string data 4+it or #)ar5 + more t)an one name( it
#an +e used to o8er$a or su+3di8ide areas o' string data(
0
-
8/13/2019 pl1 doc1
4/32
" e(g( 23 -,L id#ode ,AR4=56
-,L area ,AR405 -F id#ode6id#ode>EA:%B1;:
-
8/13/2019 pl1 doc1
5/32
position ma )o$d an #)ara#ter(
A position ma )o$d a$p)a+eti# #)ara#ter or a
+$anD( indi#ates t)at position ma )o$d numeri#
#)ara#ters or spa#e(
" e(g( 23 -,L 'ie$da pi# EE6
'ie$da > E1%0(H;E6
I!ITIAL or I!IT attri+ute" to assign 8a$ue to a 8aria+$e at t)e start o' t)e program e7e#ution use t)e attri+ute initia$
or init(
" e(g( 23 -,L s*it#) BIT 1 I!IT4E1EB56-,L *)o$e FI- -,4;5 I!IT4:56
-,L tit$e ,AR4105 I!IT4EJeeD$ !e*sE56
7amp$es o' some #onstants" E1:111:EB +it string
" (%;
-
8/13/2019 pl1 doc1
6/32
" !- in an IF statement indi#ates end o' a -O group +$o#D(
" e(g( 23 7 > 16i' a N + t)en do6
7 > 1::6
> ;:6end6
" e(g( 23 i' a N + t)en # > 1::6e$se do6
7 > 6
# > K 1:6
end6IF T! LS statement
" i' #)ara#ter strings o' di''erent $engt)s are #ompared t)en t)e s)orter one is padded on
t)e rig)t *it) +$anD spa#es(
" in #ase o' +it strings6 i' $engt) di''ers t)e s)orter string is padded to t)e rig)t *it) E:EB(
" !.LL statement 23 nu$$ statement #onsists o' a semi#o$on( it is used *)ere $ogi#a$$ no
statement is ne#essar(
" e(g( 23 i' 7 N t)en i' m > n t)en6
e$se > :6
e$se > K 16
OPRATORS" #omparison operators are as 'o$$o*s 23
$ess t)an not $ess t)anN greater t)an N not greater t)an
> eCua$ to > not eCua$ to
> $ess t)an or eCua$ to N> greater t)an oreCua$ to
" Bit string operators are as 'o$$o*s 23
!OT a$t31:
A!- &
OR
" ,on#atenation #)ara#ter is
-O groups
-O group statement
" iterati8e do group used in an IF statement is a$so used to put se8era$ PL/1 statements
toget)er+ut in t)is tpe o' do group t)ese statements are as a ru$e e7e#uted se8era$ times
-
8/13/2019 pl1 doc1
7/32
o8er a group(
" e(g( 23 do i > 1 to 1:6((((((((
((((((((
end6
t)e do group *i$$ run t)roug) 1: times(
-O group statement
" BY statement 23 i' t)e #ontro$ 8aria+$e is to +e in#reased + a step ot)er t)an 1 t)en ou
use + statement(
e(g( 23 do #ount > 1 to %: + %6
" in do groups ou #an a$so #ount do*n*ards(
e(g( 23 do i > %; to 1 + 316
" in addition to #onstants6 8aria+$es and e7pressions #an a$so +e *ritten in spe#i'i#ation(
e(g( 23 do a$p)a > 7 to +eta " % + de$ta6-O group statement
" Mu$tip$e Spe#i'i#ation 23 mu$tip$e spe#i'i#ations #an +e used in a do statement( #ontro$
passes to t)e ne7t spe#i'i#ation *)en pre8ious )as 'inis)ed(
e(g( 23 do i > 1 to ; %: to %; ;:6
t)is $oop is e7e#uted ; times 'or i > 1 to; t)en < times 'or i > %: to %; and t)en
again *it) i > ;:( )en#e t)e $oop is
e7e#uted tota$$ 1% times(
-O group statement
" o'ten do groups )a8e to +e e7e#uted unti$ a #ertain #ondition is met( t)ese #ases #an +e
)and$ed *it) *)i$e statement(
" e(g( 23 do *)i$e 47 56
" t)is $oop is e7e#uted as $ong as 7 is $ess t)an (
" e(g( 23 do *)i$e 47 N 5 unti$ 4 > 1::56(((((
endo6
" t)is $oop runs as $ong as 7 N and is not eCua$ to 1::(
-
8/13/2019 pl1 doc1
8/32
-O group statement
" nested -O groups 23 nesting o' do groups to a ma7imum o' H is a$$o*ed + PL/1optimiing #ompi$er(
" e(g( 23 outer 2 do i > 1 to ;6inner 2 do Q > 1 to 06
(((((
end inner6end outer6
-O group statement
" e(g( 23 to $ea8e an iterati8e do group(
do i > 1 to 1::6
(((((
i' 7 N t)en $ea8e6(((((
end6GOTO statement
" *it) goto statement ou #an Qump to an statement
*)i#) )as a $a+e$ e7#ept an iterati8e do group(
" e(g( 23 i > 16
a2i' i N 1: t)en goto +6
((((((i > i K 16
goto a6
+2 (((((-ata Aggregates & Arras
-ata Aggregates" t*o tpes o' data aggregates are t)ere 23
3 arras
3 stru#tures
" an arra is a #o$$e#tion o' se8era$ e$ements *it) same attri+utes( t)e are arranged in ata+$e or a matri7(
" *)en ou *ou$d $iDe to put uneCua$ data e$ements toget)er in an aggregate ou s)ou$duse a stru#ture(
-ata Aggregates 4Arras5
" e(g( 23 d#$ ta+$e4;:5 'i7ed de#ima$4056
=
-
8/13/2019 pl1 doc1
9/32
" ta+$e is a one dimensiona$ arra o' ;: e$ements( ea#) e$ement is a de#ima$ 'i7ed point
*it) t)e pre#ision 0:( ta+$e is to +e regarded as a string o' ;: e$ements(
" i' ou *ant to address a sing$e arra e$ement(
" e(g( 23 d#$ #ountta+4;:5 #)ar41:56
d#$ #ountnm #)ar41:56
#ountnm > #ountta+4%56
" se#ond e$ement o' #ountta+ is assigned to #ountnm(
-ata Aggregates 4Arras5
" e(g( 23 -,L num+ers4;5 'i7ed de#4056
do i > 1 to ;6
num+ers4i5 > i " %6end6
" su+s#ripts need not Qust #onsist o' #onstants and 8aria+$es t)e #an a$so +e *)o$e
e7pressions(
e(g( 23 #ost4iKQ5
num+ers4iK%5
num+ers4#osts4i55
#osts4iKQ"%5
-ata Aggregates 4Arras5
" Bui$t3in 'un#tions 23333333333333333333
" a +ui$t3in 'un#tion rep$a#es a num+er o' statements *)i#) t)e programmer *ou$d
ot)er*ise )a8e to *rite )imse$'(
" 'or e(g( 'un#tion ALJAYS return one 8a$ue and is re#ognised + PL/1 t)ru snta7(
" e(g( 23 d#$ 4a+5 'i7ed de#456d#$ 741:5 'i7ed de#4056
d#$ 41%5 'i7ed de#456
a > + K sum475 K sum456-ata Aggregates 4Arras5
" Mu$ti3-imensiona$ Arra 23
33333333333333333333333" t)e dimension attri+ute states t)e num+er o' t)e dimensions 'or an arra and t)e +ounds
o' ea#) dimension(
" e(g( 23 d#$ ta+$e4%5 'i7ed de#ima$4056
-
8/13/2019 pl1 doc1
10/32
" t)e a+o8e mentioned arra #onsists o' ro*s and % #o$umns(
" e(g( 23 d#$ parts400;5 #)ar41:56
" t)e a+o8e de#$ared parts arra #onsist o' H; e$ements(-ata Aggregates 4Arras5
e(g( 23 d#$ ta+40;5 'i7ed +inar41;56
do Q > 1 to 06
do D > 1 to ;6
ta+4QD5 > %6
end6end6
7 > sum4ta+56
" 8a$ue o' E7E a'ter e7e#ution is 0: +e#ause ea#) o' t)e 1; e$ements in t)is arra is set to %(
" a$$ e$ement o' arra ta+ #an +e set to % + one sing$e instru#tion( @ ta+ > % (
-ata Aggregates 4Arras5
" ,ross se#tion o' an arra 23 ou #an a$so address a #ross se#tion o' a arra(
" e(g( 23 d#$ 'igures4;05 'i7ed de#6
d#$ 74056
7 > 'igures4%"56
" in t)e a+o8e #ase " represents a$$ t)e e$ements o' ro* %(
" )en#e 7 > 'igures4%"5 is eCua$ to
7415 > 'igures4%15674%5 > 'igures4%%56
7405 > 'igures4%056
-ata Aggregates 4Stru#tures5" Simp$e Stru#tures 23
33333333333333333
" *)en ou *ou$d $iDe to put uneCua$ data e$ements toget)er in an aggregate ou s)ou$duse a stru#ture(
" e(g( 23 d#$ 1 personne$% name #)ar40:5
% sa$ar 'i7ed de#ima$4%56
" name o' t)e *)o$e stru#ture is personne$( ea#) e$ement in it )as itEs o*n name and itEs
1:
-
8/13/2019 pl1 doc1
11/32
o*n attri+ute(
-ata Aggregates 4Stru#tures5
" during pro#essing e$ements #an +e addressed sing$ or a$$ toget)er using t)e stru#turename( a sing$e e$ement #an +e addressed + itEs name(
" 'or e(g( 23 name > Eo)n Mi$$erE6
put 'i$e4out5 $ist4personne$56
put 'i$e4out5 $ist4name sa$ar56
" t)e a+o8e t*o statements )a8e t)e same meaning( *rite to t)e 'i$e out t)e 8a$ues o'
name and sa$ar(
" ma7imum num+er o' $e8e$s in a stru#ture is 1;(
-ata Aggregates 4Stru#tures5
" Arras in a Stru#ture & ua$i'ied !ames 23
333333333333333333333333333333333333333" d#$ 1 mont)41%5
% ma7 'i7ed de#4%5% min 'i7ed de#4;%56
" t)ere are 1% o##uren#e o' mont) and ea#) o##uren#e )as % e$ements(
" i' ou *ant to re'er t)e e$ement min in 1:t) stru#ture(
mont)41:5(min 4OR5 mont)(min41:5
" Cua$i'ied name is mont)41:5(min 4OR5 mont)(min41:5
BY !AM option in a stru#ture" t)ere is one *a + *)i#) ou #an use non3identi#a$ stru#tures in stru#ture e7pression(
t)at is + name option(
" + name is used to maDe assignments 'rom one stru#ture to anot)er *)ere+ #ompi$er
pro#esses on$ t)e e$ements *)ose 'u$$ Cua$i'ied names in +ot) stru#tures are identi#a$(
e(g( 23 d#$ 1 ne* d#$ 1 o$d% name % name
% address
% pament % pament0 gross 0 gross
0 net 0 net
0 dedu#tions6 % dedu#tions6BY !AM option in a stru#ture
" t)ere is an assignment 'or a$$ t)e e$ements *)i#) )a8e t)e same Cua$i'ied names in t)e
stru#tures ne* and o$d(
11
-
8/13/2019 pl1 doc1
12/32
ne* > o$d + name6
" 0 e$ements are assigned in t)is stru#ture e7pression(
ne*(name > o$d(name6
ne*(pament(gross > o$d(pament(gross6ne*(pament(net > o$d(pament(net6
Introdu#tion to Input/Output
Basi# 'eatures o' Input/Output
" GT 23 transmits or gets data 'rom e7terna$ medium
to interna$ storage(
" P.T 23 transmits data 'rom interna$ to e7terna$
storage(
" % tpes o' transmission are t)ere +et*een interna$ &e7terna$ storage 23
stream i/o *it) get & put 23 data item is transmitted sing$( ad8isa+$e 'or sma$$ Cuantities
i(e( s#reen & #ard readers(
re#ord input/output *it) read & *rite 23 #omp$ete re#ord o' data items is transmitted and
#op o' t)e re#ord is usua$$ Dept in interna$ storage( it is pre'era+$e 'or $arger Ct o' data(
Basi# 'eatures o' Input/Output
" snta7 o' % i/o statements 2333333333333333333333333333
stream 3N get 'i$e4input5 $ist4a+#56
re#ord 3N read 'i$e4input5 into4inarea56
" opening & #$osing o' 'i$es 2333333333333333333333333333
e(g( 23 d#$ master 'i$e re#ord seCuentia$6
((((((((((
open 'i$e4master5 output6((((((((((
#$ose 'i$e4master56
n8ironment attri+ute
" en8ironment attri+ute de'ines t)e p)si#a$ organisation o' data sets 4e(g( re#ord $engt)
+$o#Ds5 and t)e met)od o' pro#essing t)em(
" de'au$t 8a$ue 'or t)e tpe o' organiation is #onse#uti8e( t)is tpe o' organiation #an
+e pro#essed on$ seCuentia$$(
1%
-
8/13/2019 pl1 doc1
13/32
" e(g( 23 d#$ pur#)ase re#ord seCuentia$ input
en84#onse#uti8e56
open 'i$e4pur#)ase56
" re#ord is an attri+ute in t)e de#$aration(
stream is de'au$t 'or t)e transmission tpe(STRAM Input/Output
STRAM I/O Features" a string o' #)ara#ters is transmitted in stream i/o(
" #)ara#ter data tpe *i$$ not #ause #on8ersion i' it is used in get or put(
" standard 'i$es 'or stream i/o 23 t)e get and t)e put statements not )a8ing data 'i$e
de#$arations are $inDed *it) standard 'i$es 'or *)i#) t)ere are pres#ri+ed 'i$e names(
SYSI! 'or input SYSPRI!T 'or output
" )en#e P.T LIST4-ATA LIST56is taDen as P.T FIL4SYSPRI!T5 LIST4-ATA LIST56
0 Tpes o' I/O Stream
" $ist 3 a$*as reCuires data $ist
" data 3 reCuires no $ist
" edit 3 reCuires data and 'ormat $istSTRAM I/O Features
" List3-ire#ted I/O 23
33333333333333333it is simp$est 'orm o' stream I/O and is idea$ 'or testing input at t)e termina$(
" e(g( 23 get $ist4#1#%#056put $ist4grossnetgross3net56
" e(g( 23 d#$ temps4%5 'i7ed de#ima$4056
(((((get $ist4temps56
1H e$ements *ou$d +e read + t)e get statement(
" input in $ist dire#ted i/o is in #)ara#ter 'orm( t)e data items are separated + #omma
and/or +$anDs(STRAM I/O Features
" -ata3-ire#ted I/O 23
33333333333333333
input data #an +e read in t)e 'orm o' assignment statements in input stream( a semi #o$on
10
-
8/13/2019 pl1 doc1
14/32
or t)e end o' data 'i$e ends t)e transmission o' an i/o statement(
" e(g( 23 A>% B>EYE6 333333N get data4a+56A>;6 333333N get data4a+56
B>E.VE6 333333N get data4a+56
" in 'irst read EAE is numeri#a$ and EBE is #)ara#ter(
on se#ond get EAE > ; and EBE is un#)anged(
on t)ird get EAE is un#)anged and EBE is E.VE(STRAM I/O Features
" dit3-ire#ted I/O 23
33333333333333333
" it is t)e most #ommon$ used tpe o' stream i/o( a data $ist is needed )ere as *e$$ to#ontain t)e names o' data items arras or stru#tures( in addition a 'ormat $ist is reCuired
in *)i#) t)e 'ormat o' i/o data is des#ri+ed(
" e(g( 23 put 'i$e4output5 edit4data $ist5 4'ormat56get 'i$e4ssin5 edit4data $ist5 4'ormat56
" e(g( 23 get edit4Ct pri#e te7t5
4"40574
-
8/13/2019 pl1 doc1
15/32
option meaning de'au$t
333333 3333333 3333333
$inesie4nn5 $ine $engt) 1%: #)ars per $inepagesie4nn5 page $engt)
-
8/13/2019 pl1 doc1
16/32
" re#ord i/o transmits re#ords Qust as t)e are stored(
in stream i/o data #on8ersion is possi+$e(
" in re#ord i/o t)ere are no standard 'i$es(
SYSI! and SYSPRI!T are 8a$id standard 'i$es 'or stream i/o(
" re#ord i/o a$$o*s 8arious 'orms o' data set organiation(
stream i/o a$$o*s on$ seCuentia$ 'orm o' data set(R,OR- I/O Features
" re#ord i/o o''ers % a$ternati8e modes o' pro#essing 4mo8e / $o#ate5(
" MOV mode 23 in mo8e mode a $ogi#a$ re#ord is transmitted + reading 'rom t)e+u''er to an area 4e(g( stru#ture5 *)ere it is t)en pro#essed(
" 'orm 23 read 'i$e4'i$ename5 into4area56
" using read a $ogi#a$ re#ord is put into a 8aria+$e de#$ared in t)e program(
e(g( 23 d#$ 1 inre#
% part1 #)ar4%;5
% part% 41:5 de#ima$ 'i7ed4%56
read 'i$e4materia$5 into4inre#56
R,OR- I/O Features
" IG!OR option 23 ignore spe#i'ies )o* man $ogi#a$ re#ords are to +e sDipped(
" 'orm 23 read 'i$e4'i$ename5 ignore4!56
E!E is t)e num+er o' re#ords to +e sDipped(
" Re#ord output in MOV mode23 on ea#) *rite a $ogi#a$ re#ord is transmitted 'rom t)earea to a +u''er( i' re#ord 4or +$o#D5 is 'u$$ a p)si#a$ re#ord 4'or +$o#D5 is *ritten into t)e
data set(
'orm 23 *rite 'i$e4'i$ename5 'rom4area56
*rite statement #auses a re#ord to +e
*ritten 'rom t)e area spe#i'ied i(e( t)ere#ords are put in +$o#Ds(
R,OR- I/O Features
" de#$aration and opening o' 'i$e 233333333333333333333333333333333
" e(g( 23 d#$ pers 'i$e input seCuentia$ +u''ered
en84#onse#uti8e FB R,SI41::5
BLSI4;::5 B.FFRS40556
1
-
8/13/2019 pl1 doc1
17/32
FB means 'i7ed re#ord $engt) +$o#Ded
R,SI means $engt) o' t)e re#ord in +tesBLSI means $engt) o' t)e +$o#D in +tes
B.FFRS means num+er o' +u''ers
" t)e re#ord )as 1:: #)ara#ters and +$o#D )as ;:: #)ara#ters )en#e t)ere are ; re#ords
per +$o#D(
" en8ironment attri+ute des#ri+es t)e p)si#a$ properties o' a data set( #onse#uti8e means
t)at re#ords are stored seCuentia$$(
LOCATE mode
In t)is mode t)e $ogi#a$ re#ords are dire#t$ pro#essed in +u''er( )ere a +ased 8aria+$e or a pointer
8aria+$e is needed 4a stru#ture *it) t)e $engt) o' a $ogi#a$ re#ord5 is $iDe a masD *)i#) is $aid o8er
t)e +u''er(
record input in locate mode :-Fi$es to +e pro#essed using $o#ate mode must $iDe ot)er 'i$es +e
de#$ared and opened( t)e 'irst p)si#a$ re#ord )as a$read +een read into t)e +u''er and opened(
using :-read 'i$e4'i$ename5 set4pointer56
T)e address o' t)e 'irst re#ord $ogi#a$ pointer is put in t)e 8aria+$e pointer(
POINTER Variable
A pointer 8aria+$e is a 8aria+$e 4'u$$ *ord H +tes5 *)i#) #ontains a storage address( t)is address
#an +e assigned to pointer 8aria+$e in 8arious *as(
e(g( 23 d#$ 7 pointer6
read 'i$e4input5 set4756
A pointer is used to point to t)e position o' t)e ne7t re#ord in a +u''er or to anot)er 8aria+$e(
BAE! Variable
In t)e e(g( gi8en +e$o* read p$a#es t)e address o' ne7t $ogi#a$ re#ord in t)e pointer ptr(
e(g( 23 d#$ 1 e'i$e +ased4ptr5
% name #)ar40:5
% 'irst9name #)ar4%:5
% persno 'i7ed de#4;56
Read 'i$e4pers5 set4ptr56
1
-
8/13/2019 pl1 doc1
18/32
T)e +ased 8aria+$e e'i$e is o8er$aid on t)e $ogi#a$ re#ord as it )as t)e attri+ute +ased and #ontains
address as t)e pointer(
E"ample o# Record read in locate mode
Fd#$ one 'i$e input seCuentia$ +u''ereden84'+ re#sie4%::5 +$Dsie41:::5 +u''ers41556
d#$ C pointer6
d#$ re#ord9a #)ar4%::5 +ased4C56
(((((
read 'i$e4one5 set4C56
On inre#6
goto $oop6
Re$riting o# a #ile in %OVE and LOCATE mode
Jit) RJRIT statement re#ords read in #an +e #)anged and *ritten +a#D to t)e same p$a#e
t)e #ame 'rom in t)e data set(
e(g( 23 d#$ personne$ 'i$e seCuentia$ +u''ered
update6
d#$ re#ord #)ar4;::5 +ased4p56
d#$ p pointer6
1=
-
8/13/2019 pl1 doc1
19/32
read 'i$e4personne$5 set4p56
(((((((
#)ange re#ord read in (((((
(((((((
re*rite 'i$e4personne$56
Variable lengt& record
I' Cuantit o' data per $ogi#a$ re#ord 8aries a great dea$ 4as 'or e(g( *it) addresses5 it is a
good idea to store t)e data in 8aria+$e $engt) re#ord(
note 23 T)ere is H +te re#ord $engt) 'ie$d 4RL5+e'ore e8er 8aria+$e re#ord(
T)ere is a H +te +$o#D $engt) 'ie$d +e'ore e8er +$o#D(
e(g( 23 suppose t)e +iggest $ogi#a$ re#ord #an +e 1::: +tes $ong and t)at t)e re#ords are to
+e +$o#Ded in su#) a *a t)at a +$o#D is $iDe*ise to )a8e t)e ma7imum $engt) o' 1:::
+tes t)en en8ironment attri+ute o' 'i$e de#$aration *ou$d $ooD $iDe
en848+ re#sie41::H5 +$Dsie41::=556
i'e statements are calculated as :-
re#sie > 1::: +tes K H +tes re#ord $engt)
+$Dsie > re#sie K H +tes +$o#D $engt)
In 'i7ed 'ormat t)e re#ord $engt) and t)e +$o#D $engt) are 'i7ed +ut in 8aria+$e 'ormat t)e
re#ord $engt) and t)e +$o#D $engt) 8ar
+$o#D $engt) is sie o' t)e p)si#a$ re#ord
re#ord $engt) is sie o' t)e $ogi#a$ re#ord
I' data $engt) o' t)e re#ord is ;: t)e re#ord sie *i$$ +e ;H and t)e +$o#D sie *i$$ +e ;=(
CALAR VAR(IN) option
I' ou are using re#ord i/o *it) 8aria+$e $engt) strings and $o#ate mode t)en s#a$ar 8aring
option must +e stated in en8 attri+ute 'or i/o so t)at t)e % +te $engt) area *)i#) goes +e'ore ea#)
8aria+$e $engt) string are taDen into #onsideration(
e(g( 23 d#$ pers3'i$e 'i$e re#ord output +u''ered
en848+ re#sie41:
-
8/13/2019 pl1 doc1
20/32
1( e SeCuen#ed -ata Set 4S-S5
%( ntr SeCuen#ed -ata Set 4S-S5
0( Re$ati8e Re#ord -ata Set 4RR-S5
Note :-SeCuentia$ is t)e de'au$t 'i$e organiation )en#e 8sam s)ou$d +e spe#i'ied in t)e !V
option(
Vsam 'i$es are a$*as re#ord 'i$es( Re#ords on a 8sam 'i$e are not )e$d in +$o#Ds )en#e t)e
+$Dsie option e8en i' spe#i'ied is ignored( A re#sie option *i$$ +e #)e#Ded against t)e detai$s
stored *it) t)e 'i$e(
T)e uti$it I-,AMS 4a##ess met)od ser8i#es5 is used to set up a 8sam 'i$e initia$$(
Various !CL #or VA% datasets
e(g( 23 d#$ 8'i$e re#ord dire#t Deed input en848sam56
Vsam 'i$es are a$$ dire#t a##ess 'i$es( asso#iated *it) e8er re#ord is a De *)i#) )e$ps in
a##essing t)e re#ord in an order(
e(g( 23 d#$ 8'i$e 'i$e re#ord seCuentia$ input en848sam56
I' ou *ant to start at t)e +eginning and pro#ess e8er re#ord Qust as *it) a #onse#uti8e 'i$e
spe#i' t)e 'i$e as seCuentia$(
e(g( 23 d#$ 8'i$e 'i$e re#ord seCuentia$ Deed input en848sam56
T)e 'irst read o' t)e program spe#i'ies t)e De o' t)e re#ord ou *ant to start at su+seCuent
seCuentia$ read statements are issued *it)out a De(
e(g( 23 d#$ in'i$e 'i$e re#ord dire#t Deed input en848sam56
to read a 8sam 'i$e dire#t$(
e(g( 23 d#$ in'i$e 'i$e re#ord dire#t update en848sam pass*ord4EmasterE556
J)en a 'i$e is origina$$ set it #an +e gi8en one or more pass*ords( i' attri+ute re#ord is gi8en it
means t)at it must +e a 'i$e )en#e t)e attri+ute 'i$e is imp$ied and t)ere'ore optiona$(
*e+ e,uenced !ata et *!.
S-S is used to )o$d master 'i$e data( identi'i#ation is + means o' De so t)e attri+ute -IR,T
imp$ies Y-(
e(g(23 d#$ amast 'i$e re#ord dire#t input en848sam56
SeCuentia$ a##ess is possi+$e *it) Dsds(
A Dsds )as a De *)i#) is part o' a data re#ord t)is is Dno*n as an em+edded De(
%:
-
8/13/2019 pl1 doc1
21/32
es are a$so stored in anot)er part o' data set #a$$ed as prime inde7(
T)e Des are uniCue sin#e dup$i#ation is not a$$o*ed(
*! /eaturesReading a 0sds directl+ :-Re#ords are a##essed + spe#i'ing a 8a$ue using t)e
De option(
e(g(23 d#$ a$most 'i$e re#ord dire#t input en848sam56
d#$ 1 area
% DsDe #)ar4;5
% Dsname #)ar41;56
read 'i$e4amast5 into4area5 De4E:::1:E56
1pdating a 0sds directl+ :-T)e 'i$e s)ou$d +e opened as update( ou #annot amend t)e De(
e(g(2 d#$ Dmast 'i$e re#ord dire#t update en848sam56
d#$ 1 area
% DsDe #)ar4;5 init4E:::=1E5
% Dsname #)ar41;56
read 'i$e4Dmast5 into4area5 De4DsDe56
/" amend "/
re*rite 'i$e4Dmast5 'rom4area5 De4DsDe56
!elete a record in 0sds :-:-:-.se de$ete statement(
e(g( 23 DsDe > E:::;
-
8/13/2019 pl1 doc1
22/32
I' genDe option is not spe#i'ied in t)e en8ironment statement 8sam sear#)es 'or a re#ord *it) a
De o' U1%0U(
I' genDe option is spe#i'ied t)e 'irst read reads t)e 'irst re#ord o' data set +eginning *it) 1%0(
Se#ond read #ontinues *it) t)e re#ord immediate$ 'o$$o*ing it(
ENTRY Sequenced Data Set (ESDS)
It is t)e most $iDe$ #onse#uti8e non38sam 'i$e( i(e( data is not in a parti#u$ar order )en#e t)e 'i$e
is seCuentia$(
An esds 'i$e *)i#) a$read )as data on it ma on$ +e opened *it) eit)er input or update
attri+utes(
e(g( 23 d#$ esds 'i$e re#ord seCuentia$ update en848sam56
1pdating an esds #ile :-
It is possi+$e to #)ange re#ords on#e t)e )a8e +een *ritten to esds 'i$e(
e(g( 23 read 'i$e4esds5 into4area56
((((((
re*rite 'i$e4esds5 'rom4area56
Jrite #an a$so +e used and t)e ne* re#ords added are a$*as added at t)e end(
-e$ete is not a$$o*ed(
Keed access to an ESDS !ile
An esds is a seCuentia$ 'i$e and )as no de'ined De(
T)e in'ormation t)at #an +e used 'or Deed a##ess is #a$$ed re$ati8e +te address 4r+a5(
re#ord31 2 re#ord3% 2 re#ord30 2 re#ord3H
2 2 2
;: +tes 2 H: +tes 2 : r+a>;: r+a>: r+a>1;:
You )a8e to get )o$d o' r+a + using YTO option on read and *rite(
e(g( 23 d#$ esds 'i$e re#ord seCuentia$ Deed update
en848sam56
%%
-
8/13/2019 pl1 doc1
23/32
d#$ r+a #)ar4H56
((((((
*rite 'i$e4esds5 'rom4area5 Deto4r+a56
R+a must +e a H +te #)ara#ter string( t)is *i$$ add a ne* re#ord to t)e end o' t)e 'i$e and p$a#e
t)e re$ati8e +te address o' t)e re#ord in t)e 'ie$d r+a( t)is is t)en used as a De on a read orre*rite( 'i$e s)ou$d +e de#$ared as Deed(
e(g( 23 read 'i$e4esds5 into4area5 De4r+a56
e(g( 23 /" e7amp$e o' esds read and re*rite "/
d#$ esds 'i$e re#ord seCuentia$ Deed update
en848sam56
d#$ r+a #)ar4H56
read 'i$e4esds5 into4area5 Deto4r+a56
( ( ( ( ( (
re*rite 'i$e4esds5 'rom4area5 De4r+a56
RE"AT#VE Reco$d Data Set (RRDS)
Re#ords are read and #an +e a##essed seCuentia$$ or dire#t$ *it) or *it)out Des(
T)e data set ma +e t)oug)t o' as a set o' num+ered s$ots ea#) o' *)i#) ma )o$d re#ord( t)e
num+ering starts at 1 and goes to t)e ma7imum spe#i'ied(
Re#ord num+er is t)e re$ati8e re#ord num+er( t)is is t)e De to t)e 'i$e(
T)e De must +e de#$ared as a #)ara#ter string o' $engt) =(
e(g( 23 d#$ re$re#no #)ar4=5 init4E:::::1H;E56
e(g( 23 d#$ re$re#no #)ar4=5 init4E 1H;E56
*e+ed access to an RR!
Fi$e ma +e de#$ared as seCuentia$ or dire#t(
I' t)e 'i$e is de#$ared as Deed seCuentia$ a$$ De options #an +e used( i' ou $ea8e De re'eren#e
pro#essing *ou$d +e Qust 'or a seCuentia$ 'i$e(
e(g23
d#$ rrds 'i$e re#ord seCuentia$ Deed update en848sam56
d#$ rrDe #)ar4=56rrDe > 4E::::::%;E56
read 'i$e4rrds5 into4area5 De4rrDe56 /" read re$(re#(no %; "/
((((((
re*rite 'i$e4rrds5 'rom4area56 /" re#(no %; is re*ritten "/
((((((
read 'i$e4rrds5 into4area5 Deto4rrDe56 /" reCuests a "/
/" re#ord num+er( "/
%0
-
8/13/2019 pl1 doc1
24/32
/" t)e ne7t re#ord *i$$ "/
/" +e presented and t)e "/
/" De 8a$ue *i$$ +e "/
/" p$a#ed in rrDe "/
3RITE in an RR!
e(g( 23 /" assume re#ord ; e7ists on 'i$e rrds( "/
d#$ rrds 'i$e re#ord seCuentia$ Deed update
en848sam56
d#$ re$re#no #)ar4=56
d#$ 1 area
% (((((( 6
re$re#no > E:::::::;E6
read 'i$e4rrds5 into4area5 De4re$re#no56
((((((
de$ete 'i$e4rrds5 De4re$re#no56
((((((
*rite 'i$e4rrds5 'rom4area5
De'rom4re$re#no56
%$ocessing o! St$ing Data
1BTR Built-in /unction.
Su+str is used to a##ess a part o' a string(#orm :-4string38ar( start3pos( $engt)3o'3e7tra#t5
e(g( 23 d#$ data #)ar4;:56
d#$ 'ie$d #)ar41:56
((((((
data>EI!TR!ATIO!AL B.SI!SS MA,I!SE6
'ie$d>su+str4data
-
8/13/2019 pl1 doc1
25/32
#orm :-pos( > inde74string sear#) string56
Inde7 'un#tion returns a +inar num+er 41;:5( I' string to +e $ooDed 'or is not 'ound t)e return
8a$ue is ero( on$ 'irst o##uren#e is s)o*n(
e(g( 23 d#$ to*n9#ountr #)ar4%;56((((((
to*n9#ountr > EJYBRI-GS.RVYE6
i#omma>inde74to*n9#ountrEE56
i#omma *i$$ +e 1:(
e(g( 23 d#$ 4stringpart15 #)ar40:56
((((((
ipos > inde74stringE/E56
part1 > su+str4string1ipos3156
VERI/( Built-in /unction.
VERI/( #unction :-Veri' *i$$ see t)at a string *i$$ )a8e on$ #ertain #)ara#ters present(
#orm :-8eri'47 56
EE is t)e string o' #)ars to +e #)e#Ded in Y(
EYE is t)e string #ontaining t)e $ist o' #)ara#ters *)i#) are to +e $ooDed 'or(
A binar+ #i"ed point number is returned :-
3 ero i' a$$ #)ara#ters in EE appear a$so in EYE(
3 A 8a$ue *)i#) gi8es t)e position o' t)e 'irst #)ara#ter in EE *)i#) does not appear in EYE(
e(g( 23 d#$ test #)ar4056
test>EBITE6
I>8eri'4testEAB,--FGIE56
0 *ou$d +e returned +e#ause t)e t)ird #)ara#ter is not in t)e se#ond parameter o' 8eri'(
TRANLATE Built-in /unction.
#orm :-trans$ate47 5
EE > #)ara#ter string to +e #)e#Ded
EYE > string o' rep$a#ement #)ara#ter
EE > #)ars in EE *)i#) are to +e rep$a#ed i' 'ound
resu$t is modi'ied #)ara#ter string EE(
e(g( 23 d#$ 4o$d ne*5 #)ar41:56
d#$ i#)ara#ter #)ar41:5 init4EFIRT.E56
d#$ t#)ara#ter #)ar41:5 init4EA!.ITE56
%;
-
8/13/2019 pl1 doc1
26/32
((((((
o$d > EFIT.RSE6
ne* > trans$ate4o$dt#)ara#teri#)ara#ter56
ne* > trans$ate4EFIT.RSEEA!.ITEEFIRT.E56 > A!TI.S
LEN)T5 Built-in /unction.
T)is determines t)e $engt) o' t)e string( 8a$ue returned is +inar 'i7ed point num+er 41;:5(
#orm :-$engt)4756
e(g( 23 d#$ 'ie$d #)ar4:5 8aring6
'ie$d > EGOO- L., E6
i$engt) > $engt)4'ie$d56
i$engt) re#ei8es t)e 8a$ue 11(
%seudo&a$ia'les
I' a 'un#tion is on t)e $e't in an assignment ou )a8e a pseudo8aria+$e( pseudo8aria+$es are
'un#tions *)i#) ma not on$ manipu$ate 8a$ues +ut ma a$so re#ei8e t)em(
e(g( 23 su+str4t'ie$d%;5 > g'ie$d6
e(g( 23 d#$ 7 #)ar41:567 > EAB,-FGIE6
su+str47 su+str471;56
/" so$n is EAB,-AB,-E "/
note :-sCrt4sum5 > %6 is not a pseudo8aria+$e(
%$og$a $gani*ation
T+pes o# Bloc0s
PL67 0no$s t$o t+pes o# bloc0s :-
1( Pro#edures
%( Begin3+$o#Ds
Procedures are o# t$o t+pes :-
1( 7terna$ Pro#edures
%( Interna$ Pro#edures
%
-
8/13/2019 pl1 doc1
27/32
An TR!AL pro#edure is a +$o#D *)i#) is not #ontained in anot)er +$o#D(
T)e are #ompi$ed separate$ +ut t)e #an Qoined to maDe one program + $inDage editor so t)at
% programmers #an *orD on it simu$taneous$(
Option main identi'ies t)e main pro#edure(
i(e( $a+e$2pro# options4main56
An I!TR!AL pro#edure is in8oDed + a #a$$ 'rom a surrounding +$o#D and #ontro$ returns to
statement a'ter t)e #a$$(
Jit)in an e7terna$ pro#edure ou #an )a8e upto ;: interna$ pro#edures(
e(g( 23 outer2pro# options4main56
statement1
#a$$ inner6 33333333
3333333333N statement% 2
2 W inner2pro#6 3333333
2 2 statement0
2 2 statementH
V 3333333 end inner6
3333333333N statement;
statement Ea$$ #$ear XE6
put 'i$e4printer5 edit4'ie$d75 474;5A56
'ree 'ie$d76 /" storage spa#e is 'reed "/
Su'$outines + Functions
Su'$outines
It is a$*as an interna$ or e7terna$ pro#edure( A su+routine is not rep$a#ed + a resu$t 8a$ue a'ter
its e7e#ution( A su+routine is a$*as in8oDed *it) a #a$$ statement( Su+routines are o'ten added
as e7terna$ pro#edures(
e(g( 23 mrou2pro# options4main56
d#$ ((((((6
#a$$ srou16
((((((
#a$$ srou%6
end mrou6
srou12pro#6 srou%2pro#
d#$ ((((((6 d#$ ((((((6
((( ((((((
end srou16 end srou%6
Arguments
J)en a pro#edure is in8oDed using a #a$$ it is possi+$e to pass 8aria+$es *)i#) are #a$$ed as
arguments(
e(g( 23 d#$ re#1 #)ar4H;56
d#$ 1 inre#
% part1 #)ar41:5
% amount 'i7ed de#4%56
#a$$ srou4re#1inre#56 /" arguments "/
Parameters
A program to *)i#) arguments are passed *)en it is in8oDed are #a$$ed as parameters(
e(g(23 srou2pro#4a+56
d#$ a #)ar41::56
d#$ 1 +
% +1 #)ar41:5
% +% 'i7ed de#4%56
0:
-
8/13/2019 pl1 doc1
31/32
ere a & + are t)e parameters *)ere a > re#1 and + > inre#(
T)e seCuen#e and t)e attri+utes o' t)e arguments and parameters must +e identi#a$( names ma +e
di''erent +ut t)e use same area(
Note :-nu$$ arguments ma +e indi#ated + t*o #ommas and unne#essar arguments o' t)e end
o' t)e $ist ma +e omitted(
%ultiple Entr+ Points
Su+routine ma )a8e se8era$ entr points(
3 primar entr points #an +e identi'ied + PRO,(
3 se#ondar entr points #an +e identi'ied + !TRY statements(
a#) entr points ma )a8e di''erent parameter $ist(
e(g( 23 prog12pro# options4main56
#a$$ prog;4a+56
#a$$ ent%4a+#56
#a$$ ent14#56
end prog16
pro#;2pro#4756
((((((
ent12entr4m56
((((((
ent%2entr47m56
((((((
end prog;6
E"it #rom Procedures
!orma$ e7it 'or a pro#edure is !-(
Furt)ur e7it #an +e pro8ided using RT.R!(
e(g( 23 srou2pro#4756
((((((
ent%2entr4mno56
((((((
i' 7 > : t)en return6
((((((
end srou6
/unctions
Fun#tions are a$*as a part o' an e7pression( A 'un#tion is rep$a#ed + its resu$t a'ter e7e#ution(
e(g( 23 /" +ui$t3in 'un#tions "/
7 > sum4ta+056 /" *it) an argument "/
01
-
8/13/2019 pl1 doc1
32/32
adds up a$$ e$ements o' arra ta+(
8 > date456 /" *it) empt arguments "/
A 'un#tion #a$$ is rep$a#ed + 8a$ue returned(
e(g( 23 #a$#2pro#4a+#56((((((
i' 7 N t)en return47"56
e$se return456
((((((
end #a$#6
ON-1NIT.
On !-PAG and on !-FIL are some important #onditions *)i#) #an +e 'orseen(
e(g( 23 on endpage4ssprint5 +egin6
n > n K 16
put edit4EpageE n5 4page 74:5 a pEE56
put sDip4056
end6
T)is *rites t)e #urrent page num+er *)en t)e pre#eding page is 'u$$(
I)NAL 2 REVERT
I)NAL option :-Jit) signa$ statement a #ondition #an +e #aused arti'i#a$$( T)e program
#ontinues *it) t)e statement *)i#) #omes immediate$ a'ter signa$ statement(#orm :-SIG!AL #ondition6
Signa$ is used to raise #onditions de$i+erate$(
e(g( 23 on endpage4print05 #a$$ o8ers6
((((((
signa$ endpage4print056
REVERT option :-,an#e$s on3unit 'or t)e #ondition spe#i'ied(
e(g( 23 on error #a$$ error16
/" error1 *i$$ +e #a$$ed "/on error #a$$ error%6
/" error% *i$$ +e #a$$ed "/
re8ert error6
/" #an#e$s error% error1 *i$$ +e #a$$ed "/