Application Development and Automation 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: 
Read only

ALV GRID with custom container

Former Member
0 Likes
1,934

Hi Experts,

I developed one program to display the output with alv grid in custom container.

I got the tool bar options on the custom container by copying the STANDARD gui status.

Some of the icos were grayed out ... can anyone guide me how to activate those icons..?

My requirement is to add some extra icons like create, insert, delete....

Please guide me how to do that... If you have any piece of code... I really appreciate your help...

thanks in advance.

Sri

Hi Experts,

I developed one program to display the output with alv grid in custom container.

I got the tool bar options on the custom container by copying the STANDARD gui status.

Some of the icos were grayed out ... can anyone guide me how to activate those icons..?

My requirement is to add some extra icons like create, insert, delete....

Please guide me how to do that... If you have any piece of code... I really appreciate your help...

thanks in advance.

Sri

4 REPLIES 4
Read only

Former Member
0 Likes
1,314

Hi,

To add custome buttons to the ALV grid, you need to create a local class and declare an event handler.

CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

METHODS:

handle_toolbar

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.

ENDCLASS.

Set the following event handlers for the ALV grid.

SET HANDLER cl_event_receiver->handle_user_command FOR grid2.

SET HANDLER cl_event_receiver->handle_toolbar FOR grid2.

In the handle_toolbar event, you can add the custome buttons as follows:

METHOD handle_toolbar .

DATA: lw_toolbar TYPE stb_button.

CLEAR lw_toolbar.

MOVE 3 TO lw_toolbar-butn_type.

APPEND lw_toolbar TO e_object->mt_toolbar.

CLEAR lw_toolbar.

MOVE 'SELALL' TO lw_toolbar-function.

MOVE icon_select_all TO lw_toolbar-icon.

MOVE 'Select all the checkboxes' TO lw_toolbar-quickinfo.

MOVE 'Select all' TO lw_toolbar-text.

MOVE ' ' TO lw_toolbar-disabled.

APPEND lw_toolbar TO e_object->mt_toolbar.

CLEAR lw_toolbar.

MOVE 3 TO lw_toolbar-butn_type.

APPEND lw_toolbar TO e_object->mt_toolbar.

CLEAR lw_toolbar.

MOVE 'DESELALL' TO lw_toolbar-function.

MOVE icon_deselect_all TO lw_toolbar-icon.

MOVE 'Deselect all the checkboxes' TO lw_toolbar-quickinfo.

MOVE 'Deselect all' TO lw_toolbar-text.

MOVE ' ' TO lw_toolbar-disabled.

APPEND lw_toolbar TO e_object->mt_toolbar.

ENDMETHOD. "handle_toolbar.

And add the required processing logic in the USER_COMMAND handler.

METHOD handle_user_command.

DATA: lt_rows TYPE lvc_t_row.

DATA: li_filtered TYPE lvc_t_fidx.

DATA : lv_vkaus LIKE VBAP-VKAUS,

lv_refresh TYPE C.

data : li_cells type lvc_t_modi,

lw_cells type lvc_s_modi ,

lv_valid.

CASE e_ucomm.

*---> Select all

WHEN 'SELALL'.

*/ Method provide the the filtered entries. Use them to avoid

*/ marking only those which are not filtered while doing select all.

CALL METHOD grid2->get_filtered_entries

IMPORTING

et_filtered_entries = li_filtered.

LOOP AT gi_item_display INTO gw_item_display.

READ TABLE li_filtered FROM sy-tabix TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.

gw_item_display-checkbox = 'X'.

MODIFY gi_item_display FROM gw_item_display

TRANSPORTING checkbox.

ENDIF.

ENDLOOP.

*---> De-select all

WHEN 'DESELALL'.

LOOP AT gi_item_display INTO gw_item_display.

gw_item_display-checkbox = ' '.

MODIFY gi_item_display FROM gw_item_display

TRANSPORTING checkbox.

ENDLOOP.

ENDCASE.

Read only

Former Member
0 Likes
1,314

Hi Sri,

To add your own functions, ALV Grid control has an open door letting you to add your own functions triggered by a button press on the ALV toolbar. For this, we mainly utilize two of ALV Grid events. We use the event u201Ctoolbaru201D to add the button and the event u201Cuser_commandu201D to implement the new function.

In the method handling the u201Ctoolbaru201D event, we define a new button by filling a structure and appending it to the table attribute u201Cmt_toolbaru201D of the object to whose reference we can reach via the parameter u201Ce_objectu201D of the event.

Please refer the below code:-

DATA: ls_toolbar TYPE stb_button.

CLEAR ls_toolbar.

MOVE 3 TO ls_toolbar-butn_type.

APPEND ls_toolbar TO i_object->mt_toolbar.

CLEAR ls_toolbar.

MOVE 'PER' TO ls_toolbar-function. "#EC NOTEXT

MOVE icon_display_text TO ls_toolbar-icon.

MOVE 'Passenger Info'(201) TO ls_toolbar-quickinfo.

MOVE 'Passenger Info'(201) TO ls_toolbar-text.

MOVE ' ' TO ls_toolbar-disabled. "#EC NOTEXT

APPEND ls_toolbar TO i_object->mt_toolbar.

CLEAR ls_toolbar.

MOVE 'EXCH' TO ls_toolbar-function. "#EC NOTEXT

MOVE 2 TO ls_toolbar-butn_type.

MOVE icon_calculation TO ls_toolbar-icon.

MOVE 'Payment in Other Currencies'(202) TO ls_toolbar-quickinfo.

MOVE ' ' TO ls_toolbar-text.

MOVE ' ' TO ls_toolbar-disabled. "#EC NOTEXT

APPEND ls_toolbar TO i_object->mt_toolbar.

ENDFORM .

Hope it helps you.

Please set to resolved if it helps you.

Regards

Abhii...

Read only

0 Likes
1,314

Thanks guys... I will try this and get back to you...

Sri

Read only

0 Likes
1,314

... and don't forget to search for topic

how to post code on SDN?

Thanks,

Clemens