CASE WHEN statement in Easytrieve

Just like “EVALUATE WHEN” in Cobol, “Switch Case” in C, Easytrieve has got its equivalent “CASE WHEN” statement.

And, the when statement is not only capable of validating one particular value, it can also validate a range of values.

See the below sample Easytrieve program, which is self explanatory.

 CASE WS-NUM
  WHEN 1 
     DISPLAY 'ONE'
  WHEN 2
     DISPLAY 'TWO'
  WHEN 3 THRU 99
     DISPLAY '3 TO 99'
  OTHERWISE
     DISPLAY 'NOT IN RANGE'
 END-CASE

A complete program will look like,

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 FILE FILE1
 WS-DAY  W 2 N
 JOB INPUT NULL
 WS-MONTH = 5
 CASE WS-MONTH
  WHEN 1 
     DISPLAY 'SUNDAY'
  WHEN 2
     DISPLAY 'MONDAY'
  WHEN 3
     DISPLAY 'TUESDAY'
  WHEN 4
     DISPLAY 'WEDNESDAY'
  WHEN 5
     DISPLAY 'THURSDAY'
  WHEN 6
     DISPLAY 'FRIDAY'
  WHEN 7
     DISPLAY 'SATURDAY'
  OTHERWISE
     DISPLAY 'INVALID'
 END-CASE
 STOP
Advertisement

One thought on “CASE WHEN statement in Easytrieve”

  1. Do we have equivalent of EVALUATE TRUE?
    I have multiple varied conditions to be checked. Picking the examples from above something like follows:
    EVALUATE TRUE
    when iteration-nbr = 1
    read record read into file-rec1
    when ws-month=Jan and iteration=3
    do process1
    when ws-month = dec
    do-process-end

    END-EVALUATE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.