0

As the title may indicate, I am having some difficulty getting the desired output for my COBOL program. The program takes in data from a file and outputs in a specific format, this is for a homework assignment. When i run the program it works for the name header, schoolID header, and column header. The first course works fine then the output starts to cut off by one and messes up all my other outputs.

Input File example

CMPS161 ALGORITHM DSGN/IMPLMNT I A 3.00 CMPS280 ALGORITHM DSGN/IMPLEM II B 3.00

Output file desired example

<Name> <schoolID> Course Title GR Earned CMPS161 ALGORITHM DSGN/IMPLMNT I A 3.00 CMPS280 ALGORITHM DSGN/IMPLEM II B 3.00

Output actual example

<Name> <schoolID> Course Title GR Earned CMPS161 ALGORITHM DSGN/IMPLMNT I A 0.00 MPS280 ALGORITHM DSGN/IMPLEM II B 0.00

COBOL Project

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 inRecord.
   02 Course   PIC X(13).
   02 Title    PIC X(32).
   02 Grade    PIC X(4).
   02 Earned   PIC Z9.99.
   02 FILLER   PIC X(3).
FD myOutFile.
01 outRecord.
   02 myCourse  PIC X(13).
   02 myTitle   PIC X(32).
   02 myGrade   PIC X(4).
   02 myEarned  PIC Z9.99.
   02 FILLER    PIC X(3).
WORKING-STORAGE SECTION.
01 E0F PIC X(3) VALUE "NO ".
01 NAME-HDR.
    05 FILLER    PIC X(10) VALUE "NAME HERE ".
01 SCHOOLID-HDR.
    05 FILLER    PIC X(8) VALUE "SCHOOLID"
01 COLUMN-HDR.
    05 FILLER   PIC X(6)  VALUE "COURSE".
    05 FILLER   PIC X(6)  VALUE  SPACES.
    05 FILLER   PIC X(6)  VALUE "TITLE".
    05 FILLER   PIC X(6)  VALUE  SPACES.
    05 FILLER   PIC X(6)  VALUE "GR".
    05 FILLER   PIC X(6)  VALUE  SPACES.
    05 FILLER   PIC X(6)  VALUE "EARNED".
PROCEDURE DIVISION.
MAIN-PROGRAM.
    PERFORM HEADER.
    PERFORM FILE-IO.
    PERFORM CLOSING.
    STOP RUN.
HEADER.
    OPEN INPUT myInFile
         OUTPUT myOutFile.
    WRITE outRecord FROM NAME-HDR
           AFTER ADVANCING 1 LINE.
    WRITE outRecord FROM SCHOOLID-HDR
           AFTER ADVANCING 1 LINE.
    WRITE outRecord FROM COLUMN-HDR
           AFTER ADVANCING 2 LINES.
    MOVE SPACES TO outRecord.
    WRITE outRecord
          AFTER ADVANCING 1 LINE.
    FILE-IO.
       READ myInFile
          AT END
               MOVE "YES" TO EOF.
       PERFORM PROCESS-RECORD
       UNTIL EOF = "YES".
    PROCESS-RECORD.
         MOVE SPACES TO outRecord.
         MOVE Course to myCourse.
         MOVE Title to myTitle.
         MOVE Grade to myGrade.
         MOVE Earned to myEarned.
         WRITE outRecord
            AFTER ADVANCING 1 LINE.
         READ myInFile
            AT END
               MOVE "YES" TO EOF.
     CLOSING.
         CLOSE myInFile
               myOutFile.
CoryC
  • 11
  • 4
  • 3
    What is most likely is that your data-records are one byte "shorter" than your data-definition of the records. You haven't told the compiler otherwise, so remember that you would have to include a byte for a record-terminator, but only one. – Bill Woodger Sep 04 '16 at 18:59
  • Yes I hand counted my data definitions including the free space at the end and the new line character in my filler. course is 13 spaces, title is 32, grade is 4 spaces so i can have a suppressed number for later calculations in earned, and 3 in the filler spot including line terminator. – CoryC Sep 04 '16 at 19:05
  • 1
    Spot on sir, I fixed it with the filler value i was including too many spaces. Thanks a million. – CoryC Sep 04 '16 at 19:17
  • 1
    @bill-woodger: looks like you've posted the answer, can you please re-post it enabling the OP to accept (and therefore kind of close this question)? – Simon Sobisch Sep 05 '16 at 06:39

1 Answers1

0

My COBOL is very rusty but I don't think that 'Z' in input formats will work. Leading zero suppression is just for output formats. You may simply have to replace leading spaces with zeroes before you do anything with the data. Try something like:

INSPECT Earned REPLACING ALL SPACES BY '0'.

after the read (and change the input format to 99.99). It's a common problem but I can't remember how I used to deal with it.

Mick
  • 4,987
  • 1
  • 19
  • 23
  • No. According to the COBOL Standard, that should just be an alphanumeric MOVE. Since 1985, if the target had been a numeric field, it would have been a "de-editing" MOVE, where the formatting is "reversed". But as it is, it is still an alpha-numeric MOVE and won't affect, perfectly valid, and won't affect anything. – Bill Woodger Sep 04 '16 at 18:58