Hi Darryl,

You no longer have to use templates. You can write lower-level DSs directly into the original DS, which is more readable.

dcl-ds dsOBK368 qualified;
CMSnumber varchar(6) ; // obcsq100.kcms#
EnteredBy varchar(10); // obcsq100.kenusr
Currency varchar(3); // mscmp100.ccrcd
// Use USD if blank
dcl-ds dsErrorUsers dim(5) ;
User varchar(10); // obcsq100.ke1usr
// obcsq100.ke2usr
// obcsq100.ke3usr
// obcsq100.ke4usr
// obcsq100.ke5usr
end-ds;
SalesmanNumber varchar(3); // obcsq100.ksalno
SalesManName varchar(25); // sasmp100.smnam
dcl-ds dsCMSLines dim(100) ;
LineNumber varchar(3); // obcsq200.kline
Product varchar(15); // obcsq200.kprdn
ReasonCode varchar(3); // obcsq200.klrcd
ReturnQuantity varchar(6); // obcsq200.klnqty (5,0)
InvoicePrice varchar(15); // obcsq200.kinvpr (13,3)
RequestedPrice varchar(15); // obcsq200.kreqpr (13,3)
ListPrice varchar(15); // obcsq200.kprice (13,3)
CMSAmount varchar(15); // List Price * Return Qty
ApprovalType char(1); // obcsq100.kcmsty
NextUser varchar(10); // obcsq100.knxusr
NextApprover varchar(10); // obcsq100.knxapv
EditAllowed char(1); // Default Y
end-ds;
end-ds;

The good syntax is

dsOBK368.dsCMSLines(wCount).LineNumber = %char(dsOBCSQ200_a.KLINE) ;



-----Message d'origine-----
De : RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> De la part de dfreinkel@xxxxxxxxxxxxxxxxx
Envoyé : lundi 1 septembre 2025 18:05
À : 'RPG programming on IBM i' <rpg400-l@xxxxxxxxxxxxxxxxxx>
Objet : Help with nested data structures/arrays



ATTENTION : Ce message provient d'une source EXTERNE. Veuillez n'ouvrir les liens ou pièces jointes que si vous êtes sûr de l'expéditeur.



This is something I have not done before, working with nested data structures.



Here is an abbreviated definition of the data structure.



dcl-ds dsOBK368 qualified;



CMSnumber varchar(6) ; // obcsq100.kcms#

EnteredBy varchar(10); // obcsq100.kenusr



Currency varchar(3); // mscmp100.ccrcd

// Use USD if blank



dcl-ds dsErrorUsers likeds(dsErrorUsers_t) dim(5) ;



SalesmanNumber varchar(3); // obcsq100.ksalno

SalesManName varchar(25); // sasmp100.smnam



dcl-ds dsCMSLines likeds(dsCMSLines_t) dim(100) ;

end-ds;



dcl-ds dsErrorUsers_t qualified Template;

User varchar(10); // obcsq100.ke1usr

// obcsq100.ke2usr

// obcsq100.ke3usr

// obcsq100.ke4usr

// obcsq100.ke5usr

end-ds;



dcl-ds dsCMSLines_t qualified Template;

LineNumber varchar(3); // obcsq200.kline

Product varchar(15); // obcsq200.kprdn

ReasonCode varchar(3); // obcsq200.klrcd

ReturnQuantity varchar(6); // obcsq200.klnqty (5,0)

InvoicePrice varchar(15); // obcsq200.kinvpr (13,3)

RequestedPrice varchar(15); // obcsq200.kreqpr (13,3)

ListPrice varchar(15); // obcsq200.kprice (13,3)

CMSAmount varchar(15); // List Price * Return Qty

ApprovalType char(1); // obcsq100.kcmsty

NextUser varchar(10); // obcsq100.knxusr

NextApprover varchar(10); // obcsq100.knxapv

EditAllowed char(1); // Default Y

end-ds;



Snippet of RPG



dsOBK368.dsCMSLines[wCount].LineNumber =
%char(dsOBCSQ200_a.KLINE) ;

dsCMSLines[wCount].Product = dsOBCSQ200_a.KPRDNO ;

dsOBK368.dsCMSLines.ReasonCode = dsOBCSQ200_a.KLRCD ;





Question:

1. How do I increment the element number ? The above does not get past
the compiler. I have tried it the other way too.

dsCMSLines.Product[wCount] = dsOBCSQ200_a.KPRDNO ;



2. Compiler complains about the first lines saying the field types are
not the same. However, I am converting the packed to character using %CHAR.



This is an SQLRPGLE program on v7.4.





Thank you.

Darryl Freinkel

A4G

Telephone: 770.321.8562



--
This is the RPG programming on IBM i (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx<mailto:RPG400-L@xxxxxxxxxxxxxxxxxx> To subscribe, unsubscribe, or change list options,
visit: https://urldefense.com/v3/__https://lists.midrange.com/mailman/listinfo/rpg400-l__;!!J76aczzK!zkwXR2khoZpyaFUYQDdK7TZdzsvpcZx5ovVYn6GPQ4NSQ6e_7M5-fQVdosabOh-8fDDtAEGdrMA-t7Q9AViNhg1JaRiyC2yS$
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx<mailto:RPG400-L-request@xxxxxxxxxxxxxxxxxx>
Before posting, please take a moment to review the archives at https://urldefense.com/v3/__https://archive.midrange.com/rpg400-l__;!!J76aczzK!zkwXR2khoZpyaFUYQDdK7TZdzsvpcZx5ovVYn6GPQ4NSQ6e_7M5-fQVdosabOh-8fDDtAEGdrMA-t7Q9AViNhg1JaaLOy7nG$ .

Please contact support@xxxxxxxxxxxxxxxxxxxx<mailto:support@xxxxxxxxxxxxxxxxxxxx> for any subscription related questions.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2025 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.