Reputation: 7
My task was to read a record from first file and check for the corresponding record from the second file and display it. this is my code:
PERFORM READ-PARA1 THRU END-PARA UNTIL WS-END-OF-FILE.
PERFORM READ-PARA2 THRU END-PARA UNTIL WS-END-OF-FILE.
CLOSE FILEX.
CLOSE FILEY.
STOP RUN.
READ-PARA1.
READ FILEX
AT END
MOVE 'Y' TO WS-EOF-IND.
DISPLAY SPACE
DISPLAY OCODE1,' 'ACODE1,' 'POLNO1,' 'EDATE1,
' 'PHOLD1,' 'LOCATION1,' '.
READ-PARA2.
READ FILEY
READ FILEY
AT END
PERFORM READ-PARA3 UNTIL R1 = 4.
IF POLNO1 = POLNO2
DISPLAY ' ',
LICNO1,' 'VMAKE1,' 'VMODEL,' 'YEAR,' 'PREM
ELSE
READ FILEY NEXT RECORD
GO TO READ-PARA2.
END-PARA.
EXIT.
READ-PARA3.
CLOSE FILEY.
OPEN INPUT FILEY.
READ FILEY
AT END
MOVE 'Y' TO WS-EOF-IND.
ADD 1 TO R1.
IF POLNO1 = POLNO2
DISPLAY ' ',
DISPLAY ' ',
LICNO1,' 'VMAKE1,' 'VMODEL,' 'YEAR,' 'PREM
ELSE
READ FILEY NEXT RECORD
GO TO READ-PARA3.
This code works only to find the corresponding record for first record of file 1, but for rest all it displays blank, and both are sequential files.
Upvotes: 0
Views: 2089
Reputation: 16928
I don't really know what to say here, except maybe try re-writing your program using up-to-date coding practices - your current code is a mix of pre/post COBOL-85 coding styles making it very difficult to follow. Try re-writing with the following objectives.
PERFORM THRU
. PERFORM
is fine, the THRU
bit is a pre COBOL-85 throwback and should no longer be used. If you need to preform several paragraphs/sections inside a loop, try something like:
PERFORM UNTIL some-condition PERFORM PARA-A PEROFMR PARA-B END-PERFORM
END-IF
, END-PERFORM
etc. GO TO
. There are very few places where the use of GO TO
is warranted. In a program of this size/complexity it should never be used.EXIT
. When using scope terminators properly (see point 1 and 2). EXIT
is no longer needed.NEXT SENTENCE
. This too is a pre COBOL-85 throwback and is technically obsolete.If you manage to re-write with the above guidelines, you might just find that your problems are a lot easier to spot and fix. Give it another shot. I think it may work out a lot better on a second try.
Upvotes: 4