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

Evaluate statement, when-clause in conjunction with and


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

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Mon Jul 16, 2012 6:49 pm
Reply with quote

Hello gent's

Me and my mate have a littel discussion about evaluate statement.

In his opinion one could use "and" to conbine to fields in a when clause.
Example:

EVALUATE TRUE
WHEN TFLD01-OK AND TFLD02-OK PERFORM A10-EXEC-STARTUP
WHEN TFLD01-OK AND TFLD02-NO PERFORM A10-EXEC-STARTUP
WHEN TFLD01-NO AND TFLD02-NO PERFORM A10-EXEC-STARTUP
WHEN TFLD01-NO AND TFLD02-OK PERFORM A10-EXEC-STARTUP
WHEN OTHER CONTINUE
END-EVALUATE

I be really convinced that this does not work. I just tested it via XPEDITER. The first time, when both fields meet the requirement, everything runs fine. After that nothing works any more, no matter whether the rule is true or not.

But he's still disbelieving cause i could not explain in detail the rason why.

Could anyone explain the rason ???

Thanks in advance
Back to top
View user's profile Send private message
Peter cobolskolan

Active User


Joined: 06 Feb 2012
Posts: 104
Location: Sweden

PostPosted: Mon Jul 16, 2012 7:27 pm
Reply with quote

Code:
Evaluate True Also True
    WHEN TFLD01-OK Also TFLD02-OK
              PERFORM A10-EXEC-STARTUP 
    WHEN TFLD01-OK Also Any
              PERFORM A10-EXEC-STARTUP
    WHEN Any  Also TFLD02-OK
             PERFORM A10-EXEC-STARTUP
    WHEN OTHER
             CONTINUE
End-Evaluate
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Jul 16, 2012 7:32 pm
Reply with quote

Easy enough to check:
Code:
01  WS-VARS.
    05  WS-TFLD01       PIC X(02) VALUE 'OK'.
        88  TFLD01-OK             VALUE 'OK'.
        88  TFLD01-NO             VALUE 'NO'.
    05  WS-TFLD02       PIC X(02) VALUE 'OK'.
        88  TFLD02-OK             VALUE 'OK'.
        88  TFLD02-NO             VALUE 'NO'.

PROCEDURE DIVISION.
S1000-MAIN       SECTION.
    PERFORM 9999-CHECK.
    MOVE 'NO'           TO  WS-TFLD02.
    PERFORM 9999-CHECK.
    MOVE 'OK'           TO  WS-TFLD02.
    MOVE 'NO'           TO  WS-TFLD01.
    PERFORM 9999-CHECK.
    MOVE 'NO'           TO  WS-TFLD02.
    PERFORM 9999-CHECK.
    MOVE SPACES         TO  WS-TFLD01
                            WS-TFLD02.
    PERFORM 9999-CHECK.
    GOBACK.

9999-CHECK.
    EVALUATE TRUE
    WHEN TFLD01-OK AND TFLD02-OK
        DISPLAY '1 >' WS-TFLD01 '<>' WS-TFLD02 '<'
    WHEN TFLD01-OK AND TFLD02-NO
        DISPLAY '2 >' WS-TFLD01 '<>' WS-TFLD02 '<'
    WHEN TFLD01-NO AND TFLD02-NO
        DISPLAY '3 >' WS-TFLD01 '<>' WS-TFLD02 '<'
    WHEN TFLD01-NO AND TFLD02-OK
        DISPLAY '4 >' WS-TFLD01 '<>' WS-TFLD02 '<'
    WHEN OTHER
        DISPLAY '5 >' WS-TFLD01 '<>' WS-TFLD02 '<'
    END-EVALUATE.
gives output of
Code:
 1 >OK<>OK<
 2 >OK<>NO<
 4 >NO<>OK<
 3 >NO<>NO<
 5 >  <>  <
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Jul 16, 2012 7:43 pm
Reply with quote

without knowing what
TFLD01-OK
TFLD01-NO
TFLD02-OK
TFLD02-NO
represent,
can not give you an answer.

short answer though is that you can use "and" in a WHEN clause.
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 Jul 16, 2012 7:48 pm
Reply with quote

dbz got me beat. It's in the manual. A condition can be a compound, sorry, combined condition.

For the example not to be working, I'm afraid there is an error in the code, not the with the way EVALUATE works.

I hope for your sake it was only a small wager. A bottle of Red, not a Case...
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Mon Jul 16, 2012 8:08 pm
Reply with quote

Thank's guys !


Just to make shure, using the ALSO-clause is not the name of the game.

@ Peter cobolskolan: Ok, that's the way i would code that.

@Robert Sample: The thing is, is the use of combining fields in a when-clause using "and" or "or" legal or not.

In all the manuals you could not find something about the use of "and" or "or" in Evaluate-Statement.
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 Jul 16, 2012 8:17 pm
Reply with quote

...did you read mine? It is in the manual. May not be so explicit as giving examples, but it is all there. The condition can just be the same as any condition in an IF or whatever. AND, OR, whatever.

The ALSO could be used in combination with the combined conditions. Could be, but not sure I'd do it.

The ALSO segregates and matches for the EVALUATE rules. It would be, as Peter showed, possible to do the same with the ALSO ALSO.
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 Jul 16, 2012 8:26 pm
Reply with quote

Why test in Expeditor rather than just run the code?
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Mon Jul 16, 2012 8:54 pm
Reply with quote

Thanks all !!!

I'll be reformed !!!

After my last post, i tried several exampels and it worked well.
I never saw a code line using the "and" in a when-clause before.

Seams that i had been along time away from Cobol, just using Assembler for the last 10 years.

@ Dick & Bill:
Ok, the condition can just be the same as any condition in an IF or whatever. AND, OR, whatever. That makes it clear.
A condition can be a combined condition.

And yes, it was a small wager, relative small. A dinner at McDonalds now after work.

@ Phrzby Phil:
Cause i can customize fields and the programm-flow as i need without editing and compiling.

So thank's for the quick response again.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Jul 16, 2012 9:07 pm
Reply with quote

UmeySan,

to follow-up on Bill's post:

within the EVALUATE discussion under 6.2.13.2 Determining values
the 4th point discussing Expression-1/Expression-2
provides a link to 6.1.6 Conditional expressions
which speaks of
Quote:
Conditional expressions are specified in EVALUATE, IF, PERFORM, and SEARCH statements.

which further expands to 6.1.6.13 Combined conditions

Unfortunately, IBM Manuals expects one to remember the definitions of terminology.
That way the manual does not have to continually provide full explanations of repeated terminology.

I also see that by the time I managed to cobble this together,
you have accepted the points brought to the table by others.

I have decided to leave this post for the benefit of those
who attempt to learn a language by just looking at the examples.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Mon Jul 16, 2012 10:41 pm
Reply with quote

Hi Dick !

Thank's a lot for this extraordinarydetailed description.
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 To search DB2 table based on Conditio... DB2 1
No new posts JOIN STATEMENT PERFORMANCE. DFSORT/ICETOOL 12
No new posts Evaluate variable to execute a jcl step JCL & VSAM 3
No new posts Relate COBOL statements to EGL statement All Other Mainframe Topics 0
No new posts process statement for SUPREC, CMPCOLM... TSO/ISPF 4
Search our Forums:

Back to Top