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

Destructor for Class CL_COLUMN_TREE_MODEL

Former Member
0 Likes
1,666

Dear Colleagues !

In an FM I build a tree for the class CL_COLUMN_TREE_MODEL. It works fine. But this class doesn't have a destructor method for the tree (I want to use it at exit from the FM). Do You know a solution for it ? Is there an FM for destroying the address room after calling this FM (it would be a solution too - if I call this FM more times in the same program).

Thanks a lot for Your help and kind regards

Peter

Moved by moderator to correct forum

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,391

Simply do the following:

lo_column_tree->free( ).

clear lo_column_tree.

lo_column_tree_container->free( ).

clear lo_column_tree_container.

The "free" frees the GUI control on the SAP GUI.

Regards,

Thomas

Dear Colleagues !

In an FM I build a tree for the class CL_COLUMN_TREE_MODEL. It works fine. But this class doesn't have a destructor method for the tree (I want to use it at exit from the FM). Do You know a solution for it ? Is there an FM for destroying the address room after calling this FM (it would be a solution too - if I call this FM more times in the same program).

Thanks a lot for Your help and kind regards

Peter

Moved by moderator to correct forum

8 REPLIES 8
Read only

Former Member
0 Likes
1,391

ABAP does not know the concept of destructors, instead it has the garbage collector, which destroys any object which is no longer referenced. Thus all you have to do is:

1.) call the control framework method "free"; clear the object reference variable of your cl_gui_column_tree.

Regards,

Thomas

Read only

0 Likes
1,391

Hi Thomas,

the variable, which I want to destroy, is defined with reference to CL_COLUMN_TREE_MODEL.

I want to destroy it: FREE OBJECT gw_tree, but I get a syntax error: variables with references cann't be destroyed with FREE.

Do You know perhaps another solution ?

Regards Peter

Read only

matt
Active Contributor
0 Likes
1,391

>

> Hi Thomas,

>

> the variable, which I want to destroy, is defined with reference to CL_COLUMN_TREE_MODEL.

>

> I want to destroy it: FREE OBJECT gw_tree, but I get a syntax error: variables with references cann't be destroyed with FREE.

>

> Do You know perhaps another solution ?

>

> Regards Peter

What you are wanting to do is destroy the object refered to by the object reference variable - not the object reference variable itself. When an object on the heap no longer has any object reference variables assigned to it, then it will be collected (at some undefined time) by the garbage collector.

So,


CREATE gw_tree.
* do stuff
CLEAR gw_tree

will mean no more references to the object created by the CREATE, so the memory the object is using will be reclaimed.

matt

Read only

Former Member
0 Likes
1,392

Simply do the following:

lo_column_tree->free( ).

clear lo_column_tree.

lo_column_tree_container->free( ).

clear lo_column_tree_container.

The "free" frees the GUI control on the SAP GUI.

Regards,

Thomas

Read only

0 Likes
1,391

Hi Thomas,

I make the followings:

class lcl_tree definition inheriting from CL_COLUMN_TREE_MODEL.

...

data: G_TREE TYPE REF TO lcl_TREE,

...

CREATE OBJECT G_TREE

EXPORTING

...

These codes are OK.

At exit I want make:

MODULE exit INPUT.

CALL METHOD g_tree->free().

clear: g_tree.

leave to screen 0.

ENDMODULE. " exit INPUT

but I get the error:

"Die Methode "FREE()" ist unbekannt bzw. PROTECTED oder PRIVATE."

I make anything false ...

Do You have an idea ?

Thanks a lot Peter

Read only

0 Likes
1,391

First try to free the Tree object and than free the Container object.

Like this:


data  o_tree         type ref to cl_column_tree_model.
data  o_container       type ref to cl_gui_custom_container.

MODULE EXIT.
  if not o_tree is initial.
    clear o_tree.
    free o_tree.
  endif.
  if not o_container is initial.
    call method o_container->free.
    free o_container.
  endif.

ENDMODULE.

Regards,

Naimesh Patel

Read only

Former Member
0 Likes
1,391

In your column tree model you somewhere create a tree control and a container for that control, i.e. you call the method "create_tree_control" and you are exporting the container for the control and you get back an object of type cl_gui_control. On this object you call the "free" method. After you freed the control you have to free also the container. The model itself is cleared by clead lo_tree_model.

Regards,

Thomas

Read only

0 Likes
1,391

Hi Naimesh Patel, hi Thomas !

Thank You for helping ! I took the proposal of Naimesh Patel (it comes earlier), and it works fine !!!

I will open another thread in this forum, please check it too !

Thanks a lot and kind regards

Peter