Or Not Equal To Syntax for RPG Programming

Hi Everyone,

I'd just like to confirm a line of code that I'm modifying in an RPG program...

This is what the code currently is:

 MBFTPT    IFEQ 'P'      
 MBSGNP    IFNE 'L'      
 MBSS#     CHAINLABGOOD  

Open in new window


I need to add another line for MBSGNP that if it is not equal 'O' as well.  But I'm not completely confident on the syntax of the "or not equal to part".   Can someone assist me with this.

Thanks.
LVL 1
Anthony6890Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Barry HarperConsultantCommented:
Hi,
I am not sure exactly what you need, but try a small test program to see how it works.

Here is some sample code for RPG program TEST:
C           *ENTRY    PLIST                          
C                     PARM           MBFTPT  1       
C                     PARM           MBSGNP  1       
C           MBFTPT    IFEQ 'P'                       
C           MBSGNP    IFNE 'L'                       
C           MBSGNP    IFNE 'O'                       
C           'CHAIN'   DSPLY                          
C                     END                            
C                     END                            
C                     END                            
C                     SETON                     LR   
C                     RETRN                          

Open in new window

and here are some test cases.
call test (P O)
call test (P L)
call test (Q O)
call test (Q L)
call test (X L)
call test (X X)
call test (P X)
DSPLY  CHAIN    

Hope this helps,
Barry
Anthony6890Author Commented:
Thanks Barry. I was originally going your route as well but then I came across this code on the IBM site...

ORNE 'O'

and when I went to compile it compiled correctly. we are running the program tomorrow night so I'll let you know if I had to change it to match your logic...
Barry HarperConsultantCommented:
Here is a program using the ORNE instead of IFNE.
Review the test cases below.
Note that (MBSGNP not equal 'L'  OR MBSGNP not equal 'O') will always be true regardless of the value of MBSGNP  because it can only have one value so it will always be not equal to the other.

C           *ENTRY    PLIST                        
C                     PARM           MBFTPT  1     
C                     PARM           MBSGNP  1     
C           MBFTPT    IFEQ 'P'                     
C           MBSGNP    IFNE 'L'                     
C           MBSGNP    ORNE 'O'                     
C           'CHAIN'   DSPLY                        
C                     END                          
C                     END                          
C                     SETON                     LR 
C                     RETRN                        

Open in new window


call test (P O )
DSPLY  CHAIN    
call test (P L )
DSPLY  CHAIN    
call test (Q O )
call test (Q L )
call test (X L )
call test (X X )
call test (P X )
DSPLY  CHAIN
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Gary PattersonVP Technology / Senior Consultant Commented:
This is a "Programming 101" issue, not an RPG syntax issue.  Remember how a logical OR works.  Yes, we all understand what you mean when you say verbally:

"Do this if MBSGNP is not 'L' or 'O'".

What you really mean "the value of MBSGNP is not a member of the set {'L','O'}", but people who aren't math professors don't talk like that.

But that's not a logical OR operation.  In a logical OR, both sides of the OR are evaluated first, and then the OR operation is performed between the two:

Logical OR truth table

TRUE OR TRUE = TRUE
FALSE OR TRUE = TRUE
TRUE OR FALSE = TRUE
FALSE OR FALSE = FALSE

So:

Case: MBSGNP = 'L'

MBSGNP <> 'L' = FALSE (because this is a NOT EQUAL test.  If they are not equal, result is TRUE.  If they ARE equal, it is FALSE)
MBSGNP <> 'O' = TRUE
False OR True =  TRUE, because if either side of the OR evaluates to TRUE, the expression is TRUE

Case: MBSGNP = 'L'
MBSGNP    IFNE 'L'                   Evaluates to TRUE, not equal to 'L'
MBSGNP    ORNE 'O'                Evaluates to FALSE, -NOT- not equal to 'O'
MBSS#     CHAINLABGOOD    So, CHAIN GETS EXECUTED

Case: MBSGNP = 'O'
MBSGNP    IFNE 'L'                   Evaluates to FALSE
MBSGNP    ORNE 'O'                Evaluates to TRUE
MBSS#     CHAINLABGOOD    CHAIN GETS EXECUTED

Case: MBSGNP = 'X'
MBSGNP    IFNE 'L'                   Evaluates to TRUE (X is not L)
MBSGNP    ORNE 'O'                Evaluates to TRUE (X is not O)
MBSS#     CHAINLABGOOD    CHAIN GETS EXECUTED

Only way you can get the chain to execute is if BOTH clauses evaluate to FALSE.  That's impossible, since you are testing the same variable for two different values.

I suspect that you only want to CHAIN when both conditions are true.  

MBSGNP is not' L'
AND
MGSGNP is not 'O'.  

So:

Case: MBSGNP = 'X'
MBSGNP    IFNE 'L'                   Evaluates to TRUE
MBSGNP    ANDNE 'O'             Evaluates to TRUE
MBSS#     CHAINLABGOOD    CHAIN is not executed

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anthony6890Author Commented:
Hi Gary, that makes complete sense and I don't know why I didn't catch it.  I just made the adjustment to my program.  We'll be running int tomorrow so I'll let you know if it worked correctly.

Thanks for the assistance.
Gary PattersonVP Technology / Senior Consultant Commented:
RPGIII syntax is awkward at best, and without being able to express complex logic as expressions, as in other modern languages, it makes things like this more complicated.  

Plus, I see "AND/OR" confusion when debugging code in many languages - including my own code.  Sometimes it just takes another pair of (less tired?) eyes.

By the way, in Free Form ILE RPG IV, the logic would look like this:

if MBFTPT = 'PT';
   if ((MBSGNP <> 'L') and (MBSGNP <> 'O'));
      chain MBSS# LABGOOD;  
   endif;
endif;
Theo KouwenhovenApplication ConsultantCommented:
/Free
   Select;
      When MBFTPT = 'P'                       
         If %scan(MBSGNP:'LOX') = 0;                          
            DSPLY  'CHAIN'                            
         EndIf;
      When MBFTPT = 'Q'                       
         If %scan(MBSGNP:'LO') = 0;                          
            DSPLY  'CHAIN'                            
         EndIf;
      When MBFTPT = 'X'                       
         If %scan(MBSGNP:'LX') = 0;                          
            DSPLY  'CHAIN'                            
         EndIf;
   EndSl;
/End-Free

Open in new window

Anthony6890Author Commented:
Gary, your logic worked flawlessly.  Thanks again for the assistance and the education.
Gary PattersonVP Technology / Senior Consultant Commented:
@Theo,

%SCAN function looks for the entire string, not individual characters of the string, so that code isn't going to do what Anthony wants.  I think you mean %CHECK.
Theo KouwenhovenApplication ConsultantCommented:
Gary,




I know what the %scan is doing :-)

 %scan(MBSGNP:'LOX')  returns 1,2 or 3 and 0 if it is a not Equal situation
I prefer this because I can test several NE values at the same time

If %scan(A:'YN') + %scan(B:'XYZ') + %scan(c:'123') = 0;   // = nor

If %scan(A:'YN') + %scan(B:'XYZ') + %scan(c:'123') > 0;   //= or


BTW in the question there are 2 variables MBFTPT and  MBSGNP
Gary PattersonVP Technology / Senior Consultant Commented:
Hi Theo,

Sorry, misread the direction of the scan.  I get it now.  Nice technique.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
IBM System i

From novice to tech pro — start learning today.