Question:
What am I missing in this COBOL code?
taciturnanthem
2008-11-06 13:11:20 UTC
So, my GLORIOUS professor (::sarcasm::) has decided to delay in giving me a compiler to test anything in COBOL, let alone cancel a bunch of classes. So, again, I'm back on the internet asking for programming help.

The question presents itself as: "Write a program to print all information from payroll records for employees of the International Cherry Machine Company (ICM)."

My code is as follows (there is a separate file that is called C0402):

IDENTIFICATION DIVISION.
PROGRAM-ID. PAYROLL-MASTER.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT C0402 ASSIGN TO DATA4E.
*
DATA DIVISION.
FILE SECTION.
FD C0402.
01 PAYROLL-MASTER.
05 IN-EMPLOYEE-NO. PIC X(5).
05 IN-EMPLOYEE-NAME. PIC X(20)














100-MAIN-MODULE.
OPEN INPUT C0402
OUTPUT OUT-SAMPLE
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO'
READ IN-EMPLOYEE-FILE
AT END
MOVE 'NO' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 200-PROCESS-RTN
END-READ
END-PERFORM
CLOSE IN-EMPLOYEE-FILE
OUT-SALARY-FILE
STOP RUN.

200-PROCESS-RTN.
MOVE C0402 TO
MOVE C0402 TO
WRITE
Three answers:
TheMadProfessor
2008-11-07 08:28:36 UTC
Well, unless you plan to write output using DISPLAY (which I assume you didnt since you had an OPEN OUTPUT), at a minimum you need:



1) A SELECT in file-control for your output (OUT-SAMPLE)

2) An FD for your output (may need additional clauses for both the input and output FDs as well.)

3) A WORKING-STORAGE section containing your flag (initialized to "YES") and output-record format(s).

4) Code in 2000-PROCESS-RTN to MOVE IN-EMPLOYEE-NO and IN-EMPLOYEE-NAME to the corresponding output format(s) and then WRITEs of the output file record name FROM the format(s) (Remember the rule: Read a file, write a record.)



Note, you could have the output record format(s) directly in the FD and do WRITE instead of WRITE FROM, but I'd recommend using working-storage - it can make life much easier with more complex projects. Also, I'd suggest putting the detailed input file format in working storage as well and do a READ INTO...avoid working directly with the file areas as a general rule.



As for compilers, take a look at http://www.cobug.com/cobug/docs/freeCompilers0098.html to see if any of those work for you.



(and all due respect to Peter, Cobol is hardly 'rubbish' - it's still going strong after nearly 50 years iwth literally billions of lines of code still being executed. Name me another computer language with that sort of longevity... The current version of Cobol is object-oriented and plays very nicely in the client-server sandbox - it isn't just for mainframes anymore...)
2008-11-06 13:27:01 UTC
Ouch. I last saw COBOL in about 1978 and it was rubbish even back then. Is this an ancient languages course?



However, there is no excuse for not being able to compile COBOL these days as there are plenty of free compilers out there.
sunshine
2016-05-26 06:52:39 UTC
Unless YA is suppressing some of your whitespace, might be that your 2nd line is starting too far to the left (tho I would have expected a different error message in that case - parens and punctuation look OK to me too).


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...