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.
CRTRPGPGM PGM(MYLIB/RPG3PGM) SRCFILE(DEVSRC) OPTION(*SRCDBG)
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:
For RPGLE objects: STRDBG PGM(PGMSDH/TESTRPG) For RPG object: STRDBG PGM(PGMSDH/TESTRPG3) OPMSRC(*YES)
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) ; 5 6 Date1 = '122516' ; 7 Date2 = '022195' ; 8 9 Difference = %diff(%date(Date1:*mdy0):%date(Date2:*mdy0):*d) ; 10 11 *inlr = *on ; Bottom 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.
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.
On the "Run SQL Scripts" window I select "Run", and then "Debugger" in the drop down.
When the "Start debugger" window opens I just need to enter the program and the library it is in, and click the "OK" button.
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 ).
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.