View previous topic :: View next topic
|
Author |
Message |
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
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 |
|
|
Peter cobolskolan
Active User
Joined: 06 Feb 2012 Posts: 104 Location: Sweden
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
...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 |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
Why test in Expeditor rather than just run the code? |
|
Back to top |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
Hi Dick !
Thank's a lot for this extraordinarydetailed description. |
|
Back to top |
|
|
|