30
Tue, Apr
1 New Articles

Long Live RPG IV!

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

RPG IV is nearly 10 years old. Most modern technologies take about 10 years to be introduced into the public at large. RPG IV is no different; for 10 years, many of us have been trying to persuade RPG III programmers to make the move, but it has been a difficult road. Today, the floodgates are open, and it is rare that you go into an iSeries shop without seeing at least some level of RPG IV being used.

Originally, RPG IV was just a replacement for RPG III, with most of the language's limitations either removed or improved to a point of being virtually removed. For example, the length of a field was increased from 256 characters to 32,767 and later (around V4R4) increased again to 65,535.

IBM improved upon the language's capabilities with seemingly every release. Take the length of a numeric field. RPG III was limited to 15 with 9 decimals. RPG IV increased that to 30 with 30 decimals. Then, in V5R2, it increased to 31 with 31 decimals, and in V5R3 it increased again, to 63 with 63 decimals. Why couldn't IBM have just waited and jumped right to 63?

One interesting enhancement in RPG IV over RPG III was the length of a field name. In RPG III, a 6-character field name was the limit. RPG IV introduced 10-character field names, and everyone thought, "Wow! How could I ever use that many characters for a field name?"

Then, in V3R7, IBM did something very interesting. Partly in response to critics and partly simply because it was possible, IBM increased the number of characters we could use in a field name to 4096. While field name lengths could have simply been unlimited, IBM chose to document the limitation. That way, if somebody actually tried to hit the limit, they could ask, "What's wrong with you?"

So RPG went from having what some consider the shortest limitation for field names to the longest. Even the C language, which boasts 255 or so characters for field names, only truly recognizes the first 16 unique characters, ignoring the rest. RPG IV is truly the champ in this area.

Probably the single biggest and most important enhancement to RPG IV over RPG III was the introduction of subprocedures. Yet that enhancement is probably one of the least-used new features. Oh sure, regular readers of this column use subprocedures at some level, but the vast majority of RPG IV programmers still haven't written that first subprocedure. Perhaps one problem is that IBM called them "subprocedures" instead of "procedures." This gives them a false association with subroutines. While this was intended to bring subroutine writers over to subprocedures more easily, what has happened is that programmers feel that the two are so similar that there is little reason to move off of subroutines.

You see this every day when you look at someone's /free code that includes subroutines all over the place. Is that irony or what?

Another major new feature was the controversial /free syntax. This feature allows RPG programmers to avoid using most of the fixed-format columns. I say "most" because you still cannot code anything in columns 6 or 7; consequently, you have to specify free-format code in columns 8 though 80.

There is still plenty of room for improvement in the /free syntax, including the fact that there is no compelling reason to require /free and /end-free statements. If nothing is in 6 and 7, then it should be considered a free-format statement. In fact, IBM already does this with comments. If you specify two slashes (//) as the first characters on the line, IBM interprets them as /free comments, even when they are intermixed with fixed-format code. Here's an example:

     C                   Read      CustRec
     C                   if        NOT %EOF()
         // Test for all numeric
     C                   if        %Check('0123456789':CSTNBR) = 0
     C                   callp     GetCustData(CSTNBR)
     C                   endif
     C                   endif

The third line is considered a comment by the compiler. So why doesn't this compile?

     C                   Read      CustRec
     C                   if        NOT %EOF()
          chain (CstNbr:Region:ItmNbr) OrdHist;
     C                   endif

Granted, I don't care for this specific example, but you get the point.

Another major enhancement was the introduction of the FOR opcode. This opcode replaces the legacy DO opcode by allowing you to specify an expression in Extended Factor 2 or free-format. Here's an example:

     C                   for       i = 1 to %elem(MyArr) by 1
     C                   eval      var = MyArr(i)
     C                   if        %Check('0123456789':MyArr(I)) = 1
     C                   Leave
     C                   endif
     C                   endfor

The FOR opcode allows you to specify a variable that is automatically incremented each time the loop is performed (similar to a DO loop) as well as a loop limit and an increment value. By allowing expressions, you can do things that allow you to avoid unnecessary work fields, as illustrated in this example, %ELEM(MYARR).

Of the other new operation codes, the EVALR (copy text, right-justified) is probably the most significant. This opcode allows you to simply and easily copy one character value to another with right-justification. Interestingly, I often have to point out that it "only" works with character variables since EVAL implicitly copies numeric data right-justified. I suppose people think that EVALR should work with numeric values, and perhaps it could, but EVAL already does a fine job of that.

Originally, IBM planned a complicated set of built-in functions that required you to wrap your variables in these built-in functions and then use other built-in functions (nested built-ins) to end up with right-justified text. I mentioned to them that perhaps something easier was better and recommended EVALR. Fortunately, IBM decided to use EVALR, and it's been a great success; you now only need to specify EVALR target = source and the data is copied beginning on the right side of the variables. In fact, IBM did such a good job of "componentizing" the EVALR functionality that they added it to procedure parameters. You can specify an OPTIONS(*RIGHTADJ) value for a procedure, and the compiler effectively issues an EVALR operation on the data specified for the parameter. The only problem is that some people think EVALR is one of those V5R2 or later features. Little do they know it has been around for a long time.

Finally, what conversation about RPG IV history would be complete without mentioning built-in functions? Built-in functions (a.k.a. "built-ins" or BIFs) opened up a level of flexibility in programming RPG IV beyond anything else IBM has done to the language, save subprocedures. The original list of built-in functions included the following:

  • %ELEM
  • %SIZE
  • %TRIMx
  • %SUBST
  • %ADDR
  • %PADDR

Today, there are over 100 built-in functions and while I would have to do a count to verify it, I believe there are now more built-in functions than operation codes. At one point, IBM decided that no more opcodes would be created; only built-ins would be introduced. But that philosophy has changed, and now new opcodes and built-in functions are being created. I have a page on my Web site that includes documentation (including release availability) for all built-in functions. I haven't updated it for V5R3 as of this writing, but it is fairly complete.

RPG IV has come a long way since OS/400 V3R1. It has grown from being a simple replacement for RPG III syntax to the powerful language it is today. It can compete with virtually every other language out there on features and flexibility. While there is always room for improvement in areas of consistency and performance, RPG IV has truly become The Modern RPG Language.

Bob Cozzi is a programmer/consultant, writer/author, and software developer of the RPG xTools, a popular add-on subprocedure library for RPG IV. His book The Modern RPG Language has been the most widely used RPG programming book for nearly two decades. He, along with others, speaks at and runs the highly-popular RPG World conference for RPG programmers.

BOB COZZI

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

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: