Hi,
In COBOL can we actually skip the record i.e. don't proces the record and go to next record?
In my input files I can some of the records which i don't want process for the current execution. It is like validating the input. If there is/are any invalid records, I would like to skip them and read next recod. How can I do that? Should I use continue or NEXT-SETENCE?
READ and don't proces the record in COBOL.
- Akatsukami
- Global Moderator
- Posts: 122
- Joined: Tue Oct 20, 2015 3:20 am
- Location: Bloomington, IL
- Contact:
Re: READ and don't proces the record in COBOL.
Of course. The pseudo-code is:
Code: Select all
read record
do while (¬end of file)
if (valid-record)
then process
read record
end
"I come to the conclusion that, men loving according to their own will and fearing according to that of the prince, a wise prince should establish himself on that which is in his own control and not in that of others." -- Niccolò Machiavelli
- Robert Sample
- Global Moderator
- Posts: 1895
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: READ and don't proces the record in COBOL.
That would depend upon how your code is written. If you put a period after each COBOL statement, NEXT SENTENCE (which is the correct spelling) would be the way to go; if you only put a period at the end of each paragraph, CONTINUE would be the way to go.Should I use continue or NEXT-SETENCE?
In general, you write the code the way you want it to go. If you don't want to do anything with a record, READ it and then READ the next record. How, specifically, to code this most likely would depend upon the site coding standards.
-
- Global Moderator
- Posts: 490
- Joined: Sun Aug 25, 2013 7:24 pm
Re: READ and don't proces the record in COBOL.
Don't use NEXT SENTENCE (ever, unless you compiler is so old as to not allow it). Use CONTINUE.
NEXT SENTENCE will work as expected if an IF (or wherever else used) is terminated by a full-stop/period. It will not, otherwise, work as the reader of the code expects. NEXT SENTENCE is effectively GO TO NEXT FULL-STOP/PERIOD. Once full-stops/periods ceased to be mandatory terminators of a verb outside a conditional use, NEXT SENTENCE becomes a failure waiting to happen.
NEXT SENTENCE doesn't care about END-IF, as the full-stop/period is its target.
CONTINUE is a place-holder, it does nothing, it does not generate any code. Within a "leg" of a condition there must be a statement. If you have a use for NEXT SENTENCE in a simple condition prior to COBOL 85, you can use CONTINUE, which does nothing, and the compiler will generate its normal code for what to do next (CONTINUE does nothing, it just so happens that within the context of a condition, the compiler is going to generate a branch anyway when needed).
In poor-quality code that also uses full-stops/periods, I'm prepared to bet that for every 1,000 conditions there is at least on with an "missing" full-stop/period. That's already bad enough, but if there is also a NEXT SENTENCE within that construct, then the weirdness increases.
The way that NEXT SENTENCE needed to be used (when needed) means it can always be replaced by CONTINUE. So don't use NEXT SENTENCE.
NEXT SENTENCE will work as expected if an IF (or wherever else used) is terminated by a full-stop/period. It will not, otherwise, work as the reader of the code expects. NEXT SENTENCE is effectively GO TO NEXT FULL-STOP/PERIOD. Once full-stops/periods ceased to be mandatory terminators of a verb outside a conditional use, NEXT SENTENCE becomes a failure waiting to happen.
NEXT SENTENCE doesn't care about END-IF, as the full-stop/period is its target.
CONTINUE is a place-holder, it does nothing, it does not generate any code. Within a "leg" of a condition there must be a statement. If you have a use for NEXT SENTENCE in a simple condition prior to COBOL 85, you can use CONTINUE, which does nothing, and the compiler will generate its normal code for what to do next (CONTINUE does nothing, it just so happens that within the context of a condition, the compiler is going to generate a branch anyway when needed).
In poor-quality code that also uses full-stops/periods, I'm prepared to bet that for every 1,000 conditions there is at least on with an "missing" full-stop/period. That's already bad enough, but if there is also a NEXT SENTENCE within that construct, then the weirdness increases.
The way that NEXT SENTENCE needed to be used (when needed) means it can always be replaced by CONTINUE. So don't use NEXT SENTENCE.
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute