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

How to access table in on_user_command

perage
Participant
1,039

Hi,

I've developed a program using cl_salv_table and are using the event at_user_command to update data based on selected lines.

I've built this on the MVC pattern, which means I have a report <rep> using class lcl_data, class lcl_salv and lcl_salv_events.

The data table itab are filled inside lcl_data and passed back to <rep>, then passed inn as a changing parameter to lcl_salv. The issue is; how do I access it inside the user_command method?

I could of course made it completely global, visible to all, but that would void the MVC principle.

I am not sure if understand your question compeltely but if you want to use an Attribute in Class A which is a private Attribute of class B you have to make them friends.

CLASS - LOCAL FRIENDS

Syntax

CLASS class DEFINITION
LOCAL FRIENDS class1 class2 ...
intf1 intf2 ...

2 REPLIES 2
Read only

pokrakam
Active Contributor
0 Likes
888

Nice question. My approach is that the controller handles the user response (IMHO this is the 'correct' MVC behaviour).

From your description, it seems to me your report is the controller? Make it an own class.

class lcl_controller definition.
  public section. 
    methods start. 
    methods on_double_click for event double_click of cl_salv_events_table. 
  private section. 
    data: model type ref to lcl_data, 
          view  type ref to lcl_salv.
endclass. 

class lcl_controller implementation.
  method start. 
    model = lcl_model=>new( )->load_from_db( ). 
    view = lcl_view=>new( model->get_data_ref( ) ).
    view->display( ). 
  endmethod.

  method on_double_click. 
    model->update_time( row = row time = sy-uzeit ). 
    view->refresh( ).
  endmethod.

endclass.

Note for larger datasets it's a good idea to work with data references to avoid excessive copying of large tables.

Read only

hohoman
Active Participant
0 Likes
888

I am not sure if understand your question compeltely but if you want to use an Attribute in Class A which is a private Attribute of class B you have to make them friends.

CLASS - LOCAL FRIENDS

Syntax

CLASS class DEFINITION
LOCAL FRIENDS class1 class2 ...
intf1 intf2 ...