Page 1 of 1

READ and don't proces the record in COBOL.

Posted: Sun Nov 13, 2016 7:39 pm
by Sonu Sood
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?

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

Posted: Sun Nov 13, 2016 8:00 pm
by Akatsukami
Of course. The pseudo-code is:

Code: Select all

read record

do while (¬end of file)
    if (valid-record)
        then process
 
    read record
end

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

Posted: Sun Nov 13, 2016 8:21 pm
by Robert Sample
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.

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

Posted: Mon Nov 14, 2016 1:03 pm
by William Collins
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.