02
Thu, May
6 New Articles

10 New Functions We'd Like to See in RPG IV

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

I'm getting so tired of a vocal minority giving IBM advice on new RPG IV features while the vast hundreds of thousands sit quietly by and say virtually nothing. Not every piece of advice is for an ostentatious feature, but some ideas are. I admit that my own list is no less pretentious than the list any other cage-rattler would create, but hey, I "wrote the book."

But seriously, do you really want to sit quietly by as features are introduced that will impact the language in perpetuity?

For example, EVAL-CORR is a proposed enhancement that would copy data structures to other data structures. MOVE CORRESPONDING is the COBOL equivalent and the origin of this requirement. It copies each subfield of one data structure to the same field name in a second data structure. That's long overdue in RPG IV, and it will benefit us with QUALIFIED data structures.

The problem with EVAL-CORR is the embedded hyphen in the opcode name. Do we really want all new opcodes to contain an embedded hyphen? The Z-ADD opcode is being used as the precedent for moving in this direction. Of course Z-ADD isn't supported in /free RPG IV, so using Z-ADD to justify it isn't valid in my mind.

Hyphens should never be used within an operation code, nor should any other operation code separator be used. The opcode should be named EVALC, EVALCORR, ECORR, CPYCOR, or something similar. In other words EVAL-CORR will no doubt lead to EVAL-CENTER. Wouldn't you rather use EVALC than EVAL-CENTER and EVALCOR (or something similar) than EVAL-CORR?

The justification for doing the embedded hyphen is... Well, who cares what it is? It isn't right.

1. Move Corresponding Opcode

Continuing our tradition of taking cool features from other languages, the COBOL MOVE CORRESPONDING statement needs to be imported to RPG IV. This feature allows you to copy one qualified data structure to another; copying only the subfields whose names match in both data structures. The subfields are copied based on the names. For example:

     D Customer        DS                  Qualified 
     D  CustNo                        7P 0
     D  CustName                     35A
     D  Address                      30A
     D  City                         30A
     D  BalDue                        5P 2

     D CustStats       DS                  Qualified 
     D  CtrlID                        5I 0
     D  CustNo                        7P 0
     D  BalDue                        5P 2

     C                   EvalMap   CustStats = Customer

In the example above, specific subfields of the data structure CUSTOMER are copied to the corresponding subfields in the CUSTSTATS data structure. The opcode name I suggest, EVALMAP (pronounced "Eval with Map" or simply "Eval Map"), is more RPG-like than COBOL's MOVE CORRESPONDING and much, much easier to teach than EVAL-CORR.

2. %RANGE and %VALUES Built-In Functions

If you go back to the days of System/34 SSP, you may remember a little-used language named WSU (pronounced "Woo Soo"). This language had some very cool opcodes, including VALUES and RANGE. Here we are decades later, and RPG IV does not yet have this capability built in.

I think we need both %RANGE and %VALUES as well as %MIN, %MAX, %AVG, and %STDDEV. These built-in functions will do more for the language and programming community than most other enhancements. Why? Because they will be used effectively in nearly all RPG IV programs/modules being written.

For example, with these built-in functions, you could code like this:

     C                   if        AmtDue = %Range(1 : 100)
     C                   eval      Group = 1
     C                   elseif    AmtDue = %Range(101 : 1000)
     C                   eval      Group = 2
     C                   elseif    AmtDue = %Range(1001 : 10000)
     C                   eval      Group = 3
     C                   endif

     C                   if        Group = %Value(2:3)
     C                   exsr      Midrange
     C                   endif

3. %ISxxxx Built-in Functions

I don't know how many times I've needed these features in CGI programming. The ability to test a field for all numeric data, all non-numeric (i.e., alpha) text, or a mix of both without special characters is becoming more and more important every day. It's about time RPG IV goes the following:

  • %IsDigits--Does the field contain all numeric digits only?
  • %IsAlpha--Does the field contain alpha characters A-Z (in uppercase or lowercase) only?
  • %IsAlphaNum--Does the field contain A to Z, a to z, and 0 to 9 only (i.e., no special characters)?
  • %IsNum--Does the field contain a valid number, with or without standard numeric editing symbols (decimal, thousands notation, sign, currency symbol)?

All of these built-ins return *ON if they succeed and *OFF if they fail.

4. Initialization of Arrays

When RPG IV came out, IBM ported the decade's only compile-time array and compile-time data. Today, the only reason you use compile-time data is because there's no easy way to initialize an array's elements on the Definition specification. IBM needs to add the following capability to the language:

     D RegionName      S             10A   Dim(4) 
     D                                     Inz('NORTH' : 'SOUTH' : 
     D                                         'EAST'  : 'WEST') 

     D RegionCode      S              5I 0 Dim(4) Inz(1:2:3:4) 

Could it get any easier than this?

5. Typeless Parameters on Subprocedures

Just like built-in functions, the subprocedures we write should also have the capability to allow the caller to specify character, numeric, or date values (any type) for the same parameter. Today, if you declare a parameter as numeric, you can't pass character, and vice versa. Whether this capability is implemented via so-called procedure overloading or through an OPTION(*ANYTYPE) keyword on the parameter definition does not matter. What does matter is having the capability in the language.

6. Default Values for Unspecified Procedure Parameters

When you define a procedure, you have a choice of allowing the caller to specify some value or not. When no value is specified, however, it would be beneficial to be able to specify a default value for that parameter. This way, the value you receive in the subprocedure is defined on the prototype instead of in the procedure logic/code.

7. Improved Performance with Large Return Values

If you've ever written a procedure and had a character return variable or an array as the return value, you know what I'm talking about. RPG IV performance stinks when the length of the return value exceeds a certain (unknown at press time) length.

For example:

     P GetCustNames    B                   Export 
     D GetCustNames    PI            50A   Dim(300)
     D m_Parm01                       7P 0  
     D m_Parm02                       7P 0  
     D m_Parm03                       7P 0  
     D  l_rtnvalue     S             50A   Dim(300)
      **  procedure code goes here
      **  Return value is VERY LARGE
     C                   return    l_RtnValue 
     P GetCustNames    E

This procedure returns an array of 300 elements, each of which is 50 bytes in length. Therefore, the procedure returns 15,000 bytes, which can seemingly take centuries to accomplish. This really needs to be enhanced.

8. Multiple Statements per Line on Conditional Logic (/free)

OK, it's not a secret that I'm no fan of the /free syntax in RPG IV. It isn't that I dislike free-format, I just dislike syntax that I have to fight with every time I use it.

One thing that would help is if IBM altered the grammar of the /free syntax to allow multiple statements on a line when conditional statements are used. For example:

      /Free
            if  (A = B) ;
              code = 3 ;
            elseif (C = D) ;
              code = 4;
            endif;
      /end-free

I would much rather have the syntax accept the following:

      /Free
            if  (A = B) 
              code = 3 ;
            elseif (C = D) 
              code = 4;
            endif;
      /end-free

Even better would be the following:

      /Free
            if     (A = B) code = 3;
            elseif (C = D) code = 4; 
            endif;
      /end-free

9. Compile-Time and Runtime Support for Add-on Libraries

I suppose this is more problematic than the other requirements on this wish list. What is missing from the iSeries is the ability for vendors to ship both development and runtime software to customers. For example, take the RPG xTools (my own product): Today, I can ship a development version that includes the runtime, but I can't ship just runtime. Why? Because no function exists that allows me to sell a developer version and then give away or greatly reduce the runtime version for systems on which no development is being done.

That is, I can't allow programs to call procedures in this service program, but not allow compiling and linking to the service program; this would allow runtime support. I have no way to restrict one from the other. On other platforms, you do have this capability; if customers license only the runtime version, they can't compile a program that calls the procedures in the service program, but they can buy or install already-compiled programs that use the service program. Those programs have been compiled on a system where the developer version was licensed.

10. Inline Optimization for Procedures

RPG IV's performance is good, but not great. I think IBM tends to believe that you should just buy more CPU cycles to fix your problems. But a compiler should have various levels of optimization to make our own code run faster.

Inline code is a method by which short user-written subprocedures are copied inline by the compile rather than stored in a separate routine. This allows the code to be run slightly faster than if it were inside a procedure.

Today, most but not all of the OS/400 CEExxx APIs are inline routines. If an API begins with the letters "CEE," it is more than likely that the compiled object code is "/copied" into the program, replacing the CALLB or CALLP to the procedure with the actual executable code itself.

RPG IV needs an INLINE keyword on procedures to encourage the compiler, when possible, to "/copy" object code from a procedure as inline code. This does create bigger programs, but they tend to run slightly faster. To the programmer, you don't code anything differently when calling the procedure so the benefit is at runtime.

What Features Do You Want?

I've coordinated this week's survey with this article. So vote for your favorite feature listed above, and we'll let IBM know which ones are most favored by our readers. And if you don't see a feature you'd like, mention it in the forums discussion associated with this article. This is a chance for those of you who don't usually voice your opinion to either vote or make yourself heard!

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.

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: