READ and don't proces the record in COBOL.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Previous topicNext topic

Topic Author
Sonu Sood
New Member
Posts: 1
Joined: Tue May 24, 2016 9:37 am

READ and don't proces the record in COBOL.

Post by Sonu Sood » Sun Nov 13, 2016 7:39 pm

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?



User avatar

Akatsukami
Global Moderator
Global Moderator
Posts: 117
Joined: Tue Oct 20, 2015 3:20 am
Location: Bloomington, IL

Re: READ and don't proces the record in COBOL.

Post by Akatsukami » Sun Nov 13, 2016 8:00 pm

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

User avatar

Robert Sample
Global Moderator
Global Moderator
Posts: 1328
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
Zodiac: Virgo

Re: READ and don't proces the record in COBOL.

Post by Robert Sample » Sun Nov 13, 2016 8:21 pm

Should I use continue or NEXT-SETENCE?
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.

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.




William Collins
Global Moderator
Global Moderator
Posts: 499
Joined: Sun Aug 25, 2013 7:24 pm

Re: READ and don't proces the record in COBOL.

Post by William Collins » Mon Nov 14, 2016 1:03 pm

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.



Previous topicNext topic

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”