Home   Easy-Code    Forum  Updater 
Twitter Facebook



Program to find the average length of a line in a given text file)np program to merge two student files using cobol

Critics Rating:

Users Rating:

*(PROGRAM TO FIND THE AVERAGE LENGTH OF A LINE IN A GIVEN TEXT FILE)NP.

*       PROGRAM TO MERGE TWO STUDENT FILES.

***********************************************************************

   IDENTIFICATION DIVISION.

   PROGRAM-ID.

   ENVIRONMENT DIVISION.

   INPUT-OUTPUT SECTION.

   FILE-CONTROL.

      SELECT DATAFILE1 ASSIGN TO DISK

      ORGANIZATION IS LINE SEQUENTIAL.



      SELECT DATAFILE2 ASSIGN TO DISK

      ORGANIZATION IS LINE SEQUENTIAL.



      SELECT MERGEFILE ASSIGN TO DISK

      ORGANIZATION IS LINE SEQUENTIAL.

      

      SELECT WORKFILE ASSIGN TO DISK.

   DATA DIVISION.

   FILE SECTION.

   FD DATAFILE1

      LABEL RECORDS ARE STANDARD

      VALUE OF FILE-ID IS "DATA1.DAT".

   01 STUDENT1.

    02 F PIC X(4).

    02 SNO PIC X(3).

    02 F PIC X(3).

    02 SNAME PIC X(10).

    02 F PIC X(5).

    02 MF PIC Z(3).

    02 F PIC X(7).

    02 MS PIC Z(3).

    02 F PIC X(7).

    02 MT PIC Z(3).

    02 F PIC X(6).

    02 T PIC 9(4).

   FD DATAFILE2

      LABEL RECORDS ARE STANDARD

      VALUE OF FILE-ID IS "DATA2.DAT".

   01 STUDENT2.

    02 F PIC X(4).

    02 SSNO PIC X(3).

    02 F PIC X(3).

    02 SSNAME PIC X(10).

    02 F PIC X(5).

    02 SMF PIC Z(3).

    02 F PIC X(7).

    02 SMS PIC Z(3).

    02 F PIC X(7).

    02 SMT PIC Z(3).

    02 F PIC X(6).

    02 ST PIC 9(4).

   FD MERGEFILE

      LABEL RECORDS ARE STANDARD

      VALUE OF FILE-ID IS "MERGE.DAT".

   01 STU.

    02 F PIC X(4).

    02 PSNO PIC X(3).

    02 F PIC X(3).

    02 PSNAME PIC X(10).

    02 F PIC X(5).

    02 PMF PIC Z(3).

    02 F PIC X(7).

    02 PMS PIC Z(3).

    02 F PIC X(7).

    02 PMT PIC Z(3).

    02 F PIC X(6).

    02 PT PIC 9(4).

   SD WORKFILE.

   01 WORK.

    02 F PIC X(4).

    02 WSNO PIC X(3).

    02 F PIC X(3).

    02 WSNAME PIC X(10).

    02 F PIC X(5).

    02 WMF PIC Z(3).

    02 F PIC X(7).

    02 WMS PIC Z(3).

    02 F PIC X(7).

    02 WMT PIC Z(3).

    02 F PIC X(6).

    02 WT PIC 9(4).

   WORKING-STORAGE SECTION.

   77 EOF PIC A VALUE "N".

   PROCEDURE DIVISION.

   MAIN-PARA.

      DISPLAY "FIRST FILE :".

      DISPLAY "------------"

      OPEN INPUT DATAFILE1 DATAFILE2.

      PERFORM X-PARA UNTIL EOF = "Y".

      MOVE "N" TO EOF.

      DISPLAY " ".

      DISPLAY "SECOND FILE :".

      DISPLAY "-------------"

      PERFORM Y-PARA UNTIL EOF = "Y".

      CLOSE DATAFILE1 DATAFILE2.

      MERGE WORKFILE ON DESCENDING KEY WT

      USING DATAFILE1 DATAFILE2 GIVING MERGEFILE.

      ACCEPT EOF.

      OPEN INPUT MERGEFILE.

      MOVE "N" TO EOF.

      DISPLAY (1 , 1) ERASE.

      DISPLAY "MERGED FILE :".

      DISPLAY "-------------".

      PERFORM Z-PARA UNTIL EOF = "Y".

      CLOSE MERGEFILE.

      STOP RUN.

   X-PARA.

      READ DATAFILE1 RECORD AT END MOVE "Y" TO EOF.

      IF (EOF NOT = "Y")

       DISPLAY STUDENT1.

   Y-PARA.

      READ DATAFILE2 RECORD AT END MOVE "Y" TO EOF.

      IF (EOF NOT = "Y")

       DISPLAY STUDENT2.

   Z-PARA.

      READ MERGEFILE RECORD AT END MOVE "Y" TO EOF.

      IF (EOF NOT = "Y")

       DISPLAY STU.

Courtesy, Source, References & Regards: Kishore AVGK

While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright@2009-2011 by KuGuNi.com. All Rights Reserved.