Wednesday, September 28, 2016

Quickly retrieving the source for a program

retrieve source of rpg program

Once in a while I find a program in one the libraries I am responsible for that is missing the source it was compiled from. Looking at the object description I can see that the program was compiled from a source member in the right source file, but the member is not there. Other times a program was compiled from a member in a source file or library that no longer exists, but I can find a member of that name elsewhere, and I do not know if this source is the same that was used to create the program. Both scenarios should not happen in a perfect world, but most of us work in places that are not perfect.

I know there are programs various people have written to retrieve the source from a program, but I do not have time to do that today. I need to get to the source quickly to find out what this program is suppose to do.

If the object is either a CLP or CLLE and it was compiled with the "Allow RTVCLSRC" parameter, ALWRTVSRC, set to *YES I can use the Retrieve CL Source command, RTVCLSRC, to recover the source. I go into this in detail in RTVCLSRC makes a comeback.

If it is RPG or RPGLE then there is no IBM command to retrieve the source code. I need to be a bit creative in my thinking.

When I compile a RPG/RPGLE object I have choices in the debug views and these are included in the compiled object. I wrote about the debug views and the advantages of them for RPGLE in Debug views finding your favorite.

With old fashioned RPG/400 (RPG III) I have fewer options. If the program was compiled with the "Source listing options" parameter, OPTION, of *SRCDBG or *LSTDBG then the source was included in the program object.


As neither of these are the parameters default there is a good chance that if the person who performed the compile used PDM and they just put a "14" next to the member and pressed Enter the source will be missing from the object.

The other debugger that many of us have used with old RPG source is STRISDB. This will display the source for the program if the source member is where it was when the program was compiled. If the member has been deleted, renamed, or moved STRISDB cannot display the source code.

I am going to say that today I am lucky, and the program I need to the retrieve the source for was compiled with the appropriate debug values. I can just start debug using the "Start debug" command, STRDBG, for both RPGLE and RPG:



And the source code is displayed:

                             Display Module Source

 Program:   TESTRPG        Library:   MYLIB          Module:   TESTRPG
      1  **free
      2  dcl-s Date1 char(6) ;
      3  dcl-s Date2 char(6) ;
      4  dcl-s Difference packed(10) ;
      6  Date1 = '122516' ;
      7  Date2 = '022195' ;
      9  Difference = %diff(%date(Date1:*mdy0):%date(Date2:*mdy0):*d) ;
     11  *inlr = *on ;

 Debug . . .                                                                  
 F3=End program   F6=Add/Clear breakpoint   F10=Step   F11=Display variable
 F12=Resume       F17=Watch variable   F18=Work with watch   F24=More keys

In this example it would be easy to copy-n-paste the source into a source member. But if the program was one of those thousand line monsters it would take a long time to copy a screen of the source at a time. Fortunately there is an easier way to do a larger program than the one shown above.

If you do not have RDi, Operations Navigator has a debug feature within the "Run SQL Scripts" function. On your computer Operation Navigator could be known as iSeries Navigator or System i Navigator. When I open the IBM i Access for Windows folder from the start menu I find Operation Navigator within it. On my PC it is called System i Navigator.

Click on image to open a larger version in another browser window

When the Navigator opens in the left panel is a list of all IBM i I can connect to. I find the one with the program on it and click the plus ( + ) next to it. Then I find the "Databases" icon and click on the plus next to it. When that opens immediately under it is the database I want, I right click on it and select "Run SQL scripts", see below.

Click on image to open a larger version in another browser window

On the "Run SQL Scripts" window I select "Run", and then "Debugger" in the drop down.

Click on image to open a larger version in another browser window

When the "Start debugger" window opens I just need to enter the program and the library it is in, and click the "OK" button.

Click on image to open a larger version in another browser window

I can go to the code section part of the "System Debugger" window, select all the code ( Ctrl-a ), copy it ( Ctrl-c), then paste it into Notepad ( Ctrl-v ).

Click on image to open a larger version in another browser window

I save the contents of Notepad as a text file. I can now FTP that to the IBM i and place it in the appropriate source file. I would also compile the source to make ensure the next time I look at that object it refers to the right source member.

As you can imagine this has saved me on many occasions where the source has gone missing. I strongly suggest that you all compile your programs and modules with an appropriate debug view. You never know when you have to hunt for missing source, and be grateful that you did.


This article was written for IBM i 7.3, and should work for earlier releases too.


  1. Wow, that's a beauty. Thanks for sharing.

  2. In more than one time I approached IBM looking for this. Thanks a lot!

  3. I wish I had thought of that. My motto is "There is always another way...."

  4. I think it was 2004 when I encountered a 10,000 line BPICS monster. I wrote a VB based CA/400 macro. I never needed since then, so I do not remember anything except that it was a pretty painful program to write.

    Thanks for the tip

  5. I tried to get the source but It ask me about the member of the object. And that's the point I don't have it. I have only the object. :(

    1. Please be more specific: Where are you seeing this?

  6. in the compiler option:
    I get an error for "*SRCDBG" with valid options as:
    (any of these appropriate to the functionality you refer to?)

    1. Those are the OPTIONS for compiling RPGLE. You do not specify the debug view in that parameter, you use the DBGVIEW instead see here for more details.

  7. AnonymousSeptember 28, 2016 at 2:09 PM

    I tried to get the source but It ask me about the member of the object. And that's the point I don't have it. I have only the object. :(

    Simon HutchinsonSeptember 28, 2016 at 3:10 PM

    Please be more specific: Where are you seeing this?

    I am also having the same issue. We are trying to recover source of RPG program which wasn't compiled to include source. So there is no source view.
    In iseries navigator, I am getting error
    Source file not available for ....
    Is the source file located on this client? Yes/No.

    Thank you

    1. If it is asking you that question then the object was not compiled with the DBGVIEW you need to see and retrieve the source code.

  8. The OPTION (*SRCDBG) option is for the old STRISDB command (I never used it) but a lot of people, for some reason, think it is the DBGVIEW parameter. It is not. There is a way to retrieve the source but since STRISDB is for RPGIII programs, it does not work for RPGIV or CLLE. Perhaps it works for CLP, but I haven't seen it in 20+ years or so now.

  9. Hi Simon what if I have an object without this debug options in the compilation? There's a way to solve it? Hope there's a solution, I got a SYNON ilerpg objects and I need to recover a few. Let me know. Thanks again for your posts.

    1. If there is no source to view when in debug then I do not know of another way to recover a RPGLE program's source.

  10. Good one Simon. Thanks for a very interesting tip. I hope I don't need to use it but you never know.

  11. Just an FYI. I was trying to retrieve source for a CLLE that was compiled with ALWRTVSRC(*NO) in V5R4M0 back in 2010. In one article, it said "But if you have been compiling your CLLE programs and modules for an earlier release, the "Target release" (TGTRLS) parameter is not either *CURRENT or V7R1M0, then you cannot retrieve the source." I know things change. We are on V7R4.So I tried your idea for RPG debug display on the CL. ( so I did STRDBG PGM(JMASCUS/APME20CL) MAXTRC(1000) UPDPROD(*YES) and it WORKED. The source was displayed and I was able to copy it.


To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.