<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic create context menu automatically when set_table_for_first_display is used in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-context-menu-automatically-when-set-table-for-first-display-is-used/m-p/2013532#M411233</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi experts, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you please help.  I used the set_table_for_first_display method to create an ALV list.  Everything worked out great.  However, I noticed that there was no really a context menu (except System, and Help) populated.  I searched for the context menu in the class cl_gui_alv_grid or others.  It seems to me that all context menu handling's method are either private or protected.  Do you know a way to over come the issue?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks, &lt;/P&gt;&lt;P&gt;Debbie&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 21 Mar 2007 20:34:42 GMT</pubDate>
    <dc:creator>debbielei</dc:creator>
    <dc:date>2007-03-21T20:34:42Z</dc:date>
    <item>
      <title>create context menu automatically when set_table_for_first_display is used</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-context-menu-automatically-when-set-table-for-first-display-is-used/m-p/2013532#M411233</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi experts, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you please help.  I used the set_table_for_first_display method to create an ALV list.  Everything worked out great.  However, I noticed that there was no really a context menu (except System, and Help) populated.  I searched for the context menu in the class cl_gui_alv_grid or others.  It seems to me that all context menu handling's method are either private or protected.  Do you know a way to over come the issue?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks, &lt;/P&gt;&lt;P&gt;Debbie&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Mar 2007 20:34:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-context-menu-automatically-when-set-table-for-first-display-is-used/m-p/2013532#M411233</guid>
      <dc:creator>debbielei</dc:creator>
      <dc:date>2007-03-21T20:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: create context menu automatically when set_table_for_first_display is used</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-context-menu-automatically-when-set-table-for-first-display-is-used/m-p/2013533#M411234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Debbie&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The context menus are always &amp;lt;b&amp;gt;dynamically &amp;lt;/b&amp;gt;generated. Thus, when you right-click on something this raises event &amp;lt;b&amp;gt;CONTEXT_MENU_REQUEST&amp;lt;/b&amp;gt; and when you choose a function this raises event &amp;lt;b&amp;gt;USER_COMMAND&amp;lt;/b&amp;gt; (the naming of the events is somewhat special for CL_GUI_ALV_GRID).&lt;/P&gt;&lt;P&gt;The following sample report shows how to code a context menu. Instead of dynamically adding the functions to an existing context menu it is also possible to use a static context menu corresponding to a GUI status object.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Report  ZUS_SDN_ALVGRID_EVENTS_CTXMENU
*&amp;amp;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;
*&amp;amp;
*&amp;amp;---------------------------------------------------------------------*

REPORT  ZUS_SDN_ALVGRID_EVENTS_CTXMENU.



DATA:
  gd_okcode        TYPE ui_func,
*
  gt_fcat          TYPE lvc_t_fcat,
  go_docking       TYPE REF TO cl_gui_docking_container,
  go_grid1         TYPE REF TO cl_gui_alv_grid.


DATA:
  gt_knb1          TYPE STANDARD TABLE OF knb1.


PARAMETERS:
  p_bukrs      TYPE bukrs  DEFAULT '2000'  OBLIGATORY.



*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
  PUBLIC SECTION.
    CLASS-DATA:
      ms_row     TYPE lvc_s_row.

    CLASS-METHODS:
      handle_context_menu_request
        FOR EVENT context_menu_request OF cl_gui_alv_grid
        IMPORTING
          e_object  " type ref to cl_ctmenu
          sender,

       handle_user_command
         FOR EVENT user_command OF cl_gui_alv_grid
         IMPORTING
           e_ucomm
           sender.

ENDCLASS.                    "lcl_eventhandler DEFINITION


*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.

  METHOD handle_user_command.
*   define local data
    DATA:
      ls_knb1     TYPE knb1,
      ls_col_id   TYPE lvc_s_col.

    CHECK ( e_ucomm = 'XD03' ).

    READ TABLE gt_knb1 INTO ls_knb1 INDEX ms_row-index.
    CHECK ( ls_knb1-kunnr IS NOT INITIAL ).


    SET PARAMETER ID 'KUN' FIELD ls_knb1-kunnr.
    SET PARAMETER ID 'BUK' FIELD ls_knb1-bukrs.

    CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.


  ENDMETHOD.                    "handle_user_command

  METHOD handle_context_menu_request.
*   define local data
    DATA:
      lt_rows    TYPE lvc_t_row.

    CLEAR: ms_row.
    CALL METHOD go_grid1-&amp;gt;get_selected_rows
      IMPORTING
        et_index_rows = lt_rows.
    READ TABLE lt_rows INTO ms_row INDEX 1.

    e_object-&amp;gt;add_separator( ).
    CALL METHOD e_object-&amp;gt;add_function
      EXPORTING
        fcode       = 'XD03'
        text        = 'Display Customer'
*        ICON        =
*        FTYPE       =
*        DISABLED    =
*        HIDDEN      =
*        CHECKED     =
*        ACCELERATOR =
        .



  ENDMETHOD.                    "handle_context_menu_request

ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION


START-OF-SELECTION.

  SELECT        * FROM  knb1 INTO TABLE gt_knb1
         WHERE  bukrs  = p_bukrs.



* Create docking container
  CREATE OBJECT go_docking
    EXPORTING
      parent                      = cl_gui_container=&amp;gt;screen0
      ratio                       = 90
    EXCEPTIONS
      OTHERS                      = 6.
  IF sy-subrc &amp;lt;&amp;gt; 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* Create ALV grid
  CREATE OBJECT go_grid1
    EXPORTING
      i_parent          = go_docking
    EXCEPTIONS
      OTHERS            = 5.
  IF sy-subrc &amp;lt;&amp;gt; 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

* Set event handler
  SET HANDLER:
    lcl_eventhandler=&amp;gt;handle_user_command         FOR go_grid1,
    lcl_eventhandler=&amp;gt;handle_context_menu_request for go_grid1.


* Build fieldcatalog and set hotspot for field KUNNR
  PERFORM build_fieldcatalog_knb1.



* Display data
  CALL METHOD go_grid1-&amp;gt;set_table_for_first_display
    CHANGING
      it_outtab       = gt_knb1
      it_fieldcatalog = gt_fcat
    EXCEPTIONS
      OTHERS          = 4.
  IF sy-subrc &amp;lt;&amp;gt; 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.




* Link the docking container to the target dynpro
  CALL METHOD go_docking-&amp;gt;link
    EXPORTING
      repid                       = syst-repid
      dynnr                       = '0100'
*      CONTAINER                   =
    EXCEPTIONS
      OTHERS                      = 4.
  IF sy-subrc &amp;lt;&amp;gt; 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* ok-code field = GD_OKCODE
  CALL SCREEN '0100'.
* NOTE: no dynpro elements on screen. Flow logic as shown below:
*PROCESS BEFORE OUTPUT.
*  MODULE STATUS_0100.
**
*PROCESS AFTER INPUT.
*  MODULE USER_COMMAND_0100.

END-OF-SELECTION.

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Module  STATUS_0100  OUTPUT
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS_0100'.
*  SET TITLEBAR 'xxx'.


ENDMODULE.                 " STATUS_0100  OUTPUT

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Module  USER_COMMAND_0100  INPUT
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE gd_okcode.
    WHEN 'BACK' OR
         'END'  OR
         'CANC'.
      SET SCREEN 0. LEAVE SCREEN.


    WHEN OTHERS.
  ENDCASE.

  CLEAR: gd_okcode.

ENDMODULE.                 " USER_COMMAND_0100  INPUT


*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  BUILD_FIELDCATALOG_KNB1
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --&amp;gt;  p1        text
*  &amp;lt;--  p2        text
*----------------------------------------------------------------------*
FORM build_fieldcatalog_knb1 .
* define local data
  DATA:
    ls_fcat        TYPE lvc_s_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'KNB1'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = gt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 2
      OTHERS                       = 3.
  IF sy-subrc &amp;lt;&amp;gt; 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


*  LOOP AT gt_fcat INTO ls_fcat
*          WHERE ( fieldname = 'KUNNR'  OR
*                  fieldname = 'ERNAM' ).
*    ls_fcat-hotspot = abap_true.
*    MODIFY gt_fcat FROM ls_fcat.
*  ENDLOOP.


ENDFORM.                    " BUILD_FIELDCATALOG_KNB1&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Mar 2007 23:11:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-context-menu-automatically-when-set-table-for-first-display-is-used/m-p/2013533#M411234</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2007-03-21T23:11:28Z</dc:date>
    </item>
  </channel>
</rss>

