IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Evaluate statemet in cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
bnveena

New User


Joined: 29 May 2007
Posts: 50
Location: hyderabad

PostPosted: Fri Aug 28, 2009 9:14 am
Reply with quote

Hello

can we use if statement while using evaluate statement in cobol???
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Aug 28, 2009 9:16 am
Reply with quote

Show us what you propose, and then we can answer. Your question is a bit vague.
Back to top
View user's profile Send private message
bnveena

New User


Joined: 29 May 2007
Posts: 50
Location: hyderabad

PostPosted: Fri Aug 28, 2009 9:23 am
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Aug 28, 2009 9:31 am
Reply with quote

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
View user's profile Send private message
steve6

New User


Joined: 10 Jul 2007
Posts: 7
Location: Chennai

PostPosted: Fri Aug 28, 2009 9:46 am
Reply with quote

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
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Fri Aug 28, 2009 10:25 am
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Aug 28, 2009 10:39 am
Reply with quote

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
View user's profile Send private message
bnveena

New User


Joined: 29 May 2007
Posts: 50
Location: hyderabad

PostPosted: Fri Aug 28, 2009 10:52 am
Reply with quote

Hi... I got the logic.. thnks for the suggestions

I have used evaluate and if together its running fine
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Aug 28, 2009 11:10 am
Reply with quote

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
View user's profile Send private message
bnveena

New User


Joined: 29 May 2007
Posts: 50
Location: hyderabad

PostPosted: Fri Aug 28, 2009 11:32 am
Reply with quote

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
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Fri Aug 28, 2009 11:53 am
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Aug 28, 2009 12:02 pm
Reply with quote

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
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Aug 28, 2009 12:29 pm
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Aug 28, 2009 7:18 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top