Tip

Using %REPLACE biff in RPG

Stop concatenating strings together just to build command strings. Now you can put your command string in your program as one constant string and use the %REPLACE to run the command with different parameters, similar to what PDM does with option commands.

At (A), the command string is contained in one constant. Each parameter I want to replace with different values at each call all start with the "&" character and a two-character string meant to represent something to myself.

At (B) I use the %REPLACE biff to replace my "PDM option parameters" with actual values from file OUTQP. The %REPLACE biff can replace a varying number of characters with a varying number of characters. That means you do not have to replace three characters with three characters. The fourth parameter ("source length to replace") tells the system to replace only that many characters of the original string adding any remaining replacement characters directly afterward. The effect is the command is expanded to accommodate the replaced parameters.

When all parameters are replaced, I execute the command at (C).

Code:

* Input file build from TAATOOL, CVTOUTQ
     FOUTQP     IF   E             DISK

      * Non-selected splf control TO outq
     DDTAARA1          DS           150    DTAARA(DTAARA1 )
     D OUTQ1                         10

      * Default printer outq
     DDTAARA2          DS           128    DTAARA(DTAARA2)
     D OUTQ2                         10

      ** OS/400 Command processor.
     DQcmdExc          PR                  ExtPgm('QCMDEXC')
     D CmdString                   3000    OPTIONS(*VARSIZE) CONST
     D CmdLength                     15P 5 CONST
     D CmdOpt                         3    OPTIONS(*NOPASS)                     4 DBCS setups

      * Stand-alone fields ****************
     D cmdexc          S            256
     D cmdlen          S             15  0

      * Constants definitions  ************
      *******( A )*******
     D ChgSplfa        C                   'CHGSPLFA FILE(&SF) JOB(&J#/&JU/&JN)-
     D                                      SPLNBR(&SN) OUTQ(&OQ)'
     D DltSplf         C                   'DLTSPLF FILE(&SF) JOB(&J#/&JU/&JN)-
     D                                      SPLNBR(&SN)'

     C                   IN        DTAARA1
     C                   IN        DTAARA2

     C                   READ      OUTQP
     C                   DOW       NOT %eof(OUTQP)
     C                   EVAL      CmdExc = ChgSplfa
      *******( B )*******
      * Replace &SF with SPFILE (Splf name)
     C                   EVAL      CmdExc = %Replace(%trim(SPFILE)       :
     C                                               CmdExc              :
     C                                               %scan('&SF': CmdExc):
     C                                               3)
      * Replace &JN with SPJNAM (Splf job name)
     C                   EVAL      CmdExc = %Replace(%trim(SPJNAM)       :
     C                                               CmdExc              :
     C                                               %scan('&JN': CmdExc):
     C                                               3)
      * Replace &JU with SPUSER (Splf job user)
     C                   EVAL      CmdExc = %Replace(%trim(SPUSER)       :
     C                                               CmdExc              :
     C                                               %scan('&JU': CmdExc):
     C                                               3)
      * Replace &J# with SPJNBR (Splf job number)
     C                   EVAL      CmdExc = %Replace(%trim(SPJNBR)       :
     C                                               CmdExc              :
     C                                               %scan('&J#': CmdExc):
     C                                               3)
      * Replace &SN with SPFNBR (Splf number)
     C                   EVAL      CmdExc = %Replace(%trim(SPFNBR)       :
     C                                               CmdExc              :
     C                                               %scan('&SN': CmdExc):
     C                                               3)
      * Replace &OQ with RETLQ
     C                   IF        Outq2 = 'Y'
     C                   EVAL      CmdExc = %Replace(%trim(OUTQ2)        :
     C                                               CmdExc              :
     C                                               %scan('&OQ': CmdExc):
     C                                               3)
     C                   ELSE
      *  -OR - Replace &OQ with TOOUTQ
     C                   EVAL      CmdExc = %Replace(%trim(OUTQ1 )       :
     C                                               CmdExc              :
     C                                               %scan('&OQ': CmdExc):
     C                                               3)

     C                   ENDIF

      *******( C )*******
     C                   EVAL      CmdLen = %len(CmdExc)
     C                   CALLP     Qcmdexc(CmdExc: CmdlEN)
      * Insert your code to do whatever with OUTQ entry.
      *                 /
      *                  :
      *                  :
      *                  :
      *                 /
      * Insert your code to do whatever with OUTQ entry.

     C                   READ      OUTQP
     C                   ENDDO

     C                   EVAL      *INLR = *ON

This was first published in December 2001

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

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
Sort by: OldestNewest

Forgot Password?

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

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.