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: 

why i get same grid in different screens after handle_user_command

Former Member
0 Kudos
463

I've craeated a grid, then i add a button to toolbar. And i want to display second grid on the second screen.
why i get the same grid at 2 screens?
Here's my code:

 MODULE STATUS_1100 OUTPUT.
  SET PF-STATUS '1100'.
  SET TITLEBAR '1100'.

   IF lo_custom_container IS INITIAL.


*    CREATE OBJECT lo_custom_container
*      EXPORTING
*        container_name = lv_container.

    CREATE OBJECT lo_alv
      EXPORTING
        i_parent = lo_custom_container.

    lcl_alv_grid=>load_from_db( ).
    if so_svod is INITIAL.
      lcl_alv_grid=>build_fieldcat( ).
    else.
      lcl_alv_grid=>build_fieldcat_of_svod( ).
    endif.


    DATA : mo_controller type ref to lcl_controller.
    CREATE OBJECT mo_controller.
   SET HANDLER mo_controller->handle_toolbar FOR lo_alv .
   SET HANDLER mo_controller->handle_user_command for lo_alv.
if so_svod is INITIAL.
    lo_alv->set_table_for_first_display(
          EXPORTING
                    is_layout       = ls_layout
                      i_save          = 'A'
                      is_variant      = w_variant
          CHANGING
                    it_outtab       = lt_tab[]
                    it_fieldcatalog = gt_fieldcat

                                          ).
else.

      lo_alv->set_table_for_first_display(
          EXPORTING
                    is_layout       = ls_layout
                      i_save          = 'A'
                      is_variant      = w_variant
          CHANGING
                    it_outtab       = <gfs_dyn_table>
                    it_fieldcatalog = gt_fieldcat ).


endif.
endif.

ENDMODULE.  






CLASS lcl_controller DEFINITION FINAL.
  PUBLIC SECTION.
  METHODS:handle_user_command for event after_user_command of cl_gui_alv_grid
                   IMPORTING e_ucomm,
                handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
                IMPORTING e_object e_interactive,
                  MENU_BUTTON for event menu_button of cl_gui_alv_grid
                  IMPORTING E_OBJECT e_ucomm.

   ENDCLASS.
  CLASS lcl_controller IMPLEMENTATION.
      METHOD handle_user_command.
        case e_ucomm.
          when 'EXCH'.
            if so_svod is INITIAL.
              MESSAGE 'Доступно только для сводной таблицы' TYPE 'I' DISPLAY LIKE 'E'.
            else.
              call screen 1200.
            endif.
        endcase.

   ENdMETHOD.
   METHOD handle_toolbar.
    DATA: lv_toolbar TYPE stb_button.

* Push Button
      CLEAR lv_toolbar.
      MOVE 'EXCH' TO lv_toolbar-function.
      move ICON_OBJECT_LIST to lv_toolbar-icon.
      MOVE 'Переход в лист'(100) TO lv_toolbar-text.
      MOVE 'Переход в лист'(100) TO lv_toolbar-quickinfo.
      MOVE ' ' TO lv_toolbar-disabled.
      APPEND lv_toolbar TO e_object->mt_toolbar.

endmethod.

METHOD menu_button.
  case e_ucomm.
          when 'EXCH'.
   ENDCASE.
ENDMETHOD.

endclass.



MODULE STATUS_1200 OUTPUT.
  SET PF-STATUS '1200'.
  SET TITLEBAR '1200'.
IF lo_custom_container2 IS INITIAL.

    CREATE OBJECT lo_custom_container2
      EXPORTING
        container_name = lv_container2.

CREATE OBJECT lo_alv2
      EXPORTING
        i_parent = lo_custom_container2.

data : qr_tab type TABLE OF mara.
data : gt_fieldcat2   TYPE lvc_t_fcat.
    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
      EXPORTING
        I_STRUCTURE_NAME       = 'MARA'
        I_BYPASSING_BUFFER     = 'X'
      CHANGING
        CT_FIELDCAT            = gt_fieldcat2
      EXCEPTIONS
        INCONSISTENT_INTERFACE = 1
        PROGRAM_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.

select * from mara into table qr_tab up to 10 ROWS.

        lo_alv2->set_table_for_first_display(
          EXPORTING
                    is_layout       = ls_layout
                      i_save          = 'A'
                      is_variant      = w_variant
          CHANGING
                    it_outtab       = qr_tab
                    it_fieldcatalog = gt_fieldcat2 ).


  endif.
ENDMODULE.                 " STATUS_1200  OUTPUT




3 REPLIES 3

jens_michaelsen
Participant
424

Uncomment the following lines and try it again.

*    CREATE OBJECT lo_custom_container
*      EXPORTING
*        container_name = lv_container.

raymond_giuseppi
Active Contributor
0 Kudos
424

Specify a different value in the HANDLE field of the IS_VARIANT parameter for the two ALVs, so as not to mix their variants, layout and field catalog.

Sandra_Rossi
Active Contributor
0 Kudos
424

I can't compile your program to tell you what is wrong, there are lots of syntax errors. Instead, you could prepare a minimal reproducible example, which compiles, and which is cleansed of useless lines.

Also, not sure if you mean the first ALV in screen 1100 and the second one in screen 1200.