D-spec Discoveries

Do you think you know everything there is to know about using D-specs in RPGIV? Read on and you may find a few things that surprise you.

The inspiration for this column comes from one of the most commonly asked questions on RPG programming lists: "How do I directly load fields from a database record into an array?" The question normally arises when each database record contains a series of related values-for example, monthly sales figures. Yes, we know that a normalized database wouldn't contain such a thing, but we're talking real life here.

For these examples, we'll use the following DDS for the physical file:

 * Sales per quarter by Customer
          R SALESREC1
            CUSTNO         4
            DIVISION       2
            Q1             7  2
            Q2             7  2
            Q3             7  2
            Q4             7  2
          K CUSTNO

Our objective is to access the individual fields Q1-Q4 as an array of four elements.

One approach is to move each field in the record into its corresponding array element. In this example, with only four fields, this wouldn't be too arduous. But, what if there were 12 or 20 fields? Regardless of the number, it's inefficient and better solutions are available, including several that involve some little-known features of D-specs.

Let's start with the simplest and, perhaps, most obvious option. Define an externally described Data Structure (DS) using the record format to supply the description (A). Then use the OVERLAY keyword to create the array (B).

(A)  D SalesData     E DS                  ExtName(TestFile)

      // Define array over Quarterly Sales figures

(B)  D  SalesForQtr                        Overlay(SalesData: 7)
(C)  D                                     Like(Q1) Dim(4)


Jon Paris is a technical editor with IBM Systems Magazine and co-owner of Partner400.

Susan Gantner is a technical editor with IBM Systems Magazine and co-owner of Partner400.

comments powered by Disqus



2019 Solutions Edition

A Comprehensive Online Buyer's Guide to Solutions, Services and Education.

Are You Multilingual?

Rational enables development in multiplatform environments

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link iPad App Google Play Store
IBMi News Sign Up Today! Past News Letters