MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

IF Then Else Assistance required

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
hogandeveloper
Beginner


Joined: 05 Aug 2008
Posts: 11
Topics: 10

PostPosted: Mon Sep 28, 2009 2:44 am    Post subject: IF Then Else Assistance required Reply with quote

Hi All,
I have an unusual problem. The eventhough the FIELD-A is spaces it still goes to the IF part and not to the ELSE part. Please help me to sort this out.
Code:

IF FIELD-A NOT = SPACES OR LOW-VALUES           
    SET ALPH-NAME(12)      TO TRUE                   
    MOVE 'ACCOUNT TYPE:'   TO ENT-ALPHA(12)   
    SET ALPH-NAME(13)      TO TRUE                   
    MOVE 'SAVINGS POCKET'  TO ENT-ALPHA(13)
    SET ALPH-NAME(14)      TO TRUE                   
    MOVE 'ACCOUNT NUMBER:' TO ENT-ALPHA(14)   
    SET STAT-DATA(15)      TO TRUE                   
    MOVE FIELD-A           TO ENT-ALPHA(15)   
ELSE                                                     
    SET  ALPH-NAME(12)   TO TRUE                   
    MOVE SPACES          TO ENT-ALPHA(12)   
    SET ALPH-NAME(13)    TO TRUE                   
    MOVE SPACES          TO ENT-ALPHA(13)   
    SET ALPH-NAME(14)    TO TRUE                   
    MOVE SPACES          TO ENT-ALPHA(14)   
    SET ALPH-NAME(15)    TO TRUE                 
    MOVE SPACES          TO ENT-ALPHA(15) 
END-IF.                                                 

Thanks,
HD
Back to top
View user's profile Send private message
Anuj Dhawan
Intermediate


Joined: 19 Jul 2007
Posts: 298
Topics: 7
Location: Mumbai,India

PostPosted: Mon Sep 28, 2009 4:07 am    Post subject: Re: assistance required Reply with quote

Please check the contentes of FIELD-A with HEX ON, you will come to know what's there.

Please learn to use BBcode that makes code rather readable.
_________________
Regards,
Anuj
Back to top
View user's profile Send private message
acevedo
Beginner


Joined: 03 Dec 2002
Posts: 127
Topics: 0
Location: Europe

PostPosted: Mon Sep 28, 2009 6:41 am    Post subject: Re: assistance required Reply with quote

If I'm not wrong:

Code:
IF FIELD-A NOT = SPACES OR LOW-VALUES 

is the same as

Code:
IF FIELD-A NOT = SPACES OR field-a not = LOW-VALUES 


so if FIELD-A = SPACES then meets the IF condition.

maybe, just maybe you ment:
Code:
IF FIELD-A NOT = SPACES AND LOW-VALUES 


HTH
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Mon Sep 28, 2009 8:25 am    Post subject: Reply with quote

acevedo,

very nicely posed.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
Anuj Dhawan
Intermediate


Joined: 19 Jul 2007
Posts: 298
Topics: 7
Location: Mumbai,India

PostPosted: Mon Sep 28, 2009 11:37 am    Post subject: Reply with quote

acevedo is correct and just to extend a bit on what he has said. Actually, the code:
Code:
 IF FIELD-A NOT = SPACES OR LOW-VALUES
will NOT work. While you can use "NOT =" with AND, you can not have it work with OR.

Your code:
Code:
IF FIELD-A NOT = SPACES OR LOW-VALUES
will expand to
Code:
IF FIELD-A NOT = SPACES OR
   FIELD-A NOT = LOW-VALUES
as acevedo has said and it will ALWAYS set TRUE with any value of FIELD-A. Reason: FIELD-A = SPACES is NOT = LOW-VALUES result is true on first condition and same for other condition etc...
_________________
Regards,
Anuj
Back to top
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Mon Sep 28, 2009 3:17 pm    Post subject: Reply with quote

A good example of how using NOT can get you in trouble. Alternative methods of coding this:
Code:
IF FIELD-A = SPACE OR LOW-VALUE
    <DO ONE THING>
ELSE
    <DO SOMETHING ELSE>
END-IF

or
Code:
EVALUATE FIELD-A
    WHEN SPACE
    WHEN LOW-VALUE
        do something
    WHEN OTHER
        do another thing
END-EVALUATE

_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group