Sunteți pe pagina 1din 41

Mainframe Refresher Part-1 COBOL-Page: 1

COBOL (COmmon Business Oriented Language)


History.
Developed by 1959 by a group called COnerence on Data !ystems Language
(COD"!#L). $irst COBOL compiler %as released by December 1959.
$irst "&!' approved version ( 19)*
+odiied "&!' approved version ( 19,- (O!./! COBOL)
+odiied "&!' approved version ( 19*5 (/! COBOL 0)
12is boo3 is %ritten based on 'B+ COBOL or O!.495 /060.
!peciality.
1. $irst language developed or commercial application development7 %2ic2 can
eiciently 2andle millions o data.
0. 8rocedure Oriented Language 9 8roblem is segmented into several tas3s.
:ac2 tas3 is %ritten as a 8aragrap2 in 8rocedure Division and e;ecuted in a
logical se<uence as mentioned.
4. :nglis2 Li3e language ( :asy to learn7 code and maintain.
Coding !2eet.
1 , 10 ,0 *5
COL9" COL=+&9B
19) 8age.line numbers ( Optional (automatically assigned by compiler)
, Continuity (9)7 Comment (>)7 !tarting a ne% page (.)
Debugging lines (D)
*911 Column " (Division7 !ection7 8aragrap27 517,, declarations must begin 2ere.
10.,0 Column B ("ll t2e ot2er declarations.statements begin 2ere.
,49*5 'dentiication ield. 't %ill be ignored by t2e compiler but visible in t2e source
listing.
Language !tructure.
C2aracter Digits (599)7 "lp2abets ("9?)7 !pace (b)7
!pecial C2aracters (@ 9 > . ( ) A B C D E F . 7)
Gord One or more c2aracters9 =ser deined or 6eserved
Clause One or more %ords. 't speciies an attribute or an entry
!tatement One or more valid %ords and clauses
!entence One or more statements terminated by a period
8aragrap2 One or more sentences.
!ection One or more paragrap2s.
Division One or more sections or paragrap2s
8rogram +ade up o our divisions
Mainframe Refresher Part-1 COBOL-Page: 2
Divisions in COBOL.
12ere are our divisions in a COBOL program and Data division is optional.
1.'dentiication Division.
0.:nvironment Division.
4.Data Division.
-.8rocedure Division.
'dentiication Division.
12is is t2e irst division and t2e program is identiied 2ere. 8aragrap2
86OH6"+9'D ollo%ed by user9deined name is mandatory. "ll ot2er paragrap2s are
optional and used or documentation. 12e lengt2 o user9deined name or 'B+
COBOL is :'HH1.
'D:&1'$'C"1'O& D'/'!'O&.
86OH6"+9'D. 86OH6"+ &"+:.
"=1HO6. CO++:&1 :&16#.
'&!1"LL"1'O&. CO++:&1 :&16#.
D"1:9G6'11:&. CO++:&1 :&16#.
D"1:9CO+8'L:D. CO++:&1 :&16#.
!:C=6'1#. CO++:&1 :&16#.
!ecurity does not pertain to t2e operating system security7 but t2e
inormation t2at is passed to t2e user o t2e program about t2e security eatures o
t2e program.
:nvironment Division.
Only mac2ine dependant division o COBOL program. 't supplies inormation
about t2e 2ard%are or computer e<uipment to be used on t2e program. G2en your
program moves rom one computer to anot2er computer7 t2e only section t2at may
need to be c2anged is :&/'6O&+:&1 division.
Coniguration !ection.
't supplies inormation concerning t2e computer on %2ic2 t2e program %ill be
compiled (!O=6C:9CO+8=1:6) and e;ecuted (OBI:C19CO+8=1:6). 't consists o
t2ree paragrap2s ( !O=6C: CO+8=1:67 OBI:C19CO+8=1:6 and !8:C'"L9&"+:!.
12is is O81'O&"L section rom COBOL *5.
!O=6C:9CO+8=1:6. 'B+9-4*1 (Computer and model J supplied by manuacturer)
G'1H D:B=HH'&H +OD: clause speciies t2at t2e debugging lines
in t2e program (statements coded %it2 KDL in column ,) are compiled.
OBI:C19CO+8=1:6. 'B+9-4*1 (=sually same as source computer)
!8:C'"L9&"+:!. 12is paragrap2 is used to relate 2ard%are names to user9speciied
mnemonic names.
1. !ubstitute c2aracter or currency sign. (C=66:&C# !'H& '! litearal91)
0. Comma can be used as decimal point. (D:C'+"L98O'&1 '! CO++")
4. Deault collating se<uence can be c2anged. 't %ill be e;plained later.
-. &e% class can be deined using CL"!! 3ey%ord. (CL"!! DIGIT is D5M t2ru D9M)

Mainframe Refresher Part-1 COBOL-Page: 3
'nput9Output !ection.
't contains inormation regarding t2e iles to be used in t2e program and
it consists o t%o paragrap2s $'L:9CO&16OL N '9O CO&16OL.
$'L: CO&16OL. $iles used in t2e program are identiied in t2is paragrap2.
'9O CO&16OL. 't speciies %2en c2ec3 points to be ta3en and storage areas t2at are
s2ared by dierent iles.
Data Division.
Data division is used to deine t2e data t2at need to be accessed by t2e
program. 't 2as t2ree sections.
$'L: !:C1'O& describes t2e record structure o t2e iles.
GO6O'&H9!1O6"H: !:C1'O& is used to or deine intermediate variables.
L'&O"H: !:C1'O& is used to access t2e e;ternal data.
:;P Data passed rom ot2er programs or rom
8"6+ o ICL.
Literals7 Constants7 'dentiier7
1. Literal is a constant and it can be numeric or non9numeric.
0. &umeric literal can 2old 1* digits and non9numeric literal can 2old 1)5 c2aracters
in it. (COBOL,- supports 105 c2aracters only)
4. Literal stored in a named memory location is called as variable or identiier.
-. $igurative Constant is a COBOL reserved %ord representing re<uently used
constants. 12ey are ?:6O.?:6O!.?:6O:!7 Q=O1:.Q=O1:!7 !8"C:.!8"C:!7
"LL7 H'HH9/"L=:.H'HH9/"L=:!7 LOG9/"L=:.LOG9/"L=:!.
:;ampleP 51 G!9/"61 8'C R(5-) /"L=: K+=!"L.
K+=!" K is a non9numeric literal. G!9/"61 is a identiier or variable.
Declaration o variable

LevelJ B /ariable B 8icture clause B /alue clause B =sage Clause B !ync clause.
$'LL:6
LevelJ
't speciies t2e 2ierarc2y o data %it2in a record. 't can ta3e a value rom t2e
set o integers bet%een 519-9 or rom one o t2e special level9numbers )) ,, **
51 level. !peciies t2e record itsel. 't may be eit2er a group item or an
:lementary item. 't must begin in "rea ".
509-9 levels. !peciy group or elementary items %it2in a record. Hroup level items
must not 2ave picture clause.
)) level. 'dentiy t2e items t2at contain t2e 6:&"+:! clause.
,, level. 'dentiy independent data item.
** level. Condition names.
/ariable name and Qualiier
/ariable name can 2ave 1945 c2aracters %it2 at least one alp2abet in it.
Hyp2en is t2e only allo%ed special c2aracter but it cannot be irst or last letter o t2e
name. &ame s2ould be uni<ue %it2in t2e record. ' t%o variables %it2 same name
are t2ere7 t2en use O$ <ualiier o 2ig2 level grouping to reer a variable uni<uely.
:;P +O/: balance OF record91 1O balance OF record90.
Mainframe Refresher Part-1 COBOL-Page: 4
$'LL:6
G2en t2e program is not intended to use selected ields in a record structure7
deine t2em as $'LL:6. $'LL:6 items cannot be initialiSed or used in any operation o
t2e procedure division.
8'C1=6: Clause
Describes t2e attributes o variable.
&umeric 9 (Digit)7 / ('mplied decimal point)7 ! (!ign)
&umeric :dited @ (8lus !ign)7 9 (+inus !ign)7 C6 DB (Credit Debit !ign)
. (8eriod)7 b (Blan3)7 K7L(comma)7 5 (?ero)7 . (!las2)
BL"&O GH:& ?:6O ('nsert blan3 %2en data value is 5)7
? (?:6O suppression)7 > ("!1:6'!O)7 B(Currency !ign)
&on &umeric " (alp2abet)7 B (Blan3 insertion C2aracter)7 R("lp2a numeric)7
H(DBC!)
:;clusive sets 1. @ 9 C6 DB
0. / K.L
4. B @ 9 ? > (But B Can appear as irst place and > as
loating. B>>>.>>)
DBC! (Double Byte C2aracter !et) is used in t2e applications t2at support large
c2aracter sets. 1) bits are used or one c2aracter. :;P Iapanese language
applications.
6eres2ing Basics
&ibble. - Bits is one nibble. 'n pac3ed decimal7 eac2 nibble stores one digit.
Byte. * Bits is one byte. By deault7 every c2aracter is stored in one byte.
Hal %ord. 1) bits or 0 bytes is one 2al %ord. (+/!)
$ull %ord. 40 bits or - bytes is one ull %ord. (+/!)
Double %ord. )- bits or * bytes is one double %ord. (+/!)
=sage Clause
D'!8L"# Deault. &umber o bytes re<uired e<uals to t2e siSe o t2e data item.
CO+8 Binary representation o data item.
8'C clause can contain ! and 9 only.
!9(51) ( !9(5-) Hal %ord.
!9(55) ( !9(59) $ull %ord.
!9(15) 9 !9(1*) Double %ord.
+ost signiicant bit is O& i t2e number is negative.
CO+891 !ingle %ord loating point item. 8'C Clause s2ould not be speciied.
CO+890 Double %ord loating9point item. 8'C Clause s2ould not be speciied.
CO+894 8ac3ed Decimal representation. 1%o digits are stored in eac2 byte.
Last nibble is or sign. ($ or unsigned positive7 C or signed positive
and D or signed negative)
$ormula or BytesP 'nteger ((n.0) @ 1)) AE n is number o 9s.
'&D:R 't is used or preserve t2e inde; value o an array. 8'C Clause s2ould
not be speciied.
Mainframe Refresher Part-1 COBOL-Page: 5

/"L=: Clause
't is used or initialiSing data items in t2e %or3ing storage section. /alue o
item must not e;ceed picture siSe. 't cannot be speciied or t2e items %2ose siSe is
variable.
!ynta;P /"L=: '! literal.
/"L=:! "6: literal91 1H6= T 1H6O=HH literal90
/"L=:! "6: literal917 literal90
Literal can be numeric %it2out <uotes O6 non9numeric %it2in <uotes O6 igurative
constant.
!'H& Clause
!ynta; !'H& '! (L:"D'&H) !:8"6"1: CH"6"C1:6 (16"'L'&H).
't is applicable %2en t2e picture string contain K!L. Deault is 16"'L'&H G'1H &O
!:8"6"1: CH"6"C1:6. !o K!L doesnLt ta3e any space. 't is stored along %it2 last
digit.
@1A" @0AB @4AC @-AD @5A: @)A$ @,AH @*AH @9A'
95AU7 91A I7 90A O7 94AL7 9-A+7 95A&7 9)AO7 9,A87 9*AQ7 99A6
&umber 16"'L'&H !'H&
(Deault)
L:"D'&H !'H& L:"D'&H
!:8"6"1:.
9105 10& I05 9105
@105 10: "05 @105
!#&C Clause and !lac3 Bytes
!#&C clause is speciied %it2 CO+87 CO+891 and CO+890 items. 12ese items
are e;pected to start at 2al.ull.double %ord boundaries or aster address
resolution. !#&C clause does t2is but it may introduce slac3 bytes (unused bytes)
beore t2e binary item.
51 G!91:!1.
15 G!9/"61 8'C R(50).
15 G!9/"60 8'C !9()) CO+8 !#&C.
"ssumes G!91:!1 starts at relative location 5 in t2e memory7 G!9/"61
occupies Sero and irst byte. G!9/"60 is e;pected to start at second byte. "s t2e
comp item in t2e e;ample needs one %ord and it is coded %it2 !#&C clause7 it %ill
start only at t2e ne;t %ord boundary t2at is -
t2
byte. !o t2is introduces t%o slac3
bytes bet%een G!9/"61 and G!9/"60.
6:D:$'&:!
12e 6:D:$'&:! clause allo%s you to use dierent data description entries to
describe t2e same computer storage area. 6edeining declaration s2ould immediately
ollo% t2e redeined item and s2ould be done at t2e same level. +ultiple redeinitions
are possible. !iSe o redeined and redeining need not be t2e same.
:;ampleP
51 G!9D"1: 8'C 9(5)).
51 G!96:D:$9D"1: 6:D:$'&:! G!9D"1:.
55 G!9#:"6 8'C 9(50).
55 G!9+O& 8'C 9(50).
Mainframe Refresher Part-1 COBOL-Page: 6
55 G!9D"# 8'C 9(50).
6:&"+:!
't is used or regrouping o elementary data items in a record. 't s2ould be
declared at )) level. 't need not immediately ollo%s t2e data item7 %2ic2 is being
renamed. But all 6:&"+:! entries associated %it2 one logical record must
immediately ollo% t2at recordVs last data description entry. 6:&"+:! cannot be
done or a 517 ,,7 ** or anot2er )) entry.
51 G!96:8!O&!:.
55 G!9CH"61-4 8'C R(54).
55 G!9CH"6- 8'C R(5-).
)) "DD96:8!O&!: 6:&"+:! G!9CH"61-4.
CO&D'1'O& name
't is identiied %it2 special level K**L. " condition name speciies t2e value t2at
a ield can contain and used as abbreviation in condition c2ec3ing.
51 !:R 8'C R.
** +"L: /"L=: K1L
** $:+"L: /"L=: K0L K4L.
'$ !:RA1 can also be coded as '$ +"L: in 8rocedure division.
K!:1 $:+"L: 1O 16=: K moves value 0 to !:R. ' multiple values are coded on
/"L=: clause7 t2e irst value %ill be moved %2en it is set to true.
I=!1'$':D 6'HH1
12is clause can be speciied %it2 alp2anumeric and alp2abetic items or rig2t
Wustiication. 't cannot be used %it2 )) and ** level items.
OCC=6! Clause
OCC=6! Clause is used to allocate p2ysically contiguous memory locations to
store t2e table values and access t2em %it2 subscript or inde;. Detail e;planation is
given in 1able Handling section.
L'&O"H: !:C1'O&
't is used to access t2e data t2at are e;ternal to t2e program. ICL can send
ma;imum 155 c2aracters to a program t2ru 8"6+. Lin3age section +=!1 be coded
%it2 a 2al %ord binary ield7 prior to actual ield. ' lengt2 ield is not coded7 t2e irst
t%o bytes o t2e ield coded in t2e lin3age section %ill be illed %it2 lengt2 and so
t2ere are c2ances o 0 bytes data truncation in t2e actual ield.
51 LO9D"1".
55 LO9L:&H1H 8'C !9(5-) CO+8.
55 LO9/"6'"BL: 8'C R(5*).
L'&O"H: section o sub9programs %ill be e;plained later.
Mainframe Refresher Part-1 COBOL-Page: 7
8rocedure Division.
12is is t2e last division and business logic is coded 2ere. 't 2as user9deined
sections and paragrap2s. !ection name s2ould be uni<ue %it2in t2e program and
paragrap2 name s2ould be uni<ue %it2in t2e section.
8rocedure division statements are broadly classiied into ollo%ing categories.
!tatement 1ype +eaning
'mperative Direct t2e program to ta3e a speciic action.
:;P +O/: "DD :R'1 HO 1O
Conditional Decide t2e trut2 or alse o relational condition and based on
it7 e;ecute dierent pat2s.
:;P '$7 :/"L="1:
Compiler Directive Directs t2e compiler to ta3e speciic action during compilation.
:;P CO8# !O'8 :I:C1
:;plicit !cope
terminator
1erminate t2e scope o conditional and imperative statements.
:;P :&D9"DD :&D9'$ :&D9:/"L="1:
'mplicit !cope
terminator
12e period at t2e end o any sentence7 terminates t2e scope o
all previous statements not yet terminated.
+O/: !tatement
't is used to transer data bet%een internal storage areas deined in eit2er ile
section or %or3ing storage section.
!ynta;P
+O/: identiier1.literal1.igurative9constant 1O identiier0 (identiier4)
+ultiple move statements can be separated using comma7 semicolons7 blan3s
or t2e 3ey%ord 1H:&.
Numeric move rules:
" numeric or numeric9edited item receives data in suc2 a %ay t2at t2e
decimal point is aligned irst and t2en illing o t2e receiving ield ta3es place.
=nilled positions are illed %it2 Sero. ?ero suppression or insertion o editing
symbols ta3es places according to t2e rules o editing pictures.
' t2e receiving ield %idt2 is smaller t2an sending ield t2en e;cess digits7 to
t2e let and.or to t2e rig2t o t2e decimal point are truncated.
Alphanumeric Move Rules:
"lp2abetic7 alp2anumeric or alp2anumeric9edited data ield receives t2e data
rom let to rig2t. "ny unilled ield o t2e receiving iled is illed %it2 spaces.
G2en t2e lengt2 o receiving ield is s2orter t2an t2at o sending ield7 t2en
receiving ield accepts c2aracters rom let to rig2t until it is illed. 12e
unaccomodated c2aracters on t2e rig2t o t2e sending ield are truncated.
G2en an alp2anumeric ield is moved to a numeric or numeric9edited ield7
t2e item is moved as i it %ere in an unsigned numeric integer mode.
CO66:!8O&D'&H can be used to transer data bet%een items o t2e same
names belonging to dierent group9items by speciying t2e names o group9items to
%2ic2 t2ey belong.
+O/: CO66:!8O&D'&H group91 1O group90
Mainframe Refresher Part-1 COBOL-Page: 8
Group Move rule
G2en +O/: statement is used to move inormation at group level7 t2e
movement o data ta3es place as i bot2 sending and receiving ields are speciied as
alp2anumeric items. 12is is regardless o t2e description o t2e elementary items
constituting t2e group item.
!amples or understanding +O/: statement (+O/: " 1O B)

8icture o " /alue o " 8icture o B /alue o B ater
+ove
8'C 99/99 10.45 8'C 999/99 510.45
8'C 99/99 10.45 8'C 9999/9999 5510.4555
8'C 99/999 10.4-5 8'C 9/99 0.4-
8'C9(55)/9(54) 5-401.5-4 8'C 9(54)/9(54) 401.5-4
8'C 9(5-)/9(50) 04.0- 8'C ???99.9 04.0
8'C 99/99 55.4- 8'C BBB.99 B.4-
8'C R(5-) +=!" RBRBRB + = !
"6'1H+:1'C /:6B!
"ll t2e possible arit2metic operations in COBOL using "DD7 !=B16"C17
+=L1'8L# and D'/'D: are given belo%P
"rit2metic Operation " B C D
"DD " 1O B " "@B
"DD " B C 1O D " B C "@B@C@D
"DD " B C H'/'&H D " B C "@B@C
"DD " 1O B C " "@B "@C
!=B16"C1 " $6O+ B " B9"
!=B16"C1 " B $6O+
C
" B C9("@B)
!=B16"C1 " B $6O+
C H'/'&H D
" B C C9("@B)
+=L1'8L# " B# B " ">B
+=L1'8L# " B# B
H'/'&H C
" B ">B
D'/'D: " '&1O B " B."
D'/'D: " '&1O B
H'/'&H C
" B B."
D'/'D: " B# B
H'/'&H C
" B ".B
D'/'D: " '&1O B
H'/'&H C
6:+"'&D:6 D
" B 'nteger (B.") 'nteger
remainder
H'/'&H is used in t2e ollo%ing casesP
1.1o retain t2e values o operands participating in t2e operation.
0.12e resultant value o operation e;ceeds any o t2e operand siSe.
Mainframe Refresher Part-1 COBOL-Page: 9
6O=&D:D option
Git2 6O=&D:D option7 t2e computer %ill al%ays round t2e result to t2e
8'C1=6: clause speciication o t2e receiving ield. 't is usually coded ater t2e ield
to be rounded. 't is prei;ed %it2 6:+"'&D:6 3ey%ord O&L# in D'/'D: operation.
"DD " B H'/'&H C 6O=&D:D.
D'/'D:..6O=&D:D 6:+"'&D:6
CautionP DonLt use or intermediate computation.
O& !'?: :66O6
' "A05 (8'C 9(50)) and BA95 (8'C 9(50))7 "DD " 1O B %ill result 15 in B
%2ere t2e e;pected value in B is 115. O& !'?: :66O6 clause is coded to trap suc2
siSe errors in arit2metic operation.
' t2is is coded %it2 arit2metic statement7 any operation t2at ended %it2 !'?:
error %ill not be carried out but t2e statement ollo%s O& !'?: :66O6 %ill be
e;ecuted.
"DD " 1O B O& !'?: :66O6 D'!8L"# K:66O6XL.
CO+8=1:
Comple; arit2metic operations can be carried out using CO+8=1: statement.
Ge can use arit2metic symbols t2an 3ey%ords and so it is simple and easy to code.
@ $or "DD7 9 or !=B16"C17 > or +=L1'8L#7 . or D'/'D: and >> or e;ponentiation.
6uleP Let to rig2t ( 1.8arent2eses
0.:;ponentiation
4.+ultiplication and Division
-."ddition and !ubtraction
CautionP G2en 6O=&D:D is coded %it2 CO+8=1:7 some compiler %ill do rounding
or every arit2metic operation and so t2e inal result %ould not be precise.
,, " 8'C 999 /"L=: 15
CO+8=1: " 6O=&D:D A ("@0.95) >15.99
6esultP (6O=&D:D(6O=&D:D(10.95) > 6O=&D:D(15.99)) A105 or
6O=&D:D(1-0.4055) A 1-0
!o t2e result can be 105 or 1-0.Be cautious %2en using 6O=&D:D 3ey%ord
%it2 CO+8=1: statement.
"ll arit2metic operators 2ave t2eir o%n e;plicit scope terminators. (:&D9"DD7
:&D9!=B16"C17 :&D9+=L1'8L#7 :&D9D'/'D:7 :&D9CO+8=1:). 't is suggested to
use t2em.
CO66:!8O&D'&H is available or "DD and !=B16"C1 only.
'&'1'"L'?:
/"L=: clause is used to initialiSe t2e data items in t2e %or3ing storage
section %2ereas '&'1'"L'?: is used to initialiSe t2e data items in t2e procedure
division.
'&'1'"L'?: sets t2e alp2abetic7 alp2anumeric and alp2anumeric9edited items
to !8"C:! and numeric and numeric9edited items to ?:6O. 12is can be overridden
by 6:8L"C'&H option o '&'1'"L'?:. $'LL:67 OCC=6! D:8:&D'&H O& items are not
aected.
Mainframe Refresher Part-1 COBOL-Page: 10
!ynta;P '&'1'"L'?: identiier91
6:8L"C'&H ("L8H"B:1'C."L8H"&=+:6'C."L8H"9&=+:6'C9:D'1:D
&=+:6'C.&=+:6'C9:D'1:D)
D"1" B# (identiier90 .Literal90)
"CC:81
"CC:81 can transer data rom input device or system inormation contain in
t2e reserved data items li3e D"1:7 1'+:7 D"#.
"CC:81 G!9/"61 ($6O+ D"1:.1'+:.D"#.O1H:6 !#!1:+ /"6!).
' $6O+ Clause is not coded7 t2en t2e data is read rom terminal. "t t2e time
o e;ecution7 batc2 program %ill "B:&D i t2ere is no in9stream data rom ICL and
t2ere is no $6O+ clause in t2e "CC:81 clause.
D"1: option returns si; digit current date in ####++DD
D"# returns 5 digit current date in ##DDD
1'+: returns * digit 6=& 1'+: in HH++!!11
D"#9O$9G::O returns single digit %2ose value can be 19, (+onday9!unday
respectively)
D'!8L"#
't is used to display data. By deault display messages are routed to !#!O=1.
!ynta;P D'!8L"# identiier1T literal1 (=8O& mnemonic name)
!1O8 6=&7 :R'1 86OH6"+ N HO B"CO
!1O8 6=& is t2e last e;ecutable statement o t2e main program. 't returns
control bac3 to O!.
:R'1 86OH6"+ is t2e last e;ecutable statement o sub9program. 't returns
control bac3 to main program.
HOB"CO can be coded in main program as %ell as sub9program as t2e last
statement. 't Wust gives t2e control bac3 rom %2ere it received t2e control.
Collating !e<uence
12ere are t%o amous Collating !e<uence available in computers. 'B+ and
'B+ Compatible mac2ine use :BCD'C collating se<uence %2ereas most micro and
many mainrame systems use "!C'' collating se<uence. 12e result o arit2metic and
alp2abetic comparison %ould be same in bot2 collating se<uences %2ereas t2e same
is not true or alp2anumeric comparison.
:BCD'C ("scending Order) "!C'' ("scending Order)
!pecial C2aracters !pecial C2aracters
a9S 599
"9? "9?
599 a9S
Deault collating se<uence can be overridden by an entry in OBI:C19CO+8=1:6 and
!8:C'"L &"+:! paragrap2s.
1. Code t2e 86OH6"+ COLL"1'&H !:Q=:&C: Clause in t2e ObWect computer
paragrap2. 86OH6"+ COLL"1'&H !:Q=:&C: '! alp2abet9name
0. +ap t2e alp2abet9name in t2e !8:C'"L9&"+:! paragrap2 as ollo%sP
"L8H"B:1 alp2abet9name is !1"&D"6D91 T &"1'/:
&"1'/: stands or computerLs o%n collating se<uence %2ereas !1"&D"6D91 stands
or "!C'' collating se<uence.
Mainframe Refresher Part-1 COBOL-Page: 11
'$.1H:&.:L!:.:&D9'$
12e most amous decision ma3ing statement in all language is K'$L. 12e synta;
o '$ statement is given belo%P '$ can be coded %it2out any :L!: statement. 1H:&
is a noise %ord and it is optional.
' O6s N "&Ds are used in t2e same sentence7 "&Ds are evaluated irst rom
let to rig2t7 ollo%ed by O6s. 12is rule can be overridden by using parent2eses.
12e permitted relation conditions are A7 F7 E7 FA7 EA7 FE
CO&1'&=: is no operation statement. 12e control is Wust passed to ne;t
!1"1:+:&1. &:R1 !:&1:&C: passes t2e control to t2e ne;t !:&1:&C:. ' you
orgot t2e dierence bet%een statement and sentence7 reer t2e irst page.
't is advised to use :&D9'$7 e;plicit scope terminator or t2e '$ statements
t2an period7 implicit scope terminator.
'$ condition1 "&D condition0 1H:&
!tatement9Bloc391
:L!:
'$ condition4 1H:&
CO&1'&=:
:L!:
'$ condition- 1H:&
!tatement9Bloc390
:L!:
&:R1 !:&1:&C:
:&D9'$
:&D9'$
:&D9'$
!tatement9Bloc390 %ill be e;ecuted only %2en condition 17 0 and - are 16=:
and condition 4 is $"L!:.
'mplied operandP 'n compound conditions7 it is not al%ays necessary to
speciy bot2 operands or eac2 condition. '$ 1O1"LA, or * is acceptable. Here
1O1"LA* is implied operation.
!'H& test and CL"!! test
!'H& test is used to c2ec3 t2e sign o a data item. 't can be done as ollo%s (
'$ identiier is 8O!'1'/:.&:H"1'/:.?:6O
CL"!! test is used to c2ec3 t2e content o data item against pre9deined range o
values. 't can be done as ollo%s 9
'$ identiier is &=+:6'C."L8H"B:1'C."L8H"B:1'C9H'HH:6.
"L8H"B:1'C9LOG:6
#ou can deine your o%n classes in t2e special names paragrap2. Ge 2ave deined a
class D'H'1 in our special names paragrap2. 't can be used in t2e ollo%ing %ay.
'$ identiier is D'H'1
Mainframe Refresher Part-1 COBOL-Page: 12
&egated conditions.
"ny simple7 relational7 class7 sign test can be negated using &O1.
But it is not al%ays true t2at &O1 &:H"1'/: is e<ual to 8O!'1'/:. (:;ample ?:6O)
:/"L="1:
Git2 COBOL*57 %e use t2e :/"L="1: verb to implement t2e case structure o
ot2er languages. +ultiple '$ statements can be eiciently and eectively replaced
%it2 :/"L="1: statement. "ter t2e e;ecution o one o t2e %2en clauses7 t2e
control is automatically come to t2e ne;t statement ater t2e :&D9:/"L="1:. "ny
comple; condition can be given in t2e GH:& clause. Brea3 statement is not needed7
as it is so in ot2er languages.
General Syntax
:/"L="1: subWect91 ("L!O subWect0..)
GH:& obWect91 ("L!O obWect0..)
GH:& obWect94 ("L!O obWect-..)
GH:& O1H:6 imperative statement
:&D99:/"L="1:
1.&umber o !ubWects in :/"L="1: clause s2ould be e<ual to number o
obWects in every GH:& clause.
0.!ubWect can be variable7 e;pression or t2e 3ey%ord 16=:. $L"!: and
respectively obWects can be values7 16=:.$"L!: or any condition.
4.' none o t2e GH:& condition is satisied7 t2en GH:& O1H:6 pat2 %ill be
e;ecuted.
Sample
:/"L="1: !QLCOD: "L!O 16=:
GH:& 155 "L!O "AB imperative statement
GH:& 9455 "L!O (".CA-) imperative statement
GH:& O1H:6 imperative statement
:&D9:/"L="1:
Mainframe Refresher Part-1 COBOL-Page: 13
8:6$O6+ !1"1:+:&1!
8:6$O6+ %ill be useul %2en you %ant to e;ecute a set o statements in
multiple places o t2e program. Grite all t2e statements in one paragrap2 and invo3e
it using 8:6$O6+ %2erever needed. Once t2e paragrap2 is e;ecuted7 t2e control
comes bac3 to ne;t statement ollo%ing t2e 8:6$O6+.
1.!'+8L: 8:6$O6+.
8:6$O6+ 8"6"91.
D'!8L"# K8"6"91 e;ecutedL
!1O8 6=&.
8"6"91.
!tatement1
!tatement0.
't e;ecutes all t2e instructions coded in 8"6"91 and t2en transers t2e control
to t2e ne;t instruction in se<uence.
0.'&L'&: 8:6$O6+.
G2en sets o statements are used only in one place t2en %e can group all o
t2em %it2in 8:6$O6+ :&D98:6$O6+ structure. 12is is called '&L'&: 8:6$O6+.
12is is e<ual to DO..:&D structure o ot2er languages.
8:6$O6+
"DD " 1O B
+=L1'8L: B B# C
D'!8L"# K/"L=: O$ "@B>C K C
:&D98:6$O6+
4. 8:6$O6+ 8"6"91 1H6= 8"6"9&.
"ll t2e paragrap2s bet%een 8"6"91 and 8"6"9& are e;ecuted once.
-. 8:6$O6+ 8"6"91 1H6= 8"6"9& =&1'L condition(s).
12e identiiers used in t2e =&1'L condition(s) must be altered %it2in t2e
paragrap2(s) being perormedC ot2er%ise t2e paragrap2s %ill be perormed
indeinitely. ' t2e condition in t2e =&1'L clause is met at irst time o e;ecution7
t2en named paragrap2(s) %ill not be e;ecuted at all.
5. 8:6$O6+ 8"6"91 1H6= 8"6"9& & 1'+:!.
& can be literal deined as numeric item in %or3ing storage or 2ard coded
constant.
). 8:6$O6+ 8"6"91 1H6= 8"6"9& /"6#'&H identiier1
$6O+ identiier 0 B# identiier4 =&1'L condition(s)
'nitialiSe identiier1 %it2 identiier0 and test t2e condition(s). ' t2e condition
is alse e;ecute t2e statements in 8"6"91 t2ru 8"6"9& and increment identiier1 B#
identiier4 and c2ec3 t2e condition(s) again. ' t2e condition is again alse7 repeat
t2is process till t2e condition is satisied.
,.8:6$O6+ 8"6"91 G'1H 1:!1 B:$O6:."$1:6 =&1'L condition(s).
Mainframe Refresher Part-1 COBOL-Page: 14
Git2 1:!1 B:$O6:7 Condition is c2ec3ed irst and i it ound alse7 t2en 8"6"9
1 is e;ecuted and t2is is t2e deault. ($unctions li3e DO9 GH'L:)
Git2 1:!1 "$1:67 8"6"91 is e;ecuted once and t2en t2e condition is
c2ec3ed. ($unctions li3e DO9=&1'L)
6eer 1able session or eig2t2 type o 8:6$O6+.
:R'1 statement.
COBOL reserved %ord t2at perorms &O1H'&H. 't is used as a single
statement in a paragrap2 t2at indicate t2e end o paragrap2(s) e;ecution.
:R'1 must be t2e only statement in a paragrap2 in COBOL,- %2ereas it can be used
%it2 ot2er statements in COBOL*5.
HO 1O =sageP
'n a structured top9do%n programming HO 1O is not preerable. 't oers
permanent control transer to anot2er paragrap2 and t2e c2ances o logic errors is
muc2 greater %it2 HO 1O t2an 8:6$O6+. 12e readability o t2e program %ill also be
badly aected.
But still HO 1O can be used %it2in t2e paragrap2s being perormed. i.e. G2en
using t2e 1H6= option o 8:6$O6+ statement7 branc2es or HO 1O statements7 are
permitted as long as t2ey are %it2in t2e range o named paragrap2s.
8:6$O6+ 1559!1:81 1H6= !1:89-
..
1559!1:891.
"DD " 1O B H'/'&H C.
'$ D A ?:6O D'!8L"# K+=L1'8L'C"1'O& &O1 DO&:L
HO 1O 4559!1:84
:&D9'$.
0559!1:890.
+=L1'8L# C B# D.
4559!1:894.
D'!8L"# K/"L=: O$ CPL C.
Here HO 1O used %it2in t2e range o 8:6$O6+. 12is 3ind o Controlled HO 1O is ine
%it2 structured programming alsoX
Mainframe Refresher Part-1 COBOL-Page: 15
1"BL:!
"n OCC=6! clause is used to indicate t2e repeated occurrences o items o
t2e same ormat in a structure. OCC=6! clause is not valid or 517 ,,7 ** levels.
't can be deined as elementary or group item. 'nitialiSation o large table
occurrences %it2 speciic values are usually done using perorm loops in procedure
division. !imple tables can be initialiSed in t2e ollo%ing %ay.
51 G::O9"66"# /"L=: K+O&1=:G:D1H=$6'!"1!=&L.
55 G!9G::O9D"#! OCC=6! , 1'+:! 8'C R(54).

Dynamic array is t2e array %2ose siSe is decided during runtime Wust beore t2e
access o irst element o t2e array.
51 G!9+O&1H9D"#9C"L.
55 G!9D"#! OCC=6! 41 1'+:! D:8:&D'&H O& G!9OCC=6:&C:.
'$ +O&1H A K$:BL +O/: K0*L to G!9OCC=66:&C:.
"rray 'tems can be accessed using '&D:R or subscript and t2e dierence
bet%een t2em are listed in t2e table. 6elative subscripts and relative inde;es are
supported only in COBOL*5. Literals used in relative subscripting.inde;ing must be
an unsigned integer.
"DD G!9!"L(!=B) G!9!"L(!=B @ 1) 1O G!9!"L(!=B @ 0).
!l J !ubscript 'nde;
1 Gor3ing !torage item 'nternal 'tem ( &o need to declare it.
0 't means occurrence 't means displacement
4 Occurrence7 in turn translated to
displacement to access elements
and so slo%er t2an '&D:R access.
$aster and eicient.
- 't can be used in any arit2metic
operations or or display.
't cannot be used or arit2metic
operation or or display purpose.
5 !ubscripts can be modiied by any
arit2metic statement.
'&D:R can only be modiied %it2 !:17
!:"6CH and 8:6$O6+ statements.
!ometimes7 you may ace a <uestion li3e 2o% to randomly access t2e
inormation in t2e se<uential ile o 55 records t2at contains all t2e designation and
t2e respective lo%er and 2ig2er salary inormation.
Obviously7 O! does not allo% you to randomly access t2e se<uence ile. #ou
2ave to do by yoursel and t2e best %ay is7 load t2e ile into a %or3ing storage table
in t2e irst section o t2e program and t2en access as you %is2.
12e table loo39up can be done in t%o %ays.
9!e<uential searc2.
9Binary searc2.
Mainframe Refresher Part-1 COBOL-Page: 16
!e<uential !:"6CH
During !:6'"L !:"6CH7 t2e irst entry o t2e table is searc2ed. ' t2e
condition is met7 t2e table loo39up is completed. ' t2e condition is not met7 t2en
inde; or subscript is incremented by one and t2e ne;t entry is searc2ed and t2e
process continues until a matc2 is ound or t2e table 2as been completely searc2ed.
!:1 inde;name91 1O 1.
!:"6CH identiier91 "1 :&D display Kmatc2 not oundPL
GH:& condition91 imperative statement91 .&:R1 !:&1:&C:
GH:& condition90 imperative statement90 .&:R1 !:&1:&C:
:&D9!:"6CH
'dentiier91 s2ould be OCC=6! item and not 51 item.
Condition917 Condition90 compares an input ield or searc2 argument %it2 a table
argument.
12oug2 "1 :&D Clause is optional7 it is 2ig2ly recommended to code t2at. Because i
it is not coded and element loo3ing or is not ound7 t2en t2e control simply comes to
t2e ne;t statement ater !:"6CH %2ere an invalid table item can be reerred and
t2at may lead to incorrect results . abnormal ends.
!:1 statement !ynta;P
!:1 inde;9name91 1O.=8 B#.DOG& B# integer91.
Binary !:"6CH
G2en t2e siSe o t2e table is large and it is arranged in some se<uence (
eit2er ascending or descending on searc2 ield7 t2en B'&"6# !:"6CH %ould be t2e
eicient met2od.
!:"6CH "LL identiier91 "1 :&D imperative9statement91
GH:& dataname91 A identiier90.literal91.arit2metic e;pression91
"&D dataname90 A identiier94.literal90.arit2metic e;pression90
:&D9!:"6CH.
'dentiier90 and identiier94 are subscripted items and dataname91 and
dataname90 are %or3ing storage items t2at are not subscripted.
Compare t2e item to be searc2ed %it2 t2e item at t2e center. ' it matc2es
ine7 else repeat t2e process %it2 t2e let or rig2t 2al depending on %2ere t2e item
lies.

!l J !e<uential !:"6CH Binary !:"6CH
1 !:"6CH !:"6CH "LL
0 1able s2ould 2ave '&D:R 1able s2ould 2ave '&D:R
4 1able need not be in !O61:D
order.
1able s2ould be in sorted order o t2e
searc2ing argument. 12ere s2ould be
"!C:&D'&H.D:!C:&D'&H Clause.
- +ultiple GH:& conditions can be Only one GH:& condition can be coded.
Mainframe Refresher Part-1 COBOL-Page: 17
coded.
5. "ny logical comparison is possible. Only A is possible. Only "&D is possible
in compound conditions.
) 'nde; s2ould be set to 1 beore
using !:"6CH
'nde; need not be set to 1 beore
!:"6CH "LL.
, 8reer %2en t2e table siSe is small 8reer %2en t2e table siSe is signiicantly
large.
+ulti Dimensional "rrays
COBOL,- supports array o ma;imum o t2ree dimensions %2ereas COBOL*5
supports up to seven dimensions. 12e lo%est9 level OCC=6! data9name or an item
subordinate to it is used to access an entry in t2e array or t2e table.
' %e use !:"6CH or accessing multi9dimension table7 t2en '&D:R:D B#
must be used on all OCC=6! levels. :;panded nested perorm is available or
processing multi level tables. 12e synta; o t2is perorm is given belo%P
8:6$O6+ para91 t2ru para9n
/"6#'&H inde;91 rom 1 B# 1 =&1'L inde;91 E siSe9 o9 outer9occurs
"$1:6 /"6#'&H inde;90 rom 1 by 1 until inde;90 E siSe o inner occurs.
!:"6CH e;ample or multi level tablesP
51 :+891"BL:.
55 D:81&=+B:6 OCC=6! 15 1'+:! '&D:R:D B# '1.
15 :+89D:1"'L OCC=6! 55 1'+:! '&D:R:D B# '0.
15 :+89&=+B:6 8'C 9(5-).
15 :+89!"L"6# 8'C 9(55).
,, :+8&=+B:69'& 8'C 9(5-) /"L=: K0550L.
8:6$O6+ 1559!:"6CH9:+89!"L /"6#'&H '1 $6O+ 1 B# 1
=&1'L '1 E 15 O6 G!9$O=&D
1559!:"6CH9:+89!"L.
!:1 '0 1O 1.
!:"6CH :+89D:1"'L "1 :&D D'!8L"# K&O1 $O=&DL AA E Lo%est Occurs
GH:& :+8&=+B:69'& A :+89&=+B:6('17'0)
D'!8L"# K!"L"6# '!PL :+89!"L"6#('17'0)
!:1 G!9$O=&D 1O 16=: AA E !earc2 ends
:&D9!:"6CH.
&:!1:D 86OH6"+!7 HLOB"L7 :R1:6&"L
One program may contain ot2er program(s). 12e contained program(s) may
t2emselves contain yet ot2er program(s). "ll t2e contained and containing programs
s2ould end %it2 :&D 86OH6"+ statement. 8H+B is nested a program in t2e
e;ample belo%P
:;ampleP 'D:&1'$'C"1'O& D'/'!'O&.
86OH6"+9'D. 8H+"
Y
'D:&1'$'C"1'O& D'/'!'O&.
86OH6"+9'D. 8H+B
Y
:&D 86OH6"+ 8H+B.
Y
:&D 86OH6"+ 8H+".
Mainframe Refresher Part-1 COBOL-Page: 18
' you %ant access any %or3ing storage variable o 8H+" in 8H+B7 t2en
declare t2em %it2 t2e clause K'! HLOB"LL in 8H+". ' you %ant to access any
%or3ing storage variable o 8H+B in 8H+"7 declare t2em %it2 t2e clause K'!
:R1:6&"LL in 8H+B. &ested 8rograms are supported only in COBOL*5.
' t2ere is a program 8H+C inside 8H+B7 it cannot be called rom 8H+"
unless itLs program id is <ualiied %it2 3ey%ord CO++O&.
!O61 and +:6H:
12e programming !O61 is called as internal sort %2ereas t2e sort in ICL is
called e;ternal sort. ' you %ant to manipulate t2e data beore eeding to sort7 preer
internal sort. 'n all ot2er cases7 e;ternal sort is t2e good c2oice. 'nternal sort7 in turn
invo3es t2e !O61 product o your installation. (D$!O61). 'n t2e run ICL7 allocate at
least t2ree sort %or3 iles. (!O619GOnn AE nn can be 55999).
$"!1!61 compiler option ma3es t2e D$!O61 to do all ile '9O operation t2an
your COBOL program. 't %ould signiicantly improve t2e perormance. 12e result o
t2e !O61 can be c2ec3ed in !O6196:1=6& register. ' t2e sort is successul7 t2e
value %ill be 5 else 1).
!ynta;P
!O61 !O61$'L: O& "!C:&D'&H .D:!C:&D'&H O:# sd93ey91 sd93ey0
=!'&H ile1 ile0 . '&8=1 86OC:D=6: '! section91
H'/'&H ile4 . O=18=1 86OC:D=6: is section90
:&D9!O61
$ile17 $ile0 are to9be9sorted input iles and $ile4 is sorted9output ile and all
o t2em are deined in $D.!O61$'L: is Dis3 !O61 Gor3 ile t2at is deined at !D. 't
s2ould not be e;plicitly opened or closed.
'&8=1 86OC:D=6: and =!'&H are mutually e;clusive. ' =!'&H is used7 t2en
ile1 and iles s2ould not be opened or 6:"D e;plicitly. ' '&8=1 86OC:D=6: is used
t2en $ile1 and ile0 need to be O8:&ed and 6:"D t2e records one by one until end o
t2e ile and pass t2e re<uired records to sort9%or39ile using t2e command 6:L:"!:.
!ynta;P 6:L:"!: sort9%or39record rom input9ile9record.
O=18=1 8rocedure and H'/'&H are mutually e;clusive. ' H'/'&H is used7
t2en ile4 s2ould not be opened or G6'1: e;plicitly. ' O=18=1 procedure is used7
t2en $ile4 s2ould be O8:&ed and t2e re<uired records rom sort %or3 ile s2ould be
6:1=6&ed to it. Once "1 :&D is reac2ed or sort9%or39ile7 close t2e output ile.
!ynta;P 6:1=6& sort9%or39ile9name "1 :&D imperative statement.
'&8=1 86OC:D=6: /s O=18=1 86OC:D=6:P
!ometimes it %ould be more eicient to process data beore it is sorted7
%2ereas ot2er times it is more eicient to process ater it is sorted. ' %e intend to
eliminate more records7 t2en it %ould be better preprocess t2em beore eeding to
!O61. ' %e %ant to eliminate all t2e records 2aving spaces in t2e 3ey ield t2en it
%ould be eicient i %e eliminate t2em ater sorting. Because t2e records %it2 blan3
3ey comes irst ater sorting.
+:6H:
't is same as sort. =!'&H is mandatory. 12ere s2ould be minimum t%o iles in
=!'&H.
+:6H: !ort9%or39ile O& "!C:&D'&H O:# dataname1 dataname0
Mainframe Refresher Part-1 COBOL-Page: 19
=!'&H ile1 ile0
H'/'&H ile4 . O=18=1 86OC:D=6: is section91
:&D9+:6H:
8rogram sort registers (and its e<uivalent D$!O61 parameter.meaning)
!O619$'L:9!'?: ($'L!?)7 !O619CO6:9!'?: (6:!'&/)7 !O619+!H(+!HDD&)
!O619+OD:9!'?: (!+!Annnnn)
!O6196:1=6&(return9code o sort) and
!O619CO&16OL (&ames t2e ile o control card ( deault is 'H?!61CD)
!16'&H +"&'8=L"1'O&
" string reers to a se<uence o c2aracters. !tring manipulation operations
include inding a particular c2aracter.sub9string in a string7 replacing particular
c2aracter.sub9string in a string7 concatenating strings and segmenting strings.
"ll t2ese unctions are 2andled by t2ree verbs '&!8:C17 !16'&H and =&!16'&H in
COBOL. :R"+'&: is t2e obsolete version o '&!8:C1 supported in COBOL,-.
'&!8:C19 $O6 CO=&1'&H
't is used to tally t2e occurrence o a single c2aracter or groups o c2aracters in a
data ield.
'&!8:C1 identiier91 1"LL#'&H identiier90 $O6
"LLTL:"D'&H literal91Tidentiier94
ZB:$O6:T"$1:6 '&'1'"L identiier9-Tliteral90[ 9 Optional.
'&!8:C1 identiier91 1"LL#'&H identiier90 $O6
CH"6"C1:6!
ZB:$O6:T"$1:6 '&'1'"L identiier9-Tliteral90[ 9 Optional.
+ain !tring is identiier91 and count is stored in identiier90. Literal91 or
'dentiier94 is a c2aracter or group9o9c2aracters you are loo3ing in t2e main9string.
'&!8:C1 urt2er <ualiies t2e searc2 %it2 B:$O6: and "$1:6 o t2e initial occurrence
o identiier9- or literal90.
:;ampleP
G!9&"+: ( K+=1H= !"6"/"&" S=6#" CH"&D6" D:/'L
'&!8:C1 G!9&"+: 1"LL#'&H G!9CO=&1 "LL K!L
B:$O6: '&'1'"L K!"6"/"&"L "$1:6 '&'1'"L KCH"&D6"L
:&D9'&!8:C1
6esultP G!9CO=&1 contains ( 1
'&!8:C19 $O6 6:8L"C'&H
't is used to replace t2e occurrence o a single c2aracter or groups o
c2aracters in a data ield.
'&!8:C1 identiier91 6:8L"C'&H
"LLTL:"D'&H literal91Tidentiier90 B# identiier94Tliteral90
ZB:$O6:T"$1:6 '&'1'"L identiier9-Tliteral90[ 9 Optional.
'&!8:C1 identiier91 6:8LC'&H CH"6"C1:6!
B# identiier90 B:$O6:T"$1:6 '&'1'"L identiier94Tliteral91
Mainframe Refresher Part-1 COBOL-Page: 20
'&!8:C19$O6 CO=&1'&H "&D 6:8L"C'&H
't is a combination o t2e above t%o met2ods.
'&!8:C1 identiier91 1"LL#'&H Ftallying part E 6:8L"C'&H Freplacing partE
!16'&H
!16'&H command is used to concatenate one or more strings.
!ynta;P
!16'&H identiier91 . literal917 identiier90. literal90
D:L'+'1:D B# (identiier94.literal94.!'?:)
'&1O identiier9-
:&D9!16'&H.
51 /"61 8'C R(15) /"L=: K+=1H= K
51 /"60 8'C R(15) /"L=: K!"6" K
51 /"60 8'C R(05).
1o get display K+=1H=7!"6"L
!16'&H /"61 D:L'+'1:D B# K K
K7L D:L'+'1:D B# !'?:
/"60 D:L'+'1:D B# K K
'&1O /"64
:&D9!16'&H.
12e receiving ield must be an elementary data item %it2 no editing symbols
and I=!1 6'HH1 clause.
Git2 !16'&H statement7 speciic c2aracters o a string can be replaced
%2ereas +O/: replaces t2e ull string.
51 "H:9O=1 8'C R(10) /"L=: L10 #:"6! OLDL.
!16'&H K1*L D:L'+'1:D B# !'?: '&1O "H:9O=1. AE 1* #:"6! OLD.
6eerence +odiication ( e<uivalent o !=B!16
K6eerence modiicationL is used to retrieve or over%rite a sub9string o a
string. K:L is 3no%n as reerence modiication operator.
!ynta;P !tring(!tarting98osition:Lengt2)
+O/: K1*L 1O "H:9O=1(1P0) does t2e same as %2at %e did %it2 !16'&H command.
G2en it is used in array elements7 t2e synta; is
"rray9element (occurrence) (!tarting98ositionPLengt2)

=&!16'&H
=&!16'&H command is used to split one string to many strings.
!ynta;P
=&!16'&H identiier91
ZD:L'+'1:D B# ("LL.) identiier0.literal1 Z7O6 ("LL.) (identiier94.literal90)7..[[
'&1O identiier9- Z7D:L'+'1:6 '& identiier957 CO=&1 '& identiier9)[
Z7identiier9, Z7D:L'+'1:6 '& identiier9*7 CO=&1 '& identiier99[
51 G!9D"1" 8'C R(10) /"L=: K15.055.455.1L.
Mainframe Refresher Part-1 COBOL-Page: 21
=&!16'&H G!9D"1" D:L'+'1:D B# K.L
'&1O G!9$LD1 D:L'+'1:6 '& G!9D1 CO=&1 '& G!9C1
G!9$LD0 D:L'+'1:6 '& G!9D0 CO=&1 '& G!9C0
G!9$LD4 D:L'+'1:6 '& G!9D4 CO=&1 '& G!9C4
:&D9=&!16'&H.
6esultP
G!9$LD1 A 15 G!9$LD0 A055 G!9$LD4A455
G!9C1 A 0 G!9C0A4 G!9C4A4 G!9D1 A K.L G!9D0AL.L G!9D4 K.L
O& O/:6$LOG can be coded %it2 !16'&H and =&!16'&H. ' t2ere is !16'&H
truncation t2en t2e imperative statements ollo%ed O& O/:6$LOG %ill be e;ecuted.
CO8# !tatement
" CO8# statement is used to bring a series o pre%ritten COBOL entries t2at
2ave been stored in library7 into a program.
1.Common routines li3e error routine7 date validation routine are coded in a library
and bring into t2e program by CO8#.
0. +aster iles are used in multiple programs. 12eir layout can be placed in one
copyboo3 and be placed %2erever t2e iles are used. 't promotes program
standardiSation since all t2e programs s2are t2e same layout and t2e same data
names.
12is reduces coding and debugging time. C2ange in layout needs c2ange in
copyboo3 only. 't is enoug2 i %e Wust recompile t2e program or ma3ing t2e ne%
copy eective.
!ynta;P
CO8# copyboo39name Z(O$.'&) library name[
Z6:8L"C'&H string9to9be9replaced B# replacing9string[
Copyboo3s are stored as members in 8D! library and during compilation time7 t2ey
are included into t2e program. By deault7 t2e copyboo3 library is !#!L'B and it can
be c2anged using '& or O$ o CO8# statement.
Copyboo3s can be used in t2e ollo%ing paragrap2s.
!O=6C:9CO+8=1:67 OBI:C19CO+8=1:67 !8:C'"L9&"+:!7 $'L:9CO&16OL7
'O9CO&16OL7 $D !:C1'O&7 8"6"H6"8H! '& 86OC:D=6: D'/'!'O&.

' t2e same copyboo3 is used more t2an once in t2e program7 t2en t2ere %ill
be Dduplicate data declarationM error during compilation7 as all t2e ields are declared
t%ice. 'n t2is case7 one copyboo3 can be used %it2 6:8L"C'&H verb to replace 2ig29
level <ualiier o t2e all t2e variables %it2 anot2er <ualiier.
:;ampleP CO8# C=!1O+:6 6:8L"C'&H KC=!119K B# KC=!109K.
Delimiter KA AL s2ould be used or replacing pseudo te;ts. 12e replacing
option does not alter t2e pre%ritten entries in t2e libraryC t2e c2anges are made to
t2e userLs source program only.
C"LL statement (!ub98rograms)
G2en a speciic unctionality need to be perormed in more t2an one
program7 it is best to %rite t2em separately and call t2em into eac2 program. !ub
8rograms can be %ritten in any programming language. 12ey are typically %ritten in
Mainframe Refresher Part-1 COBOL-Page: 22
a language best suited to t2e speciic tas3 re<uired and t2us provide greater
le;ibility.
+ain 8rogram C2angesP
C"LL statement is used or e;ecuting t2e sub9program rom t2e main
program. " sample o C"LL statement is given belo%P
C"LL K8H+0L =!'&H B# 6:$:6:&C: G!9/"617 B# CO&1:&1 G!9/"60.
8H+0 is called 2ere. G!9/"61 and G!9/"60 are %or3ing storage items.
G!9/"61 is passed by reerence. G!9/"60 is passed by Content. B# 6:$:6:&C: is
deault in COBOL and need not be coded. B# CO&1:&1 L:&H1H p2rase permits t2e
lengt2 o data item to be passed to a called program.
!ub98rogram C2angesP
G!9/"61 and G!9/"60 are %or3ing storage items o main program.
"s %e 2ave already mentioned7 t2e lin3age section is used or accessing e;ternal
elements. "s t2ese %or3ing storage items are o%ned by main program7 to access
t2em in t2e sub9program7 %e need to deine t2em in t2e lin3age section.
L'&O"H: !:C1'O&.
51 L'&O"H: !:C1'O&.
55 LO9/"61 8'C 9(5-).
55 LO9/"60 8'C 9(5-).
'n addition to deine t2em in lin3age section7 t2e procedure division s2ould be coded
%it2 t2ese data items or address9ability.
86OC:D=6: D'/'!'O& =!'&H LO9/"617LO9/"60
12ere is a one9one correspondence bet%een passed elements and received
elements (Call using7 lin3age and procedure division using) B# 8O!'1'O&. 12is
implies t2at t2e name o t2e identiiers in t2e called and calling program need not be
t2e same (G!9/"61 N LO9/"61) but t2e number o elements and picture clause
s2ould be same.
12e last statement o your sub9program s2ould be :R'1 86OH6"+. 12is
returns t2e control bac3 to main program. HOB"CO can also be coded instead o
:R'1 86OH6"+ but not !1O8 6=&. :R'1 86OH6"+ s2ould be t2e only statement in a
paragrap2 in COBOL,- %2ereas it can be coded along %it2 ot2er statements in a
paragrap2 in COBOL*5.
86OH6"+9'D. F8rogram9nameE '! '&'1'"L 86OH6"+.
' '! '&'1'"L 86OH6"+ is coded along %it2 program9id o sub program7 t2en
t2e program %ill be in initial stage every time it is called (COBOL*5 eature).
"lternatively C"&C:L issued ater C"LL7 %ill set t2e sub9program to initial state.
' t2e sub program is modiied t2en it needs to be recompiled. 12e need or
main program recompilation is decided by t2e compiler option used or t2e main
program. ' t2e D#&"+ compiler is used7 t2en t2ere is no need to recompile t2e main
program. 12e modiied subroutine %ill be in eect during t2e run. &OD#&"+ is
deault t2at e;pects t2e main program recompilation.
Dierence bet%een 8ass9by9reerence and 8ass9by9content
Mainframe Refresher Part-1 COBOL-Page: 23
!l J 8assl By 6eerence 8ass By Content
1 C"LL Ksub1L =!'&H B#
6:$:6:&C: G!9/"61
C"LL Ksub1L =!'&H B# CO&1:&1 G!9/"61
(B# CO&1:&1 3ey%ord is needed)
0 't is deault in COBOL. B#
6:$:6:&C: is not needed.
B# CO&1:&1 3ey %ord is mandatory to
pass an element by value.
4 "ddress o G!9/"61 is passed /alue o G!9/"61 is passed
- 12e sub9program modiications
on t2e passed elements are
visible in t2e main program.
12e sub9program modiications on t2e
passed elements are local to t2at
sub9program and not visible in t2e main
program.
Dierence bet%een !tatic Call and Dynamic Call
!l J !1"1'C Call D#&"+'C Call
1 'dentiied by Call literal.
:;P C"LL K8H+1L.
'dentiied by Call variable and t2e
variable s2ould be populated at run time.
51 G!98H+ 8'C R(5*).
+ove K8H+1L to G!98H+
C"LL G!98H+
0 Deault Compiler option is
&OD#&"+ and so all t2e literal
calls are considered as static calls.
' you %ant convert t2e literal calls into
D#&"+'C7 t2e program s2ould be
compiled %it2 D#&"+ option.
By deault7 call variables and any un9
resolved calls are considered as dynamic.
4. ' t2e subprogram undergoes
c2ange7 sub program and main
program need to be recompiled.
' t2e subprogram undergoes c2ange7
recompilation o subprogram is enoug2.
- !ub modules are lin3 edited %it2
main module.
!ub modules are pic3ed up during run
time rom t2e load library.
5 !iSe o load module %ill be large !iSe o load module %ill be less.
) $ast !lo% compared to !tatic call.
, Less le;ible. +ore le;ible.
* !ub9program %ill not be in initial
stage t2e ne;t time it is called
unless you e;plicitly use '&'1'"L or
you do a C"&C:L ater eac2 call.
8rogram %ill be in initial state every time
it is called.
'&16'&!'C $=&C1'O&!P
L:&H1H 6eturns t2e lengt2 o t2e 8'C clause. =sed or inding lengt2 o group
item t2at spanned across multiple levels.
+"R 6eturns t2e content o t2e argument t2at contains t2e ma;imum value
+'& 6eturns t2e content o t2e argument t2at contains t2e minimum value
&=+/"L 6eturns t2e numeric value represented by an alp2anumeric c2aracter
string speciied in t2e argument.
&=+/"L9C !ame as &=+/"L but currency and decimal points are ignored during
conversion.
C=66:&1 6eturns 01 C2ars alp2anumeric value ( ####++DDHH++!!nnnnnn
D"1:
'&1:H:6 O$ D"1: 6eturns '&1:H:6 e<uivalent o Hregorian date passed.
'&1:H:6 O$ D"# 6eturns '&1:H:6 e<uivalent o Iulian date passed.
Mainframe Refresher Part-1 COBOL-Page: 24
D"1: O$ '&1:H:6 6eturns Hregorian date or t2e integer passed.
D"# O$ '&1:H:6 6eturns Iulian date or t2e integer passed.
&oteP $=&C1'O& '&1:H:6 O$ D"1: (5195191)51) returns 1.
$'L: H"&DL'&H
" data ile is collection o relevant records and a record is collection o
relevant ields. 12e ile 2andling in COBOL program involves ive steps.
!teps in ile92anding
1."llocationP 12e iles used in t2e program s2ould be declared in $'L:9
CO&16OL paragrap2 o environment division. 12e mapping %it2 ICL DD&"+: is done
2ere. 12e ile is allocated to your program by t2is statement.
0.Deinition. 12e layout o t2e ile and its attributes are deined in t2e $'L:
!:C1'O& o D"1" D'/'!'O&.
4.OpenP Dataset is connected.readied to your program using O8:&
statement. 12e mode o O8:& decides t2e operation allo%ed and t2e initial pointer in
t2e dataset. $or e;ample7 :R1:&D mode allo%s only %rite access and t2e pointer is
3ept on t2e end o ile to append.
-.8rocessP 8rocess t2e ile as per re<uirement7 using t2e '9O statements
provided by COBOL. (6:"D7 G6'1:7 6:G6'1: and D:L:1:)
5. CloseP "ter t2e processing7 close t2e ile to disconnect it rom t2e
program.
"llocation o ile 9 !:L:C1 !tatement
(:&/'6O&+:&19E '&8=19O=18=19E $'L:9CO&16OL)
!:L:C1 ZO81'O&"L[ FILNAM "!!'H& to DDNAM AE"LL $iles
O6H"&'?"1'O& '! !:Q=:&1'"L.'&D:R:D.6:L"1'/: AE"LL $iles
"CC:!! '! !:Q=&:1'"L.6"&DO+.D#&"+'C AE"LL $iles
6:CO6D O:# '! FIL!"#$ AEO!D!
6:L"1'/: O:# '! %S!RRN AE66D!
"L1:6&"6: 6:CO6D O:# '! FIL!"#& G'1H D=8L'C"1:! AEO!D! %it2
"L1:6&"6: 6:CO6D O:# '! FIL!"#' G'1HO=1 D=8L'C"1:! AE"'R
$'L: !1"1=! '! %S!FIL!STAT$ AE"LL $iles
Z7%S!FIL!STAT&[ AE/!"+ $iles
!:L:C1 !tatement9 O81'O&"L Clause
12is can be coded only or input iles. ' O81'O&"L is not coded7 t2en t2e
input ile is e;pected to present in ICL. ' not7 an e;ecution error %ill occur.
' O81'O&"L is coded7 t2en i t2e ile is not mapped in ICL7 it is considered as
empty ile and t2e irst read results end o ile.
12e ile can also be dynamically allocated instead o static allocation in ICL.
Mainframe Refresher Part-1 COBOL-Page: 25
!:L:C1 !tatement9 "!!'H& 1O
FILNAM is t2e logical name used inside t2e program and DDNAM is t2e
logical name in t2e ICL7 mapped %it2 p2ysical dataset. DDNAM can be prei;ed %it2
K!9K to indicate Q!"+ ile7 K9"!L to indicate :!D! ile and %it2 no prei; to indicate
O!D!.66D! ile.
ICL !tep e;ecuting t2e program s2ould 2ave a dataset %it2 DDNAM as label
..DDNAM DD D!&AB8+"'&.:+8LO#::.D"1"7D'!8A!H6
!:L:C1 !tatement9O6H"&'?"1'O&
't can be !:Q=:&1'"L (8! or /!"+ :!D!)7 '&D:R:D (/!"+ O!D!)7
6:L"1'/: (/!"+ 66D!). Deault is !e<uential.
!:L:C1 !tatement9"CC:!! +OD:
!:Q=:&1'"L.
't is deault access mode and it is used to access t2e records O&L# in
se<uential order. 1o read 155
t2
record7 irst 99 records need to be read and s3ipped.
6"&DO+.
6ecords can be randomly accessed in t2e program using t2e
primary.alternate 3ey o inde;ed ile organiSation or relative record number o
relative organiSation.155
t2
record can directly be read ater getting t2e address o t2e
record rom t2e '&D:R part or '&D:R:D iles.155
t2
record can directly be read or
6:L"1'/: iles even %it2out any inde;.
D#&"+'C.
't is mi;ed access mode %2ere t2e ile can be accessed in random as %ell as
se<uential mode in t2e program.
:;ampleP 6eading t2e details o all t2e employees bet%een 155590555. $irst
randomly access 1555
t2
employee record7 t2en read se<uentially till 0555
t2
employee
record. !1"61 and 6:"D &:R1 commands are used or t2is purpose in t2e procedure
division.
!:L:C1 !tatement96:CO6D O:# '!
't is primary 3ey o /!"+ O!D! ile. 't s2ould be uni<ue and part o inde;ed
record structure.
!:L:C1 !tatement9"L1:6&"1: 6:CO6D O:# '!
12is p2rase is used or O!D! iles deined %it2 "'R. "dd t2e clause G'1H
D=8L'C"1:! i t2e "'R is deined %it2 duplicates.
6eerring to /!"+ basics7 every alternate inde; record 2as an associated
8"1H and t2e pat2 s2ould be allocated in t2e ICL t2at invo3es t2is program.
12e DD&"+: o t2e pat2 s2ould be DD&"+: o t2e base cluster sui;ed %it2
1 or t2e irst alternate record clause7 sui;ed %it2 n or nt2 "L1:6&"1: 6:CO6D
O:# clause in !:L:C1 clause.
!:L:C1 !tatement9$'L: !1"1=! '! %S!FIL!STAT$(%S!FIL!STAT&
%S!FIL!STAT$ s2ould be deined as 8'C R(50) in %or3ing storage section.
"ter every ile operation7 t2e ile status s2ould be c2ec3ed or allo%able values.
%S!FIL!STAT& can be coded or /!"+ iles to get t2e /!"+ return code (0
bytes)7 /!"+ unction9code (1 byte) and /!"+ eedbac3 code (4 bytes).
Mainframe Refresher Part-1 COBOL-Page: 26
12is is a )9 byte ield in %or3ing storage.
6:!:6/: Clause.
6:!:6/: clause Z6:!:6/: integer "6:" [ can be coded in t2e !:L:C1
statement. 12e number o buers to be allocated or t2e ile is coded 2ere.
By deault t%o buers %ill be allocated i t2e clause is not coded. !ince similar option
is available in ICL7 t2is is not coded in program.
6:!:6/: 1 "6:" allocates one buer7 or t2e ile in t2e !:L:C1 statement.
Deining t2e ile in $'L: !:C1'O& 9 $D
$D FILNAM
6:CO6D'&H +OD: '! /./B.$.$B
6:CO6D CO&1"'&! + CH"6"C1:6! (1O & CH"6"C1:6!)
BLOCO CO&1"'&! R CH"6"C1:6!.6:CO6D! (1O # CH"6"C1:6!.6:CO6D!)
L"B:L 6:CO6D! "6: O+'11:D.!1"&D"6D
D"1" 6:CO6D '! FIL!R)ORD.
51 FIL!R)ORD 8'C R(nnn).
$D96:CO6D CO&1"'&!
't speciies t2e lengt2 o t2e record in terms o bytes. ('t %ill be 6:CO6D
contains m to n CH"6"C1:6! or variable ormat iles)
$D9BLOCO CO&1"'&!
't speciies t2e p2ysical record siSe. 't can be mentioned as number o logical
records O6 number o c2aracters7 t2at is multiple o logical record lengt2. 't is
suggested to code BLOCO CO&1"'&! 5 6:CO6D! so t2at system %ill decide t2e
optimum siSe or t2e ile based on t2e device used or storing t2e ile. BLOCO
CO&1"'&! clause is treated as comments or /!"+ iles.
"dvantage o Bloc3ingP
1.'9O time is reduced as n numbers o records are read into main memory buer
during an '9O.
0.'nter record gap is removed and t2e gap e;ist only bet%een bloc3s. !o memory
%astage due to '6H is avoided.
$D96:CO6D'&H +OD: '!
't can be $ ($'R:D) /(/"6'"BL:) $B($'R:D BLOCO) /B(/"6'"BL: BLOCO:D)
/ariable record ile identiicationP
' t2ere is no recording mode.record contains clause7 it is still possible to
identiy variable lengt2 records. ' t2ere is an OCC=6! depending on clause or t2ere
are multiple 51 levels and every 51 level is o dierent siSe7 t2en t2e ile %ould be o
variable lengt2. +ultiple 51 level in $ile section is an e;ample or implicit redeinition.
$D9L"B:L 6:CO6D! Clause
"s a general rule7 L"B:L 6:CO6D! are !1"&D"6D is coded or Dis3 and 1ape
iles7 L"B:L 6:CO6D! "6: O+'11:D is coded or printer iles. 'n COBOL,-7 t2is
clause is a mandatory clause %2ereas COBOL*5 made t2is as optional.
Mainframe Refresher Part-1 COBOL-Page: 27
$D9D"1" 6:CO6D '! Clause
't is used to name t2e data record(s) o t2e ile. +ore t2an one record can be
coded 2ere.
O8:& !1"1:+:&1
!ynta;P O8:& O8:&+OD: FILNAM
O8:&+OD: can be '&8=1 O=18=1 '9O :R1:&D
'&8=1 9 $ile can be used O&L#9$O696:"D purpose.
O=18=1 9 $ile can be used O&L#9$O69G6'1: purpose.
'9O 9 $ile can be used $O6 6:"D7 G6'1: and 6:G6'1: purpose.
:R1:&D 9 $ile can be used $O6 appending records using G6'1:.
CLO!: statement.
12e used iles are closed using CLO!: statement. ' you donLt close t2e iles7
t2e completion o t2e program closes all t2e iles used in t2e program.
!ynta;P CLO!: FILNAM
O8:& and CLO!: or 1"8: iles 9 "dvanced
' more t2an one ile is stored in a reel o tape7 it is called as multi9ile
volume. G2en one ile is stored in more t2an one reel o tape7 it is called as
multi9volume label. One reel is 3no%n as one volume. G2en t2e end o one volume
is reac2ed7 automatically t2e ne;t volume opens. !o t2ere is no special control is
needed or multi volume iles.
O8:& '&8=1 ile91 ZG'1H &O 6:G'&D T 6:/:6!:D[
O8:& O=18=1 ile90 ZG'1H &O 6:G'&D[
CLO!: ile94 Z\6::LT=&'1U ZG'1H &O 6:G'&DT $O6 6:+O/"L[
CLO!: ile94 ZG'1H &O 6:G'&DTLOCO[
=&'1 and 6::L are synonyms.
"ter opening a 1"8: ile7 t2e ile is positioned at its beginning. G2en opening
t2e ile i t2e clause 6:/:6!:D is coded7 t2en t2e ile can be read in t2e 6:/:6:!:
direction. (8rovided 2ard%are supports t2is eature)
G2en you close t2e ile7 t2e tape is normally re%ound. 12e &O 6:G'&D
clause speciies t2at t2e 1"8: s2ould be let in its current position.
CLO!: statement %it2 6::L option closes t2e current reel alone. !o t2e ne;t
6:"D %ill get t2e irst record o ne;t 6::L. 12is %ill be useul %2en you %ant s3ip all
t2e records in t2e irst reel ater n number o records processing.
!ince 1"8: is se<uential device7 i you create multiple iles in t2e same 1"8:7
t2en beore opening t2e second ile7 irst ile s2ould be closed. "t any point o time7
you can 2ave only one ile is active in t2e program. 'n addition to t2is7 you 2ave to
code +=L1'8L: $'L: clause in t2e '9O control paragrap2 o environment division.
+=L1'8L: $'L: 1"8: CO&1"'&! O=19$'L:1 8O!'1'O& 1
O=19$'L:4 8O!'1'O& 4.
12e iles O=19$'L:1 and O=19$'L:4 used in t2e program are part o a same
1"8: and t2ey e;ist in irst and t2ird position in t2e tape. "lternatively7 t2is
inormation can be passed rom ICL using L"B:L parameter.
Mainframe Refresher Part-1 COBOL-Page: 28
6:"D statement
6:"D statement is used to read t2e record rom t2e ile.
!ynta;P 6:"D FILNAM Z'&1O %s9record[ ZO:# '! FIL!"#$[
Z"1 :&D.'&/"L'D O:# imperative statement1[
Z&O1 "1 :&D.&O1 '&/"L'D O:# imperative statement0[
:&D96:"D
' '&1O clause is coded7 t2en t2e ile is directly read into %or3ing storage
section record. 't is preerred as it avoids anot2er move o ile9section9record to
%or3ing9storage9record ollo%ed by simple 6:"D. 6:"D9'&1O is not preerred or
variable siSe records %2ere t2e lengt2 o t2e record being read is not 3no%n.
O:# '! clause is used %2ile accessing a record randomly using
primary.alternate record 3ey.
"1 :&D and &O1 "1 :&D are used during se<uential 6:"D o t2e ile.
'&/"L'D O:# and &O1 '&/"L'D O:# are used during random read o t2e ile.
Beore accessing t2e ile randomly7 t2e 3ey ield s2ould 2ave a value beore 6:"D.
G6'1: !tatement
Grite statement is used to %rite a ne% record in t2e ile. ' t2e ile is opened
in :R1:&D mode7 t2e record %ill be appended. ' t2e ile is opened in O=18=1 mode7
t2e record %ill be added at t2e current position.
!ynta;P G6'1: FIL!R)ORD Z$6O+ %s9record[
Z'&/"L'D O:# imperative statement1[
:&D9G6'1:
$6O+ clause avoids t2e e;plicit move o %or3ing storage record to ile section record
beore G6'1:.

6:G6'1: !tatement
6:G6'1: is used to update an already read record. 1o update a record in a
ile7 t2e ile s2ould be opened in '9O mode.
!ynta;P 6:G6'1: FIL!R)ORD Z$6O+ %s9record[
Z'&/"L'D O:# imperative statement1[
:&D96:G6'1:
!1"61 !tatement
!1"61 is used %it2 dynamic access mode o inde;ed iles. 't establis2es t2e
current location in t2e cluster or 6:"D &:R1 statement. !1"61 itsel does not
retrieve any record.
!ynta;P !1"61 FILNAM
Mainframe Refresher Part-1 COBOL-Page: 29
O:# is :Q="L 1O.&O1 L:!! 1H"&.H6:"1:6 1H"& 3ey9name
Z'&/"L'D O:# imperative statement1[
:&D9!1"61.
D:L:1: !tatement
D:L:1: is used to delete t2e most recently read record in t2e ile. 1o delete a
record7 t2e ile s2ould be opened in '9O mode.
!ynta;P D:L:1: FILNAM 6:CO6D
Z'&/"L'D O:# imperative statement1[
:&D9D:L:1:
$ile :rror ( Handling
12ere are c2ances or ailure o any ile '9O processing. 12e ailure o an '9O
operation can be accepted or cannot be tolerated. 12e severity o ailure 2as to be
deined in t2e program design stage.
Let us assume t2at %e donLt 2ave any error 2andling in our program. 'n t2is
case7 or e;ample7 i you donLt 2ave a speciic record in t2e ile7 t2e random read o
t2at record %ould immediately terminate t2e program %it2 error Krecord not oundL.
:rror Handling Clauses 8rovided by COBOL.
12e sudden termination can be avoided by 2andling t2is error7 %it2 '&/"L'D
O:# clause o 6:"D. Based on t2e importance o t2e record and business rule7 %e
can continue our program %it2 ne;t record or terminate t2e program properly.
"1 :&D is anot2er error 2andling clause provided by COBOL. But t2ere is no %ay to
2andle all suc2 errors in t2is %ay.
"ssign ile9status and ta3e t2e responsibility.
12e second met2od is7 assigning ile9status to t2e ile in t2e !:L:C1 clause
and c2ec3s t2e ile status ater eac2 and every '9O and ensures t2at t2e value o
status code is one o t2e allo%able values. ' it is not an allo%able return code7 t2en
abnormally end t2e program %it2 error statements t2at %ould be easier to debug.
But %e 2ave to do t2is c2ec3ing ater eac2 and every '9O operation.
12is is +O!1 86:$:66:D :66O6 H"&DL'&H +:1HOD in structured programming.
Declaratives ( =!: statement
COBOL provides an option to group all t2e possible errors o speciic
operation(s) in a place and t2at %ill be automatically invo3ed during t2e respective
operation(s) o any ile. 12is avoids redundant code.
12is is done in D:CL"6"1'/: section o t2e procedure division. D:CL"6"1'/:
s2ould be t2e irst section in t2e procedure division i coded.
86OC:D=6: D'/'!'O&.
D:CL"6"1'/:!.
=!:986OC:D=6: !:C1'O&.
=!: "$1:6 :RC:81'O& 86OC:D=6: O& '&8=1
:66O6986OC:D=6:.
C2ec3 t2e ile9status code or validity.
:&D9D:CL"6"1'/:!.
G2enever t2ere is an error in t2e processing o "&# $'L: opened in '&8=1
mode7 t2en t2e control comes to :66O6986OC:D=6:. 12e validity o error s2ould be
c2ec3ed in t2is paragrap2 and allo% or restrict t2e process do%n7 based on severity
o error code.
Mainframe Refresher Part-1 COBOL-Page: 30
12e complete synta; o =!: statements isP
=!: "$1:6 !1"&D"6D :66O6T:RC:81'O& 86OC:D=6: O&
'&8=1TO=18=1T'9OT:R1:&DT ile91
' '&8=1 is coded7 t2e ollo%ing procedure %ill be e;ecuted or every
operation involved in any ile t2at is opened in '&8=1 mode. O=18=17 '9O and
:R1:&D 2ave t2e same meaning but t2e mode is dierent.
' ile name (ile91) is coded in t2e =!: statement7 t2en all t2e input9output
operation o t2at speciic ile %ill be c2ec3ed.
:66O6 and :RC:81'O& are synonyms.
12e 8rocedure %ritten in a D:CL"6"1'/: section s2ould not reer to any non9
declarative procedure %ritten ater t2e end procedure and vice9versa.
'9O9CO&16OL 9 !"+: "6:" "&D !"+: 6:CO6D "6:"
6:!:6/: clause o !:L:C1 statement speciies t2e number o buers to be
allocated or a ile. !"+: "6:" allo%s more t2an one ile to use t2e same buer
area. 12is %ill be very useul %2en t2e program must %or3 %it2 a limited memory
space. But t2e problem is only one ile s2ould be open at a time i !"+: "6:" is
coded.
!ynta;P !"+: "6:" $O6 ile91 ile90 ile94.
' !"+: 6:CO6D "6:" is coded7 t2en t2e buer is not s2ared but only t2e
record area is s2ared. !o more t2an one ile can be in open state. Ge s2ould be
careul %2ile illing in t2e record area o t2e output ile. 12is may destroy t2e record
read most recently.
!ynta;P !"+: 6:CO6D "6:" $O6 ile91 ile90 ile94.
!"+: !O61 "6:" allo%s more t2an one sort.merge %or3 iles to use t2e
same area. 12e sort %or3 iles are automatically allocated %2en ile is opened and
de9allocated %2en ile is closed. "s t2e sort ile is automatically opened and closed
during a !O61 and t%o sort iles cannot be opened at a time7 t2is clause may not be
useul.
!ynta;P !"+: !O61T!O619+:6H: "6:" or ile91 ile90.
$ile91 or ile90 s2ould be a !D ile.
'9O CO&16OL9 6:6=& Clause
6:6=& O& rescue $O6 :/:6# integer 6:CO6D! on ile91
12is %ill cause c2ec3point to be ta3en or every interger91 records processing o
ile91. ' t2e program "B:&D:D beore t2e complete processing o t2e ile917 t2en
t2e program %ill restart rom integer@1
!1
record instead o irst record. 12e rescue
ile details s2ould be mentioned outside t2e program and it varies rom installation to
installation.
:&16# statement
:&16# statement establis2es an alternate :&16# point in a COBOL called
sub9program. G2en a C"LL statement naming t2e alternate entry point is e;ecuted
in a calling program7 control is transerred to t2e ne;t e;ecutable statement
ollo%ing t2e entry statement. :;cept %2en a C"LL statement reers to an entry
name7 t2e :&16# statements are ignored at run9time.
+atc2ing Logic
' you 2ave been given t%o iles o similar type7 say master and transaction
ile and you are re<uested to update t2e master ile %it2 transaction ile inormation
Mainframe Refresher Part-1 COBOL-Page: 31
or e;isting records and prepare a report o ne% transactions and deleted
transactions7 t2en you s2ould go or %2at is called +atc2ing logic. 12is is also 3no%n
as co9se<uential processing.
!ort bot2 t2e iles on 3ey and compare t2e 3eys. ' t2e 3eys are matc2ing
t2en update t2e ile. ' you ind any record t2at is ound in transaction but not in
master ile7 t2en t2at is ne% addition and t2e reverse is deletion. ' t2e master 3ey is
greater t2an transaction 3ey7 t2en t2at corresponds to t2e irst case and reverse is
t2e second case.
12is can be easily done in ICL using 'C:1OOL. 6eer ICL section.
$'L: !1"1=! COD:!
't is a t%o9byte %or3ing storage item. 12e irst byte denotes t2e general
category %2ereas second byte denotes t2e particular type o error message under
t2at category.
* Success+ul O,N-RAD-%RIT Operation
5 !uccessul completion
0 Duplicate 3ey %as detected %2ic2 is allo%ed as per deinition o "'R.
- Lengt2 o record Wust 6:"D didnLt conorm to t2e i;ed lengt2 attributes or
t2e ile.
5 6eerenced Optional ile is not present during O8:&. ' open mode is '9O or
:R1:&D7 t2en ile %ill be created.
, Open or Close statement is e;ecuted %it2 a p2rase t2at implies a tape ile (e;
&O 6:G'&D) %2ereas t2e ile is not in 1"8:.
$ %hen AT ND con.ition +ails
5 !e<uential 6:"D is attempted on
1.ater t2e end o ile is reac2ed
0.optional ile t2at is not present.
- !e<uential 6:"D %as attempted or a relative ile and 66& is larger t2an t2e
ma;imum t2at can be stored in t2e relative 3ey data item.
* %hen IND/ "ey +ails
1 !e<uence error e;ists or se<uentially accessed inde; ile.
0 "ttempt %as made to %rite a record t2at %ould create a duplicate 3ey.
4 6ecord not ound.(or 3eyed random access)
- !pace not ound or G6'1:
' ,ermanent Open error
5 Opening a non9optional ile t2at %as not present.
, Open mode is not permitted.
* Open issued or a ile t2at %as closed previously %it2 loc3
9 $ile attribute mismatc29Open ailed.
0 Lo1ic error in openin1-closin1-.eletin1
1 O8:& a opened ile.
0 CLO!: attempted or not opened ile.
4 'O statement beore t2e current 6:G6'1:.D:L:1: is not successul.
- 6:G6'1: attempt %it2 invalid lengt2
, 6:"D ile %2ic2 is not opened in '&8=1 or '9O mode
* G6'1: ile %2ic2 is not opened in '9O O=8=1 or :R1:&D mode
9 D:L:1: or 6:G6'1: ile %2ic2 is not opened in '9O mode.
Mainframe Refresher Part-1 COBOL-Page: 32
2 Implementation .e+ine.
1 /!"+ pass%ord error
0 Logic error
4 /!"+ resource unavailable
) &o DD statement speciied or /!"+ ile.
, $ile integrity veriied or /!"+ ile.
COBOL CO+8'L"1'O&
!#!86'&1
8"6+ (Compiler listing)
(Compiler
Options)
!#!'& !#!L'&(ObWect +odule)
(!ource)
!#!L'B 8"6+
(Copyboo3 Library) (Lin3
edit Options)
!#!L+OD
(Load +odule)
!#!86'&1 !#!L'B
(Lin3 edit messages) (!ubroutine Library)
CO+8'L"1'O& ICLP
..!+!RL*)B IOB 7VCO+8'L"1'O& ICLV7 +!HCL"!!AQ7+!HL:/:LA(171)7CL"!!AC
..CO+8'L:1 :R:C 8H+A'H#C6C1L7 8"6+ALR6:$7"8O7"D/7+"87L'!1)76:H'O&A5+
..!1:8L'B DD D!&A!#!1.COB0L'B7D'!8A!H6
..!#!'& DD D!&A!+!RL*).1:!1.COBOL(!"+8H+51)7D'!8A!H6
..!#!L'B DD D!&A!+!RL*).CO8#L'B7D'!8A!H6
..!#!86'&1 DD !#!O=1A>
..!#!L'& DD D!&ANNLO"D!:17 DCBA(6:C$+A$B7L6:CLA*57BLO!'?:A4055)7
.. D'!8A(&:G78"!!)7=&'1A!#!D"7!8"C:A(C#L7(5715)76L!:)7
..!#!=11 DD =&'1AN!#!D"7!8"C:A(C#L7(1715)) AE )o.e S#S3T& to 3T4
..L'&O:D11 :R:C 8H+A':GL7CO&DA(-7L1)
..!#!L'& DD D!&ANNLO"D!:17 D'!8A(OLD7D:L:1:)
..!#!L+OD DD D!&ANNHO!:1(!"+8H+51)7D'!8A(&:G78"!!)7=&'1A!#!D"
'H#C6C1L
(COBOL CO+8'L:6)
':GL
(Lin3 :ditor)
Mainframe Refresher Part-1 COBOL-Page: 33
.. !8"C:A(C#L717171))
..!#!L'B DD D!&A!+!RL*).LO"DL'B7D'!8A!H6
..!#!=11 DD =&'1A!#!D"7!8"C:A(C#L7(1715))
..!#!86'&1 DD !#!O=1A>
..>>> :R:C=1: 1H: 86OH6"+ >>>
..:R:C=1:1 :R:C 8H+A>.L'&O:D11.!#!L+OD7CO&DA(-7L1)76:H'O&A5+
..!1:8L'B DD D!&A!+!RL*).LO"DL'B7D'!8A!H6
.. DD D!&A!#!1.!C::6=&7D'!8A!H6
..!#!O=1 DD !#!O=1A>
..!#!86'&1 DD !#!O=1A>

Compiler Options
12e deault options t2at %ere set up %2en your compiler %as installed are in
eect or your program unless you override t2em %it2 ot2er options. 1o c2ec3 t2e
deault compiler options o your installation7 do a compile and c2ec3 in t2e
compilation listing.
Gays o overriding t2e deault options
1.Compiler options can be passed to COBOL Compiler 8rogram ('H#C6C1L) t2roug2
t2e 8"6+ in ICL.
0.86OC:!! or CBL statement %it2 compiler options7 can be placed beore t2e
identiication division.
4.' t2e organiSation uses any t2ird party product or its o%n utility t2en t2ese options
can be coded in t2e pre9deined line o t2e utility panel.
8recedence o Compiler Options
1. (Hig2est precedence). 'nstallation deaults7 i;ed by t2e installation.
0. Options coded on 86OC:!! .CBL statement
4. Options coded on ICL 8"6+ parameters
-. (Lo%est 8recedence). 'nstallation deaults7 but not i;ed.
12e complete list o compiler option is in t2e tableP
"spect Compiler Option
!ource Language "8O!17 C+8607 C=66:&C#7 DBC!7 L'B7 &=+B:67
Q=O1:7 !:Q=:&C:7 GO6D
Date 8rocessing D"1:86OC7 '&1D"1:7 #:"6G'&DOG
+aps and Listing L"&H="H:7 L'&:CO=&17 L'!17 +"87 O$$!:17 !O=6C:7 !8"C:7
1:6+'&"L7 /B6:$7 R6:$
ObWect Dec3
generation
CO+8'L:7 D:CO7 &"+:7 OBI:C17 8H+&"+:
ObWect Code
Control
"D/7 "GO7 DLL7 :R8O61"LL7 $"!1!617 O81'+'?:7 &=+86OC7
O=1DD7 16=&C7 ?GB
Debugging D=+87 $L"H7 $L"H+'H7 $L"H!1D7 !!6"&H:7 1#8:CHO
Ot2er "D"1"7 "&"L#?:7 :R'17 'DLH:&
"D/P 't is meaningul i your program 2as any printer iles %it2 G6'1:.."D/"&C'&H
3ey%ord. 12e compiler adds one byte prei; to t2e original L6:CL o printer iles or
Mainframe Refresher Part-1 COBOL-Page: 34
printing control purpose. ' you are manually populating printing control c2aracter in
t2e program7 t2en you can compile your program %it2 &O"D/.
D#&"+P =se D#&"+ to cause separately compiled programs invo3ed t2roug2 t2e
C"LL literal statement to be loaded dynamically at run time. D#&"+ causes dynamic
loads (or C"LL) and deletes (or C"&C:L) o separately compiled programs at obWect
time. "ny C"LL i.enti+ier statements t2at cannot be resolved in your program are
also treated as dynamic calls. G2en you speciy D#&"+7 6:!'D:&1 is also put into
eect.
L'!1.O$$!:1P L'!1 and O$$!:1 are mutually e;clusive. ' you use bot27 L'!1 %ill be
ignored. L'!1 is used to produce listing a listing o t2e assembler language e;pansion
o your code. O$$!:1 is used to produce a condensed 8rocedure Division listing.
Git2 O$$!:17 t2e procedure portion o t2e listing %ill contain line numbers7
statement reerences7 and t2e location o t2e irst instruction generated or eac2
statement. 12ese options are useul or solving system "B:&D!. 6eer ICL session
or more details.
+"8P =se +"8 to produce a listing o t2e items you deined in t2e Data Division.
!!6"&H:P ' t2e program is compiled %it2 !!6"&H: option7 t2en any attempt to
reer an area outside t2e region o t2e table %ill abnormally terminate %it2
protection e;ception7 usually !5C-.'t also avoids any meaningless operation on
reerence modiication li3e negative number in t2e starting position o reerence
modiication e;pression. ' t2e program is compiled %it2 &O!!6"&H:7 t2en t2e
program may proceed urt2er %it2 Wun3 or irrelevant data. !o usually t2e programs
are compiled %it2 !!6"&H: during development and testing.
6:&1P " program compiled as 6:&1 is generated as a reentrant obWect module. C'C!
programs s2ould be compiled %it2 6:&1 option to s2are t2e same copy o t2e
program by multiple transactions (+ultit2reading)
6:!'D:&1P =se t2e 6:!'D:&1 option to re<uest t2e COBOL Library +anagement
$eature. (12e COBOL Library +anagement $eature causes most COBOL library
routines to be located dynamically at run time7 instead o being lin39edited %it2 t2e
COBOL program.).C'C! 8rograms s2ould be compiled %it2 6:!':&1 option.
R6:$P =se R6:$ to get a sorted cross9reerence listing. :BCD'C data9names and
procedure9names %ill be listed in alp2anumeric order. 't also includes listing7 %2ere
all t2e data9names t2at are reerenced %it2in your program and t2e line number
%2ere t2ey are deined. 12is is useul or identiying t2e ields t2at are deined but
not used any%2ere ater t2e development o ne% program.

Mainframe Refresher Part-1 COBOL-Page: 35
1!O Commands rom COBOL program
CBL APOST,NODECK,OBJECT,BUF(10000),DYNAM => Compile op!io" o#ei$e
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FUNCT&ON = T'i( ()mple po*)m $emo"(!)!e( 'o+ !o i"#o,e %
% TSO -omm)"$( .om ) COBOL po*)m /(i"* %
% (!)"$)$ TSO (e#i-e( )( $o-/me"!e$ i" !'e %
% TSO0E Po*)mmi"* Se#i-e( m)"/)l1 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
&$e"!i.i-)!io" Di#i(io"1
Po*)m2&D1 SMSTSOE31

D)!) Di#i(io"1
4o,i"*2S!o)*e Se-!io"1
01 Fille1
05 +(2$/mm6 Pi- (7(8) Comp1
05 +(2e!/"2-o$e Pi- (7(8) Comp1
05 +(2e)(o"2-o$e Pi- (7(8) Comp1
05 +(2i".o2-o$e Pi- (7(8) Comp1
05 +(2-ppl2)$$e(( Pi- (7(8) Comp1
05 +(2.l)*( Pi- 9(:) 3)l/e 9;00010001;1
05 +(2</..e Pi- 9(=5>)1
05 +(2le"*!' Pi- (7(8) Comp 3)l/e =5>1

Po-e$/e Di#i(io"1
%2222222222222222222222222222222222222222222222222222222222222222%
% C)ll &KJTSOE3 !o -e)!e !'e TSO0E e"#io"me"! %
%2222222222222222222222222222222222222222222222222222222222222222%
CALL ;&KJTSOE3; U(i"* +(2$/mm6,+(2e!/"2-o$e,+(2e)(o"2-o$e,
+(2i".o2-o$e,+(2-ppl2)$$e((1
&F +(2e!/"2-o$e > ?eo
D&SPLAY ;&KJTSOE3 F)ile$, @e!/"2-o$e=; +(2e!/"2-o$e
; @e)(o"2-o$e=; +(2e)(o"2-o$e
;&".o2-o$e=; +(2i".o2-o$e
MO3E +(2e!/"2-o$e !o @e!/"2-o$e
STOP @UN1
%2222222222222222222222222222222222222222222222222222222222222222%
% B/il$ !'e TSO0E -omm)"$ i" +(2</..e %
%2222222222222222222222222222222222222222222222222222222222222222%

MO3E ;ALLOCATE DD(SYSPUNCA) SYSOUT AOLD; !o +(2</..e1

%2222222222222222222222222222222222222222222222222222222222222222%
% C)ll !'e TSO0E Se#i-e @o/!i"e !o eBe-/!e !'e TSO0E -omm)"$ %
%2222222222222222222222222222222222222222222222222222222222222222%
CALL ;&KJEFTS@; U(i"* +(2.l)*(,+(2</..e,+(2le"*!'
+(2e!/"2-o$e,+(2e)(o"2-o$e,+(2$/mm61
Mainframe Refresher Part-1 COBOL-Page: 36
&F +(2e!/"2-o$e > ?eo
D&SPLAY ;&KJEFTS@ F)ile$, @e!/"2-o$e=; +(2e!/"2-o$e
; @e)(o"2-o$e=; +(2e)(o"2-o$e
MO3E +(2e!/"2-o$e !o @e!/"2-o$e
STOP @UN1

%2222222222222222222222222222222222222222222222222222222222222222%
% C'e-, !')! !'e ALLOCATE -omm)"$ +o,e$ %
%2222222222222222222222222222222222222222222222222222222222222222%
D&SPLAY ;ALLOCATE 4o,e$ C ; Upo" S6(p/"-'1

STOP @UN1
'ntervie% Questions('Q)P
> !ays importance and possibility o t2e <uestion in an intervie%.
1.Dierence bet%een &e;t !entence and Continue >>>
0.Comp7 Comp917 Comp90 and Comp94 dierence and 2o% many bytes occupied by
eac2. !2ould 3no% 2o% to read CO+894 data. >>>>>
4.'dentiying and ma3ing !tatic and Dynamic call >>>>>
-.Binary and !e<uential searc2 and %2en you preer %2at] >>>>>
5.G2at are t2e various %ays o passing data rom ICL to 8rogram and 2o% to receive
t2em in 8rogram] >>>>>
).Dierence bet%een COBOL,- (O!./! COBOL) and COBOL*5 (/! COBOL0) >>>>
,.!ubscript and 'nde; dierence and %2en you preer %2at] >>>>
*.6eerence modiication. >>>>
9.Compiler and Lin3 edit option ( !!6"&H: +"8 L'!1 O$$!:1 6:&1 6:!'D:&1
D#&"+ and "+OD:.6+OD: >>>
15.Ho% to ma3e a call by content in COBOL] >>>
11.Ho% do you set return code rom t2e program] >>>
10.Case structure7 !ub9string7 Do %2ile7 Do =ntil7 BLL e<uivalent in COBOL >>>
14.Dierence bet%een section and paragrap2 >>>>>
1-.Can occurs be coded in 51 level] >>>>>
15."re multiple 51 levels supported in ile section] >>
1)./arious %ays o overriding deault compiler options >>
1,.!ort algorit2ms >>
1*.Ho% to get t2e actual lengt2 o alp2anumeric item] >>
19.G2at is =19! means %it2 respect to !:L:C1 statement] >
05.Can ' re%rite a se<uential ile in 1"8:] >
01.CO+894 items are al%ays better t2an CO+8 in terms o memory. #es.&o >>
00.G2ic2 /!"+ type is astest] 6elative 3ey is part o ile section] >>
04.Ho% to create a report in COBOL program] >>>
0-.Ho% to submit a ICL rom COBOL program] >>>>
05.G2at is !#&C Clause] >>
0).G2at is in line 8:6$O6+ and %2en %ill you use it] >>>>
0,.G2at is '&!8:C1 statement] >>>
0*.1o use !:"6CH "LL7 t2e table s2ould be in sorted order. ' am loading t2e table
rom one o t2e 8D! members. 12e 8D! member data is not in sorted order. Ho% %ill
' load t2e table in !O61:D order] #ou s2ould not sort in ICL. >>
09.G2at is t2e purpose o =!: statement] >
45.G2at are !"+: "6:" and !"+: 6:CO6D "6:"] >
Mainframe Refresher Part-1 COBOL-Page: 37
41. 's dynamic allocation possible in COBOL] ' yes7 Ho%] >
40. G2at is t2e dierence bet%een O& !'?: :66O6 and O& O/:6$LOG] >
44.Ho% to s%ap t%o variables %it2out t2ird variable] >
4-.G2at is limit o lin3age section] >
"ns%ers or selected <uestionsP
G2at is t2e limit o %or3ing storage and lin3age section limit] ('Q 4-)
Gor3ing storage and Lin3age section limit o COBOL*5 is 10*+B (COBOL,-9
1+B)
,,7519-9 level item limit in COBOL*5 is 1)+B (COBOL,-91+B)
Ho% to s%ap t2e values o t%o variables %it2out an intermediate variable]('Q 44)
Let t2e variables be " and B
Gay 1P CO+8=1: " A "@B Gay 0P CO+8=1: "A">B
CO+8=1: B A "9B CO+8=1: BA".B
CO+8=1: " A "9B CO+8=1: "A".B
' 2ave retrieved a value rom DB0 /"6CH"6 column. (:;P G!9/"6 A Kmut2uBsaraBK
B is 19n spaces.) Ho% to get t2e lengt2 o t2e G!9/"6 in COBOL program] ' s2ould
not count rig2t 2and spaces. ('Q 05)
L:&H1H unction counts space also as a c2aracter. !o %e cannot use t2at
unction or our purpose. '&!8:C1 is also not useul as t2e string may contain 19 n
spaces in bet%een and t2at needs to be counted. !o t2e logic %ould be M 6ead rom
rig2t until you read irst noon9space c2aracterM.
8:6$O6+ /"6#'&H G!9!=B9&"+: $6O+
L:&H1H O$ G!9/"6 B# 91
=&1'L :&D9$O=&D O6 G!9!=B9&"+: A 5
'$ G!9&"+:9CHO(G!9!=B9&"+:P1) &O1 :Q="L 1O !8"C:
+O/: V#V 1O G!9:&D9O$9$':LD
D'!8L"# VL:&H1H V G!9!=B9&"+:
:&D9'$
:&D98:6$O6+
Ho% to pass user return code and user "B:&D rom t2e COBOL program to t2e ICL]
6:1=6&9COD: is a special register and its content is moved to register15 %2en t2e
control is given bac3 to O!. !o move t2e return code to t2is register in t2e program.
:;P +O/: 1555 to 6:1=6&9COD:.
12is sets return code as 1555 or t2e step t2at e;ecutes t2is program.
$or "B:&D7 you s2ould call your installation speciic assembler routine or 'LBO"B&5
%it2 t2e "B:&D code you %ant.
C"LL K'LBO"B&5L =!'&H G!9"B9COD:.
Mainframe Refresher Part-1 COBOL-Page: 38
G!9"B:&D9COD: is t2e variable t2at 2as "B:&D9COD:. 't is a 2al %ord
binary.
G2at s2ould be t2e L6:CL o printer iles]
=se 144 c2aracter records in your program and set t2e print control c2aracter
yoursel. 'n t2is case your ICL %ould 2ave 6:C$+A$B7 L6:CLA144
=se 140 c2aracter records in t2e program and 2ave G6'1: ...."D/"&C'&H
put in t2e print control. #ou need t2e compiler option "D/ or t2is and t2e ICL %ould
2ave 6:C$+A$B"7L6:CLA144.........
G2at are t2e sort algorit2ms] ('Q 1, and 0*)
Bubble !ortP Consecutive elements are compared and 3eys o t%o elements are not
in proper order7 t2ey are s%apped. 'n t2e irst pass7 t2e 3ey %it2 largest value %ill
be moved to t2e last position and n91 passes needed to sort t2e %2ole table.
'n bet%een7 i any pass results no interc2ange it implies t2at t2e table is in sorted
order.
"rrayP 1 05 9 55 *
$irst 8assP (+a;imum - comparisons or 5 elements)
17 059Eno c2ange7 05 N 9 9E 05 is great so s%ap (1 9 05 55)7
05 N 55 9E no c2ange7 55 N * 9E 55 is great7 so s%ap. (1 9 05 * 55)
!econd 8assP (1 9 05 * 55) 9 (+a;imum 4 comparison or 5 elements)
1 N 99E no c2ange7 9 N 05 9E no c2ange7 05 N * 9E 05 is great so s%ap
(1 9 * 05 55)
12ird 8assP (1 9 * 05 55) ( (+a;imum 0 comparisons or 5 elements)
1 N 9 9E no c2ange7 9 N *9E c2ange (1 * 9 05 55)
$ourt2 8assP (1 * 9 05 55) ( (+a;imum 1 comparison or 5 elements)
1 N 9 9E no c2ange
&oteP #ou can come out o sort %2en you ind Kno c2angeL in all t2e
comparisons o a pass.
!2uttle !ortP 'n t2e irst pass only irst t%o elements are compared and sorted and in
t2e second pass7 t2ird element is compared %it2 t%o and one and it is placed in t2e
rig2t position. 'n t2e it2 pass7 it assumes t2at ' elements are in already sorted order7
proceeds to sort t2e irst ('@1) elements by comparing '@1 t2 element %it2 '7 and '
%it2 '91 and so on until top o t2e table is reac2ed or no9e;c2ange in a comparison.
"rrayP 1 05 9 55 *
$irst 8assP 1%o elements (1 05) 9 +a;imum 1 comparison
17 059Eno c2ange
!econd 8assP 12ree elements (1 05 9) ( +a;imum 0 comparisons
9 N 05 9E c2ange (1 9 05) 9 N 1 9E no c2ange
12ird 8assP $our elements (1 9 05 55) ( +a;imum 4 comparisons
55 N 05 9E no c2ange and stop (no need or any ot2er comparison)
$ourt2 8assP $ive elements (1 9 05 55 *) ( +a;imum - comparisons
* N 55 9E c2ange ( 1 9 05 * 55) 7 * N 059E C2ange ( 1 9 * 05 55)
Mainframe Refresher Part-1 COBOL-Page: 39
* N 9 9E C2ange (1 * 9 05 55) 7 * N 1 9E no c2ange and stop.
&oteP #ou can come out o pass i you ind one Kno c2angeL
!2uttle sort is better t2an bubble sort or sorting arrays %it2 more t2an 15 elements.
CO+894 items are al%ays better t2an CO+8 %it2 respect to memory usage ('Q 01)]
&o. CO+8 items occupy less space t2an CO+894 items at boundaries.
8'C !9(5-) CO+8 occupies 0 bytes %2ereas 8'C !9(5-) CO+894 occupies 4 bytes.
8'C !9(59) CO+8 occupies - bytes %2ereas 8'C !9(59) CO+894 occupies 5 bytes.
8'C !9(1*) CO+8 occupies * bytes %2ereas 8'C !9(1*) CO+894 occupies 15 bytes.
' 2ave a O!D! !tudents ile %it2 - bytes 3ey. $irst t%o9bytes contain class number
and ne;t t%o9bytes contain student number. ' %ant to read all t2e students in class
K50L. Ho% %ill you do t2at]
"llocate t2e ile %it2 dynamic access mode. +ove K50L to irst t%o9bytes o t2e
3ey and lo%9values to ne;t t%o9bytes o t2e 3ey. #ou can do t2ese moves by
reerence modiication operator or de9grouping t2e our9byte ield into t%o t%o9byte
ields in t2e ile section.
'ssue t2e !1"61 command %it2 O:# '! H6:"1:6 1H"& clause. !tart reading
t2e ile in loop until irst t%o9bytes is not e<ual to 0.
&O1:!
Mainframe Refresher Part-1 COBOL-Page: 40
&O1:!
Mainframe Refresher Part-1 COBOL-Page: 41

S-ar putea să vă placă și