Reputation: 919
I am having a bit of a problem with my COBOL homework again. I think everything is how it is suppose to be, but for some reason I cannot get any output data when I run my program. All it does is show blank lines like someone just hit the enter key over and over. It really sucks cause I can't see if I am right or wrong. Here is my code:
WORKING-STORAGE SECTION.
01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE 'YES'.
01 LINE-COUNT PIC 99 VALUE ZEROS.
01 WS-DATE.
05 RUN-YEAR PIC XX.
05 RUN-MONTH PIC XX.
05 RUN-DAY PIC XX.
01 HEADING-LINE-1.
05 PIC X(24) VALUE SPACES.
05 PIC X(26)
VALUE 'BASEBALL PLAYER STATISTICS'.
05 PIC X(12) VALUE SPACES.
05 HL-1-DATE.
10 MONTH-2 PIC XX.
10 PIC X VALUE '/'.
10 DAY-2 PIC XX.
10 PIC X VALUE '/'.
10 YEAR-2 PIC XX.
05 PIC X(6) VALUE SPACES.
05 PAGE-1 PIC X(4) VALUE 'PAGE'.
01 HEADING-LINE-2.
05 PIC X(6) VALUE 'LEAGUE'.
05 PIC X(3) VALUE SPACES.
05 PIC X(4) VALUE 'TEAM'.
05 PIC X(5) VALUE SPACES.
05 PIC X(4) VALUE 'NAME'.
05 PIC X(10) VALUE SPACES.
05 PIC X(4) VALUE 'HITS'.
05 PIC X(6) VALUE SPACES.
05 PIC X(7) VALUE 'AT BATS'.
01 DETAIL-LINE.
05 BLANK-A-OUT PIC X VALUE SPACES.
05 DL-LEAGUE PIC XX.
05 BLANK-B-OUT PIC X(3) VALUE SPACES.
05 DL-TEAM PIC X(3).
05 BLANK-C-OUT PIC X(3) VALUE SPACES.
05 DL-NAME PIC X(10).
05 BLANK-D-OUT PIC X(3) VALUE SPACES.
05 DL-HITS PIC ZZ9.
05 BLANK-E-OUT PIC X(3) VALUE SPACES.
05 DL-AT-BATS PIC ZZ9.
PROCEDURE DIVISION.
100-MAIN.
OPEN INPUT BASEBALL-FILE-IN
OPEN OUTPUT BASEBALL-FILE-OUT
ACCEPT WS-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-2
MOVE RUN-DAY TO DAY-2
MOVE RUN-YEAR TO YEAR-2
WRITE BASEBALL-RECORD-OUT
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
READ BASEBALL-FILE-IN
AT END
MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 200-PROCESS-ONE-RECORD
END-READ
END-PERFORM
CLOSE BASEBALL-FILE-IN
CLOSE BASEBALL-FILE-OUT
STOP RUN.
200-PROCESS-ONE-RECORD.
MOVE LEAGUE-IN TO DL-LEAGUE
MOVE SPACES TO BLANK-A-OUT
MOVE TEAM-IN TO DL-TEAM
MOVE SPACES TO BLANK-B-OUT
MOVE NAME-IN TO DL-NAME
MOVE SPACES TO BLANK-C-OUT
MOVE HITS-IN TO DL-HITS
MOVE SPACES TO BLANK-D-OUT
MOVE AT-BATS-IN TO DL-AT-BATS
MOVE SPACES TO BLANK-E-OUT
WRITE BASEBALL-RECORD-OUT
AFTER ADVANCING 2 LINES.
300-LINE.
IF LINE-COUNT >= 50
PERFORM 400-NEXT-PAGE
END-IF
WRITE BASEBALL-RECORD-OUT
AFTER ADVANCING 1 LINE
ADD 1 TO LINE-COUNT.
400-NEXT-PAGE.
WRITE BASEBALL-RECORD-OUT
AFTER ADVANCING PAGE
MOVE ZEROS TO LINE-COUNT.
Upvotes: 1
Views: 4021
Reputation: 126
I see there are two paragraphs which are not executed in the code starting 300- and 400- as they are not performed and are below the stop run. There may be i-o-control entries omitted for the output to the file and the output appears to be written to a file and not to a display screen or printer. This would depend any default settings or those of any external assignments or redirects.
Upvotes: 0
Reputation: 16928
Several different patterns may be used when coding COBOL I/O operations. I see two distinct patterns in your program.
Pattern 1:
Define I/O record layouts under the FD entry. You have done this for your input file. BASEBALL-RECORD-IN serves as both a file I/O buffer and a full record description.
Pattern 2:
Define a dummy FD record buffer then create additional detail record definitions under Working Storage. You did this for your output record. BASEBALL-RECORD-OUT is just an I/O buffer and the detail record layouts are defend under Working Strorage using three different record layouts: HEADING-LINE-1, HEADING-LINE-1 and DETAIL-LINE.
What is the difference?
The primary differences relate to when each of these records becomes addressable and how you read/write data.
When using Pattern 1, only a single record buffer is allocated. This is the record associated with the file's FD clause. In your case this is the 36 byte BASEBALL-RECORD-IN record. This buffer may not be addressable until after the file it is associated with has been OPENed. Attempting to access this record buffer (by explicitly initializing it, moving spaces to it or any other reference) would cause a run-time error (crash and burn). After the open and READ, data are available in the record buffer associated with the FD. Since this FD has a defined record structure, you may reference any of the fields in it (e.g. NAME-IN) immediately after issuing a READ statement.
When using Pattern 2, Separate record structures are declared in Working Storage. Here the records HEADING-LINE-1, HEADING-LINE-2 and DETAIL-LINE are all addressable when the program starts running - even though the output record buffer BASEBALL-RECORD-OUT (associated with the FD) will not be addressable until after the output file has been opened. The thing to remember here is that there is no "automatic" connection between the record buffer BASEBALL-RECORD-OUT and the Working storage records HEADING-LINE-1, HEADING-LINE-2 and DETAIL-LINE - you have to explicitly MOVE the data from Working Storage to the record buffer using something like:
MOVE HEADING-LINE-1 TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT
before each and every WRITE operation. Alternatively you could write from the Working Storage record as in:
WRITE BASEBALL-RECORD-OUT FROM HEADING-LINE-1
This is just a sugar coated way of doing the MOVE/WRITE illustrated above.
This explanation should make it clear to you why the READ puts data directly into a fully fielded record structure for reference, but WRITE requires an additional MOVE of some sort.
These are two I/O patterns available in COBOL. As you learn more about the language quite a few additional patterns should come to light as well.
Upvotes: 3
Reputation: 2882
You are never moving the data you read from BASEBALL-2.SEQ into the record used to write BASEBALL-2.RPT.
You can do something like
* WRITE THE HEADER INFO
MOVE HEADING-LINE-1 TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT
Or
WRITE BASEBALL-RECORD-OUT FROM HEADING-LINE-1
Similarly you can write the details line
* WRITE THE DETAIL
MOVE DETAIL-LINE TO BASEBALL-RECORD-OUT
WRITE BASEBALL-RECORD-OUT
Upvotes: 1
Reputation: 51445
You have to move HEADING-LINE-1, HEADING-LINE-2, and DETAIL-LINE to BASEBALL-RECORD-OUT before you WRITE BASEBALL-RECORD-OUT.
Upvotes: 0
Reputation: 4970
It's been a while since I touched Cobol but you are probably missing updating BASEBALL-RECORD-OUT.
Upvotes: 0