• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: 7.4 Brings New RPG Goodies

    June 3, 2019 Jon Paris

    As I’m sure you know by now, IBM recently announced version 7.4 of IBM i. Along with major enhancements such as Db2 Mirror, we also got a number of new RPG features. In this tip I’ll cover those that are already available in 7.3 via PTF. The 7.4-only enhancements will be covered in a subsequent tip.

    Before we get into the details of the 7.3 features, just a hint of what is to come . . . 7.4 brings the long-awaited arrival of dynamic arrays known to IBM as varying dimension arrays. No more do you have to compromise between memory usage and safety! And it makes so many other things easier, too. But while this is a terrific feature, due to the complexity of the changes required to support it, it will not be PTF’d back into 7.3. So the majority of us will not be able to get our hands on it for a month or three. That is why I decided to focus this first tip on the RPG enhancements that are available now in 7.3 and I will review the array enhancements in a later tip.

    PSDS Updates

    RPG has added two additional fields to the PSDS. This feature has also been made available for the 7.2 release. The one that most people will find a use for is the 8-character system name that appears in positions 396 to 403. The second is the 16 byte Internal Job ID, which can be found in positions 380 to 395. This ID is used for, among other things, socket communications or retrieving spool file information for the job. Previously the simplest way to obtain it was to call the QUSRJOBI API. Having it readily accessible in the PSDS is clearly a lot easier. Here’s how it looks:

    // Internal job ID, in positions 380 to 395
    // System name, in positions 396 - 403
    Dcl-Ds  PSDS;
       jobId       Char(16)  Pos(380);
       systemName  Char(8)   Pos(396);
    End-Ds;
    

    New Keyword SAMEPOS

    This one is deceptively simple but has so many potential uses. In most cases it doesn’t do anything we couldn’t do before, but it makes it simpler and more obvious. Let’s start by making a simple comparison with the OVERLAY keyword.

    Take a look at these two structures. In both cases the separate day, month, and year fields are being grouped together in a single date field. In the first case the date field is defined first and the component fields are specified as overlaying it. It works, but it looks clumsy.

    Dcl-DS  overlayDS;
       orderDate  char(8);
       orderDay    zoned(2)  Overlay( orderDate );
       orderMonth  zoned(2)  Overlay( orderDate: *Next );
       orderYear   zoned(4)  Overlay( orderDate: *Next );
    End-Ds;
    
    Dcl-DS  samePosDS;
       orderDay    zoned(2);
       orderMonth  zoned(2);
       orderYear   zoned(4);
       // Overlay day, month and year as single field
       orderDate  char(8)  SamePos(orderDay);
    End-Ds;
    

    In the second case the component fields are specified first, and the combined date field uses SAMEPOS to specify that it starts in the same position as the orderDay field. I think that you will agree that the second version is a lot cleaner.

    As these samples demonstrate, the primary difference between OVERLAY and SAMEPOS is that with OVERLAY the field being defined must be totally contained within the referenced parent field. With SAMEPOS we are simply saying that the field “starts in the same place as” the referenced field. Basically it is a “soft” version of the POS keyword which accepts a field name rather than an absolute position — and anything that helps avoid hard-coding is a good thing.

    SAMEPOS really comes into its own when used with an externally described data structure. For example, suppose in the example above the separate day, month, and year fields were in the database. We could still use SAMEPOS to create the orderDate field like this:

    Dcl-Ds  orderData  Ext;
       orderDate  Char(8)  SamePos(orderDay);
    End-Ds;
    

    In a similar manner you can also use it to create an array over a series of fields. Not that any of our readers have databases that are not fully normalized, but just in case . . .

    Suppose that the table contains quantity and value fields for sales for each day of the week, i.e., MONQUANTITY, MONVALUE, TUEQUANTITY, TUEVALUE, etc., all the way to SUNVALUE. We can use SAMEPOS to create a DS array within the main DS like this:

    Dcl-Ds  dailySales  Ext  Qualified;
       Dcl-Ds  daySales  Dim(7)  SamePos(MONQUANTITY);
          quantity  Like(MONQUANTITY);
          value     Like(MONVALUE);
       End-Ds;
    End-Ds;
    

    The daily quantity and value fields for each day can now be accessed as array elements.

    One other use that immediately came to my mind concerned its applicability to dealing with multi-format data, i.e. where you have a fixed portion of the record (perhaps a Customer number and Order number, together with a record identifier. Header, detail, total, etc.) You’d think that this was a style of data definition that we had left behind with punch cards and mag tapes but it continues to be used. In particular I’ve encountered it recently with EDI data.

    SAMEPOS makes this kind of definition far easier than the alternatives of copying data to the appropriately defined layout, or using pointers to map different layouts to the same data. Here’s basically how it would work.

    Dcl-Ds  Record  Qualified; 
       RecordType  Char(1);
       //  Additional common data such as customer Id
    
       Dcl-Ds  HeaderInfo;
          // Definitions for header layout
       End-Ds;
    
       Dcl-Ds  DetailInfo  SamePos(HeaderInfo);
          // Definitions for detail layout
       End-Ds;
    
       Dcl-Ds  TotalInfo   SamePos(HeaderInfo);
          // Definitions for total layout 
       End-Ds;
    End-Ds;
    

    Summary

    As you’ve seen, there is a lot you can do with this new support. You can find details of the required PTF numbers in the RPG Cafe at these links —  ibm.biz/rpg_samepos_keyword and ibm.biz/rpg_psds_int_job_sys_name.

    In my next tip I’ll take a look at the new array support. In the meantime, if you have any questions or comments about these features please let me know via the comments section.

    Jon Paris is one of the world’s foremost experts on programming on the IBM i platform. A frequent author, forum contributor, and speaker at User Groups and technical conferences around the world, he is also an IBM Champion and a partner at Partner400 and System i Developer. He hosts the RPG & DB2 Summit twice per year with partners Susan Gantner and Paul Tuohy.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: 400guru, Db2 Mirror, FHG, Four Hundred, Four Hundred Guru, IBM i, PTF, RPG

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    As I See It: In The Face Of Bad Behavior Speaking The SQL Lingua Franca On IBM i

    One thought on “Guru: 7.4 Brings New RPG Goodies”

    • Chris says:
      June 3, 2019 at 2:52 pm

      So I presume the system name in the PSDS is the current system name where the code is currently running, as opposed to the system name where object was compiled. Thanks for info!

      Ringer

      Reply

    Leave a Reply Cancel reply

TFH Volume: 29 Issue: 33

This Issue Sponsored By

  • iTech Solutions
  • WorksRight Software
  • CNX
  • Computer Keyes
  • Manta Technologies

Table of Contents

  • POWERUp Delivers Shot In The Arm To IBM i
  • Speaking The SQL Lingua Franca On IBM i
  • Guru: 7.4 Brings New RPG Goodies
  • As I See It: In The Face Of Bad Behavior
  • IBM i PTF Guide, Volume 21, Number 21

Content archive

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

Recent Posts

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • 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

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