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



Matt - that's true - but the rest of the world - and SQL - does not have the concept of allocated length - this is a way to optimize disk space usage on the i that other platforms don't have. It may have to do with how IBM chose to implement varying length - using that auxiliary space.

Vern

Haas, Matt (CL Tech Sv) wrote:
One other good reason to use varying length DB fields is that the rest of the world has been doing this for a long, long time and it makes it easier to work with people who are used to other databases.

Matt

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Charles Wilt
Sent: Thursday, September 10, 2009 9:55 AM
To: RPG programming on the IBM i / System i
Subject: Re: Use of VARYING fields

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