RPGLE /free syntax question

5 pts.
Tags:
AS/400 administration
AS/400 backup
AS/400 development
RPGLE
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

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

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Splat
    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.
    6,835 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following