views:

1418

answers:

4

Say I have a data structure, such as

d dog           DS                  qualified
d   name                        20
d   breed                       20
d   birthdate                    8  0

I can then define

d   poochie                         likeds(dog)

and use poochie.name, etc.

But can I just set up the 'dog' as a template without creating the structure in memory?

A: 

To the best of my knowledge, no. But it might be possible to do something similar with subprocedures.

Post this question on Midrange.com RPG-L and someone smarter than me might be able to answer your question.

Mike Wills
Ok, thanks Mike.
+3  A: 

Two options come to mind. The first is to create a source member with the d-specs for the dog attributes and instead of using likeds(dog), have a /copy after each data structure that will use that subfield definition. In my opinion, this can make for some sloppy code and can make things difficult for someone to analyze down the road. On the other hand, if you are using this same data structure in multiple programs, there are benefits.

The second option that comes to mind is to use the Based() keyword on the dog data structure and then define a pointer field. The pointer field will take up some memory, but the dog data structure will not take up any memory until your program allocates it. The Based() keyword does not carry over into other data structures defined against it with LikeDS(). So that way you have your data structure defined in your program source. You don't have to allocate memory for it and you don't have to set your pointer to any value. It defaults to Null. Just be careful not to access the dog data structure in your code. You'll get a pointer error that looks the same as if your program was called without a required parameter.

Tracy Probst
+3  A: 

In V6R1 there will be another keyword that is called TEMPLATE. Datastructures with It are not created in the memory and are just used by the compiler for reference. You can also combine it with inz() to have default values in your likeds().

squarefox
+2  A: 

Do this: BASED(pointer-name)

Using the pointer is unnecessary---I think will do what you want.