|
Comments inline...
On Thu, Sep 10, 2009 at 9:34 AM, Vern Hamberg <vhamberg@xxxxxxxxxxx> wrote:
I also do not recommend defining short fields as varying - don't
remember the length, but I'd not make anything 20 or less into a varying
length.
I'd recommend making even short fields varying. In my mind it is not
the length of the field that matters, but how many times I'd possibly
end up using %trimr() on it. A great example, 10A fields designed to
hold library, file, or member names. Much better to %trimr() once
before storing the data IMHO. When I have a short varying field, I
simply allocate the max size for the field. Which means each fields
cost me an extra 2 bytes vs. fixed, not a big deal now-a-days.
Once a field is short enough, 5A or so, it's unlikely that I'd ever
%trimr() it and thus unlikely that I'd make it varying.
One advantage of varying length variables in RPGLE is that you don't
have to use the %trim built-in function. You do have to know that if you
set a varying length variable to the value of a fixed length variable,
without using the trim on the fixed length one, then the varying one is
set to the length of the fixed one. As an example, say you have a field
CHAR200V defined as 200 A varying - and a field CHAR50F defined as 50 A
fixed.
eval char50f = 'aaaaaaaaaabbbbbbbbbb'
That is 20 characters long, and there are 30 trailing blanks.
eval char200v = char50f
Then char200v will be assigned a length of 50 (first 2 bytes carry the
length). You probably don't want this.
eval char200v = %trim(char50f)
I know Vern really meat %trimr() here. <grin> %trimr() is preferred
when you intend only to trim trailing spaces.
-Charles
As an Amazon Associate we earn from qualifying purchases.
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.