Skip to content

Instantly share code, notes, and snippets.

@sandeep-sparrow
Created September 23, 2020 17:14
Show Gist options
  • Save sandeep-sparrow/8439736fd401724de25aef7a5944d157 to your computer and use it in GitHub Desktop.
Save sandeep-sparrow/8439736fd401724de25aef7a5944d157 to your computer and use it in GitHub Desktop.
COBOL program loads data in 1-D table from External File.
IDENTIFICATION DIVISION.
PROGRAM-ID. CBL1DTBL.
AUTHOR. SANDEEP R PRAJAPATI.
******************************************************************
*DESCRIPTION: COBOL PROGRAM LOADS DATA INTO EMPLOYEE TABLE *
* USING EXTERNAL FILE *
*DATE : 23-09-2020 *
******************************************************************
*
ENVIRONMENT DIVISION.
*
INPUT-OUTPUT SECTION.
*
FILE-CONTROL.
*
SELECT IN-FILE ASSIGN TO EMPROJ.
*
DATA DIVISION.
*
FILE SECTION.
*
FD IN-FILE RECORD CONTAINS 80 CHARACTERS
RECORDING MODE IS F.
*
01 EMP-PROJECT-TABLE-I.
05 EMP-PROJECT-I PIC X(05).
05 EMP-NAME-I PIC X(25).
05 FILLER PIC X(50).
*
WORKING-STORAGE SECTION.
*
77 PROJECT-SUB PIC S9(04) COMP.
77 TABLE-MAX PIC S9(04) COMP VALUE 20.
77 SW-END-OF-FILE PIC X(01) VALUE SPACE.
88 END-OF-FILE VALUE 'Y'.
*
01 EMP-PROJECT-TABLE. *> DEFINE THE TABLE
05 EMP-PROJECT-ITEM OCCURS 20 TIMES.
10 EMP-PROJECT PIC X(05).
10 EMP-NAME PIC X(25).
*
PROCEDURE DIVISION.
*
OPEN INPUT IN-FILE.
*
READ IN-FILE
AT END MOVE 'Y' TO SW-END-OF-FILE
END-READ.
*
PERFORM VARYING PROJECT-SUB FROM 1 BY 1
UNTIL PROJECT-SUB = TABLE-MAX
OR END-OF-FILE
MOVE EMP-PROJECT-I TO EMP-PROJECT(PROJECT-SUB)
MOVE EMP-NAME-I TO EMP-NAME(PROJECT-SUB)
READ IN-FILE
AT END MOVE 'Y' TO SW-END-OF-FILE
END-READ
END-PERFORM.
*
DISPLAY EMP-PROJECT-ITEM(1).
DISPLAY EMP-PROJECT-ITEM(5).
DISPLAY EMP-PROJECT-ITEM(10).
DISPLAY EMP-PROJECT-ITEM(15).
DISPLAY EMP-PROJECT-ITEM(20).
*
DISPLAY "----------------------".
DISPLAY EMP-PROJECT-TABLE.
*
GOBACK.
CUBE1SANDEEP PRAJAPATI
CUBE2MUKESH KHANNA
CUBE3SALMAN KHAN
CUBE4SACHIN TENDULKAR
CUBE5RAMESH PRAJAPATI
CUBE6VIKAS SINGH
CUBE7SHAH RUKH KHAN
CUBE8AKSHAY KUMAR
CUBE9VIVEK OBERIA
TEL10FREE FIRE
TEL11NARENDRA MODI
TEL12HEMA MALINI
TEL13RITA PRAJAPATI
TEL14AJAY DEVGUN
TEL15CALL OF DUTY
TEL16JATIN RANAWAT
TEL17MURLI PRASAD
TEL18UDAY PRASAD
TEL19JACK SPARROW
TEL20JAY VEER MAHARAJ
CUBE1SANDEEP PRAJAPATI
CUBE5RAMESH PRAJAPATI
TEL10FREE FIRE
TEL15CALL OF DUTY
----------------------
CUBE1SANDEEP PRAJAPATI CUBE2MUKESH KHANNA CUBE3SALMAN KHAN CUBE4SACHIN TENDULKAR
CUBE5RAMESH PRAJAPATI CUBE6VIKAS SINGH CUBE7SHAH RUKH KHAN CUBE8AKSHAY KUMAR
CUBE9VIVEK OBERIA TEL10FREE FIRE TEL11NARENDRA MODI TEL12HEMA MALINI
TEL13RITA PRAJAPATI TEL14AJAY DEVGUN TEL15CALL OF DUTY TEL16JATIN RANAWAT
TEL17MURLI PRASAD TEL18UDAY PRASAD TEL19JACK SPARROW
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment