Tue, Jun
3 New Articles

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 This email address is being protected from spambots. You need JavaScript enabled to view it. 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



Support MC Press Online

$0.00 Raised:

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: