Diving Deeper into RPG /Free

  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

In the last article, we started building a /Free program, something that we could use as a model, but we didn’t get far enough to even be able to compile it. Let’s fix that right now and get this baby off the ground.

Editor's Note: This article is excerpted from chapter 4 of 21st Century RPG: /Free, ILE, and MVC, by David Shirey.

I am taking it slow to start with. I want to show those people who are not on 7.2 that they can grow, too. Modern approaches are not exclusive to those whose management realizes it is important to use the new tools. It is something that almost everyone can do. But it’s something you do one step at a time, and I don’t want to scare off or leave anyone behind.

Now, let’s continue on with developing that /Free model.

Please note that I am not talking here about the /end-Free tag. That ends a /Free code section but does not actually end a program. No, I am talking here about the LR indicator and how it is used in the /Free world.

In one sense, there is no change in /Free in terms of how you end a program. The need to set the LR indicator on is driven not by /Free or positional, but by the program model, OPM or ILE.

In the OPM world, we tend to write monolithic programs, or BOPs (Big Ol’ Programs). When we are done, you need to close the program and reclaim all the resources.

And you can do the same in ILE, although with ILE you are hopefully writing smaller modules or using sub-procedures and service programs, which do not use the LR. Plus, with ILE you have activation groups to consider, and that will change what happens when your program ends.

That said, what has changed in /Free is the way we code up setting the LR. The SETON opcode from positional didn’t make the cut into /Free, so to end a /Free program you have to code it up like this:

*INLR = '1';

Since it is a logic statement, you will start it in column 8 or beyond and before the /end-Free, if you are using one.

You may think that this violates what we said in a previous chapter about indicators and /Free. But it doesn’t. Indicators are supported in /Free, although there are other ways to do things, and, except for the INLR, it is hoped you will stop using IN43 to control things. What is no longer supported, however, are indicators in I/O statements. We will talk more about that later.

VERY IMPORTANT: Every /Free statement or clause will end with a semicolon. That is what tells the compiler that one statement is finished and another is starting (because a given /Free statement might be spread out over several lines).

Diving Deeper into /Free - Figure 1


This section should probably have come before we talked about ending the program because comments should always come before you do any logic statements. Otherwise, they never get added. You know how it is. Fortunately, comments are easy to do in /Free.

Just set them up preceded by two slashes (//). The // can go in any two adjacent columns from 8–80. After the //, you can put whatever you want; it’s comments.

// The following program is very likely to blow up at

// the weirdest times. Good luck.

You can even put the comments after the end of a valid /Free statement, but I really don’t like that. Just a personal thing.

*inlr = '1';         // This is the end of the program.

Interestingly enough, you can also use the // for comments in positional RPG. I never knew that. I probably won’t do it, as it seems sort of traditional to use * in positional, but then I hope I won’t have too much coding using positional anyway, so it’s not a big deal.

Diving Deeper into /Free - Figure 2

EVAL Statement Stuff

Now that we have a functioning shell, let’s start doing things “the /Free way.”

The first thing we will do is very simple. Let’s add an EVAL statement to the skeleton program. Now remember, we said that some opcodes were not transferred over to /Free, and one of those was the MOVE (in all its forms). I will give you just a moment to stop hyperventilating, and then we will move on. (Get it? “Move” on. I kill myself!)

Anyway, in /Free, all value setting will be done with the EVAL opcode. When doing an EVAL, you can specify the EVAL opcode:

eval name = 'Dave';

or else just skip the opcode entirely (which is what the cool kids do) and use this:

name = 'Dave';

where name is obviously a variable either from a file or a D-spec or somewhere. By itself, /Free has not changed variable-naming standards (it can’t start with a number, blah, blah, blah), although you can use longer names. Neither has it changed the maximum size of a variable or the types of variables you can define. That was done separately from both /Free and ILE in various operating system releases.

One thing that is very important is that in /Free, variables cannot be spontaneously defined within the code; they must be set up prior to the execution steps.

The statement can be set up anywhere from column 8 to 80 (unless you are on 7.3), so you have the ability to stack things for easy viewing. For example:

Diving Deeper into /Free - Figure 3

One thing to keep in mind about the EVAL is that it only allows you to relate fields that are of the same type or accept data of the same type (numeric or character oriented). That is, you can’t use the EVAL to move packed data into a character field. There are ways to do that, but not by using the EVAL by itself. Later we will look at how to do that with BIFs.

Diving Deeper into /Free - Figure 4

EVAL Opcode Extenders

Another thing to mention is that you can use the opcode extenders—h, m, and r— with the EVAL statement (although then of course you must use the EVAL opcode and not omit it). For example:


All of this looks pretty simple, doesn’t it? And it is. I mean that’s the whole idea behind /Free, making things simpler than they were before. As we go through this book, however, we will see the EVAL can be a complex statement.

For example, later we will see that the EVAL can use not just variables, but BIFs and other complex things as elements in the equation. And, under the heading of ILE, we will see that we can even use the EVAL to call other modules—generally called a function call—rather than using the CALLP. So it is simple, but we will see the EVAL with but mostly without the opcode EVAL, in many places and guises.

Other EVAL Opcodes

As I mentioned, IBM did not bring the MOVE opcodes over into /Free, so you use the EVAL. But there are a few different flavors of that command.


This EVAL allows you to move a group of identically named fields from one data structure to another.

EVAL-CORR data_struc1 = data_struc2;

where data_struc1 and data_struc2 have at least some field names in common.

This opcode can be used with both /Free and positional RPG, but when you use it in /Free you can include the h/m/r extenders. No room for them in positional.


And this one will perform the evaluate and then right adjust. Since it is only for character fields, there is no h extender.

EVALR MSG = 'Function Successful';

If we assume the MSG field is 25 characters, then the result will be

'      Function Successful'.

You can try these if you want, but it’s pretty simple. You may not even ever use them. Who knows?

David Shirey

David Shirey is president of Shirey Consulting Services, providing technical and business consulting services for the IBM i world. Among the services provided are IBM i technical support, including application design and programming services, ERP installation and support, and EDI setup and maintenance. With experience in a wide range of industries (food and beverage to electronics to hard manufacturing to drugs--the legal kind--to medical devices to fulfillment houses) and a wide range of business sizes served (from very large, like Fresh Express, to much smaller, like Labconco), SCS has the knowledge and experience to assist with your technical or business issues. You may contact Dave by email at or by phone at (616) 304-2466.

MC Press books written by David Shirey available now on the MC Press Bookstore.

21st Century RPG: /Free, ILE, and MVC 21st Century RPG: /Free, ILE, and MVC
Boost your productivity, modernize your applications, and upgrade your skills with these powerful coding methods.
List Price $69.95

Now On Sale

More Articles By This Author
Related Articles


Support MC Press Online

$0.00 Raised:


   Support MC Press Online

MC Contributors Header 785x150

Support MC Press with a contribution of any size.

Your support helps MC Press deliver free quality information about the new and legacy technologies you rely on to IT Professionals everywhere. Our goal continues to be helping you become more productive on the job and get more out of your career. Every contribution, regardless of size, furthers that goal.