• 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
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    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

  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20
  • POWERUp 2025 –Your Source For IBM i 7.6 Information
  • Maxava Consulting Services Does More Than HA/DR Project Management – A Lot More
  • Guru: Creating An SQL Stored Procedure That Returns A Result Set
  • As I See It: At Any Cost
  • IBM i PTF Guide, Volume 27, Number 19

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