Newsletters Subscriptions Media Kit About Us Contact Search Home

mgo
OS/400 Edition
Volume 3, Number 51 -- August 6, 2003

Two-Dimensional Compile-Time Arrays in RPG


Hey, Ted:

How do you define a two-dimensional compile-time array in V5R2 RPG?

--Joe

Good question. I've only had to do that one time, and this is the method I used

     D AdjTbl          s             48a   
                           dim(3) ctdata perrcd(1) 

     D AdjTblPtr       s               *   
                           inz(%addr(AdjTbl))

     D AdjRow          ds                  
                           dim(3) qualified 
     D                                     
                           based(AdjTblPtr) 
     D   AdjCol                      12a   dim(4) 

     D Adjective       s             12a 
     D Row             s             10u 0 
     D Col             s             10u 0 

      /free 

          Adjective = AdjRow(Row).AdjCol(Col); 

      /end-free 
** 
acrimonious bucolic     crapulous   dyadic 
equivocal   fecund      gelatinous  heliocentric
irascible   jingoistic  kinesthetic laic

I defined a compile-time array with the rows of data as I needed them. Then I used a pointer to overlay the compile-time array with a multi-dimensioned data structure that contained an array subfield. Notice that the AdjRow data structure is qualified. A data structure has to be qualified if it's given a dimension.

To extract an element of the two-dimensional array, reference both the outer dimension (the data structure) and the inner dimension (the subfield) with subscripts. In this example, if Row has the value 3 and Col has the value 1, Adjective takes the value irascible.

I'm guessing COBOL programmers won't bother to write me about this tip. COBOL has had 2D and 3D arrays for something like 40 years.

--Ted


Sponsored By
WORKSRIGHT SOFTWARE

600 Billion

That's how much a recent independent study estimated U.S. businesses spend on dirty data. How much of that 600 billion is spent by your company? Cleanse your dirty ZIP Codes and mailing addresses with our software and save big bucks.

WorksRight Software, Inc.
Phone: 601-856-8337
E-mail: software@worksright.com
Web site: www.worksright.com


THIS ISSUE
SPONSORED BY:

WorksRight Software
COMMON


BACK ISSUES

TABLE OF
CONTENTS

Two-Dimensional Compile-Time Arrays in RPG

Redirecting Java's Standard Output, Take 2

Reader Feedback and Insights: COBOL API Resources


Editors
Howard Arner
Joe Hertvik
Ted Holt
David Morris

Managing Editor
Shannon Pastore

Publisher and
Advertising Director:

Jenny Thomas

Advertising Sales Representative
Kim Reed

Contact the Editors
Do you have a gripe, inside dope or an opinion?
Email the editors:
editors@itjungle.com

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.