Hi,
We can add custom function code to standard button as follows.
Define TOOLBAR event handler,and raise that event by calling set_toolbar_Interactive( ).
In that event handler write
LOOP AT e_object->mt_toolbar INTO ls_toolbar.
CASE ls_toolbar-function.
WHEN cl_gui_alv_grid=><name of standard-ok-code for print>.
ls_toolbar-function = 'Custom function code'.
WHEN OTHERS.
CONTINUE.
ENDCASE.
MODIFY e_object->mt_toolbar FROM ls_toolbar INDEX syst-tabix.
ENDLOOP.
ENDMETHOD.
After this when user click on print it raises custom function code and trigger USER_COMMAND.
So write your code in USER_COMMAND.
Regards,
Sreenivas.