21
Thu, Nov
1 New Articles

Programmer's Toolbox

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

CVTILEFMT: A Beautician Specializing in RPG IV Source Code

Converting RPG III source to RPG IV source has never been as easy as this. By using CVTILEFMT after using IBM’s CVTRPGSRC command, you will save time and money and make your code more readable by taking advantage of RPG IV’s free-format operands.

Many of us have undoubtedly started working on projects that we allocated time for in this new year. One of the projects most of us have been meaning to start is converting our RPG III source to RPG IV, and possibly throwing in a hint of ILE. This project as a whole may seem overwhelming, but when it is broken down into steps, it’s really nothing more than doing the same task over and over again.

IBM aids you with this conversion by supplying the Convert RPG Source (CVTRPGSRC) command. CVTRPGSRC performs an uncomplicated conversion of an RPG III source member to RPG IV. This is a great start, but CVTRPGSRC doesn’t take advantage of the free-format expressions we have been waiting eagerly to use. That’s where Convert ILE Format (CVTILEFMT) comes in. CVTILEFMT picks up where CVTRPGSRC leaves off by converting your source to use the free-format style and by performing a couple of other conversions to make your code more understandable. After running CVTRPGSRC, run CVTILEFMT on your source member and enjoy your new free-formatted source.

I created CVTILEFMT a few years ago when I was part of a team converting homegrown software to RPG IV. We wanted to take full advantage of the free-format expressions now available to us but found converting all of the source by hand time- consuming. I wrote CVTILEFMT to take care of these concerns. CVTILEFMT worked so well on our code that I made it available to others. Since then, CVTILEFMT has been tested and tweaked using suggestions from the many people who found it useful. (Find the CVTILEFMT utility on the MC Web site at www.midrangecomputing.com/mc/99/03.)

What CVTILEFMT Will Do for You

CVTILEFMT, when run on source after IBM’s CVTRPGSRC command, will do the following:

• Convert expressions such as IFs, DOs, and WHENs to free-format expressions. Parentheses also are added to make the expressions more readable.

• Convert arithmetic expressions to free-format EVALs. Each mathematical operand (ADD, MULT, DIV, SUB) can be converted or left as is. The reason for providing this choice is that sometimes you won’t want to convert certain statements. This is because, if you do otherwise, the statement may perform some unwanted task, such as “date flipping.” Arithmetic conversion is controlled by the CVTxxx parameters, where “xxx” is ADD, SUB, MULT, or DIV.

• Move all C-spec defined variables into the D-specs, alphabetically. If a variable is defined on a C-spec, the declaration is removed and placed in the D-specs.

• Format all END statements, converting them to their proper form (ENDIF, ENDDO, etc.) This capability comes in handy in cases where programmers coded only END for DOs, IFs, CASEs, and SELECTs. This change increases the ease of tracing the program, whether in SEU or while debugging.

• Convert the source (excluding comments, constants, and table data) to all uppercase or all lowercase. Depending on what you specify on the Uppercase or lowercase (UPLOW) parameter, your source will be converted to uppercase or lowercase.

What CVTILEFMT Will Not Do for You

CVTILEFMT will not convert MOVE statements. This is because MOVE can be used to move data of one type to a field of another type. Also, if you previously used resulting indicators on mathematical operations and you convert these operations to EVALs, the resulting indicators will be lost. This is a good time to convert these less-used methods into more readable code and also eliminate the use of confusing indicators.

How It Works

CVTILEFMT consists of five objects, listed in Figure 1. The CL program FMT001CL handles command validation. The program checks to make sure that the source member specified on the CVTILEFMT command exists and that it is either of type RPGLE or SQLRPGLE. Then, FMT001CL will make sure that the libraries you specified on both the To and From parameters are in your library list. If they are not, those parameters are added, and a flag is set to remove the libraries from your library list after CVTILEFMT is complete. Control is then passed to the main processing program, FMT001RG.

FMT001RG first reads one line of source at a time. For each line of source, FMT001RG first determines if the line of source needs to be converted. If the current line of source is one that can be converted, it then uses a simple table of RPG operands to decide what to do with the statement. FMT001RG then formats a new free-form expression by using information gathered from the old expression. If, during this processing, a variable is found that is declared on the C-spec statement, FMT001RG adds this field to an array to be added to the D-specs.

FMT001CL then calls the second RPG program, FMT002RG, to resequence the source and convert to uppercase or lowercase. Case translation is done character by character. This process occurs so that special attention can be taken so as not to convert literal data inside of quotation marks, comments, or table data located at the bottom of the source. After FMT002RG completes, it passes control back to FMT001CL where a completion message is sent to the user telling them that the conversion is complete.

An Ounce of Precaution

When using CVTILEFMT for the first time, it is best to be cautious. CVTILEFMT does all it can to help you from accidentally overwriting source that already exists. But, CVTILEFMT will not allow you to convert your source into the same member or into a member that already exists unless you specify to do so on the command. You can achieve this conversion by specifying a *YES on the Replace member (RPLMBR) parameter of the CVTILEFMT command. This parameter defaults to *NO so you won’t accidentally

overwrite an existing member. I suggest you convert and compile your source into a library other than your production library and thoroughly test the programs before moving them into production.

More Power to You

I hope you find CVTILEFMT as helpful and timesaving as we did at our company. If you like it, you may want to create a PDM option like the one in Figure 2.

Just as you create business application programs that save users time, you can use those same skills to write programs that perform even the most tedious of chores. Although it takes time to develop tools like CVTILEFMT, the time saved most certainly makes up for it.

Object Type Function

CVTILEFMT CMD Command interface for CVTILEFMT utility FMT001CL CLP Command processing program FMT001PG PNLGRP Help text
FMT001RG RPGLE Converts RPG IV source code FMT002RG RPGLE Converts to uppercase or lowercase

Figure 1: The CVTILEFMT utility consists of five objects.

CVTILEFMT FROMFILE(&L/&F) FROMMBR(&N) +

TOFILE(&L/QRPGLESRC) TOMBR(*FROMMBR) +

RPLMBR(*YES)

Figure 2: Creating a handy PDM option, such as this one, makes CVTILEFMT even easier to use.

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: