It looks like your max size is off. It should be 352 not 310.
Example:
Dcl-Pi ProgramName Extname('PROGRAMNAME');
Boxes LIKEDS(Boxlist_t) Options(*Varsize);
End-pi;
// Count Groups, Offset to Each Element, Count fields passed in Element, Element
// 2+ 2*10 + 10 * (2+ 20 +1 +9 +1) = 352
Dcl-ds Boxlist_t Len(352) Template Qualified;
Count Int(5) Inz;
Offset Int(5) Dim(10);
End-ds;
Dcl-Ds Boxdta_t TEMPLATE QUALIFIED;
Count Int(5) INZ;
Boxid Char(20) INZ;
BoxType Char(1) INZ;
BoxQty Char(9) INZ;
BoxHex Char(1) INZ;
End-Ds;
Dcl-s Ptr_Box Pointer;
Dcl-ds Box Likeds(Boxdta_t) Based(Ptr_Box);
Dcl-s BoxId Int(5);
Dcl-s textString Varchar(100);
//Boxes.count returns how many offsets were loaded.
For idx = 1 to Boxes.Count;
Ptr_box = %Addr( Boxes ) + Boxes.Offset(idx);
//Box.count should always be 4 since none of the inner elements are optional.
textString = 'Box is ' + Box.Boxid +
' type is ' + Box.BoxType +
' qty is ' + Box.BoxQty +
' hex is ' + Box.BoxHex;
Endfor;
An interesting note is that the offset array is always in the order that the elements were passed to the command.
However, the data for the first element I've found to always be at the end of the chunk of memory defined by the parameter in RPGLE.
You may notice that when you debug the program and pass multiple entries into the command.
Also, I've chosen to define my input parameter as options varsize, however I did set the length of the BoxList ds to the total length I would expect based on the command definition.
Chris Hiebert
Senior Programmer/Analyst
Disclaimer: Any views or opinions presented are solely those of the author and do not necessarily represent those of the company.
-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Jeff Young
Sent: Friday, January 13, 2017 1:27 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: Processing a List from a command
All,
I have a command that defines a list consisting of a maximum of 10 entries of 4 elements each as follows:
PARM KWD(BOXING) TYPE(BOX_DATA) MAX(10) +
PROMPT('Boxing Data')
BOX_DATA: ELEM TYPE(*CHAR) LEN(20) PROMPT('LUCAS Box Id')
ELEM TYPE(*CHAR) LEN(1) PROMPT('Box Type')
ELEM TYPE(*CHAR) LEN(9) PROMPT('Box Qty') +
CHOICE('ie. "000000100" is 1')
ELEM TYPE(*HEX) LEN(1) CONSTANT(X'25')
In my program, I define it as a 310 byte character field:
c Parm inBoxData 310
When I execute the command with a single entry, I get the following data
returned:
EVAL INBOXDATA :X
00000 00010004 0004F1F2 F4F5F4F5 F4C1C1C1 - ......1245454AAA
00010 40404040 40404040 4040C7F0 F0F0F0F0 - G00000
00020 F0F2F0F0 25404040 40404040 40404040 - 0200.
00030 40404040 40F04040 40404040 40404040 - 0
00040 40404040 40404040 40404040 40404040 -
00050 40404040 40404040 40404040 40404040 -
00060 40404040 40404040 40404040 40404040 -
00070 40404040 40404000 00000000 00000000 - .........
I know that the first 2 bytes are the number of entries, but what are the next 4 bytes before the start of my data?
TIA
Jeff Young
Sr. Programmer Analyst
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (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.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
http://amzn.to/2dEadiD
As an Amazon Associate we earn from qualifying purchases.