Microsoft KB Archive/43695

From BetaArchive Wiki

How to READ an ISAM File in Reverse Order Using COBOL 3.0

PSS ID Number: Q43695 Article last modified on 04-20-1993

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

The information in this article applies to:
- Microsoft COBOL for MS-DOS and OS/2, versions 3.0 and 3.0a

Summary: Microsoft COBOL Versions 3.0 and 3.0a offer the PREVIOUS clause with the READ statement. This clause allows the programmer to read an ISAM file in reverse order (backward).

More Information: The following code example shows how you can read an ISAM file in reverse order using READ…PREVIOUS in COBOL 3.0 or 3.0a. The program first creates the data file TESTIN.DAT and then READs from the same file.

Code Example IDENTIFICATION DIVISION. PROGRAM-ID. TESTus. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INPUT-FILE ASSIGN TO DISK ORGANIZATION IS INDEXED ACCESS IS DYNAMIC RECORD KEY IS PRIME-KEY. DATA DIVISION. FILE SECTION. FD INPUT-FILE LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS “TESTIN.DAT”. 01 INPUT-REC. 03 PRIME-KEY PIC xxx. WORKING-STORAGE SECTION. 77 FILE-STAT PIC XX. 77 stat-stuff. 03 in-numbers pic xxx value spaces. 03 in-letters pic xxx value spaces. 03 junk pic x value space. SCREEN SECTION. 01 get-screen. 05 blank screen. 05 line 01 column 01 value “enter a three digit number”. 05 line 02 column 02 pic 9(3) to in-numbers . 01 display-screen. 05 blank screen. 05 line 01 column 01 pic 9(3) from prime-key. 01 dummy-screen. 05 line 05 column 05 pic x to junk. PROCEDURE DIVISION. 000-MAIN. OPEN output INPUT-FILE. display file-stat. perform get-info 7 times. CLOSE INPUT-FILE. open input input-file. move high-values to prime-key. START INPUT-FILE key IS < = prime-key. perform read-file 7 times. close input-file. STOP RUN. get-info. display get-screen. accept get-screen. move in-numbers to prime-key. write input-rec. read-file. READ INPUT-FILE previous RECORD. display display-screen. accept dummy-screen.

Additional reference words: 3.00 3.00a Copyright Microsoft Corporation 1993.