09.
COBOL – Tables &
PERFORM….Varying
Prepared & Presented By: ASM Practices
Date:03/08/2007
A CMMI Level 5 Company
www.zensar.com
Course wise Metadata
Created By: ASM Practices
Credential Training Material
Information: Zensar Technologies
Version and 1.0 03/08/2007
Date:
A CMMI Level 5 Company
www.zensar.com
Course wise Information
Course • This course gives an Overview of COBOL
Description • It provides an insight into developing
applications with COBOL
Prerequisites TSO/ISPF, MVS
Target Trainees
Audience
A CMMI Level 5 Company
www.zensar.com
Course Objective & Outline
Course Objective
After completion of this course, you will be able to
1. get a good understanding of COBOL
2. develop applications using COBOL
Course Outline
1. Tables & PERFORM….VARYING
A CMMI Level 5 Company
www.zensar.com
Course Objective & Outline
1. Tables & PERFORM…VARYING
1.1 Tables / Arrays with an example
1.2 Declaring tables
1.3 Group Items as Elements
1.4 PERFORM….VARYING syntax with an example
A CMMI Level 5 Company
www.zensar.com
TaxTotal
Variable = Named location in memory
PAYENum CountyNum TaxPaid
The program
to calculate
PROCEDURE DIVISION.
Begin. the total
OPEN INPUT TaxFile taxes paid for
READ TaxFile
AT END SET EndOfTaxFile TO TRUE the country is
END-READ easy to write.
PERFORM UNTIL EndOfTaxFile
ADD TaxPaid TO TaxTotal BUT.
READ TaxFile
AT END SET EndOfTaxFile TO TRUE What do we
END-READ
END-PERFORM. do if we want
DISPLAY "Total taxes are ", TaxTotal to calculate
CLOSE TaxFile the taxes paid
STOP RUN. A CMMI Level 5 Company
in each
www.zensar.com
County1 County2 County3 County4 County5
TaxTotal TaxTotal TaxTotal TaxTotal TaxTotal
PROCEDURE DIVISION.
Begin.
OPEN INPUT TaxFile
READ TaxFile
AT END SET EndOfTaxFile TO TRUE
END-READ
PERFORM SumCountyTaxes UNTIL EndOfTaxFile
DISPLAY "County 1 total is ", County1TaxTotal
: : : 24 Statements : : :
DISPLAY "County 26 total is ", County26TaxTotal
CLOSE TaxFile
STOP RUN.
SumCountyTaxes.
IF CountyNum = 1 ADD TaxPaid TO County1TaxTotal
END-IF
: : : 24 Statements : : :
IF CountyNum = 26 ADD TaxPaid TO County26TaxTotal
END-IF
READ TaxFile
AT END SET Level
A CMMI EndOfTaxFile
5 Company TO TRUE
END-READ
www.zensar.com
58 Statements
Tables/Arrays
A table is a contiguous sequence of memory locations
called elements, which all have the same name, and are
uniquely identified by that name and by their position in
the sequence.
CountyTax
10
1 2 3 4 5 6
MOVE 10 TO CountyTax(5)
ADD TaxPaid TO CountyTax(CountyNum)
ADD TaxPaid TO CountyTax(CountyNum + 2)
A CMMI Level 5 Company
www.zensar.com
Tables/Arrays
A table is a contiguous sequence of memory locations
called elements, which all have the same name, and are
uniquely identified by that name and by their position in
the sequence.
CountyTax
55 10
1 2 3 4 5 6
MOVE 10 TO CountyTax(5)
55 2
ADD TaxPaid TO CountyTax(CountyNum)
ADD TaxPaid TO CountyTax(CountyNum + 2)
A CMMI Level 5 Company
www.zensar.com
Tables/Arrays
A table is a contiguous sequence of memory locations
called elements, which all have the same name, and are
uniquely identified by that name and by their position in
the sequence.
CountyTax
55 55 10
1 2 3 4 5 6
MOVE 10 TO CountyTax(5)
ADD TaxPaid TO CountyTax(CountyNum)
55 2
ADD TaxPaid TO CountyTax(CountyNum + 2)
A CMMI Level 5 Company
www.zensar.com
Tables/Arrays
A table is a contiguous sequence of memory locations
called elements, which all have the same name, and are
uniquely identified by that name and by their position in
the sequence.
CountyTax The position index is called a subscript.
55 55 10
1 2 3 4 5 6
MOVE 10 TO CountyTax(5)
ADD TaxPaid TO CountyTax(CountyNum)
Subscript
ADD TaxPaid TO CountyTax(CountyNum + 2)
A CMMI Level 5 Company
www.zensar.com
CountyTax
1 2 3 4 5 6
PROCEDURE DIVISION.
Begin.
OPEN INPUT TaxFile
READ TaxFile
AT END SET EndOfTaxFile TO TRUE
END-READ
PERFORM UNTIL EndOfTaxFile
ADD TaxPaid TO CountyTax(CountyNum)
READ TaxFile
AT END SET EndOfTaxFile TO TRUE
END-READ
END-PERFORM. Subscript
PERFORM VARYING Idx FROM 1 BY 1
UNTIL Idx GREATER THAN 26
DISPLAY "County ", CountyNum
" tax total is " CountyTax(Idx)
END-PERFORM
CLOSE TaxFile
STOP RUN.A CMMI Level 5 Company 9 Statements
www.zensar.com
TaxRecord.
PAYENum CountyName TaxPaid
A-89432 CLARE 7894.55
CountyTax
1 2 3 4 5 6
IF CountyName = "CARLOW"
ADD TaxPaid TO CountyTax(1)
END-IF
IF CountyName = "CAVAN"
ADD TaxPaid TO CountyTax(2)
END-IF
: : : : :
: : : : :
24Level
A CMMI TIMES
5 Company
www.zensar.com
TaxRecord.
PAYENum CountyName TaxPaid Idx
A-89432 CLARE 7894.55 1
County
CARLOW CAVAN CLARE CORK DONEGAL DUBLIN
1 2 3 4 5 6
CountyTax
500.50 125.75 1000.00 745.55 345.23 123.45
1 2 3 4 5 6
PERFORM VARYING Idx FROM 1 BY 1
UNTIL County(Idx) = CountyName
END-PERFORM
ADD TaxPaid TO CountyTax(Idx)
A CMMI Level 5 Company
www.zensar.com
TaxRecord.
PAYENum CountyName TaxPaid Idx
A-89432 CLARE 7894.55 2
County
CARLOW CAVAN CLARE CORK DONEGAL DUBLIN
1 2 3 4 5 6
CountyTax
500.50 125.75 1000.00 745.55 345.23 123.45
1 2 3 4 5 6
PERFORM VARYING Idx FROM 1 BY 1
UNTIL County(Idx) = CountyName
END-PERFORM
ADD TaxPaid TO CountyTax(Idx)
A CMMI Level 5 Company
www.zensar.com
TaxRecord.
PAYENum CountyName TaxPaid Idx
A-89432 CLARE 7894.55 3
County
CARLOW CAVAN CLARE CORK DONEGAL DUBLIN
1 2 3 4 5 6
CountyTax
500.50 125.75 1000.00 745.55 345.23 123.45
1 2 3 4 5 6
PERFORM VARYING Idx FROM 1 BY 1
UNTIL County(Idx) = CountyName
END-PERFORM
ADD TaxPaid TO CountyTax(Idx)
A CMMI Level 5 Company
www.zensar.com
TaxRecord.
PAYENum CountyName TaxPaid Idx
A-89432 CLARE 7894.55 3
County
CARLOW CAVAN CLARE CORK DONEGAL DUBLIN
1 2 3 4 5 6
CountyTax
500.50 125.75 8894.55 745.55 345.23 123.45
1 2 3 4 5 6
PERFORM VARYING Idx FROM 1 BY 1
UNTIL County(Idx) = CountyName
END-PERFORM
ADD TaxPaid TO CountyTax(Idx)
A CMMI Level 5 Company
www.zensar.com
Declaring Tables.
TaxTotals
CountyTax
000000
1 000000
2 000000
3 4 000000 5 000000
6 00000
01 TaxTotals.
02 CountyTax PIC 9(10)V99
OCCURS 26 TIMES.
or
02 CountyTax OCCURS 26 TIMES
PIC 9(10)V99.
e.g.
MOVE ZEROS TO TaxTotals.
MOVE 20Level
A CMMI TO5 CountyTax(5).
Company
www.zensar.com
Group Items as Elements.
TaxTotals
1 225 3 4 67 5 6
CountyTax PayerCount
000000 000000
CountyTaxDetails
01 TaxTotals.
02 CountyTaxDetails OCCURS 26 TIMES.
03 CountyTax PIC 9(10)V99.
03 PayerCount PIC 9(7).
e.g. MOVE 25 TO PayerCount(2).
MOVE 67 TO CountyTax(5).
MOVE ZEROS
A CMMI Level 5TO CountyTaxDetails(3).
Company
www.zensar.com
PERFORM..VARYING Syntax
THRU BEFORE
PERFORM 1stProc THROUGH EndProc WITH TEST
AFTER
Identifier 2
Identifer1
VARYING FROM IndexName 2
IndexName1 Literal
Identifier3
BY UNTIL Condition1
Literal
Identifier 5
Identifier4
AFTER FROM IndexName 4
IndexName3 Literal
Identifier6
BY UNTIL Condition2
Literal
StatementBlock END - PERFORM
A CMMI Level 5 Company
www.zensar.com
PERFORM VARYING Idx1 FROM 1 BY 1 UNTIL
Idx1 EQUAL TO 3
DISPLAY Idx1
END-PERFORM.
Idx1
1
Move 1 to Idx1
True
Idx1 = 3 Next Statement
False
Loop Body
Inc Idx1
A CMMI Level 5 Company
www.zensar.com
PERFORM VARYING Idx1 FROM 1 BY 1 UNTIL
Idx1 EQUAL TO 3
DISPLAY Idx1
END-PERFORM.
Idx1
1
Move 1 to Idx1
True
Idx1 = 3 Next Statement
False
Loop Body
Inc Idx1
A CMMI Level 5 Company
www.zensar.com
PERFORM VARYING Idx1 FROM 1 BY 1 UNTIL
Idx1 EQUAL TO 3
DISPLAY Idx1
END-PERFORM.
Idx1
1
Move 1 to Idx1
True
Idx1 = 3 Next Statement
False
Loop Body 1
Inc Idx1
A CMMI Level 5 Company
www.zensar.com
PERFORM VARYING Idx1 FROM 1 BY 1 UNTIL
Idx1 EQUAL TO 3
DISPLAY Idx1
END-PERFORM.
Idx1
2
Move 1 to Idx1
True
Idx1 = 3 Next Statement
False
Loop Body 1
Inc Idx1
A CMMI Level 5 Company
www.zensar.com
PERFORM VARYING Idx1 FROM 1 BY 1 UNTIL
Idx1 EQUAL TO 3
DISPLAY Idx1
END-PERFORM.
Idx1
2
Move 1 to Idx1
True
Idx1 = 3 Next Statement
False
Loop Body 1
Inc Idx1
A CMMI Level 5 Company
www.zensar.com
PERFORM VARYING Idx1 FROM 1 BY 1 UNTIL
Idx1 EQUAL TO 3
DISPLAY Idx1
END-PERFORM.
Idx1
2
Move 1 to Idx1
True
Idx1 = 3 Next Statement
False
Loop Body 1
2
Inc Idx1
A CMMI Level 5 Company
www.zensar.com
PERFORM VARYING Idx1 FROM 1 BY 1 UNTIL
Idx1 EQUAL TO 3
DISPLAY Idx1
END-PERFORM.
Idx1
3
Move 1 to Idx1
True
Idx1 = 3 Next Statement
False
Loop Body 1
2
Inc Idx1
A CMMI Level 5 Company
www.zensar.com
PERFORM VARYING Idx1 FROM 1 BY 1 UNTIL
Idx1 EQUAL TO 3
DISPLAY Idx1
END-PERFORM.
Idx1
3
Move 1 to Idx1
True
Idx1 = 3 Next
Next Statement
Statement
False
Loop Body 1
2
Inc Idx1 Exit value = 3
A CMMI Level 5 Company
www.zensar.com
PERFORM IterationCount VARYING Idx1 FROM 1 BY 2
UNTIL Idx1 EQUAL TO 5
AFTER Idx2 FROM 6 BY -1
UNTIL Idx2 LESS THAN 4
Move 1 to Idx1 T Idx1 Idx2
Move 6 to Idx2
1 1
6
Y
Idx1 = 5 Next Statement
2 1
5
N
Idx2 < 4
Y
3 1
N 4
IterationCount Move 6 to Idx2
Inc Idx1 4 3
Dec Idx2 6
A CMMI Level 5 Company
5 3
www.zensar.com
A CMMI Level 5 Company
www.zensar.com