Monday 18 February 2013

Evaluate statement



Evaluate statement

Introduction:
 
When we have to decide from a multiple choice then it is very difficult to use IF-ELSE logic as it will be complicated to write in a code.
So EVALUATE clause will be very useful when we have a multiple conditions which decides the flow of program.
Suppose we have a online screen which sets the Bonus-flag of an employee and if the FLAG is set to yes then it will add the bonus amount to employee salary else it will gives you some message.
As this is COBOL I will already set the value of BONUS-Flag to yes i.e. “Y” and will show you how salary gets added by bonus amount.
Below example shows you the use of EVALUATE clause with the analyzing a field   defined in W-S section.

Program:




Procedure division:



After compilation I will get MAXCC=00. See below load module,



Now I will run my job and will show you the output.

OUTPUT:



As bonus-flag set to yes the new salary is: salary+9000=39000
Now if I am submitting the job by setting a flag =N then output will be 30,000 only.

How to use EVALUATE TRUE statement?

Suppose in above example there are multiple flag like travelling flag, insurance flag, mediclaim flag and I have to check all the flag and if all the flags are “Yes” then I have to add respective amount for each flag.

Program:





Here I have to check 2 different conditions i.e. Bonus condition and Travel condition. So I have written 2 conditions under Bonus i.e.

88 BONUS-FLAG VALUE “Y”. And
88 BONUS-FLAGF VALUE “N”.
Similarly I have written 2 conditions under Travel i.e.
88 TRAVEL-FLAG VALUE “Y”. And
88 NO-TRAVELF VALUE “N”.
 

Now look at the procedure division.




Here I have coded my logic. I set the BONUS-FLAG and NO-TRAVELF to true. Then I have checked two different conditions. So after executing this program 5000 Rs. Got added into salary. 

OUTPUT:




In this way you can use EVALUATE statements in your program.