Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

programs uses two input files and produces output using binary search on criteria fields

Posted By: Lola Hughes     Category: Cobol     Views: 3529

Write a programs uses two input files and produces output using binary search on criteria fields.

Code for programs uses two input files and produces output using binary search on criteria fields in Cobol

       IDENTIFICATION DIVISION.
        PROGRAM-ID. BinarySearch.

       ENVIRONMENT DIVISION.

        CONFIGURATION SECTION.
         SOURCE-COMPUTER. IBM-PC.
         OBJECT-COMPUTER. IBM-PC.

        INPUT-OUTPUT SECTION.
         FILE-CONTROL.

           SELECT TABLE-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.

           SELECT CUST-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.

           SELECT BILL-FILE ASSIGN TO DISK
           ORGANIZATION IS LINE SEQUENTIAL.

       DATA DIVISION.

        FILE SECTION.

         FD TABLE-FILE
           VALUE OF FILE-ID IS "TABLE.IND".
         01 TABLE-REC.
            05 ZIPCODE PIC 9(6).
            05 FILLER PIC XX.
            05 TAX-RATE PIC 99.

         FD CUST-FILE
           VALUE OF FILE-ID IS "CUST.DAT".
         01 SAL-REC.
            05 C-ID PIC 9(4).
            05 FILLER PIC XX.
            05 C-ZIPCODE PIC 9(6).
            05 FILLER PIC XX.
            05 C-SALE PIC 9(6).

         FD BILL-FILE
           VALUE OF FILE-ID IS "BILL.RPT".
         01 BILL-REC PIC X(80).

        WORKING-STORAGE SECTION.
        01 TAB.
            05 TABLE-ENTRIES OCCURS 5 TIMES
               ASCENDING KEY IS TEMP-ZIPCODE
               INDEXED BY X1.

                07 TEMP-ZIPCODE PIC 9(6).
                07 FILLER PIC XX.
                07 TEMP-TAX-RATE PIC 99.

        01 OUT-REC.
           05 OUT-C-ID PIC 9(4).
           05       PIC XX VALUE SPACES.
           05 OUT-C-ZIPCODE PIC 9(6).
           05       PIC XX VALUE SPACES.
           05 OUT-C-SALE PIC 9(6).
           05       PIC XX VALUE SPACES.
           05 OUT-C-TAX-RATE PIC 9(2).
           05       PIC XX VALUE SPACES.
           05 OUT-C-TAX PIC 9(6).

        77 EOF PIC X VALUE 'N'.

       PROCEDURE DIVISION.

         BEGIN.
           OPEN INPUT TABLE-FILE
                      CUST-FILE
               OUTPUT BILL-FILE.

           PERFORM GET-TABLE-ENTRIES.
           PERFORM GET-SAL-ENTRIES.

           CLOSE TABLE-FILE
                 CUST-FILE
                 BILL-FILE.

           STOP RUN.

         GET-TABLE-ENTRIES.
           PERFORM VARYING X1 FROM 1 BY 1
                   UNTIL X1 > 5
            READ TABLE-FILE
             AT END CONTINUE
             NOT AT END PERFORM MOVE-TABLE-ENTRIES
            END-READ
           END-PERFORM.

         MOVE-TABLE-ENTRIES.
           MOVE ZIPCODE TO TEMP-ZIPCODE (X1)
           MOVE TAX-RATE TO TEMP-TAX-RATE (X1).

         GET-SAL-ENTRIES.
           PERFORM UNTIL EOF = 'Y'
            READ CUST-FILE
             AT END MOVE 'Y' TO EOF
             NOT AT END PERFORM MOVE-CUST-ENTRIES
            END-READ
           END-PERFORM.

         MOVE-CUST-ENTRIES.
           MOVE C-ID TO OUT-C-ID
           MOVE C-ZIPCODE TO OUT-C-ZIPCODE
           MOVE C-SALE TO OUT-C-SALE

      *******************************************************
      *         SEARCH BLOCK USING CLAUSE SEARCH            *
      *         PERFORMS BINARY SEARCH                      *
      *         THEREFORE WE NEED NOT TO SET INDEX VAR TO 1 *
      *                                          (X1)       *
      *         BUT NEED TO SPECIFY ASCENDING OR            *
      *                             DECENDING KEY           *
      *******************************************************

      *    SET X1 TO 1

           SEARCH ALL TABLE-ENTRIES

            AT END
              MOVE 0 TO OUT-C-TAX-RATE OUT-C-TAX

            WHEN C-ZIPCODE = TEMP-ZIPCODE (X1)
              MOVE TEMP-TAX-RATE (X1) TO OUT-C-TAX-RATE
              COMPUTE OUT-C-TAX = (OUT-C-SALE * OUT-C-TAX-RATE) /100

           END-SEARCH
           WRITE BILL-REC FROM OUT-REC.


***********************
INPUT FILE 1- TABLE.IND                            
***********************

380001  05
380002  10
380003  15
380004  20
380005  25

*********************
INPUT FILE 2- EMP.DAT                            
*********************

0001  380001  100000
0002  380002  100000
0003  380003  100000
0004  380004  100000
0005  380005  100000


*************************
OUTPUT FILE - BSEARCH.COB                            
*************************
           
0001  380001  100000  05  005000
0002  380002  100000  10  010000
0003  380003  100000  15  015000
0004  380004  100000  20  020000
0005  380005  100000  25  025000
  
Share: 



Lola Hughes
Lola Hughes author of programs uses two input files and produces output using binary search on criteria fields is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!