02
Sat, Nov
2 New Articles

RPG IV Enhancements in OS/400 V5R2

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
The ink is barely dry on the early announcement of OS/400 V5R2, and already I'm hearing about planned enhancements for next year's V5R3 announcement. OS/400 V5R2 was announced early so that IBM could ship its new high-end "mainframe" midrange i890 system. The eServer iSeries 890, known as the "i890," is a 24-way Power4 system that is just about the fastest thing in the solar system as of this date. If IBM is listening, please send my free evaluation unit as soon as possible.

But what is really important to us lowly old RPG coders is what IBM has done to the development tools and to RPG. I can safely and summarily report that nothing has been done to SEU and PDM. Yes, IBM still believes we all use CODE/400 or CodeStudio, but only about 1 out of 40 of us seems to get it.

There is more news in V5R2 regarding RPG IV. This marks the first time IBM has enhanced the language in two consecutive releases since V3R2. Let's take a look at some of the RPG IV enhancements in V5R2.

Increased Numeric Field Length

Packed and zoned decimal fields may now be declared with up to 31 digits (up from 30). This subtle increase was added to provide compatibility with tables created with SQL. A new keyword is added to the Header specification. The DECPREC(31) keyword causes all expressions to use 31 digit numeric "work" fields. The keyword is not needed to simply use a 31-digit number.

Converting Character to Numeric

A long-standing requirement in RPG has been to convert number data stored in a character variable to a numeric variable. You could do this on a limited basis using the traditional MOVE opcode; however, there was no way to do this with an EVAL operation.

In V5R2, IBM is adding integrated character-to-numeric conversion to several built-in functions, including %DEC, %INT, and their associated variations. This means that if you have a numeric value stored in a character string, moving it into a valid numeric field will be unbelievably easier than before. For example:

.....DName+++++++++++EUDS.......Length+TDc.Functions+++++++++
0001 D QtyOrd          S             20A   Inz('18')
0002 D QtySold         S              7P 0
.....CSRn01..............OpCode(ex)Extended-factor2++++++++++
0003 C                   Eval      QTYSOLD = %Int(QtyOrd)

The above example would result in the QTYSOLD field being assigned the number 18. This will come in very handy for all those CGI RPG and XML applications being created.

Data Structures Enhancements

The first thing you'll notice in V5R2 with regard to data structures is that IBM has deprecated the OCCURS keyword by introducing the DIM keyword for data structures. By using DIM, a data structure occurrence can be accessed using the same syntax as an array. This means the OCCURS opcode also becomes passé.

The overhaul of the data structure feature didn't stop there. V5R2 also introduces the concept of nested data structures--data structures that have a subfield that is also a data structure. Each nested data structure may also have the DIM keyword, providing a capability to RPG IV previously seen in C, C++, and Java.

To declare a subfield as a data structure, IBM enhanced the V5R1 LIKEDS keyword. In V5R2, LIKEDS may be specified on a data structure subfield, causing the subfield to inherit the properties of the referenced data structure.

To access a value in a subfield data structure, traditional RPG IV array syntax is used. That is, the data structure name is followed by the index, with the index enclosed in parentheses. See line 12 in Figure 1 for an example.

.....DName+++++++++++EUDS.......Length+TDc.Functions+++++++++++++++++
0001 D ItemSold        DS                  BASED(ptr)
0002 D  ItemNo                        7P 0
0003 D  Qty                           5P 0
0004 D  Price                        11P 2
0005 D  Status                        1A

.....DName+++++++++++EUDS.......Length+TDc.Functions+++++++++++++++++
0006 D MyStruct        DS                  DIM(20) QUALIFIED
0007 D  OrdNo                        11P 0
0008 D  CustNO                        7P 0
0009 D  LineItem                           LikeDS(ItemSoldDim(50)
0010 D  OrdTotal                     11P 2

.....CSRn01..............OpCode(ex)Extended-factor2+++++++++++++++++++
0011 C                   Eval      CurItem = 
0012 C                                MyStruct(x).LineItem(y).ItemNo

Figure 1: Data structure "arrays" and qualified subfield syntax

As mentioned, the LIKEDS keyword may now be specified for a data structure subfield, thus providing a nested data structures feature to RPG IV. In addition, the INZ keyword accepts a new option of INZ(*LIKEDS). This option causes the subfields of the new data structure to inherit the initial values from the subfields of the referenced data structure.

Storing RPG IV Source on the IFS

With the combination of CODE/400, Eclipse, and CodeStudio, you probably have close to five percent of the RPG developers in the world using a non-SEU solution for RPG source code editing. These tools read and save the source code onto a local PC disk or on the Integrated File System (IFS). Then, when the program needed to be compiled, the source needed to be moved into a traditional OS/400 source file member. With IBM's support for IFS in V5R2, the RPG IV compilers can compile RPG IV source directly from a text file stored on the IFS. The new SRCSTMF parameter of the CRTBNDRPG and CRTRPGMOD commands identifies the IFS source file name to compile. This is a nice option, but, of course you can continue to use the traditional source file and member structure that is familiar to you.

Short-Form Expression Arithmetic

One of the nice things about the traditional RPG ADD, SUB, MULT, and DIV operation codes was that they supported short-form syntax. That is, Factor 1 could be omitted from the operation code, and the Result field would be used in its place. Enter the EVAL opcode and free-form arithmetic. Unfortunately, the initial implementation requires complete expressions--no short-form support. So X=X+1 was required to add 1 to the variable named X. In V5R2, IBM has added short-form expression arithmetic, which allows you to omit the replication of the result variable on the left side of the expression. So to add 1 to X using the new short-form operation, X+=1 would be specified.

Short-form operations are now supported for +, - , *, /, and ** operations.

Bitwise Built-In Functions

Continuing its tradition of introducing new built-in functions in each release, IBM has nearly completed the expression support in RPG IV by introducing bitwise built-in functions. These include bitwise AND, OR, XOR, and NOT. One nice feature of these built-in functions is that they are supported on both the Definition and Calculation specifications. This means that the bitwise built-in functions may be used in expressions and as the initial value for fields.

Potpourri

A few other enhancements to RPG IV in V5R2 include the ability to specify a variable name for the name of the external data area (are people still using data areas?). Program Call Markup Language (PCML) generation by the compilers allows PCML tags to be generated so that your RPG program can be called by a Java application.

The new keyword LIKEREC allows you to declare an externally described input file record format and then use that record format as a template for a data structure. The LIKEREC keyword works similar to the LIKEDS keyword, except the referenced item is an externally described record format.

The database I/O opcodes--such as CHAIN, UPDATE, WRITE, READ, and READE--will support a list of field and host variable names that allow them to support a level of functionality similar to embedded SQL I/O commands.

The EXTNAME keyword, used for externally described data structures, can now be tailored to include only input, output, or keyfields from the external file.

Summary

All in all, this release has a couple of great enhancements, such as the updates to the %DEC and %INT built-in functions, and the DIM keyword on data structures. Some things, such as the V5R1 QUALIFIED keyword continue to confuse me. Do I need to always use it? Do I need to not use it? Is it required here and illegal there? Do I use it only when I use LIKEDS or only when I don't use LIKEDS? Is it implied when I use LIKEDS? If so, why not make it a global implication and eliminate it altogether? Not my favorite implementation. QUALIFIED should probably have never seen the light of day.

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

$

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: