Vous êtes sur la page 1sur 32

PL / I

GRAVITYLimitedBAS Group PL/1 Programming Language / 1 PL/1 Statements & Programs FORMAT OF A PL/1 STAT M !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#edure statement must +egin *it) a $a+e$/ 1 to 01 #)ars( " t)e 'irst #)ara#ter o' a $a+e$ s)ou$d a$*a1s +e an a$p)a+et and t)e $a+e$ s)ou$d +e 'o$$o*ed +1 a #o$on( " $ast statement o' a pro#edure a$*a1s ends *it) !-( !- ends t)e program and passes t)e #ontro$ to t)e operating s1stem( 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(

" in PL/1 t)ere are % +asi# data t1pes 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 +inar1( " 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<=0%; %: > 1<=0%; " 41:""%:5 -,L Binar1 data items " +inar1 num+ers #onsists o' 1 and :( to indi#ate t)at a #onstant is a +inar1/ it is 'o$$o*ed +1 a ?B?( " e(g( 23 1:111::1:B @ pre#ision is 4A/:5 B " a +inar1 'i7ed point 8aria+$e is de#$ared as -,L m+innum 'i7ed +in41</:56 " t)e ma7imum num+er o' digits in a +inar1 num+er is 01( t)e de'au$t 'or 'i7ed +inar1 8aria+$e is 1;/:( -,L String data items " string data #an +e eit)er #)ara#ter or +it string( PL/1 re#ognises string data +1 t)e Cuotation marD *)i#) must appear at t)e start and 'inis) o' ea#) string( " e(g( 23 Et)e *or$dE " to use Cuotation in #)ara#ter string/ #ode t*o o' t)em( " e(g( 23 donEt as a #)ar string is represented +1 EdonEEtE

-,L String data items " to repeat a #)ara#ter string use 4n5E#)ar stringE " e(g( 23 4=:5ERAFE 4RAF *i$$ +e repeated =: times(5 " de#$aration o' #)ara#ter string 8aria+$e is done as -,L name ,GAR41;5 " to 8ar1 not on$1 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 ,GAR4005 VARYI!G6 " t)e $engt) #an 8ar1 'rom 1 to 00 and no padding o' spa#es is done/ i' t)e $engt) is $ess t)an 00( BIT strings " +it strings are $iDe #)ar strings e7#ept t)at t)e digits represent one +it 4: and 15( +it strings must +e en#$osed in Cuotation marDs( " +it strings ma1 too )a8e 8ar1ing attri+utes( " e(g( o' +it string #onstants E1:111:1::1EB E111EB 4%H5E:EB " e(g( o' +it string 8aria+$es -,L s*it#) BIT415/ -,L +itstr BIT40%:5 VARYI!G6 7p$anation o' some s1m+o$s used in P$/1 program " ,OLO! 2 3 'o$$o*s a $a+e$ " ,OMMA / 3 separates $ist items " S MI,OLO! 6 3 ends a statement " PAR !TG S S 45 3 en#$oses $ist items " AST RISI " 3 mu$tip$i#ation -i''eren#e +et*een a +inar1 num+er & a +it string " a +inar1 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 +1 more t)an one name( it #an +e used to o8er$a1 or su+3di8ide areas o' string data(

" e(g( 23 -,L id#ode ,GAR4=56 -,L area ,GAR405 - F id#ode6 id#ode>EA:%B1;:<E6 P.T LIST4area56 " +ase 8aria+$e id#ode o##upies = +1tes o' storage( " 8aria+$e area de'ined o8er it starts at t)e same address +ut it is on$1 0 +1tes $ong( " put *rites out t)e 'irst 0 #)ara#ters o' id#ode EA:%E( POSITIO! or POS attri+ute " *it) POS/ 1ou #an maDe t)e de'ined 8aria+$e start at an1 position o' t)e +ase 8aria+$e( " e(g( 23 -,L id#ode ,GAR4=5/ part1 ,GAR405 - F id#ode/ part% ,GAR405 - F id#ode POS4H5/ part0 ,GAR4%5 - F id#ode POS4&56 " part1 o8er$a1s t)e 'irst 0 #)ara#ters o' id#ode6 part% is o8er #)ara#ters H/;/<6 and part0 is o8er #)ara#ters &/=( POSITIO! or POS attri+ute " e(g( 23 -,L *)o$e BIT41:5/ se$e#t BIT405 - F *)o$e POS4;56 JGOL >E1:::111:1:EB6 " #ontents o' se$e#t are E111EB PI,T.R attri+ute & some spe#ia$ #)ara#ters " 8aria+$es *)i#) are to )o$d +ot) t1pes o' data must +e de#$ared using pi#ture attri+ute or pi#( " A indi#ates numeri#/ V indi#ates de#ima$ point( " pi#ture edit #)ara#ters must +e en#$osed in Cuotation marDs( " minus and de#ima$ point use storage spa#es( i' t)e num+er is non3negati8e/ it is rep$a#ed +1 a +$anD( " e(g( 23 -,L num+er PI, ESAAAV(AAE num+er > 1%0(H;6 " in storage/ t)e num+er $ooD $iDe K1%0(H; PI,T.R attri+ute & some spe#ia$ #)ara#ters " to edit #)ara#ter strings/ 1ou ma1 use 0 edit #)ara#ters 23

L position ma1 )o$d an1 #)ara#ter( A position ma1 )o$d a$p)a+eti# #)ara#ter or a +$anD( A indi#ates t)at position ma1 )o$d numeri# #)ara#ters or spa#e( " e(g( 23 -,L 'ie$da pi# EAAALAAE6 '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 FIL - - ,4;5 I!IT4:56 -,L tit$e ,GAR4105 I!IT4EJeeD$1 !e*sE56 7amp$es o' some #onstants " E1:111:EB +it string " (%;<0= %: de#ima$ '$oating point num+er " E0H=<%E #)ara#ter string " 1:11:1B +inar1 'i7ed point num+er " 1:0=& de#ima$ 'i7ed point num+er 7pressions IF/ TG ! / LS statement " simp$est i' t)en e$se statement 23 " 'orm 23 IF e7pression TG ! t)en3unit3e7pression6 LS e$se3unit3e7pression6 " e(g( 23 i' a>: t)en #ounter > #ounter K 16 " e(g( 23 i' A M> B t)en A>B6 e$se A>BK1::6 " e(g( 23 -,L s*it#) BIT4156 s*it#) > A6 i' s*it#) t)en goto su+16 IF/ TG !/ LS statement " -O in an IF statement indi#ates start o' a -O group +$o#D(

" !- in an IF statement indi#ates end o' a -O group +$o#D( " e(g( 23 7/ 1 > 16 i' a N + t)en do6 7 > 1::6 1 > ;:6 end6 " e(g( 23 i' a N + t)en # > 1::6 e$se do6 7 > 16 # > O K 1:6 end6 IF/ TG !/ 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$$1 no statement is ne#essar1( " e(g( 23 i' 7 N 1 t)en i' m > n t)en6 e$se O > :6 e$se O > O K 16 OP RATORS " #omparison operators are as 'o$$o*s 23 M $ess t)an PM not $ess t)an N greater t)an PN not greater t)an > eCua$ to P> not eCua$ to M> $ess t)an or eCua$ to N> greater t)an or eCua$ to " Bit string operators are as 'o$$o*s 23 !OT P 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 t1pe o' do group t)ese statements are as a ru$e e7e#uted se8era$ times

<

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 +1 a step ot)er t)an 1/ t)en 1ou use +1 statement( e(g( 23 do #ount > 1 to %: +1 %6 " in do groups 1ou #an a$so #ount do*n*ards( e(g( 23 do i > %; to 1 +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 " % +1 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 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 M 156 " t)is $oop is e7e#uted as $ong as 7 is $ess t)an 1( " e(g( 23 do *)i$e 47 N 15 unti$ 4O > 1::56 ((((( endo6 " t)is $oop runs as $ong as 7 N 1 and O is not eCua$ to 1::(

&

-O group statement " nested -O groups 23 nesting o' do groups to a ma7imum o' HA is a$$o*ed +1 PL/1 optimiOing #ompi$er( " e(g( 23 outer 2 do i > 1 to ;6 inner 2 do Q > 1 to 06 ((((( end inner6 end outer6 -O group statement " e(g( 23 to $ea8e an iterati8e do group( do i > 1 to 1::6 ((((( i' 7 N 1 t)en $ea8e6 ((((( end6 GOTO statement " *it) goto statement 1ou #an Qump to an1 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 & Arra1s -ata Aggregates " t*o t1pes o' data aggregates are t)ere 23 3 arra1s 3 stru#tures " an arra1 is a #o$$e#tion o' se8era$ e$ements *it) same attri+utes( t)e1 are arranged in a ta+$e or a matri7( " *)en 1ou *ou$d $iDe to put uneCua$ data e$ements toget)er in an aggregate/ 1ou s)ou$d use a stru#ture( -ata Aggregates 4Arra1s5 " e(g( 23 d#$ ta+$e4;:5 'i7ed de#ima$4056

" ta+$e is a one dimensiona$ arra1 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' 1ou *ant to address a sing$e arra1 e$ement( " e(g( 23 d#$ #ount1ta+4;:5 #)ar41:56 d#$ #ount1nm #)ar41:56 #ount1nm > #ount1ta+4%56 " se#ond e$ement o' #ount1ta+ is assigned to #ount1nm( -ata Aggregates 4Arra1s5 " e(g( 23 -,L num+ers4;5 'i7ed de#4056 do i > 1 to ;6 num+ers4i5 > i " %6 end6 " su+s#ripts need not Qust #onsist o' #onstants and 8aria+$es/ t)e1 #an a$so +e *)o$e e7pressions( e(g( 23 #ost4iKQ5 num+ers4iK%5 num+ers4#osts4i55 #osts4iKQ"%5 -ata Aggregates 4Arra1s5 " Bui$t3in 'un#tions 23 333333333333333333 " 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 +1 PL/1 t)ru s1nta7( " e(g( 23 d#$ 4a/+5 'i7ed de#4A56 d#$ 741:5 'i7ed de#4056 d#$ 141%5 'i7ed de#4&56 a > + K sum475 K sum4156 -ata Aggregates 4Arra1s5 " Mu$ti3-imensiona$ Arra1 23 33333333333333333333333 " t)e dimension attri+ute states t)e num+er o' t)e dimensions 'or an arra1 and t)e +ounds o' ea#) dimension( " e(g( 23 d#$ ta+$e4&/%5 'i7ed de#ima$4056

" t)e a+o8e mentioned arra1 #onsists o' & ro*s and % #o$umns( " e(g( 23 d#$ parts40/0/;5 #)ar41:56 " t)e a+o8e de#$ared parts arra1 #onsist o' H; e$ements( -ata Aggregates 4Arra1s5 e(g( 23 d#$ ta+40/;5 'i7ed +inar141;56 do Q > 1 to 06 do D > 1 to ;6 ta+4Q/D5 > %6 end6 end6 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 arra1 is set to %( " a$$ e$ement o' arra1 ta+ #an +e set to % +1 one sing$e instru#tion( @ ta+ > % B( -ata Aggregates 4Arra1s5 " ,ross se#tion o' an arra1 23 1ou #an a$so address a #ross se#tion o' a arra1( " 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%/156 74%5 > 'igures4%/%56 7405 > 'igures4%/056 -ata Aggregates 4Stru#tures5 " Simp$e Stru#tures 23 33333333333333333 " *)en 1ou *ou$d $iDe to put uneCua$ data e$ements toget)er in an aggregate/ 1ou s)ou$d use a stru#ture( " e(g( 23 d#$ 1 personne$/ % name #)ar40:5/ % sa$ar1 '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:

o*n attri+ute( -ata Aggregates 4Stru#tures5 " during pro#essing e$ements #an +e addressed sing$1 or a$$ toget)er using t)e stru#ture name( a sing$e e$ement #an +e addressed +1 itEs name( " 'or e(g( 23 name > EFo)n Mi$$erE6 put 'i$e4out5 $ist4personne$56 put 'i$e4out5 $ist4name/ sa$ar156 " 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$ar1( " ma7imum num+er o' $e8e$s in a stru#ture is 1;( -ata Aggregates 4Stru#tures5 " Arra1s in a Stru#ture & Rua$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' 1ou *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 *a1 +1 *)i#) 1ou #an use non3identi#a$ stru#tures in stru#ture e7pression( t)at is +1 name option( " +1 name is used to maDe assignments 'rom one stru#ture to anot)er/ *)ere+1 #ompi$er pro#esses on$1 t)e e$ements *)ose 'u$$1 Cua$i'ied names in +ot) stru#tures are identi#a$( e(g( 23 d#$ 1 ne*/ d#$ 1 o$d/ % name/ % name/ % address/ % pa1ment/ % pa1ment/ 0 gross/ 0 gross/ 0 net/ 0 net/ 0 dedu#tions6 % dedu#tions6 BY !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

ne* > o$d/ +1 name6 " 0 e$ements are assigned in t)is stru#ture e7pression( ne*(name > o$d(name6 ne*(pa1ment(gross > o$d(pa1ment(gross6 ne*(pa1ment(net > o$d(pa1ment(net6 Introdu#tion to Input/Output Basi# 'eatures o' Input/Output " G T 23 transmits or gets data 'rom e7terna$ medium to interna$ storage( " P.T 23 transmits data 'rom interna$ to e7terna$ storage( " % t1pes o' transmission are t)ere +et*een interna$ & e7terna$ storage 23 stream i/o *it) get & put 23 data item is transmitted sing$1( 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 #op1 o' t)e re#ord is usua$$1 Dept in interna$ storage( it is pre'era+$e 'or $arger Ct1 o' data( Basi# 'eatures o' Input/Output " s1nta7 o' % i/o statements 23 33333333333333333333333333 stream 3N get 'i$e4input5 $ist4a/+/#56 re#ord 3N read 'i$e4input5 into4inarea56 " opening & #$osing o' 'i$es 23 33333333333333333333333333 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)1si#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 t1pe o' organiOation is #onse#uti8e( t)is t1pe o' organiOation #an +e pro#essed on$1 seCuentia$$1(

1%

" 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 t1pe( STR AM Input/Output STR AM I/O Features " a string o' #)ara#ters is transmitted in stream i/o( " #)ara#ter data t1pe *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 LIST56 is taDen as P.T FIL 4SYSPRI!T5 LIST4-ATA LIST56 0 T1pes o' I/O Stream " $ist 3 a$*a1s reCuires data $ist " data 3 reCuires no $ist " edit 3 reCuires data and 'ormat $ist STR AM I/O Features " List3-ire#ted I/O 23 33333333333333333 it is simp$est 'orm o' stream I/O/ and is idea$ 'or testing input at t)e termina$( " e(g( 23 get $ist4#1/#%/#056 put $ist4gross/net/gross3net56 " e(g( 23 d#$ temps4&/%5 'i7ed de#ima$4056 ((((( get $ist4temps56 1H e$ements *ou$d +e read +1 t)e get statement( " input in $ist dire#ted i/o is in #)ara#ter 'orm( t)e data items are separated +1 #omma and/or +$anDs( STR AM 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

or t)e end o' data 'i$e ends t)e transmission o' an i/o statement( " e(g( 23 A>%/ B>ELYE6 333333N get data4a/+56 A>;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( STR AM I/O Features " dit3-ire#ted I/O 23 33333333333333333 " it is t)e most #ommon$1 used t1pe o' stream i/o( a data $ist is needed )ere as *e$$/ to #ontain t)e names o' data items/ arra1s 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'ormat56 get 'i$e4s1sin5 edit4data $ist5 4'ormat56 " e(g( 23 get edit4Ct1/ pri#e/ te7t5 4"405/74<5/"4;/%5/74;5/a41:556 " is used 'or numeri# data item/ A 'or #)ara#ter string/ L 'or spa#e( PAG & SIIP in -IT -ire#ted I/O " 'or preparation o' numeri#a$ data t)e 'ormat item P #an +e used *it) a$$ pi#ture spe#i'i#ation( " e(g( 23 d#$ no 'i7ed de#4;5/ order 'i7ed de#4&/%5/ te7t #)ar4%:56 put PAG edit4ERe8ision ListE5 4A56 put SIIP4%5 edit4no/order/te7t5 4"4;5/ 74%5/ PE4H5SAV(AA3E/ 74%5/ a56 " a'ter ad8an#ing to ne7t page/ a tit$e is printed( t)en t*o $ines are sDipped and t)e t)ree 8aria+$es are printed *it) % spa#es in +et*een( resu$t is ''''' ppppp(pp aaaaaaaaaaaaaaaaaaaa LI! SIS & PAG SIS in -IT3-ire#ted I/O " print is a 'i$e attri+ute *)i#) #an +e used in #onne#tion *it) stream output( " some options *)i#) #an +e stated in open statement are 23

1H

option meaning de'au$t 333333 3333333 3333333 $inesiOe4nn5 $ine $engt) 1%: #)ars per $ine pagesiOe4nn5 page $engt) <: $ines per page " e(g( 23 open 'i$e4$ist5 output stream print $inesiOe41::5 pagesiOe4;:56 O! !-PAG #ondition " i' t)e option PAG SIS 4<:5 is in 'or#e and <: $ines )a8e a$read1 +een printed t)en t)e on endpage #ondition is raised +e'ore printing t)e <1st $ine and t)e #ontro$ passes to t)e most re#ent$1 e7e#uted on endpage statement( " on endpage4s1sprint5 +egin6 n > n K 16 put edit4EPG3!OE/ n5 4page/ L411:5/ A/ PESSAE56 2222 2 2 2print !Ts 8a$ue 2 2 print #)ar string sDip a page 2 EPG3!OE $ea8e 11: +$anD spa#es " #urrent page num+er is printed on t)e 'irst $ine( O! RROR #ondition " O! RROR #ondition 23 333333333333333333 P.T statements *it)out data $ist/ *rite out a$$ t)e 8aria+$es o' a program +$o#D( t)e1 gi8e programmers an e7#e$$ent too$ to use in sear#)ing 'or too$s( " e(g( 23 on error +egin6 on error s1stem6 put data6 goto e7it6 end6 " t)e on error #ondition must a$so )a8e +een run t)ru at$east on#e +e'ore it #an +e e7e#uted( " on error s1stem means t)at in #ase o' an error/ t)e s1stem routine is e7e#uted t)at in#$udes +reaDing o'' t)e program e7e#ution( Re#ord Input/Output O8er8ie* & -i''eren#es +et*een STR AM & R ,OR- I/O " in re#ord i/o/ t)e data in a data set is #onsidered as a #o$$e#tion o' re#ord( in stream i/o/ data is #onsidered as a #ontinuous seCuen#e(

1;

" re#ord i/o transmits re#ords Qust as t)e1 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 organiOation( stream i/o a$$o*s on$1 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 +1 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* man1 $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)e area to a +u''er( i' re#ord 4or +$o#D5 is 'u$$/ a p)1si#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)e re#ords are put in +$o#Ds( R ,OR- I/O Features " de#$aration and opening o' 'i$e 23 3333333333333333333333333333333 " e(g( 23 d#$ pers 'i$e input seCuentia$ +u''ered en84#onse#uti8e FB R ,SIS 41::5 BLISIS 4;::5 B.FF RS40556

1<

FB means 'i7ed re#ord $engt)/ +$o#Ded R ,SIS means $engt) o' t)e re#ord in +1tes BLISIS means $engt) o' t)e +$o#D in +1tes B.FF RS 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)1si#a$ properties o' a data set( #onse#uti8e means t)at re#ords are stored seCuentia$$1(
LOCATE mode In t)is mode t)e $ogi#a$ re#ords are dire#t$1 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)1si#a$ re#ord )as a$read1 +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 +1tes5 *)i#) #ontains a storage address( t)is address #an +e assigned to pointer 8aria+$e in 8arious *a1s(

e(g( 23 d#$ 71O pointer6 read 'i$e4input5 set471O56 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(

BA E! 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&

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 F d#$ one 'i$e input seCuentia$ +u''ered en84'+ re#siOe4%::5 +$DsiOe41:::5 +u''ers41556 d#$ C pointer6 d#$ re#ord9a #)ar4%::5 +ased4C56 ((((( read 'i$e4one5 set4C56 On <t) read/ t)e %nd p)1si#a$ re#ord is retrie8ed 'rom t)e data set and put in +u''er( 1ou re#ogniOe MOV mode +1 t)e option FROM and LO,AT mode +1 t)e option S T(

Record Output in Locate mode Records read in are $ritten out #orm :- LO,AT +ased98aria+$e FIL 4'i$ename56 e(g( 23 d#$ in 'i$e re#ord +u''ered input en84'+ re#siOe41::5 +$DsiOe41:::5 +u''ers4%556 d#$ out 'i$e re#ord +u''ered output en84'+ re#siOe41::5 +$DsiOe41:::5 +u''ers4%556 d#$ inre# #)ar41::5 +ased4C56 d#$ outre# #)ar41::5 +ased4p56 $oop 2 read 'i$e4in5 set4C56 $o#ate outre# 'i$e4out56 outre# > inre#6 goto $oop6

Re$riting o# a #ile in %OVE and LOCATE mode Jit) R JRIT statement/ re#ords read in #an +e #)anged and *ritten +a#D to t)e same p$a#e t)e1 #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=

read 'i$e4personne$5 set4p56 ((((((( #)ange re#ord read in ((((( ((((((( re*rite 'i$e4personne$56 Variable lengt& record I' Cuantit1 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 +1te re#ord $engt) 'ie$d 4RL5+e'ore e8er1 8aria+$e re#ord( T)ere is a H +1te +$o#D $engt) 'ie$d +e'ore e8er1 +$o#D( e(g( 23 suppose t)e +iggest $ogi#a$ re#ord #an +e 1::: +1tes $ong and t)at t)e re#ords are to +e +$o#Ded in su#) a *a1 t)at a +$o#D is $iDe*ise to )a8e t)e ma7imum $engt) o' 1::: +1tes/ t)en en8ironment attri+ute o' 'i$e de#$aration *ou$d $ooD $iDe en848+ re#siOe41::H5 +$DsiOe41::=556 i'e statements are calculated as :re#siOe > 1::: +1tes K H +1tes re#ord $engt) +$DsiOe > re#siOe K H +1tes +$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) 8ar1 +$o#D $engt) is siOe o' t)e p)1si#a$ re#ord re#ord $engt) is siOe o' t)e $ogi#a$ re#ord I' data $engt) o' t)e re#ord is &;:/ t)e re#ord siOe *i$$ +e &;H and t)e +$o#D siOe *i$$ +e &;=( CALAR VAR(IN) option I' 1ou are using re#ord i/o *it) 8aria+$e $engt) strings and $o#ate mode/ t)en s#a$ar 8ar1ing option must +e stated in en8 attri+ute 'or i/o/ so t)at t)e % +1te $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#siOe41:<5 +$DsiOe411:5 s#a$ar8ar1ing +u''ers41556 d#$ outre# #)ar41::5 8ar1ing6

Handling VSAM Files V A% data sets 0 T1pes o' VSAM data sets are t)ere 23

1A

1( Ie1 SeCuen#ed -ata Set 4IS-S5 %( ntr1 SeCuen#ed -ata Set 4 S-S5 0( Re$ati8e Re#ord -ata Set 4RR-S5 Note :- SeCuentia$ is t)e de'au$t 'i$e organiOation/ )en#e 8sam s)ou$d +e spe#i'ied in t)e !V option( Vsam 'i$es are a$*a1s re#ord 'i$es( Re#ords on a 8sam 'i$e are not )e$d in +$o#Ds/ )en#e t)e +$DsiOe option e8en i' spe#i'ied is ignored( A re#siOe option *i$$ +e #)e#Ded against t)e detai$s stored *it) t)e 'i$e( T)e uti$it1 I-,AMS 4a##ess met)od ser8i#es5 is used to set up a 8sam 'i$e initia$$1(

Various !CL #or V A% datasets e(g( 23 d#$ 8'i$e re#ord dire#t De1ed input en848sam56 Vsam 'i$es are a$$ dire#t a##ess 'i$es( asso#iated *it) e8er1 re#ord is a De1/ *)i#) )e$ps in a##essing t)e re#ord in an1 order( e(g( 23 d#$ 8'i$e 'i$e re#ord seCuentia$ input en848sam56 I' 1ou *ant to start at t)e +eginning and pro#ess e8er1 re#ord/ Qust as *it) a #onse#uti8e 'i$e/ spe#i'1 t)e 'i$e as seCuentia$( e(g( 23 d#$ 8'i$e 'i$e re#ord seCuentia$ De1ed input en848sam56 T)e 'irst read o' t)e program spe#i'ies t)e De1 o' t)e re#ord 1ou *ant to start at su+seCuent seCuentia$ read statements are issued *it)out a De1( e(g( 23 d#$ in'i$e 'i$e re#ord dire#t De1ed input en848sam56 to read a 8sam 'i$e dire#t$1( e(g( 23 d#$ in'i$e 'i$e re#ord dire#t update en848sam pass*ord4EmasterE556 J)en a 'i$e is origina$$1 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 -* ! . IS-S is used to )o$d master 'i$e data( identi'i#ation is +1 means o' De1 so t)e attri+ute -IR ,T imp$ies I 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 De1 *)i#) is part o' a data re#ord/ t)is is Dno*n as an em+edded De1(

%:

Ie1s are a$so stored in anot)er part o' data set #a$$ed as prime inde7( T)e De1s are uniCue sin#e dup$i#ation is not a$$o*ed( * ! /eatures Reading a 0sds directl+ :- Re#ords are a##essed +1 spe#i'1ing a 8a$ue using t)e De1 option(

e(g(23 d#$ a$most 'i$e re#ord dire#t input en848sam56 d#$ 1 area/ % DsDe1 #)ar4;5/ % Dsname #)ar41;56 read 'i$e4amast5 into4area5 De14E:::1:E56

1pdating a 0sds directl+ :- T)e 'i$e s)ou$d +e opened as update( 1ou #annot amend t)e De1( e(g(2 d#$ Dmast 'i$e re#ord dire#t update en848sam56 d#$ 1 area/ % DsDe1 #)ar4;5 init4E:::=1E5/ % Dsname #)ar41;56 read 'i$e4Dmast5 into4area5 De14DsDe156 /" amend "/ re*rite 'i$e4Dmast5 'rom4area5 De14DsDe156 !elete a record in 0sds :- :- :- .se de$ete statement( e(g( 23 DsDe1 > E:::;<E6 de$ete 'i$e4Dsds5 De14DsDe156 Add a record in 0sds :- :- :- .se *rite statement( e(g( 23 DsDe1 > E:::%HE6 Dsname > EApp$etsE6 *rite 'i$e4Dsds5 'rom4area5 De1'rom4DsDe156 /irst direct access 2 t&en se,uential access :e(g(2 d#$ ramp 'i$e re#ord seCuentia$ De1ed en848sam56 read 'i$e4ramp5 into4area5 De14E1%0/AAA/+E56 read 'i$e4ramp5 into4area56 GENKEY option e(g( 23 d#$ 8sam 'i$e re#ord seCuentia$ De1ed en848sam genDe156 read 'i$e48mast5 into4area5 De14E1%0E56 read 'i$e48mast5 into4area56 Assume t)at t)e De1 is de'ined as nine #)ars $ong(

%1

I' genDe1 option is not spe#i'ied in t)e en8ironment statement/ 8sam sear#)es 'or a re#ord *it) a De1 o' U1%0U( I' genDe1 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$1 'o$$o*ing it(

ENTRY Sequenced Data Set (ESDS) It is t)e most $iDe$1 #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$read1 )as data on it/ ma1 on$1 +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)e1 )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$*a1s added at t)e end( -e$ete is not a$$o*ed(

Ke ed access to an ESDS !ile An esds is a seCuentia$ 'i$e and )as no de'ined De1( T)e in'ormation t)at #an +e used 'or De1ed a##ess is #a$$ed re$ati8e +1te address 4r+a5(

re#ord31 2 re#ord3% 2 re#ord30 2 re#ord3H 2 2 2 ;: +1tes 2 H: +1tes 2 <: +1tes 2 0: +1tes 2 2 2 r+a>: r+a>;: r+a>A: r+a>1;: You )a8e to get )o$d o' r+a +1 using I YTO option on read and *rite(

e(g( 23 d#$ esds 'i$e re#ord seCuentia$ De1ed update en848sam56

%%

d#$ r+a #)ar4H56 (((((( *rite 'i$e4esds5 'rom4area5 De1to4r+a56 R+a must +e a H +1te #)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 +1te address o' t)e re#ord in t)e 'ie$d r+a( t)is is t)en used as a De1 on a read or re*rite( 'i$e s)ou$d +e de#$ared as De1ed(

e(g( 23 read 'i$e4esds5 into4area5 De14r+a56 e(g( 23 /" e7amp$e o' esds read and re*rite "/ d#$ esds 'i$e re#ord seCuentia$ De1ed update en848sam56 d#$ r+a #)ar4H56 read 'i$e4esds5 into4area5 De1to4r+a56 (((((( re*rite 'i$e4esds5 'rom4area5 De14r+a56 RE"AT#VE Reco$d Data Set (RRDS) Re#ords are read and #an +e a##essed seCuentia$$1 or dire#t$1 *it) or *it)out De1s( T)e data set ma1 +e t)oug)t o' as a set o' num+ered s$ots ea#) o' *)i#) ma1 )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 De1 to t)e 'i$e( T)e De1 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 ma1 +e de#$ared as seCuentia$ or dire#t( I' t)e 'i$e is de#$ared as De1ed seCuentia$ a$$ De1 options #an +e used( i' 1ou $ea8e De1 re'eren#e/ pro#essing *ou$d +e Qust 'or a seCuentia$ 'i$e( e(g23 d#$ rrds 'i$e re#ord seCuentia$ De1ed update en848sam56 d#$ rrDe1 #)ar4=56 rrDe1 > 4E::::::%;E56 read 'i$e4rrds5 into4area5 De14rrDe156 /" read re$(re#(no %; "/ (((((( re*rite 'i$e4rrds5 'rom4area56 /" re#(no %; is re*ritten "/ (((((( read 'i$e4rrds5 into4area5 De1to4rrDe156 /" reCuests a "/ /" re#ord num+er( "/

%0

/" t)e ne7t re#ord *i$$ "/ /" +e presented and t)e "/ /" De1 8a$ue *i$$ +e "/ /" p$a#ed in rrDe1 "/ 3RITE in an RR! e(g( 23 /" assume re#ord ; e7ists on 'i$e rrds( "/ d#$ rrds 'i$e re#ord seCuentia$ De1ed update en848sam56 d#$ re$re#no #)ar4=56 d#$ 1 area/ % (((((( 6 re$re#no > E:::::::;E6 read 'i$e4rrds5 into4area5 De14re$re#no56 (((((( de$ete 'i$e4rrds5 De14re$re#no56 (((((( *rite 'i$e4rrds5 'rom4area5 De1'rom4re$re#no56 %$ocessing o! St$ing Data 1B TR -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!T R!ATIO!AL B.SI! SS MA,GI! SE6 'ie$d>su+str4data/</=56 Fie$d *i$$ +e E!ATIO!ALE In S.BSTR parameter % and 0 #an +e e7pression/ resu$ting to +e an integer( note :- i' t)e parameters represent a 8a$ue *)i#) $ies outside t)e string t)e resu$t is unpredi#ta+$e(

IN!E4 -Built-in /unction. Inde7 'un#tion is used to $ooD 'or a #ertain #)ara#ter or a string o' #)ars in a gi8en string(

%H

#orm :- pos( > inde74string/ sear#) string56 Inde7 'un#tion returns a +inar1 num+er 41;/:5( I' string to +e $ooDed 'or is not 'ound/ t)e return 8a$ue is Oero( on$1 'irst o##uren#e is s)o*n(

e(g( 23 d#$ to*n9#ountr1 #)ar4%;56 (((((( to*n9#ountr1 > EJ YBRI-G /S.RV YE6 i#omma>inde74to*n9#ountr1/E/E56 i#omma *i$$ +e 1:( e(g( 23 d#$ 4string/part15 #)ar40:56 (((((( ipos > inde74string/E/E56 part1 > su+str4string/1/ipos3156 VERI/( -Built-in /unction. VERI/( #unction :- Veri'1 *i$$ see t)at a string *i$$ )a8e on$1 #ertain #)ara#ters present( #orm :- 8eri'147/ 156 ELE 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 Oero/ i' a$$ #)ara#ters in ELE appear a$so in EYE( 3 A 8a$ue/ *)i#) gi8es t)e position o' t)e 'irst #)ara#ter in ELE *)i#) does not appear in EYE( e(g( 23 d#$ test #)ar4056 test>EBITE6 IL>8eri'14test/EAB,- -FGGIE56 0 *ou$d +e returned/ +e#ause t)e t)ird #)ara#ter is not in t)e se#ond parameter o' 8eri'1(

TRAN LATE -Built-in /unction. #orm :- trans$ate47/ 1/ O5 ELE > #)ara#ter string to +e #)e#Ded EYE > string o' rep$a#ement #)ara#ter ESE > #)ars in ELE *)i#) are to +e rep$a#ed i' 'ound resu$t is modi'ied #)ara#ter string ELE( e(g( 23 d#$ 4o$d/ ne*5 #)ar41:56 d#$ i#)ara#ter #)ar41:5 init4EFIRT.LE56 d#$ t#)ara#ter #)ar41:5 init4EA!.IRTE56

%;

(((((( o$d > EFILT.R SE6 ne* > trans$ate4o$d/t#)ara#ter/i#)ara#ter56 ne* > trans$ate4EFILT.R SE/EA!.IRTE/EFIRT.LE56 > A!TIR. S LEN)T5 -Built-in /unction. T)is determines t)e $engt) o' t)e string( 8a$ue returned is +inar1 'i7ed point num+er 41;/:5( #orm :- $engt)4756

e(g( 23 d#$ 'ie$d #)ar4A:5 8ar1ing6 'ie$d > EGOO- L.,I VE6 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/ 1ou )a8e a pseudo8aria+$e( pseudo8aria+$es are 'un#tions *)i#) ma1 not on$1 manipu$ate 8a$ues/ +ut ma1 a$so re#ei8e t)em(

e(g( 23 su+str4t'ie$d/%/;5 > g'ie$d6 e(g( 23 d#$ 7 #)ar41:56 7 > EAB,- FGGIFE6 su+str47/</;5 > su+str47/1/;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

%<

An LT R!AL pro#edure is a +$o#D *)i#) is not #ontained in anot)er +$o#D( T)e1 are #ompi$ed separate$1 +ut t)e1 #an Qoined to maDe one program +1 $inDage editor/ so t)at % programmers #an *orD on it simu$taneous$1( Option main identi'ies t)e main pro#edure( i(e(/ $a+e$2pro# options4main56 An I!T R!AL pro#edure is in8oDed +1 a #a$$ 'rom a surrounding +$o#D and #ontro$ returns to statement a'ter t)e #a$$( Jit)in an e7terna$ pro#edure 1ou #an )a8e upto ;: interna$ pro#edures(

e(g( 23 outer2pro# options4main56 statement1 #a$$ inner6 33333333 3333333333N statement% 2 2 W inner2pro#6 M3333333 2 2 statement0 2 2 statementH V 3333333 end inner6 3333333333N statement; statement< end outer6 BE)IN-bloc0 :- T)e1 a$*a1s $ie *it)in a pro#edure and are e7e#uted *)ere t)e1 are( T)e1 'inis) *it) an end statement(

#orm :- A2pro#6 (((((( +egin6 (((((( (((((( end6 (((((( end A6 cope o# !eclaration Variables $&ic& are declared &a8e t$o scope attributes :1( Interna$ %( 7terna$ I' a 8aria+$e )as an I!T R!AL s#ope/ t)en it is Dno*n in t)e +$o#D in *)i#) it *as de#$ared and in a$$ t)e +$o#Ds *)i#) p)1si#a$$1 $ie in t)at +$o#D unti$ it is not de#$ared in one o' t)ese su+ordinate +$o#Ds(

%&

e(g( 23 outer2pro# options4main56 d#$ rate 'i7ed de#4&/056 d#$ minus #)ar4;56 d#$ 7 #)ar41::56 (((((( inner2pro#6 d#$ minus 'i7ed de#4&/%56 d#$ 7 #)ar41::56 end inner6 end outer6 rate 'ie$d is addressed in +ot) +$o#Ds( #)ara#ter 'ie$d minus is not Dno*n in +$o#D inner( T)e 8aria+$e ELE )as attri+ute interna$ and )en#e 1ou are dea$ing *it) % 8aria+$es t)at are Dno*n *it)in t)eir +$o#Ds( I' a 8aria+$e is to +e same in t*o e7terna$ pro#edures/ t)en it must +e de#$ared *it) same attri+utes LT R!AL(

mpro2pro# options4main56 d#$ 1 re# e7terna$/ % a #)ar40:5/ % + 'i7ed +in40156

su+pro2pro#6 d#$ 1 re# e7terna$/ % a #)ar40:5/ % + 'i7ed +in40156

Stru#ture re# *)i#) is de#$ared in +ot) e7terna$ pro#edures/ o##upies t)e same data area(

torage Class in a Variable .sing storage #$ass attri+utes/ t)e programmer de'ines/ *)en storage spa#e is to +e a$$o#ated to a 8aria+$e and *)en t)is storage spa#e is 'reed( T&ere are 9 di##erent storage class :1( %( 0( H( A1TO%ATIC torage Class An automati# 8aria+$e )as interna$ attri+ute( Storage is a$$o#ated *)en +$o#D #ontaining storage de#$aration is a#ti8ated and is 'reed again *)en t)e +$o#D is terminated( Automati# 4de'au$t5 Stati# Based ,ontro$$ed

e(g( 23 72pro# options4main56

%=

(((((( +egin6 M3333333333333333333333333 (((((( 2 d#$ ta+41::/1::/1:/%5 #)ar4%;56 2 a#ti8ated (((((( 2 end6 M3333333333333333333333333 'reed (((((( end 76 TATIC torage Class Stati# 8aria+$e )as e7terna$ attri+ute( Storage is a$$o#ated +e'ore t)e e7e#ution o' t)e program and remains a$$o#ated unti$ end o' t)e program( T)is storage #$ass #annot +e in'$uen#ed +1 t)e programmer during program e7e#ution(

e(g( 23 d#$ ta+41:/1:5 'i7ed de#ima$4&/%5 stati#6 d#$ 741:/1:5 'i7ed de#ima$4;/%5 +ased4p56 d#$ 7 #)ar41%:5 stati# e7terna$6 BA E! torage Class Based storage #$ass is used in #onne#tion *it) re#ord i/o( Based 8aria+$e s)ou$d a$*a1s )a8e attri+ute interna$( In $o#ate mode/ it *as ne#essar1 to de#$are t)e storage #$ass +ased 'or re#ord to +e read in / *ritten out(

e(g( 23d#$ in 'i$e re#ord +u''ered input en84'+ re#siOe41::5 +$DsiOe41:::5 +u''ers4%556 d#$ out 'i$e re#ord +u''ered output en84'+ re#siOe41::5 +$DsiOe41:::5 +u''ers4%556 d#$ iarea #)ar41::5 +ased4C56 d#$ oarea #)ar41::5 +ased4p56 d#$ 4C/p5 pointer6 (((((( read 'i$e4in5 set4C56 (((((( $o#ate oarea 'i$e4out56 CONTROLLE! torage Class Jit) #ontro$$ed 8aria+$e t)e programmer )as #omp$ete #ontro$ o8er storage spa#e( .sing ALLO,AT spa#e is assigned and *it) FR t)e storage spa#e is 'reed again( t)e1 #an )a8e t)e attri+utes interna$ or e7terna$(

e(g( 23d#$ 'ie$d7 #)ar41%5 #ontro$$ed6 a$$o#ate 'ie$d76 /" storage spa#e is assigned "/

%A

'ie$d7 > Ea$$ #$ear XE6 put 'i$e4printer5 edit4'ie$d75 474;5/A56 'ree 'ie$d76 /" storage spa#e is 'reed "/ Su'$outines + Functions Su'$outines It is a$*a1s an interna$ or e7terna$ pro#edure( A su+routine is not rep$a#ed +1 a resu$t 8a$ue a'ter its e7e#ution( A su+routine is a$*a1s 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 d#$ ((((((6 (((Y end srou16 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#1/inre#56 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 /" arguments "/ srou%2pro# d#$ ((((((6 (((((( end srou%6

0:

Gere 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 ma1 +e di''erent/ +ut t)e1 use same area( Note :- nu$$ arguments ma1 +e indi#ated +1 t*o #ommas and unne#essar1 arguments o' t)e end o' t)e $ist ma1 +e omitted( %ultiple Entr+ Points Su+routine ma1 )a8e se8era$ entr1 points( 3 primar1 entr1 points #an +e identi'ied +1 PRO,( 3 se#ondar1 entr1 points #an +e identi'ied +1 !TRY statements( a#) entr1 points ma1 )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#47/156 (((((( ent12entr14m56 (((((( ent%2entr147/1/m56 (((((( end prog;6 E"it #rom Procedures !orma$ e7it 'or a pro#edure is !-( Furt)ur e7it #an +e pro8ided using R T.R!( e(g( 23 srou2pro#47/156 (((((( ent%2entr14m/n/o56 (((((( i' 7 > : t)en return6 (((((( end srou6 /unctions Fun#tions are a$*a1s a part o' an e7pression( A 'un#tion is rep$a#ed +1 its resu$t a'ter e7e#ution( e(g( 23 /" +ui$t3in 'un#tions "/ 7 > sum4ta+056 /" *it) an argument "/

01

adds up a$$ e$ements o' arra1 ta+( 8 > date456 /" *it) empt1 arguments "/ A 'un#tion #a$$ is rep$a#ed +1 8a$ue returned( e(g( 23 #a$#2pro#4a/+/#56 (((((( i' 7 N 1 t)en return47"156 e$se return4O56 (((((( end #a$#6 -ON-1NIT. On !-PAG and on !-FIL are some important #onditions *)i#) #an +e 'orseen( e(g( 23 on endpage4s1sprint5 +egin6 n > n K 16 put edit4EpageE/ n5 4page/ 74&:5/ a/ pEOAE56 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$$1( T)e program #ontinues *it) t)e statement *)i#) #omes immediate$1 a'ter signa$ statement( #orm :- SIG!AL #ondition6 Signa$ is used to raise #onditions de$i+erate$1( 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 "/

0%

Vous aimerez peut-être aussi