Loading

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

Related Posts




blog comments powered by Disqus

There's 1 Comment So Far

Share your thoughts, leave a comment!