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




How can I improve this procedure for performance? I am a little worried
about how the ReasonDS is declared.
Basically I need an Array of the Datastructure that the procedure can
return. I also need to be able to look up this array with @RsnCode as the
key.

The best way to improve performance is to pass the data structure as a parameter instead of as a return value. The return value is much less efficient, and I personally would never use it for anything larger than 30 bytes (or so) if performance is a concern.

* Array of Data structures to hold reason code details
D  ReasonDS       DS          5400
D   @RsnCode                     2A   Dim(200)
D   @Charge                      9  2 Dim(200)
D   @Weight                      9  0 Dim(200)
D   @Units                       7  0 Dim(200)

This isn't an array of data structures. It's a data structure that contains 4 arrays, each array is independent of the others. I also don't understand why you've hardcoded the data structure to be 5400 bytes long when it actually only needs 3200 bytes of memory. I know that 2200 bytes isn't a big deal, but why waste it if it brings you no benefit at all?

You probably meant to do this:

     D                 DS
     D ReasonDS                            dim(200)
     D  @RsnCode                      2A   overlay(ReasonDS:1)
     D  @Charge                       9P 2 overlay(ReasonDS:*NEXT)
     D  @Weight                       9P 0 overlay(ReasonDS:*NEXT)
     D  @Units                        7P 0 overlay(ReasonDS:*NEXT)

In this case, "ReasonDS" is an array of 16A DIM(200). The other fields overlay positions in that array, so @RsnCode is an array that always overlays positions 1-2 of ReasonDS. @Charge is an array that overlays positions 3-7 of ReasonDS, etc.

Alternately, you could code it as follows:

     D ReasonDS        ds                  qualified dim(200)
     D  @RsnCode                      2A
     D  @Charge                       9P 2
     D  @Weight                       9P 0
     D  @Units                        7P 0

In this case, it actually *is* an array of data structures. You have one DS with 4 subfields, and 200 copies of that DS. The only problem with this technique is that RPG won't let you use BIFs like %LOOKUP, or op-codes like SORTA on the array, which some people find to be a disadvantage. Personally, I don't mind coding my own functions to replace %LOOKUP and SORTA, so it doesn't bother me.

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.