RPG is now a completely free format language!

Posted by Pascal Polverini on Oct 23, 2013 11:00:00 PM

    

The announcement of the IBM i 7.1 Technology Refresh (TR7) includes a breaking feature:

RPG Dude Pascal Polverini

RPG is now completely free format!

All the traditional specifications for control, file, field, table, data-structure, procedure, etc... can now be declared in free format! No more fixed column positioning constraints to declare elements in your code.

The code declaration becomes more meaningful, more fluent and more friendly.     

Existing programmers, and above all, newcomers to RPG, will greatly appreciate this and there are strong indications that it will contribute to the growth of the IBM i community. 
 

The syntax for free format declaration statements uses dcl-spec and end-spec, where spec represents the type of declaration.

 

For instance, for a data-structure (DS) we have:

dcl-ds myDS;

   field1 char(10);

   field2 char(20);

end-ds;

 

For statements without sub-fields nor parameters there is no end-spec.

For instance, for a display file we have:

            dcl-f myDspf workstn;

 

For control specs we have a ctl-opt statement:

            ctl-opt dftactgrp(*no);

 

Some will argue that this new free-form syntax should have used curly braces to delimit blocks, as follows:

            spec { ... }        vs.        dcl-spec ... end-spec;

If that had been the case, the "if" and "for" calculation statements would need to be reviewed and revisited. What we can say is that the dcl-spec style avoids any confusion.

 

Another advantage is the simplification of element type definitions.

For instance, for fields we have:

            field3 varchar(100);

            field4 zoned(5:2);

            field5 int(10);

For files we have:

            dcl-f qprint printer(length);

            dcl-f myFile usage(*update) extfile('MYLIB/MYFILE');

 

The I and O specifications are not included in free-format RPG and this is a deliberate move. Using program-described input or output file specs is bad practice. It is dreadful to maintain and disables any multi-tier approaches.  

 

Fixed-form can still be mixed with free-form and there is no need to use /free /end-free anymore.

 


This new feature represents a turning point:

Generally speaking, it is always good for a programmer to know more than one language.

Before this enhancement, programmers new to RPG found it difficult to apply their knowledge of other languages. Now, the learning curve for non-RPG programmers is far more gradual. The path is set to welcome them to the best programming language for business machines.

References:

ILE RPG Reference - Section: What's New since 7.1:
http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/topic/books/sc092508a.pdf

You and i - Steve Will
http://ibmsystemsmag.blogs.com/you_and_i/2013/10/announcing-ibm-i-71-tr7.html

Developer Works - Barbara Morris
https://ibm.biz/BdDMwB


Pascal Polverini
Author
Pascal Polverini
IBM i ISV Advisory Council

 

Topics: IBM i, RPG Open Access, IBM i Redbook