‎2014 Aug 12 3:39 PM
Hi everyone,
I have one question, can we create object inside INITIALIZATION event. Why, I am asking this question is, because most of the time I have seen people to create object inside start-of-selection. Please give your thought on this.
The code I have just coded below is also right or wrong?
CLASS lcl_build_data DEFINITION.
PUBLIC SECTION.
METHODS : constructor,
get_all_files,
validate_site.
*-- Private Section declaration
PRIVATE SECTION.
METHODS : clear_and_refresh,
display_output.
ENDCLASS.
*** class declaration, create instance for the class
DATA: gv_data TYPE REF TO lcl_build_data.
INITIALIZATION.
*** Create class object. Constructor method will be called to Refresh
*** and Clear all internal tables and Work areas
CREATE OBJECT gv_data.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON s_vkbur.
*** Sales Office validation
CALL METHOD gv_data->validate_site.
*----------------------------------------------------------------------*
* START-OF-SELECTION *
*----------------------------------------------------------------------*
START-OF-SELECTION.
*** Get the list of all files from unix dir.
CALL METHOD gv_data->get_all_files.
‎2014 Aug 12 4:31 PM
Since you are using the same object for your Selection screen related events, AT SELECTION-SCREEN, you would have to instantiate the object in the INITIALIZATION event. If your object usage is just for the data - In case you use the MVC design pattern, you should push back the object creation in START-OF-SELECTION.
Regards,
Naimesh Patel
‎2014 Aug 12 3:53 PM
If you make use of the object instance in the processes of the screen, INITIALIZATION looks a good spot to me.
Best,
Sander
‎2014 Aug 12 4:31 PM
Since you are using the same object for your Selection screen related events, AT SELECTION-SCREEN, you would have to instantiate the object in the INITIALIZATION event. If your object usage is just for the data - In case you use the MVC design pattern, you should push back the object creation in START-OF-SELECTION.
Regards,
Naimesh Patel
‎2014 Aug 12 4:42 PM