Retrofit source code with the MRGSRC command

Many programmers like to use the PDM option 54 "Compare Physical File member (CMPPFM)" to find source code changes. This method generally works well especially since there are several additional parameter process options like ignoring comment lines, ignoring case, find moved lines, etc. However, there are several major short-comings with this method and my opinion is that a better solution exists in the command MRGSRC which interactively allows you to selectively merge source differences into a target source member.

Limitations of the PDM compare method become clearer once you become familiar with the MRGSRC command. The PDM method does not display statement numbers when showing differences in source members. Finding the exact source lines often entails some searching for the correct location of the change. The PDM method only gives the user an opportunity to view differences but not to accept/reject into a target source member.

As an example, say your software vendor sends you an "update" to an existing program. First, especially while you are learning to use MRGSRC, make a backup copy of your source. Instead of creating extra copies with messy names ending in SV, BK, 01 that may never get cleaned up start a new library and give it a name that reminds you that old source is kept there (ie. KEEPSRC, OLDSRC, XSRC, etc.).

Now, since the upgraded program is new we need to find exactly what was changed and optionally merge that into your custom version. Let's say the new copy is in a library called "UPDLIB" and your custom version is in a library named "CUSTOM".

MRGSRC     TGTFILE(CUSTOM/QRPGLESRC)
           TGTMBR(MYPGM)
           MAINTFILE(UPDLIB/QRPGLESRC)
           MAINTMBR(MYPGM)
           ROOTFILE(CUSTOM/QRPGLESRC)
           ROOTMBR(MYPGM)
           SELECT(*YES)

Because you have *YES for the SELECT parameter a split screen is displayed where you can see the differences and accept them (F15) or reject them(F2) individually or accept them all(F14). Updates can be reviewed one at a time and you can skip to the next difference by pressing 'next change'(F16). Personally, I get better results by entering all parameters and none of the default parameters (ie. "*target") are used.

Great you say, but there other scenarios that occur that may not be as simple as the first example. I agree so here is a second example where you are working on a custom program in a new version and want to find changes that were made in the previous release, that is from the previous release base code to the previous release custom code. In this case you will be starting with the latest version of the program from the new release (target) and want to find what was changed (maintenance) when the older program (root) was customized.

MRGSRC     TGTFILE(CUSTNEW/QRPGLESRC)
           TGTMBR(MYPGM)
           MAINTFILE(CUSTOLD/QRPGLESRC)
           MAINTMBR(MYPGM)
           ROOTFILE(BASEOLD/ALLSOURCE)
           ROOTMBR(MYPGM)
           SELECT(*YES)

It seems the MRGSRC command can be a little confusing to some programmers but it doesn't take long to get familiar with this method because it works so well. I still occasionally use compare in PDM but MRGSRC is superior. The two methods are not mutually-exclusive.

The only caveat is that it is possible to accidentally press the wrong function key and merge a change that you meant to reject. The solution is just to exit and not save changes and start the MRGSRC split screen session again.