• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Define Compile-Time Array Data in D-Specs

    September 8, 2004 Hey, Ted

    For performance reasons there are certain tables that I would prefer to implement as compile-time arrays rather than as physical files. But I don’t want to hard-code the compile-time array definitions in each RPG program that uses them, since that would require manual modification of each program if an array’s definition or data changes. Loading each array from a file at program startup is also an option, but I’d prefer to avoid the unnecessary I/O. I came up with a method to store compile-time array definitions in a copyable source member, but it has one little problem.

    Here’s my idea. I created a source member containing both definition and data of a compile-time array.

          /if not defined(CTDATA)
         D NbrOfRegions    c                   const(5)
         D RegionNbr       S              2    dim(NbrOfRegions)
         D                                     ctdata PerRcd(1)
         D RegionName      S              8    dim(NbrOfRegions)
         D                                     alt(RegionNbr)
          /eof
          /endif
    **ctdata RegionNbr
    N NORTH
    S SOUTH
    E EAST
    W WEST
    MWMIDWEST
    

    Any program that needs the regions table can access my source member at run time, defining or undefining the CTDATA condition appropriately.

    D Region          s              2
    D R               s             10i 0
    D DtlRegion       s              8
    D
    D/undefine CTDATA
    D/include mylib/tables,Regions
    
     /free
    
         R = %lookup(Region:RegionNbr);
         if (R > *zero);
            eval DtlRegion = RegionName (R);
         else;
            eval DtlRegion = 'REG ' + Region;
         endif;
    
         *inlr = *on;
     /end-free
    
    D/define CTDATA
    D/include mylib/tables,Regions
    

    If the region data changes (a region is added, deleted, or renamed), I need only revise the source member that contains the region data and recompile the programs that use the array.

    This method works fine as long as there is only one compile-time array in the program. When I try to include a second source member that contains a compile-time array, my technique breaks down. The included D-specs are perfect, but the compile-time array data is not. The compiler does not recognize that the first compile-time array data set has ended, and tries to treat the second /include (or /copy) as another data record for the first compile-time array.

    Do you know of another method that would accomplish my goal?

    –Nathan

    I had never considered this idea before, so your question was intriguing to me. I came up with a method that will do what you want, but I should tell you that I have never used this method in production.

    It occurred to me that if you could load the data through the D-specs, similar to the way COBOL programmers define compile-time array data in the data division, you would be rid of the compiler’s insistence on treating compiler directives as compile-time array data.

    Here’s your region data defined in D-specs.

    D NbrOfRegions    c                   const(5)
    D RegionData      ds
    D                               10    inz('N NORTH   ')
    D                               10    inz('S SOUTH   ')
    D                               10    inz('E EAST    ')
    D                               10    inz('W WEST    ')
    D                               10    inz('MWMIDWEST ')
    D RegionBase      s               *   inz(%addr(RegionData))
    D RegionArray     ds                  based(RegionBase)
    D   RegionElem                  10    dim(NbrOfRegions)
    D   RegionNbr                    2    overlay(RegionElem:1)
    D   RegionName                   8    overlay(RegionElem:3)
    

    The RegionData data structure takes the place of the compile-time array dataset that is normally coded at the end of the source member. RegionArray contains the definition of the compile-time array data in a slightly different format than the one to which you’re accustomed. Each record of the array data is an element of the RegionElem array. The OVERLAY keyword lets you break RegionElem into the two arrays you access: RegionNbr and RegionName.

    To make this technique work, it is necessary to assign the RegionData and RegionArray data structures to the same address in memory. I did this by creating pointer variable RegionBase. This pointer contains the address of RegionData. Since RegionArray is based at the address contained in RegionBase, RegionArray overlays RegionData in memory.

    You will need only one /include (or /copy). Place it anywhere in the D-specs.

    If you use this technique, you will be able to define multiple compile-time arrays in external source members. Since I have not used this method in production, I would like to hear from anyone who tries it.

    –Ted

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    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

    Goering Bolsters iExcelGen with Better Automation PeopleSoft Says It’s Working Hard to Make a Better World

    Leave a Reply Cancel reply

Content archive

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

Recent Posts

  • 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
  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18

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