I normally use the template method, however, in your example, you're defining the initial values as *n, and then laying the array over that. If you change the way you're writing it, you could define the values more directly, such as the following example I use to specify Excel column headings. As a bonus, this method can calculate the size of your array automatically.
dcl-s CurCol_t uns(3) template;
dcl-s ColHdr_t varchar(50) template;
dcl-s ColWid_t uns(3) template;
dcl-ds CD_t qualified template;
Col like(CurCol_t);
Wid like(ColWid_t);
Hdg1 like(ColHdr_t);
end-ds;
/////////////////////////////////////
//Tab 1 layout
/////////////////////////////////////
dcl-ds T1 qualified;
TtlSiz;
dcl-ds Fac overlay(TtlSiz:*next);
Col like(CurCol_t) INZ;
Wid like(ColWid_t) inz(5);
Hdg1 like(ColHdr_t) inz('Fac');
end-ds;
dcl-ds Whs overlay(TtlSiz:*next);
Col like(CurCol_t) INZ;
Wid like(ColWid_t) inz(5);
Hdg1 like(ColHdr_t) inz('Whs');
end-ds;
arr likeds(CD_t) dim(T1Cnt) pos(1);
end-ds;
dcl-c T1Cnt %div(%size(T1.TtlSiz):%size(CD_t));
-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Justin Taylor
Sent: Thursday, September 12, 2019 12:40 PM
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: Nested DS & LIKE()
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
I'm trying to use a nested data structure to create a compile-time key/value-pair store. It works if I explicitly set the type for each of the initial values, but I'd like to use a LIKE() instead. Is there a way to do that directly? Plan B would be to create a template data structure to reference.
Here's the code snippet with compiler errors inserted.
Dcl-ds A qualified ;
*n like(A.xyz.key) inz(1) ;
RNF7030: The name or indicator A.XYZ.KEY is not defined.
RNF0623: The simple qualified name is not specified correctly.
*n varChar(128) inz('AA') ;
*n int(10) inz(2) ;
*n varChar(128) inz('BB') ;
*n int(10) inz(3) ;
*n varChar(128) inz('CC') ;
Dcl-ds xyz dim(3) pos(1) ;
key int(10) ;
value varChar(128) ;
End-ds ;
End-ds;
TIA
--
This is the RPG programming on IBM i (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
https://amazon.midrange.com
As an Amazon Associate we earn from qualifying purchases.