Passing Lists to other components

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
jyoung
Posts: 653
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Passing Lists to other components

Post by jyoung » Mon Apr 04, 2016 10:57 pm

How do I pass a list to other components?

I have a list defined as such

Code: Select all

def_list name(#PCTCPAIRList) fields(#PRID #PRGROUP #PRSNDRCV #PRSTAMP #PRTRANSI #PRNAME #PRVALUE) counter(#LISTCOUNT) type(*WORKING) entrys(*MAX)
I populate that list in a reusable part and I would like to pass that list to another reusable part (so that I don't have to re-fetch the data).

I've tried passing it via methods and properties, but cannot define the class for it since it is a list.

Thanks,
Joe

User avatar
Jiri
Posts: 43
Joined: Thu Feb 11, 2016 11:41 pm

Re: Passing Lists to other components

Post by Jiri » Tue Apr 05, 2016 1:55 am

It depends on environment you are working in. If the components are VL-Windows components or IBMi components, or WAMs it is quite easy. You cannot pass it directly from one component to another, but you can pass it into function, shared by both and used as 'transaction container'.

Use :
Function Options(*DIRECT *HEAVYUSAGE) RCV_LIST(#PCTCPAIRList)
DEF_LIST (#PCTCPAIRList) ......
DEF_LIST (#PCTCPAIR_IN) ... (the same structure)
* Function logic based on exchanged operation
CASE #STD_CODEL
When '= Clear'
CLR_LIST #PCTCPAIR_IN
When ' = READ'
CLR_LIST #PCTCPAIRList
SELECTLIST #PCTCPAIR_IN
Add_entry #PCTCPAIRList
endselect
when '= WRITE'
CLR_LIST #PCTCPAIR_IN
SELECTLIST #PCTCPAIRList
Add_entry #PCTCPAIR_IN
Endselect
Endcase
RETURN


Then you can from both components clear, put or get the list data, i.e. :
* Put data populated in component:
#STD_CODEL := WRITE
EXCHANGE #STD_CODEL
CALL *DIRECT MYFUNCT PASS_LIST(#PCTCPAIRList)
...


Read data to component:
#STD_CODEL := READ
EXCHANGE #STD_CODEL
CALL *DIRECT MYFUNCT PASS_LIST(#PCTCPAIRList)
...


The *HEAVYUSAGE option is esential for keeping the function shared by all job components.
All this is very fast, because only memory operation are done, no additional I/O.

Function cannot be used in VL-WEB!

jyoung
Posts: 653
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Passing Lists to other components

Post by jyoung » Tue Apr 05, 2016 2:13 am

I am in VL-Web. I have a reusable part (panel) that loads some data from a server module. That panel shows a "summary" version of the data even though all data has been retrieved. I have a popup component that I would like to show all of the data when a user clicks a "view all" button.

User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: Passing Lists to other components

Post by Stewart Marshall » Tue Apr 05, 2016 6:05 am

Passing a working list is not ideal in the object world. Better is to create a collection of data and pass a reference to the collection. This will ensure that you only have a single instance of the data rather than the many that you'd have by passing a working list.

V14 makes this super simple by using the *ListFields of user designed controls such as Prim_tree.

You can create a simple reusable part to represent you data object. It will look a bit like this.

Begin_Com Role(*EXTENDS #PRIM_OBJT *listFields #ListFields)

* These field values will be mapped in to this object as part of the instance being created
* They will also be mapped in to the component when the collection is accessed using list Selectlist and Get_Entry
Group_By Name(#ListFields) Fields(#EMPNO #SURNAME #GIVENAME #ADDRESS1 #ADDRESS2 #ADDRESS3 #POSTCODE #PHONEHME #PHONEBUS #DEPTMENT #SECTION #SALARY #STARTDTE #TERMDATE #MNTHSAL #empthm)

End_Com

This can then be used as an object in a collection.

Define_Com Class(#Prim_acol<#MyDataObject>) Name(#Data)

and the call to the server function can return the data directly in to the collection, instantiating the objects and passing the field values in.

Define_Com Class(#ServerModule.GetData) Name(#GetData)
#GetData.ExecuteAsync( #Data )


Sample xDemoWebPassingWorkingLists demonstrates the technique
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au

jyoung
Posts: 653
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Passing Lists to other components

Post by jyoung » Tue Apr 05, 2016 7:14 am

That was a lot easier than how I was doing it.

Thanks.

Post Reply