IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

NEXT SENTENCE control flow works.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
jaffarhussain

New User


Joined: 26 Nov 2010
Posts: 30
Location: Hyderabad

PostPosted: Fri Aug 26, 2011 11:03 pm
Reply with quote

Hi Intellects,

F25BM.
IF VA00-CF = '0'
NEXT SENTENCE
ELSE
GO TO F25BM-FN.
F2515.
MOVE '0' TO VX00-CF.
MOVE MW41-VEH-SER-NBR
TO VX00-INTRM-VIN

PERFORM F80-VX00-R THRU F80-FN.
IF IK = '0'
MOVE '1' TO VX00-CF.

How does NEXT SENTENCE flow goes::: Is it will go for PARA F2515 OR
Move to PERFORM F80-VX00-R THRU F80-FN and continue from there.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Aug 26, 2011 11:12 pm
Reply with quote

Hello,

There is a link to "IBM Manuals" at the top of the page. There are manuals for the current releases of the Compiler. Read about NEXT SENTENCE and if you find something that is not clear, post what you found and your doubt. Someone will be able to clarify.

This should be very easy to test for yourself. What happens when you run this. Adding a few DISPLAYs would also help you see what happens. . .
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Sat Aug 27, 2011 4:12 am
Reply with quote

Can someone tell me why (even "experienced") people code like this
Code:
IF VA00-CF = '0'
NEXT SENTENCE
ELSE
GO TO F25BM-FN.

instead of like this
Code:
IF VA00-CF NOT = '0'
GO TO F25BM-FN.

?
If your answer is "to drive you nuts," then I think you are right.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Aug 27, 2011 9:14 am
Reply with quote

Hi Phil,

I've worked several places that really discourage the use of NOT logic. . .

I was never able to get a good reason for this, but i suspect that someone sometime got burned by a NOT a OR b compare. . .
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Sat Aug 27, 2011 9:07 pm
Reply with quote

Well Dick, I totally disagree.

I think people should be more negative.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun Aug 28, 2011 9:21 am
Reply with quote

Well, that's a good start. . . icon_cool.gif

d
Back to top
View user's profile Send private message
jaffarhussain

New User


Joined: 26 Nov 2010
Posts: 30
Location: Hyderabad

PostPosted: Mon Aug 29, 2011 12:39 pm
Reply with quote

Hi All,

Code generated ia pacbol code.. So It's not the manually written.
Generated by pacbase tools..

So we can find lot of next sentence and Go to in the program.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Mon Aug 29, 2011 5:27 pm
Reply with quote

Thanks for the info Jaffar.

I feel much better knowing that instead of a programmer writing dumb code, they wrote a program that writes dumb code.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Aug 29, 2011 5:34 pm
Reply with quote

That's nothing, Ph.. Phil. Have you ever seen the output from a Cobol Decision Table pre-processor? And then see the people who use negative conditions for the test, along with Y and N for the route through the table. Is that two negatives make a positive?
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Mon Aug 29, 2011 5:46 pm
Reply with quote

IMO, the worst aspect of this code not the avoidance of negative logic and not even the use of GO TO, it is the use of "NEXT SENTENCE", which introduces a dependency on the period (full stop). icon_mad.gif
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Aug 29, 2011 6:01 pm
Reply with quote

Well, Don, at least it is all generated code. So, as long as the generator works... it probably hasn't had a new version for a while!

The DT processor I saw generated bus-loads of GO TOs to generated paragraph-names.

You could make the Decision Tables look nice, but the generated code was a mess. I guess it is the "easy" way to generate code.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Aug 29, 2011 8:22 pm
Reply with quote

Today I found a few programs that have
Code:
IF a OR b
    CONTINUE
ELSE
    PERFORM ...
END-IF
It is a bit less worst than NEXT SENTENCE, but I hate that too!

To make it easy with some fellow programmers, I code:
Code:
IF NOT (a OR b)
    PERFORM ...
END-IF
instead of:
Code:
IF NOT a AND NOT b
    PERFORM ...
END-IF
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Mon Aug 29, 2011 9:58 pm
Reply with quote

Well, to each his own, but in my case I find that decoding:
Code:
 IF a OR b
    CONTINUE
ELSE
    PERFORM ....
END-IF
takes a few less brain cycles than:
Code:
IF NOT (a OR b)
    PERFORM ....
END-IF
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Aug 29, 2011 10:25 pm
Reply with quote

I agree with Don,
I really dislike negativation (new word?).
and since I don't use periods,
except after the CONTINUE just before the 9999-exit. exit. at the end of every section.

but, i'd almost (read just almost) rather deal with NOT
than deal with mixed case.
I work with idiots who create a CAPS OFF situation by creating a VALUE with a lower case literal (when the lower case is not needed). sometimes I either create a copybook
or when I really feel like pissing them off, I make the literal caps
and then I code a CONVERT to LOWER-CASE in initialization. That really winds them up because I am wasting so many resources.
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Mon Aug 29, 2011 10:59 pm
Reply with quote

I have mixed feelings about mixed case. I like mixed case comments because I find them easier to read, but don't like mixed case code.

In any case, we should all be thankful that Cobol is not case sensitive.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 30, 2011 4:55 am
Reply with quote

Code:

IF VA00-CF = '0'
    NEXT SENTENCE
ELSE
    GO TO F25BM-FN.


The above example is an easy one to answer about the NEXT SENTENCE. Since the IF itself is terminated with a period/full-stop, control will continue with the start of the next sentence, which is located immediately after the period/full-stop for the IF.

Code:
IF VA00-CF = '0'
    NEXT SENTENCE
ELSE
    GO TO F25BM-FN
END-IF


This is the ugly one. The IF itself is termnated by the END-IF, but, so what? say IBM. The NEXT SENTENCE causes a hunt for the next full-stop/period, and control will pass to the first part of the sentence after that next full-stop.

I hope that no-one makes use of this particular "feature" of the "IBM Extension" that allows NEXT SENTENCE with END-IF.

On the "TO NOT, OR NOT TO NOT" debate, I admit to no preference. If the business spec says "if it is not green it has to be in the warehouse, otherwise it can be outside" then that is how I would code it. I wouldn't turn it around with a CONTINUE.

I would make it look nice, and write it as clearly as I consider possible.

I'm still thinking about that NEXT SENTENCE. It is an entirely invisible GO TO. Something which sites should happily ban from being used. If you use END-IF, don't use NEXT SENTENCE, even though the compiler will let you. It can just so easily go wrong.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 30, 2011 1:33 pm
Reply with quote

I'm becoming quite impressed (but early days yet) with my little compiler.

Code:

        IDENTIFICATION DIVISION.
        PROGRAM-ID. NEXTSNT.
        ENVIRONMENT DIVISION.
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01  W-DISPLAY-WHEN-COMPILED PIC X(8)BX(8).
        01  W-TEST-ALWAYS-NEGATIVE PIC X VALUE "N".
            88  W-TEST-POSITIVE VALUE "Y".
        PROCEDURE DIVISION.
            MOVE WHEN-COMPILED TO W-DISPLAY-WHEN-COMPILED
            DISPLAY W-DISPLAY-WHEN-COMPILED
            PERFORM A-PARA-CALLED-A
            PERFORM A-PARA-CALLED-B
            PERFORM A-PARA-CALLED-C
            STOP RUN
            .
        A-PARA-CALLED-A.
            IF NOT W-TEST-POSITIVE
                NEXT SENTENCE
            ELSE
                DISPLAY "A-DISPLAY 00 never to be done"
                GO TO A-PARA-CALLED-B
            END-IF
            DISPLAY "There is an awful lot of crucial code here"
            DISPLAY "A-DISPLAY 01 missed in error"
      *     Just for fun, I wonder if "OPT" would flag any of the code as
      *     unaccessible? Any kind soul like to let us know?
      *
            GO TO A-PARA-CALLED-B
            .
            DISPLAY "A-DISPLAY 02 it jumped to here"
            .
        A-PARA-CALLED-B.
            IF NOT W-TEST-POSITIVE
                CONTINUE
            ELSE
                DISPLAY "B-DISPLAY 00 never to be done"
            END-IF
            DISPLAY "B-DISPLAY 01 Not missed in error"
            .
            DISPLAY "B-DISPLAY 02 it didn't jump to here"
            .
        A-PARA-CALLED-C.

            IF NOT W-TEST-POSITIVE
                NEXT SENTENCE
            ELSE
                DISPLAY "C-DISPLAY 00 never to be done"
            END-IF
            .
            DISPLAY "C-DISPLAY 01 Not missed in error"
            .
            DISPLAY "C-DISPLAY 02 it didn't jump to here"
            .
   
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 30, 2011 9:26 pm
Reply with quote

Forgot to include the output from the above.

Code:
08/30/11 09.01.12
A-DISPLAY 02 it jumped to here
B-DISPLAY 01 Not missed in error
B-DISPLAY 02 it didn't jump to here
C-DISPLAY 01 Not missed in error
C-DISPLAY 02 it didn't jump to here


The IF-NEXT SENTENCE with no period/full-stop behaves very badly.
The IF-NEXT SENTENCE with a period/full-stop is equivalent to the IF-CONTINUE with no period/full-stop.

Don't mix "NEXT SENTENCE" and "END-IF" .

If you see a program which mixes them, and where there is no period/full-stop for the END-IF, you have a problem.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Using Dynamic file handler in the Fil... COBOL Programming 2
No new posts Help Control-R IBM Tools 2
No new posts Try to understand IMS control block IMS DB/DC 0
No new posts Control-M Delay All Other Mainframe Topics 0
This topic is locked: you cannot edit posts or make replies. Control-m JOB executing even when the... Compuware & Other Tools 6
Search our Forums:

Back to Top