Page 1 of 1

What's the difference between EVALUATE and EVALUATE TRUE?

Posted: Mon Dec 16, 2013 9:31 pm
by Maulik
Hi,

What's the difference between EVALUATE and EVALUATE TRUE in COBOL? I get confused about it. Please help.

Re: What's the difference between EVALUATE and EVALUATE TRUE

Posted: Mon Dec 16, 2013 11:43 pm
by Robert Sample
The difference is mostly one of style since either can be converted to the other. Example:

Code: Select all

EVALUATE WS-X
WHEN (1)
   <do something>
WHEN (2)
   <do something else>
END-EVALUATE
will execute the same as

Code: Select all

EVALUATE TRUE
WHEN (WS-X = 1) 
    <do something>
WHEN (WS-X = 2)
   <do something else>
END-EVALUATE

Re: What's the difference between EVALUATE and EVALUATE TRUE

Posted: Mon Dec 16, 2013 11:53 pm
by zprogrammer
Evaluate - Checks for value in variable and performs based on that

Eg

Code: Select all

EVALUATE WS-VAR
          WHEN '1'
               PERFORM …
          WHEN '2'
               PERFORM ...
          WHEN OTHER
               PERFORM ...
END-EVALUATE.
EVALUTE TRUE - Checks for TRUTHNESS in the logical expression and does action accordingly

Code: Select all

EVALUATE TRUE
        WHEN  A = '1'
              PERFORM
        WHEN  A = '2'
              PERFORM
        WHEN  OTHER
              PERFORM
END-EVALUATE

Hope it clarifies

Edited

Re: What's the difference between EVALUATE and EVALUATE TRUE

Posted: Wed Dec 18, 2013 2:06 pm
by Maulik
Thanks Robert and PB, with these examples - it helps me to understand this well.

Thank you,

Re: What's the difference between EVALUATE and EVALUATE TRUE

Posted: Wed Dec 18, 2013 2:08 pm
by zprogrammer
Glad that it helped :)