• 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
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    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

  • IBM Pulls The Curtain Back A Smidge On Project Bob
  • IBM Just Killed Merlin. Here’s Why
  • Guru: Playing Sounds From An RPG Program
  • A Bit More Insight Into IBM’s “Spyre” AI Accelerator For Power
  • IBM i PTF Guide, Volume 27, Number 42
  • What You Will Find In IBM i 7.6 TR1 and IBM i 7.5 TR7
  • Three Things For IBM i Shops To Consider About DevSecOps
  • Big Blue Converges IBM i RPG And System Z COBOL Code Assistants Into “Project Bob”
  • As I See It: Retirement Challenges
  • IBM i PTF Guide, Volume 27, Number 41

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