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

Better performance switch OR group var in IF


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

New User


Joined: 04 Mar 2008
Posts: 6
Location: Chennai

PostPosted: Tue Mar 11, 2008 7:40 pm
Reply with quote

Hi,

Can anyone help me out of this..
I ran a strobe request and it is pointing to a section of code where
i have used a IF statement with 2 else and a lot of OR and AND conditinos
i.e.
if var1 = 1 or 3 and var2 = 3 or 6
else if condition with many or/and

My question is if use a switch instead or the var1 or variable will i get a performance boost?
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 97
Location: India

PostPosted: Tue Mar 11, 2008 7:57 pm
Reply with quote

Hi Sutirtha,
It is advisable that you use switch statement instead of nested if. Since, some compilers will not support more than 4 or 5 nested level. Also, the code looks simple and understandable easily while using switch statement.
In the switch you can use and/ or as your requirement.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Mar 11, 2008 8:38 pm
Reply with quote

I have been around IT for a day or two, but this one has me. What language has a SWITCH command? what is a SWITCH command?
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue Mar 11, 2008 8:44 pm
Reply with quote

switch is a C ( maybe JAVA ) construct
Code:
switch (variable) {
    case expression1:
        ..... ;
    break;
    case expression2:
        ..... ;
    break;
    case expression3:
        ..... ;
    break;
    default:
        ...... ;   
}
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Mar 11, 2008 9:05 pm
Reply with quote

How about a COBOL EVALUATE?

It's easy to maintain and even easier to comprehend.

Many times, maintenance causes well-intentioned "IF-THEN-ELSE" constructs to wind up looking looking like a Chinese menu (no offence implied), causing programmers to apply some "creative" code.

As most of us have been around the block a few times, I myself have had to resort to generating the ASSEMBLER expansion of a COBOL program, because the logic has become so convoluted, it's the only way it can be followed.

When you have an "IF" ending in 6 right-parenthesis, embedded with OR's and AND's, as well as other nested "IF"'s and "ELSE"s, it's time for review and apply a different approach.

Just my .02 cents....

Regards,

Bill
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Tue Mar 11, 2008 9:22 pm
Reply with quote

As far as I know MAINFRAME cobol doesn't have a switch!
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Tue Mar 11, 2008 10:29 pm
Reply with quote

Hi,

EVALUATE should work for Your scenario..try the below feacture of EVALUATE
Code:
EVALUATE TRUE ALSO TRUE


Check the manuals please, it should be doable.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Mar 11, 2008 10:29 pm
Reply with quote

Hello,

On many of the systems i've supported the "switch" is just a field that can be turned "on" or "off" and then tested in the code. Many have 88 levels to use a name rather than a value (i.e. "if switch-on. . ." rather than "if swiotch-field = 1).
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 97
Location: India

PostPosted: Wed Mar 12, 2008 2:48 pm
Reply with quote

Hi All,
Sorry for the confusion... I knew in cobol there is no switch statement like c/c++/java.... In my reply I mentioned Evaluate statement as switch. Since, he had mentioned as switch and I simply followed it icon_sad.gif .
Back to top
View user's profile Send private message
sutirtha mukherjee

New User


Joined: 04 Mar 2008
Posts: 6
Location: Chennai

PostPosted: Wed Mar 12, 2008 5:39 pm
Reply with quote

sorry all ,
i created the confusion ...

actually i intended to ask this:

var pic s9(4) comp. (mine is a comp variable)

"if var = 2
imperative statement"
would perform better

OR

var value 1
88 var-flag pic x value 1
"if var-flag
imperative statement"

would perform better ?


(NOTE:i am using only the variable for comparision only no arithmetic operations)
Back to top
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Wed Mar 12, 2008 5:49 pm
Reply with quote

I prefer second one.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Wed Mar 12, 2008 5:59 pm
Reply with quote

Bill -

Your opinions are worth much more than 2/100 of a cent to me.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Mar 13, 2008 12:27 am
Reply with quote

Hello,

Quote:
would perform better ?
It would be difficult to measure the difference as they are both "the same".

If you look at the generated assembler, you will be able to see the actual code.

Quote:
Your opinions are worth much more than 2/100 of a cent to me
Me too - at least 19/100 of a cent. . . icon_smile.gif
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 exploiting Z16 performance PL/I & Assembler 2
No new posts Db2 SQL - how to switch among differe... DB2 18
No new posts Compare latest 2 rows of a table usin... DB2 1
No new posts JOIN STATEMENT PERFORMANCE. DFSORT/ICETOOL 12
No new posts Problem with IFTHEN=(WHEN=GROUP,BEGIN... DFSORT/ICETOOL 5
Search our Forums:

Back to Top