• 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:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

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

    Sponsored by
    FalconStor

    Begin Your Journey to the Cloud with Hybrid Cloud Date Protection and Disaster Recovery

    FalconStor StorSafe optimizes and modernizes your IBM i on-premises and in the IBM Power Virtual Server Cloud

    FalconStor powers secure and encrypted IBM i backups on-premise and now, working with IBM, powers migration to the IBM PowerVS cloud and on-going backup to IBM cloud object storage.

    Now you can use the IBM PowerVS Cloud as your secure offsite copy and take advantage of a hybrid cloud architecture or you can migrate workloads – test & development or even production apps – to the Power VS Cloud with secure cloud-native backup, powered by FalconStor and proven IBM partners.

    Learn More

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

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

    Leave a Reply Cancel 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

  • With Power11, Power Systems “Go To Eleven”
  • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
  • Izzi Buys CNX, Eyes Valence Port To System Z
  • IBM i Shops “Attacking” Security Concerns, Study Shows
  • IBM i PTF Guide, Volume 27, Number 26
  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25

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