Unfortunately, RPG does not support recursivity nor can we call a program that's already in the program stack. But there are cases when this would be greatly appreciated. So I here propose a trick, in the form of a small simple program, that lets us do just that. It consist in creating a duplicate of the program we intend to call "recursivilly" in library QTEMP, under another name. The code for that program UTRCPGM follows. I also provide an example: traditional case for recursivity, the calculation of the factorial of a given number, in the program UTRKFACT. Program TESTRFACT and Display File TESTDFACT provide the user interface.


To review this code, click here.

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Ask your programming questions--or help out your peers by answering them--in our live discussion forums.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.

Search400's targeted search engine: Get relevant information on RPG.

This was first published in August 2001

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.