Examples (REREAD command)
Using REREAD to Process Different Record Formats
INPUT PROGRAM.
DATA LIST /PARTNO 1-2 KIND 10-14 (A).
DO IF (KIND EQ 'FORD').
REREAD.
DATA LIST /PRICE 3-6 (DOLLAR,2) QUANTITY 7-9.
END CASE.
ELSE IF (KIND EQ 'CHEVY').
REREAD.
DATA LIST /PRICE 15-18 (DOLLAR,2) QUANTITY 19-21.
END CASE.
END IF.
END INPUT PROGRAM.
BEGIN DATA
111295100FORD CHAPMAN AUTO SALES
121199005VW MIDWEST VOLKSWAGEN SALES
11 395025FORD BETTER USED CARS
11 CHEVY 195005 HUFFMAN SALES & SERVICE
11 VW 595020 MIDWEST VOLKSWAGEN SALES
11 CHEVY 295015 SAM'S AUTO REPAIR
11 CHEVY 210 20 LONGFELLOW CHEVROLET
9555032 VW HYDE PARK IMPORTS
END DATA.
LIST.
- Data are extracted from an inventory of automobile parts. The automobile part number always appears in columns 1 and 2, and the automobile type always appears in columns 10 through 14. The location of other information such as price and quantity depends on both the part number and the type of automobile.
- The first
DATA LIST
extracts the part number and type of automobile. - Depending on the information from the first
DATA LIST
, the records are reread using one of twoDATA LIST
commands, pulling the price and quantity from different places. - The two
END CASE
commands limit the active dataset to only those cases with part 11 and automobile type Ford or Chevrolet. Without theEND CASE
commands, cases would be created for other part numbers and automobile types, with missing values for price, quantity, and buyer.
The output from the LIST
command is as follows:
PARTNO KIND PRICE QUANTITY
11 FORD $12.95 100
11 FORD $3.95 25
11 CHEVY $1.95 5
11 CHEVY $2.95 15
11 CHEVY $2.10 20
Multiple REREAD Commands for the Same Record
INPUT PROGRAM.
DATA LIST NOTABLE/ CDIMAGE 1-20(A).
REREAD COLUMN = 6. /* A, C, and E are in column 6
REREAD COLUMN = 11. /* B, D, and F are in column 11
DATA LIST NOTABLE/ INFO 1(A).
END INPUT PROGRAM.
BEGIN DATA
1 A B
2 C D
3 E F
END DATA.
LIST.
- Multiple
REREAD
commands are used without an interveningDATA LIST
. Only the last one is used. Thus, the starting column comes from the lastREREAD
specified and the pointer is reset to column 11.
The output from the LIST
command is as follows:
CDIMAGE INFO
1 A B B
2 C D D
3 E F F