Monday, May 23, 2016

The different flavors of free format RPG

different types of rpg free format programming

I am sure that I have confused readers with the names I call the different flavors of free format RPG. I thought it would be best to have a post where I describe each flavor, and then refer the reader to this post from others when I need to explain the differences.

Before I start I just want to explain that these are the names I call the different flavors. These might not be (probably definitely not) the names that IBM would call them, but I do call them this.

In my opinion there are three flavors of free format RPG:

  1. Free format calculations
  2. Free format definitions
  3. Totally free form

ILE RPG, RPGIV, or RPGLE was introduced by IBM as part of V3R1 in 1994. It still had a column centric format, but the EVAL operation code, with its "extended factor 2", gave us a foretaste of what free format could look like.

  FINVMST    IF   E           K DISK

  D wkCorp          S                   like(CORPNO) inz('100')
  D wkInvoice       S             10

  C     klist1        klist
  C                   kfld                    wkCorp
  C                   kfld                    wkInvoice

  C                   eval      wkInvoice = 'I035552120'
  C     klist1        chain     INVMSTR
  C                   if        (%found)
  C                   endif

  C                   eval      *inlr = *on

 

Free form calculations

Seven years later, 2001, came the first free format flavor. V5R1 came with RPG free format calculations. All I had to do was insert /FREE and I could write all of what had been Calculation specifications in free format code. Alas, some of the functionality that had been available in the fixed format was not available in the new free format. Fixed format code could be inserted amongst the free just by placing a /END-FREE on the line before the fixed format line, and a /FREE on the line after to return to free format. The flipping in and out of free format code became a pain-in-the-neck when coding procedures, and I am sure this dissuaded many from adopting them.

While the free format code was not columnar, like the fixed format specifications, it was limited to where it could be in the source code. It could not start before the eighth column, and not extend beyond the 80th.

  FINVMST    IF   E           K DISK
  D wkInvoice       S             10
   /free
    wkInvoice = 'I035552120' ;

    chain ('100':wkInvoice) INVMSTR ;
    if (%found) ;
    endif ;

    *inlr = *on ;

 

Free format definitions

It made sense for the next development in free format was to make the definition specifications free. That came in a PTF that accompanied IBM i 7.1 TR7, in November 2013. This liberated the Header, File and Data definition specifications. It is interesting that the Input and Output specs were not freed, I think this is IBM saying that we need not to stop using them. It did away with the /FREE, allowing me to easily intermingle free and fixed format code.

I have written extensively about free format definitions and the other changes in the posts listed below.

Alas, even though those specifications were freed I still could only code them between the eighth and 80th columns.

...+... 1 ...+... 2 ...+... 3 ...+... 4
       dcl-f INVMST keyed ;

       dcl-s wkInvoice char(10) ;

       wkInvoice = 'I035552120' ;

       chain ('100':wkInvoice) INVMSTR ;
       if (%found) ;
       endif ;

       *inlr = *on ;

 

Totally free form

The final act of liberation came in November 2015 in IBM i technology refreshes 7.2 TR3 and 7.1 TR11. Now I could start my free format RPG code in the first column and, if I want to "go all the way" I can go to the 240th column! All I have to do is to have **FREE starting in the first column to inform the compiler I am going totally free.

Alas, by going totally free form I lose the ability to easily insert fixed format code amongst the free format. There is a way to do it, I am not going to explain how to do it here as I have written about it in the post linked below:

...+... 1 ...+... 2 ...+... 3 ...+... 4
**free
dcl-f INVMST keyed ;

dcl-s wkInvoice char(10) ;

wkInvoice = 'I035552120' ;

chain ('100':wkInvoice) INVMSTR ;
if (%found) ;
endif ;

*inlr = *on ;

 

Jon Paris, IBM i guru, wrote six articles accounting the evolution of free format. As he was involved in the process it is interesting to have the chance to peek behind the curtain to see why it took IBM so long to give us totally free format. His post here provides links to all six parts in one place.

9 comments:

  1. How to use "like" keyword in free format?

    ReplyDelete
    Replies
    1. You will find examples of using the "like" when defining variables in the post Defining variables in RPG all free, which I provided a link to above.

      Delete
    2. In my opinion, if a variable is used just once or twice in the program, it is better to define it next to where it is used. This gives me one more reason to stay with /Free and not move to **Free.

      Delete
  2. I know we run into the same issues, many I work with call it "all free" for when the Header and D-Specs went free form but i consider "all free" when you can use **FREE at the top to code on line 1 and past 80

    ReplyDelete
  3. How do you move a array to field in free format. I did field1= arr1

    ReplyDelete
  4. Hans Boldt, the RPG compiler lead at that time, had written this article about the history of free format. I think everyone here would be interested in reading it:

    http://omnifarium.blogspot.ca/2013/11/a-short-history-of-free-form-rpg.html

    ReplyDelete
  5. RPG All FREE will work in SEU also ? or only in RDPI?

    ReplyDelete
    Replies
    1. You can code any of the forms of RPG mentioned above in SEU. You just need to turn off "syntax checking" in SEU, see here how to do it.

      Delete

To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.