• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: Compare Pieces Of Source Members

    April 19, 2021 Ted Holt

    Next to Barbara Morris, the F15 key seems to be the RPG programmer’s best friend. I do not like duplicated source code, but for years I have been finding it everywhere. Sometimes I find the same source code in multiple source members. Sometimes I find the same source code two or more times in a single source member. If you’ve been programming in an IBM i shop for more than two hours, you know what I’m talking about.

    As I wrote three years ago in this august publication, duplicated source code is bad because it embodies the WET principle, whereas DRY is better. That article dealt with one technique I use to find duplicated source code. Today I’m pleased to publish a utility I use to determine whether a section of source code is truly duplicated or not.

    This story contains code, which you can download here.

    I wrote this utility several years ago because I needed something that would compare two sections of a single source member to see if they were duplicates or not. The Compare Physical File Member (CMPPFM) command compares entire source members. It was too “noisy” for my purposes, so I came up with the idea of copying pieces of one or two source members to temporary source members, and having CMPPFM compare the temporary members. It’s not rocket science, but I learned years ago that rocket science doesn’t put product on the shipping dock.

    My utility is built from four source members.

    Name Type Description
    CMPSRC CMD The command interface
    CMPSRCC CLLE The command processing program
    MOVPGMMSG CMD Brian Rusch’s command interface over the QMHMOVPM API
    RSNESCMSG CMD Brian Rusch’s command interface over the QMHRSNEM API

    If you missed the last two when we published them in 2012, here’s a second chance to get them. They are fabulous. I put all four members into the downloadable code, along with a text file with the necessary object-creation commands.

    Once you’ve created the objects, type CMPSRC on a CL command line and press F4. The system will prompt you for the qualified file name, member name and range of source code sequence numbers for the two sections of code you want to compare.

    These are the parameters.

    Name Description
    FILE1 The qualified file and member name that contains one section of source code.
    RANGE1 The first and last sequence numbers of the first file member.
    FILE2 The qualified file and member name that contains the other section of source code. Leave the file name blank to compare two sections of source code within the same source physical file member.
    RANGE2 The first and last sequence numbers of the second file member.

    Be aware that the sequence number field is defined as 6,2 zoned decimal in source physical files. This means that you must key the decimal point if there’s a non-zero digit following the decimal point. However, you don’t have to key leading zeros. If you edit in SEU, you’ll have no trouble remembering the decimal point because SEU shows them to you. If you use the LPEX editor in RDi, as I do, you may forget to key the decimal point until you get used to using the utility.

    Once I determine that two sections of code are identical, the refactoring fun begins. I often move duplicate code into a subroutine, and from there into a subprocedure. If two sections of source code are almost identical except for a slight difference, such as a field or variable name, I parameterize the code. Once a routine is in a subprocedure, it may very well end up in a service program. What better home could there be for a routine that has been needed in many places?

    RELATED STORIES

    Guru: Use SQL To Find Duplicate Source Code

    CL Error-Handling With APIs

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    Tags: Tags: 400guru, CL, FHG, Four Hundred Guru, IBM i, LPEX, RDi, SEU

    Sponsored by
    JAMS Software

    One Scheduler. IBM i, Windows, Linux, and More.

    IBM i teams trust JAMS to schedule and orchestrate jobs across every platform in their environment. Centralized visibility, cross-platform dependency management, and alerts that reach the right person before the business feels it.

    Fewer than 5% of IBM i shops run IBM i only. The rest are managing cross-platform dependencies — often without a clear picture of how they connect. JAMS draws that map, enforces those dependencies automatically, and gives your team a single place to monitor, manage, and recover when something goes wrong.

    If you are running hundreds of CL scripts and custom RPG processes, bring them as-is. JAMS runs them exactly as they do today — except now they are visible, monitored, and part of an orchestrated workflow instead of scattered across folders only one person knows about.

    No consumption-based pricing. No surprise bills when your workload spikes. You pay based on how many machines JAMS talks to — that’s it.

    Learn More → https://jamsscheduler.com/lp/ibm-i

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    As I See It: Ambivalence Every Day Has To Be Earth Day

    Leave a ReplyCancel reply

TFH Volume: 31 Issue: 30

This Issue Sponsored By

  • Racksquared
  • IBM
  • RPG & DB2 Summit
  • ARCAD Software
  • Raz-Lee Security

Table of Contents

  • Need An RPG Programmer? Nalashaa May Have You Covered
  • Every Day Has To Be Earth Day
  • Guru: Compare Pieces Of Source Members
  • As I See It: Ambivalence
  • IBM i PTF Guide, Volume 23, Number 16

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Big Blue Ships Bob 2.0 And Premium Package For IBM i
  • Your IBM i Jobs Don’t Live On An Island Anymore
  • FalconStor Creates Cloud Clean Room To Prove Backup Recoveries Work
  • Talking Git On IBM i With A Bunch Of IBM i Gits
  • IBM i PTF Guide, Volume 28, Number 22
  • More Power Systems Price Hikes, This Time They Are “Directional”
  • AI Is Not Just For Developers, It Is For Everyone At Your Company
  • Guru: Finding Data In The Forest – Exploring Three-Part Naming In SQL
  • Former IBMer’s New Book Puts The Midrange In The Spotlight
  • Have You Tried To Buy A Server Lately?

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle