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



Titus Kruse wrote:

Hello!

I've written a procedure that returns a value of type varying length string.
Because I want to let the maximum size of the field in the calling programm
open, the size of the return field is defined with 65535 bytes.

Independently of the number of bytes to be returned, the call of the
procedure is very slow (time job running was 19 seconds). When I define the
return field like the input field with 255 bytes the call is faster (runtime
only 1 second).

Why that? I would expect, that only characters needed and length information
are copied to the calling procedure. Not the hole storage area.

Here my coding example (V5R2):
 * ------------------------------------------------------------------
d #str1           s          65535    varying
d #str2           s            255    varying
d                                     inz('Let the sun shine!')
d TSTPRC2         pr         65535    varying
d                              255    varying
c                   do        200000
c                   eval      #str1 = TSTPRC2(#str2)
c                   enddo
c                   eval      *inlr = *on
 * ------------------------------------------------------------------
h nomain
d TSTPRC2         pr         65535    varying
d                              255    varying
p TSTPRC2         b                   export
d                 pi         65535    varying
d $InpStr                      255    varying
d #RtnStr         s          65535    varying
c                   eval      #RtnStr = $InpStr
c                   return    #RtnStr
p                 e
 * ------------------------------------------------------------------


I think Scott already addressed the issues, but I'd like to put a different perspective on this. It simply boils down to one thing: Varying length strings in RPG IV are handled by RPG, and not by the underlying W-Code. Operations handled by RPG can be done efficiently, dealing with only the number of bytes required. But operations that are left to W-Code are less speedy since W-Code doesn't understand the implementation of varying length variables, and so deal with the aggregate as a whole. When passing varying length string values as parameters or when returning varying length values, W-Code moves around the whole aggregate, not just what is specified by the current length.


Cheers! Hans



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.