Collection in collections

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
soa
Posts: 339
Joined: Mon Dec 07, 2015 3:15 pm

Collection in collections

Post by soa » Thu Sep 26, 2019 4:33 pm

I have a reusable part call #MARKENTRY which contains an array of strings like

Define_Pty Name(StudentId) Get(*AUTO #STDID) Set(*AUTO #STDID)
Define_Com Class(#PRIM_ACOL<#SMMKC2>) Name(#ItemMarkCol)

In my model RP I have a collection of MARKENTRYs

Define_Com Class(#PRIM_ACOL<#MARKEntry>) Name(#StdMarkCol)

Which I'm populating like

#iMarkEntry <= *New #MarkEntry
#iMarkEntry.StudentId := #STDID
#StdMarkCol.Insert( #iMarkEntry )

Which is great and I do this all the time

My problem is population the ItemMarkCol

I can code the following line which compiles but crashes at time with

#iMarkEntry.Marks<1> := #STDMKC_1

'Index 1 is outside the allowable range (1 to 0)

#iMarkEntry.Marks. doesn't have any methods such add or insert.


I don't know what I'm doing and the documentation doesn't help! Any ideas?

LANSAGuru
Posts: 68
Joined: Thu Mar 24, 2016 5:31 am

Re: Collection in collections

Post by LANSAGuru » Fri Sep 27, 2019 1:13 am

Hard to know exactly what the problem is because

#iMarkEntry.Marks<1> := #STDMKC_1

You have not provided the details for a .Mark or what the #STDMKC_1 represents.

In the abstract your are nesting collections which should be possible.
I think you will need to first get a pointer to the collection inside the first level collection, and then call a method inside that specific instance to add/update/remove entries.

I don't have a ready made example of this off hand but it should be fairly straight forward. You have a temp object which represents the first row...do an assign #temp <= #StdMarkCol<#stid>

Then #temp.mAdd(parm)
Which will reference a method inside the specific #MARKENTRY RP. There you would write the code to update the collection living inside that rp. Remember, that RP could be ANYTHING....it could contain 100 fields and 10 separate collections...you need to expose that to the world if you want it update able.

Hopefully someone on the forum has and example of this.

If not, when I have time I will write an example given time of a simple 2 level nested collection.

Paul

soa
Posts: 339
Joined: Mon Dec 07, 2015 3:15 pm

Re: Collection in collections

Post by soa » Fri Sep 27, 2019 3:27 pm

Thanks for the response.

The #STDMKC_1 variable is just a *CHAR 5 so this is the simplest array possible.

BrendanB
Posts: 41
Joined: Tue Nov 24, 2015 10:29 am

Re: Collection in collections

Post by BrendanB » Fri Sep 27, 2019 3:46 pm

soa,

you need to:

Define_Pty Name(ItemMarks) get(*REFERENCE #ItemMarkCol)

then you can do:

#StdMarkCol.ItemMarks.Insert((*New #SMMKC2))
#StdMarkCol.ItemMarks.Last := #STDMKC_1 (could also do: #StdMarkCol.ItemMarks<#StdMarkCol.ItemMarks.ItemCount> := #STDMKC_1

and this should work.

Post Reply