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

Custom button on ALV Toolbar

Former Member
0 Likes
40,356

Hello Experts

I want to add Some custom buttons on my ALV Toolbar with caption 'SAVE' and 'CHECK'. Suggest the best possible way for this.

Thanks in advance

Gaurav

1 ACCEPTED SOLUTION
Read only

Former Member
26,136

See the report BCALV_GRID_05.

Filippo

Hello Experts

I want to add Some custom buttons on my ALV Toolbar with caption 'SAVE' and 'CHECK'. Suggest the best possible way for this.

Thanks in advance

Gaurav

11 REPLIES 11
Read only

Former Member
26,137

See the report BCALV_GRID_05.

Filippo

Read only

Former Member
0 Likes
26,136

pls create the gui status ,then u can customize the buttons.

tks. best regards.

Read only

koolspy_ultimate
Active Contributor
0 Likes
26,136

OPEN tcode se80 and select function group and open SALV

open gui status and right click on standard and copy it to your required program

and add your required two buttons wit your desired names.

and use the below sample code in your program.


FORM pf_status_set USING rt_extab TYPE slis_t_extab.

SET PF-STATUS 'STATUS1' .

ENDFORM. "PF_STATUS_SET

Pass this form name to your ALV FM.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_repid
i_callback_pf_status_set = 'PF_STATUS_SET'
i_callback_user_command = 'USER_COMMAND'
is_layout = i_layout
it_fieldcat = i_fieldcat[]
TABLES
t_outtab = p_out
EXCEPTIONS
program_error = 1
OTHERS = 2.

Read only

Former Member
0 Likes
26,136

hi,

you need to create a gui_status.

Add these two buttons and assign a func code to them.

in your program at user command event check the value of sy-ucomm.And assign the desired processing.

Read only

Former Member
0 Likes
26,136

Use Events TOOLBAR and USER_COMMAND of class CL_GUI_ALV_GRID

TOOLBAR -> to add your buttons into e_object->mt_toolbar (ALV Toolbar)

USER_COMMAND -> To handle the actions to be done on press of these buttons.

Regards,

Seema

Read only

Former Member
26,136

Hi ,

If you are using CL_GUI_ALV_GRID then

1) Create an event handler class.

2) Handle events TOOLBAR and USER_COMMAND of class CL_GUI_ALV_GRID.

3) In method of event TOOLBAR use structure STB_BUTTON to fill your toolbar button details like Fcode, text Icon

append this structure to E_OBJECT->MT_TOOLBAR .

4) In USER COMMAND write your code for the buttons

5) Set event handler after method SET_TABLE_FOR_FIRST_DISPLAY

Check the code below


CLASS CL_EVENT_HANDLER DEFINITION.
  PUBLIC SECTION.
    METHODS : USER_COMMAND FOR EVENT AFTER_USER_COMMAND OF CL_GUI_ALV_GRID IMPORTING E_UCOMM,
              TOOLBAR FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID IMPORTING E_OBJECT E_INTERACTIVE.
ENDCLASS. 

CLASS CL_EVENT_HANDLER IMPLEMENTATION.
  METHOD TOOLBAR.
    DATA : MT_TOOLBAR TYPE STB_BUTTON.

    CLEAR MT_TOOLBAR.
    MT_TOOLBAR-BUTN_TYPE = '3'.   "separator 
    APPEND MT_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
    CLEAR MT_TOOLBAR.
    MT_TOOLBAR-BUTN_TYPE = '0'.   "normal Button
    MT_TOOLBAR-FUNCTION = 'CL_REF'.   "fcode
    MT_TOOLBAR-ICON = '@42@'.
    MT_TOOLBAR-QUICKINFO = 'UPDATE LOG FILE'.
    APPEND MT_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
  ENDMETHOD.                    "TOOLBAR
  METHOD USER_COMMAND.
    IF E_UCOMM = 'CL_REF'.
      PERFORM ACTION.
    ENDIF.
  ENDMETHOD.                    "USER_COMMAND
ENDCLASS.   

Thanks,

Anmol Bhat.

Read only

0 Likes
26,136

Hello,

Thank you for your answer Anmol. I've used your code to show an information message when I click on the button, and after I want it to open another screen using : "CALL SCREEN 101" on the ACTION FORM, so I created the screen 101, but actually when I click on the button the current screen still show in up and hiding the new one. I'm wondering if we can do it with this solution or we can't do that way.

Thank you.

Youssef

Read only

Former Member
0 Likes
26,136

Hi

I have got the buttons now. Now I have created a sub-routine and I am writing some code for user-command. Same Sub-routine I have passed to the REUSE_ALV_GRID_DISPLAY FM to the appropriate field. But still the click on button is not getting captured. Plz help.

Thanks

Gaurav

Read only

0 Likes
26,136

if you want the button to take effect then you need you write your code in this way


at user-command.
case sy-ucomm.
when 'Your button name here'.
your code.
when 'your second button'.
you code.
endcase.
endat.

please visit this video for clear idea [click here|http://www.youtube.com/watch?v=z5OAW1btigQ]

Read only

Former Member
0 Likes
26,136

Very helpful...

Read only

0 Likes
26,136

Solved? why no accept an answer? wich is the tip? can you paste some code?

thanks.