Cobol-Refresher.doc

download Cobol-Refresher.doc

of 40

Transcript of Cobol-Refresher.doc

  • 8/9/2019 Cobol-Refresher.doc

    1/40

    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)

    2is boo3 is %ritten based on 'B+ COBOL or O!49 /060.

    !peciality.1. $irst language developed or commercial application development7 %2ic2 can

    eiciently 2andle millions o data.0. 8rocedure Oriented Language 8roblem is segmented into several tas3s.

    :ac2 tas3 is %ritten as a 8aragrap2 in 8rocedure Division and e;ecuted in alogical se

  • 8/9/2019 Cobol-Refresher.doc

    2/40

    Mainframe Refresher Part-1 COBOL-Page: 2

    Divisions in COBOL.2ere 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.

    2is is t2e irst division and t2e program is identiied 2ere. 8aragrap286O6"+'D ollo%ed by userdeined name is mandatory. "ll ot2er paragrap2s are

    optional and used or documentation. 2e lengt2 o userdeined name or 'B+COBOL is :'H.

    'D:&'$'C"'O& D'/'!'O&.

    86O6"+'D. 86O6"+ &"+:."=HO6. CO++:& :&6#.

    '&!"LL"'O&. CO++:& :&6#.D":G6':&. CO++:& :&6#.

    D":CO+8'L:D. CO++:& :&6#.!:C=6'#. CO++:& :&6#.

    !ecurity does not pertain to t2e operating system security7 but t2einormation 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 inormationabout t2e 2ard%are or computer e

  • 8/9/2019 Cobol-Refresher.doc

    3/40

    Mainframe Refresher Part-1 COBOL-Page: 3

    'nputOutput !ection.

    't contains inormation regarding t2e iles to be used in t2e program andit consists o t%o paragrap2s $'L:CO&6OL N 'O CO&6OL.

    $'L: CO&6OL. $iles used in t2e program are identiied in t2is paragrap2.'O CO&6OL. '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: !:C'O& describes t2e record structure o t2e iles.

    GO6'&!O6": !:C'O& is used to or deine intermediate variables.L'&": !:C'O& is used to access t2e e;ternal data.

    :;P Data passed rom ot2er programs or rom8"6+ o ICL.

    Literals7 Constants7 'dentiier7

    1. Literal is a constant and it can be numeric or nonnumeric.0. &umeric literal can 2old 1* digits and nonnumeric literal can 2old 1 c2aracters

    in it. (COBOL,- supports 10 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

  • 8/9/2019 Cobol-Refresher.doc

    4/40

    Mainframe Refresher Part-1 COBOL-Page: 4

    $'LL:6G2en 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 ot2e procedure division.

    8'C=6: Clause

    Describes t2e attributes o variable.

    &umeric 9 (Digit)7 / ('mplied decimal point)7 ! (!ign)

    &umeric :dited @ (8lus !ign)7 (+inus !ign)7 C6 DB (Credit Debit !ign)

    . (8eriod)7 b (Blan3)7 K7(comma)7 (?ero)7 (!las2)

    BL"& GH:& ?:6O ('nsert blan3 %2en data value is )7? (?:6O suppression)7 > ("!:6'!)7 (Currency !ign)

    &on &umeric " (alp2abet)7 B (Blan3 insertion C2aracter)7 R("lp2a numeric)7

    (DBC!)

    :;clusive sets 1. @ C6 DB

    0. / K. 4. @ ? > (But Can appear as irst place and > as

    loating. >>>.>>)

    DBC! (Double Byte C2aracter !et) is used in t2e applications t2at support largec2aracter 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

  • 8/9/2019 Cobol-Refresher.doc

    5/40

    Mainframe Refresher Part-1 COBOL-Page: 5

    /"L=: Clause

    't is used or initialiSing data items in t2e %or3ing storage section. /alue oitem must not e;ceed picture siSe. 't cannot be speciied or t2e items %2ose siSe is

    variable.!ynta;P /"L=: '! literal.

    /"L=:! "6: literal1 H6= T H6O=H literal0/"L=:! "6: literal17 literal0

    Literal can be numeric %it2out

  • 8/9/2019 Cobol-Refresher.doc

    6/40

    Mainframe Refresher Part-1 COBOL-Page: 6

    5 G!D"# 8'C 9(0).

    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 beingrenamed. But all 6:&"+:! entries associated %it2 one logical record must

    immediately ollo% t2at recordVs last data description entry. 6:&"+:! cannot bedone or a 17 ,,7 ** or anot2er entry.

    1 G!6:8!O&!:.5 G!CH"61-4 8'C R(4).

    5 G!CH"6- 8'C R(-). "DD6:8!O&!: 6:&"+:! G!CH"61-4.

    CO&D''O& name

    't is identiied %it2 special level K**. " condition name speciies t2e value t2ata ield can contain and used as abbreviation in condition c2ec3ing.

    1 !:R 8'C R.** +"L: /"L=: K1

    ** $:+"L: /"L=: K0 K4.'$ !:RA1 can also be coded as '$ +"L: in 8rocedure division.

    K!: $:+"L: O 6=: 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=!'$':D 6'H2is 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 tostore t2e table values and access t2em %it2 subscript or inde;. Detail e;planation is

    given in able Handling section.

    L'&": !:C'O&'t is used to access t2e data t2at are e;ternal to t2e program. ICL can send

    ma;imum 1 c2aracters to a program t2ru 8"6+. Lin3age section +=! 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 sot2ere are c2ances o 0 bytes data truncation in t2e actual ield.

    1 LD"". 5 LL:&H 8'C !9(-) CO+8.(%2en data coming orm ICL)

    5 L/"6'"BL: 8'C R(*).L'&": section o subprograms %ill be e;plained later.

  • 8/9/2019 Cobol-Refresher.doc

    7/40

    Mainframe Refresher Part-1 COBOL-Page: 7

    8rocedure Division.

    2is is t2e last division and business logic is coded 2ere. 't 2as userdeinedsections and paragrap2s. !ection name s2ould be uni

  • 8/9/2019 Cobol-Refresher.doc

    8/40

    Mainframe Refresher Part-1 COBOL-Page: 8

    Group Move ruleG2en +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. 2is is regardless o t2e description o t2e elementary items

    constituting t2e group item.

    !amples or understanding +O/: statement (+O/: " O B)

    8icture o " /alue o " 8icture o B /alue o B ater

    +ove

    8'C 99/99 10.45 8'C 999/99 10.45

    8'C 99/99 10.45 8'C 9999/9999 10.45

    8'C 99/999 10.4-5 8'C 9/99 0.4-

    8'C9(5)/9(4) 5-401.5-4 8'C 9(4)/9(4) 401.5-4

    8'C 9(-)/9(0) 04.0- 8'C ???99.9 04.0

    8'C 99/99 .4- 8'C .99 .4-8'C R(-) +=!" RBRBRB + = !

    "6'H+:'C /:6B!

    "ll t2e possible arit2metic operations in COBOL using "DD7 !=B6"C7+=L'8L# and D'/'D: are given belo%P

    "rit2metic Operation " B C D

    "DD " O B " "@B

    "DD " B C O D " B C "@B@C@D

    "DD " B C '/'& D " B C "@B@C

    "DD " O B C " "@B "@C

    !=B6"C " $6O+ B " B"!=B6"C " B $6O+

    C

    " B C("@B)

    !=B6"C " B $6O+

    C '/'& D

    " B C C("@B)

    +=L'8L# " B# B " ">B

    +=L'8L# " B# B'/'& C

    " B ">B

    D'/'D: " '&O B " B"

    D'/'D: " '&O B

    '/'& C

    " B B"

    D'/'D: " B# B

    '/'& C

    " B "B

    D'/'D: " '&O B

    '/'& C6:+"'&D:6 D

    " B 'nteger (B") 'nteger

    remainder

    '/'& is used in t2e ollo%ing casesP

    1.o retain t2e values o operands participating in t2e operation.0.2e resultant value o operation e;ceeds any o t2e operand siSe.

  • 8/9/2019 Cobol-Refresher.doc

    9/40

    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'C=6: clause speciication o t2e receiving ield. 't is usually coded ater t2e ieldto be rounded. 't is prei;ed %it2 6:+"'&D:6 3ey%ord O&L# in D'/'D: operation."DD " B '/'& C 6O=&D:D.

    D'/'D:..6O=&D:D 6:+"'&D:6CautionP Dont use or intermediate computation.

    O& !'?: :66O6

    ' "A0 (8'C 9(0)) and BA9 (8'C 9(0))7 "DD " O B %ill result 1 in B

    %2ere t2e e;pected value in B is 11. O& !'?: :66O6 clause is coded to trap suc2siSe 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 bee;ecuted.

    "DD " O B O& !'?: :66O6 D'!8L"# K:66O6X.

    CO+8=:Comple; arit2metic operations can be carried out using CO+8=: statement.

    Ge can use arit2metic symbols t2an 3ey%ords and so it is simple and easy to code.@ $or "DD7 or !=B6"C7 > or +=L'8L#7 or D'/'D: and >> or e;ponentiation.

    6uleP Let to rig2t 1.8arent2eses0.:;ponentiation

    4.+ultiplication and Division-."ddition and !ubtraction

    CautionP G2en 6O=&D:D is coded %it2 CO+8=:7 some compiler %ill do rounding

    or every arit2metic operation and so t2e inal result %ould not be precise.

    ,, " 8'C 999 /"L=: 1CO+8=: " 6O=&D:D A ("@0.95) >1.99

    6esultP (6O=&D:D(6O=&D:D(10.95) > 6O=&D:D(1.99)) A10 or 6O=&D:D(1-0.405) A 1-0

    !o t2e result can be 10 or 1-0.Be cautious %2en using 6O=&D:D 3ey%ord%it2 CO+8=: statement.

    "ll arit2metic operators 2ave t2eir o%n e;plicit scope terminators. (:&D"DD7

    :&D!=B6"C7 :&D+=L'8L#7 :&DD'/'D:7 :&DCO+8=:). 't is suggested to use

    t2em.CO66:!8O&D'& is available or "DD and !=B6"C only.

    '&''"L'?:/"L=: clause is used to initialiSe t2e data items in t2e %or3ing storage

    section %2ereas '&''"L'?: is used to initialiSe t2e data items in t2e proceduredivision.

    '&''"L'?: sets t2e alp2abetic7 alp2anumeric and alp2anumericedited itemsto !8"C:! and numeric and numericedited items to ?:6O. 2is can be overridden

    by 6:8L"C'& option o '&''"L'?:. $'LL:67 OCC=6! D:8:&D'& O& items are notaected.

  • 8/9/2019 Cobol-Refresher.doc

    10/40

    Mainframe Refresher Part-1 COBOL-Page: 10

    !ynta;P '&''"L'?: identiier16:8L"C'& ("L8H"B:'C"L8H"&=+:6'C"L8H"&=+:6'C:D':D

    &=+:6'C&=+:6'C:D':D)D"" B# (identiier0 Literal0)

    "CC:8"CC:8 can transer data rom input device or system inormation contain in

    t2e reserved data items li3e D":7 '+:7 D"#."CC:8 G!/"61 ($6O+ D":'+:D"#OH:6 !#!:+ /"6!).

    ' $6O+ Clause is not coded7 t2en t2e data is read rom terminal. "t t2e timeo e;ecution7 batc2 program %ill "B:&D i t2ere is no instream data rom ICL and

    t2ere is no $6O+ clause in t2e "CC:8 clause.

    D": option returns si; digit current date in ####++DDD"# returns 5 digit current date in ##DDD

    '+: returns * digit 6=& '+: in HH++!!D"#O$G:: returns single digit %2ose value can be 1, (+onday!unday

    respectively)

    D'!8L"#'t is used to display data. By deault display messages are routed to !#!O=.

    !ynta;P D'!8L"# identiier1T literal1 (=8O& mnemonic name)

    !O8 6=&7 :R' 86O6"+ N O B"C

    !O8 6=& is t2e last e;ecutable statement o t2e main program. 't returnscontrol bac3 to O!.

    :R' 86O6"+ is t2e last e;ecutable statement o subprogram. 't returns

    control bac3 to main program.OB"C can be coded in main program as %ell as subprogram as t2e last

    statement. 't Wust gives t2e control bac3 rom %2ere it received t2e control.

    Collating !e

  • 8/9/2019 Cobol-Refresher.doc

    11/40

    Mainframe Refresher Part-1 COBOL-Page: 11

    '$H:&:L!::&D'$

    2e most amous decision ma3ing statement in all language is K'$. 2e synta;o '$ statement is given belo%P '$ can be coded %it2out any :L!: statement. H:&

    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. 2is rule can be overridden by using parent2eses.2e permitted relation conditions are A7 F7 E7 FA7 EA7 FE

    CO&'&=: is no operation statement. 2e control is Wust passed to ne;t!":+:&. &:R !:&:&C: passes t2e control to t2e ne;t !:&:&C:. ' you orgot

    t2e dierence bet%een statement and sentence7 reer t2e irst page.'t is advised to use :&D'$7 e;plicit scope terminator or t2e '$ statements

    t2an period7 implicit scope terminator.

    '$ condition1 "&D condition0 H:& !tatementBloc31

    :L!: '$ condition4 H:&

    CO&'&=: :L!:

    '$ condition- H:& !tatementBloc30

    :L!: &:R !:&:&C:

    :&D'$ :&D'$

    :&D'$

    !tatementBloc30 %ill be e;ecuted only %2en condition 17 0 and - are 6=:

    and condition 4 is $"L!:.

    'mplied operandP 'n compound conditions7 it is not al%ays necessary to

    speciy bot2 operands or eac2 condition. '$ O"LA, or * is acceptable. HereO"LA* is implied operation.

    !'& test and CL"!! test!'& test is used to c2ec3 t2e sign o a data item. 't can be done as ollo%s

    '$ identiier is 8O!''/:&:"'/:?:6O

    CL"!! test is used to c2ec3 t2e content o data item against predeined range ovalues. 't can be done as ollo%s

    '$ identiier is &=+:6'C"L8H"B:'C"L8H"B:'CH'H:6 "L8H"B:'CLOG:6

    #ou can deine your o%n classes in t2e special names paragrap2. Ge 2ave deined aclass D'' in our special names paragrap2. 't can be used in t2e ollo%ing %ay.

    '$ identiier is D''

  • 8/9/2019 Cobol-Refresher.doc

    12/40

    Mainframe Refresher Part-1 COBOL-Page: 12

    &egated conditions."ny simple7 relational7 class7 sign test can be negated using &O.

    But it is not al%ays true t2at &O &:"'/: is e

  • 8/9/2019 Cobol-Refresher.doc

    13/40

    Mainframe Refresher Part-1 COBOL-Page: 13

    "DD " O B+=L'8L: B B# C

    D'!8L"# K/"L=: O$ "@B>C K C:&D8:6$O6+

    4. 8:6$O6+ 8"6"1 H6= 8"6"&.

    "ll t2e paragrap2s bet%een 8"6"1 and 8"6"& are e;ecuted once.

    -. 8:6$O6+ 8"6"1 H6= 8"6"& =&'L condition(s).2e identiiers used in t2e =&'L condition(s) must be altered %it2in t2e

    paragrap2(s) being perormed ot2er%ise t2e paragrap2s %ill be perormedindeinitely. ' t2e condition in t2e =&'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"1 H6= 8"6"& & '+:!.& can be literal deined as numeric item in %or3ing storage or 2ard coded

    constant.

    . 8:6$O6+ 8"6"1 H6= 8"6"& /"6#'& identiier1$6O+ identiier 0 B# identiier4 =&'L condition(s)

    'nitialiSe identiier1 %it2 identiier0 and test t2e condition(s). ' t2e condition

    is alse e;ecute t2e statements in 8"6"1 t2ru 8"6"& 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"1 G'H :! B:$O6:"$:6 =&'L condition(s).

    Git2 :! B:$O6:7 Condition is c2ec3ed irst and i it ound alse7 t2en 8"6"1 is e;ecuted and t2is is t2e deault. ($unctions li3e DO GH'L:)

    Git2 :! "$:67 8"6"1 is e;ecuted once and t2en t2e condition is c2ec3ed.($unctions li3e DO=&'L)

    6eer able session or eig2t2 type o 8:6$O6+.:R' statement.

    COBOL reserved %ord t2at perorms &OH'&. 't is used as a single

    statement in a paragrap2 t2at indicate t2e end o paragrap2(s) e;ecution.:R' must be t2e only statement in a paragrap2 in COBOL,- %2ereas it can be used

    %it2 ot2er statements in COBOL*5.

    O O =sageP'n a structured topdo%n programming O O is not preerable. 't oers

    permanent control transer to anot2er paragrap2 and t2e c2ances o logic errors ismuc2 greater %it2 O O t2an 8:6$O6+. 2e readability o t2e program %ill also be

    badly aected.

    But still O O can be used %it2in t2e paragrap2s being perormed. i.e. G2enusing t2e H6= option o 8:6$O6+ statement7 branc2es or O O statements7 arepermitted as long as t2ey are %it2in t2e range o named paragrap2s.

    8:6$O6+ 1!:81 H6= !:8-..

    1!:81.

    "DD " O B '/'& C.'$ D A ?:6O D'!8L"# K+=L'8L'C"'O& &O DO&:

    O O 4!:84

  • 8/9/2019 Cobol-Refresher.doc

    14/40

    Mainframe Refresher Part-1 COBOL-Page: 14

    :&D'$.0!:80.

    +=L'8L# C B# D.4!:84.

    D'!8L"# K/"L=: O$ CP C.Here O O used %it2in t2e range o 8:6$O6+. 2is 3ind o Controlled O O is ine

    %it2 structured programming alsoX

    "BL:!

    "n OCC=6! clause is used to indicate t2e repeated occurrences o items ot2e same ormat in a structure. OCC=6! clause is not valid or 17 ,,7 ** levels.

    't can be deined as elementary or group item. 'nitialiSation o large tableoccurrences %it2 speciic values are usually done using perorm loops in procedure

    division. !imple tables can be initialiSed in t2e ollo%ing %ay.1 G::"66"# /"L=: K+O&=:G:DH=$6'!"!=&.

    5 G!G::D"#! OCC=6! , '+:! 8'C R(4).

    Dynamic array is t2e array %2ose siSe is decided during runtime Wust beore t2eaccess o irst element o t2e array.

    1 G!+O&HD"#C"L. 5 G!D"#! OCC=6! 41 '+:! D:8:&D'& O& G!OCC=6:&C:.

    '$ +O&H A K$:B +O/: K0* to G!OCC=66:&C:.

    "rray 'tems can be accessed using '&D:R or subscript and t2e dierencebet%een t2em are listed in t2e table. 6elative subscripts and relative inde;es are

    supported only in COBOL*5. Literals used in relative subscriptinginde;ing must bean unsigned integer.

    "DD G!!"L(!=B) G!!"L(!=B @ 1) O G!!"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 elementsand 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 anyarit2metic statement.

    '&D:R can only be modiied %it2 !:7!:"6CH and 8:6$O6+ statements.

    !ometimes7 you may ace a

  • 8/9/2019 Cobol-Refresher.doc

    15/40

    Mainframe Refresher Part-1 COBOL-Page: 15

    Binary searc2.

    !e

  • 8/9/2019 Cobol-Refresher.doc

    16/40

    Mainframe Refresher Part-1 COBOL-Page: 16

    using !:"6CH !:"6CH "LL.

    , 8reer %2en t2e table siSe is small 8reer %2en t2e table siSe is signiicantly

    large.

    +ulti Dimensional "rraysCOBOL,- supports array o ma;imum o t2ree dimensions %2ereas COBOL*5

    supports up to seven dimensions. 2e lo%est level OCC=6! dataname or an itemsubordinate to it is used to access an entry in t2e array or t2e table.

    ' %e use !:"6CH or accessing multidimension table7 t2en '&D:R:D B#must be used on all OCC=6! levels. :;panded nested perorm is available or

    processing multi level tables. 2e synta; o t2is perorm is given belo%P

    8:6$O6+ para1 t2ru paran/"6#'& inde;1 rom 1 B# 1 =&'L inde;1 E siSe o outeroccurs

    "$:6 /"6#'& inde;0 rom 1 by 1 until inde;0 E siSe o inner occurs.

    !:"6CH e;ample or multi level tablesP1 :+8"BL:.

    5 D:8&=+B:6 OCC=6! 1 '+:! '&D:R:D B# '1.1 :+8D:"'L OCC=6! 5 '+:! '&D:R:D B# '0.

    15 :+8&=+B:6 8'C 9(-).

    15 :+8!"L"6# 8'C 9(5).,, :+8&=+B:6'& 8'C 9(-) /"L=: K050.

    8:6$O6+ 1!:"6CH:+8!"L /"6#'& '1 $6O+ 1 B# 1

    =&'L '1 E 1 O6 G!$O=&D1!:"6CH:+8!"L.

    !: '0 O 1.!:"6CH :+8D:"'L " :&D D'!8L"# K&O $O=&D AA E Lo%est Occurs

    GH:& :+8&=+B:6'& A :+8&=+B:6('17'0)D'!8L"# K!"L"6# '!P :+8!"L"6#('17'0)

    !: G!$O=&D O 6=: AA E !earc2 ends

    :&D!:"6CH.

    &:!:D 86O6"+!7 LOB"L7 :R:6&"LOne program may contain ot2er program(s). 2e contained program(s) may

    t2emselves contain yet ot2er program(s). "ll t2e contained and containing programss2ould end %it2 :&D 86O6"+ statement. 8+B is nested a program in t2e

    e;ample belo%P:;ampleP 'D:&'$'C"'O& D'/'!'O&.

    86O6"+'D. 8+" Y

    'D:&'$'C"'O& D'/'!'O&.

    86O6"+'D. 8+BY:&D 86O6"+ 8+B.

    Y

    :&D 86O6"+ 8+".

    ' you %ant access any %or3ing storage variable o 8+" in 8+B7 t2endeclare t2em %it2 t2e clause K'! LOB"L in 8+". ' you %ant to access any

  • 8/9/2019 Cobol-Refresher.doc

    17/40

    Mainframe Refresher Part-1 COBOL-Page: 17

    %or3ing storage variable o 8+B in 8+"7 declare t2em %it2 t2e clause K'!:R:6&"L in 8+B. &ested 8rograms are supported only in COBOL*5.

    ' t2ere is a program 8+C inside 8+B7 it cannot be called rom 8+"unless its program id is

  • 8/9/2019 Cobol-Refresher.doc

    18/40

    Mainframe Refresher Part-1 COBOL-Page: 18

    8rogram sort registers (and its e

  • 8/9/2019 Cobol-Refresher.doc

    19/40

    Mainframe Refresher Part-1 COBOL-Page: 19

    !6'&!6'& command is used to concatenate one or more strings.

    !ynta;P!6'& identiier1 literal17 identiier0 literal0

    D:L'+':D B# (identiier4literal4!'?:)'&O identiier-

    :&D!6'&.

    1 /"61 8'C R(1) /"L=: K+=H= K1 /"60 8'C R(1) /"L=: K!"6" K

    1 /"60 8'C R(0).

    o get display K+=H=7!"6"!6'& /"61 D:L'+':D B# K K

    K7 D:L'+':D B# !'?:

    /"60 D:L'+':D B# K K '&O /"64

    :&D!6'&.2e receiving ield must be an elementary data item %it2 no editing symbols

    and I=! 6'H clause.

    Git2 !6'& statement7 speciic c2aracters o a string can be replaced%2ereas +O/: replaces t2e ull string.

    1 ":O= 8'C R(10) /"L=: 10 #:"6! OLD.!6'& K1* D:L'+':D B# !'?: '&O ":O=. AE 1* #:"6! OLD.

    6eerence +odiication e

  • 8/9/2019 Cobol-Refresher.doc

    20/40

    Mainframe Refresher Part-1 COBOL-Page: 20

    G!$LD4 D:L'+':6 '& G!D4 CO=& '& G!C4:&D=&!6'&.

    6esultPG!$LD1 A 1 G!$LD0 A0 G!$LD4A4

    G!C1 A 0 G!C0A4 G!C4A4 G!D1 A K G!D0A G!D4 KO& O/:6$LOG can be coded %it2 !6'& and =&!6'&. ' t2ere is !6'&

    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 t2at2ave 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. 2eir layout can be placed in onecopyboo3 and be placed %2erever t2e iles are used. 't promotes program

    standardiSation since all t2e programs s2are t2e same layout and t2e same datanames.

    2is reduces coding and debugging time. C2ange in layout needs c2ange incopyboo3 only. 't is enoug2 i %e Wust recompile t2e program or ma3ing t2e ne%

    copy eective.

    !ynta;P

    CO8# copyboo3name Z(O$'&) library name[ Z6:8L"C'& stringtobereplaced B# replacingstring[

    Copyboo3s are stored as members in 8D! library and during compilation time7 t2eyare 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:CO+8=:67 OBI:CCO+8=:67 !8:C'"L&"+:!7 $'L:CO&6OL7'OCO&6OL7 $D !:C'O&7 8"6"6"8H! '& 86OC:D=6: D'/'!'O&.

    ' t2e same copyboo3 is used more t2an once in t2e program7 t2en t2ere %illbe duplicate 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'& verb to replace 2ig2level

  • 8/9/2019 Cobol-Refresher.doc

    21/40

    Mainframe Refresher Part-1 COBOL-Page: 21

    +ain 8rogram C2angesPC"LL statement is used or e;ecuting t2e subprogram rom t2e main

    program. " sample o C"LL statement is given belo%PC"LL K8+0 =!'& B# 6:$:6:&C: G!/"617 B# CO&:& G!/"60.

    8+0 is called 2ere. G!/"61 and G!/"60 are %or3ing storage items.G!/"61 is passed by reerence. G!/"60 is passed by Content. B# 6:$:6:&C: is

    deault in COBOL and need not be coded. B# CO&:& L:&H p2rase permits t2elengt2 o data item to be passed to a called program.

    !ub8rogram C2angesP

    G!/"61 and G!/"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 accesst2em in t2e subprogram7 %e need to deine t2em in t2e lin3age section.

    L'&": !:C'O&.

    1 L'&": !:C'O&. 5 L/"61 8'C 9(-).

    5 L/"60 8'C 9(-).

    'n addition to deine t2em in lin3age section7 t2e procedure division s2ould be coded

    %it2 t2ese data items or addressability.

    86OC:D=6: D'/'!'O& =!'& L/"617L/"60

    2ere is a oneone correspondence bet%een passed elements and received

    elements (Call using7 lin3age and procedure division using) B# 8O!''O&. 2isimplies t2at t2e name o t2e identiiers in t2e called and calling program need not be

    t2e same (G!/"61 N L/"61) but t2e number o elements and picture clauses2ould be same.

    2e last statement o your subprogram s2ould be :R' 86O6"+. 2isreturns t2e control bac3 to main program. OB"C can also be coded instead o:R' 86O6"+ but not !O8 6=&. :R' 86O6"+ s2ould be t2e only statement in a

    paragrap2 in COBOL,- %2ereas it can be coded along %it2 ot2er statements in aparagrap2 in COBOL*5.

    86O6"+'D. F8rogramnameE '! '&''"L 86O6"+.

    ' '! '&''"L 86O6"+ is coded along %it2 programid o sub program7 t2ent2e 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 subprogram to initial state.

    ' t2e sub program is modiied t2en it needs to be recompiled. 2e need or

    main program recompilation is decided by t2e compiler option used or t2e mainprogram. ' t2e D#&"+ compiler is used7 t2en t2ere is no need to recompile t2e mainprogram. 2e modiied subroutine %ill be in eect during t2e run. &OD#&"+ is

    deault t2at e;pects t2e main program recompilation.

    Dierence bet%een 8assbyreerence and 8assbycontent

    !l J 8assl By 6eerence 8ass By Content

    1 C"LL Ksub1 =!'& B# C"LL Ksub1 =!'& B# CO&:& G!/"61

  • 8/9/2019 Cobol-Refresher.doc

    22/40

    Mainframe Refresher Part-1 COBOL-Page: 22

    6:$:6:&C: G!/"61 (B# CO&:& 3ey%ord is needed)

    0 't is deault in COBOL. B#

    6:$:6:&C: is not needed.

    B# CO&:& 3ey %ord is mandatory to

    pass an element by value.

    4 "ddress o G!/"61 is passed /alue o G!/"61 is passed

    - 2e subprogram modiications

    on t2e passed elements are

    visible in t2e main program.

    2e subprogram modiications on t2e

    passed elements are local to t2at

    subprogram and not visible in t2e mainprogram.

    Dierence bet%een !tatic Call and Dynamic Call

    !l J !"'C Call D#&"+'C Call

    1 'dentiied by Call literal.:;P C"LL K8+1.

    'dentiied by Call variable and t2evariable s2ould be populated at run time.

    1 G!8+ 8'C R(*).+ove K8+1 to G!8+

    C"LL G!8+

    0 Deault Compiler option is

    &OD#&"+ and so all t2e literalcalls are considered as static calls.

    ' you %ant convert t2e literal calls into

    D#&"+'C7 t2e program s2ould becompiled %it2 D#&"+ option.

    By deault7 call variables and any unresolved calls are considered as dynamic.

    4. ' t2e subprogram undergoesc2ange7 sub program and main

    program need to be recompiled.

    ' t2e subprogram undergoes c2ange7recompilation o subprogram is enoug2.

    - !ub modules are lin3 edited %it2main module.

    !ub modules are pic3ed up during runtime 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.

    * !ubprogram %ill not be in initialstage t2e ne;t time it is called

    unless you e;plicitly use '&''"L or

    you do a C"&C:L ater eac2 call.

    8rogram %ill be in initial state every timeit is called.

    '&6'&!'C $=&C'O&!P

    L:&H 6eturns t2e lengt2 o t2e 8'C clause. =sed or inding lengt2 o groupitem 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 c2aracterstring speciied in t2e argument.

    &=+/"LC !ame as &=+/"L but currency and decimal points are ignored duringconversion.

    C=66:& 6eturns 01 C2ars alp2anumeric value ####++DDHH++!!nnnnnnD":

    '&::6 O$ D": 6eturns '&::6 e

  • 8/9/2019 Cobol-Refresher.doc

    23/40

    Mainframe Refresher Part-1 COBOL-Page: 23

    &oteP $=&C'O& '&::6 O$ D": (1111) returns 1.

    $'L: H"&DL'&" data ile is collection o relevant records and a record is collection o

    relevant ields. 2e ile 2andling in COBOL program involves ive steps.

    !teps in ile2anding

    1."llocationP 2e iles used in t2e program s2ould be declared in $'L:CO&6OL paragrap2 o environment division. 2e mapping %it2 ICL DD&"+: is done

    2ere. 2e ile is allocated to your program by t2is statement.

    0.Deinition. 2e layout o t2e ile and its attributes are deined in t2e $'L:!:C'O& o D"" D'/'!'O&.

    4.OpenP Dataset is connectedreadied to your program using O8:&

    statement. 2e mode o O8:& decides t2e operation allo%ed and t2e initial pointer in

    t2e dataset. $or e;ample7 :R:&D mode allo%s only %rite access and t2e pointer is3ept on t2e end o ile to append.

    -.8rocessP 8rocess t2e ile as per re

  • 8/9/2019 Cobol-Refresher.doc

    24/40

    Mainframe Refresher Part-1 COBOL-Page: 24

    FILNAMis t2e logical name used inside t2e program and DDNAMis t2elogical name in t2e ICL7 mapped %it2 p2ysical dataset. DDNAM can be prei;ed %it2

    K!K to indicate Q!"+ ile7 K"! to indicate :!D! ile and %it2 no prei; to indicate!D!66D! ile.

    ICL !tep e;ecuting t2e program s2ould 2ave a dataset %it2 DDNAMas label

    DDNAM DD D!&AB8+"'&.:+8LO#::.D""7D'!8A!H6

    !:L:C !tatementO6"&'?"'O&'t can be !:Q=:&'"L (8! or /!"+ :!D!)7 '&D:R:D (/!"+ !D!)7

    6:L"'/: (/!"+ 66D!). Deault is !e

  • 8/9/2019 Cobol-Refresher.doc

    25/40

    Mainframe Refresher Part-1 COBOL-Page: 25

    6:!:6/: Clause.6:!:6/: clause Z6:!:6/: integer "6:" [ can be coded in t2e !:L:C

    statement. 2e 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:C statement.

    Deining t2e ile in $'L: !:C'O& $D

    $D FILNAM6:CO6D'& +OD: '! //B$$B

    6:CO6D CO&"'&! + CH"6"C:6! (O & CH"6"C:6!)BLOC CO&"'&! R CH"6"C:6!6:CO6D! (O # CH"6"C:6!6:CO6D!)

    L"B:L 6:CO6D! "6: O+':D!"&D"6DD"" 6:CO6D '! FIL!R)ORD.

    1 FIL!R)ORD8'C R(nnn).

    $D6:CO6D CO&"'&!

    't speciies t2e lengt2 o t2e record in terms o bytes. ('t %ill be 6:CO6Dcontains m to n CH"6"C:6! or variable ormat iles)

    $DBLOC CO&"'&!

    '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 issuggested to code BLOC CO&"'&! 6:CO6D! so t2at system %ill decide t2e

    optimum siSe or t2e ile based on t2e device used or storing t2e ile. BLOCCO&"'&! clause is treated as comments or /!"+ iles.

    "dvantage o Bloc3ingP1.'O time is reduced as n numbers o records are read into main memory buerduring an 'O.

    0.'nter record gap is removed and t2e gap e;ist only bet%een bloc3s. !o memory%astage due to '6 is avoided.

    $D6:CO6D'& +OD: '!

    't can be $ ($'R:D) /(/"6'"BL:) $B($'R:D BLOC) /B(/"6'"BL: BLOC:D)/ariable record ile identiicationP

    ' t2ere is no recording moderecord contains clause7 it is still possible toidentiy variable lengt2 records. ' t2ere is an OCC=6! depending on clause or t2ere

    are multiple 1 levels and every 1 level is o dierent siSe7 t2en t2e ile %ould be o

    variable lengt2. +ultiple 1 level in $ile section is an e;ample or implicit redeinition.

    $DL"B:L 6:CO6D! Clause

    "s a general rule7 L"B:L 6:CO6D! are !"&D"6D is coded or Dis3 and apeiles7 L"B:L 6:CO6D! "6: O+':D is coded or printer iles. 'n COBOL,-7 t2is

    clause is a mandatory clause %2ereas COBOL*5 made t2is as optional.

  • 8/9/2019 Cobol-Refresher.doc

    26/40

  • 8/9/2019 Cobol-Refresher.doc

    27/40

    Mainframe Refresher Part-1 COBOL-Page: 27

    6:"D statement6:"D statement is used to read t2e record rom t2e ile.

    !ynta;P 6:"D FILNAMZ'&O %srecord[ Z:# '! FIL!"#$[

    Z" :&D'&/"L'D :# imperative statement1[ Z&O " :&D&O '&/"L'D :# imperative statement0[

    :&D6:"D

    ' '&O clause is coded7 t2en t2e ile is directly read into %or3ing storagesection record. 't is preerred as it avoids anot2er move o ilesectionrecord to

    %or3ingstoragerecord ollo%ed by simple 6:"D. 6:"D'&O is not preerred orvariable siSe records %2ere t2e lengt2 o t2e record being read is not 3no%n.

    :# '! clause is used %2ile accessing a record randomly usingprimaryalternate record 3ey.

    " :&D and &O " :&D are used during se

  • 8/9/2019 Cobol-Refresher.doc

    28/40

    Mainframe Refresher Part-1 COBOL-Page: 28

    :# is :Q="L O&O L:!! H"&6:":6 H"& 3eynameZ'&/"L'D :# imperative statement1[

    :&D!"6.

    D:L:: !tatementD:L:: is used to delete t2e most recently read record in t2e ile. o delete a

    record7 t2e ile s2ould be opened in 'O mode.!ynta;P D:L:: FILNAM6:CO6D

    Z'&/"L'D :# imperative statement1[:&DD:L::

    $ile :rror Handling

    2ere are c2ances or ailure o any ile 'O processing. 2e ailure o an 'Ooperation can be accepted or cannot be tolerated. 2e severity o ailure 2as to be

    deined in t2e program design stage.Let us assume t2at %e dont 2ave any error 2andling in our program. 'n t2is

    case7 or e;ample7 i you dont 2ave a speciic record in t2e ile7 t2e random read ot2at record %ould immediately terminate t2e program %it2 error Krecord not ound.

    :rror Handling Clauses 8rovided by COBOL.

    2e sudden termination can be avoided by 2andling t2is error7 %it2 '&/"L'D

    :# clause o 6:"D. Based on t2e importance o t2e record and business rule7 %ecan continue our program %it2 ne;t record or terminate t2e program properly.

    " :&D is anot2er error 2andling clause provided by COBOL. But t2ere is no %ay to2andle all suc2 errors in t2is %ay.

    "ssign ilestatus and ta3e t2e responsibility.2e second met2od is7 assigning ilestatus to t2e ile in t2e !:L:C clause

    and c2ec3s t2e ile status ater eac2 and every 'O and ensures t2at t2e value ostatus 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 'O operation.2is is +O! 86:$:66:D :66O6 H"&DL'& +:HOD in structured programming.

    Declaratives =!: statementCOBOL provides an option to group all t2e possible errors o speciic

    operation(s) in a place and t2at %ill be automatically invo3ed during t2e respectiveoperation(s) o any ile. 2is avoids redundant code.

    2is is done in D:CL"6"'/: section o t2e procedure division. D:CL"6"'/:s2ould be t2e irst section in t2e procedure division i coded.

    86OC:D=6: D'/'!'O&.

    D:CL"6"'/:!.

    =!:86OC:D=6: !:C'O&.=!: "$:6 :RC:8'O& 86OC:D=6: O& '&8=:66O686OC:D=6:.

    C2ec3 t2e ilestatus code or validity.:&DD:CL"6"'/:!.

    G2enever t2ere is an error in t2e processing o " $'L: opened in '&8=

    mode7 t2en t2e control comes to :66O686OC:D=6:. 2e validity o error s2ould bec2ec3ed in t2is paragrap2 and allo% or restrict t2e process do%n7 based on severity

    o error code.

  • 8/9/2019 Cobol-Refresher.doc

    29/40

    Mainframe Refresher Part-1 COBOL-Page: 29

    2e complete synta; o =!: statements isP

    =!: "$:6 !"&D"6D :66O6T:RC:8'O& 86OC:D=6: O&'&8=TO=8=T'OT:R:&DT ile1

    ' '&8= is coded7 t2e ollo%ing procedure %ill be e;ecuted or everyoperation involved in any ile t2at is opened in '&8= mode. O=8=7 'O and

    :R:&D 2ave t2e same meaning but t2e mode is dierent.' ile name (ile1) is coded in t2e =!: statement7 t2en all t2e inputoutput

    operation o t2at speciic ile %ill be c2ec3ed.:66O6 and :RC:8'O& are synonyms.

    2e 8rocedure %ritten in a D:CL"6"'/: section s2ould not reer to any nondeclarative procedure %ritten ater t2e end procedure and viceversa.

    'OCO&6OL !"+: "6:" "&D !"+: 6:CO6D "6:"6:!:6/: clause o !:L:C statement speciies t2e number o buers to be

    allocated or a ile. !"+: "6:" allo%s more t2an one ile to use t2e same buerarea. 2is %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:" iscoded.

    !ynta;P !"+: "6:" $O6 ile1 ile0 ile4.

    ' !"+: 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 becareul %2ile illing in t2e record area o t2e output ile. 2is may destroy t2e record

    read most recently.!ynta;P !"+: 6:CO6D "6:" $O6 ile1 ile0 ile4.

    !"+: !O6 "6:" allo%s more t2an one sortmerge %or3 iles to use t2esame area. 2e sort %or3 iles are automatically allocated %2en ile is opened and

    deallocated %2en ile is closed. "s t2e sort ile is automatically opened and closedduring a !O6 and t%o sort iles cannot be opened at a time7 t2is clause may not be

    useul.

    !ynta;P !"+: !O6T!O6+:6: "6:" or ile1 ile0.$ile1 or ile0 s2ould be a !D ile.

    'O CO&6OL 6:6=& Clause6:6=& O& rescue $O6 :/:6# integer 6:CO6D! on ile1

    2is %ill cause c2ec3point to be ta3en or every interger1 records processing oile1. ' t2e program "B:&D:D beore t2e complete processing o t2e ile17 t2en

    t2e program %ill restart rom integer@1!record instead o irst record. 2e rescueile details s2ould be mentioned outside t2e program and it varies rom installation to

    installation.

    :&6# statement

    :&6# statement establis2es an alternate :&6# point in a COBOL calledsubprogram. G2en a C"LL statement naming t2e alternate entry point is e;ecutedin 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:&6# statements are ignored at runtime.

    +atc2ing Logic' you 2ave been given t%o iles o similar type7 say master and transaction

    ile and you are re

  • 8/9/2019 Cobol-Refresher.doc

    30/40

    Mainframe Refresher Part-1 COBOL-Page: 30

    or e;isting records and prepare a report o ne% transactions and deletedtransactions7 t2en you s2ould go or %2at is called +atc2ing logic. 2is is also 3no%n

    as cose

  • 8/9/2019 Cobol-Refresher.doc

    31/40

  • 8/9/2019 Cobol-Refresher.doc

    32/40

    Mainframe Refresher Part-1 COBOL-Page: 32

    !8"C:A(C#L717171))!#!L'B DD D!&A!+!RL*.LO"DL'B7D'!8A!H6

    !#!=1 DD =&'A!#!D"7!8"C:A(C#L7(171))!#!86'& DD !#!O=A>

    >>> :R:C=: H: 86O6"+ >>>

    :R:C=:1 :R:C 8+A>.L'&:D1.!#!L+OD7CO&DA(-7L)76:'O&A+!:8L'B DD D!&A!+!RL*.LO"DL'B7D'!8A!H6

    DD D!&A!#!1.!C::6=&7D'!8A!H6!#!O= DD !#!O=A>

    !#!86'& DD !#!O=A>

    Compiler Options2e deault options t2at %ere set up %2en your compiler %as installed are in

    eect or your program unless you override t2em %it2 ot2er options. o c2ec3 t2edeault 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 ('#C6CL) 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 predeined 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.

    2e complete list o compiler option is in t2e tableP

    "spect Compiler Option

    !ource Language "8O!7 C+8607 C=66:&C#7 DBC!7 L'B7 &=+B:67Q=O:7 !:Q=:&C:7 GO6D

    Date 8rocessing D":86OC7 '&D":7 #:"6G'&DOG

    +aps and Listing L"&=":7 L'&:CO=&7 L'!7 +"87 O$$!:7 !O=6C:7 !8"C:7

    :6+'&"L7 /B6:$7 R6:$

    ObWect Dec3

    generation

    CO+8'L:7 D:C7 &"+:7 OBI:C7 8+&"+:

    ObWect CodeControl

    "D/7 "GO7 DLL7 :R8O6"LL7 $"!!67 O8'+'?:7 &=+86OC7O=DD7 6=&C7 ?GB

    Debugging D=+87 $L"7 $L"+'7 $L"!D7 !!6"&:7 #8:CH

    Ot2er "D""7 "&"L#?:7 :R'7 'DL:&

    "D/P 't is meaningul i your program 2as any printer iles %it2 G6':.."D/"&C'&

    3ey%ord. 2e compiler adds one byte prei; to t2e original L6:CL o printer iles or

  • 8/9/2019 Cobol-Refresher.doc

    33/40

    Mainframe Refresher Part-1 COBOL-Page: 33

    printing control purpose. ' you are manually populating printing control c2aracter int2e program7 t2en you can compile your program %it2 &O"D/.

    D#&"+P =se D#&"+ to cause separately compiled programs invo3ed t2roug2 t2e

    C"LL literalstatement to be loaded dynamically at run time. D#&"+ causes dynamicloads (or C"LL) and deletes (or C"&C:L) o separately compiled programs at obWect

    time. "ny C"LL i.enti+ierstatements t2at cannot be resolved in your program arealso treated as dynamic calls. G2en you speciy D#&"+7 6:!'D:& is also put into

    eect.

    L'!O$$!:P L'! and O$$!: are mutually e;clusive. ' you use bot27 L'! %ill be

    ignored. L'! is used to produce listing a listing o t2e assembler language e;pansiono your code. O$$!: is used to produce a condensed 8rocedure Division listing.

    Git2 O$$!:7 t2e procedure portion o t2e listing %ill contain line numbers7statement reerences7 and t2e location o t2e irst instruction generated or eac2

    statement. 2ese options are useul or solving system "B:&D!. 6eer ICL sessionor more details.

    +"8P =se +"8 to produce a listing o t2e items you deined in t2e Data Division.

    !!6"&:P ' t2e program is compiled %it2 !!6"&: option7 t2en any attempt toreer an area outside t2e region o t2e table %ill abnormally terminate %it2

    protection e;ception7 usually !C-.'t also avoids any meaningless operation on

    reerence modiication li3e negative number in t2e starting position o reerencemodiication e;pression. ' t2e program is compiled %it2 &O!!6"&:7 t2en t2e

    program may proceed urt2er %it2 Wun3 or irrelevant data. !o usually t2e programsare compiled %it2 !!6"&: during development and testing.

    6:&P " program compiled as 6:& is generated as a reentrant obWect module. C'C!programs s2ould be compiled %it2 6:& option to s2are t2e same copy o t2e

    program by multiple transactions (+ultit2reading)

    6:!'D:&P =se t2e 6:!'D:& option to re

  • 8/9/2019 Cobol-Refresher.doc

    34/40

    Mainframe Refresher Part-1 COBOL-Page: 34

    !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"#oe %

    % TSO -omm"$ .om COBOL po*m /i"* %

    % !"$$ TSO e#i-e $o-/me"!e$ i" !'e % % TSOE Po*mmi"* Se#i-e m"/l %

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    &$e"!i.i-!io" Di#iio"

    Po*m2&D SMSTSOE3

    D! Di#iio"

    4oi"*2S!o*e Se-!io"

    01 Fille

    05 +2$/mm6 Pi- 7(8) Comp

    05 +2e!/"2-o$e Pi- 7(8) Comp

    05 +2eo"2-o$e Pi- 7(8) Comp

    05 +2i".o2-o$e Pi- 7(8) Comp

    05 +2-ppl2$$e Pi- 7(8) Comp

    05 +2.l* Pi- 9(:) 3l/e 9;00010001;

    05 +2

  • 8/9/2019 Cobol-Refresher.doc

    35/40

    Mainframe Refresher Part-1 COBOL-Page: 35

    &F +2e!/"2-o$e > ?eo

    D&SPLAY ;&KJEFTS@ File$, @e!/"2-o$e=; +2e!/"2-o$e

    ; @eo"2-o$e=; +2eo"2-o$e

    MO3E +2e!/"2-o$e !o @e!/"2-o$e

    STOP @UN

    %2222222222222222222222222222222222222222222222222222222222222222%

    % C'e- !'! !'e ALLOCATE -omm"$ +oe$ % %2222222222222222222222222222222222222222222222222222222222222222%

    D&SPLAY ;ALLOCATE 4oe$ ; Upo" S6p/"-'

    STOP @UN

    'ntervie% Questions('Q)P

    > !ays importance and possibility o t2e >>

    0.Comp7 Comp17 Comp0 and Comp4 dierence and 2o% many bytes occupied byeac2. !2ould 3no% 2o% to read CO+84 data. >>>>>

    4.'dentiying and ma3ing !tatic and Dynamic call >>>>>-.Binary and !e>>>>

    5.G2at are t2e various %ays o passing data rom ICL to 8rogram and 2o% to receivet2em 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"&: +"8 L'! O$$!: 6:& 6:!'D:&

    D#&"+ and "+OD:6+OD: >>>1.Ho% to ma3e a call by content in COBOL] >>>

    11.Ho% do you set return code rom t2e program] >>>

    10.Case structure7 !ubstring7 Do %2ile7 Do =ntil7 BLL e>>14.Dierence bet%een section and paragrap2 >>>>>

    1-.Can occurs be coded in 1 level] >>>>>15."re multiple 1 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 =! means %it2 respect to !:L:C statement] >0.Can ' re%rite a se>

    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:C statement] >>>0*.o use !:"6CH "LL7 t2e table s2ould be in sorted order. ' am loading t2e table

    rom one o t2e 8D! members. 2e 8D! member data is not in sorted order. Ho% %ill' load t2e table in !O6:D order] #ou s2ould not sort in ICL. >>

    09.G2at is t2e purpose o =!: statement] >4.G2at are !"+: "6:" and !"+: 6:CO6D "6:"] >

  • 8/9/2019 Cobol-Refresher.doc

    36/40

    Mainframe Refresher Part-1 COBOL-Page: 36

    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

  • 8/9/2019 Cobol-Refresher.doc

    37/40

    Mainframe Refresher Part-1 COBOL-Page: 37

    G!"B:&DCOD: is t2e variable t2at 2as "B:&DCOD:. 't is a 2al %ordbinary.

    G2at s2ould be t2e L6:CL o printer iles]

    =se 144 c2aracter records in your program and set t2e print control c2aracteryoursel. 'n t2is case your ICL %ould 2ave 6:C$+A$B7 L6:CLA144

    =se 140 c2aracter records in t2e program and 2ave G6': ...."D/"&C'&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 bemoved to t2e last position and n1 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 0 9 5 *$irst 8assP (+a;imum - comparisons or 5 elements)

    17 0Eno c2ange7 0 N 9 E 0 is great so s%ap (1 9 0 5)7

    0 N 5 E no c2ange7 5 N * E 5 is great7 so s%ap. (1 9 0 * 5)!econd 8assP (1 9 0 * 5) (+a;imum 4 comparison or 5 elements)

    1 N 9E no c2ange7 9 N 0 E no c2ange7 0 N * E 0 is great so s%ap(1 9 * 0 5)

    2ird 8assP (1 9 * 0 5) (+a;imum 0 comparisons or 5 elements)

    1 N 9 E no c2ange7 9 N *E c2ange (1 * 9 0 5)$ourt2 8assP (1 * 9 0 5) (+a;imum 1 comparison or 5 elements)

    1 N 9 E no c2ange

    &oteP #ou can come out o sort %2en you ind Kno c2ange in all t2ecomparisons 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 t2erig2t 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 '1 and so on until top o t2e table is reac2ed or noe;c2ange in a comparison.

    "rrayP 1 0 9 5 *$irst 8assP %o elements (1 0) +a;imum 1 comparison17 0Eno c2ange

    !econd 8assP 2ree elements (1 0 9) +a;imum 0 comparisons9 N 0 E c2ange (1 9 0) 9 N 1 E no c2ange

    2ird 8assP $our elements (1 9 0 5) +a;imum 4 comparisons

    5 N 0 E no c2ange and stop (no need or any ot2er comparison)$ourt2 8assP $ive elements (1 9 0 5 *) +a;imum - comparisons

    * N 5 E c2ange ( 1 9 0 * 5) 7 * N 0E C2ange ( 1 9 * 0 5)

  • 8/9/2019 Cobol-Refresher.doc

    38/40

    Mainframe Refresher Part-1 COBOL-Page: 38

    * N 9 E C2ange (1 * 9 0 5) 7 * N 1 E no c2ange and stop.&oteP #ou can come out o pass i you ind one Kno c2ange

    !2uttle sort is better t2an bubble sort or sorting arrays %it2 more t2an 1 elements.

    CO+84 items are al%ays better t2an CO+8 %it2 respect to memory usage ('Q 01)]

    &o. CO+8 items occupy less space t2an CO+84 items at boundaries.8'C !9(-) CO+8 occupies 0 bytes %2ereas 8'C !9(-) CO+84 occupies 4 bytes.

    8'C !9(9) CO+8 occupies - bytes %2ereas 8'C !9(9) CO+84 occupies 5 bytes.8'C !9(1*) CO+8 occupies * bytes %2ereas 8'C !9(1*) CO+84 occupies 1 bytes.

    ' 2ave a !D! !tudents ile %it2 - bytes 3ey. $irst t%obytes contain class numberand ne;t t%obytes contain student number. ' %ant to read all t2e students in class

    K0. Ho% %ill you do t2at]"llocate t2e ile %it2 dynamic access mode. +ove K0 to irst t%obytes o t2e

    3ey and lo%values to ne;t t%obytes o t2e 3ey. #ou can do t2ese moves by

    reerence modiication operator or degrouping t2e ourbyte ield into t%o t%obyteields in t2e ile section.

    'ssue t2e !"6 command %it2 :# '! 6:":6 H"& clause. !tart reading

    t2e ile in loop until irst t%obytes is not e

  • 8/9/2019 Cobol-Refresher.doc

    39/40

    Mainframe Refresher Part-1 COBOL-Page: 39

    &O:!

  • 8/9/2019 Cobol-Refresher.doc

    40/40