Page 1 of 1

Passing Lists to other components

Posted: Mon Apr 04, 2016 10:57 pm
by jyoung
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

Re: Passing Lists to other components

Posted: Tue Apr 05, 2016 1:55 am
by Jiri
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!

Re: Passing Lists to other components

Posted: Tue Apr 05, 2016 2:13 am
by jyoung
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.

Re: Passing Lists to other components

Posted: Tue Apr 05, 2016 6:05 am
by Stewart Marshall
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

Re: Passing Lists to other components

Posted: Tue Apr 05, 2016 7:14 am
by jyoung
That was a lot easier than how I was doing it.

Thanks.