Menu

CONTINUE VS NEXT SENTENCE

2023-10-02
2023-10-03
  • Michael F Gleason

    I think I recall reading that NEXT SENTENCE is or will be discontinued using CONTINUE in its place. I am old enough to use NEXT SENTENCE but have been using CONTINUE as of late. This is my question. In the code
    IF WS-TALLY EQUAL ZERO
    STRING WS-CUR-DIR DELIMITED BY " "
    "\" DELIMITED BY " "
    WS-FILE1 DELIMITED BY " "
    INTO WS-NEW-FILE1
    ON OVERFLOW DISPLAY "STRING OVERFLOWED"
    DISPLAY " "
    MOVE SPACE TO WS-NEW-FILE1
    CONTINUE
    END-STRING
    MOVE WS-NEW-FILE1 TO WS-FILE1
    DISPLAY "New INPUT " TRIM(WS-FILE1)
    DISPLAY " "
    END-IF.
    Will an OVERFLOW condition skip to the END-IF? Or will it skip to the MOVE that follows the END-STRNG?

           Michael:-)
    
           Never mind.
           I forced an OVERFLOW and CONTINUE goes to the END-STRING.
           NEXT SENTENCE goes to the END-IF.
    
     

    Last edit: Michael F Gleason 2023-10-04
    • Vincent (Bryan) Coen

      On 02/10/2023 22:54, Michael F Gleason wrote:

      I think I recall reading that NEXT SENTENCE is or will be discontinued
      using CONTINUE in its place. I am old enough to use NEXT SENTENCE but
      have been using CONTINUE as of late. This is my question. In the code
      IF WS-TALLY EQUAL ZERO
      STRING WS-CUR-DIR DELIMITED BY " "
      "\" DELIMITED BY " "
      WS-FILE1 DELIMITED BY " "
      INTO WS-NEW-FILE1
      ON OVERFLOW DISPLAY "STRING OVERFLOWED"
      DISPLAY " "
      MOVE SPACE TO WS-NEW-FILE1
      CONTINUE
      END-STRING
      MOVE WS-NEW-FILE1 TO WS-FILE1
      DISPLAY "New INPUT " TRIM(WS-FILE1)
      DISPLAY " "
      END-IF.
      Will an OVERFLOW condition skip to the END-IF? Or will it skip to the
      MOVE that follows the END-STRNG?

      Assuming I am reading it correctly you want within the on overflow check
      disp 2 msgs the continue AFTER the END-STRING BUT, BUT

      If CONTINUE is a direct replacement for NEXT SENTENCE then that is NOT
      the flow  -  at least according to my reading.

      Best bet it to do similar in a test program and trace out what it
      actually does on a JIC basis having compiled the prog as -d -f
      -ftraceall etc.

      See the prog guide which states :

      The CONTINUE statement is a no-operation statement that may be coded
      anywhere an imperative
      statement (see [Imperative Statement], page 678) may be coded.

      1. The CONTINUE statement _has no effect _on the execution of the program.

      2. This statement (perhaps in combination with an appropriate comment
      or two) makes
           a convenient “place holder” — particularly in ELSE (see [IF], page
      318) or WHEN (see
      [EVALUATE], page 301) clauses where no code is currently expected
      to be needed, but
           a place for code to handle the conditions in question is to be
      reserved in case it’s ever
           needed.

      3. The optional extension of (AFTER) when used with the CONTINUE
      statement pauses execution for a specified length of time.

      The underlines are mine.

      Now for the IF and NEXT SENTENCE

      again in the PG under 7.8.22

      1. The clause NEXT SENTENCE may be substituted for either
        imperative-statement, but not
        both. If control reaches a NEXT SENTENCE clause due to the truth or
        falsehood of conditional-
        expression, control will be transferred to the first statement of the
        next sentence found in
        the program (the first statement after the next period).

      NEXT SENTENCE was needed for COBOL programs that were coded according to
      pre-1985
      standards that wish to nest one IF statement inside another. See [Use of
      VERB/END-
      VERB Constructs]
      , page 52, for an explanation of why NEXT SENTENCE was
      necessary.

      Programs coded for 1985 (and beyond) standards don’t need it, instead
      using the explicit
      scope-terminator END-IF to inform the compiler where
      imperative-statement-2 (or
      imperative-statement-1 if there is no ELSE clause coded) ends. New
      GnuCOBOL pro-
      grams should be coded to use the END-IF scope terminator for IF
      statements. See [Use of
      VERB/END-VERB Constructs]
      , page 52, for additional information.

      Now look at 2.2.7 Use of VERB/END-VERB Constructs regarding NEXT SENTENCE

      Good luck and yes I recommend a test prog to check what exactly the
      compiler does - as it does not mean the compiler has read the manual :)

       
    • Simon Sobisch

      Simon Sobisch - 2023-10-02

      if course NEXT SENTENCE will not skip to either END-STRING or END-IF - it will skip directly to after the next separator period. And currently it is directly after the END-IF, but if it is ever changed (for example because there's code added afterwards or the STRING statement is moved out to a PERFORMed procedure´, then "all of a sudden" it will skip to somewhere else.... wherever the NEXT SENTENCE starts.

       
  • Michael F Gleason

    Bryan.
    Thanks for the quick reply.
    I have done all your recommendations for reading before.
    You were so quick in replying that you did not see that I edited my post with a never mind.
    The answer to my question is to use the NEXT SENTENCE statement.

    I only wander if NEXT SENTENCE will become obsolete, as the manual seems to rant against it.

    Michael :-)

     
    • Vincent (Bryan) Coen

      On 02/10/2023 23:54, Michael F Gleason wrote:

      Bryan.
      Thanks for the quick reply.
      I have done all your recommendations for reading before.
      You were so quick in replying that you did not see that I edited my
      post with a never mind.
      The answer to my question is to use the NEXT SENTENCE statement.

      I only wander if NEXT SENTENCE will become obsolete, as the manual
      seems to rant against it.

      Michael :-)

      Personally I would never 'assume' about anything with the Cobol language
      now that the so called standard is done via a different agency as
      against CODASYL  etc that appear to just want money for a digital copy
      of their standards and a silly amount at that  - sorry bitten once and
      that was more than enough.

      The good news is that if it does get removed it is unlikely to be
      removed from any compiler any time soon - say within a 10 year period.

      By which time it might come back :)

      Stranger things have happened with IT standards over the years.- there
      again may be my memory is better than I thought :(

       
    • Simon Sobisch

      Simon Sobisch - 2023-10-02

      NEXT SENTENCE was made archaic with COBOL 85 (and it is still in). Here is what COBOL 2023 says about those elements and specific on the statement from Annex F:

      The purpose of the archaic language element designation is to discourage the use in new programs of some features that are unreliable, poor programming practice, or ill-defined -- where better programming techniques are available in standard COBOL. These elements are classified as archaic rather than obsolete because their use in existing programs might be too extensive to warrant removal in the next edition of standard COBOL.
      There is no schedule for deleting archaic elements from standard COBOL; however, this may be reevaluated for any future editions of standard COBOL.
      Archaic features are likely to cause future compiler errors. It is therefore recommended that they are avoided in new source units and replaced in existing ones. {...]

      NEXT SENTENCE phrase in the IF and SEARCH statements.
      This phrase can be confusing, especially when specified in a delimited scope statement. It is a common belief among users that control is transferred to a position after the scope delimiter rather than to a separator period that follows it somewhere. In addition, it is a common source of errors, especially for maintenance programmers who inadvertently insert a period somewhere before the actual terminating separator period. The CONTINUE statement and scope delimiters may be used to accomplish the same functionality and such constructs are clearer and less prone to error.

       
  • Mickey White

    Mickey White - 2023-10-03

    SInce I became a 'period less' programmer, I have never used Next Sentence or Continue.
    Would the following work for you? ( I did not mess with the period)... My indents are are only for example..

    IF  WS-TALLY EQUAL ZERO
        STRING WS-CUR-DIR DELIMITED BY " "
               "\" DELIMITED BY " "
               WS-FILE1 DELIMITED BY " "
               INTO WS-NEW-FILE1
            ON OVERFLOW DISPLAY "STRING OVERFLOWED"
                        DISPLAY " "
                        MOVE SPACE TO WS-NEW-FILE1
            NOT ON OVERFLOW 
                        MOVE WS-NEW-FILE1 TO WS-FILE1
                        DISPLAY "New INPUT " TRIM(WS-FILE1)
                        DISPLAY " "
        END-STRING
    END-IF.
    
     

    Last edit: Mickey White 2023-10-03
  • Michael F Gleason

    Thanks Mickey.
    I missed the NOT ON OVERFLOW when reading about STRING.
    I have been trying to code a clean sentence but your example is good/correct way to do it.

    Michael :-)

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.