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



For performance purposes, you might want to avoid using a return value by
passing the ReasonDS as a bi-directional parm.  Return values are notorious
for being slow when returning large amounts of data.  

Doing this means you can't call this function as part of an expression, but
I would not expect that you're needing to use the ReasonDS directly in a
calculation, since it's not returning a simple value....

Your prototype would look something like this:
D BilUtil_getReasonTotals...
D                 PR
D @prPlant_                      3  0 Value
D @prBillTo_                     5  0 Value
D @prBillDate_                    D   Value
D @prInvoice_                    5  0 Value
D tempReasonDS                        LikeDS(ReasonDS)

Add your ReasonDS into the copy member along with your prototype, so that
you always compile from a common DS definition.

Also, take a look at your %lookup.  Since you're uning counters to track how
many elements you have loaded, you can save some cycles on the lookup by
specifying parms 3 and 4 (starting element, number of elements to search) in
the %lookup bif...  

FWIW, when I use an array DS as parameter data, I often include associated
data fields in the DS definition.  For example, I add @Count to the DS, so
that I always have a valid value for the number of elements loaded to the
arrays.....  

Another suggestion, if ever you need to sort the ReasonDS, you will need to
define your array so that all element sort properly.  See the example
below...

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

hth,

Eric DeLong
Sally Beauty Company
MIS-Project Manager (BSG)
940-297-2863 or ext. 1863



-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of praveen gunda
Sent: Wednesday, April 19, 2006 11:42 AM
To: RPG programming on the AS400 / iSeries
Subject: How can I Improve this procedure...


Hi all,
 I have the following procedure in a service program that would be called
quite a few times from different programs.

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.


* 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)


P BilUtil_getReasonTotals...
P                 B                   Export

D BilUtil_getReasonTotals...
D                 PI                  LikeDS(ReasonDS)
D @prPlant_                      3  0 Value
D @prBillTo_                     5  0 Value
D @prBillDate_                    D   Value
D @prInvoice_                    5  0 Value

 * Return Data structure
D tempReasonDS    DS                  LikeDS(ReasonDS)

 * Local variables
D @Count          S              2  0 Inz(*Zeros)
D @tCount         S              2  0 Inz(*Zeros)
D @Century        S              2  0 Inz(*Zeros)
D @BillDt         S              6  0 Inz(*Zeros)
 /free


   If Not %Open(BMCTOTL4);
      Open BMCTOTL4;
   EndIf;

   If Not %Open(BHCTOTL1);
      Open BHCTOTL1;
   EndIf;

   @Century = DateUtil_getCentury(@prBillDate_);
   @BillDt  = %Dec(%Char(@prBillDate_:*YMD0):6:0);

   // First check if record exists in current
   SetLL (@prPlant_:@prBillTo_:@prInvoice_:@Century:@BillDt) BMCTOTL4
   ReadE (@prPlant_:@prBillTo_:@prInvoice_:@Century:@BillDt) BMCTOTL4
   DoW Not %EoF(BMCTOTL4);
         // Accumulate all charges per reason code for this custom
         @tCount = %LookUp(BTREA:@RsnCode);
         If @tCount <> 0;
            tempReasonDS.@Charge(@tCount) += BTTDO;
            tempReasonDS.@Weight(@tCount) += BTTLB;
            tempReasonDS.@Units(@tCount)  += BTTUN;
         Else;
            @Count += 1;
            tempReasonDS.@RsnCode(@Count) = BTREA;
            tempReasonDS.@Charge(@Count)  = BTTDO;
            tempReasonDS.@Weight(@Count)  = BTTLB;
            tempReasonDS.@Units(@Count)   = BTTUN;

EndIf;


         ReadE (@prPlant_:@prBillTo_:@prInvoice_:@Century:@BillDt)
                          BMCTOTL4;
   EndDo;

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.