• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • The Geezer’s Guide to Free-Form RPG, Part 5: File Definitions

    August 13, 2014 Jon Paris

    While the changes in data definition introduced by the new free-form RPG support are great, I have to admit that it was probably the free-form file specifications that raised the biggest cheer from me. Let me tell you why.

    I have always hated F-specs. Those nasty little single column codes drove me crazy. I could never remember what went where. I know I’m not the only one. All of the programmers we have taught RPG to over the last few years have also had similar problems coming to grips with with F-specs.

    I am reminded of this almost every time I dive into coding, since F-specs remained as the only thing I ever needed the prompter for once I started to use RDi for all my development work. Now, for the first time ever, I am coding file definitions without prompting and without referencing the manual.

    Happy, happy, happy!

    So, let’s get into some details.

    Basic Syntax

    As with all the new declarations, file definitions begin with the characters “dcl-” for files, followed by “f”. It might have been nice to be able to spell out “file” as an alternative, but I’m happy enough with just the “f”.

    The name of the file follows and here we encounter our first new feature. BIG file names! Or perhaps, to be more precise, the option to use meaningful file names. In the past we were stuck with using a traditional 10-character system name for our files, but no such limit applies in the new RPG. I really like this because it has always bothered me that determining the function of a file in a program invariably requires the use of some secret decoder ring. This is often worse in the case of print files where, for example, a monthly sales summary report might have a highly meaningful name such as SLSRPT0055. How much better it is to be able to use a meaningful file name. Of course it would be even nicer if we could also use meaningful record names, or indeed use the file name for all I/O operations on single format files, but I digress.

    The downside is that you need to specify both the EXTFILE and EXTDESC keywords as you can see in the example below. I can’t help wishing that the compiler had not been as strict about this and had simply allowed EXTDESC and provided EXTFILE(*EXTDESC) as the default whenever it was used. Perhaps we’ll see this in the future.

    Here’s the original fixed form version of a printer file definition:

     FSLSRPT0055O    E             Printer OflInd(pageFull)
    

    This is a straightforward translation:

      dcl-f SLSRPT0055 Printer OflInd(pageFull);
    

    And this uses the new long name support:

      dcl-f MthSalesSummary Printer ExtDesc('SLSRPT0055') 
                                    ExtFile(*ExtDesc)
                                    OflInd(pageFull);
    

    The next entry following the name must be the device keyword, or alternatively LIKEFILE. If no device is specified then the compiler assumes a default of DISK.

    Once the device has been specified then next come the device specific keywords. These are basically those that used to appear in the keyword area of the F-spec, and since these are basically unchanged I won’t deal with them here. There is, however, one new keyword, KEYED, which replaces the old “A” and “K” entries in the Record Address type field. The remaining single column entries, such as Limits Processing, are not supported in free-format. If you still need them then you must stick with a fixed format definition.

    File Usage. . . At Long Last Sensible Defaults

    As I noted in my first tip on this subject, one of the best parts of the new support is the use of sensible defaults.

    No longer do we have to tell the compiler that files are externally described: it is the default! If you get nostalgic for the bad old days you can always add *EXT as a parameter to the device type keyword—i.e., DISK(*EXT)–but why bother? Nor do we have to specify that a printer file is used for output. Output is the default usage for printer files! In a similar fashion, the file usage (input, output, both) also defaults based on the device type.

    To give you the full picture, here are the defaults for the basic file types:

    File Type

    Default
    Usage

    DISK (Default type)

    Input

    PRINTER

    Output

    WORKSTN

    Input/Output

    But the provision of sensible defaults doesn’t end there. It also comes into play even in cases where the default usage is not sufficient for the task at hand. The compiler takes an incremental approach. For example, in order to perform updates, the file must be defined as input capable. But you don’t have to specify that, the compiler provides *INPUT as by default when *UPDATE is specified. This table shows the defaults used:

    Usage
    Specified

    Additional
    Usage Included

    Can Also Be
    Coded As:

    *Input

    None

     

    *Output

    None

     

    *Update

    *Input

    *Input: *Update

    *Delete

    *Update (and therefore *Input)

    *Input: *Update: *Delete

    Previously, if you specified a “U” to enable a file for update, it was also enabled for delete. As you can see from the table this is not the case in free-form. Specifying *DELETE implies *UPDATE, but the reverse is not true. To me this makes perfect sense.

    In a similar vein, in order for records to be added to a file, *OUTPUT must now be specified. Previously file addition was specified by coding an “A” in a specific column. This resulted in the, to me, rather perverse situation of an apparent input file being capable of having new records written to it. Again, the new requirement makes a lot more sense.

    Program Described Files

    So far I have focused on externally described files because, while not the norm in the early days of RPG, they are in the vast majority these days. It makes sense then that the new free-form support makes external definitions the default.

    Printer files are the major exception to the march away from program defined files. For some reason while many RPGers have accepted the benefits of externally described disk and display files, they have failed to embrace printer files with the same degree of enthusiasm. Go figure. Perhaps the fact that O-specs are not supported in free-form may be the final carrot that leads them to the right path. One can but hope.

    To define a file as program described simply requires adding a length parameter to the device keyword. For instance, Printer(132). Similarly, in the unlikely event that you want to program describe a keyed disk file, you would need to add a key type and length parameter to the KEYED keyword. For example, KEYED( *Char: 5 ).

    Wrapping Up

    I hope you have found this “Geezer’s Guide” series useful. I’m sure there are things I have forgotten, or simply don’t know yet. As I discover them, I’ll be share them with you here.

    For myself I have found writing this an interesting exercise and, as I have noted from time to time, found a few “tweaks” here and there that I’d like to see made in this support. Interestingly several of these concern default behaviors that I’d like to see extended. Interesting how picky one can get about such things once you see what can be done!

    Jon Paris is one of the world’s most knowledgeable experts on programming on the System i platform. Paris cut his teeth on the System/38 way back when, and in 1987 he joined IBM’s Toronto software lab to work on the COBOL compilers for the System/38 and System/36. He also worked on the creation of the COBOL/400 compilers for the original AS/400s back in 1988, and was one of the key developers behind RPG IV and the CODE/400 development tool. In 1998, he left IBM to start his own education and training firm, a job he does to this day with his wife, Susan Gantner–also an expert in System i programming. Paris and Gantner, along with Paul Tuohy and Skip Marchesani, are co-founders of System i Developer, which hosts the new RPG & DB2 Summit conference. Send your questions or comments for Jon to Ted Holt via the IT Jungle Contact page.

    RELATED STORIES

    The Geezer’s Guide To Free-Form RPG, Part 4: Prototypes and Procedure Interfaces

    The Geezer’s Guide to Free-Form RPG, Part 3: Data Structures and More Data Definitions

    The Geezer’s Guide to Free-Form RPG, Part 2: Data Structures and More

    Four Reasons RPG Geezers Should Care About The New Free-Form RPG



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Linoma Software:  FREE Webinar: Managed File Transfer 101.
    System i Developer:  Upgrade your skills at the RPG & DB2 Summit in Minneapolis, Sept 30 - Oct 2.
    COMMON:  Join us at the COMMON 2014 Fall Conference & Expo in Indianapolis, Oct 27-29

    More IT Jungle Resources:

    System i PTF Guide: Weekly PTF Updates
    IBM i Events Calendar: National Conferences, Local Events, and Webinars
    Breaking News: News Hot Off The Press
    TPM @ EnterpriseTech: High Performance Computing Industry News From ITJ EIC Timothy Prickett Morgan

    IBM Cooks Up Online Consultant Shopping Power8 Packs More Punch Than Expected

    Leave a Reply Cancel reply

Volume 14, Number 18 -- August 13, 2014
THIS ISSUE SPONSORED BY:

SEQUEL Software
WorksRight Software
QUERY FILE for IBM i

Table of Contents

  • The Geezer’s Guide to Free-Form RPG, Part 5: File Definitions
  • Do It Now!
  • Admin Alert: More On Porting User Profiles Between IBM i Partitions

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle