× 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.



On Dec 4, 2010, at 7:32 AM, rpg400-l-request@xxxxxxxxxxxx wrote:

We have the following:
a file contains 54 buckets (packed 9,0) (one for each accounting week of
year)
to easily get these into an array I make:

an array: QtyArr s like(TAW01) Dim(54) Based(ptQty)
a pointer: ptQty s *

I read a record,
then I set the pointer to the first field in the record:

ptQty = %addr(TAW01) ;

I can work with QtyArr(x) fine...


Then you have been very lucky!

What none of the other answers have pointed out is that this is a _really_ bad idea.

The fields may be contiguous in your file but there is ZERO guarantee that the RPG compiler will place them in contiguous storage. Even your "working" programs could suddenly fail due to nothing more than a recompile if something was changed in the compiler and/or translator. Do yourself a favor and do not propagate this technique any further. This kind of assumption only works for C and COBOL (for example) where the compiler always handles file fields as sunsets of the the record. RPG doesn't work that way.

The _only_ way this technique is guaranteed to work is if you take steps to ensure that the fields are contiguous by either manually placing them in an array or by defining the fields in an Externally described DS.

This topic has been discussed in this forum before and I (among others) have written articles on different approaches to dealing with it. See this article for examples of the techniques that can be used. http://www.ibmsystemsmag.com/ibmi/february03/enewsletterexclusive/8073p1.aspx

You don't mention the actual field layout for the second example so I can't offer a definitive solution - but please take it from me that it is pure bad luck that your original approach ever worked. You were lucky with this second program - hopefully stopping you from perpetuating this really dangerous technique.


Jon Paris

www.Partner400.com
www.SystemiDeveloper.com



As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.