• 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 4: Prototypes and Procedure Interfaces

    July 9, 2014 Jon Paris

    As promised in Part 3 of this Geezer’s Guide, this time I am going to be looking at the new support for prototypes and procedure interfaces. There are not a large number of enhancements in this area. Mostly they consist of improvements in the compiler’s use of defaults. Of course they also inherit all of the data definition enhancements in areas such as data type and length.

    Prototypes

    Let’s start with prototypes and see how they have changed. The basic building blocks are dcl-pr and dcl-parm. As with dcl-subf in data structures, the dcl-parm is optional and only needed when someone has been foolish enough to give a variable the same name as an RPG op-code. I often use QCMDEXC as an example of a program prototype so I’ll start with that. Here’s a fixed form version:

     d qcmdexc         Pr                  ExtPgm('QCMDEXC')
     d   cmd                        500a   Const Options(*VarSize)
     d   cmdLength                   15p 5 Const
    

    And here is its free-form counterpart:

      dcl-pr qcmdexc ExtPgm;
        cmd          char(500)     Const Options(*VarSize);
        cmdLength    packed(l5: 5) Const;
      end-pr;
    

    The only real difference between the two, apart from the free-form of course, is that if the name of the program to be called matches the prototype name then the program name parameter for the ExtPgm keyword is optional. The compiler will simply convert the prototype name to upper case and use that. So in the example coding ExtPgm was equivalent to coding ExtPgm(‘QCMDEXC’). This particular feature also seems to have been enabled in fixed form.

    Prototypes can also use a short-form definition when no parameters are required. This is similar to the short-form support for Data Structures that I described in the previous tip. Here’s an example:

      dcl-pr MyProgram EXTPGM end-pr;
    

    One new feature that those of you who make frequent use of APIs may appreciate is the new *DCLCASE option for the ExtProc keyword. Previously if you were prototyping a procedure with a mixed-case name you had to specify the name to the ExtProc keyword. Now you can simply specify ExtProc(*DCLCASE) and the compiler will use the procedure name as you declared it on the dcl-pr. In the example below, the first prototype would call a procedure named ‘JONSTESTPROC’ whereas the second and third would call ‘JonsTestProc’.

      dcl-pr JonsTestProc end-pr;
    
      dcl-pr JonsTestProc ExtProc('JonsTestProc') end-pr;
    
      dcl-pr JonsTestProc ExtProc(*DclCase) end-pr;
    

    This is particularly useful for those who make extensive use of APIs that use mixed case names such as Qp0lRenameUnlink and Qp0lRenameKeep, where a simple mistyping of the name can be a cause of frustration and can be surprisingly difficult to spot.

    Defining Subprocedures and Procedure Interfaces

    Given all of the new declaration (dcl) types we have introduced so far, you can probably guess that the old beginning P-spec has been replaced by dcl-proc as you can see in the example below. Not surprisingly the ending P-spec is replaced by end-proc.

    As in the case of fixed form procedure interfaces, the new free-form style matches that of the prototypes. It uses dcl-pi and end-pi to begin and end the declaration and the (mostly) optional dcl-parm for the individual parameters. As with data structures, the only real difference is that the placeholder *N must be used if the name of the subprocedure is to be omitted on the dcl-pi statement.

    So that you have a direct comparison, the example shows both the fixed and free-form versions of the interface definitions for the subprocedure DateInfo. This subprocedure accepts a date in *MDY format and returns a data structure containing the day number, day name, and fully formatted date string.

    Here is the fixed-form version:

    d dateInfo_T1     DS                  Template
    d   dayNumber                    1s 0
    d   dayName                      9a
    d   dateString                  40a   Varying 
    
    
     /end-free
    
     // DateInfo Subprocedure
    p DateInfo        B                   Export
    d                 PI                  LikeDS(dateInfo_T)  
    d   inputDate                     D   DatFmt(*MDY) Const  
    
      /free
      ... 
      /end-free
    p DateInfo        E
    

    And here is the free-form translation:

      dcl-ds dateInfo_T   Template;
        dayNumber   zoned(1);
        dayName     char(9);
        dateString  varChar(40);
      end-ds;
    
      // DateInfo Subproceure
    
      dcl-proc DateInfo export;
      dcl-pi   *N       LikeDS(dateInfo_T);
        inputDate       date(*MDY) Const;
      end-pi;
      ...
      end-proc DateInfo;
    

    Wrapping Up

    One final point related to the use of subprocedures and ILE in general. Another of IBM‘s sensible new defaults allows that if you have coded at least one free-form ILE related control statement such as ACTGRP, BNDDIR, or STGMDL, you no longer need to remember to specify DFTACTGRP(*NO). Not a big thing, but helpful nonetheless.

    Next time I will take a look at the changes made to file specifications. Changes that will be warmly welcomed by every RPGer who, like myself, is convinced that fixed format F-specs, with all their arcane columns and codes, are truly the spawn of the devil.

    Until then if you have any questions or comments, please let me know.

    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 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

    PowerTech:  IBM i security found 94% of systems fail to protect all 27 exit points. Download our study.
    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

    EXTOL Finds New Partners for EDI Counting The Cost Of Power8 Systems

    One thought on “The Geezer’s Guide To Free-Form RPG, Part 4: Prototypes and Procedure Interfaces”

    • Raymond Hess says:
      April 3, 2023 at 4:16 pm

      Fixed format F-specs may be the spawn of the devil but coders who don’t use any coding formatting are scrapped dung from the walls of hell.

      Reply

    Leave a Reply Cancel reply

Volume 14, Number 15 -- July 9, 2014
THIS ISSUE SPONSORED BY:

PowerTech
WorksRight Software
Valence Framework for IBM i

Table of Contents

  • The Geezer’s Guide To Free-Form RPG, Part 4: Prototypes and Procedure Interfaces
  • Advantageous Options
  • Admin Alerts: Old IBM i Backups, New Tricks

Content archive

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

Recent Posts

  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20
  • POWERUp 2025 –Your Source For IBM i 7.6 Information
  • Maxava Consulting Services Does More Than HA/DR Project Management – A Lot More
  • Guru: Creating An SQL Stored Procedure That Returns A Result Set
  • As I See It: At Any Cost
  • IBM i PTF Guide, Volume 27, Number 19

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