• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Today’s Special: Data Area Surprise!

    January 25, 2006 Ted Holt

    Data areas are as handy as pockets. Maybe that’s because they are like pockets in that you can stuff things into them. RPG, like other iSeries programming languages, can read and modify data areas. In fact, RPG allows for two different data area I/O methods, and one of them has a “feature” that could give you a nasty surprise!

    If you want an RPG program to read and/or change a data area, you have two options. You can let the RPG cycle handle the input and output operations, or you can control the I/O by hand. The easier method is to let the cycle do the work, so let’s look at it first.

    To tell the RPG cycle that you want it to control data area input and output, create a named data structure with the U option in the definition specs. Here’s how to create a data structure for the data area named STATUS.

     D Status         uds
     D  Stat                   1      8
      /free
          Stat = 'BR-549';
    

    The data structure must have a name. If you omit the name, the program will access the local data area.

    If the data area’s name is different from the data area name, use the DTAARA keyword to specify the object name. In this example, the data structure is named STATUS, but the object name is PGMSTAT.

     D Status         uds                  dtaara('PGMSTAT')
     D  Stat                   1      8
      /free
          Stat = 'BR-549';
    

    When the program begins to run, it allocates the data area with a lock and brings its contents into storage. When the program ends, it updates the data area and releases the lock. Nothing to it.

    The other method is the procedural method. Use the IN, OUT, and UNLOCK op codes to control data area I/O in calculations. The following example retrieves the current value of a data area, assigns a new value, and writes the changed value back to the data area object.

    D Status          ds             8    dtaara('STATUS')
     /free
         in *lock Status;
         Status = 'BR-549';
         out Status;
    

    So which is the better method? I vote for the procedural method. For one reason, under the cycle method, the data area remains locked for the duration of the program run, even if the program does not change the data area’s value. In some cases, such as when run time is short, locking the data area is of no importance. But when run time is longer and other programs may also need to access the data area, keeping the data area locked is out of the question.

    But what concerns me more is that the cycle method includes a “feature” that I don’t like. If the data area is not found at run time, the system takes it on itself to create a data area of the proper name in the QTEMP library. Surprise! If by some fluke the desired data area has been deleted, the program does not halt, as it does when data area I/O is handled with the IN and OUT op codes, but creates a temporary data area and keeps on truckin’. I do not like to take such risks.

    Not only are there two ways to read and modify data areas, there are also two ways to define data areas–in calculation specifications and in definition specifications. The D-spec method is the “new and improved” one, so that is the definition method I use and the one I recommend others to use. One interesting feature of the D-spec method is you may specify DTAARA(*VAR) in a D spec in order to specify the name of a data area object at run time. The DEFINE op code, on the other hand, binds to the object name at compilation.

    To learn more about the C-spec method, read about the DEFINE op code (DEFN in RPG III).

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    New Generation Software

    FREE Webinar:

    Creating Great Data for Enterprise AI

    Enterprise AI relies on many data sources and types, but every AI project needs a data quality, governance, and security plan.

    Wherever and however you want to analyze your data, adopting modern ETL and BI software like NGS-IQ is a great way to support your effort.

    Webinar: June 26, 2025

    RSVP today.

    www.ngsi.com – 800-824-1220

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    T.L. Ashford:  BARCODE400 - the fastest way to create compliance labels directly from the iSeries
    COMMON:  Join us at the Spring 2006 conference, March 26-30, in Minneapolis, Minnesota
    Bug Busters Software Engineering:  Quality software solutions for the iSeries since 1988

    Vision Solutions Appoints New Executive VP of Sales and Marketing How Low Can You Go?

    Leave a Reply Cancel reply

Volume 6, Number 4 -- January 25, 2006
THIS ISSUE SPONSORED BY:

Advanced Systems Concepts
Gabriel Consulting Group
COMMON

Table of Contents

  • Today’s Special: Data Area Surprise!
  • Use SQL to Run PDM Options?
  • Admin Alert Feedback: Quicker Ways to Change Library Object Ownership

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