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

Enable User Defined toolbar button on click - editable alv grid using oops

Former Member
0 Likes
2,516

Hi all,

I have created editable alv using oops concept.

created 2 user defined toolbar button save and print using method toolbar

ls_toolbar-text = 'Print'. "#EC NOTEXT

ls_toolbar-quickinfo = space.

ls_toolbar-checked = space.

APPEND ls_toolbar TO e_object->mt_toolbar.

requirement is

initially print button should be disabled, and save enabled

when i click save button, print button should be enabled.

I want coding in editable alv oops concept

kindly help

regards

senthil kumar

11 REPLIES 11
Read only

Former Member
0 Likes
1,809

Halo Senthil,

Step 1

Define a method on_toolbar in your class which is an event handler method for cl_gui_alv_grids toolbar event

Step2

Depending on the condition you can disable/enable the print button.

if you want to enable

MOVE 'X' to l_toolbar-disabled.

if you want to enable.

MOVE space TO l_toolbar-disabled.

append l_toolbar to e_object->mt_toolbar.

Regards

Arshad.

Read only

0 Likes
1,809

hi arshad,

thanx for the immediate reply.

But the coding u have given where should i include , in user command or somewhere else.

we can disable print button in method toolbar itself by giving

ls_toolbar-disabled = 'X'.

that is ok,

my conditiion is if i click save button , print should be enabled.

i want more clarity please.

regards

senthil kumar p

Read only

0 Likes
1,809

"set handler for the toolbar buttons

on_toolbar

FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING e_object.


if sy-ucomm eq 'SAVE'.
read table e_object->mt_toolbar assigning <fs_toolbar>  with key FUNCTION = 'PRINT'.
clear <fs_toolbar> -disabled .
endif.

This code should be a part of on_toolbar implementation

Regards

Arshad

Read only

0 Likes
1,809

hi arshad,

If i give the coding in on_toolbar implementation, sy_ucomm is blank

and print button not enabled.

Also u toolbar event does not sy_ucomm as parameter.

regards

senthil kumar P

Read only

0 Likes
1,809

Did you try what Vinod suggested

ignore

modify TOOLBAR from event USER_COMMAND and trigger SET_TOOLBAR_INTERACTIVE once again?

modify from TOOLBAR and trigger SET_TOOLBAR_INTERACTIVE once again from USER_COMMAND

Regards

Marcin

Edited by: Marcin Pciak on Mar 29, 2011 2:50 PM

Read only

0 Likes
1,809

Halo Senthil,

You should call set_toolbar_interactive method of cl_gui_alv_grid in the on_user_command( ie the event handler for event user command) .

method on_user_command.

case e_ucomm.

when 'SAVE'. or whatever your function code is .

my_save_flag = 'X'.

call method grid->set_toolbar_interactive.

endmethod.

This triggers the toolbar event of the

cl_gui_alv_grid. Inside the eventhandler method ( ie the on_toolbar method ) you should set the toolbar.

if my_save_flag = 'X'.

read table e_object->mt_toolbar

clear l_toolbar-disabled.

modify e_object->mt_toolbar.

endif.

e_ucomm will not have the function code if the save button is not in the toolbar area.

then you can set the my_save_flag in the data_changed event handler of the Cl_gui_alv_grid.

Regards

Arshad

Read only

0 Likes
1,809

As Arshad mentioned you can use the logic of setting the flag in event USER_COMMAND and using it in event HANDLE_TOOLBAR. But you cannot use the logic of READ contents of E_OBJECT->MT_TOOLBAR for the custom button in HANDLE_TOOLBAR event and modifying E_OBJECT->MT_TOOLBAR-DISABLED.

When you call the method GRID->SET_TOOLBAR_INTERACTIVE, the records for custom button in E_OBJECT->MT_TOOLBAR will get deleted and READ statement will give SY-SUBRC NE 0 (Put a Break point in the method for handling event TOOLBAR and see the records in E_OBJECT->MT_TOOLBAR) . Only thing you need to do is, with the APPEND statements to E_OBJECT->MT_TOOLBAR for creating customer buttons, pass the appropriate value (FLAG) for the field DISABLED.

Read only

0 Likes
1,809

Hi arshad,

Thanx a lot.

Problem solved

You are rocking !!!!!!!!!!

Regards

Senthil Kumar P

Read only

MarcinPciak
Active Contributor
0 Likes
1,809

"add function code for each button
ls_toolbar-function = 'PRINT'.
ls_toolbar-disabled = 'X'.
append ...

ls_toolbar-function = 'SAVE'.
append ...

"set handler for the toolbar buttons
    handle_user_command
        FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING e_ucomm.

"in the method's implementation (once button is clicked)
"enable PRINT
read lt_toolbar into ls_toolbar with key function = 'PRINT'.
ls_toolbart-disabled = space.
modify lt_toolbar from ls_toobar.

"now disable SAVE in the same manner
...

"refresh display

That should more or less do the job.

Regards

Marcin

Read only

0 Likes
1,809

Dear Marcin

"in the method's implementation (once button is clicked)
"enable PRINT
read lt_toolbar into ls_toolbar with key function = 'PRINT'.
ls_toolbart-disabled = space.
modify lt_toolbar from ls_toobar.
 
"now disable SAVE in the same manner

While handling USER_COMMAND only importing parameter is E_UCOMM, I think we cannot change the values of E_OBJECT->MT_TOOLBAR (Details of Toolbar) which is importing parameter of event TOOLBAR. We may have to write the above logic while handling the event TOOLBAR and trigger it using GRID->REFRESH_TABLE_DISPLAY or GRID->SET_TOOLBAR_INTERACTIVE from the event USER_COMMAND.

Correct me if I am wrong.

Regards

Vinod

Read only

0 Likes
1,809

Dear Vinod,

While handling USER_COMMAND only importing parameter is E_UCOMM, I think we cannot change the values of E_OBJECT->MT_TOOLBAR (Details of Toolbar) which is importing parameter of event TOOLBAR. We may have to write the above logic while handling the event TOOLBAR and trigger it using GRID->REFRESH_TABLE_DISPLAY or GRID->SET_TOOLBAR_INTERACTIVE from the event USER_COMMAND.

I agree, though never tried dynamic toolbar modification. Anyhow thanks for correcting me.

Regards

Marcin