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



Good questions. I've had those recently myself.
The compile will create a temp variable for literals and things like that and
then reuse that temp variable. By "temp" I think we mean "work field". 
So for example, if it needs a 200-byte field in one instance and a 14-byte field
in anther, it'll reuse that 200-byte field.
If a variable is passed to a OPTIONS(*VARSIZE) CONST parm and that variable is
equal to or longer than the parm def, it'll get passed directly.
If the variable is shorter, a substring-like function is used to pass the data
or another temp variable is created.
If a literal is passed, it is copied to a temp variable and that temp variable
is passed. The only guarantee is that the temp variable in this case will be
large enough to hold the literal.

For CONST VARYING, if the value being passed is also a varying, then...
If the variable being passed is longer than the parm def, it is passed directly.
If the variable being passed  is shorter it may or may not be copied to a temp
variable.
If a literal is being passed, it is copied to a temp variable that may be up to
the length of the parm def, but it could be longer or shorter than the parm def,
depending on a number of things.


-Bob Cozzi
www.RPGxTools.com
RPG xTools - Enjoy programming again.

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On
Behalf Of Wilt, Charles
Sent: Friday, May 05, 2006 2:13 PM
To: RPG programming on the AS400 / iSeries
Subject: CONST Parameter passing, varying and *varsize

Ok,

I got a question about using varying and *varsize with CONST parameters.

First, let me make it clear that I do (mostly;-) understand the
differences between varying and *VARSIZE.

Now as to my question, perhaps an example would make it clear.

     d Proc1a          pr
     d  msgData                   32768a   const 
     d                                     options(*varsize)
     d  msgLen                       10u 0 const

     d Proc1b          pr
     d  msgData                   32768a   const 
     d                                     varying

     d Proc2           pr
     d  msgData                   32768a   const 
     d                                     options(*varsize)
     d  msgLen                       10u 0 const


Now the code for Proc1a and Proc2a

     p Proc1a          b
     d Proc1a          pi
     d  msgData                   32768a   const 
     d                                     options(*varsize)
     d  msgLen                       10u 0 const
      /free
         Proc2(msgData:msgLen);
         return;
      /end-free
     p Proc1a          e


     p Proc1b          b
     d Proc1b          pi
     d  msgData                   32768a   const 
     d                                     varying
      /free
         Proc2(msgData:%len(msgData));
         return;
     p Proc1b          e


Now say you call:
       Proc1a('This is a Test':14);
       Proc1b('This is a Test');

I'm trying to understand the interactions between varying and *varsize
when the compiler builds the temporary variable due to the CONST.

Is the temporary for the call to Proc1a 32,768 bytes long or only 14?

How about Proc1b?

Any difference when dealing with a string expression using fixed-length
or varying strings?
       Proc1a('Fld1 is:' + fld1 : %len('Fld1 is:' + fld1));
       Proc1b('Fld1 is:' + fld1);

What about just a varying field by itself?
       Proc1a(varyingFld1:%len(varyingFld1));
       Proc1b(varyingFld1);

I don't think the call to Proc1b would need a temporary variable or
would it?

Perhaps I should have Proc1b defined like so:
     d Proc1b          pr
     d  msgData                   32768a   const 
     d                                     varying options(*varsize)

That would give me a procedure that would accept any size varying field,
which is what I believe I want.  The question is, do I need varying and
*varsize to do what I want; which is minimize the size of any temporary
fields built.


Lastly, it is obvious that no temporary variables are needed when Proc1a
calls Proc2.  How about when Proc1b calls Proc2?  Am I going to get a
32768 byte temporary for that call or not?



Thanks,

Charles Wilt
--
iSeries Systems Administrator / Developer
Mitsubishi Electric Automotive America
ph: 513-573-4343
fax: 513-398-1121
 


As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.