beautypg.com

Compaq COBOL AAQ2G1FTK User Manual

Page 143

background image

Handling Tables

4.3 Accessing Table Elements

Example 4–20 Using SEARCH and Varying an Index Other than the First Index

01

TAXABLE-INCOME PIC 9(6) VALUE 50000.

01

FED-TAX-DEDUCTION PIC 9(6).

PROCEDURE DIVISION.
BEGIN.

PERFORM MARRIED.
DISPLAY FED-TAX-DEDUCTION.
STOP RUN.

MARRIED.

IF TAXABLE-INCOME < 04800

MOVE ZEROS TO FED-TAX-DEDUCTION
GO TO END-FED-COMP.

SET IND-3 TO 1.
SEARCH MARRIED-TABLE VARYING IND-3 AT END

GO TO TABLE-3-ERROR

WHEN TAXABLE-INCOME = M-MIN-RANGE(IND-3)

MOVE M-TAX(IND-3) TO FED-TAX-DEDUCTION

WHEN TAXABLE-INCOME < M-MAX-RANGE(IND-3)

COMPUTE FED-TAX-DEDUCTION =

M-TAX(IND-3) + (TAXABLE-INCOME - M-TAX(IND-3)) *
M-PERCENT(IND-3).

.
.
.

Example 4–21 Using SEARCH and Varying an Index Data Item

01

TAXABLE-INCOME PIC 9(6) VALUE 50000.

01

FED-TAX-DEDUCTION PIC 9(6).

PROCEDURE DIVISION.
BEGIN.

PERFORM SINGLE.
DISPLAY FED-TAX-DEDUCTION.
STOP RUN.

SINGLE.

IF TAXABLE-INCOME < 02500

GO TO END-FED-COMP.

SET IND-2 TO 1.
SEARCH SINGLES-TABLE VARYING TEMP-IND AT END

GO TO TABLE-2-ERROR

WHEN TAXABLE-INCOME = S-MIN-RANGE(IND-2)

MOVE S-TAX(IND-2) TO FED-TAX-DEDUCTION

WHEN TAXABLE-INCOME < S-MAX-RANGE(IND-2)

MOVE S-TAX(IND-2) TO FED-TAX-DEDUCTION
SUBTRACT S-MIN-RANGE(IND-2) FROM TAXABLE-INCOME
MULTIPLY TAXABLE-INCOME BY S-PERCENT(IND-2) ROUNDED
ADD TAXABLE-INCOME TO FED-TAX-DEDUCTION.

.
.
.

Example 4–22 shows how to use SEARCH while varying an index not associated
with the target table.

Handling Tables 4–21