0% found this document useful (0 votes)
313 views

COBOL Programming

cobol

Uploaded by

Richard Edwin
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
313 views

COBOL Programming

cobol

Uploaded by

Richard Edwin
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 115

STRUCTURED COBOL An Overview

Tata Consultancy Services ltd.

February 27, 2014

Course Pre-requisites
Some knowledge of information processing concepts and terms.

Topics Covered
Introduction to COBOL Program Structure ata T!pes Coding "ormat Programming ivisions Programming S!nta# Input$Output Processing String %andling &eport 'eneration

O()ectives
To *nderstand T+e "eatures of COBOL COBOL Programming S!nta# Condition Statements ,odes of "ile Processing %ow to Call ot+er Programs &eport 'eneration

COBOL L-.'*-'/
CO,,O. B*SI./SS O&I/.T/ L-.'*-'/ O&I'I. CO.C/I0/ 1 2343 P&/LI,I.-&5 0/&SIO. 1 /C 2343 "I&ST ST-. -& COBOL 1 2362 ST-. -& 0/&SIO.S -PP&O0/ B5 -.SI 1 23678 239: L-T/ST COBOL 0/&SIO. 1 2374 3; 0/&SIO. /;P/CT/
5

SO,/ COBOL "/-T*&/S


/.'LIS% LI</ w+ere we emplo! ver(s like cop!8 add8 su(tract8 move8 compute etc. S/L" OC*,/.TI.' w+ere we can incorporate comments for (etter understanding.

SO,/ COBOL "/-T*&/S


0OL*,I.O*S -T- P&OC/SSI.' ,ore comple# mat+ematical manipulations involving large volumes of data P&I.CIPL/S O" ,O *L-& /SI'. In+erent Structured programming principles makes t+e program modular.

SO,/ COBOL "/-T*&/S


I$O OP/&-TIO.S -&/ /-SIL5 /SI'..-T/ w+ere t+e placement of input and output definitions are known. S/&0/S B*SI./SS "*.CTIO.S Programs are compiled and an o()ect program is created for e#ecution.

COBOL P&O'&-, ST&*CT*&/


P&O'&-, I0ISIO.S S/CTIO.S P-&-'&-P%S S/.T/.C/S ST-T/,/.TS =O& S
!

COBOL C%-&-CT/& S/T


COBOL 9: - 42 C%-&-CT/&S COBOL 74 - 4> C%-&-CT/&S ?1@ - new feature included to identif! a segment of data suc+ as .-,/ ?>414@ ena(les t+e programmer to access 4 c+aracters data from >4t+ (!te.

10

COBOL =O& S
&/S/&0/ =O& S T+ese are t+e Co(ol ver(s for specific functions can not (e used as user defined data names. e.g1 T5P/8 C&8 &8 BL-.<8 SP-C/8 A/&O etc.

11

COBOL =O& S
*S/& /"I./ =O& S -T+e word$.ame can (e an!t+ing ad+ering to t+e prescri(ed standards and naming conventions. -Ot+er t+an &eserved words.
,-; BC C%-&-CT/&S --A C-3 %5P%/. w+ic+ ma! not appear as first or last c+aracter

12

COBOL -T LIT/&-LS ?CO.ST-.TS@ -T--.-,/S ?0-&I-BL/S@

13

LIT/&-LS
-LP%-.*,/&IC - enclosed wit+in quotes ma#. 26C c+aracters long .*,/&IC - C-3 ?optional sign D decimal@ ma#. 27 digits "I'*&-TI0/ CO.ST-.T E A/&O8A/&OS8A/&O/S E F*OT/8F*OT/S E SP-C/8SP-C/S E %I'%-0-L*/8LO=-0-L*/8-LL
14

-T- .-,/S ?I /.TI"I/&S@


B T5P/S O" -T- .-,/S -LP%-.*,/&IC ,a# 26C c+aracters8 efined wit+ PIC ;. .*,/&IC ,a# 27 digits efined wit+ PIC 3 ?S for Sign 0 for decimal@ S and 0 are implicit -LP%-B/TIC ,a# 26C digits8 can contain onl! space D alp+a(ets efined wit+ PIC 15

COBOL Coding Format

Tata Consultancy Services ltd.

February 27, 2014

16

COBOL CO I.' "O&,-T


*nlike ot+er languages8 Co(ol e#pects us to code t+e program in a specific format. T+e start and end positions$columns are clearl! defined. It is possi(le t+at t+e compiler ma! t+row t+e entire program wit+ errors unless t+e rules are followed. *nderstand -rea - and -rea B.

17

COBOL CO I.' "O&,-T


COL*,.S 2-6 Ignored (! t+e compiler 2-B page num(er and :-6 line num(er COL*,. 9 comment G continuation page (reak $ de(ug

COL*,.S 7 - 22 -rea ivision names8 Section names8Paragrap+ names COL*,.S 2> - 9> -rea B COBOL code is written +ere COL*,.S 9B-7C Ignored (! compiler

1!

COBOL CO I.' "O&,-T


T+ere are ivisions8 sections8 paragrap+s8 sentences8 statements and words in Co(ol. ivision8 section names are predefined and same names are to (e coded. Paragrap+ names can (e an! name as per t+e TCS prescri(ed standards or as per t+e standards provided (! t+e client.

20

COBOL CO I.' "O&,-T


H-----H------------------------B--------------------------------------------2I...7.2CIIIIIIIIIIIIIIIIIIIII.9>II.7C I0ISIO.S. S/CTIO.S P-&-'&-P%S S/.T/.C/S CO.SISTI.' O" ST-T/,/.TS -. =O& S

21

COBOL CO I.' "O&,-T


Identification ivision will provide t+e information to identif! t+e program-id8 aut+or8 dates and t+e purpose and function of t+e program. /nvironment ivision will provide information in two parts suc+ as details of configuration of t+e computer and Input-Output section will provide details of inputs and outputs used . ata ivision will provide t+e data(ase structures in file section8 memor! varia(le definitions in working-storage section and parameters definitions in linkage-section. Procedure ivision will +ave t+e entire functional logic (ased on (usiness rules specified.
22

I0ISIO.S O" COBOL


I0ISIO.S I /.TI"IC-TIO. I0ISIO. /.0I&O.,/.T I0ISIO. -T- I0ISIO. P&OC/ *&/ I0ISIO.

23

I /.TI"IC-TIO. I0ISIO.
P&O'&-,-I . P&O'&-,-.-,/. J-*T%O&. Comment entr!K JI.ST-LL-TIO.. Comment entr!K J -T/-=&ITT/.. Comment entr!K -T/-CO,PIL/ . Comment entr!K S/C*&IT5. Comment entr!K

24

/.0I&O.,/.T I0ISIO.
> S/CTIO.S CO."I'*&-TIO. S/CTIO. I.P*T-O*TP*T S/CTIO. CO."I'*&-TIO. S/CTIO. SO*&C/-CO,P*T/& OBL/CT-CO,P*T/&. SP/CI-L-.-,/S.

25

I.P*T-O*TP*T S/CTIO.
CO.SISTS O" > S/CTIO.S "IL/-CO.T&OL. .ames eac+ file 1 -ll files consisting of inputs8 outputs are to (e defined +ere. Identifies file medium I-O CO.T&OL. Specifies file location on multiple file reel s+ared memor! areas

26

I.P*T-O*TP*T S/CTIO.
"IL/-CO.T&OL.
S!nta#1 Select infil assign to infile. Logical "ile .ame 1 "ile name referred t+roug+out t+e program for open8 read8 write and close. ?infil@ P+!sical "ile .ame1 "ile name referred in LCL and S+ell Scripts to link to t+e logical file name in t+e program.?infile@

27

I.P*T-O*TP*T S/CTIO.

isk Storage

Select /,P"IL/ assign to " /,P"IL/. C2 /,P&/C. C4 /,P.O C4 /,P.-,/ C4 /,P /S'CO / C4 /,PB-SIC C4 /,PP&OL

/,P"IL/

Central Storage

/,P&/C ?&/CO& @
"ield "ield "ield "ield "ield

"IL/ CO.T&OL P-&S/L/CT logical file name -SSI'. TO ddname O&'-.IA-TIO. IS S/F*/.TI-L I. /;/ &/L-TI0/ -CC/SS IS S/F*/.TI-L &-. O, 5.-,IC &/CO& </5 IS data-name-2 -LT/&.-T/ </5 IS data-name-> "IL/ ST-T*S IS file-stat
2!

"IL/ CO.T&OL P-&Important points to note for inde#ed files1 2. If t+e organiMations is inde#ed and access is random- records can (e accessed randoml! and not sequentiall!. >. If t+e organiMation is inde#ed and access is d!namic - records can (e accessed randoml! as well as sequentiall!.

30

"IL/ CO.T&OL P-&"IL/-ST-T*S *sed to c+eck t+e following1 2. To c+eck t+e e#istence of a file w+ile open8 close. >. To c+eck t+e e#istence of a record. B. To c+eck t+e invalid ke!s

31

-T- I0ISIO.
"IL/ S/CTIO. =O&<I.'-STO&-'/ S/CTIO. LI.<-'/ S/CTIO.

32

-T- I0ISIO.
L/0/L ST&*CT*&/ In+erent in t+e logical record /ac+ (asic su(division is an elementar! item /lementar! items ma! form part of one or more groups Level num(ers 1 C2 - :3 1 66 99 77

33

-T- I0ISIO.
PICT*&/ CL-*S/
Picture clause is used to specif! t+e t!pe of field8 its siMe8 and its form. PIC used in Co(ol is t+e a((reviated form of PICT*&/. PIC or PICT*&/ is a reserved word. PIC or PICT*&/ can not (e used as a user defined data name. PIC is followed (! t!pe and lengt+ of field in (rackets

34

-T- I0ISIO.
PICT*&/ CL-*S/ Specified for ever! elementar! item .umeric ata item - 3 P S 0 ? @ -lp+a(etic data item - - B ? @ -lp+anumeric data item - ; ? @

35

PICT*&/ CL-*S/S
/;-,PL/S 1 3?:@033 N numeric value wit+ decimals. ;?>C@ N alp+anumeric values -?2C@ N alip+atic values S3?:@033 N signed field B?:@ N num(er of (lanks

36

"IL/ S/CTIO.
T+e rules for defining a file structure.
"ile description is denoted (! " followed (! t+e logical file name. &ecord name will +ave to (e at C2 level. T+e name defined at C2 level represents t+e entire record. T+e segments or fields of record are defined wit+ levels w+ic+ is greater t+an C2. ?In general it will (e multiples of 4.@ 0alues can not (e assigned to an! field in t+e file la! out. /#ception is 77 level w+ic+ is e#plained in t+e su(sequent PPT.

37

"IL/ S/CTIO.
/#ample for defining file la!out. " /,P,-S. C2 /,P&/C. C4 /,P-.O PIC 3?C6@. C4 /,P-.-,/. 2C "I&ST-.-,/ PIC ;?24@. 2C ,I L/-.-,/ PIC ;?>C@. 2C L-ST-.-,/ PIC ;?>C@. ?.aming standards are not followed +ere@
3

"IL/ S/CTIO.
" /.T&5 "O& /-C% "IL/ "OLLO=/ B5 &/CO& /SC&IPTIO. ?(egins in C2 level@ "ile record naming convention 1 e#1 ;..-TTTT-&/C ;.. 1 "irst B c+aracters of file name TTTT1 .ame of record ? 2 to >> c+aracters@ &/C 1 S+ould appear as it is O2-CO.T&OL-&/C PC3-P&I.T-&/C
3!

=O&<I.'-STO&-'/ S/CTIO.
Succeeds "ile Section *sed "or Intermediate Storage /.'.8
C2 =-,/,- /T-ILS.

C4 =-,/,-.*, PIC 3?2C@ C4 =-,/,-- &/SS.

2C =-,/,-- &-LI./2 PIC ;?BC@. 2C =-,/,-- &-LI./> PIC ;?BC@. Please see notes (elow.
40

0-L*/ CL-*S/
-ssigns Initial 0alue To - ata Item S!nta# 1 0alue Is literal literal can (e
.*,/&IC .O.-.*,/&IC I. F*OT/S "I'*&-TI0/ CO.ST-.T

/#amples1 C4 ws-(asic pic 3?C4@ value >CCCC. C4 ws-code pic #?C4@ value OC >CCCP. C4 ws-varia(le-pa! pic 3?C4@ value Mero.

41

/ ITI.' C%-&-CT/&S
.*,/&IC / ITI.' -T A A/&O S*PP&/SSIO. G 8 Q - R C& B P/&IO BL-.< 8 A/&O8 SL-S%8BL-.< =%/. A/&O -LP%-B/TIC BL-.< I.S/&TIO. -LP%-.*,/&IC BL-.<8 A/&O 8 SL-S% I.S/&TIO.
42

CO. ITIO. .-,/S


-PP/-&S I. L/0/L 77. CO.SI /& - -T- IT/, S-L-&5 C2 S-L-&5 PIC 3?4@033 . TO C%/C< "O& 0-LI IT58 I" S-L-&5 S 7CCC -. S-L-&5 T >4CCC C-. B/ *S/ . USING CONDITION-NAMES C2 S-L-&5 PIC 3?4@033.
77 C-0-LI -S-L-&5 0-L*/ 7CCC T%&* >4CCC I" C-0-LI -S-L-&5 C-. B/ *S/ .
43

CO. ITIO. .-,/S - CO.TI.*/


TO C%/C< "O& '&- / C2 '&- / PIC ;. 77 C-0-LI -'&- / 0-L*/ O-P8PBP8PCP. 77 C-'&- /-0-L*/ O-P 77 C-'&- /-B 0-L*/ OBP 77 C-'&- /-C 0-L*/ OCP I" C-0-LI -'&- /?to c+eck for - or B or C@ I" C-'&- /-B ?to c+eck for grade B alone@
44

&/ /"I./S
T%IS CL-*S/ -LLO=S T%/ S-,/ -&/- O" ,/,O&5 TO B/ &/"/&/.C/ B5 ,O&/ T%-. O./ -T--.-,/ =IT% I""/&/.T "O&,-TS -. SIA/S. TL/0/LS T -T--.-,/-2S &/ /"I./S T -T--.-,/->S T%IS CL-*S/ ,*ST I,,/ I-T/L5 "OLLO= T -T--.-,/-2S L/0/L .OS O" T.-,/-2S -. T.-,/->S ,*ST B/ I /.TIC-L -. .OT 66 O& 77.

45

&/ /"I./S
-. /;-,PL/1 C2 -5S-I.-=//<. C4 -5-.-,/S PIC ;?>2@ 0-L*/ US*.,O.T*/...V. C4 =-.-,/S &/ /"I./S -5-.-,/S. 2C =- -5S PIC ;?B@ OCC*&S 9 TI,/S. T+e da!s can (e accessed as =- -5S?2@8=- -5S?>@8/TC.

46

&/ /"I./S
.OT/ 21 -T C2 L/0/L8 &/ /"I./S D OCC*&S C-..OT B/ CO,BI./ . .OT/ >1 O&I'I.-L -T- .-,/ -. &/ /"I./ I""/&/.T. -T- .-,/S S%O*L B/

.OT/ B1 .// TO B/ C-*TIO*S =%IC% .-,/ IS B/I.' *S/ I. P&OC/ *&/ I0ISIO.. .OT/ :1 &/,/,B/& T%-T BOT% =ILL %-0/ S-,/ 0-L*/ *.L/SS ./= 0-L*/S -&/ -SSI'./ B/"O&/ ,O0I.' TO OT%/& /.TIT5.

47

*S-'/ CL-*S/
"O&,S O" I.T/&.-L &/P&/S/.T-TIO. ISPL-5 CO,P CO,P2 CO,P> CO,PB S5.T-;1 *S-'/ IS ISPL-5 CO,P-2
4

*S-'/ CL-*S/ CO.TI.*/


CO,P ,-I.T-I./ I. BI.-&5 "O&, .O.O" 3PS L/.'T% I. B5T/S 2 TO : > 4 TO 3 : 2C TO 27 7 CO,P-2 O./ =O& I. "LO-TI.' POI.T "O&,-T
4!

*S-'/ CL-*S/ CO.TI.*/


CO,P-> Two words in floating point form no pic clause for CO,P-2 D CO,P->. CO,P-B : (inar! digits representing single decimal digit /ac+ digit and sign occup! 2$> (!te

50

LI.<-'/ S/CTIO.
&equires onl! w+en ot+er programs are called to perform specific functions. T+is section appears in called program. It is almost like performing some Para wit+ in a program Parameters are defined in called program under t+is section -ll parameters are defined at C2 level. /nsure t+at t+e program-id in called program is same as t+at of t+e program name called from main program.

51

LI.<-'/ S/CTIO.
/#ample1 working-storage section. ----linkage section C2 # pic 33. C2 ! pic 33. C2 M pic 33. .ote1 Please see C-LL ver( for furt+er details.

52

P&OC/ *&/ I0ISIO.


ST&*CT*&/ S/CTIO. - composed of paragrap+s P-&-'&-P% - composed of sentences ?identified (! Para name@.
/g.8 C2CC-&/- -I.P*T S/.T/.C/-Composed of one or more statements and terminated (! Period.

53

COBOL 0/&BS
CL-SSI"IC-TIO. I.P*T O*TP*T -&IT%,/TIC P&OC/ *&/ B&-.C%I.' -T- ,O0/,/.T /. I.' CO. ITIO.-L T-BL/ %-. LI.' CO,PIL/& I&/CTI.' ST&I.'-%-. LI.' OT%/&S
54

I.P*T O*TP*T 0/&BS


-CC/PT *S/ TO &/- -T S5.T-; -CC/PT identifier "&O, mnemonic-name -T/ TI,/ -5

55

ISPL-5
*S/ TO ISPL-5 -T S5.T-; ISPL-5 identifier-1 literal-1 ,identifier2 ,literal2

OP/&-. S S%O*L B/ *S-'/ ISPL-5

56

-&IT%,/&IC 0/&BS
OP/&-TIO.S 1 S*BT&-CT ,*LTIPL5 I0I / CO,P*T/

57

- TO B - TO B &O*. /

0/&B

- - TO B 'I0I.' C &O*. / O. SIA/ /&&O& P/&"O&, /&&-P-& - TO B C - B C TO 'I0I.' / " '

- CO&& '2 TO '> ?CO&& IS T%/ S%O&T "O&, O" CO&&/SPO. I.'@

,*LTIPL58 I0I /8S*BT&-CT


,*LTIPL5 ,*LTIPL5 - B5 B 'I0I.' C O. SIA/ /&&O& P/&"O&, /&&O&-P-&I0I / I0I / - B5 B 'I0I.' C &/,-I. /& S*BT&-CT -lso +as man! formats. Similar to -dd. CO,P*T/ CO,P*T/ P&IC/ N &-T/ G FT5 - ISCO*.T

5!

B&-.C%I.'
P/&"O&, 'O TO ?*nconditional (ranc+ing@ /;IT ?to e#it from a paragrap+@

60

P/&"O&,
P/&"O&, P-&--2 T%&* P-&--. P/&"O&, P-&--2 2C TI,/S P/&"O&, P-&--2 *.TIL C-"IL/-/. P/&"O&, P-&--2 0-&5I.' I "&O, 2 B5 2 *.TIL I S 2C -"T/& P-&--> "&O, 2 B5 2 *.TIL L S4

61

I.-LI./ P/&"O&,
To sum a series for eg.8 2Q>QBQ:Q4QI.Q.
,O0/ C TO S*,-O"- I'ITS ,O0/ 2 TO CO*.T/& P/&"O&, *.TIL CO*.T/& S .

CO*.T/& TO S*,-O"- I'ITS 2 TO CO*.T/&

/. -P/&"O&,.

62

P/&"O&,
P/&"O&, P&OC/SS- /T-IL =IT% T/ST -"T/& *.TIL C-"IL/-/. P/&"O&, P&OC/SS- /T-IL =IT% T/ST B/"O&/ *.TIL C-"IL/-/.

63

-T- T&-.S"/&
ata transfer in Co(ol is done using O,O0/P ver( t+oug+ values in sending field remain unaffected. &eceiving field s+ould not (e smaller t+an sending field to avoid truncation. ,ove of -lip+atic or alp+anumeric value is left )ustified. ,ove of .umeric values is rig+t )ustified.

64

-T- ,O0/,/.T 0/&BS


,O0/ id-1 To id-2 id-3 id-n lit-1 ,O0/ CO&& G-1 TO G-2

65

C-T/'O&5 O" &/C/I0I.' -T- IT/,


CATEGORY OF SENDING DATA ITEM ALPHABETIC ALPHANUMERIC NUMERIC ALPHANUMERIC INTEGER; EDITED NUMERIC NONINTEGER NUMERIC EDITED YES YES NO YES NO NO NO NO
66

ALPHABETIC ALPHANUMERIC ALPHANUMERIC EDITED NUMERIC INTEGER NUMERIC NONINTEGER NUMERIC EDITED

YES YES YES NO YES

NO NO YES YES NO

/. I.'
STOP &*. &/T*&.S CO.T&OLTO OP/&-TI.' S5ST/, STOP lit-1 T/,PO&-&IL5 %-LTS - P&O'&-, /;IT P&O'&-, &/T*&.S "&O, - S*B P&O'&-, TO - ,-I. P&O'&-,
67

CO. ITIO.-L /;P&/SSIO.S


&/L-TIO. &/L-TIO.-L OP/&-TO&S T N SN TN .OT N CL-SS .*,/&IC -LP%-B/TIC SI'. POSITI0/ ./'-TI0/

A/&O

-BB&/0I-T/ CO,PO*. CO. ITIO.S


I" -NB -. -NC is equivalent to I" -NB -. C -SB O& .OT ?-SC@ O& ?-S @ is equivalent to -SB O& .OT C O&

6!

T-BL/ %-. LI.'


/liminates need for separate entries for related data. OCC*&S clause defines ta(les of contiguous data items Can (e specified for elementar! D group items (ut not for C2 99 66 77 levels.
O./ I,/.SIO. T-BL/
C2 ST* /.T-&/C. C4 ST* /.T-.-,/ PIC ;?2C@. C4 ST* /.T-,-&<S OCC*&S 2C TI,/S PIC 333033. ,-&<S C-. B/ -CC/SS/ -S ST* /.T-,-&<S?2@ /TC.8

70

T-BL/ %-. LI.'


O./ I,/.SIO. T-BL/
C2 ST* /.T-&/C. C4 ST* /.T-.-,/ PIC ;?2C@. C4 ST* /.T-,-&<S OCC*&S 2C TI,/S PIC 333033. ,-&<S C-. B/ -CC/SS/ -S ST* /.T-,-&<S?2@ /TC.8

T=O I,/.SIO. T-BL/


C2 ST* /.T-&/C. C4 ST* /.T-.-,/ PIC ;?2C@. C4 ST* /.T-,-&<S OCC*&S 2C TI,/S. 2C ,-&<S-I.T-/;T OCC*&S 2C TI,/S. 24 ,-&<S-I.T PIC 33. 24 ,-&<S-/;T PIC 33. ,-&<S C-. B/ -CC/SS/ -S ST* /.T-,-&<S?282@ /TC.8

71

OCC*&S S5.T-;
"O&,-T-2 OCC*&S integer-2 TI,/S W-SC/. I.'$ /SC/. I.'X </5 IS data-name-1 [data-name-2] JI. /;/ B5 index-name-1 [,index-name-2] .. "O&,-T-> OCC*&S integer-1 to integer-2 TI,/S /P/. I.' O. data-name-1 W-SC/. I.'$ /SC/. I.'X </5 IS [data-name-2] JI. /;/ B5 index-name-1 [,index-name-2] ..

72

I. /;
I. /; IS - ST-C< 0-&I-BL/ ,*ST B/ I.ITI-LIS/ B/"O&/ IT C-. B/ *S/ - B5 *SI.' S/T 0/&B /'.8 S/T I. /;-2 TO 4 S/T I. /;-2 *P B5 2 S/T I. /;-2 O=. B5 2

73

S/-&C%
To searc+ a ta(le element Two searc+ options S/-&C% 0-&5I.' S/-&C% -LL - ma! (e carried out of sorted ta(les.

74

S/-&C%
S/-&C% id-2 0-&5I.' Winde#-2$ id->X -T /. statement-2 =%/. Condition-2 stmt-> S/-&C% -LL id-2 -T /. stmt-2 =%/. Condition-2 ./;T S/.T/.C/

75

S/-&C%
99 .-,/ C2 S-0/-B.<--CCT. PIC ;?>C@

C4 -CCT-TBL OCC*&S :CC TI,/S I. /;/ B5 -2. 2C -CCT-.O PIC 3?6@ 2C -CCT-.-,/ PIC ;?>C@ 2C -CCT--,T PIC 3?6@033. S/T -2 TO 2. S/-&C% -CCT-TBL -T /. ISPL-5 U.OT "O*. V =%/. .-,/N-CCT-.-,/?-2@ ISPL-5 U.-,/ "O*. V ISPL-5 -CCT-.O U U -CCT--,T.

76

S/-&C% -LL
C2 /,P-T-BL/. C4 /-.-,/-.O OCC*&S :C TI,/S -SC/. I.' </5 IS /-.-,/ I. /;/ B5 I. ;-2. 2C /-.-,/ PIC ;?2C@. 2C /-.O PIC 3?2C@. S/-&C% -LL /-.-,/-.O -T /. P/&"O&, .O-"I. -P-&=%/. /-.-,/?I. ;-2@N/,PL-.-,/ ,O0/ /-.O?I. ;-2@ TO /,PL-.O. .OT/1 T-BL/ %-S TO B/ SO&T/ O. /-.-,/.

77

CO,PIL/& I&/CTI.'
COP5 0/&B S5.T-; 1 COP5 U"IL/V

In !t"O!t !t #ro$e%%ing

Tata Consultancy Services ltd.

February 27, 2014

7!

"IL/ I-Os
OP/. CLOS/ &/ =&IT/ &/=&IT/ /L/T/ ST-&T

OP/.
,O /S O" OP/. I.P*T O*TP*T I-O /;T/.

OP/.
,O /S O" OP/. =+en files are opened in input mode8 records can onl! (e read =+en files are opened in output mode8 records can onl! (e written =+en files are opened in input-output ?I-O@ mode8 records can read and write =+en files are opened in /#tend mode8 records can onl! (e appended to t+e e#isting file

OP/.8 CLOS/ 0/&BS


OP/. TmodeS LO'IC-L-"IL/-.-,/ CLOS/ LO'IC-L-"IL/-.-,/

%O= TO C%OOS/ T%/ ,O /Y


OPERATION
READ

SEQUENTIAL
INPUT, I/O

INDEXED
INPUT,I/O

WRITE

OUTPUT,EXTEND

I/O,OUTPUT

REWRITE

I/O

I/O

&/ "O&,-T-2 &/- file-name -T /. imperative statement "O&,-T-> &/- file-name I.0-LI </5 imperative statement "O&,-T-B &/- file-name ./;T &/CO& I.TO identifier -T /. imperative statement

&/ "O&,-T-2 &/- EMPFILE -T /. M !E "#$ % E F. E F to &e defined in 'or(ing-storage se)tion assigning val*e "+$. -T /. clause is determined (! t+e s!stem and 5 is moved to /O" and no furt+er process takes place.

&/ "O&,-T-2 &/- EMPFILE -T /. M !E "#$ % E F. E F to &e defined in 'or(ing-storage se)tion assigning val*e "+$. "O&,-T-> &/- EMPM,- I.0-LI </5 . % P,/,-E0I% "O&,-T-B &/- file-name ./;T &/CO& I.TO identifier -T /. imperative statement

=&IT/
"O&,-T-2 =&IT/ re)ord-name J"&O, id-1K WB/"O&/$-"T/&X - 0-.CI.' Wint-28 LI./8P-'/X "O&,-T-> =&IT/ re)ord-name I.0-LI </5 imperative-statement

&/=&IT/
&/=&IT/ re)ord-name I.0-LI </5 imperative statement

/L/T/
/L/T/ file-name &/CO& I.0-LI </5 imperative statement +ote 11 2ELE%E )an not &e *sed for a se3*ential file. +ote 21 2ELE%E is *sed for Indexed files onl4 '5en t5e file is opened in I- mode.

!0

ST-&T
/.-BL/S POSITIO.I.' O" POI.T/& -T - SP/CI"I/ POI.T I. -. I. /;/ "IL/ "IL/ S%O*L B/ OP/./ I. I.P*T O& I-O ,O / -CC/SS S%O*L B/ S/F*/.TI-L O& 5.-,IC ST-&T O/S .OT &/- T%/ &/CO&

ST-&T file-name </5 IS WN S .OT T X I.0-LI </5 imperative statement

!1

ST&I.' %-. LI.'


I.SP/CT Provides a(ilit! to tall!8 replace c+aracters in a ata item "O&,-T-2 I.SP/CT id-2 T-LL5I.' id-> "O& W-LL id-B$L/- I.' lit-2$C%-&-CT/&SX WB/"O&/$-"T/&X I.ITI-L Wid-:$lit->X

!2

I.SP/CT Icontd
,5-ST&I.' ;?>C@ C%-. &- B-B* .-I * T-LL5-CO*.T 3?>@ 0-L*/ C7 I.SP/CT ,5-ST&I.' T-LL5I.' T-LL5-CO*.T "O& -LL U-V. 2> I.SP/CT ,5-ST&I.' T-LL5I.' T-LL5-CO*.T "O& L/- I.' UCV C3 I.SP/CT ,5-ST&I.' T-LL5I.' T-LL5-CO*.T "O& -LL U-. V B/"O&/ I.ITI-L U&V -"T/& I.ITI-L U%V. C3 I.SP/CT FT5 &/PL-CI.' L/- I.' SP-C/S B5 A/&OS I.SP/CT 5 T-LL5I.' C.T "O& -LL ULV &/PL-CI.' L/- I.' U-V B5 U/V -"T/& I.ITI-L ULV 5?B/"O&/@ L-TT/& 5?-"T/&@ L/TT/& C.T 2

!3

ST&I.'
C2 .-,/. C4 "-.-,/ PIC ;?2C@. C4 ,-.-,/ PIC ;?2C@. C4 S-.-,/ PIC ;?>C@. C2 O*T-&/C PIC ;?6C@. C2 PIC ; 0-L*/ SP-C/S. ST&I.' S-.-,/ /LI,IT/ B5 SP-C/S - /LI,IT/ B5 SIA/ "-.-,/ /LI,IT/ B5 SP-C/S - /LI,IT/ B5 SIA/ ,-.-,/ /LI,IT/ B5 SP-C/S I.TO O*T-&/C.

!4

*.ST&I.'
C2 "I/L -2 PIC ;?24@. C2 "I/L -> PIC ;?24@. C2 "I/L -B PIC ;?24@. C2 C,P-.-,/ PIC ;?>4@ 0-L*/ IS UT-T- CO.S*LT-.C5 S/&0IC/SV. *.ST&I.' C,P-.-,/ /LI,IT/ B5 U U I.TO "I/L -2 "I/L -> "I/L -B. "I/L CO.T/.TS "I/L -2 T-T"I/L -> CO.S*LT-.C5 "I/L -B S/&0IC/S

!5

OT%/& 0/&BS
SO&T &/L/-S/ &/T*&. C-LL I" -. ./ST/ I" /0-L*-T/

!6

SO&T 0/&B
S5.T-;
SO&T SO&T-"IL/ W-SC/. I.'$ /SC/. I.'X </5 data-name-1 J*SI.' inp*t-file$I.P*T P&OC/ *&/ IS se)tion-1 t5r* se)tion-2] J'I0I.' o*tp*t-file$O*TP*T P&OC/ *&/ IS se)tion-6 t5r* se)tion-7]

!7

&/L/-S/
Transfers records to t+e initial p+ase of a sort operation &/CO& .-,/ ,*ST B/ -. S /.T&5 ,-5 .OT B/ *S/ O*TSI / -. I.P*T P&OC/ *&/ O.L5 &/L/-S/ &/CO& S -&/ SO&T/ S5.T-; &/L/-S/ re)ord-name J"&O, identifierK

&/T*&.
O(tains sorted records from t+e final p+ase of sort /#ecution causes t+e ne#t record to (e made availa(le S5.T-; &/T*&. file-name &/CO& JI.TO identifier K -T /. imperative statement

!!

C-LL
S5.T-; C-LL Wid-2$lit-2X J*SI.' data-name-2 J8data-name->KIK J ZO. O0/&"LO= imp-stmtK P&OC/ *&/ I0ISIO. J*SI.' data-name-2 J8data-name->KIK LI.<-'/ S/CTIO. C2 level entries /;IT P&O'&-,

100

C-LL
Calling Program1
I /.TI"IC-TIO. I0ISIO.. P&O'&-,-I . T&.'2. -----------------------------------------------------------T- I0ISIO.. ---C2 PIC 33. C2 B PIC 33. C2 --PL*S-B PIC 333. C2 ST-T*S-CO / PIC ;?:@. ---P&OC/ *&/ I0ISIO.. CALL &TRNG'( USING A) B) A-#LUS-B) STATUS-CODE* I" ST-T*S-CO / N OO.<P P/&"O&, --P-&/LS/ P/&"O&, B-P-&/. -I".

101

C-LL
Called Program1
I /.TI"IC-TIO. I0ISIO.. P&O'&-,-I . T&.'>. -----------------------------------------------------------T- I0ISIO.. ---LI.<-'/ S/CTIO. C2 PIC 33. C2 B PIC 33. C2 --PL*S-B PIC 333. C2 ST-T*S-CO / PIC ;?:@. P&OC/ *&/ I0ISIO. USING A) B) A-#LUS-B) STATUS-CODE* CO,P*T/-P-&-. I" - IS .*,/&IC -. B IS .*,/&IC CO,P*T/ --PL*S-B N - Q B ,O0/ OO.<P TO ST-T*S-CO / /LS/ ,O0/ SP-C/S TO ST-T*S-CO / /. -I". C-LL-/. -P-&-. /;IT P&O'&-,.
102

I" -. /LS/
T+e most important ver( in an! language. *sed for conditional c+ecks /#ample1 if designation-code S C6 perform process-para2 t+ru process-para2-e#it else perform process-para> t+ru process-para>-e#it end-if

103

I" -. /LS/
.ote21 /ver! I+ e#pression ma! +ave e,%e to provide alternate action for false condition. .ote>1 Period at t+e end of statement containing OifP passes t+e control to t+e ne#t statement after period.? see notes@ .oteB1 /nd-if ?scope terminator@ at t+e end of statement nullifies current if statement.

104

Conditional statement-flow
false true
condition

Statement-2

Statement-1

Next sentence
105

./ST/ I"
Points to .ote1 Com(ination of several OI" and /LS/P statements. *sed for c+ecking several conditions to pass t+e control to respective modules. *sed for (ranc+ing complicated calculations. "irst /LS/ pertains to t+e preceding if and ne#t else pertains to t+e I" )ust preceding t+e inner I".

106

./ST/ I"

I"---I"---I"---/LS/---/LS/---/LS/---

107

/0-L*-T/
T+is ver( is added in t+e modified Co(ol version 74. &eplace I" wit+ /0-L*-T/ to avoid complications of ./ST/ I" /. -/0-L*-T/ is t+e scope terminator. Powerful and fast as compared to I".

10

/0-L*-T/
/#ample 21 /0-L*-T/ /S'-CO / =%/. C2 P/&"O&, C2-P-&=%/. C> P/&"O&, C>-P-&=%/. CB P/&"O&, CB-P-&=%/. OT%/& P/&"O&, /&&O&-P-&/. -/0-L*-T/

10!

/0-L*-T/
/#ample >1 /0-L*-T/ T&*/ =%/. C2-- P/&"O&, C2-P-&=%/. C>-- P/&"O&, C>-P-&=%/. CB-- P/&"O&, CB-P-&=%/. OT%/& P/&"O&, /&&O&-P-&/. --0-L*-T/ .ote1 C2-- 8 C>-- and CB-- are 77 level condition names.

110

/0-L*-T/
/#ample B1 /0-L*-T/ /S'-CO / -. B-SIC-P-5 =%/. C2 T%&* CB -LSO 2CCCC T%&* 24CCC P/&"O&, C2CB-P-&=%/. C: T%&* C6 -LSO 24CC2 T%&* >CCCC P/&"O&, C:C6-P-&=%/. OT%/& P/&"O&, /&&O&-P-&/. --0-L*-T/

111

&/PO&T '/./&-TIO.
&equirements 2. input data. >. formatting t+e report. Input is +owever o(tained from input files. "ormatting a print report in Co(ol needs special attention.

112

&/PO&T '/./&-TIO.
CentraliMe %eadings on 7C columnar stationar! C2 +eading-2. C4 filler pic #?>4@ value spaces. C4 filler pic #?>4@ value OTraining Co(ol Batc+ .o 1 O. C4 (atc+-no pic M?C:@(. spacing (etween two data items need to (e defined wit+ num(er of fillers required.

113

Summar!
Introduction to COBOL "eatures Coding "ormat D Programming S!nta# Programming ivisions "ile processing

114

&eferences
OCOBOL *nleas+edP (! Lon =essler and et.al8 ,acmillan$Pearson Tec+nolog! COBOL (ooks and courses in Skillport ?+ttp1$$tcs.skillport.com@ OStructured COBOL ProgrammingP (! Stern D Stern8 Lo+n =ile!8 .ew 5ork OCOBOL Programming including ,S COBOL D COBOL 74P (! &o! D as+tidar8 II edition8 Tata ,c'raw-%ill

115

You might also like