Skip to Content
author's profile photo Former Member
Former Member

Modify ALV GRID contents on button click

Hi,

In my ALV grid display, am creating a new button in the toolbar. Once I click on the button the values displayed should change. More precisely if the values are 100, 200, 300 after clicking on the button it should show as 100%, 200%, 300%.

Need sample code please.

Thanks

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Oct 21, 2015 at 07:21 PM

    Hi,

    I think you can do it by trying to use this code 😊

    REPORT zibo_pg_alv_toolbar4.
    DATA lt_exclude TYPE ui_functions.
    DATA:
    r_container TYPE REF TO cl_gui_custom_container,
    g_grid TYPE REF TO cl_gui_alv_grid.
    DATA:
    t_sflight TYPE TABLE OF sflight.

    DATA:
    ls_layout TYPE lvc_s_layo.

    DATA: gr_alv_toolbarmanager TYPE REF TO cl_alv_grid_toolbar_manager. "Toolbar man

    INCLUDE ZIBO_INC_LCL_CLASS_BUTTONS2.
    *INCLUDE zibo_inc_lcl_class_buttons.

    DATA: gr_alv_toolbar TYPE REF TO lcl_alv_toolbar.

    DATA: gv_toolbar_hide TYPE abap_bool VALUE abap_false.

    START-OF-SELECTION.

    SELECT * FROM sflight INTO TABLE t_sflight.
    CALL SCREEN 100.


    MODULE status_0100 OUTPUT.
    SET PF-STATUS 'SCREEN'.
    SET TITLEBAR 'TITLE'.
    PERFORM exclude_tb_functions CHANGING lt_exclude.
    ENDMODULE. " STATUS_0100 OUTPUT

    MODULE user_command_0100 INPUT.
    CASE sy-ucomm.
    WHEN 'BACK'.
    LEAVE TO SCREEN 0.
    ENDCASE.
    ENDMODULE. "USER_COMMAND_0100 INPUT


    FORM exclude_tb_functions CHANGING ct_execlude TYPE ui_functions.

    DATA:
    ls_exclude TYPE ui_func,
    lt_event TYPE cntl_simple_events.

    ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
    APPEND ls_exclude TO ct_execlude.
    ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
    APPEND ls_exclude TO ct_execlude.


    CREATE OBJECT r_container
    EXPORTING
    container_name = 'CONTAINER'.
    CREATE OBJECT g_grid
    EXPORTING
    i_parent = r_container.


    * create ALV event handler
    CREATE OBJECT gr_alv_toolbar
    EXPORTING
    io_alv_grid = g_grid.
    * ALV attributes FOR LAYOUT
    PERFORM alv_report_layout.

    CHECK g_grid IS NOT INITIAL.
    * Register event handler
    SET HANDLER gr_alv_toolbar->on_toolbar FOR g_grid.
    SET HANDLER gr_alv_toolbar->alv_handle_user_command FOR g_grid.


    CALL METHOD g_grid->set_table_for_first_display
    EXPORTING
    i_structure_name = 'SFLIGHT'
    is_layout = ls_layout
    it_toolbar_excluding = lt_exclude
    CHANGING
    * it_fieldcatalog = pt_fieldcat
    it_outtab = t_sflight.

    g_grid->refresh_table_display( ).
    ENDFORM.

    FORM alv_user_command USING e_ucomm TYPE sy-ucomm.
    DATA:
    l_line1 TYPE string.
    CASE e_ucomm.

    WHEN 'BUT1'.
    PERFORM change_to_percent.

    WHEN OTHERS.

    ENDCASE.
    ENDFORM. "alv_user_command



    FORM alv_report_layout.
    ls_layout-cwidth_opt = 'X'.
    ls_layout-zebra = 'X'.
    ENDFORM. " alv_report_layout

    FORM change_to_percent .
    FIELD-SYMBOLS <ls_sflight> TYPE sflight.

    loop at t_sflight ASSIGNING <ls_sflight>.
    CONCATENATE <ls_sflight>-PLANETYPE '%' into <ls_sflight>-PLANETYPE.
    ENDLOOP.
    g_grid->refresh_table_display( ).
    ENDFORM.





    *&---------------------------------------------------------------------*
    *& Include ZIBO_INC_LCL_CLASS_BUTTONS
    *&---------------------------------------------------------------------*

    CLASS lcl_alv_toolbar DEFINITION.
    PUBLIC SECTION.
    *Constructor
    METHODS: constructor
    IMPORTING
    io_alv_grid TYPE REF TO cl_gui_alv_grid,
    *Event for toolbar
    on_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
    IMPORTING e_object,
    * activate context menu handling
    alv_handle_user_command
    FOR EVENT user_command OF cl_gui_alv_grid
    IMPORTING e_ucomm.
    ENDCLASS. "lcl_alv_toolbar DEFINITION


    CLASS lcl_alv_toolbar IMPLEMENTATION.
    METHOD constructor.
    * Create ALV toolbar manager instance
    CREATE OBJECT gr_alv_toolbarmanager
    EXPORTING
    io_alv_grid = io_alv_grid
    iv_initial_state = '3'.
    ENDMETHOD. "constructor


    METHOD on_toolbar.
    DATA:
    ls_toolbar TYPE stb_button.
    ls_toolbar-function = 'BUT1'.
    ls_toolbar-icon = icon_phone.
    ls_toolbar-butn_type = 0.
    ls_toolbar-text = 'change to% '.
    APPEND ls_toolbar TO e_object->mt_toolbar.


    CALL METHOD gr_alv_toolbarmanager->reorganize
    EXPORTING
    io_alv_toolbar = e_object.
    ENDMETHOD. "on_toolbar
    METHOD alv_handle_user_command.
    PERFORM alv_user_command
    USING e_ucomm.
    ENDMETHOD. "alv_handle_context_menu
    ENDCLASS. "lcl_alv_toolbar IMPLEMENTATION



    Regards

    Ebrahim



    1.jpg (220.6 kB)
    2.jpg (222.5 kB)
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 22, 2015 at 06:28 AM

    Hi Ramya,

    Just concatenate the value with '%'.

    Look into the sample code attached.

    Regards,

    N. HARISH KUMAR


    Capture.JPG (27.8 kB)
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.