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



"variables as constants"

What I meant is this:
We can have a simple variable
D var1 s 10a Inz( 'test' )

And I can easily make it a constant
D const1 c 'test'

That's all I was really trying to get at there. I'd like to be able to do that for data structures.

For instance, I have an output parameter in a procedure.
D outDS LikeDS( templateOutDS )

I want to initialize this parameter every time the procedure is called. Let the procedure initialize the return values vs the caller (since we're encapsulating business logic here), except I can't Reset a parameter. So instead of clearing each subfield individually, I'm doing this:

// This data structure is like a constant with all default values,
// never to be modified by the program. Defined as Static so the
// memory is only allocated once.
D emptyOutDS DS LikeDS( templateOutDS ) Inz
D Static

outDS = emptyOutDS;


The other example is a data structure that I build to be used as an array. However I want to reference the elements individually as well as doing a lookup.
d DS Inz
d testDS 18a
d MODE_Add 6a Inz( 'Add' )
d MODE_Del Inz( 'Delete' ) Like( MODE_Add )
d MODE_Upd Inz( 'Update' ) Like( MODE_Add )
d testAry Dim( %div( %len(testDS):
d %len(MODE_Add) ) ) Like(MODE_Add)

Sure, if I wanted I could give a name to the DS and Reset it every time I accessed the data structure/array - but that seems like a waste of time (we do a lot of database processing here). I see no reason why the above data structure/array couldn't be resolved at compile time (given some special keyword).



-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Tom Liotta
Sent: Tuesday, April 14, 2009 2:43 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: Data Structure Constant

Kurt Anderson wrote:

Constants are great. But it kind of sucks that we can only have simple [[variables as constants]].

"Variables"? As "constants"?

I'm not sure what that means. However, each DS subfield seems
required to be initialized (INZ()) separately at least through V5R3.
And it appears that "a literal, named constant, figurative constant,
built-in function, or one of the special values *SYS, *JOB, *EXTDFT,
*USER, *LIKEDS, or *NULL" can be used as an INZ() parameter for a DS
subfield -- though not for an entire DS!

So, a group of constants:

DScon1 C const( 'KEY1' )
DScon2 C const( 1 )
DScon3 C const( d'12-31-08' )

Then each DS subfield could be "initialized" with INZ(DScon1),
INZ(DScon2), etc.

The DS itself wouldn't be inviolable unfortunately. But at least it
should be possible to reinitialize it to guaranteed values whenever
desired.

Maybe what's needed is something similar to the STATIC keyword in
the sense that a new keyword would influence how that memory is
handled; something like READONLY that somehow flags the memory range
as not updateable, perhaps by something akin to incorporating the DS
within the program-code memory area.

Tom Liotta

--
Tom Liotta
The PowerTech Group, Inc.
19426 68th Avenue South
Kent, WA 98032
Phone 253-872-7788 x313
253-479-1416
Fax 253-872-7904
http://www.powertech.com
--
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.