CIS 214 Introduction to COBOL- program #0

This program is to see the example from the first chapter (first given on page 19 with sample data on page 20 and the sample output on page 20 and also given on page 25).

The objectives of this assignment are:

Here is the program code (slightly modified by the instructor) - notice that some statements start in column 8 (margin A) and others in column 12 (margin B). Statements in the first three divisions end with periods. Be careful to have periods in the right place in the procedure division. You may want to copy the following lines of code (select the text and then press Ctrl-C to copy the lines to the clipboard) - and paste the code into notepad (Ctrl-V) and save the code as Lab0.cbl (or "copy-and-paste" into the Microfocus editor - BUT make sure that the statements start in column 8 - or the program will not work).

       IDENTIFICATION DIVISION.
       PROGRAM-ID. COBOL-LAB1.
       AUTHOR.  BRUCE A. WHITE.
      *PAGE 19 IN TEXTBOOK (ALSO PAGE 25)
      ******************************************************************
       ENVIRONMENT DIVISION.
      *  defines the external files - an input file and output file
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.

       SELECT EMPLOYEE-FILE ASSIGN TO "A:\LAB0.TXT"
              ORGANIZATION IS LINE SEQUENTIAL.

       SELECT PAYROLL-FILE ASSIGN TO "A:\LAB0OUT.TXT"
              ORGANIZATION IS LINE SEQUENTIAL.

       DATA DIVISION.
      * has two sections - the file section that describes the files
      * and the working storage section - where output lines and
      * processing variables are defined

       FILE SECTION.

       FD EMPLOYEE-FILE.
      * this defines the structure of the input-file
       01 EMPLOYEE-RECORD.
           05 EMPLOYEE-NAME-IN         PIC X(20).
           05 HOURS-WORKED-IN          PIC 99.
           05 HOURLY-RATE-IN           PIC 9V99.
      *****************************************************************
      * the payroll file has three fields:  employee-name, hours
      * worked and hourly-rate-of-pay
      *
      * first name is up to 20 characters long (thus a picture
      * clause of X(20) indicating 20 characters
      *
      * the hours-worked field is two numeric digits like 40 for
      * 40 hours worked in a week.
      *
      * the hourly-rate-in field is three numeric digits long with
      * an implied decimal place, so 9.75 would be 975 in the data
      * file (nobody gets over 9.99 an hour!)
      *****************************************************************


       FD PAYROLL-FILE.
       01 PRINT-RECORD.
           05                          PIC X(20).
           05 NAME-OUT                 PIC X(20).
           05                          PIC X(10).
           05 HOURS-OUT                PIC 9(2).
           05                          PIC X(8).
           05 RATE-OUT                 PIC 9.99.
           05                          PIC X(6).
           05 WEEKLY-WAGES-OUT         PIC 999.99.

       WORKING-STORAGE SECTION.

      * defines processing variables and output lines

       01  FLAGS-AND-ACCUMULATORS.
           05  END-OF-FILE             PIC XXX VALUE "NO".

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

       PROCEDURE DIVISION.
      * finally - where the real work gets done
      * it is divided into paragraphs (or modules) generally called
      * from the main controlling module (here 1000-MAIN-CONTROL).

       100-MAIN-MODULE.
           OPEN INPUT EMPLOYEE-FILE,
                OUTPUT PAYROLL-FILE.
           PERFORM UNTIL END-OF-FILE = "YES"
               READ EMPLOYEE-FILE
                   AT END
                       MOVE "YES" TO END-OF-FILE
                   NOT AT END
                       PERFORM 200-WAGE-ROUTINE
               END-READ
           END-PERFORM
           CLOSE EMPLOYEE-FILE,
                 PAYROLL-FILE.
           STOP RUN.


       200-WAGE-ROUTINE.
           MOVE SPACES TO PRINT-RECORD
           MOVE EMPLOYEE-NAME-IN       TO NAME-OUT
           MOVE HOURS-WORKED-IN        TO HOURS-OUT
           MOVE HOURLY-RATE-IN         TO RATE-OUT

      * now calculate the gross pay
           MULTIPLY HOURS-WORKED-IN BY HOURLY-RATE-IN
               GIVING WEEKLY-WAGES-OUT.

           WRITE PRINT-RECORD.

This assignment will be not graded, but it is designed to get the student familiar with the MicroFocus environment and COBOL.

After writing the program, you will need to "check" it.  If it checks clean, then you can execute it; if it doesn't check clean, you will need to correct the syntax errors.

You might need to re-open the file in execution mode (files can be opened for edit or they can be opened for execution).  Execution files will have the file extension of .int.  You then will run the program.  You should get this message:

When you run the program - you know it is successful when it displays this message:

 

If you have difficulties or want some additional help in getting this accomplished, PLEASE e-mail me (at bruce.white@quinnipiac.edu )or call me (203) 281-6482 (home) or (203) 582-3386 (office).  I'll call you and we'll walk our way through the editor, through the processes and the application!!!!

Bruce

 

Click here to see the data file

Click here to see the program output

Return to Internet COBOL main page