To add to this discussion of boolean expressions in RPG... I just wanted to point out that you can use these expressions as parameters to subprocedures.


For example, maybe I want to write a routine that will log a message to the job log ONLY IF a particular condition is true. I could do the following:

     H DFTACTGRP(*NO)

     D IfLog           PR
     D   Condition                    1N   const
     D   Message                    100A   varying const

     D x               s             10I 0 inz(-1)
      /free

            IfLog(X<=0: 'ERROR! X must be 1 or more!');

            *inlr = *on;
      /end-free

      *++++++++++++++++++++++++++++++++++++++++++++++++++++
      * Write a diagnostic message to the job log if
      * a condition is true.
      *++++++++++++++++++++++++++++++++++++++++++++++++++++
     P IfLog           B
     D IfLog           PI
     D   Condition                    1N   const
     D   Message                    100A   varying const

     D QMHSNDPM        PR                  ExtPgm('QMHSNDPM')
     D   MessageID                    7A   Const
     D   QualMsgF                    20A   Const
     D   MsgData                  32767A   Const options(*varsize)
     D   MsgDtaLen                   10I 0 Const
     D   MsgType                     10A   Const
     D   CallStkEnt                  10A   Const
     D   CallStkCnt                  10I 0 Const
     D   MessageKey                   4A
     D   ErrorCode                32767A   options(*varsize)

     D NullError       S              8A   inz(*ALLx'00')
     D MsgKey          s              4A

      /free

          if (Condition);
               QMHSNDPM( 'CPF9897'
                       : 'QCPFMSG   *LIBL'
                       : Message
                       : %Len(Message)
                       : '*DIAG'
                       : '*'
                       : 1
                       : MsgKey
                       : NullError        );
          endif;
      /end-free
     P                 E


Since the RPG expression parser distills all of the boolean conditions down to a single true/false (indicator) condition, you could use this same subprocedure with any condition that you'd normally use on a IF statement.


      IfLog( %found(ITMMAST): 'ITMMAST record was found');

      IfLog( %date(myDate)>=StartDate and %date(myDate)<=EndDate
           : 'Date falls into date range');

and so on... If you change the QMHSNDPM to send an escape message, it works just like an assert() (like you'd use in C). I posted an example of this to the mailing list awhile back... search for "assert" in the archives if you're interested.


This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.