24
Sun, Nov
1 New Articles

More Free-Form for RPG, Part 2

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

RPG took a great leap forward when free-form C-specs were introduced. Now, with a PTF on V7.1, you can extend that to do free-form H-, F-, D-, and prototype-oriented specs. Want to know more about it?

 

In our last exciting episode, we looked at free-form in RPG in general and started to go through the new additions for the V7.1 PTF by looking at the replacements for H-specs (option control statements). Now it's time to move on to the other positional specs and their free-form control statements counterparts.

File Control Statements: Basic Format

Let's start with the F-specs. Like all control statements, the file control statement starts with the statement keyword (dcl-f), followed by the name of the file, followed by whatever other keywords might be required. For example:

 

dcl-f MSPMP100 DISK;

 

Of course being free-form, you can write it in sentence format like this or put a few spaces in there so it's easier to read, such as this:

 

dcl-f       MSPMP100       DISK;

 

DCL-F     pspsp100         DISK;

 

Or however you want it to look.

Some Other Things You Should Know

What types of files can you define here? Full procedural and output files only. You cannot define tables, record address files, or cycle files with this statement. So what do you do if you just can't live without one of those files? Simple: fall back on the F-spec. Remember from last month's article, you can use either the F-spec or the file control statements and even mix them together with no problem. The same is true of other specs and control statements including C-specs and /free RPG code.

 

How long can the name be? You can use names longer than 10 digits as long as you use the EXTFILE keyword with a value of *EXTDESC with it. Then the EXTDESC keyword will contain the 10-digit name of the file. And if you were a fan of using ellipses here, can't do that anymore. It should also be noted that you can't use any of George Carlin's "Seven Words You Can't Say on Television" in the file name, although most people under 35 use them constantly in casual conversation.

 

dcl-f       Product_Master_File   Disk EXTFILE(*EXTDESC)

                                                         

                                           EXTDESC('MSPMP100');

 

Is there some sort of order you need to list all of this stuff in (since it's not positional anymore)? Of course! What do you think we are, animals? You start with the "dcl-f" thingy. Then comes the file name. Then the first keyword you need to specify is either the device keyword (DISK, PRINTER, SEQ, SPECIAL, or WRKSTN) or the LIKEFILE keyword. After that, it's a free-for-all. And speaking of the device keyword, here's some more stuff.

The Device Keyword

If you don't key in this third element (dclf-f is first, and file name is second), the system will assume that it's DISK, but I really think that's RBFJ (Really Bad Form, Jack). It's a couple of lousy characters. Just key it in.

 

If the file is externally described, you can use the EXT value in parentheses with the device keyword: DISK(*EXT) or PRINTER(*EXT). But that value is the default, so here you can ignore it and I don't consider that RBFJ. I know, it's a judgment call, but it makes sense to me.

 

If we're dealing with a program file, then you specify the length of the record along with the file type: PRINTER(132).

 

Confused? Let's look at a couple of examples. The first is a printer file with a name longer than 10 digits.

 

 

dcl-f           year_end_report                 printer           oflind(overflow

                                                                  extdesc(‘XXXXX’)

                                                                  extfile(*extdesc);

 

Again, note that I have listed the three keywords in a vertical format, but that's not required, and there's no particular column that these have to start in (hey, this is free-form). But I like to list the keywords in a vertical format and so do most cool people. It's up to you, though. Just keep everything in columns 8 – 80 and you won't get any compiler errors.

 

One thing that should be re-mentioned here is that, because this is free-format, you need to end each statement with a semicolon. The question is, does this mean a semicolon on every line? The answer is no, just on the final line of the control statement. Remember, even though I like to put things in a vertical format, each dcl-f statement is a single statement.

The Keyed Keyword

Remember the K flag to indicate a file was keyed? That has been replaced by the Keyed keyword.

 

For an externally described file, there is no value attached to the keyword.

 

dcl-f     MSPMP100     DISK     Keyed;

 

For a program described file, you can indicate a value of *CHAR:len, where len is the length of the key (duh). Unfortunately, I guess, only *CHAR keys are supported right now. But then again, I don't dig program described files. Why not define it externally? Are you ashamed of it? Whatever, in the example below, we have a program defined file with a length of 120 and an 8-character key.

 

dcl-f     Prog_File     Disk(120)     Keyed(*CHAR:8);

 

What if you have a packed key? Well, then you make it an externally described file. Or, if you insist, either through willfulness or the same type of behavior that has been strongly linked to juvenile delinquency and drug abuse, you can define the key as *CHAR in your file control statement (almost said "spec") and then lay that out in a data structure like so:

 

dcl-f prog_file   DISK(519) Keyed(*CHAR:7); //you don’t put ds

                                             //name in the file

                                             //in file control

                                             //statement.

            

dcl-ds    key     len(7) qualified;

         order_number packed(12);

end-ds;

 

And the nice thing about this is that it shows how you can mix dcl-f statements and dcl-ds statements so they're next to each otherthat is, the end-ds statement could be followed by another dcl-f.

TheUsage Keyword

The USAGE keyword replaces the file type (I, O, U) and the file addition (A) flags in the F-spec, a la USAGE(*INPUT).

 

You can specify more than one usage, like *UPDATE and *OUTPUT or *INPUT and *OUTPUT. If listing more than one usage value, use a colon to separate them, like so:

 

USAGE(*UPDATE:*DELETE.)

 

In F-specs, a U can be update and/or delete, but in free-format, *DELETE is its own man and must be specified if you want to do a delete.

 

The default for DISK is INPUT, for PRINTER is OUTPUT, for WRKSTN is (*INPUT:*OUTPUT), and for SEQ and SPECIAL is *INPUT. But you know how I feel about defaults. RBFJ.

 

Of course, the old hierarchy still holds. So *UPDATE implies *INPUT, and *DELETE implies *UPDATE and *INPUT. We aren't changing everything. All we're doing is making things more visible, more obvious. And that's important if you're teaching somebody who wasn't born in a 36 shop how to use RPG. And isn't that what we want? For more people to know RPG?

 

Fortunately, most keywords currently in use in F-specs can still be used for file control statements. This includes things like the RENAME or the PREFIX. But for a full view of what's still supported, you should check out the RPG Programming Reference Guide. What you need to look at here are the lines with a vertical bar (|) next to them. This shows things that are new in the 7.1 PTF and covers the new free-form control statement details.

If/Then/Else in a Control Statement

I know. This is really weird. But with this 7.1 PTF you can actually imbed If/Then/Else commands within the file control or other statements.

 

Now I know what you're thinking. Why? Right? Well, maybe you want to vary the keywords that are associated with the file. Or maybe you just like to make things very complicated. Lots of people like to do that. To be honest, it doesn't really matter why you would want to do this. What's important is you can. Actually, you're more likely to do this kind of thing with data structure control statements, which we'll look at more closely next month when we discuss that. Oops. I gave away the surprise ending. Pretend you didn't hear that.

 

The point is, you can if you need to. And sometimes it might be helpful to be able to assign file control statement keywords based on some external thingy. Like suppose you had a flag that was set based on a user profile value and it indicated a level of trust: either an input only or update state. You could control that with code like this built right into where your F-specs would go now. And don't confuse the slash (/) in front of the IF with the double slash (//) that indicates a comment. These are not comments:

 

/IF flag1 = 'I';

dcl-f product_master Usage(*input) Keyed;

/ELSE;

/IF flag1 = 'U';

dcl-f       product_master   Usage(*Update)                

                             Keyed;

/ENDIF;

/ENDIF;

 

Summary

So admit it. That was fun. Right? The next step will be to look at the final specs being replaced by the control statements: data structure and prototyping oriented structures. Stand by for next month. And until then, if you're on 7.1 and have the PTF for these enhancements, give them a try. And if you don't, then push for an upgrade! Remember: being current is not a penalty; it's a reward.

 

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

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

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: