Wednesday, June 18, 2014

RTVCLSRC makes a comeback

clp clle rtvclsrc retreive source

I am sure I am not the only person who has come across a CLP program, not been able to find its source, and been thankful for the RTVCLSRC command to be able to retrieve its source. By all means the code retrieved was not pretty, but it was a lot better than having nothing.

When the CLLE create program (CRTBNDCL) and module (CRTCLMOD) commands were introduced the "Allow RTVCLSRC" parameter was not included. With IBM i 7.1 the parameter has been reintroduced for both commands.

The default for the Create CLP program (CRTCLPGM) command, and the CCLE CRTBNDCL and CRTCLMOD commands "Allow RTVCLSRC" (ALWRTVSRC) parameter is *YES. Therefore, if your IBM i is running 7.1 you have probably been compiling your CLLE objects with the default to allow you to retrieve the source. 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.

Below are examples of the 3 commands where I have decided to give the ALWRTVSRC parameter.




Having created the programs and modules how do we retrieve the source?

When you prompt the RTVCLSRC command for the first time in 7.1 the first thing you notice is all the extra parameters:

                          Retrieve CL Source (RTVCLSRC)

 Type choices, press Enter.

 Program  . . . . . . . . . .   __________    Name
   Library  . . . . . . . . .     *LIBL      Name, *LIBL, *CURLIB 
 Service program  . . . . . .   __________    Name
   Library  . . . . . . . . .     *LIBL      Name, *LIBL, *CURLIB
 Module . . . . . . . . . . .   *PGM          Name, *PGM
   Library  . . . . . . . . .     __________  Name, *LIBL, *CURLIB 
 Source file  . . . . . . . .   QCLSRC        Name
   Library  . . . . . . . . .     *LIBL      Name, *LIBL, *CURLIB
 Source member  . . . . . . .   *PGM          Name, *PGM
 Retrieve included source . .   *NO           *NO, *YES

The following parameters are new:

  • "Service program" and library, SRVPGM
  • "Module" and library, MODULE
  • "Retrieve included source", RTVINCSRC

When you think about how modules can be bound to programs and service programs the first two parameters are understandable. The third is whether to include source that has been included into CLLE, this feature was added in 6.1 and I am not going to describe it in this post.

If you created a CLP or a CLLE program using the CRTCLPGM or CRTBNDCL commands then the source can simply retrieve like this:


If I had created a CLLE module, using the CRTCLMOD command, and bound it into program I would retrieve the source:


Or if the CLLE module was bound into a service program I would retrieve the source:


If the person who created the programs and modules changed the ALWRTVSRC parameter to *NO then it is not possible to retrieve the source in this manner. The only time I have compiled CL with the ALWRTVSRC as *NO was when I was working for a software company. They did not want their customers to be able to retrieve and modify their source.


You can learn more about these from the IBM web site:


This article was written for IBM i 7.1.


  1. I have always been big on using RTVCLSRC anytime we need to modify the STARTUP routine ... it is a lot safer that way. Too bad it strips out the comments but you can get around that by defining otherwise meaningless character variables and changing text at the appropriate lines.

  2. I never write cl programs anymore, everything I can do is in rpg. is there any good reason to create a cl program? What are the benefits?

    1. I think about a 1/3rd of my time is spent writing or maintaining CL programs. I know I could use QCMDEXC (or equivalent), but there are so many commands that I use that do not lend themselves to be called in that API.

      I know that many CL commands have API equivalents, but I believe in keep things simple & getting output from a command is a lot clear & easier to maintain than extracting data from a User Space.

    2. The benefit of CL programs is the ability to do OS level work in a language specifically designed to do OS level work. Those of us who still write reports enjoy the natural flow of OVRPRTF FORMTYPE(PAYROLL), CALL PRTPRCHECK rather than having to define the printer file as USROPN, then issue a QCMDEXEC call to OVRPRTF, then OPEN the printer file. Basically, a CL program is a good fit any time I have to do prep work before an RPG program starts (clear a file, create a directory, set a form type or output queue, copy a file, etc) or cleanup work (copy to tape, archive transaction data, etc) after an RPG program has completed.

      I also use CL programs extensively to sequence RPG programs. It's a lot easier to look at a single CL program to see the full sequence of RPG programs than to drill through say a dozen RPG programs to follow the cascade. It's also easier to reuse an RPG program if it doesn't CALL a successor program.

      Certainly sometimes it's more convenient to issue an OS command in the middle of typical RPG processing, and for those times I would use QCMDEXEC or system().

  3. Someone at my site wrote a DSPCLPGM using RTVCLSRC. very easy to write utility. Place the CL code into a source file in QTEMP then dive straight into SEU to display it.

    Only problem with RTVCLPGM - it doesn't show any comments

  4. Can we able to retrieve display file source which is used in CL program ?

  5. Is there anyway to retrieve the source code when ALWRTVSRC(*NO)?

    1. If the CLLE program was compiled with DBGVIEW(*ALL) or any of the options not *STMT or *NONE then you might be able to. I wrote about how to do it from the debug data here.

  6. Hello everyone.
    Is there something similar to RTVCLSRC but for menus?

    1. What kind of menu?
      - DDS, you can look in the message file to find what the options are.
      - UIM
      - (Or my employer's favorite) CL program with a display file.


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.