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

ABAP Objects: Private variable with reference to global internal table

Former Member
0 Likes
1,384

Hello. I want an object that can hold a private reference

to a global internal table so that when one of it's methods are invoked, the global table contents are modified.

Simplification of scenario:


class myObject definition.
*
  public section.
*
    methods: 
      set_global_table
        importing reference(i_table) type standard table,
*
      change_global_table.
*
  private section.
*
    data:
      m_pointer_to_table " not sure how to type this"
*
endclass.
*
class myObject implementation.
*
  method set_global_table.
*
    m_pointer_to_table = i_table. " this needs to  "
                                  " assign a pointer to "
                                  " the global variable "
*
  endmethod.
*
*
  method change_global_table.
*
    refresh m_pointer_to_table. "this should change "
                                "the contents of global "
                                "variable "
  endmethod.
*
endclass.
*
*
data: gt_itable   type standard table of t_widget,
      go_myobject type ref to myobject.
*
* Main code
*
  create object go_myobject.
*
*
*
* phantom code fills gt_itable
*
*
  call method go_myobject->set_global_table
                exporting i_table = gt_itable.
*
  call method go_myobject->change_global_table.
*
*
  if gt_itable is initial.
*
     write 'this should output'.
*
  endif.

The code here doesn't work and I've tried messing with field-symbols, etc. all to no avail. Thank you for any help you could provide!

Brett

6 REPLIES 6
Read only

Former Member
0 Likes
1,047

Hi,

One small question. Is this pointer to global table always pointing to same internal table or differnt tables depending on the situation in runtime.

Regards,

Ramesh

Read only

0 Likes
1,047

Hi Ramesh,

There's a global table that stores the data for an ALV grid control.

I have an object that holds the event handler for a tree control. When a person double clicks on a node, I want to query a db and reset the grid data within the event handler.

Since there's no way to pass in the global table on the event handler method, the object I've defined needs to have a reference to it already in the form of a class/private variable.

Hope this helps clarify!

Thanks,

Brett

Read only

0 Likes
1,047

I'm not sure that I completely understand what you are trying to do, but in your event handler method, can you call a subroutine(FORM) that would refresh your grid data?

REgards,

Rich Heilman

Read only

0 Likes
1,047

Rich,

That's definitely an option. I was just hoping to find a way within the OO context.

I'm going to settle with your suggestion.

Thanks!

Brett

Read only

0 Likes
1,047

I've been messing with your example code for a while now, trying to use field symbols, but even then the field symbol must be global. You may be able to pass the table to a method like you do when filling it, and refresh inside the method.

Regards,

Rich Heilman

Read only

ChristianFi
Active Participant
0 Likes
1,047

Just typed in this editor - so no syntax-check but you will get the idea:

Pass the internal table and get the reference of it

Store the reference and manipulate the global contents with local field-symbols to which you have assigned the reference.

Hope this helps

Christian

>


> class myObject definition.
> *
>   public section.
> *
>     methods: 
>       set_global_table
> importing reference(i_table) type standard
> standard table,
> *
>       change_global_table.
> *
>   private section.
> *
>     data:
> m_pointer_to_table type ref to data
> *
> endclass.
> *
> class myObject implementation.
> *
>   method set_global_table.
> *
     GET REFERENCE of i_table into m_pointer_to_table.
>   endmethod.
> *
> *
>   method change_global_table.
> *
  field-symbols: <lit_table> type any table. 
    assign m_pointer_to_table to <lit_table>.
 * manipulate <lit_table>

>   endmethod.
> *
> endclass.
> *
> *
> data: gt_itable   type standard table of t_widget,
>       go_myobject type ref to myobject.
> *
> * Main code
> *
>   create object go_myobject.
> *
> *
> *
> * phantom code fills gt_itable
> *
> *
>   call method go_myobject->set_global_table
>                 exporting i_table = gt_itable.
> *
>   call method go_myobject->change_global_table.
> *
> *
>   if gt_itable is initial.
> *
>      write 'this should output'.
> *
>   endif.

>

>

> The code here doesn't work and I've tried messing

> with field-symbols, etc. all to no avail. Thank you

> for any help you could provide!

>

> Brett