2004 Oct 20 11:27 AM
Hi,
How can I destroy completely an ALV grid object?
My situation is the following:
I have a screen, where in case of click the details are displayed on a pop-up window with ALV-grid control.
So, when the user clicks first time, the ALV grid object is created, second time it's not created, it's already exists although I called the free method for the container.
If I call the free method, the object is still exists, I can see in the debugger.
Any idea?
Thanks in advance,
Peter
My code is the following:
*=======================================================================
* Screen 101 - Difference screen
*=======================================================================
*&---------------------------------------------------------------------*
*& Module status_0101 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0101 OUTPUT.
* IF gro_custom_container_101 IS INITIAL.
CREATE OBJECT gro_custom_container_101
EXPORTING
container_name = gv_container_101.
CREATE OBJECT gro_grid_101
EXPORTING i_parent = gro_custom_container_101.
CALL METHOD gro_grid_101->set_table_for_first_display
EXPORTING
i_structure_name = 'GIT_ALVOUTTAB_101'
is_layout = gwa_layout_101
CHANGING
it_outtab = git_alvouttab_101
it_fieldcatalog = git_fieldcat_101.
* ELSE.
*
* CALL METHOD gro_grid_101->refresh_table_display
* EXPORTING i_soft_refresh = c_flagged.
*
* ENDIF.
ENDMODULE. " STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0101 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0101 INPUT.
CASE gv_ok_code_101.
* Close button
WHEN 'CLOSE'.
CALL METHOD gro_custom_container_101->free.
CALL METHOD cl_gui_cfw=>flush.
CLEAR gv_ok_code_101.
SET SCREEN 0.
LEAVE SCREEN.
* Close icon on the window frame
WHEN 'CANCEL'.
CALL METHOD gro_custom_container_101->free.
CALL METHOD cl_gui_cfw=>flush.
CLEAR gv_ok_code_101.
SET SCREEN 0.
LEAVE SCREEN.
ENDCASE.
ENDMODULE. " USER_COMMAND_0101 INPUT
2004 Oct 20 11:55 AM
Try this :
free gro_custom_container_101.
Not sure if this does the intended work.
In case of
CALL METHOD gro_custom_container_101->free.
I believe what it does is, it has marked it as a destroyable object, and doesn't destroy it, until you completely exit from the program.
I debugged the BCALV_GRID_02 program, copied into a 'Y' temporary program and it seems to work.
Let us know if this is the solution you were looking at.
Regards,
Subramanian V.
2004 Oct 20 11:55 AM
Try this :
free gro_custom_container_101.
Not sure if this does the intended work.
In case of
CALL METHOD gro_custom_container_101->free.
I believe what it does is, it has marked it as a destroyable object, and doesn't destroy it, until you completely exit from the program.
I debugged the BCALV_GRID_02 program, copied into a 'Y' temporary program and it seems to work.
Let us know if this is the solution you were looking at.
Regards,
Subramanian V.
2004 Oct 20 1:05 PM
Hi Subramanian V.,
Thanks, it works fine.
Probable it's a nicer solution not to destroy the object, only use set_frontend_layout / refresh_table_display methods for refresh.
However it's easier. I'll try the refresh if it works then I won't have to destroy the objects.
Regards,
Peter
2004 Oct 20 1:23 PM
Hi Peter,
Actually it is normal behaviour when you use an inheritance of CL_GUI_CUSTOM_CONTAINER. This object belongs to the SUPER class and is always available.
When you make an inheritance (your gro_custom_container_101) a copy is made in memory (actually just a pointer copy).
When using the free method it will clear your "modified" object, but it will not clear the pointer reference.
The solution of Subramanian does clear the pointer reference, but it is not a very safe way.
Two things you have to keep in mind:
1. For clearing your local objects, your code is OK and to destroy the object reference simply use the ABAP FREE command.
2. I saw in your code (Module status_001 OUTPUT) that you do not check if your gro_custom_container_101 IS INITIAL (you remarked it out). Under normal conditions you should check this (because of the way that SAP Dynpro's loop over the modules when the screen changes). But NOT only your gro_custom_container_101 must be tested, also your gro_grid_101 must be tested.
In any case if one of them is initial (lost object reference) you need to create them again. In other cases you don't. When duplicate creation occurs SAP will keep track of them on the stack, but you will not be sure which instance is destroyed when calling the free method.
Hope this helps you.
Regards,
Rob.
2004 Oct 20 1:36 PM
Hi Rob,
Thanks for your detailed answer.
The reason I commented out, because I got a short dump:-(
Meanwhile I realized, it's because I was after the 'free' method, and a soft refresh will dump in this case.
Now I kept this check, not calling 'free', not destroying the objects, but I use method set_frontend_layout and refresh_table_display and it works fine.
Regards,
Peter
2004 Oct 20 1:39 PM
Rob, the point 2, that you have mentioned, somehow I overlooked the same and your reply is quite insightful.
It is always safe to check whether there is an existent copy of the grid and the container before creating one in PBO of the screen.
Thanks.
One more point is instead of using:
LEAVE SCREEN 0.
SET SCREEN 0.
use
LEAVE PROGRAM.
I have a question though, I quote you(Rob) here , when you say " <i>when using the free method it will clear your "modified" object</i>"
I debugged the code in BC_ALV_GRID_02, and found that after calling the free method of the container, the custom_container still contained the reference. Apparently it <b>does not clear the reference</b>, but <b>marks it to clear the reference</b>.
Share your thoughts on the same.
Subramanian V.
Message was edited by: Subramanian Venkateswaran
2004 Oct 20 4:49 PM
Hi,
Thanks for your answer.
Unfortunately LEAVE PROGRAM. is not an option as it's a popup window, and I want to leave only the screen not the program.
Peter
2004 Oct 20 8:30 PM
Hi
Use the method <b>"FREE"</b>, which is inherited from "CL_GUI_OBJECT" to destroy a custom control at the frontend. Once you have called this method, you should also initialize the object reference ( <b>FREE my_control .</b> ).
We free objects when we are completely finished with them. To refresh contents of these GUI objects, we use their refresh-like methods.
<b>Garbage collector</b> handles deleting of object references when their lifetime expires or when they are explicitly deleted.
*--Serdar