Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Using container from another global class

Former Member
0 Likes
714

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?

4 REPLIES 4
Read only

MarcinPciak
Active Contributor
0 Likes
634

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

Read only

0 Likes
634

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

Read only

0 Likes
634

These are global classes

Read only

Former Member
0 Likes
634

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