Converting the FREE operation code

To replace the function of the FREE operation, you must first determine why the FREE operation was being used.

  • If the FREE operation was being used to ensure that the program would be initialized on the next call to the program, change the called program so that it may be called with a special parameter (or no parameter), indicating that it should simply set on LR and return. Then, instead of coding the FREE operation, call the program with the special "free" parameter.
 * RPG III coding
C                     CALL 'MYPGM'
C                     PARM             P1
...
C                     FREE 'MYPGM'
...
C                     CALL 'MYPGM'
C                     PARM             P1

* Replacement RPG IV coding for the "reresolve" function of FREE 

C                   call      MYPGM_var
C                   parm                    p1
 ...
 * Cause MYPGM to initialize on the next call
C                   call      MYPGM_VAR
 ...
C                   call      MYPGM_var
C                   parm                    p1

* Modified version of MYPGM.  It ends itself when it is called with no parameters.
D                SDS
D PARMS             *PARMS
C     *ENTRY        PLIST
C                   PARM                    NAME             10
c     PARMS         IFEQ      0
C                   SETON                                        LR
C                   RETURN
C                   ENDIF
 ...
 * RPG III coding
C                     CALL 'MYPGM'
C                     PARM             P1
...
C                     FREE 'MYPGM'
...
C                     CALL 'MYPGM'
C                     PARM             P1

* Replacement RPG IV coding for the "reresolve" function of FREE 

D MYPGM_var       s             21a   INZ('MYPGM')
C                   call      MYPGM_var
C                   parm                    p1
 ...
 * Cause a reresolve to MYPGM for the next call
C                   eval      MYPGM_var = 'MYLIB/FREEPGM'
C                   call      MYPGM_VAR
C                   reset                   MYPGM_var
 ...
C                   call      MYPGM_var
C                   parm                    p1

To replace the function of the DEBUG operation, use an interactive debugger. For information on program debugging see Debugging Programs.