Application Development 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: 

Destroy ALV which is using Screen as container

Former Member
0 Kudos

<b>What I did:</b>

-


*In the PBO of screen <b>200</b>

*Created a l_alv of type alv grid which is using screen as container

CREATE OBJECT l_alv EXPORTING i_parent = cl_gui_container=>screen0.

*filling it with data

*--Transfer data to ALV

CALL METHOD l_alv->set_table_for_first_display

Expor . . .

When user is pressing F3 on screen <b>200</b>, i m going back to sel-screen

leave to screen 1000

or

call selection-screen 1000

<b>Problem Statement:</b>

-


Though I am landing up to screen 1000 as i can see the menu of sel screen, but my ALV is still visible on top of screen 1000

<b>What I did:</b>

-


to destroy it, i m using these lines before <i>Call selection-screen 1000</i>

call method cl_gui_container=>screen0->free.

call method l_alv->free.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
************************************************************************
* Internal Tables:
************************************************************************
DATA: i_exclude TYPE ui_functions,   " Function button table definitions
      i_fieldcat TYPE lvc_t_fcat,    " Field catalogue
      i_output TYPE STANDARD TABLE OF ZLIGHT_STRUC,
      i_groups  TYPE lvc_t_sgrp,

************************************************************************
* Work Areas:
************************************************************************
       w_variant TYPE disvariant,          " Enable variant saving
       w_layout  TYPE lvc_s_layo,          " Define the layout structure
       w_output TYPE MARA.

************************************************************************
* Constants Declaration
************************************************************************
CONSTANTS:  c_a       TYPE c VALUE 'A'.          "All Layouts

***********************************************************************
* Object Declarations
************************************************************************
DATA : o_alvgrid          TYPE REF TO cl_gui_alv_grid,
       o_dockingcontainer TYPE REF TO cl_gui_docking_container.

In PBO,
FORM f9000_objects_create.

* Check to see if we are runnng on online
  IF cl_gui_alv_grid=>offline( ) IS INITIAL.

    CREATE OBJECT o_dockingcontainer
      EXPORTING
        ratio                       = '95'
     EXCEPTIONS
      cntl_error                  = 1
      cntl_system_error           = 2
      create_error                = 3
      lifetime_error              = 4
      lifetime_dynpro_dynpro_link = 5
      others                      = 6.

    IF sy-subrc NE 0.
*      MESSAGE i001 WITH text-e01.
      LEAVE LIST-PROCESSING.
    ENDIF.

  ENDIF.

  CREATE OBJECT o_alvgrid
    EXPORTING
      i_parent = o_dockingcontainer.

ENDFORM.                    " f9000_objects_create
FORM f9200_build_field_cat TABLES p_fieldcat STRUCTURE lvc_s_fcat
                      USING value(p_structure).

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
       EXPORTING
            i_structure_name       = p_structure
       CHANGING
            ct_fieldcat            = p_fieldcat[]
       EXCEPTIONS
            inconsistent_interface = 1
            program_error          = 2
            OTHERS                 = 3.
  IF sy-subrc <> 0.
*    MESSAGE i277.
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " f9200_build_field_cat
FORM f9400_layout USING    value(ptitle)
                     value(pzebra)
                     value(pmode)
                     value(pwidth)
                     value(pvariant).

  w_layout-grid_title = ptitle.
  w_layout-zebra      = pzebra.
  w_layout-sel_mode   = pmode.
  w_layout-cwidth_opt = pwidth.
  w_variant-handle    = pvariant.
  w_variant-report    = sy-repid.
ENDFORM.                    " f9400_layout

FORM f9500_display_data TABLES p_output
                         p_groups
                         p_exclude
                         p_fieldcat
                  USING value(p_layout).

  CALL METHOD o_alvgrid->set_table_for_first_display
     EXPORTING
       is_variant                    = w_variant
       i_save                        = c_a
       is_layout                     = p_layout
       it_special_groups             = p_groups[]
       it_toolbar_excluding          = p_exclude[]
    CHANGING
       it_outtab                     = p_output[]
       it_fieldcatalog               = p_fieldcat[]
    EXCEPTIONS
       invalid_parameter_combination = 1
       program_error                 = 2
       too_many_lines                = 3
       OTHERS                        = 4.

  IF sy-subrc <> 0.
*    MESSAGE i278.
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " f9500_display_data
FORM f9600_free_objects USING pobject
                    value(ptype)
                    value(ptext).

  DATA: l_objectalv TYPE REF TO cl_gui_alv_grid.
* Need to type the field symbol or it does not work

  CASE ptype.
    WHEN 'ALV'.

      l_objectalv = pobject.

      IF NOT ( l_objectalv IS INITIAL ).
        CALL METHOD l_objectalv->free
          EXCEPTIONS
            cntl_error        = 1
           cntl_system_error = 2
            OTHERS            = 3.
        CLEAR: pobject, l_objectalv.
        PERFORM f9700_error_handle USING ptext.

      ENDIF.
    WHEN 'DOCKING'.
      DATA: lobjectdock TYPE REF TO cl_gui_docking_container.
      lobjectdock = pobject.

      IF NOT ( lobjectdock IS INITIAL ).
        CALL METHOD lobjectdock->free
          EXCEPTIONS
            cntl_error        = 1
           cntl_system_error = 2
            OTHERS            = 3.
        CLEAR: pobject, lobjectdock.
        PERFORM f9700_error_handle USING ptext.

      ENDIF.
    WHEN 'CONTAINER'.
      DATA: lobjectcontainer TYPE REF TO cl_gui_container.
      lobjectcontainer = pobject.

      IF NOT ( lobjectcontainer IS INITIAL ).
        CALL METHOD lobjectcontainer->free
          EXCEPTIONS
            cntl_error        = 1
           cntl_system_error = 2
            OTHERS            = 3.
        CLEAR: pobject, lobjectcontainer.
        PERFORM f9700_error_handle USING ptext.

      ENDIF.
    WHEN OTHERS.
      sy-subrc = 1.
      PERFORM f9700_error_handle USING
                                text-e04.
  ENDCASE.

ENDFORM.                    " f9600_free_objects

*&---------------------------------------------------------------------*
*&      Form  f9700_error_handle
*&---------------------------------------------------------------------*
*       This form is used to handle errors
*----------------------------------------------------------------------*
*      -->P_PTEXT - Text holding the messsage to be displayed as
*                   information
*----------------------------------------------------------------------*
FORM f9700_error_handle USING    value(ptext).

  IF sy-subrc NE 0.
* Add your handling, for example
    CALL FUNCTION 'POPUP_TO_INFORM'
         EXPORTING
              titel = text-e03
              txt2  = sy-subrc
              txt1  = ptext.
  ENDIF.

ENDFORM.                    " f9700_error_handle

MODULE status_9001 OUTPUT.

  IF o_dockingcontainer IS INITIAL.

    SET PF-STATUS 'ZSTATUS'.
    SET TITLEBAR 'ZTITLE'.

*Create Objects
    PERFORM f9000_objects_create.

*Build field catalog
    PERFORM f9200_build_field_cat TABLES i_fieldcat
                             USING 'MARA.

*Layout
    PERFORM f9400_layout USING sy-title 'X' 'X' 'X' p_layout.

*Display data
    PERFORM f9500_display_data TABLES i_output
                                i_groups
                                i_exclude
                                i_fieldcat
                          USING w_layout.

  ENDIF.

ENDMODULE.                 " STATUS_9001  OUTPUT
*&---------------------------------------------------------------------
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------
* This is used for PAI details
*----------------------------------------------------------------------
MODULE user_command_9001 INPUT.

  CASE sy-ucomm.

    WHEN 'EXIT' OR  'CANC'.
      PERFORM f9600_free_objects:
               USING o_alvgrid 'ALV' text-e02,
               USING o_dockingcontainer 'DOCKING'
                       text-e01.
      LEAVE PROGRAM.

    WHEN 'BACK'.
      PERFORM f9600_free_objects:
               USING o_alvgrid 'ALV' text-e02,
               USING o_dockingcontainer 'DOCKING'
                       text-e01.
      SET SCREEN '0'.
      LEAVE SCREEN.

    WHEN OTHERS.

  ENDCASE.

ENDMODULE.                 " USER_COMMAND_9001  INPUT

Hope this helps u.

8 REPLIES 8

Former Member
0 Kudos

Change the following code


<i>
When user is pressing F3 on screen 200, i m going back to sel-screen 
leave to screen 1000
or
call selection-screen 1000
</i>

Change it as follows


<i>
When user is pressing F3 on screen 200, i m going back to sel-screen 
<b>leave screen.</b>
</i>

Also, in the attributes of your screen 200, set the "Next Screen" value to be 1000.

Srinivas

0 Kudos

Hi Srinivas Adavi,

Its not about how i am calling the screen 1000, its about wiping off alv, coz even if i get it off, <b>the second time I am calling screen 200 and using the method set_table_..</b>. its giving dump

0 Kudos

If I read the documentation on ALV correctly, I think I saw somewhere in there that leaving the ALV automatically destroys the control object. That is one of the advantages of ABAP OO compared to JAVA OO, where you don't have to work on clean up.

Are you making sure that all your internal tables, structures and the variables are reset before filling them again for the second call? What is dump message?

Srinivas

Former Member
0 Kudos
************************************************************************
* Internal Tables:
************************************************************************
DATA: i_exclude TYPE ui_functions,   " Function button table definitions
      i_fieldcat TYPE lvc_t_fcat,    " Field catalogue
      i_output TYPE STANDARD TABLE OF ZLIGHT_STRUC,
      i_groups  TYPE lvc_t_sgrp,

************************************************************************
* Work Areas:
************************************************************************
       w_variant TYPE disvariant,          " Enable variant saving
       w_layout  TYPE lvc_s_layo,          " Define the layout structure
       w_output TYPE MARA.

************************************************************************
* Constants Declaration
************************************************************************
CONSTANTS:  c_a       TYPE c VALUE 'A'.          "All Layouts

***********************************************************************
* Object Declarations
************************************************************************
DATA : o_alvgrid          TYPE REF TO cl_gui_alv_grid,
       o_dockingcontainer TYPE REF TO cl_gui_docking_container.

In PBO,
FORM f9000_objects_create.

* Check to see if we are runnng on online
  IF cl_gui_alv_grid=>offline( ) IS INITIAL.

    CREATE OBJECT o_dockingcontainer
      EXPORTING
        ratio                       = '95'
     EXCEPTIONS
      cntl_error                  = 1
      cntl_system_error           = 2
      create_error                = 3
      lifetime_error              = 4
      lifetime_dynpro_dynpro_link = 5
      others                      = 6.

    IF sy-subrc NE 0.
*      MESSAGE i001 WITH text-e01.
      LEAVE LIST-PROCESSING.
    ENDIF.

  ENDIF.

  CREATE OBJECT o_alvgrid
    EXPORTING
      i_parent = o_dockingcontainer.

ENDFORM.                    " f9000_objects_create
FORM f9200_build_field_cat TABLES p_fieldcat STRUCTURE lvc_s_fcat
                      USING value(p_structure).

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
       EXPORTING
            i_structure_name       = p_structure
       CHANGING
            ct_fieldcat            = p_fieldcat[]
       EXCEPTIONS
            inconsistent_interface = 1
            program_error          = 2
            OTHERS                 = 3.
  IF sy-subrc <> 0.
*    MESSAGE i277.
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " f9200_build_field_cat
FORM f9400_layout USING    value(ptitle)
                     value(pzebra)
                     value(pmode)
                     value(pwidth)
                     value(pvariant).

  w_layout-grid_title = ptitle.
  w_layout-zebra      = pzebra.
  w_layout-sel_mode   = pmode.
  w_layout-cwidth_opt = pwidth.
  w_variant-handle    = pvariant.
  w_variant-report    = sy-repid.
ENDFORM.                    " f9400_layout

FORM f9500_display_data TABLES p_output
                         p_groups
                         p_exclude
                         p_fieldcat
                  USING value(p_layout).

  CALL METHOD o_alvgrid->set_table_for_first_display
     EXPORTING
       is_variant                    = w_variant
       i_save                        = c_a
       is_layout                     = p_layout
       it_special_groups             = p_groups[]
       it_toolbar_excluding          = p_exclude[]
    CHANGING
       it_outtab                     = p_output[]
       it_fieldcatalog               = p_fieldcat[]
    EXCEPTIONS
       invalid_parameter_combination = 1
       program_error                 = 2
       too_many_lines                = 3
       OTHERS                        = 4.

  IF sy-subrc <> 0.
*    MESSAGE i278.
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " f9500_display_data
FORM f9600_free_objects USING pobject
                    value(ptype)
                    value(ptext).

  DATA: l_objectalv TYPE REF TO cl_gui_alv_grid.
* Need to type the field symbol or it does not work

  CASE ptype.
    WHEN 'ALV'.

      l_objectalv = pobject.

      IF NOT ( l_objectalv IS INITIAL ).
        CALL METHOD l_objectalv->free
          EXCEPTIONS
            cntl_error        = 1
           cntl_system_error = 2
            OTHERS            = 3.
        CLEAR: pobject, l_objectalv.
        PERFORM f9700_error_handle USING ptext.

      ENDIF.
    WHEN 'DOCKING'.
      DATA: lobjectdock TYPE REF TO cl_gui_docking_container.
      lobjectdock = pobject.

      IF NOT ( lobjectdock IS INITIAL ).
        CALL METHOD lobjectdock->free
          EXCEPTIONS
            cntl_error        = 1
           cntl_system_error = 2
            OTHERS            = 3.
        CLEAR: pobject, lobjectdock.
        PERFORM f9700_error_handle USING ptext.

      ENDIF.
    WHEN 'CONTAINER'.
      DATA: lobjectcontainer TYPE REF TO cl_gui_container.
      lobjectcontainer = pobject.

      IF NOT ( lobjectcontainer IS INITIAL ).
        CALL METHOD lobjectcontainer->free
          EXCEPTIONS
            cntl_error        = 1
           cntl_system_error = 2
            OTHERS            = 3.
        CLEAR: pobject, lobjectcontainer.
        PERFORM f9700_error_handle USING ptext.

      ENDIF.
    WHEN OTHERS.
      sy-subrc = 1.
      PERFORM f9700_error_handle USING
                                text-e04.
  ENDCASE.

ENDFORM.                    " f9600_free_objects

*&---------------------------------------------------------------------*
*&      Form  f9700_error_handle
*&---------------------------------------------------------------------*
*       This form is used to handle errors
*----------------------------------------------------------------------*
*      -->P_PTEXT - Text holding the messsage to be displayed as
*                   information
*----------------------------------------------------------------------*
FORM f9700_error_handle USING    value(ptext).

  IF sy-subrc NE 0.
* Add your handling, for example
    CALL FUNCTION 'POPUP_TO_INFORM'
         EXPORTING
              titel = text-e03
              txt2  = sy-subrc
              txt1  = ptext.
  ENDIF.

ENDFORM.                    " f9700_error_handle

MODULE status_9001 OUTPUT.

  IF o_dockingcontainer IS INITIAL.

    SET PF-STATUS 'ZSTATUS'.
    SET TITLEBAR 'ZTITLE'.

*Create Objects
    PERFORM f9000_objects_create.

*Build field catalog
    PERFORM f9200_build_field_cat TABLES i_fieldcat
                             USING 'MARA.

*Layout
    PERFORM f9400_layout USING sy-title 'X' 'X' 'X' p_layout.

*Display data
    PERFORM f9500_display_data TABLES i_output
                                i_groups
                                i_exclude
                                i_fieldcat
                          USING w_layout.

  ENDIF.

ENDMODULE.                 " STATUS_9001  OUTPUT
*&---------------------------------------------------------------------
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------
* This is used for PAI details
*----------------------------------------------------------------------
MODULE user_command_9001 INPUT.

  CASE sy-ucomm.

    WHEN 'EXIT' OR  'CANC'.
      PERFORM f9600_free_objects:
               USING o_alvgrid 'ALV' text-e02,
               USING o_dockingcontainer 'DOCKING'
                       text-e01.
      LEAVE PROGRAM.

    WHEN 'BACK'.
      PERFORM f9600_free_objects:
               USING o_alvgrid 'ALV' text-e02,
               USING o_dockingcontainer 'DOCKING'
                       text-e01.
      SET SCREEN '0'.
      LEAVE SCREEN.

    WHEN OTHERS.

  ENDCASE.

ENDMODULE.                 " USER_COMMAND_9001  INPUT

Hope this helps u.

Former Member
0 Kudos

Hi!

To properly destroy ALV and its parent container proceed as follows just before leaving to selection screen:

CALL METHOD alv_grid->free

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CALL METHOD alv_grid_parent_container->free

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

FREE:

alv_grid,

alv_grid_parent_container.

Regards,

Maxim.

0 Kudos

i guess the issue is with the following piece of code.

<i>CREATE OBJECT l_alv EXPORTING i_parent = cl_gui_container=>screen0.</i>

since you are already in screen 200 (i guess which holds the contaner) why not use screen200/container as the parent of alv instead of cl_gui_container=>screen0.

Generally we use cl_gui_container=>screen0 when no screen is created .

give it a try.

Regards

Raja

0 Kudos

Hi, raja

screen200/container as the parent of alv, is nice idea, but you can use cl_gui_container=>screen0 to cl_gui_container=>screen9 as container, so cant say which screenN denotes screen 200.

forgive if i m sounding dumb here.

0 Kudos

i knew about cl_gui_container=>screen0 to cl_gui_container=>screen9 from the ABAP FAQ (here at SDN).

What i mean to say was place a container in screen200 and use that for alv.

My guess is that the reason for the problem you are having is that cl_gui_container=>screen0 takes the current screen as the screen for rendering alv and thus gets messed up.

Regards

Raja