× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Variable length MODS
  • From: "Peter Dow" <pcdow@xxxxxxxxx>
  • Date: Fri, 13 Apr 2001 14:07:49 -0700

Hi Tom,
 
As far as I know, you'd get weird data, with no array bounds error, because as far as the compiler knows, the upper array boundary (in my example) is 9999. In other words, yes, you have to be careful how you use it, and check the NumLabels or whatever instead of the %elem(array) test.
 
hth,
Peter Dow
Dow Software Services, Inc.
909 425-0194 voice
909 425-0196 fax
 
----- Original Message -----
Sent: Friday, April 13, 2001 1:20 PM
Subject: Re: Variable length MODS


Let's say that there are 3 entries in the PFRTBLF file that I can use.  SizeLabels will = 15, which is ALLOC'd to ptrLabels.  What happens if I try to access Labels(4) in my program?  Will I get an array bounds error?  Will I get weird data?



"Peter Dow" <pcdow@yahoo.com>
Sent by: owner-rpg400-l@midrange.com

04/13/01 01:49 AM
Please respond to RPG400-L

       
        To:        <RPG400-L@midrange.com>
        cc:        
        Subject:        Re: Variable length MODS



Hi Tom,

Welcome to the wonderful world of pointers. Define your MODS as based on a
pointer, with OCCURS set to a high number. No storage is actually used for
this definition. Once you know how many occurrences you need, set the basing
pointer to ALLOCate memory for NbrLabels * size of one MODS occurrence.

d ptrLabels                     s                *
d Labels                         s          5  0         dim(9999)
based(ptrLabels)
d SizeLabels                   s        10  0

d ptrTot1                        s                *
d Tot1DS                       ds                  occurs(9999)
based(ptrTot1)
d    amt1                                    7  2    dim(7)
d SizeTot1DS                 s        10  0

d ptrTot2                        s                *
d Tot2DS                       ds                  occurs(9999)
based(ptrTot2)
d    amt2                                    8  2    dim(7)
d SizeTot2DS                 s        10  0

c*  Read thru labels file, counting all of the useable label records
c*  Store that count in NumLabels to give us the number of Occurs for each
DS

c                    eval         SizeLabels = %size(Labels) * NumLabels
c                    alloc        SizeLabels              ptrLabels

c                    eval         SizeTot1DS = %size(Tot1DS) * NumLabels
c                    alloc        SizeTot1DS            ptrTot1

c                    eval         SizeTot2DS = %size(Tot2DS) * NumLabels
c                    alloc        SizeTot2DS            ptrTot2

 * At this point you can refer to Labels, Tot1DS, or Tot2DS as you normally
would, e.g.

c                    eval         Labels(5) =  10

or

c         7         occur       Tot1DS
c                    eval          amt1 = amt1 + 73.5

I haven't done this in awhile, but I'm sure someone will correct me if I got
anything wrong ;)

hth,
Peter Dow
Dow Software Services, Inc.
909 425-0194 voice
909 425-0196 fax




----- Original Message -----
From: tomh@simas.com
To: rpg400-l@midrange.com
Sent: Thursday, April 12, 2001 3:38 PM
Subject: Variable length MODS



I need to build several MODS (multiple-occurence data structures), but I
don't know the number of occurences that I'll need for them until I read
some data from a file.  Of course, I could just set the OCCURS on the D-spec
to a high number, but would rather just create enough occurences to handle
the data.

Something like this:

d Labels                         s                dim(NumLabels) inz

d Tot1DS                       ds               occurs(NumLabels) inz
d amt1                                       7  2    dim(7)

d Tot2DS                       ds               occurs(NumLabels) inz
d amt2                                       8  2    dim(7)

c*  Read thru labels file, counting all of the useable label records
c*  Store that count in NumLabels to give us the number of Occurs for each
DS

Tom

+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.