I have been reading about LIKEDS
, TEMPLATE
, and BASED
trying to determine if there is a way to create data structure templates (prototypes) with inheritance. I have:
D costs DS QUALIFIED TEMPLATE
D material 6 0
D cutting 6 0
D ...etc...
D boxCosts DS LIKEDS(costs)
D folding 6 0
D ...etc...
D posterCosts DS LIKEDS(costs)
D laminating 6 0
D ...etc...
Where I want boxCosts to look like:
boxCosts:
material
cutting
folding
etc. (no laminating, this isn't a poster)
Is there any way to achieve this type of data structure template? I know I could do:
D boxCosts DS
D common LIKEDS(costs)
D folding 6 0
D ...etc...
But this creates a hierarchy when I want a flat structure.
I could maybe do this with a copybook, but I don't know if it would be worse to have a copy book for just the data structure parts I want in its own file, or to have potentially complicated conditional copy book for the whole application that has a small area for copying this information...? Templates come so close to what I want I suspect I must just be missing something.
If you are wondering, the compile error I get from trying to create an inherited data structure like I have shown is RNF3703: The subfield or parameter definition is not specified within a group.
on the first D spec below the LIKEDS
keyword.
Thanks for reading.
RPG data structures are memory maps. They define a way to group and overlap variables in a specific way in memory. That's why if you LIKEDS() you get a hierarchy - the compiler is copying the hierarchy from the template to your destination.
There's at least one way to flatten the structure:
d costs ds template
d t_material 6s 0
d t_cutting 6s 0
d box e ds extname(boxcosts) prefix(t_) template
d boxCosts ds qualified
d material like(t_material)
d cutting like(t_cutting)
d folding like(t_folding)
boxCosts.cutting = 1;
boxCosts.folding = 2;
The first structure is defined in the program; the second is based on a file. I did that only to show two different ways of getting the subfields defined.
You can accomplish your goal, if you are willing to use SQL to solve the problem. While ILE RPG data structures do not have inheritance, SQL tables can simulate this.
CREATE TABLE costs
(material num(6,0)
,cutting num(6,0)
);
CREATE TABLE boxCosts
( LIKE costs
,folding num(6,0)
,sealing num(6,0)
);
CREATE TABLE postrCosts
( LIKE costs
,laminating num(6,0)
);
If all you care about it the field names and definitions, that method may be fine, and all you need to use those structures in RPG would be
D boxCosts E DS EXTNAME(boxCosts)
D posterCosts E DS EXTNAME(postrCosts)
If field text or other attributes are important to you, then you may be better off with a slightly different strategy.
CREATE TABLE costs
(material num(6,0)
,cutting num(6,0)
);
LABEL ON COLUMN costs
(material text is 'Material Costs'
,cutting text is 'Cutting Costs'
);
CREATE TABLE boxCosts as
(SELECT *
FROM costs
) with no data
;
ALTER TABLE boxCosts
ADD COLUMN folding num(6,0)
ADD COLUMN sealing num(6,0)
;
LABEL ON COLUMN boxCosts
(folding text is 'Folding Costs'
,sealing text is 'Folding Costs'
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With