What's the difference between EVALUATE and EVALUATE TRUE?

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Maulik
Registered Member
Posts: 16
Joined: Thu Dec 12, 2013 8:28 pm

What's the difference between EVALUATE and EVALUATE TRUE?

Post by Maulik »

Hi,

What's the difference between EVALUATE and EVALUATE TRUE in COBOL? I get confused about it. Please help.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1891
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

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

Post 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
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

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

Post 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
zprogrammer
Maulik
Registered Member
Posts: 16
Joined: Thu Dec 12, 2013 8:28 pm

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

Post by Maulik »

Thanks Robert and PB, with these examples - it helps me to understand this well.

Thank you,
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

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

Post by zprogrammer »

Glad that it helped :)
zprogrammer
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”