<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Correct encapsulation between report, salv instance and user-command in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/correct-encapsulation-between-report-salv-instance-and-user-command/m-p/634669#M26776</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
  &lt;P&gt;I'm wondering what is the most correct way of using a MVC/encapsulation when creating a report and using CL_SALV for output and varous user-commands?&lt;/P&gt;
  &lt;P&gt;I've just created a report with two local classes; &amp;lt;model&amp;gt; and &amp;lt;view&amp;gt;, the later being the salv instance.&lt;/P&gt;
  &lt;P&gt;The model returns a table with a lot of data, which is then passed to the &amp;lt;view&amp;gt; in the report. My problem is that I don't know where to correctly put the event-handler methods as they don't have access to the instantiated &amp;lt;model&amp;gt; class where all the methods that the user-command will execute are. Also, will the event handler be able to change values in the table when called? I'm pretty sure the only thing sent into the user-command method are the rows and cols of the chosen table entry.&lt;/P&gt;
  &lt;P&gt;Hopes this is not too unclear - I'll try to illustrate with a simplified code example&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;Report test.

include lcl_model.
include lcl_view.

data: gt_data type lcl_model=&amp;gt;mty_t_data.

" Instantiate
data(go_model) = new lcl_model( ).
data(go_view) = new lcl_view( ).

" Get data

gt_data = go_model-&amp;gt;get_data( )

" View data

go_view-&amp;gt;output( changing ct_data = gt_data ).


=============================================
Somewhere else...
=============================================

METHOD on_user_command.

* DON'T THINK GT_DATA IS KNOWN HERE

assign gt_data[ row ] to field-sybol(&amp;lt;ls_data&amp;gt;). "row comes from u-comm


* GO_MODEL ARE NOT KNOWN HERE - refactor or instantiate new local object?

go_model-&amp;gt;change_something( changing is_data = &amp;lt;ls_data&amp;gt; ). 



ENDMETHOD.

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 17 Mar 2018 19:01:05 GMT</pubDate>
    <dc:creator>perage</dc:creator>
    <dc:date>2018-03-17T19:01:05Z</dc:date>
    <item>
      <title>Correct encapsulation between report, salv instance and user-command</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/correct-encapsulation-between-report-salv-instance-and-user-command/m-p/634669#M26776</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
  &lt;P&gt;I'm wondering what is the most correct way of using a MVC/encapsulation when creating a report and using CL_SALV for output and varous user-commands?&lt;/P&gt;
  &lt;P&gt;I've just created a report with two local classes; &amp;lt;model&amp;gt; and &amp;lt;view&amp;gt;, the later being the salv instance.&lt;/P&gt;
  &lt;P&gt;The model returns a table with a lot of data, which is then passed to the &amp;lt;view&amp;gt; in the report. My problem is that I don't know where to correctly put the event-handler methods as they don't have access to the instantiated &amp;lt;model&amp;gt; class where all the methods that the user-command will execute are. Also, will the event handler be able to change values in the table when called? I'm pretty sure the only thing sent into the user-command method are the rows and cols of the chosen table entry.&lt;/P&gt;
  &lt;P&gt;Hopes this is not too unclear - I'll try to illustrate with a simplified code example&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;Report test.

include lcl_model.
include lcl_view.

data: gt_data type lcl_model=&amp;gt;mty_t_data.

" Instantiate
data(go_model) = new lcl_model( ).
data(go_view) = new lcl_view( ).

" Get data

gt_data = go_model-&amp;gt;get_data( )

" View data

go_view-&amp;gt;output( changing ct_data = gt_data ).


=============================================
Somewhere else...
=============================================

METHOD on_user_command.

* DON'T THINK GT_DATA IS KNOWN HERE

assign gt_data[ row ] to field-sybol(&amp;lt;ls_data&amp;gt;). "row comes from u-comm


* GO_MODEL ARE NOT KNOWN HERE - refactor or instantiate new local object?

go_model-&amp;gt;change_something( changing is_data = &amp;lt;ls_data&amp;gt; ). 



ENDMETHOD.

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Mar 2018 19:01:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/correct-encapsulation-between-report-salv-instance-and-user-command/m-p/634669#M26776</guid>
      <dc:creator>perage</dc:creator>
      <dc:date>2018-03-17T19:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: Correct encapsulation between report, salv instance and user-command</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/correct-encapsulation-between-report-salv-instance-and-user-command/m-p/634670#M26777</link>
      <description>&lt;P&gt;In MVC, the controller has an instance of the view and an instance of the model. The model handles everything that's to do with the application and nothing to do with the presentation to the end user. It has all the business logic. The view is your SALV instance. That leaves your controller, which handles the interactions between the model and the view. That is where your event handlers go.&lt;/P&gt;
  &lt;P&gt;In a report I have a main class. I might have another class for handling selection screen interaction, or it might be part of main. I usually allow the main class to access report global variables, like parameters, directly, but the model, never. Sometimes, for simple reports, the main class takes the role of the controller. The controller instantiates the CL_SALV_TABLE, and is the correct places for events.&lt;/P&gt;
  &lt;P&gt;It looks to me like your problem is that you're trying to make the report program itself, directly the view. That won't really work, as you can't have methods directly in it. You need your controller class.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Mar 2018 12:06:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/correct-encapsulation-between-report-salv-instance-and-user-command/m-p/634670#M26777</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2018-03-18T12:06:13Z</dc:date>
    </item>
  </channel>
</rss>

