From: p2003740@csdvax.csd.unsw.edu.au (Paul [Gwon-Seung])
Newsgroups: alt.cobol
Subject: help with reading a file from disk
Date: 27 Aug 92 14:25:27 +1000
Organization: University of NSW, OZ

Could someone please help me with a small problem I have?
The problem is I don't know how to select a file on disk and use it to be read
by my cobol program.

Since I am new to COBOL, I don't know much about it and need some help.

I have assigned the input device to disk, but how can I select a file named
rental.fle and use the contents of the file for input?

Here is what I have done so far:
       PROGRAM-ID.      MPG PROJECT.
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.      ANY PC COMPATIBLE.
       OBJECT-COMPUTER.      ANY PC COMPATIBLE.
       
       INPUT-OUTPUT SECTION.
 
       FILE-CONTROL.
           SELECT CUSTOMER-FILE
                 ASSIGN TO DISK.
           SELECT CUSTOMER-OUTPUT-FILE
                 ASSIGN TO PRINTER.
             
       DATA DIVISION.
 
       FILE SECTION.
 
       FD  CUSTOMER-FILE
           LABEL RECORDS STANDARD
           DATA RECORD IS CUSTOMER-REC.
       01  CUSTOMER-REC.
           05 CUSTOMER-NAME                     PIC X(20).
           05 MILES-DRIVEN                      PIC 9(3).
           05 RENTAL-FEE                        PIC 99.
       
       FD  CUSTOMER-OUTPUT-FILE.
           RECORD CONTAINS 50 CHARACTERS
           LABEL RECORDS ARE OMITTED
           DATA RECORD IS OUTPUT-PRINT-FILE.
       01  OUTPUT-PRINT-FILE                    PIC X(50).
 
       WORKING-STORAGE SECTION.
       01  TOTAL-RENTAL-FEE                     PIC 99.
       01  CHARGE                               PIC Z.9 VALUE 0.5.
       01  ANY-MORE-RECORDS-SW                  PIC X VALUE "N".
           03  ANY-MORE-RECORDS                       VALUE "Y".
       01  OUTPUT-PRINT-FILE.
           05  FILLER                           PIC X(5)  VALUE SPACES.
           05  CUSTOMER-NAME-OUT                PIC X(20).
           05  FILLER                           PIC X(10) VALUE SPACES.
           05  MILES-DRIVEN-OUT                 PIC XXX.
           05  FILLER                           PIC X(10) VALUE SPACES.
           05  TOTAL-RENTAL-FEE-OUT             PIC XX.
 
       PROCEDURE DIVISION.
       000-PRODUCE-RENTAL-CHARGES.
           DISPLAY "Program MPG Executing...".
 
           OPEN INPUT  CUSTOMER-FILE
                OUTPUT OUTPUT-PRINT-FILE.
 
           PERFORM 100-DETERMINE-CHARGES
              UNTIL ANY-MORE-RECORDS = "N".
 
           CLOSE CUSTOMER-FILE
                 OUTPUT-PRINT-FILE.
 
           DISPLAY "Program MPG Complete.".
           STOP RUN.
           
 
       100-DETERMINE-CHARGES.
           PERFORM 200-READ-CARD
              UNTIL ANY-MORE-RECORDS = "N"
 
           PERFORM 210-CALCULATE-CHARGES.
 
           PERFORM 220-FORMAT-PRINT-LINE.
 
           PERFORM 230-WRITE-PRINT-LINE.
 
 
       200-READ-CARD.
           READ CUSTOMER-FILE
                 AT END
                    MOVE "N" TO ANY-MORE-RECORDS.
 
       210-CALCULATE-CHARGES
           COMPUTE MILES-DRIVEN-CHARGE = MILES-DRIVEN * CHARGE.
 
           COMPUTE TOTAL-RENTAL-FEE = MILES-DRIVEN-CHARGE + RENTAL-CHARGE.
 
       220-FORMAT-PRINT-LINE.
           MOVE CUSTOMER-NAME TO CUSTOMER-NAME-OUT.
           MOVE MILES-DRIVEN-CHARGE TO MILES-DRIVEN-OUT.
           MOVE TOTAL-RENTAL-FEE TO TOTAL-RENTAL-FEE-OUT.
 
       230-WRITE-PRINT-LINE.
           WRITE OUTPUT-PRINT-FILE
                 AFTER ADVANCING 1 LINES.
Newsgroups: alt.cobol