Prev Up Next
Go backward to 4.6 Fortran program
Go up to 4 Labs
Go forward to 4.8 Internet

4.7 COBOL Program 2

  1. Using an editor, type in the following program, calling it TYPER.COB. You should use the space for indenting the program statements. Name the program source file TYPER.COB. Indentation is important.

    "IDENTIFICATION DIVISION." starts in column one.

    IDENTIFICATION DIVISION. 
    PROGRAM-ID. TYPER.
    AUTHOR. your name. 
    
    ENVIRONMENT DIVISION. 
    INPUT-OUTPUT SECTION. 
    FILE-CONTROL. 
        SELECT INPUT-FILE ASSIGN TO "TYPER_INPUT". 
    
     
    DATA DIVISION. 
    
    FILE SECTION. 
    
     
    FD      INPUT-FILE 
        LABEL RECORDS ARE STANDARD 
        DATA RECORD IS INPUT-REC. 
    01  INPUT-REC. 
        02  TEXT-LINE   PIC X(80). 
    
    WORKING-STORAGE SECTION. 
     
    01  MORE-RECORDS        PIC XXX VALUE "YES". 
     
    PROCEDURE DIVISION.
    MAIN-PARAGRAPH.
        OPEN INPUT INPUT-FILE. 
        DISPLAY "HERE GOES--". 
        READ INPUT-FILE 
            AT END MOVE "NO" TO MORE-RECORDS.
        PERFORM PROCESS-A-RECORD
            UNTIL MORE-RECORDS = "NO". 
        CLOSE INPUT-FILE.
        DISPLAY "DONE". 
        STOP RUN. 
      
    PROCESS-A-RECORD. 
        DISPLAY INPUT-REC. 
        MOVE SPACES TO INPUT-REC. 
        READ INPUT-FILE
            AT END MOVE "NO" TO MORE-RECORDS. 
    
    
  2. Compile the COBOL program you created in this lab (TYPER.COB) with a listing. If you get errors, refer to the code in this lab. Correct errors with a text editor.
     
    $ cobol typer /list 
    
  3. Link and execute the program. It should type out a small file on your terminal. If not try to figure out what is wrong, correct and go back to step 1.
     
    $ link typer 
    $ run typer  
    
  4. Clean up the files you do not need and print out the final copy of the listing.
     
    $ delete typer.obj;*, typer.exe;* 
    $ purge typer.*
    $ print/delete typer.lis
    
On the final listing from the last step hand print the following:
Your-Name
Lab 4.7: COBOL compile and run
TABER CSC135
Place the lab in the instructor hand-in box in BUS R6E, the "terminal room".
Instructor: ltaber@pima.edu** Red's Home page** The Pima College Site

Prev Up Next