You are on page 1of 17

INTERVIEW TOPICS (COBOL):

COBOL (Common Business-Oriented Language): 1) What are the 2 ways to call a COBOL program? What are their advantages and disadvantages? The 2 ways in COBOL to call another COBOL program is as follows: o ynamic Call o !tatic Call "n the called program# data passed will $e defined in the L"%&'() !)CT"O%* LINK !E SECTION" +1 ,'-./B011)-* +2 ,'-./ 'T'

,"C 34225)*

"n the ,-OC) 0-) "6"!"O% of the called program# yo7 will specify ,-OC) 0-) "6"!"O% 0!"%( ,'-./B011)-* "n the calling program# data varia$les will $e defined in the WO-&"%(/!TO-'() !)CT"O%* !tatic Call o The static form of the C'LL statement specifies the name of the called mod7le as a literal8 e*g*# it is in 97otes* C'LL :,-O(%'.); 0!"%( arg7ments*

o !tatic calls refer to calls made to called mod7les that were lin</edited to the o
main program at compile time* That is# the called mod7le;s o$=ect code is part of the main mod7le;s o$=ect code* This is esta$lished on compile time with the %O >%'. compiler option*

o "n static call# the called mod7le and main mod7le are lin< edited together* o Called mod7le called in !T'T"C mode will always contain val7es from
previo7s calls if the ?"%"T"'L? <eyword was not coded in the ,rogram/" declaration in the called mod7le@s " )%T"1"C'T"O% "6"!"O%* B7t yo7 can reset the val7es $y coding C'%C)L from the main mod7le* o "n static call act7al and formal parameters share same memory location*

o "n the case of static call the main mod7le and called mod7le are loaded into
the main memory initially*

o "n static call# if we do any changes to called mod7le# we need to compile $oth
main and called*

ynamic Call o "n COBOL# the dynamic form of a called mod7le call is coded li<e this:

+1 W!/!0B-O0T"%)/'

,"C 34A) 6'L0) B,-O(%'.);*

C'LL W!/!0B-O0T"%)/' 0!"%( arg7ments* o The dynamic form of the C'LL statement specifies the name of the called mod7le 7sing a varia$le8 the varia$le contains the name of the called mod7le to $e invo<ed* ynamic calls refer to calls made to mod7les with separate o$=ect code from the main mod7le* This is esta$lished on compile time with the >%'. compiler option*

o "n ynamic call# the called mod7le and main mod7le eCist as separate
mod7les*

o Called mod7le called in >%'."C mode will always $e in initial state*


o "n dynamic call act7al and formal parameters 7ses different memory locations*

o "n the case of dynamic call only the main program is loaded first and the
called program is loaded only when a call to it is made# hence the memory 7tiliDation is good in dynamic call*

o "n dynamic call# if we change the called program# we only need to compile
called program* There is no need to compile the main program* 2) What is the difference $etween indeC and s7$script? !7$scripts and indeCes are the two tools 7sed to reference individ7al elements of a ta$le*

' s7$script is a wor<ing/storage field defined separately from the ta$le and is completely availa$le to the programmer* 'n indeC is created a7tomatically $y the system if it is directed to do so and only have limited availa$ility to the programmer* The ma=or difference $etween a s7$script and an indeC is that a s7$script is a position in the ta$le 4first element# 2+th element# etc*)* 'n indeC is a $yte offset of an element relative to the $eginning of the ta$le* !ince the first element is + $ytes away from the start of the ta$le# it has an indeC of +* The 2+th element 4say each element is a ,"C 342)) starts E2 $ytes from the start of the ta$le so its indeC is E2* When manip7lating an indeC the programmer does not do so $y this $yte offset* "t is done $y position in the ta$le and the translation to $yte offset is done internally $y COBOL*

!7$script o o

!7$script refers to the array occ7rrence* The lowest possi$le s7$script val7e is 1# which references the first occ7rrence of a ta$le element* "n a one/dimensional ta$le# the s7$script corresponds to the row n7m$er*

o o

>o7 can 7se a literal or a data/name as a s7$script* When yo7 7se a data/name as a varia$le s7$script# yo7 m7st descri$e the data/name as an elementary n7meric integer* The most efficient format is CO.,0T'T"O%'L 4CO.,) with a ,"CT0-) siDe that is smaller than five digits* >o7 can increment or decrement a literal or varia$le s7$script $y a specified integer amo7nt* 1or eCample:
TABLE-COLUMN (SUB1 - 1, SUB2 + 3)

>o7 can change part of a ta$le element rather than the whole element* To do so# refer to the character position and length of the s7$string to $e changed* 1or eCample:
01 ANY-TABLE. 05 TABLE-ELEMENT PIC X(10) OCCURS 3 TIMES VALUE "ABC E!"#I$". . . . MOVE "%%" TO TABLE-ELEMENT (1) (3 & 2).

The .O6) statement in the eCample a$ove moves the string @??@ into ta$le element n7m$er 1# $eginning at character position F# for a length of 2 characters*

"ndeC

o >o7 create an indeC $y 7sing the "% )3) B> phrase of the OCC0-!
cla7se to identify an indeC/name* o 1or eCample# "%3/' in the following code is an indeC/name:
05 TABLE-ITEM PIC X(') OCCURS 10 IN EXE BY INX-A.

o o

o o

"ndeC is the displacement 4in n7m$er of $ytes) from the $eginning of the array* The compiler calc7lates the val7e contained in the indeC as the occ7rrence n7m$er 4s7$script) min7s 1# m7ltiplied $y the length of the ta$le element* Therefore on the eCample a$ove# for the fifth occ7rrence of T'BL)/"T).# the $inary val7e contained in "%3/' is 42 / 1) G A# or F2* >o7 can 7se an indeC/name to reference another ta$le only if $oth ta$le descriptions have the same n7m$er of ta$le elements# and the ta$le elements are of the same length* >o7 can 7se the 0!'() "! "% )3 cla7se to create an indeC data item# and can 7se an indeC data item with any ta$le* 1or eCample# "%3/B in the following code is an indeC data item:

(( INX-B USA"E IS IN EX. . . . SET INX-A TO 10 SET INX-B TO INX-A. PER!ORM VARYIN" INX-A !ROM 1 BY 1 UNTIL INX-A ) INX-B ISPLAY TABLE-ITEM (INX-A) . . . EN -PER!ORM.

The indeC/name "%3/' is 7sed to traverse ta$le T'BL)/"T). a$ove* The indeC data item "%3/B is 7sed to hold the indeC of the last element of the ta$le* The advantage of this type of coding is that calc7lation of offsets of ta$le elements is minimiDed# and no conversion is necessary for the 0%T"L condition* >o7 can 7se the !)T statement to assign to an indeC data item the val7e that yo7 stored in an indeC/name# as in the statement !)T "%3/B TO "%3/' a$ove* 1or eCample# when yo7 load records into a varia$le/ length ta$le# yo7 can store the indeC val7e of the last record into a data item defined as 0!'() "! "% )3* Then yo7 can test for the end of the ta$le $y comparing the c7rrent indeC val7e with the indeC val7e of the last record* This techni97e is 7sef7l when yo7 loo< thro7gh or process a ta$le* 'n indeC is a register item that eCists o7tside the program@s working

storage. You SET an index to a value and SET it UP BY value and DOWN BY value.
o >o7 can increment or decrement an indeC/name $y an elementary integer data item or a nonDero integer literal# for eCample:
SET INX-A O*N BY 3

The integer represents a n7m$er of occ7rrences* "t is converted to an indeC val7e $efore $eing added to or s7$tracted from the indeC* o "nitialiDe the indeC/name $y 7sing a !)T# ,)-1O-. 6'->"%(# or !)'-CH 'LL statement* >o7 can then 7se the indeC/name in !)'-CH or relational condition statements* o To change the val7e# 7se a ,)-1O-.# !)'-CH# or !)T statement* o Beca7se yo7 are comparing a physical displacement# yo7 can directly 7se indeC data items only in !)'-CH and !)T statements or in comparisons with indeCes or other indeC data items* >o7 cannot 7se indeC data items as s7$scripts or indeCes* o %eed to have indeC for a ta$le in order to 7se !)'-CH# !)'-CH 'LL* o "t is not possi$le to pass a ta$le with an indeC thr7 the lin<age section* F) What are the 2 search techni97es for ta$les in COBOL? o
o COBOL provides two search techni97es for ta$les:

o o

!erial 4!)'-CH) Binary 4!)'-CH 'LL)

1or a serial search# the n7m$er of comparisons is of the order of n# the n7m$er of entries in the ta$le* 1or a $inary search# the n7m$er of comparisons is of the order of only the logarithm 4$ase 2) of n* ' $inary search# however# re97ires that the ta$le items already $e sorted*

!erial search 4!)'-CH):

To do serial searches# 7se !)'-CH and indeCing* 1or varia$le/


length ta$les# yo7 can 7se ,)-1O-. with s7$scripting or indeCing* oing a serial search 4!)'-CH) 0se the !)'-CH statement to do a serial 4se97ential) search $eginning at the c7rrent indeC setting* To modify the indeC setting# 7se the !)T statement* The conditions in the WH)% phrase are eval7ated in the order in which they appear: "f none of the conditions is satisfied# the indeC is increased to correspond to the neCt ta$le element# and the WH)% conditions are eval7ated again* "f one of the WH)% a condition is satisfied# the search ends* The indeC remains pointing to the ta$le element that satisfied the condition* "f the entire ta$le has $een searched and no conditions were met# the 'T )% imperative statement is eCec7ted if there is one* "f yo7 did not code 'T )% # control passes to the neCt statement in the program*

>o7 can reference only one level of a ta$le 4a ta$le element) with each SEARC# statement* To search m7ltiple levels of a ta$le# 7se nested SEARC# statements* elimit each nested SEARC# statement with EN -SEARC#* ,erformance: "f the fo7nd condition comes after some intermediate point in the ta$le# yo7 can speed 7p the search $y 7sing the SET statement to set the indeC to $egin the search after that point* 'rranging the ta$le so that the data 7sed most often is at the $eginning of the ta$le also ena$les more efficient serial searching* "f the ta$le is large and is presorted# a $inary search is more efficient*
)Cample: serial search

The following eCample shows how yo7 might find a partic7lar string in the innermost ta$le of a three/dimensional ta$le* )ach dimension of the ta$le has its own indeC 4set to 1# I# and 1# respectively)* The innermost ta$le 4TABLE-ENTRY3) has an ascending <ey*
01 TABLE-ONE. 05 TABLE-ENTRY1 OCCURS 10 TIMES

. . . PROCE URE IVISION. . . . SET TE1-IN EX TO 1 SET TE2-IN EX TO , SET TE3-IN EX TO 1 MOVE "A123," TO +EY1 (TE1-IN EX, TE2-IN EX, TE3-IN EX + 2) MOVE "AAAAAAAA00" TO +EY2 (TE1-IN EX, TE2IN EX, TE3-IN EX + 2) . . . SEARC# TABLE-ENTRY3 AT EN MOVE , TO RETURN-CO E *#EN TABLE-ENTRY3(TE1-IN EX, TE2-IN EX, TE3IN EX) - "A123,AAAAAAAA00" MOVE 0 TO RETURN-CO E EN -SEARC#

IN EXE BY TE1-IN EX. 10 TABLE-ENTRY2 OCCURS 10 TIMES IN EXE BY TE2-IN EX. 15 TABLE-ENTRY3 OCCURS 5 TIMES ASCEN IN" +EY IS +EY1 IN EXE BY TE3-IN EX. 20 +EY1 PIC X(5). 20 +EY2 PIC X(10).

6al7es after eCec7tion:


TE1-IN EX - 1 TE2-IN EX - , TE3-IN EX .o/012 1o 134 TABLE-ENTRY3 /145 1361 478692 "A123,AAAAAAAA00" RETURN-CO E - 0 o Binary search 4!)'-CH 'LL):

To do $inary searches# 7se !)'-CH 'LL and indeCing*


The re97irement to do a $inary search is that the ta$le sho7ld $e sorted in ascending or descending order 4i*e* in <ey se97ence)* ' $inary search can $e considera$ly more efficient than a serial search*

1or a serial search# the n7m$er of comparisons is of the order of


n# the n7m$er of entries in the ta$le* 1or a $inary search# the n7m$er of comparisons is of the order of only the logarithm 4$ase 2) of n* ' $inary search# however# re97ires that the ta$le items already $e sorted*

'n indeC cannot $e part of a calc7lation# cannot $e .O6)d to


another field or cannot receive another field from a .O6) and it

cannot $e "!,L'>ed* To manip7late an indeC the !)T statement m7st $e 7sed* oing a $inary search 4!)'-CH 'LL) "f yo7 7se !)'-CH 'LL to do a $inary search# yo7 do not need to set the indeC $efore yo7 $egin* The indeC is always the one that is associated with the first indeC/name in the OCC0-! cla7se* The indeC varies d7ring eCec7tion to maCimiDe the search efficiency* To 7se the !)'-CH 'LL statement to search a ta$le# the ta$le m7st specify the '!C)% "%( or )!C)% "%( &)> phrases of the OCC0-! cla7se# or $oth# and m7st already $e ordered on the <ey or <eys that are specified in the '!C)% "%( and )!C)% "%( &)> phrases* "n the WH)% phrase of the !)'-CH 'LL statement# yo7 can test any <ey that is named in the '!C)% "%( or )!C)% "%( &)> phrases for the ta$le# $7t yo7 m7st test all preceding <eys# if any* The test m7st $e an e97al/to condition# and the WH)% phrase m7st specify either a <ey 4s7$scripted $y the first indeC/ name associated with the ta$le) or a condition/name that is associated with the <ey* The WH)% condition can $e a compo7nd condition that is formed from simple conditions that 7se '% as the only logical connective* )ach <ey and its o$=ect of comparison m7st $e compati$le according to the r7les for comparison of data items* %ote tho7gh that if a <ey is compared to a national literal or identifier# the <ey m7st $e a national data item* )Cample: Binary search To allow the ta$le to $e searched with the !)'-CH 'LL the description of the ta$le has to $e amended to incl7de a &)> "! phrase as shown $elow* 01 L4114:T6;94. 02 L4114:V69842. 03 !ILLER PIC X(13) VALUE "ABC E!"#I$+LM". 03 !ILLER PIC X(13) VALUE "NOP<RSTUV*XY=". 02 !ILLER RE E!INES L4114:V69842. 03 L4114: PIC X OCCURS 2> TIMES ASCENDING KEY IS Letter IN EXE BY L4114:I?@.

When the ta$le description contains a &)> "! phrase we can search it 7sing the following statement / SEARC# ALL L4114:

AT EN ISPLAY "L4114: " S46:A3L4114: " B62 0o1 Co80?D" *#EN L4114:(L4114:I?@) - S46:A3L4114: SET L4114:Po2 TO L4114:I?@ ISPLAY S46:A3L4114: " /2 /0 .o2/1/o0 " L4114:Po2 EN -SEARC#.

)Cample: Binary search The following eCample shows how yo7 can code a $inary search of a ta$le* !7ppose yo7 define a ta$le that contains E+ elements of I+ $ytes each# and three <eys* The primary and secondary <eys 4+EY-1 and +EY-2) are in ascending order# $7t the least significant <ey 4+EY-3) is in descending order:
01 TABLE-A. 05 TABLE-ENTRY OCCURS E0 TIMES ASCEN IN" +EY-1, +EY-2 ESCEN IN" +EY-3 IN EXE BY IN X-1. 10 PART-1 PIC EE. 10 +EY-1 PIC E(5). 10 PART-2 PIC E(>). 10 +EY-2 PIC E(,). 10 PART-3 PIC E(1'). 10 +EY-3 PIC E(5).

>o7 can search this ta$le $y 7sing the following statements:


SEARC# ALL TABLE-ENTRY AT EN PER!ORM NOENTRY *#EN +EY-1 (IN X-1) - VALUE-1 AN +EY-2 (IN X-1) - VALUE-2 AN +EY-3 (IN X-1) - VALUE-3 MOVE PART-1 (IN X-1) TO OUTPUT-AREA EN -SEARC#

"f an entry is fo7nd in which each of the three <eys is e97al to the val7e to which it is compared 4VALUE-1# VALUE-2# and VALUE-3# respectively)# PART-1 of that entry is moved to OUTPUT-AREA* "f no matching <ey is fo7nd in the entries in TABLE-A# the NOENTRY ro7tine is performed* I) On the ,roced7re ivision# which places is the period re97ired? "f yo7 forgot to p7t this period# yo7 will get a compile error* ,eriod is re97ired only at the following places: o 't the end of each paragraph name* o 't the end of each paragraph*

5) What is the difference $etween ,aragraph and !ection?


,erforming a !)CT"O% will ca7se all the paragraphs that are part of the section# to $e performed* ,erforming a ,'-'(-',H will ca7se only that paragraph to $e performed*

5) What the difference is $etween CO%T"%0) and neCt !)%T)%C)?

CO%T"%0) gives control to the neCt ver$ after the eCplicit scope terminator 4i*e* )% /"1# )% /,)-1O-.# )% /)6'L0'T)# etc)* %)3T !)%T)%C) gives control to the verb ollowing the next !eriod.

J) What is -eference .odifications and provide eCamples? -eference modification defines a data item $y specifying a leftmost character and optional length for the data item* -eference modification eCamples: The following statement transfers the first 1+ characters of the data/item referenced $y WHOL)/%'.) to the data/item referenced $y 1"-!T/%'.)*
(( *#OLE-NAME PIC X(25). (( !IRST-NAME PIC X(10). ... MOVE *#OLE-NAME(1&10) TO !IRST-NAME. The following statement transfers the last 12 characters of the data/item referenced $y WHOL)/%'.) to the data/item referenced $y L'!T/%'.)* (( *#OLE-NAME PIC X(25). (( LAST-NAME PIC X(15). ... MOVE *#OLE-NAME(11&) TO LAST-NAME. The following statement transfers the fo7rth and fifth characters of the third occ7rrence of T'B to the varia$le !011"3* 01 (( ... TABLE-1. 02 TAB OCCURS 10 TIMES SU!!IX

PICTURE X(5). PICTURE X(2).

MOVE TAB O! TABLE-1 (3) (,&2) TO SU!!IX.

A) What is !T-"%( and 0%!T-"%( and provide eCamples? !T-"%( statement o o The !T-"%( statement strings together the partial or complete contents of two or more data items or literals into one single data item* One !T-"%( statement can $e written instead of a series of .O6) statements*

)Cample: 01 *#OLE-NAME 01 !IRST-NAME 01 MI LE-NAME 01 LAST-NAME

PIC PIC PIC PIC

X(25). X(25). X(25). X(25).

MOVE F*ILLIAMF TO !IRST-NAME. MOVE FT#OMASF TO MI LE-NAME. MOVE FRO"ERSF TO LAST-NAME. STRIN" !IRST-NAME ELIMITE BY F F ELIMITE BY MI LE-NAME ELIMITE BY F F ELIMITE BY LAST-NAME ELIMITE BY INTO *#OLE-NAME.

SPACE SI=E SPACE SI=E SPACE

R42891& *#OLE-NAME - G*ILLIAM T#OMAS RO"ERSH 0%!T-"%( statement o The 0%!T-"%( statement ca7ses contig7o7s data in a sending field to $e separated and placed into m7ltiple receiving fields* o )Cample: 01 *#OLE-NAME PIC X(25) VALUE FRO"ERS *ILLIAM T#OMASF. 01 !IRST-NAME PIC X(25). 01 MI LE-NAME PIC X(25). 01 LAST-NAME PIC X(25). UNSTRIN" *#OLE-NAME ELIMITE BY SPACE INTO LAST-NAME !IRST-NAME MI EN -UNSTRIN" R42891& !IRST NAME - G*ILLIAMH MI LE NAME - GT#OMASH LAST NAME - GRO"ERSH. E) What is the ,)-1O-. statement in COBOL and what the different formats? The ,)-1O-. statement transfers control eCplicitly to one or more proced7res and implicitly ret7rns control to the neCt eCec7ta$le statement after eCec7tion of the specified proced7res is completed* The ,)-1O-. statement is:

LE-NAME

o 'n o7t/of/line ,)-1O-. statement is when a proced7re name is specified*


)Cample: ,)-1O-. 1+++/"%"T"'L"K)/-T%

o "n in/line ,)-1O-. statement is when proced7re name is omitted*


)Cample: ,)-1O-. 0%T"L !LLCO ) M N1++

* * * )% /,)-1O-. 'n in/line ,)-1O-. m7st $e delimited $y the )% /,)-1O-. phrase* The in/line and o7t/of/line formats cannot $e com$ined* 1or eCample# if procedurename-1 is specified# imperative statements and the )% /,)-1O-. phrase m7st not $e specified* The ,)-1O-. statement formats are: o o o o Basic ,)-1O-. ,)-1O-. n T".)! ,)-1O-. 0%T"L ,)-1O-. 6'->"%(

"n a ,)-1O-. 0%T"L format# the condition is tested B)1O-) the perform* To ma<e the perform paragraph at least once in a ,)-1O-. 0%T"L# add the cla7se W"TH T)!T '1T)-* )Cample: PER!ORM PARA-A *IT# TEST A!TER VARYIN" X !ROM 1 BY 1 UNTIL X - 5.

1+) What is )3"T and when do yo7 7se it?


)3"T is =7st a placeholder* "t does not do anything*


The )3"T statement provides a common end point for a series of paragraphs* "t assigns a name to a given point in a program# and has no other effect on the compilation or eCec7tion of the program* The )3"T statement m7st $e preceded $y a paragraph/name and m7st appear in a sentence $y itself* This sentence does not need to $e the only sentence in the paragraph* The )3"T statement is 7sef7l for doc7menting the end point in a series of paragraphs* "f an )3"T paragraph is written as the last paragraph in a declarative proced7re or a series of performed proced7res# it identifies the point at which control will $e transferred: When control reaches s7ch an )3"T paragraph and the associated declarative or ,)-1O-. statement is active# control is transferred to the appropriate part of the ,roced7re ivision* When control reaches an )3"T paragraph that is not the end of a range of proced7res governed $y an active ,)-1O-. or 0!) statement# control passes thro7gh the )3"T statement to the first statement of the neCt paragraph*

11) What is the difference of %)!T) /"1 and )6'L0'T)? To $est descri$e a %)!T) /"1# here s an eCample8 "1 ' M 1 ,)-1O-. ,'-/' TH-0 ,'-/'/)3"T )L!) "1 ' M 2 ,)-1O-. ,'-/B TH-0 ,'-/B/)3"T )L!)

"1 ' M F ,)-1O-. ,'-/C TH-0 ,'-/C/)3"T )L!) ,)-1O-. ,'-/ TH-0 ,'-/ /)3"T )% /"1 )% /"1 )% /"1 The )6'L0'T) ver$ is COBOL@s version of the Case or !witch constr7ct $7t the )6'L0'T) is far more powerf7l and easier to 7se than either of these constr7cts* We can replace the %)!T) /"1 a$ove with the following statements: )6'L0'T) ' WH)% 1 ,)-1O-. ,'-/' TH-0 ,'-/'/)3"T WH)% 2 ,)-1O-. ,'-/B TH-0 ,'-/B/)3"T WH)% F ,)-1O-. ,'-/C TH-0 ,'-/C/)3"T WH)% OTH),)-1O-. ,'-/ TH-0 ,'-/ /)3"T )% /)6'L0'T) 'nother way is eval7ating a $oolean: )6'L0'T) T-0) WH)% )--O,)-1O-. ,'-/' TH-0 ,'-/'/)3"T WH)% )--O-/1-)) ,)-1O-. ,'-/B TH-0 ,'-/B/)3"T WH)% OTH),)-1O-. ,'-/C TH-0 ,'-/C/)3"T )% /)6'L0'T) >o7 can add m7ltiple arg7ments in a )6'L0'T) $y delimiting each arg7ment $y 'L!O* )Cample: EVALUATE *#EN 1 *#EN > *#EN 1( *#EN 1 *#EN > *#EN 1( *#EN 1 *#EN > *#EN 1( *#EN 1 *#EN > *#EN 1( *#EN 1 *#EN > *#EN 1( *#EN 1 *#EN > *#EN 1( <1I T#RU T#RU T#RU T#RU T#RU T#RU T#RU T#RU T#RU T#RU T#RU T#RU T#RU T#RU T#RU T#RU T#RU T#RU 5 1> EE 5 1> EE 5 1> EE 5 1> EE 5 1> EE 5 1> EE ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO VOP VOP VOP VOP VOP VOP VOP VOP VOP VOP VOP VOP VOP VOP VOP VOP VOP VOP TRUE J 501 J 501 J 501 J 2001 J 2001 J 2001 ) 2000 ) 2000 ) 2000 J 501 J 501 J 501 J 2001 J 2001 J 2001 ) 2000 ) 2000 ) 2000 ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO ALSO M45;4: "Y" MOVE "Y" MOVE "Y" MOVE "Y" MOVE "Y" MOVE "Y" MOVE "Y" MOVE "Y" MOVE "Y" MOVE "N" MOVE "N" MOVE "N" MOVE "N" MOVE "N" MOVE "N" MOVE "N" MOVE "N" MOVE "N" MOVE 2 3 5 ( 12 1' 10 23 35 1 2 3 5 10 15 ' 23 2' TO TO TO TO TO TO TO TO TO TO TO TO TO TO TO TO TO TO /2Ao801 /2Ao801 /2Ao801 /2Ao801 /2Ao801 /2Ao801 /2Ao801 /2Ao801 /2Ao801 /2Ao801 /2Ao801 /2Ao801 /2Ao801 /2Ao801 /2Ao801 /2Ao801 /2Ao801 /2Ao801

EN -EVALUATE 12) What is "%"T"'L"K) and what happens when we "%"T"'L"K) a 1"LL)-? The "%"T"'L"K) command is 7sed to set all of the val7es for fields in the same gro7p/ level field to either + or spaces# depending on the field@s definition* The statement: INITIALI=E *S-"ROUP.

where:
01 *S-"ROUP. 05 *S-!IEL 05 *S-!IEL 05 *S-!IEL 05 *S-!IEL -1 -2 -3 -, PIC PIC PIC PIC X(05). EEE. SE(0,)VEE. X(100).

is the e97ivalent to .O6)ing !,'C)! to W!/1")L /1 and W!/1")L /I and .O6)ing K)-O! to W!/1")L /2 and W!/1")L /F* The nice thing is that as elementary fields are added to the gro7p the "%"T"'L"K) will a7tomatically ta<e care of them* "%"T"'L"K) will not change the val7e of any 1"LL)- items* "f a non/1"LL)- item has a 6'L0) cla7se it will still get either K)-O! or !,'C)! with the "%"T"'L"K) statement* The 6'L0) is ignored*

1F) What are the different 7ses of "%!,)CT? "%!,)CT has two p7rposes* "t can co7nt the n7m$er of times a partic7lar character appears in an alphan7meric string# and it can change those characters to another* INSPECT field-1 TALLYIN" field-2 !OR target. Where field/1 is an alphan7meric field and field/2 is a n7meric field that will hold the co7nt* target has a few different possi$ilities* "t can $e the word CH'-'CT)-! in which case field/2 holds the n7m$er of characters in the alphan7meric string* Or a specific character can "%!,)CTed for 7sing either 'LL or L)' "%( followed $y the character* 1inally# any of these forms can $e ended with a B)1O-)O'1T)"%"T"'L cla7se:
INSPECT INSPECT INSPECT INSPECT *S-A *S-A *S-A *S-A TALLYIN" TALLYIN" TALLYIN" TALLYIN" *S-N *S-N *S-N *S-N !OR !OR !OR !OR ALL FKF LEA IN" SPACES C#ARACTERS A!TER INITIAL SPACE F,F BE!ORE INITIAL F0F

To 7se "%!,)CT to change partic7lar characters in an alphan7meric string# 7se -),L'C"%( instead of T'LL>"%(* The CH'-'CT)-!# 'LL and L)' "%( cla7ses are valid with -),L'C"%(# as is 1"-!T* >o7 can also 7se the B)1O-)O'1T)"%"T"'L cla7se with -),L'C"%(* INSPECT *S-A REPLACIN" ALL SPACES BY =EROES INSPECT *S-A REPLACIN" !IRST FAF BY FBF

INSPECT *S-A REPLACIN" ALL F F BY F0F A!TER INITIAL F,F 1I) What are the ways to get the system c7rrent date and time in COBOL? The 2 ways to get the c7rrent date and time in COBOL are thr7: o 'CC),T ver$ o Thr7 the date f7nction: C0--)%T/ 'T)* 'CC),T ver$: o 'CC),T W!/ 'T) from 'T) o 'CC),T W!/T".) from T".)* o 'CC),T W!/ '> from '>* o 'CC),T W!/ '>/O1/W))& 1-O. '>/O1/W))&* Where: W!/ 'T) is ,"C E45)* The date will $e in yymmdd format W!/T".) is ,"C E4A)* The time will $e in hhmmsscc format where cc is h7ndredths of a second* hh will $e in military time 4+/2F) W!/ '> is ,"C E4F)* The val7e will represent the c7rrent P7lian date# which is a n7m$er from 1/F55 representing the date as a n7m$er of days relative to the end of the previo7s year 4Pan 1st M 1# 1e$ 1st M F2# etc*)* W!/ '>/O1/W))& is ,"C E* The val7es range from 1 4.onday) to J 4!7nday)* ate 17nction 4C0--)%T/ 'T)): o ,ro$a$ly the most 7sef7l intrinsic f7nction is C0--)%T/ 'T) which is a replacement for 'CC),T 'T) and 'CC),T T".)* C0--)%T/ 'T) is >2&/compliant# having a I/digit year* This f7nction ret7rns a 2+/character alphan7meric field which is laid o7t as follows: 01 *S-CURRENT- ATE-!IEL S. 05 *S-CURRENT- ATE. 10 *S-CURRENT-YEAR 10 *S-CURRENT-MONT# 10 *S-CURRENT- AY 05 *S-CURRENT-TIME. 10 *S-CURRENT-#OUR 10 *S-CURRENT-MINUTE 10 *S-CURRENT-SECON 10 *S-CURRENT-MS 05 *S- I!!-!ROM-"MT

PIC PIC PIC

E(,). E(2). E(2).

PIC E(2). PIC E(2). PIC E(2). PIC E(2). PIC SE(,).

o o

!o not only can yo7 get the time down to the millisecond# $7t yo7 can get the difference $etween yo7r time and (reenwich .ean Time* The f7nction is 7sed in a .O6): MOVE !UNCTION CURRENT- ATE TO *S-CURRENT- ATE-!IEL S

B7t normally reference modification is 7sed to only gra$ the part yo7 want:

K "41 134 A8::401 ?614 /0 IIII55?? Co:561 MOVE !UNCTION CURRENT- ATE (1&') TO *S-TO AY K "41 134 A8::401 1/54 /0 335522 Co:561 MOVE !UNCTION CURRENT- ATE (E&>) TO *S-TIME 12) What are the 2 techni97es to pass data from a PCL to a COBOL program? ,assing a ,arameter via ,'-.M o This techni97e 7ses a ,'-.Mparameter <eyword on the )3)C statement in PCL* The COBOL program re97ires a L"%&'() !)CT"O%* OO!T),+1 )3)C ,(.M,-O(%'.)#P R#$%data string@ o When the data string is passed from JCL to COBOL it is preceded with a two-byte binary val e that specifies the length of the data string! "or e#ample$ if the data string is ten characters in length the act al information passed to the COBOL program wo ld be a two-byte binary val e of ten or #%&&&'% followed by the ten character data string! (f the COBOL program is e#ec ted from JCL witho t a parameter the two-byte binary val e wo ld be )ero or #%&&&&%! The L"%&'() !)CT"O% of the COBOL program will contain the 2/$yte $inary field 4i*e* ,'-./L)%(TH) and the act7al data 4i*e* ,'-./ 'T')* LINK !E SECTION" +1 ,'-./B011)-* +2 ,'-./L)%(TH +2 ,'-./ 'T' o

,"C !E4I) comp* ,"C 34225)*

To <now if there is a parameter passed to the COBOL program# chec< the ,'-./L)%(TH if it is greater than Dero* "f so# data was passed# otherwise no data was passed* ' ,'-./L)%(TH to K)-O ("6"%( PCL/,'-./L)%(TH "1 ,'-./L)%(TH Q + .O6) ,'-./ 'T'41:,'-./L)%(TH) to .)!!'()/T)3T )% /"1 .aCim7m length of ,'-. field of the PCL )3)C operator is 1++ characters* Long ,'-. val7es won@t fit into one line which can span only thro7gh pos* J1 and it might $ecome necessary to contin7e ,'-. field to the neCt line* "f ,'-. field &ontains &omma-de'imited parameters# split ,'-. field at the comma and enclose entire ,'-. field into parenthesis* ,'-. contin7ation sho7ld $e no f7rther than pos* 15 of the neCt line* )Cample: ((STEP) E*EC P!#$IE+BR),-P R#$()../01)2(( )../0133) ((STEP3 E*EC P!#$IE+BR),-P R#$(%ST RT$01()/(./%(( %STOP$01(33(./%)

o o

"f ,'-. field doesn%t &ontain &omma-de'imited parameters# enter ,'-. field data thro7gh pos* J1 and then contin7e eCactly in pos* 15 of the neCt line and enclose entire ,'-. field into apostrophes* )Cample: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7//STEP3 EXEC PGM=IEF !14"PA!M=#L$NG PA!AMETE! FIELD %IT&$'T C$MMA DEL // IMITE!S - C$NTIN'ED IN C$L'MN 16 $F T&E NEXT LINE# "f ,'-. eCceeds 1++ chars# it is necessary to 7se !>!"% instead 4neCt techni97e $elow) or inp7t files*

,assing a ,arameter via !>!"% This techni97e re97ires !>!"% statement followed $y the parameter to $e placed in the PCL* OO!T),+1 )3)C ,(.M,-O(%'.) OO!T),L"B !%MT!T*',,L*LO' L"B# "!,M!H((S4SIN 55 6 T7is is a 8arameter (6 OOG OO The in/stream parameter sho7ld $e terminated $y a OG* The COBOL program re97ires an ?'CC),T parameter from !>!"%? to $e coded in the COBOL program* "f the !>!"% statement is missing in the PCL the 'CC),T will 'B)% with a ?1ile not fo7nd? message* To avoid this it will $e necessary to 7se a ?OO!>!"% 0..>? statement in the PCL when a parameter is not $eing passed* accept !>!"%/,'-'.)T)- from S4SIN

15) What is CO.,/F and how do yo7 comp7te the length? COBOL ?Comp/F?# also called ?Comp7tational/F?# ?,ac<ed ecimal?# or ?,ac<ed?*

COBOL Comp/F is a $inary field type that p7ts 4?pac<s?) two digits into each $yte# 7sing a notation called Binary Coded ecimal# or BC * This halves the storage re97irements compared to a character# or COBOL ?display?# field* To calc7late the n7m$er of $ytes from the ,"C# add 1 4for the sign) to the total n7m$er of digits# divide $y 2# and ro7nd 7p if necessary* Therefore# for ,"C !E4m)vE4n)# form7la is: 4m N n) N 1 O 2* "f res7lt is a decimal# ro7nd it 7p* 1or eCample: ,"C !E4J) CO.,/F* ,"C !E42)6EE CO.,/F* ,"C !E45) CO.,/F* Byte siDe M 4J N 1) O 2 M I Byte siDe M 42 N 2 N 1) O 2 M I Byte siDe M 45 N 1) O 2 M F*2# ro7nded to I

Comp/F fields reserve a ny$$le for the sign# even for ?7nsigned? val7es# so the following fields are still I $ytes: ,"C E4J) CO.,/F* Byte siDe M 4J N 1) O 2 M I ,"C E45) CO.,/F* Byte siDe M 45 N 1) O 2 M F*2# ro7nded to I

1J) 1A) s

You might also like