menu driven relative file in COBOL


       IDENTIFICATION DIVISION.
       PROGRAM-ID."MENU DRIVEN PROGRAM".
       AUTHOR."KUNAL"
       DATE-WRITTEN."27/02/12".
       DATE-COMPILED."27/02/12".
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER. M8.
       OBJECT-COMPUTER. M8.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       SELECT EMPREL ASSIGN TO DISK
       ORGANIZATION IS RELATIVE
       ACCESS MODE IS SEQUENTIAL
       RELATIVE KEY IS KUNAL.
       DATA DIVISION.
       FILE SECTION.
       FD EMPREL
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "EMPREL.DAT".
       01 EMPREL-REC.
           02 ENAME  PIC X(20).
  02 EID PIC 9(3).
           02 EAGE PIC 9(2).
  02 EGEN PIC X.
       WORKING-STORAGE SECTION.
       77 CH1 PIC 9.
        77 REC PIC 99.
       77 KUNAL PIC 99.
       77 NAME1 PIC X(20).
       77 ROW1 PIC 99.
       
       77 REC1 PIC 99.
       77 ID1 PIC 9(3).
       77 AGE1 PIC 9(2).
       77 GEN1 PIC X.
       SCREEN SECTION.
         01 CLEAR-SCREEN.
  02 BLANK SCREEN.
          
       PROCEDURE DIVISION.
           MENU-PARA.
           DISPLAY " ".
  DISPLAY "PRESS..1.INSERT 2.UPDATE 3.DISPLAY 4.DELETE 5.EXIT".
  ACCEPT CH1.
  IF CH1 = 1 GO TO INSERT-PARA ELSE
  IF CH1 = 2 GO TO EDIT-PARA ELSE
  IF CH1 = 3 GO TO DISP-PARA ELSE
  IF CH1 = 4 GO TO DEL-PARA ELSE
           IF CH1 = 5 GO TO EXIT-PARA.
  END-PARA.
  INSERT-PARA.
           OPEN EXTEND EMPREL.
            DISPLAY "ENTER RECORD NO".
            ACCEPT KUNAL.
           DISPLAY "Enter ID of emp".
  ACCEPT EID.
  DISPLAY "Enter NAME of emp:".
  ACCEPT ENAME.
  DISPLAY "Enter AGE of emp:".
  ACCEPT EAGE.
  DISPLAY "Enter GENDER of emp:".
  ACCEPT EGEN.
  
  WRITE EMPREL-REC.
  CLOSE EMPREL.
  GO TO MENU-PARA.
  EDIT-PARA.
   DISPLAY "Enter RECORD NO.for editing".
   ACCEPT REC.
   OPEN I-O EMPREL.
   PARA-3.
    READ EMPREL NEXT RECORD AT END GO TO LAST-PARA.
    IF REC = KUNAL
    DISPLAY "Enter id,name,age & gender of emp"
    ACCEPT ID1
    ACCEPT NAME1
    ACCEPT AGE1
    ACCEPT GEN1
    MOVE ID1 TO EID
    MOVE NAME1 TO ENAME
    MOVE AGE1 TO EAGE
    
    REWRITE EMPREL-REC ELSE GO TO PARA-3.
    LAST-PARA.
    CLOSE EMPREL.
    GO TO MENU-PARA.
  DISP-PARA.
   DISPLAY CLEAR-SCREEN.
   OPEN INPUT EMPREL.
    DISPLAY(1,1) "---------------------------------------------------------".
    DISPLAY(2,2) "ID".
    DISPLAY(2,6) "NAME".
    DISPLAY(2,28) "AGE".
    DISPLAY(2,32) "GENDER".
    DISPLAY(3,1) "---------------------------------------------------------".
    MOVE 4 TO ROW1.
   READ-PARA.
    READ EMPREL NEXT RECORD AT END GO TO L-PARA.
    DISPLAY(ROW1,2) EID.
    DISPLAY(ROW1,6) ENAME.
    DISPLAY(ROW1,28) EAGE.
    DISPLAY(ROW1,32) EGEN.
    ADD 1 TO ROW1.
    GO TO READ-PARA.
    L-PARA.
    CLOSE EMPREL.
    GO TO MENU-PARA.
           DEL-PARA.
           DISPLAY "ENTER record no for deleting".
           ACCEPT REC1.
           OPEN I-O EMPREL.
  READ EMPREL NEXT RECORD AT END GO TO R-PARA.      
           IF REC1 = KUNAL 
  DELETE EMPREL.
  R-PARA.
           CLOSE EMPREL.
   GO TO MENU-PARA.
   
    EXIT-PARA.
    STOP RUN.  
Previous
Next Post »