0
votes

I am writing a simple COBOL program to read data and calculate tuition cost based on number of credit hours. My program is complete except for one error which I do not understand. On last line of the CALC routine I try to write the TUITION variable and I get the error: "Not a record name". I'm still learning the basic structure and setup of a COBOL program so I know it's some small mistype that I forgot about.

Code:

IDENTIFICATION DIVISION.
PROGRAM-ID. prg1-lankford.
AUTHOR. Lankford.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT DISK-FILE ASSIGN TO 'prg1.dat'
        ORGANIZATION IS LINE SEQUENTIAL.
    SELECT PRINT-FILE ASSIGN TO 'prg1-lankford.rpt'
        ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD  DISK-FILE
    RECORD CONTAINS 80 CHARACTERS.
01  DISK-REC.
    05  STUDENT-NAME-INPUT  PIC X(20).
    05  NUM-CREDITS-INPUT   PIC 9(2).
    05                  PIC X(58).
FD  PRINT-FILE
    RECORD CONTAINS 66 CHARACTERS.
01  PRINT-REC.
    05  STUDENT-NAME-OUTPUT PIC X(20).
    05                  PIC X(20).
    05  NUM-CREDITS-OUTPUT  PIC 9(2).
    05                  PIC X(20).
    05  TUITION             PIC 9(4).

WORKING-STORAGE SECTION.
01  MORE-RECORDS            PIC X VALUE 'Y'.
01  FULL-TIME-TUITION       PIC 9(4) VALUE 6300.
01  PER-CREDIT          PIC 9(3) VALUE 525.

PROCEDURE DIVISION.
100-MAIN-MODULE.
    OPEN INPUT DISK-FILE
        OUTPUT PRINT-FILE
    PERFORM UNTIL MORE-RECORDS = 'N'
        READ DISK-FILE
            AT END
                MOVE 'N' TO MORE-RECORDS
            NOT AT END
                PERFORM 200-CALC-RTN
        END-READ
    END-PERFORM
    CLOSE DISK-FILE
        PRINT-FILE
    STOP RUN.
200-CALC-RTN.
    MOVE STUDENT-NAME-INPUT TO STUDENT-NAME-OUTPUT
    MOVE NUM-CREDITS-INPUT TO NUM-CREDITS-OUTPUT
    IF NUM-CREDITS-INPUT < 12 THEN
        MULTIPLY NUM-CREDITS-INPUT BY PER-CREDIT
            GIVING TUITION
    ELSE 
        MOVE FULL-TIME-TUITION TO TUITION
    WRITE TUITION.
1
Try Write PRINT-REC you can only write full records not parts of records - Bruce Martin
Not specifically COBOL related, but routines that you perform/call should have one task, and the name should reflect that. Your "200-CALC-RTN" implies that it calculates but it does more than that: it also writes! I'd move the WRITE to just after the PERFORM statement. - Scott Nelson
It is also I good idea to put the period that closes the paragraph on its own line so people know exactly what it is. In older version of COBOL, there were no scope terminator (like END-IF), so a period was used for all termination. Putting it in the same line as WRITE TUITION can be a bit confusing, but not the end of the world - SaggingRufus

1 Answers

3
votes

Try

    Write PRINT-REC

you can only write full records not parts of records.

Also you are missing an end-if prior to the Write so try:

200-CALC-RTN.
    MOVE STUDENT-NAME-INPUT TO STUDENT-NAME-OUTPUT
    MOVE NUM-CREDITS-INPUT TO NUM-CREDITS-OUTPUT
    IF NUM-CREDITS-INPUT < 12 THEN
        MULTIPLY NUM-CREDITS-INPUT BY PER-CREDIT
        GIVING TUITION
    ELSE 
        MOVE FULL-TIME-TUITION TO TUITION
    end-if

    WRITE PRINT-REC.