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

CREATE OBJECT inside INITIALIZATION event in ABAP

0 Likes
3,127

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.





1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
1,427

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

3 REPLIES 3
Read only

former_member192854
Active Participant
0 Likes
1,427

If you make use of the object instance in the processes of the screen, INITIALIZATION looks a good spot to me.

Best,

Sander

Read only

naimesh_patel
Active Contributor
0 Likes
1,428

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

Read only

0 Likes
1,427

Thank you Naimesh. It really sounds good