<?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 Re: ALV Grid Object Oriented in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225503#M1208168</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jose,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think you have this already done here&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
 METHOD handle_menu_button.
    IF e_ucomm = 'MBUT'.
      CALL METHOD e_object-&amp;gt;add_function
        EXPORTING
          fcode = 'SUBT'
          text  = text-105.
    ENDIF.
  ENDMETHOD.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This method will be triggered each time you press the button with fcode MBUT, so the submenu will be added and shown. But what I am missing in your code is this in your &lt;STRONG&gt;instanciar_objetos&lt;/STRONG&gt; module.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  "reach toolbar event by using this method
  CALL METHOD go_grid-&amp;gt;set_toolbar_interactive.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now all the events regarding toolbar (including new buttons and submenus for them) will be active.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Feb 2009 20:00:47 GMT</pubDate>
    <dc:creator>MarcinPciak</dc:creator>
    <dc:date>2009-02-25T20:00:47Z</dc:date>
    <item>
      <title>ALV Grid Object Oriented</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225502#M1208167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a report type program I'm making, I have to show the data trough an ALV Control. I've decided to do it by the object oriented type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So this is what I have. In the TOP INCLUDE, and in the main program:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
CLASS lcl_receptor_eventos DEFINITION DEFERRED.

DATA: go_grid                   TYPE REF TO cl_gui_alv_grid,
           go_cont                  TYPE REF TO cl_gui_custom_container,
           go_context_menu    TYPE REF TO cl_ctmenu,
           go_event_receiver    TYPE REF TO lcl_receptor_eventos.

CALL SCREEN 1400.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In another include for the local classes to be declared, I have declared the class who will receive the events. I have done this in order to set handlers later, in order to add a button to the ALV's toolbar:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CLASS lcl_receptor_eventos DEFINITION.

  PUBLIC SECTION.

    METHODS:

      handle_menu_button
          FOR EVENT menu_button OF cl_gui_alv_grid
          IMPORTING e_ucomm e_object,

         handle_toolbar_set
          FOR EVENT toolbar OF cl_gui_alv_grid
          IMPORTING e_object e_interactive,

         handle_user_command
          FOR EVENT user_command OF cl_gui_alv_grid
          IMPORTING e_ucomm sender.

ENDCLASS.                    "lcl_event_receiver DEFINITION

*----------------------------------------------------------------------*
*       CLASS lvl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_receptor_eventos IMPLEMENTATION.

  METHOD handle_user_command.
    CASE e_ucomm.
      WHEN 'SUBT'.
        gv_okcode = 'SUBT'.
      ENDCASE.
  ENDMETHOD.    

* Here I will add the button 

  METHOD handle_toolbar_set.
    DATA: gs_toolbar  TYPE stb_button.

    CLEAR gs_toolbar.
    MOVE 'SUBT' TO gs_toolbar-function.
    MOVE ICON_SUM TO gs_toolbar-icon.
    MOVE 1 TO gs_toolbar-BUTN_TYPE.
    MOVE 'Totales parciales' TO gs_toolbar-quickinfo.
    MOVE ' ' TO gs_toolbar-disabled.
    INSERT gs_toolbar INTO e_object-&amp;gt;mt_toolbar INDEX 10.
    CALL METHOD cl_gui_control=&amp;gt;set_focus
      EXPORTING
        control = go_grid.

  ENDMETHOD.  

  METHOD handle_menu_button.
    IF e_ucomm = 'MBUT'.
      CALL METHOD e_object-&amp;gt;add_function
        EXPORTING
          fcode = 'SUBT'
          text  = text-105.
    ENDIF.
  ENDMETHOD.

ENDCLASS.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the 1400 screen's PBO there is two modules. One of them instantiates the objects and sets the handlers for the events:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;MODULE instanciar_objetos OUTPUT.

  IF go_cont IS INITIAL.
    CREATE OBJECT go_cont
      EXPORTING
        container_name = 'ALV_CONTAINER'.

    CREATE OBJECT go_grid
      EXPORTING
        i_appl_events     = 'X'
        i_parent = go_cont.

    CREATE OBJECT go_event_receiver.

    SET HANDLER go_event_receiver-&amp;gt;handle_toolbar_set FOR go_grid.
    SET HANDLER go_event_receiver-&amp;gt;handle_user_command FOR go_grid.
    SET HANDLER go_event_receiver-&amp;gt;handle_menu_button FOR go_grid.

    PERFORM introducir_datos_en_grilla TABLES gt_salida.
    PERFORM crear_tabla_dinamica.

  ENDIF.

ENDMODULE.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The another one is to set the status and the main window toolbar, so it's not relevant right now. In the PAI there is a module who register the events, in order to the handlers to be called at the beginning of the PAI and the ok_code to be set.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;module REGISTRAR_EVENTOS input.

DATA return_code TYPE i.

 CALL METHOD cl_gui_cfw=&amp;gt;dispatch
      IMPORTING
        return_code = return_code.

endmodule.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, here the question comes... I need, when the button I have added is pressed, to show a submenu beside it (exactly like the one that is shown when the standard sigma button in the ALV toolbar, I mean the sum button, is pressed). How can I do that??&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Feb 2009 19:38:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225502#M1208167</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-25T19:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: ALV Grid Object Oriented</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225503#M1208168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jose,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think you have this already done here&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
 METHOD handle_menu_button.
    IF e_ucomm = 'MBUT'.
      CALL METHOD e_object-&amp;gt;add_function
        EXPORTING
          fcode = 'SUBT'
          text  = text-105.
    ENDIF.
  ENDMETHOD.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This method will be triggered each time you press the button with fcode MBUT, so the submenu will be added and shown. But what I am missing in your code is this in your &lt;STRONG&gt;instanciar_objetos&lt;/STRONG&gt; module.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  "reach toolbar event by using this method
  CALL METHOD go_grid-&amp;gt;set_toolbar_interactive.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now all the events regarding toolbar (including new buttons and submenus for them) will be active.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Feb 2009 20:00:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225503#M1208168</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2009-02-25T20:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: ALV Grid Object Oriented</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225504#M1208169</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Jose&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just a few remarks regarding OO-like programming:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;I would recommend to make the entire initialization of the controls BEFORE you call your screen (for an example have a look at report ZUS_SDN_TWO_ALV_GRIDS_2SCR in thread &lt;SPAN __jive_macro_name="thread" id="826287"&gt;&lt;/SPAN&gt;)&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;I prefer to have screens with as little flow logic as possible (screens are there for displaying and not executing business logic)&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;For me the CALL SCREEN statement does not belong at all into a TOP include&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Context menus can be created in two ways:&lt;/P&gt;&lt;/LI&gt;&lt;UL&gt;&lt;LI level="2" type="ul"&gt;&lt;P&gt;Using the static method &lt;STRONG&gt;LOAD_GUI_STATUS&lt;/STRONG&gt; of CL_CTMENU (which loads a predefined gui status) =&amp;gt; static&lt;/P&gt;&lt;/LI&gt;&lt;LI level="2" type="ul"&gt;&lt;P&gt;Adding a submenu function to an existing toolbar button =&amp;gt; dynamic&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&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, 25 Feb 2009 20:41:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225504#M1208169</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2009-02-25T20:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: ALV Grid Object Oriented</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225505#M1208170</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Let's see. I'll answer you both.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Marcin Pciak&lt;/STRONG&gt;: I have given a try to your solution. I added the statement inside the &lt;STRONG&gt;instanciar_objetos&lt;/STRONG&gt; module, and the things is, just after the method call, the program dumps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've seeing the error description screen and the error seems to be generated by the statement  &lt;STRONG&gt;call method m_cl_menu_button_variant-&amp;gt;clear&lt;/STRONG&gt;, which is executed inside the &lt;STRONG&gt;toolbar_menus_init&lt;/STRONG&gt; method. By seeing the statements that follows it, I can deduce the problem is that I have exluded some buttons from the toobar, by mean of the &lt;STRONG&gt;it_toolbar_excluding&lt;/STRONG&gt; exporting parameter of the &lt;STRONG&gt;set_table_for_first_dislpay&lt;/STRONG&gt; method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The runtime error code is &lt;STRONG&gt;OBJECTS_OBJREF_NOT_ASSIGNED&lt;/STRONG&gt; and the raised, uncaughted exception name is &lt;STRONG&gt;CX_SY_REF_IS_INITIAL&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Uwe Schieferstein&lt;/STRONG&gt;: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;       - The &lt;STRONG&gt;CALL SCREEN&lt;/STRONG&gt; statement is not in the TOP Include of my program. I have put it there in my message just for practicity.&lt;/P&gt;&lt;P&gt;       - I will follow your recomendation about initialize the controls before the screen call.&lt;/P&gt;&lt;P&gt;       - The flow logic in the screens is reduced to maximum, I can't make it smaller.&lt;/P&gt;&lt;P&gt;       - Between the two ways you have stated of creating context menus, I obviusly choose the second one. So I don't get what you mean with that.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Feb 2009 21:06:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225505#M1208170</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-25T21:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: ALV Grid Object Oriented</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225506#M1208171</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jose,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not sure if this will help but try first using &lt;STRONG&gt;set_table_for_first_dislpay&lt;/STRONG&gt;, then (after setting the handlers) use   &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set_toolbar_interactive&lt;/STRONG&gt;. Maybe as you said, it is a matter of excluding standard toolbar buttons, but I believe not. In case dump is still comming, try to skip excluding table and see the results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Feb 2009 21:29:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225506#M1208171</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2009-02-25T21:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: ALV Grid Object Oriented</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225507#M1208172</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Jose&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You are right, I mixed things up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The LOAD_GUI_STATUS method can be used for context menus on the list (and not for the ALV toolbar functions) to add a fixed context menu to a pre-existing one when the user triggers the event &lt;STRONG&gt;CONTEXT_MENU_REQUEST&lt;/STRONG&gt;.&lt;/P&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>Thu, 26 Feb 2009 04:51:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225507#M1208172</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2009-02-26T04:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: ALV Grid Object Oriented</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225508#M1208173</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jose,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Refer SAP standard prog  &lt;STRONG&gt;BCALV_GRID_07&lt;/STRONG&gt;  for yourreference.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Pratik Vora&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Feb 2009 13:50:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-grid-object-oriented/m-p/5225508#M1208173</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-26T13:50:44Z</dc:date>
    </item>
  </channel>
</rss>

