Home > Back-end >  COBOL Sequential file I/O
COBOL Sequential file I/O

Time:09-30

I'm creating a program that reads an input file with some student info, then output it to the terminal and an output file. I also need to calculate the GPA based on the hours and quality points earned.

I am getting the errors:

P2.cob: 46: error: PICTURE clause required for 'outRecord'
P2.cob: in paragraph 'ProcessData':
P2.cob: 81: error: 'CUMULATIVE-QP' is not a numeric value
P2.cob: 84: error: 'CUMULATIVE-QP' is not a numeric value
P2.cob: 87: error: 'CUMULATIVE-QP' is not a numeric value
P2.cob: 90: error: 'CUMULATIVE-QP' is not a numeric value

Any help/tips would help greatly. My input file example & code attached below:

MICHAEL RICHARDSON W1234567 FALL2019 CMPS141 INTRO TO JAVA             A 3.00 12.00
MICHAEL RICHARDSON W1234567 FALL2019 ENGL101 FRESHMAN COMPOSITION      B 3.00 09.00
MICHAEL RICHARDSON W1234567 SPNG2020 CMPS220 OPERATING SYSTEMS         A 3.00 12.00
MICHAEL RICHARDSON W1234567 SPNG2020 ENGL102 CRITICAL READING AND WRIT A 3.00 12.00
IDENTIFICATION DIVISION.
PROGRAM-ID.  P2.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT myInFile  ASSIGN TO "P2In.dat".
    SELECT myOutFile ASSIGN TO "P2Out.dat".
DATA DIVISION.
FILE SECTION.
FD myInFile.
01 RecordDetails.
   03 StudentDetails.
      05 STUDENT-NAME        PIC X(16).
      05 STUDENT-ID          PIC X(9).
   03 SemesterDetails.
      05 SEMESTER            PIC X(9).
   03 ClassDetails.
      05 CLASS-NAME          PIC X(34).
      05 GRADE               PIC X(2).
   05 HOURS.
      07 HOURS-9             PIC 9.99.
   05 FILLER                 PIC X(2).
   05 POINTS.
      07 POINTS-X            PIC X(1) OCCURS 5.
   05 POINTS-9-99 REDEFINES POINTS.
      07 POINTS-9-99        PIC 9.99.
   05 POINTS-99-99 REDEFINES POINTS.
      07 POINTS-99-99       PIC 99.99.
01 CalculatedValues.
   05 CUMULATIVE-GPA-IN      PIC 99v99 VALUE ZERO.
   05 CUMULATIVE-QP-IN       PIC 99v99 VALUE ZERO.
   05 CUMULATIVE-HOURS-IN    PIC 99v99 VALUE ZERO.

FD myOutFile.
01 outRecord.

WORKING-STORAGE SECTION.

01 SWITCHES.
    05 EOF-SWITCH           PIC X VALUE "N".
01 COUNTERS.
    05 REC-COUNTER          PIC 9(3) VALUE 0.
01 CUMULATIVE.
    05 CUMULATIVE-QP        PIC ZZ.99.

PROCEDURE DIVISION.
Main.
    PERFORM Begin.
    PERFORM ProcessData.
    PERFORM PrintLines
            UNTIL EOF-SWITCH = "Y".

Begin.
    OPEN INPUT myInFile
    OPEN OUTPUT myOutFile

    READ myInFile
            AT END
                    MOVE "Y" TO EOF-SWITCH
            NOT AT END
                    COMPUTE REC-COUNTER = REC-COUNTER   1
    END-READ.

ProcessData.
    READ myInFile
    AT END
            MOVE "Y" TO EOF-SWITCH
    NOT AT END
            IF GRADE = 'A'
                    COMPUTE CUMULATIVE-QP = CUMULATIVE-QP   4
            ELSE
            IF GRADE = 'B'
 COMPUTE CUMULATIVE-QP = CUMULATIVE-QP   3
            ELSE
            IF GRADE = 'C'
                    COMPUTE CUMULATIVE-QP = CUMULATIVE-QP   2
            ELSE
            IF GRADE = 'D'
                    COMPUTE CUMULATIVE-QP = CUMULATIVE-QP   1
            END-IF.

PrintLines.

    READ myInFile
    AT END
            MOVE "Y" TO EOF-SWITCH

    NOT AT END
            DISPLAY CUMULATIVE-QP
    END-READ.

CodePudding user response:

Your first error says:

PICTURE clause required for 'outRecord'

this is telling you that in your FD for outRecord, you don't have a PIC clause defined:

FD myOutFile.
01 outRecord.

The compiler needs to know the layout of your output file.

CodePudding user response:

P2.cob: 46: error: PICTURE clause required for 'outRecord'

Like what @Slapout mentioned, you need to tell the compiler how you want output to be formatted. But you don't actually use myOutFile so perhaps you could skip that FD and open statement for now.

P2.cob: in paragraph 'ProcessData':
P2.cob: 81: error: 'CUMULATIVE-QP' is not a numeric value
P2.cob: 84: error: 'CUMULATIVE-QP' is not a numeric value
P2.cob: 87: error: 'CUMULATIVE-QP' is not a numeric value
P2.cob: 90: error: 'CUMULATIVE-QP' is not a numeric value

The picture for CUMULATIVE-QP is PIC Z9.99 which is a "numeric-edited" variable. Those are good for displaying something, but you can't use numeric-edited variables for calculations.

What you want are two data items:

  • One to store the cumulative QP and to use in calculations
  • One to display the cumulative QP

When you want to display the cumulative QP, you would MOVE the numeric variable to the numeric-edited variable, then DISPLAY that.

Perhaps (after defining display-qp with pic 99v99):

           move cumulative-qp to display-qp
           display display-qp
  • Related