Choosing between parameter passing styles

If you are calling an existing program or procedure, you must pass the parameters in the way the procedure expects them, either by reference or by value. If the parameter must be passed by reference, and it will not be modified by the called procedure program or procedure, pass it by read-only reference (using the CONST keyword). When you are free to choose between passing by value or by read-only reference, pass by read-only reference for large parameters. Use the following general guideline:

Figure 65. Prototype for Procedure DO_CALC with VALUE Parameters
      *-------------------------------------------------------------
      *  The procedure returns a value of a 10-digit integer value.
      *  The 3 parameters are all 5-digit integers passed by value.
      *-------------------------------------------------------------
     D MyFunc          PR            10I 0 EXTPROC('DO_CALC')
     D                                5I 0 VALUE
     D                                5I 0 VALUE
     D                                5I 0 VALUE
     ....
Figure 66. Procedure Interface Definition for DO_CALC Procedure
     P DO_CALC         B                   EXPORT
      *-------------------------------------------------------------
      * This procedure performs a function on the 3 numeric values
      * passed to it as value parameters.  It also returns a value.
      *-------------------------------------------------------------
     D DO_CALC         PI            10I 0
     D    Term1                       5I 0 VALUE
     D    Term2                       5I 0 VALUE
     D    Term3                       5I 0 VALUE
     D Result          S             10I 0
     C                   EVAL      Result = Term1 ** 2 * 17
     C                                    + Term2      * 7
     C                                    + Term3
     C                   RETURN    Result * 45 + 23
     P                 E
Figure 67. Prototype for ILE CEE API CEETSTA with CONST Parameter
      *------------------------------------------------------------------
      * CEETSTA (Test for omitted argument) -- ILE CEE API
      *     1. Presence flag                       Output   Binary(4)
      *     2. Argument number                     Input    Binary(4)
      *------------------------------------------------------------------
     D CEETSTA         PR                    EXTPROC('CEETSTA')
     D   Present                     10I 0
     D   ArgNum                      10I 0   CONST
     D   Feedback                    12A     OPTIONS(*OMIT)
     ...
     D HaveParm        S             10I 0
     ...
     C                     CALLP    CEETSTA(HaveParm : 3 : *OMIT)
     C                     IF       HaveParm = 1
      *        do something with third parameter
     C                     ENDIF

The second parameter passed to CEETSTA can be any numeric field, a literal, a built-in function, or expression.



[ Top of Page | Previous Page | Next Page | Contents | Index ]