beautypg.com

Compaq COBOL AAQ2G1FTK User Manual

Page 144

background image

Handling Tables
4.3 Accessing Table Elements

Example 4–22 Using SEARCH and Varying an Index not Associated with the

Target Table

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 IND-0 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–23 shows how to perform a serial search without using the VARYING
phrase.

Example 4–23 Doing a Serial Search Without Using the VARYING Phrase

01

NR-DEPENDENTS

PIC 9(2)

VALUE 3.

01

GROSS-WAGE

PIC 9(6)

VALUE 50000.

01

TAXABLE-INCOME

PIC 9(6)

VALUE 50000.

01

FED-TAX-DEDUCTION PIC9(6).

01

MARITAL-STATUS

PIC X

VALUE "M".

PROCEDURE DIVISION.
BEGIN.

PERFORM FED-DEDUCT-COMPUTATION.
DISPLAY TAXABLE-INCOME.
STOP RUN.

FED-DEDUCT-COMPUTATION.

SET IND-1 TO 1.
SEARCH FED-ALLOWANCES AT END

GO TO TABLE-1-ERROR

WHEN ALLOWANCE-NUMBER(IND-1) = NR-DEPENDENTS

SUBTRACT ALLOWANCE(IND-1) FROM GROSS-WAGE

GIVING TAXABLE-INCOME ROUNDED.

IF MARITAL-STATUS = "M"

GO TO MARRIED.

MARRIED.

.
.
.

4–22 Handling Tables