Here is what I am trying to do and the code I have so far that is not accomplishing what I need. Fetching code and desc from DB2 table. Data will change periodically (add/delete). Loading a table with fetched data. Need to take the loaded data into 5 legend print lines. I need to code it so if a codes/desc are added or deleted, I will not have to keep changing the program. Presently I am getting the data into the print lines using the code listed at the end because I know the number of entries right now.
01 WS-VVD-TABLES.
05 WS-VVD-ENTRIES OCCURS 1 TO 30 TIMES
DEPENDING ON WS-VVD-SUB.
10 WS-VVD-CODE PIC X(03).
10 WS-VVD-DESC PIC X(30).
1220-FETCH-VVDCSR.
EXEC SQL
FETCH VVD_CSR
INTO :SQL-VVD-CODE
,:SQL-VVD-DESC
END-EXEC.
EVALUATE SQLCODE
WHEN +0
MOVE WS-VVD-LIC TO SQL-VVD-TYPE
ADD +1 TO WS-VVD-ROWS
WHEN +100
ADD +1 TO WS-VVD-SUB
MOVE '999' TO WS-VVD-CODE (WS-VVD-SUB)
MOVE 'Y' TO WS-VVD-DONE-SW
1230-LOAD-VVD-TBL.
ADD +1 TO WS-VVD-SUB
IF WS-VVD-SUB <= WS-VVD-TAB-SIZE
MOVE SQL-VVD-CODE TO WS-VVD-CODE (WS-VVD-SUB)
MOVE SQL-VVD-DESC TO WS-VVD-DESC (WS-VVD-SUB)
ELSE
CONTINUE
END-IF
Loaded table:
03 WS-VVD-CODE
SUB(1) 'CIG'
SUB(2) 'CTL'
SUB(3) 'EGG'
SUB(4) 'FEN'
SUB(5) 'NEW'
SUB(6) 'PAC'
SUB(7) 'PDL'
SUB(8) 'PTL'
SUB(9) 'SBL'
SUB(10) 'STI'
SUB(11) 'STP'
SUB(12) 'TOB'
SUB(13) 'TST'
SUB(14) '999'
03 WS-VVD-DESC
SUB(1) 'Cigarettes '
SUB(2) 'Cigarette & Tobacco License # '
SUB(3) 'Egg License # '
SUB(4) 'FederalEmployerIdentification#'
SUB(5) 'New License # '
SUB(6) 'Perishable Ag Commod Act # '
SUB(7) 'Plant Dealer License # '
SUB(8) 'Privilege Tax Lic # '
SUB(9) 'State Business License # '
SUB(10) 'State Tax Id # '
SUB(11) 'Sales Tax Permit # '
SUB(12) 'Tobacco License # '
SUB(13) 'Test License # '
I need to get the above data into the 5 print lines below. Print lines 3-6.
05 LEGEND-LINE2.
10 LEGEND-CODE1 PIC X(3).
10 FILLER PIC X(3)
VALUE ' = '.
10 LEGEND-DESC1 PIC X(30).
10 FILLER PIC X(3)
VALUE ' '.
10 LEGEND-CODE2 PIC X(3).
10 FILLER PIC X(3)
VALUE ' = '.
10 LEGEND-DESC2 PIC X(30).
10 FILLER PIC X(3)
VALUE ' '.
10 LEGEND-CODE3 PIC X(3).
10 FILLER PIC X(3)
VALUE ' = '.
10 LEGEND-DESC3 PIC X(30).
10 FILLER PIC X(3)
VALUE ' '.
This is how I am getting the data to the print lines.
PERFORM TEST BEFORE VARYING WS-VVD-SUB FROM 1 BY 1
UNTIL WS-VVD-CODE (WS-VVD-SUB) = '999'
MOVE WS-VVD-CODE(WS-VVD-SUB) TO LEGEND-CODE1
MOVE WS-VVD-DESC(WS-VVD-SUB) TO LEGEND-DESC1
ADD +1 TO WS-VVD-SUB
MOVE WS-VVD-CODE(WS-VVD-SUB) TO LEGEND-CODE2
MOVE WS-VVD-DESC(WS-VVD-SUB) TO LEGEND-DESC2
ADD +1 TO WS-VVD-SUB
MOVE WS-VVD-CODE(WS-VVD-SUB) TO LEGEND-CODE3
MOVE WS-VVD-DESC(WS-VVD-SUB) TO LEGEND-DESC3
ADD +1 TO WS-VVD-SUB
MOVE WS-VVD-CODE(WS-VVD-SUB) TO LEGEND-CODE4
MOVE WS-VVD-DESC(WS-VVD-SUB) TO LEGEND-DESC4
ADD +1 TO WS-VVD-SUB
MOVE WS-VVD-CODE(WS-VVD-SUB) TO LEGEND-CODE5
MOVE WS-VVD-DESC(WS-VVD-SUB) TO LEGEND-DESC5
ADD +1 TO WS-VVD-SUB
MOVE WS-VVD-CODE(WS-VVD-SUB) TO LEGEND-CODE6