‎2011 Jun 03 7:11 AM
There are two global classes being used by me in a program - Class A and Class B.
Class A contains the container to display ALV.
Class B contains the logic to display ALV.
class B is used as attribute class in Class A.
How is that I can use the container from Class A from class B?
‎2011 Jun 03 9:30 AM
Like this?
class A ...
public section.
methods: get_container returining value(ref_cont) type ref to ...,
constructor.
private section.
data ref_container type ref to....
endclass.
class A impl...
method get_container.
ref_cont = me->ref_container.
endmethod.
method constructor.
create object ref_container ....
endmethod.
endclass.
class B ...
public section.
methods: constructor,
display alv.
private section.
data ref_alv type ref to....
data ref_A type ref to A.
endclass.
class B impl...
method constructor.
data lr_container type ref to ...
if ref_A is not bound.
create object ref_A.
endif.
"get container from class A
lr_container = ref_A->get_container( ).
create object ref_alv
exporting
....
container = lr_container
...
endmethod.
method display_alv.
call method ref_alv->set_table_for_first_display...
endmethod.
endclass.
If storing container's reference under local LR_CONTAINER in class B constructor causes not displaying ALV, you will have to store this under class B attribute. Alternative would be directly indicating the container reference as parent to ALV by calling functional method like
create object ref_alv
exporting
..
container = ref_A->get_container( )
this will however work in recent releases of SAP NW AS.
Regards
Marcin
‎2011 Jun 06 9:29 AM
let me be more clear, Class A has container with spilter where the screen is split into 2 parts. The frist part having a drop down button and second part should display the alv grid based on the input from drop down button. Which means I should fill the alv and send that to class A.
Edited by: ibmsateeshkumar on Jun 6, 2011 10:33 AM
‎2011 Jun 08 4:47 AM
‎2011 Jun 08 11:00 PM
not sure background of your design, but in your case container class A better be used as utilities class so it should be used in B but not visa versa. Then you can use A's container in B as general