Retrocomputing

Companion programs to list and load data for STOCK

The following programs build on the CIS COBOL examples STOCK1 and STOCK2 programs.

List feedstock file

The FEEDSTCK.TXT file is a line sequential file containing numbers for early Intel products. The program is an example of how to read a file sequentially and display each record on the screen.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. LIST-FEED.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STOCK-FILE ASSIGN "FEEDSTCK.TXT"
           ORGANIZATION LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  STOCK-FILE; RECORD CONTAINS 32 CHARACTERS.
       01  STOCK-ITEM.
           02  STOCK-CODE              PIC X(4).
           02  PRODUCT-DESC            PIC X(24).
           02  UNIT-SIZE               PIC 9(4).
       WORKING-STORAGE SECTION.
       01  DISP-ITEM.
           02  DI-CODE                 PIC X(4).
           02  FILLER                  PIC X VALUE " ".
           02  DI-DESC                 PIC X(24).
           02  FILLER                  PIC X VALUE " ".
           02  DI-SIZE                 PIC 9(4).
       77  END-OF-FILE                 PIC 9.
       PROCEDURE DIVISION.
           OPEN INPUT STOCK-FILE.
           DISPLAY "CODE DESCRIPTION              SIZE".
           DISPLAY "---- ------------------------ ----".
           MOVE ZERO TO END-OF-FILE.
           PERFORM READ-LINE THRU READ-LINE-EXIT
               UNTIL END-OF-FILE = 1.
           CLOSE STOCK-FILE.
           DISPLAY "---- ------------------------ ----".
           STOP RUN.
       READ-LINE.
           READ STOCK-FILE AT END
                 MOVE 1 TO END-OF-FILE
                 GO TO READ-LINE-EXIT.
           MOVE STOCK-CODE TO DI-CODE.
           MOVE PRODUCT-DESC TO DI-DESC.
           MOVE UNIT-SIZE TO DI-SIZE.
           DISPLAY DISP-ITEM.
       READ-LINE-EXIT.
           EXIT.

FEEDSTCK.TXT

40044-bit Microprocessor    0001
40404-bit Microprocessor    0001
80088-bit Microprocessor    0001
80808-bit Microprocessor    0010
80858-bit Microprocessor 5V 0010
4001256-byte ROM            0012
400240-byte RAM             0001
400310-bit Shift register   0020
40088-bit address latch     0010
4009I/O access converter    0010
4101256 x 4-bit Static RAM  0010
4201Clock Generator         0010
8224Clock generator         0010
4207G/P 8-bit Output port   0010
4209G/P 8-bit Input port    0010
4211G/P 8-bit I/O port      0010
4269Pgmable keyboard/display0010
4289Memory interface        0010
4289Std Memory Interface    0010
43081K x 8-bit ROM + I/O    0010
32164-bit parallel bus drivr0010
43162K x 8-bit ROM          0010
4702256 x 8-bit EPROM       0010
8228System controller       0010
8238System controller       0010
8251Communication controller0010
8253Interval timer          0020
8255Peripheral interface    0010
8257DMA controller          0080
4265General-purpose I/O     0010

Load feedstock file into STOCK.IT

The following program reads the FEEDSTCK.TXT file and writes each record into the STOCK.IT indexed file. There is a duplicate code in the feed stock, which will cause a load error for the second record.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. LOAD-FEED.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.

           SELECT FEED-FILE ASSIGN "FEEDSTCK.TXT"
           ORGANIZATION LINE SEQUENTIAL.

           SELECT STOCK-FILE ASSIGN "STOCK.IT"
           ORGANIZATION INDEXED
           ACCESS DYNAMIC
           RECORD KEY STOCK-CODE.

       DATA DIVISION.
       FILE SECTION.
       FD  FEED-FILE.
       01  FEED-ITEM.
           02  FEED-CODE               PIC X(4).
           02  FEED-DESC               PIC X(24).
           02  FEED-SIZE               PIC 9(4).
       FD  STOCK-FILE.
       01  STOCK-ITEM.
           02  STOCK-CODE              PIC X(4).
           02  PRODUCT-DESC            PIC X(24).
           02  UNIT-SIZE               PIC 9(4).
       WORKING-STORAGE SECTION.
       77  END-OF-FILE                 PIC 9.

       PROCEDURE DIVISION.
           OPEN INPUT FEED-FILE.
           OPEN OUTPUT STOCK-FILE.
           MOVE ZERO TO END-OF-FILE.
           PERFORM READ-LINE THRU READ-LINE-EXIT
               UNTIL END-OF-FILE = 1.
           CLOSE FEED-FILE, STOCK-FILE.
           STOP RUN.
       READ-LINE.
           READ FEED-FILE AT END
                 MOVE 1 TO END-OF-FILE
                 GO TO READ-LINE-EXIT.
           MOVE FEED-ITEM TO STOCK-ITEM.
           DISPLAY "LOADING: " STOCK-CODE.
           WRITE STOCK-ITEM INVALID KEY
                DISPLAY " -- FAILED".
       READ-LINE-EXIT.
           EXIT.

List stock indexed file

The following program lists the content of STOCK.IT sequentially. Note that the records are now sorted on stock code.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. LIST-STOCK.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STOCK-FILE ASSIGN "STOCK.IT"
           ORGANIZATION INDEXED
           ACCESS DYNAMIC
           RECORD KEY STOCK-CODE.
       DATA DIVISION.
       FILE SECTION.
       FD  STOCK-FILE.
       01  STOCK-ITEM.
           02  STOCK-CODE              PIC X(4).
           02  PRODUCT-DESC            PIC X(24).
           02  UNIT-SIZE               PIC 9(4).
       WORKING-STORAGE SECTION.
       01  DISP-ITEM.
           02  DI-CODE                 PIC X(4).
           02  FILLER                  PIC X VALUE " ".
           02  DI-DESC                 PIC X(24).
           02  FILLER                  PIC X VALUE " ".
           02  DI-SIZE                 PIC 9(4).
       77  END-OF-FILE                 PIC 9.
       PROCEDURE DIVISION.
           OPEN INPUT STOCK-FILE.
           DISPLAY "CODE DESCRIPTION              SIZE".
           DISPLAY "---- ------------------------ ----".
           MOVE ZERO TO END-OF-FILE.
           PERFORM READ-RECORD THRU READ-RECORD-EXIT
               UNTIL END-OF-FILE = 1.
           CLOSE STOCK-FILE.
           DISPLAY "---- ------------------------ ----".
           STOP RUN.
       READ-RECORD.
           READ STOCK-FILE NEXT RECORD AT END
                 MOVE 1 TO END-OF-FILE
                 GO TO READ-RECORD-EXIT.
           MOVE STOCK-CODE TO DI-CODE.
           MOVE PRODUCT-DESC TO DI-DESC.
           MOVE UNIT-SIZE TO DI-SIZE.
           DISPLAY DISP-ITEM.
       READ-RECORD-EXIT.
           EXIT.

You can now use the STOCK2 program to create a transaction file.