Anthony
asked on
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:
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.
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
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.
ASKER
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...
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...
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.
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
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
Thanks for the assistance.
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;
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;
/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
ASKER
Gary, your logic worked flawlessly. Thanks again for the assistance and the education.
@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.
%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.
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
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
Hi Theo,
Sorry, misread the direction of the scan. I get it now. Nice technique.
Sorry, misread the direction of the scan. I get it now. Nice technique.
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:
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