You may have heard that entirely free-form RPG is now available; this tip tells you how to start working with it.
RPG /free (also known as free-form RPG) has recently gone entirely free. At least, the compiler has. Unfortunately, the source editing tools haven't caught up yet (and in the case of SEU, I don't think they ever will). That's probably the reason that you won't see the new compiler capabilities even if you update to the latest Technology Refresh. Instead, you'll need to install a specific PTF. Then you can at least compile a program, even if the editor doesn't like it.
First Things First
First, go take a look at the free-form RPG timeline. You'll see that free-form has been coming for some time; starting with the release of version V5R1 back in 2001. So 10 years in the making, and now we've got a great new dialect of the RPG language. To give you an idea of what a completely free-form RPG program looks like, here's a very simple example. This is the free-form version of a program I used in a previous article on BIFs. The program simply applies a couple of BIFs to strip some characters (specifically dashes, slashes, and spaces) from the input parameter. It returns the stripped value (after displaying it for debug purposes).
ctl-opt dftactgrp(*no) actgrp(*new);
dcl-pi *n;
dcl-parm iField char(30);
end-pi;
iField = %scanrpl(' ':'':%xlate('/-':' ':iField));
dsply iField;
*inlr = *on;
On the first line, you'll see that the H-spec has been replaced by the ctl-opt statement. Hopefully, you've had a chance to get familiar with the various keywords of the H-spec; if you have, these same keywords are available to the ctl-opt statement, so the conversion is very simple. The H-spec is an example of a simple statement: it starts at the ctl-opt keyword and ends at the semicolon. While it may span multiple physical source lines (because of the number of keywords), the H-spec is a single logical statement. Several of the new statements are like that, including the F-spec replacement (dcl-f) and the statements to define variables (dcl-c and dcl-s).
Next, we see an example of the dcl-pi statement, which replaces the PI (procedure interface) D-spec. This type of statement has a slightly different syntax: it's a multi-line statement that starts with a dcl-pi and ends with an end-pi, both of which are on separate lines and terminated with a semi-colon. The parameters are sandwiched between the dcl-pi and end-pi (in this case, only one parameter, iField, is defined). Currently three statements—data structures, procedure interfaces, and prototypes—use a beginning and an ending line with nested child statements in between. Prototypes and procedures have parameters (dcl-parm) as children, while data structures have subfields (dcl-subf). Much like the eval and callp opcodes, dcl-parm and dcl-subf are optional as well. I could have coded the prototype like this:
dcl-pi *n;
iField char(30);
end-pi;
How Do I Get This Stuff?
Well, as I noted above, you can get the compiler enhancements today. Just order PTF SI51094 (more information can be found on this page). If your system is set up to electronically obtain PTFs, just execute the command SNDPTFORD PTFID((SI51094)) and then apply the resulting PTF. I found the announcement a little confusing; even though the new free-form RPG enhancements were announced as part of Technology Refresh 7 (TR7), the announcement specifically states that you don't need TR7 in order to get and apply the PTF, and not only that, but TR7 doesn't even include the RPG compiler PTF. You have to order it separately. TR7 does include changes to the SQL precompiler in order to support the new keywords, although it's not entirely clear to me what would happen if you applied TR7 but didn't apply SI51094. Would an SQLRPGLE program with the new syntax compile? My guess is that it would not, but I haven't tried it.
I am confident, though, that the program above will compile on any system with SI51094 installed, regardless of whether TR7 has been applied. The program will compile and run, although even Rational Developer for i gets the heebie-jeebies when it sees free-form code:
ctl-opt dftactgrp(*no) actgrp(*new);
RNF5347E An assignment operator is expected with the EVAL operation.
As you can see, the editor doesn't quite know what to make of the ctl-opt statement. And while getting the syntax errors is a pain, the real pain is that the syntax isn't integrated into either the tool or the help text, so you'll need to go to IBM's old-school PDF syntax manual to see the new syntax. But despite all the negatives, I highly recommend learning the new syntax. The ability to write programs without any /free or /end-free, with no fixed-format specs of any kind, and with a consistent free-flowing style is worth dealing with the growing pains now, especially since you know the rest of the tools are going to have to catch up sooner rather than later.
LATEST COMMENTS
MC Press Online