COBOL program to MERGE two files


       IDENTIFICATION DIVISION.
       PROGRAM-ID." merge".
       AUTHOR."KUNAL"
       DATE-WRITTEN."29/01/12".
       DATE-COMPILED."29/01/12".
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER. M8.
       OBJECT-COMPUTER. M8.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       SELECT STUD1 ASSIGN TO DISK
       ORGANIZATION IS SEQUENTIAL
       ACCESS MODE IS SEQUENTIAL.
       SELECT STUD2 ASSIGN TO DISK
       ORGANIZATION IS SEQUENTIAL
       ACCESS MODE IS SEQUENTIAL.
       SELECT OUT ASSIGN TO DISK
       ORGANIZATION IS SEQUENTIAL
       ACCESS MODE IS SEQUENTIAL.
       SELECT WORK ASSIGN TO DISK
       ORGANIZATION IS SEQUENTIAL
       ACCESS MODE IS SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD STUD1
           LABEL RECORDS ARE STANDARD
           VALUE OF FILE-ID IS "STUD1.DAT".
        01 STUD1-REC.
           02 R-NO1 PIC 999.
           02 NAME1 PIC X(10).
           02 ATT1 PIC 9(2).
  02 PER1 PIC 999V99.
       FD STUD2
           LABEL RECORDS ARE STANDARD
  VALUE OF FILE-ID IS "STUD2.DAT".
        01 STUD2-REC.
  02 R-NO2 PIC 999.
  02 NAME2 PIC X(10).
  02 ATT2 PIC 99.
  02 PER2 PIC 999V99.
       FD OUT
           LABEL RECORDS ARE STANDARD
  VALUE OF FILE-ID IS "MERGE.DAT".
01 OUT-REC.
  02 R-NO3 PIC 999.
  02 NAME3 PIC X(10).
  02 ATT3 PIC 99.
  02 PER3 PIC 999V99.
       SD WORK.
         01 WORK-REC.
  02 R-NO4 PIC 999.
  02 NAME4 PIC X(10).
  02 ATT4 PIC 99.
  02 PER4 PIC 999V99.                     
       WORKING-STORAGE SECTION.
       77 N PIC X.
       PROCEDURE DIVISION.
       OPEN OUTPUT STUD1,STUD2.
        PARA-1.
           DISPLAY "---FOR FILE 1---".
           DISPLAY "Enter roll no".
  ACCEPT R-NO1.          
  DISPLAY "Enter name".
  ACCEPT NAME1.
  DISPLAY "Enter attendance:".
  ACCEPT ATT1.
  DISPLAY "Enter percentage:".
  ACCEPT PER1.
  WRITE STUD1-REC.
  DISPLAY "Do u want to continue....PRESS Y".
  ACCEPT N.
  IF N = "Y"
  GO TO PARA-1.
  
       PARA-2.
           DISPLAY "---FOR FILE 2---".
  DISPLAY "Enter roll no".
  ACCEPT R-NO2.
  DISPLAY "Enter name".
  ACCEPT NAME2.
  DISPLAY "Enter attendance".
  ACCEPT ATT2.
  DISPLAY "Enter percentage".
  ACCEPT PER2.
  WRITE STUD2-REC.
  DISPLAY "TO continue...press Y".
  ACCEPT N.   
  IF N = "Y"
  GO TO PARA-2.
  END-PARA.
  CLOSE STUD1,STUD2.
  MERGE-PARA.
     MERGE WORK ON ASCENDING KEY R-NO4 USING STUD1,STUD2 
     GIVING OUT.
  OPEN INPUT OUT.
  DISPLAY "----------------------------------"
  DISPLAY "ROLL NAME       ATTENDANCE PER(%)".
  DISPLAY "----------------------------------".
  READ-PARA.
      READ OUT AT END GO TO LAST-PARA CLOSE OUT.
      DISPLAY R-NO3 NAME3 ATT3 PER3.
      GO TO READ-PARA.
      LAST-PARA.
      STOP RUN.    
Previous
Next Post »