Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NEXT SENTENCE - what and when?

Status
Not open for further replies.

Dan01

Programmer
Jun 14, 2001
439
US
What does NEXT SENTENCE do, and when might one use it? Thanks, Dan.
 
A COBOL paragraph contains one (actually zero) or more sentences. A sentence is a series of statements terminated by a period (a.k.a. full stop). A statement starts with a verb (i.e. MOVE, ADD, STOP, IF) and may contain one or more clauses.

NEXT SENTENCE is a statement that is essentially a GO TO. NEXT SENTENCE causes the transfer of control (i.e. a GO TO) to the statement following the period (full stop) that terminates the sentence containing the NEXT SENTENCE statement.
Code:
IF A = B 
   NEXT SENTENCE
ELSE
   MOVE C to D
END-IF
DISPLAY "This is NOT the NEXT SENTENCE".

DISPLAY "This IS the NEXT SENTENCE".

Tom Morrison
 
Thanks Tom, very clearly explained! Dan.
 
I misspoke slightly.

NEXT SENTENCE is not a real statement, and is only valid in the IF statement and the SEARCH statement.

I am glad you found this helpful. [wink]
Tom Morrison
 
NEXT SENTENCE has been declared "archaic" by the COBOL Standards Committee. That means we intend to declare it "obsolete" in the next standard (the one after 2002), and eliminate it in the standard after that. It is NOT structured code, and should be avoided.

Stephen J Spiro
Member, ANSI COBOL Standards Committee
 
Hi all,
Stephen is right and NEXT SENTENCE should be avoided. Reason? See this code I've posted before in a previous thread (maybe if people think it worth it, a FAQ should be created for this subject?)

Back in the days when everybody coded periods, NEXT SENTENCE would have been the same as CONTINUE (if it existed!). Nowadays, they are VERY different. Consider:
IF A = B
CONTINUE
ELSE
DISPLAY 'Hello'
END-IF
DISPLAY 'GOT HERE'
DISPLAY 'AND HERE'
.
EXIT-PARA.
EXIT.

and

IF A = B
NEXT SENTENCE
ELSE
DISPLAY 'Hello'
END-IF
DISPLAY 'GOT HERE'
DISPLAY 'AND HERE'
.
EXIT-PARA.
EXIT.

In the 1st example, if A equals B then GOT HERE and AND HERE will be displayed.
Whereas in the 2nd example, if A does equal B, it will drop thru to the next period ie GOT HERE AND HERE will not be displayed.
In legacy coding. you can expect to find a period after the END-IF, and in this case the effect of the two statements would be the same.
Basically, BE VERY CAREFUL WITH NEXT SENTENCE !!!! It can miss huge chunks of code as it will begin processing at the statement following the next period. In programs with one period at the end of the section, then statement would drop thru to the end of the section!!!

HTH
Marc
 
I wasnt aware the next standard had even been approved. Much less an implementation date set.

Periods are still in the COBOL standard last time I checked. If you do not like my post feel free to point out your opinion or my errors.
 
The Final Draft Information Standard has been forwarded to the International Standards Organization. The new Information Standard will be published this year. Typographical errors are the only changes now being made.

Periods are still in the standard. NEXT SENTENCE is on its way out.

The draft standard and an official status report are at


Stephen J Spiro
ISO COBOL Working Group
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top