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

Class parameters not seen in all methods

Former Member
0 Likes
1,152

Dear experts,

Please help!

I have two classes in my program:

Class "screen_init" and class "screen_handler".

Each class has its own constructor plus other methods.

For example class "screen_handler" has methods "constructor", "handle_node_double_click",

"handle_picture_double_click", "handle_textedit_double_click".

In Constructor of class "screen_init" I do:

- define event_handler:

 Data  event_handler type ref to screen_handler

.

- create an object event_handler:

        Create object  event_handler
           exporting textedit = textedit
                      tree = tree.

In definition section of class "screen_handler" I define constructor as:

   methods: constructor importing
                  textedit type ref to cl_gui_textedit
                  tree type ref to cl_gui_simple_tree.

When the program creates an object event_handler - then the Constructor of class "screen_handler" is run.

The problem is that textedit and tree are successfully received in the Constructor of "screen_handler" class. But when it gets to any other method of "screen_handler" class ( method "handle_textedit_double_click", for example) - these objects are empty.

I need tree object when method "handle_textedit_double_click" is run - so I could read textedit and then repopulate the tree depending on textedit value.

Please note that textedit and tree are defined in both classes in Public section:

class screen_init definition.
public section.
    data: textedit type ref to CL_GUI_TEXTEDIT,
            tree type ref to cl_gui_simple_tree.
class screen_handler definition.
  public section.
 data: textedit type ref to CL_GUI_TEXTEDIT,
          tree type ref to cl_gui_simple_tree

Thank you,

Tatyana.

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
960

Hello Tatyana

The only possible reason I see is that you do no save the imported instance into the public instance attributes. Presumably the coding of your CONSTRUTOR method is missing the following coding:

Recommendation: rename your instance attribute, e.g.

class screen_init definition.
public section.
    data: mo_textedit type ref to CL_GUI_TEXTEDIT,
            mo_tree type ref to cl_gui_simple_tree.
class screen_handler definition.
  public section.
 data: mo_textedit type ref to CL_GUI_TEXTEDIT,
          mo_tree type ref to cl_gui_simple_tree  

"       Create event handler instance
        Create object  event_handler
           exporting textedit = textedit  " instance IS BOUND
                      tree = tree.               " instance IS BOUND

" Here we are inside the CONSTRUCTOR
method CONSTRUCTOR.

  me->mo_textedit = textedit.  " save the imported instance to instance attribute
  me->mo_tree      = tree.       "  dito

endmethod.

Regards

Uwe

Hello Tatyana

The only possible reason I see is that you do no save the imported instance into the public instance attributes. Presumably the coding of your CONSTRUTOR method is missing the following coding:

Recommendation: rename your instance attribute, e.g.

class screen_init definition.
public section.
    data: mo_textedit type ref to CL_GUI_TEXTEDIT,
            mo_tree type ref to cl_gui_simple_tree.
class screen_handler definition.
  public section.
 data: mo_textedit type ref to CL_GUI_TEXTEDIT,
          mo_tree type ref to cl_gui_simple_tree  

"       Create event handler instance
        Create object  event_handler
           exporting textedit = textedit  " instance IS BOUND
                      tree = tree.               " instance IS BOUND

" Here we are inside the CONSTRUCTOR
method CONSTRUCTOR.

  me->mo_textedit = textedit.  " save the imported instance to instance attribute
  me->mo_tree      = tree.       "  dito

endmethod.

Regards

Uwe

4 REPLIES 4
Read only

uwe_schieferstein
Active Contributor
0 Likes
961

Hello Tatyana

The only possible reason I see is that you do no save the imported instance into the public instance attributes. Presumably the coding of your CONSTRUTOR method is missing the following coding:

Recommendation: rename your instance attribute, e.g.

class screen_init definition.
public section.
    data: mo_textedit type ref to CL_GUI_TEXTEDIT,
            mo_tree type ref to cl_gui_simple_tree.
class screen_handler definition.
  public section.
 data: mo_textedit type ref to CL_GUI_TEXTEDIT,
          mo_tree type ref to cl_gui_simple_tree  

"       Create event handler instance
        Create object  event_handler
           exporting textedit = textedit  " instance IS BOUND
                      tree = tree.               " instance IS BOUND

" Here we are inside the CONSTRUCTOR
method CONSTRUCTOR.

  me->mo_textedit = textedit.  " save the imported instance to instance attribute
  me->mo_tree      = tree.       "  dito

endmethod.

Regards

Uwe

Read only

0 Likes
960

I agree with Uwe.

Just a small clarification. I think the attributes need to be decalred either as private or protected attribiutes else the concept of having a OOP program is not very much justified.

Cheers

Kareem

Read only

0 Likes
960

... and I agree with Kareem.

However, even SAP standard classes have often public instance attributes (e.g. CL_REBD_BUILDING->ms_detail) but then they are defined as <b>read-only</b>.

Regards

Uwe

Read only

Former Member
0 Likes
960

Guys,

I can't express how much you helped me.

I am new to ABAP though with the years with other programming languages experience.

The 2 lines below were the key to resolve the problem.

me->textedit = textedit.  " save the imported instance to instance
                           "attribute
  me->tree      = tree.       "  dito

Thank you very much!