View previous topic :: View next topic
|
Author |
Message |
bnveena
New User
Joined: 29 May 2007 Posts: 50 Location: hyderabad
|
|
|
|
Hello
can we use if statement while using evaluate statement in cobol??? |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Show us what you propose, and then we can answer. Your question is a bit vague. |
|
Back to top |
|
|
bnveena
New User
Joined: 29 May 2007 Posts: 50 Location: hyderabad
|
|
|
|
i have 8 conditions to be checked
like if TYP-CLM= 'A' or 'B' or 'C' or 'D' till 'H'
and inside every if condition i have to check for
if WS-TOTH-UP Not = 0
so for all 8 conditions i have to check the second condition.
i want to apply evaluate condition so can u please tell me whether i can apply if condition inside evaluate?? |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
IFs can be inside EVALUATEs and EVALUATEs can be inside IFs, so yes, you can do what you want. Depending on what exactly you want to do when these conditions are met, there may be more than one way to word your statement. Can you be even more specific? |
|
Back to top |
|
|
steve6
New User
Joined: 10 Jul 2007 Posts: 7 Location: Chennai
|
|
|
|
I would suggest the following;
EVALUATE TYP-CLM ALSO WS-TOTH-UP NOT = 0
WHEN 'A' ALSO TRUE
......
WHEN 'B' ALSO TRUE
......
END-EVALUATE
_______________________________________
Stephan
Knowledge grows when shared |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
Hi Veena,
Check for the WS-TOTH-UP in the IF condition and then check for the other condition in the evaluate condition. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Given your initial post, I'd assign a condition name (88 level) to TYP-CLM, then have an IF within an IF. Unless you can be more specific about the conditions you are checking for, that's all we can suggest. |
|
Back to top |
|
|
bnveena
New User
Joined: 29 May 2007 Posts: 50 Location: hyderabad
|
|
|
|
Hi... I got the logic.. thnks for the suggestions
I have used evaluate and if together its running fine |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Can you show us the code you decided on? As I said earlier, there are probably several ways to accomplish the end result and some are easier to maintain than others. |
|
Back to top |
|
|
bnveena
New User
Joined: 29 May 2007 Posts: 50 Location: hyderabad
|
|
|
|
Code: |
EVALUATE TYP-CLM-TOT
WHEN 'A'
ADD WS-TOTAL-COUNT TO WS-TCLN-AE
IF WS-TCLN-AE NOT = ZEROES
DIVIDE WS-TCLN-AE INTO DAYS30-TOT
GIVING W-PCT-DAYS30
COMPUTE WS-PCT-DAYS30 ROUNDED = W-PCT-DAYS30 * 100
END-IF
WHEN 'B'
ADD WS-TOTAL-COUNT TO WS-TCLN-AP
if WS-TCLN-AP NOT = ZEROES
DIVIDE WS-TCLN-AP INTO DAYS30-TOT
GIVING W-PCT-DAYS30
COMPUTE WS-PCT-DAYS30 ROUNDED = W-PCT-DAYS30 * 100
end-if
.... |
this is the code i ve implemented |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
Hi Veena,
Both of the if condtion in each of the case is diff so , i dont think so that u can check for the if condtion before the evaluate you need to check inside the case statement. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Given the fact that the 8 different values of TYP-CLM-TOT deal with 8 different fields, your solution is what I would've written too, except that what happens if WS-TCLN-AE = zero? It's okay if WS-PCT-DAYS30 has been previously initialized to zero. If not, it will not have a valid value. You could eliminate the IF by replacing the DIVIDE statement by:
Code: |
DIVIDE WS-TCLN-AE INTO DAYS30-TOT GIVING W-PCT-DAYS30
ON SIZE ERROR
MOVE ZERO TO W-PCT-DAYS30
END-DIVIDE |
Also, please use BBCode for readability. See FAQ. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
I would have stored WS-TCLN-AE ..WS-TCLN-AP in an array
Code: |
Evaluate TYP-CLM-TOT
when 'A' move 1 to ws-ix
when 'B' move 2 to ws-ix
...
otherwise display 'houston we have a problem'
move 9 to ws-ix
END-EVALUATE
ADD WS-TOTAL-COUNT TO WS-TCLN (ws-ix)
IF WS-TCLN (ws-ix) NOT = ZEROES
DIVIDE WS-TCLN (ws-ix) INTO DAYS30-TOT
GIVING W-PCT-DAYS30
COMPUTE WS-PCT-DAYS30 ROUNDED = W-PCT-DAYS30 * 100 |
if you need some meaningful names for each total, you can use redefines or 88-levels on ws-IX
Code: |
01 TAB-TCLN.
03 WS-TCLN-AE PIC s9(9)v9(2) comp-3.
03 WS-TCLN-AP PIC s9(9)v9(2) comp-3.
...
03 WS-TCLN-Grbg PIC s9(9)v9(2) comp-3.
01 TAB-TCLN2 redefines TAB-TCLN.
03 WS-TCLN PIC s9(9)v9(2) comp-3 occurs 9.
01 WS-Indexes.
03 WS-IX PIC s9(4) comp.
88 WS-IX-AE VALUE 1.
88 WS-IX-AP VALUE 2.
...
88 WS-IX-grbg VALUE 9. |
|
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
veena,
As you can see, there are usually many variations that will yield the correct result. Try to pick one that is flexible enough for future changes and is easily understood by the next person who maintains the code. Because of CPU speeds these days, worry less about performance of an individual statement (there are exceptions of course) and more about maintainability. |
|
Back to top |
|
|
|