Blog Archive

How to make recursive program calls in RPGLE using Activation Group *NEW

If you try to call the same program somewhere in the same call stack you will get the error message saying "PROGRAM was called recursively" with message ID RNX8888. So how do we get around this issue? Well its very easy if you activation group properly. Activation group basically helps run the program in new scope. Let say your ProgramA calls ProgramB and then you want ProgramB to again call ProgramA, this will result in a recursive call error unless you run the ProgramB in a totally new activation group and then have ProgramA run in the same activation group of the caller program. Here are sample RPGLE programs that lets you do recursive calls.

Sample program A - PGMA

h option(*nodebugio) actgrp(*CALLER) dftactgrp(*no)
                                                   
d $mode           s              1                 
                                                   
c     *entry        plist                          
c                   parm                    $mode  
                                                   
c                   if        $mode = *blanks      
c                   call      'PGMB'               
c                   parm      'Y'           $mode  
c                   endif                          
                                                   
c                   eval      *inlr = *on          
c                   return                         

Sample program B - PGMB

h option(*nodebugio) actgrp(*NEW) dftactgrp(*no)
                                                  
d $mode           s              1                
                                                  
c     *entry        plist                         
c                   parm                    $mode 
                                                  
c                   call      'PGMA'              
c                   parm                    $mode 
                                                  
c                   eval      *inlr = *on         
c                   return                        

You can call the program A from the command line to TEST ...
CALL PGM(PGMA) PARM(' ')