29
Fri, Nov
0 New Articles

The Eagle Eye of INDRPG

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Here is a utility command that will become invaluable in your programmer’s toolbox: the Indent RPG command. It shows RPG code (any flavor) indented to reveal logic blocks. You can direct the output to the screen or the printer!

Maintenance programmers don’t lead easy lives. I should know because maintenance programming is what I do most of the time. If you’re like me, you recognize this scenario: Someone asks you to make a “tiny” modification to a program. You start SEU to edit the program only to discover that it has complex logic blocks indented one inside another several levels deep.

If RPG were a free-format language, you could identify the start and end of each block by indentation. But because RPG is a fixed-format language, indentation is not an option.

In this article, I present another method, made possible by the Indent RPG (INDRPG) command. Although the code of this command is too lengthy to publish here, it is available on the Web at www.midrangecomputing.com/mc/99/06.

Before you yell at me because CRTRPGPGM, CRTBNDRPG, and CRTRPGMOD offer an Indent parameter, let me tell you something about that. The CRTxxx commands never show the indented code on the screen, so you cannot perform searches. They require you to recompile, which may be too slow or altogether impossible (e.g., if some of the files used by the program are not online). INDRPG doesn’t have these shortcomings.

INDRPG Revealed

INDRPG presents RPG code in a readable fashion and can indent RPG III or IV code (and accepts either uppercase or lowercase for the latter).

The INDRPG command has nine parameters:
Source file (SRCFILE) identifies the source file containing the member to be indented. The library qualifier defaults to *LIBL. You can also specify a library name or *CURLIB. • Source member (SRCMBR) identifies the source member to be indented.
Subroutine name (SUBR) tells INDRPG which subroutine to indent. The default value, *ALL, processes the entire program. You can type the name of a single subroutine or the

special value *MAIN to list the program’s mainline (the portion of the C-specs before the first BEGSR).

Output (OUTPUT) determines whether the indented code should be displayed (*) or printed (*PRINT).

Columns per level (COLS) determines how many columns to the right to shift code. The default value is 2.

Symbol for indentation (SYMBOL) determines which symbol to use to join the beginning and end of a logic block. The default is a vertical bar.

Ignore commented-out C-specs (IGNCMTOUT) omits all C-specs that have been commented out (i.e., those that have an asterisk in column 7 but contain actual RPG code) when you use the default value of *YES.

Ignore top comments (IGNTOPCMT) omits all the comments located at the top of the program if you use the default value of *YES.

Display size (DSPSIZ) formats the screen display size. If you have a display station capable of showing 27 lines by 132 columns, take advantage of its extended area by specifying *WIDE.

What INDRPG Does for You

INDRPG displays or prints the following items:
• The source sequence number
• The indented source code
• The word LABEL to the left of lines containing labels (such as TAG, BEGSR, or ENDSR)

• The markers HI, LO, and EQ to the right of the code, identifying the resulting indicators coded in C-specs

• The date each record was last changed Because a 24-line by 80-column display station has less room for displaying data, only the indented source code is presented in this format. You can display the remaining pieces of information, as you will see shortly. Comments are displayed in blue, making it easier to distinguish between live code and comments (including commented-out code). INDRPG displays (or prints) a solid line of dashes right before each BEGSR op code and each RPG IV subprocedure.

Any Other Tricks?

When INDRPG sends the output to the screen, you can take advantage of four input fields located at the top of the display. The first field controls how many lines are “rolled” each time you press the Page keys. By default, INDRPG rolls 25 lines in 27 by 132 mode and 23 lines in 24 by 80 mode. You can change this value to anything between 1 and 9999. The second field allows you to go directly to any given label in the program, whether it’s a TAG, BEGSR, ENDSR, or subprocedure. The third field lets you go directly to any line of the source member. Just remember to press Field Exit after typing the sequence number (without the decimal point). For instance, to go to line 17.50, type 1750, press Field Exit, and then press Enter. The fourth field lets you go directly to a number of “special points” within the source member, all of which are identified by a letter. These special points are as follows:

• Top of program (T)
• Bottom of program (B)
• Beginning of F-specs (F)
• Beginning of E-specs (E)
• Beginning of I-specs (I)
• Beginning of C-specs (C)
• Beginning of O-specs (O)
• Beginning of D-specs (D) You can also press F4 to open a window listing all labels. When you move the cursor to one of these labels and press Enter, its name is automatically placed in the “Go to label” input field previously described. Pressing Enter a second time positions the subfile to that label. As in

SEU, pressing the F21 key displays a command line window. (You don’t need to memorize any of this. Press the Help key, and an information panel shows up.)

There are three more function keys you can use. First, you can press F13 to change the values you provided for several of the INDRPG command’s parameters. Second, the F14 key invokes SEU. Third, the F24 key provides useful information about the source member you’re looking at.

Another useful feature is that you can move the cursor to any subfile line and press Enter to display a window of additional information about that source line. You will see the sequence number, the date of last change, the name of the current subroutine or subprocedure, and the indicator usage. In the 27 by 132 format, most of this information is always displayed. This feature of the Enter key is most advantageous when you are using the 24 by 80 format.

Of Needles and Haystacks

No source code browser would be complete without a Find feature. When you press F5, INDRPG opens up a window in which you can type the following Find options:

One, two, or three strings that you want to locate. If any of them is found, INDRPG positions the subfile so that the string is at the top of the listing. By having three input fields, you can find a particular variable or file even if you don’t remember its exact name. Was it CUSMAS, CUSTMAS, or CUSTMAST? No matter, just type all three and see what you get.

An input field in which you indicate where to look for the strings. By default, this field contains a C, which means “anywhere in the code.” You can change it to any of the following values:

• L (to search in the left 5 columns of each line, since many programmers code revision identifiers there)

• D (date last changed)
• F1 (factor 1)
• OC (op code)
• F2 (factor 2)
• RF (result field)
• CM (comments)
Whether or not to ignore case differences. The default is to ignore case.
Where to start the search. This field has a C (“current”) by default, which means the search begins with the source line at the top of the screen. You can also request that the search begin at the top (T) or bottom (B) of the member.

Di rect ion of t he s earc h. It’s dow nwar d (D ) by def ault , bu t yo u ca n ch ange it to upw ard (U). Not e th at i f yo u st art the sear ch a t th e to p (T ), t he d irec tion of the se arch is alwa ys a ssum ed t o be dow nwar d (D ), e ven if y ou e nter U f or d irec tion . In co ntra st, star ting the sea rch at t he b otto m fo rces the dir ecti on u pwar d.

So far, you’ve found only the first occurrence of the string. To find the next (or previous) occurrence, press F9 (or F8). Regardless of the direction of search you have indicated, F9 always looks for the next occurrence going down, and F8 always looks going up.

Implementation Notes

INDRPG is most useful in a display station capable of showing 27 lines by 132 columns, but you can use the regular 24 by 80 display station, too. If you are like most programmers and use PC workstations with Client Access/400 (or a similar program), you can configure a 27 by 132 device without trouble.

The IGNCMTOUT feature forced me to hardcode the names of all valid operation codes in both RPG III and IV, which are listed in compile-time data at the bottom of program INDRPGR. (There are 173 op codes; can you believe that?) This list is complete as of V4R2. If later releases of the language add more op codes, you’ll have to change that list.

Finally, CL program INDRPGC uses utility command Forward Program Messages (FWDPGMMSG), which was published in my article “How to Forward Messages in CL” in the January 1998 issue of MC.

I think you will find INDRPG a useful tool, one that has several features you can’t get from SEU or from an indented compiler listing. If you have comments or suggestions for improvements, I’d love to hear from you.

Reference

“How to Forward Messages in CL,” MC, January 1998

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: