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

Getting the objects for a class

Former Member
0 Likes
543

I am able to get all live classes of a dynpro by using method cl_gui_cfw=>get_living_dynpro_controls. (Also thanks to this forum).

The resulting table has a reference to a class like ...

.

How do I use this reference to:

1. Get the objects for it?

2. How can I then free the object from memory by using the "free" method.

I guess I am asking how to dynamically assign it, then make sure it has a free method and then to use the method to actually free it.

2 REPLIES 2
Read only

uwe_schieferstein
Active Contributor
0 Likes
515

Hello Johan

Method cl_gui_cfw=>get_living_dynpro_controls return the living control instance in a table type CNTO_CONTROL_LIST (TYPE REF TO CL_GUI_CONTROL OCCURS 0, type-pool CNTO).

Thus, simply loop over the itab because CL_GUI_CONTROL is the superclass of all other GUI controls:

DATA:
  lo_control    TYPE REF TO cl_gui_control,
  lt_controls   TYPE cnto_control_list.

" lt_controls contains the living control instances

  LOOP AT lt_controls INTO lo_control.
    lo_control->free( ).
  ENDLOOP.

Regards

Uwe

Read only

Former Member
0 Likes
515

Hello Uwe

My first reaction was "NO it cannot be that easy!!". It almost was but on the second line I get a short dump. Then I realised why: the other live control in the table was a sub class of the first class and as a result it was cleared on the first call.

So I modified the call to be a recursive call (of the form) as follows...

form clear_live_controls .
DATA:
  gt_list       TYPE cnto_control_list,
  gt_wa like line of gt_list.

  REFRESH: gt_list.
  CALL METHOD cl_gui_cfw=>get_living_dynpro_controls
    IMPORTING
      control_list = gt_list.
  describe table gt_list lines tab_lines.
  if tab_lines = 0.
*    Nothing
  else.
     loop at gt_list into gt_wa.
       gt_wa->free( ).
       exit.
     endloop.
     perform clear_live_controls.
  endif.
endform.                    " clear_live_controls

This took care of it.

Many thanks for your help.

Regards