Skip to content

Instantly share code, notes, and snippets.

@sandeep-sparrow
Last active September 30, 2020 07:00
Show Gist options
  • Save sandeep-sparrow/4a9ca0e1b16a867c64a8085b00a58982 to your computer and use it in GitHub Desktop.
Save sandeep-sparrow/4a9ca0e1b16a867c64a8085b00a58982 to your computer and use it in GitHub Desktop.
passing input data in one level COBOL table with the help of subscripts
******************************************************************
* Author: SANDEEP
* Date: 10-06-2020
* Purpose: TO UNDERSTAND ONE LEVEL TABLE AND SUBSCRIPTS
* Tectonics: COBC
******************************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. CTABLE.
*
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT P-TABLE ASSIGN TO PTABLE
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS WS-FILEI-STATUS.
*
DATA DIVISION.
FILE SECTION.
*
FD P-TABLE RECORDING MODE F.
01 PRICE-TABLE-RECORD.
05 PT-ITEM-NUMBER PIC 9(03).
05 FILLER PIC X(01).
05 PT-ITEM-PRICE PIC S99V99.
05 FILLER PIC X(72).
*
WORKING-STORAGE SECTION.
*
01 SWITCHES.
05 PTABLE-EOF-SWITCH PIC X VALUE 'N'.
88 PTABLE-EOF VALUE 'Y'.
*
01 WS-FILEI-STATUS PIC X(02) VALUE SPACES.
*
01 SUBSCRIPTS BINARY.
05 PRICE-TABLE-SUB PIC S99.
05 I PIC S99.
*
01 PRICE-TABLE VALUE ZERO.
05 PRICE-GROUP OCCURS 16 TIMES.
10 ITEM-NUMBER PIC 9(03).
10 ITEM-PRICE PIC S99V99.
*
01 ITEM-PRICE-E PIC ZZ9.99.
*
PROCEDURE DIVISION.
*
DISPLAY "HELLO WORLD!".
DISPLAY "COBOL CODE TO LOAD DATA READ FROM FILE IN".
DISPLAY "ONE LEVEL TABLE WITH THE USE OF SUBSCRIPTS".
*
INITIALIZE PRICE-TABLE.
*
PERFORM 000-OPEN-FILE.
*
PERFORM 100-READ-PRICE-TABLE.
DISPLAY 'READ STATUS:' WS-FILEI-STATUS.
*
PERFORM 200-LOAD-PRICE-TABLE
VARYING PRICE-TABLE-SUB FROM 1 BY 1
UNTIL PTABLE-EOF OR
PRICE-TABLE-SUB > 16.
*
DISPLAY 'TABLE LOAD COMPLETED!'.
*
PERFORM 900-CLOSE-FILE.
*
DISPLAY 'CLOSE COMPLETED'.
*
DISPLAY '---------'.
DISPLAY 'NO PRICE'.
DISPLAY '---------'.
*
PERFORM 300-DISPLAY-TABLE
VARYING I FROM 1 BY 1 UNTIL I > 16.
*
DISPLAY '---------'.
*
STOP RUN.
*
000-OPEN-FILE.
OPEN INPUT P-TABLE.
DISPLAY 'OPEN STATUS:' WS-FILEI-STATUS.
*
100-READ-PRICE-TABLE.
READ P-TABLE AT END SET PTABLE-EOF TO TRUE.
*
200-LOAD-PRICE-TABLE.
MOVE PT-ITEM-NUMBER TO ITEM-NUMBER(PRICE-TABLE-SUB).
MOVE PT-ITEM-PRICE TO ITEM-PRICE(PRICE-TABLE-SUB).
PERFORM 100-READ-PRICE-TABLE.
*
900-CLOSE-FILE.
CLOSE P-TABLE.
DISPLAY 'CLOSE STATUS:' WS-FILEI-STATUS.
*
300-DISPLAY-TABLE.
MOVE ITEM-PRICE(I) TO ITEM-PRICE-E
DISPLAY ITEM-NUMBER(I), ITEM-PRICE-E.
*
END PROGRAM CTABLE.
101 1250 00000100
107 5000 00000200
111 0770 00000300
158 0555 00000400
161 6250 00000500
192 2500 00000600
201 0040 00000700
213 0666 00000800
277 0111 00000900
297 0777 00001000
305 0010 00001100
341 1500 00001200
342 5750 00001300
343 6500 00001400
347 2250 00001500
351 0035 00001600
HELLO WORLD!
COBOL CODE TO LOAD DATA READ FROM FILE IN
ONE LEVEL TABLE WITH THE USE OF SUBSCRIPTS
OPEN STATUS:00
READ STATUS:00
TABLE LOAD COMPLETED!
CLOSE STATUS:00
CLOSE COMPLETED
---------
NO PRICE
---------
101 12.50
107 50.00
111 7.70
158 5.55
161 62.50
192 25.00
201 0.40
213 6.66
277 1.11
297 7.77
305 0.10
341 15.00
342 57.50
343 65.00
347 22.50
351 0.35
---------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment