5 pts.
 RPGLE /free syntax question
I am modifing some code I found, and trying to add multiple 'or' statement. I have tried several different way to get the code to compile, but I always get errors. Can someone please tell me the proper syntax for the following statement below??

if Jobbstatus = 'MSGW' and SubShort = 'QBATCH' or +

  Jobbstatus = 'MSGW' and SubShort = 'QPGMR' or +

  Jobbstatus = 'MSGW' and SubShort = 'QPGMR1';

What I'm trying to test is, if Jobbstatus is MSGW, and if SubShort is any of the following subsystems, QBATCH, QPGMR, QPGMR1.

Also, how about if Jobbstatus was either 'MSGW' or 'RUN'?  I have a second if statement, but it would be nice if I could test both MSGW and RUN along with the different subsystems as well.  That would eliminate the need for 2 if statements.

 

if Jobbstatus = 'MSGW'  or 'RUN' and SubShort = 'QBATCH' or +

                                                     SubShort = 'QPGMR' or +

                                                     SubShort = 'QPGMR1';

Thanks.



Software/Hardware used:
AS400 - 570
ASKED: May 17, 2010  1:41 PM
UPDATED: May 19, 2010  2:53 PM

Answer Wiki:
You have two general alternatives for this kind of compound IF-test. You could use nested IFs:<pre> if Jobbstatus = 'MSGW' or Jobbstatus = 'RUN' ; if SubShort = 'QBATCH' or SubShort = 'QPGMR' or SubShort = 'QPGMR1';</pre> Notice that I removed the "+" continuation character from the ends of the lines. They are not used in /FREE format because the semi-colon (";") end-of-statement character determines how many lines are included. Or you could combine them all in a single IF-test:"<pre> if ( Jobbstatus = 'MSGW' or Jobbstatus = 'RUN' ) and ( SubShort = 'QBATCH' or SubShort = 'QPGMR' or SubShort = 'QPGMR1';</pre> Again, continuation characters aren't used. You can continue as much as you need. Use parentheses to group sets of conditions together. Tom
Last Wiki Answer Submitted:  May 17, 2010  7:11 pm  by  TomLiotta   107,905 pts.
All Answer Wiki Contributors:  TomLiotta   107,905 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Parentheses are your friend:

If (Jobbstatus = 'MSGW' and SubShort = 'QBATCH') or
   (Jobbstatus = 'MSGW' and SubShort = 'QPGMR')  or
   (Jobbstatus = 'MSGW' and SubShort = 'QPGMR1');    

For the more complex statement, either of Tom’s examples would work – well, with the addition of a parenthesis at the end of the second example ;-) .

I would suggest you keep in mind those that will come after you: readability is oft times more important than loading everything into a single statement.

 5,670 pts.