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



David,

First of all, you can define varying fields in your dictionary. Use
the DDS keyword VARLEN. If you decide to start actually using
variable length fields in your tables (which I do recommend) be sure
you understand how the data is stored for the fields. The best plan
is to allocate space for the field which will handle most of the
values you expect to see.

As to why you should use variable length fields, besides making the
code cleaner when handling strings, performance is much better.

http://www.itjungle.com/fhg/fhg091008-story01.html

Also from http://systeminetwork.com/article/essential-rpg-iv-style-guide

The Power of Variable-Length Fields

Barbara Morris: I just thought of this when I read the style
guide's plea to use built-in functions instead of arrays to handle
strings. The new (with V4R2) varying- length character type can also
simplify string-handling code, as well as make it more efficient. I
recommend using varying-length fields as CONST or VALUE parameters to
every string-handling subprocedure, as well as for string temporaries.
(I recently worked with an RPG programmer here, and we reduced the
number of lines in a subprocedure from about 10 icky lines to two
simple and straightforward lines, mostly through the use of varying-
length parameters.) Here's a little example; not only does it look
better, but it's also faster (no %TRIMs). Instead of

C EVAL Name = %TRIMR(Lib) + '/' +
C %TRIMR(File) + '(' +
C %TRIMR(Mbr) + ')'

with variable-length fields, you can use

C EVAL Name = Lib + '/' +
C File + '(' +
C Mbr + ')'

I thought I should check my claim that this approach is faster,
and it turns out it's more than twice as fast to produce
"Lib/File(Mbr)" where all variables (except "Name") are 10 characters
long.


HTH,
Charles

On Thu, Sep 10, 2009 at 5:47 AM, David FOXWELL <David.FOXWELL@xxxxxxxxx> wrote:
Hi,

I was asked why use this kind of variable. A part from tidying up the code when concatenating text fields, I wasn't sure. The problem is that our data dictionary is used in all our RPG sources and all zones are supposed to be declared like a field in the dictionary.

Are there other advantages?

Thanks
--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.



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.