Midrange News for the IBM i Community


Posted by: Bob Cozzi
Rogue Programmer
Cozzi Productions, Inc.
Chicagoland
RPG IV+ The Next Generation Arrives
has no ratings.
Published: 07 Oct 2013
Revised: 17 Oct 2013 - 1373 days ago
Last viewed on: 21 Jul 2017 (6233 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

RPG IV TR7 IBMi Published by: Bob Cozzi on 07 Oct 2013 view comments(1)

© Robert Cozzi, Jr. All rights reserved. Reproduction/Redistribution prohibited.
A midrangeNews.com Publication

RPG IV is now Free Format

How to turn a Legacy Tool in to the Modern RPG Language™

Disclaimer: While I was disclosed on these updates prior to announce, I was given the material with a "too late to change anything" timeline. So while I applaud the effort, I would have done some things differently. As I said, unfortunately I wasn't involved earlier enough for it to matter.

IBM today, announced the 5th generation of the Modern RPG Language, although its still called "RPG IV".  The new version removes the issues with /FREE and /END-FREE as they are no longer supported. In addition, all H, F D and P specs are free format (fixed-format versions of these specs may be freely intermixed, pun intended) however the legacy I and O specs for program-described data are still required; the compiler detects the I or O in column 6 and behaves accordingly.

Since their doesn't seem to be an official new name for this flavor of RPG, I'm calling it RPGIV+ for simplicity.

Sponsored by: Cozzi Tools

COZTOOLS Providing the Solutions for RPG IV and CL development.

We've already written the tools you need in your RPG code so you don't have to.

Featured CL Commands:

  • CPYTOCSV - Copy to Excel-compatible CSV format.
  • CPYFRMPDF - Copy PDF on your IFS to an PDF-compatible printer.
  • CPYOUTQ / CPYPRTF - Copy a SPOOL file or entire Output Queue(s) to another OutQ or to PDF.
  • RTVDATE - Retrieve Relative Dates into a CL variable.
  • SAVLIBL / RSTLIBL - Save the library list and restore the library between calls to other programs.

Visit: www.cozTools.com

Ad

The biggest change you will find in RPGIV+ is the use of the dash or hyphen or minus sign in the opcodes. In fact, everything is now referred to as an OpCode so there's no "D-spec" in RPGIV+ just DCL-xxxx where "DCL-" is the CL style Declare opcode, and xxxx is the object type being declared. Yes, IBM doesn't know how to do "DCL PROC" only "DCL-PROC" so get use to it. In fact, the DCL-xxx opcodes replace the F, D and P specifications.

Free Format Declare Statements

With this in mind, lets review the new Declare Specifications:

  • DCL-F
    • Declare a File. Replaces the File Spec
  • DCL-S
    • Declare a Stand-alone field. Replaces the D spec with the S in column 24.
  • DCL-DS
    • Declare a Data Structure. Replaces the D spec with the DS in columns 24-25.
  • DCL-C
    • Declare a Name Constant.
  • DCL-PR
    • Declare a Prototype.
  • DCL-PI
    • Declare a Parameter List (aka, Procedure Interface)
  • DCL-PROC
    • Declare the start of a SubProcedure. Replaces the beginning P spec for a procedure.
  • END-xxxx
    • Define the End of one of a corresponding DCL-DS, DCL-PR, DCL-PI and DCL-PROC statements. e.g.,
    • END-DS ends a data structure
    • END-PR ends a prototype
    • END-PI ends a procedure interface
    • END-PROC ends a subprocedure implementation

The only other new OpCode is the Header Specification. It is identified as CTL-OPT. So I guess we have to call the Header Spec the "CONTROL OPTIONS" statement.  To use it, you specify CTL-OPT followed by a Header specification keyword. People I've spoken with have indicated that they'll be sticking with the H in column 6.

Optional Declare Statements

When declaring parameters or subfields there are explicit opcodes available. These opcodes are typically optional, however if a field name is also a classic RPG IV opcode name, then these new DCL-xxx opcodes are required, and they are:

  • DCL-SUBF
    • Declare a data structure subfield
  • DCL-PARM
    • Declare a parameter

Again, only when the field being declared has an opcode name, like SELECT, CHAIN, WHEN, FOR, etc. then the DCL-SUBF or DCL-PARM opcodes are required. Otherwise the compiler understands that within DCL-PI and END-PI opcodes, all entities are Parameters, and between DCL-DS and END-DS all entities are subfields.

Example RPG IV+ Program

While this is a huge change to the RPG IV language, it is really not a big change once you get your brain around it. Here's a simple example app that accepts one 10-character input parameter and writes a message along with the parameter value to the joblog.

        ctl-opt  option(*NODEBUGIO:*SRCSTMT) DFTACTGRP(*NO)         
               BNDDIR('COZTOOLS/COZTOOLS');                       
     /include cozTools/qcpysrc,joblog                                 
        dcl-proc  helloRPG;                                         
       dcl-pi   *N;                                                
         msg  char(10);                                           
       end-pi;                                                      
                                                                  
       joblog('Hello from RPG IV+  %s': %trimR(msg));               
       end-proc  helloRPG;                                          

I suppose we will get used to these changes eventually--but it took 15 years for most RPG programmers to start using free format, so I won't be looking for most programmers to start using this newer stuff any time soon. The good news is, it does work on V7R1 so that may be a reason for earlier adoption than standard free format.

Miscellaneous Changes

There were some required changes to the language itself. Only a hand full of things have been added, and they are:

  • The OVERLAY keyword when referring to the Data Structure Name, must be replaced with the new POS keyword.
  • The EXFLD keyword requires the use of the DCL-SUBF opcode.
  • Compiler Directives (/IF, /DEFINE, /COPY, /INCLUDE) no longer have to be coded in column 7--they may start in column 7 to 78.

Challenges

RPGIV+ will be taught at conferences and online probably starting this year, as if it were being used in every shop in the world, except yours. Don't worry, it'll be 5 years before people start using it in any volume. So if you want to be an early adopter, go ahead, since it does NOT require V7R2 you won't be eliminating too many systems on which your code can run. I've been using RPGIV+ for a while and it seems to be working fine. There are only two things that continue to bug me when I use this version of RPG:

  1. The syntax and spelling of the parameters for the DCL-F (declare file) keyword are verbose at best. Most parameters have intelligent defaults, so I may not be a problem--the examples in the manual will guide whether or not programmers use them vs the F spec and the Prompter.
  2. The Header Spec keyword is CTL-OPT, which to this day, I spell CTRL-OPT. Does anyone abbreviate the word "Control" as "CTL"? Ctrl+Alt+Del. I'm going to stick with the H spec for now.

Neither issue is a show-stopper. The good news is the defaults for the various device types is accurate, therefore you don't really have to use the rather verbose declaratives. The CTL-OPT thing is just going to for us to start spelling CTRL wrong on other systems, or not use it at all, and change the compiler statement defaults instead.

Really Cool Feature

RPGIV+ is the first version of RPG to include a quasi macro language. You can now use the /IF, /ELSE, /ELSEIF, and /ENDIF statements to control how code is generated. I suppose you could always do this, but now you have easier keyword-level control. For example:

        dcl-s myDate  
              /if defined( DATE_TODAY )
                 inz(*SYS)
              /else
                 inz(*loval)
              /endif
              /IF defined(USER_USA)
                 date(*USA)
              /else
                 date(*ISO)
              /endif
                 ;

As you can see, while it looks a bit complex, it has become more powerful. And yes, /IF statement may appear anywhere on the line.

Legacy is Still Short-Changing RPG

RPGIV+ requires statements to appear in column 8 through 80. Column 1 to 5 are still that goofy S/36 comment area, while column 6 may be blank, I or O (or one of the legacy Specs if you want to intermix things). In addition, column 7 may contain the typical / (slash) symbol of a /INCLUDE, /COPY or other directive, but NOT /FREE or /END-FREE as they are no longer used.

More...

The compiler more auto-adjusts to the syntax you use in your code. So there is no separate compiler for this new free format syntax. Just start using it as soon as you get V7.1 TR7 installed or related PTFs.

Look for more information in the IBM V7R1 TR7 Refresh InfoCenter starting October 8, 2013. You can also see a bit more examples that Barbara Morris of IBM Canada, Ltd. has posted in Developerworks. You can download the IBM RPG IV TR7 Reference manual from this link or visit the InfoCenter.

Cozzi Tools - We've Already Written the Hard Part for You

The COZTOOLS ("Cozzi Tools") software product is available at www.cozTools.com Be sure to check out the list of included CL commands and the growing list of examples we provide.

Contact Me

Bob Cozzi is a technical advisor to IBM i clients around the world. His specialty is solving difficult programming issues for his clients, training their programming staffs, and performing system migration/upgrades for small shops. His consulting rates are available online. To contact Bob, send an email to: bob at cozTools.com

You can subscribe to RPG Report (we call it "follow") by visiting the RPG Report page on midrangeNews.com and then click the FOLLOW link in the table of contents for that page. To unsubscribe, simply click that same link. You must be signed up and signed in to midrangeNews.com to start following RPG Report.

Follow Bob Cozzi on Twitter

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: tdaly
Premium member *
Comment on: RPG IV+ The Next Generation Arrives
Posted: 3 years 9 months 5 days 4 hours 51 minutes ago

I like elimination of  /free /end-free, the rest doesn't really do anything for me. I'm on board with going free form, but this syntax seems a bit clunky and for no real gain.