Reputation: 1
I just started using COBOL for my COBOL class and I don't know what's wrong with lines 9, 30, and 62. Hope you could help me. Thank you.
******************************************************************
* Author: Emil
* Date: 12/02/21
* Purpose: Sorting and Debugging
* Tectonics: cobc
******************************************************************
PROGRAM-ID. InputSort.
PROCEDURE DIVISION
Using SORT and INPUT PROCEDURE. The program accepts records
* from the user and RELEASEs them to the work file
* where they are sorted. This program
* allows student records to be entered in any order but
* produces a file sequenced on ascending StudentId.
ENVIRONMENT DIVISION
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT StudentFile ASSIGN TO "SORTSTUD.DAT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT WorkFile ASSIGN TO "WORK.TMP".
DATA DIVISION.
FILE SECTION.
FD StudentFile.
01 StudentDetails PIC X(30).
* The StudentDetails record has the description shown below.
* But in this program we don't need to refer to any of the items in
* the record and so we have described it as PIC X(32)
* 01 StudentDetails
* 02 StudentId PIC 9(7).
* 02 StudentName.
* 03 Surname PIC X(8).
* 03 Initials PIC XX.
* 02 DateOfBirth.
* 03 YOBirth PIC 9(4).
* 03 MOBirth PIC 9(2).
* 03 DOBirth PIC 9(2).
* 02 CourseCode PIC X(4).
* 02 Gender PIC X.
SD WorkFile.
01 WorkRec.
02 WStudentId PIC 9(7).
02 FILLER PIC X(23).
PROCEDURE DIVISION.
Begin.
SORT WorkFile ON ASCENDING KEY WStudentId
INPUT PROCEDURE IS GetStudentDetails
GIVING StudentFile.
STOP RUN.
GetStudentDetails.
DISPLAY "Enter student details using template below."
DISPLAY "Enter no data to end.".
DISPLAY "Enter - StudId, Surname, Initials, YOB, MOB, DOB, Course, Gender"
DISPLAY "NNNNNNNSSSSSSSSIIYYYYMMDDCCCCG"
ACCEPT WorkRec.
PERFORM UNTIL WorkRec = SPACES
RELEASE WorkRec
ACCEPT WorkRec
END-PERFORM.
Upvotes: 0
Views: 639
Reputation: 616
General note: Watch your periods (full stops). They mean something. In COBOL many of them are optional but some are not. Be consistent about where you put them. In the procedure division, this is especially important!
Line 8, PROCEDURE DIVISION
. Okay, this is the first problem. The divisions are IDENTIFICATION
, ENVIRONMENT
, DATA
and PROCEDURE
, in that order. Having PROCEDURE DIVISION
here is way out of order and was missing the required period. Perhaps you meant IDENTICATION DIVISION.
but even then it should be the first statement but for comments.
Line 9 and following: Typically remarks such as these are proceeded by a REMARKS.
heading, or make them all (including line 9) into comments.
Line 30: I don't see a problem with a comment. Did you mean some other line?
Line 62: I don't see a problem. What was the error message?
BUT your perform loop will either never start or never end because nothing inside of the loop (PERFORM
through END-PERFORM
) changes WorkRec
. Perhaps you want add an additional ACCEPT
statement inside of the loop, use the WITH TEST AFTER
clause on the PERFORM
statement and move the ACCEPT
statement into the loop.
Upvotes: 1