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 REPORT WITH OOPS ISSUE

Former Member
0 Likes
779

Hi ,

I have an alv report using oops.

i want to delete or hide all tool bar menu like download to excel icon etc

if g_custom_container is initial.

create object g_custom_container

exporting container_name = g_container.

create object grid1

exporting i_parent = g_custom_container.

call method grid1->set_table_for_first_display

exporting i_structure_name = 'ZTEST'

changing it_outtab = itab.

I SEE THIS METHOD DELETE_ALL_MENUS IN CLASS CL_GUI_ALV_GRID BUT I DON'T KNOW HOW TO CALL IT.

CAN ANYONE TELL ME HOW TO DO THIS

THIS IS WHAT I HAVE DOEN ONE OTHER PROGRAM WHERE THE SITUATION WAS SAME

call method g_custom_container ->set_toolbar_mode

exporting toolbar_mode = 0.

endif.

---THIS IS NOT AN ALV REPORT THOUGH

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
743

Hello Suchitra

Have a look at my sample report

ZUS_SDN_ALV_EVT_TOOLBAR

. Choose either option to inactivate or delete toolbar buttons and execute the report. When the grid is displayed simply push the

ENTER

button repeatedly.

*&----


*

*& Report ZUS_SDN_ALV_EVT_TOOLBAR

*&

*&----


*

*& This sample report explains the handling of event TOOLBAR in order

*% to activate or inactive buttons of the ALV toolbar.

*&

*& Based on: BCALV_GRID_DEMO

*&

*& Procedure: Copy BCALV_GRID_DEMO and replace entire coding OR

  • copy screen '0100' and GUI status 'MAIN100' from

  • BCALV_GRID_DEMO to this report.

*&----


*

REPORT zus_sdn_alv_evt_toolbar.

TYPE-POOLS: abap, cntb, icon.

DATA:

ok_code TYPE ui_func,

gt_sflight TYPE TABLE OF sflight,

*

g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',

g_grid1 TYPE REF TO cl_gui_alv_grid,

g_custom_container TYPE REF TO cl_gui_custom_container.

PARAMETERS:

p_inact RADIOBUTTON GROUP grp1 DEFAULT 'X', " delete buttons

p_dele RADIOBUTTON GROUP grp1. " inactivate buttons

PARAMETERS:

p_newbut AS CHECKBOX DEFAULT ' ', " add new button

p_newddm AS CHECKBOX DEFAULT 'X'. " add dropdown menu

*----


*

  • CLASS lcl_eventhandler DEFINITION

*----


*

*

*----


*

CLASS lcl_eventhandler DEFINITION.

PUBLIC SECTION.

CLASS-DATA:

md_cnt TYPE i.

CLASS-METHODS:

handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING

e_object

e_interactive

sender.

ENDCLASS. "lcl_eventhandler DEFINITION

*----


*

  • CLASS lcl_eventhandler IMPLEMENTATION

*----


*

*

*----


*

CLASS lcl_eventhandler IMPLEMENTATION.

METHOD handle_toolbar.

  • § 2.In event handler method for event TOOLBAR: Append own functions

  • by using event parameter E_OBJECT.

DATA:

ls_toolbar TYPE stb_button,

ls_menu type STB_BTNMNU.

*....................................................................

  • E_OBJECT of event TOOLBAR is of type REF TO CL_ALV_EVENT_TOOLBAR_SET.

  • This class has got one attribute, namly MT_TOOLBAR, which

  • is a table of type TTB_BUTTON. One line of this table is

  • defined by the Structure STB_BUTTON (see data deklaration above).

*

  • A remark to the flag E_INTERACTIVE:

  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • 'e_interactive' is set, if this event is raised due to

  • the call of 'set_toolbar_interactive' by the user.

  • You can distinguish this way if the event was raised

  • by yourself or by ALV

  • (e.g. in method 'refresh_table_display').

  • An application of this feature is still unknown...

ADD 1 TO md_cnt. " a simple counter

  • (1.a) Inactivate toolbar buttons

IF ( p_inact = abap_true ).

LOOP AT e_object->mt_toolbar INTO ls_toolbar FROM 1 TO md_cnt.

ls_toolbar-disabled = 'X'.

MODIFY e_object->mt_toolbar FROM ls_toolbar.

ENDLOOP.

  • (1.b) Delete toolbar buttons

ELSE.

DO md_cnt TIMES.

DELETE e_object->mt_toolbar INDEX 1.

ENDDO.

ENDIF.

  • (2) Add new button

IF ( p_newbut = abap_true ).

  • Add separator to separate default and new buttons

CLEAR: ls_toolbar.

ls_toolbar-butn_type = cntb_btype_sep. " separator

APPEND ls_toolbar TO e_object->mt_toolbar.

  • Add new button "DETAIL"

CLEAR: ls_toolbar.

ls_toolbar-function = 'DETAIL'.

ls_toolbar-icon = icon_detail.

ls_toolbar-quickinfo = 'QuickInfo'.

ls_toolbar-butn_type = cntb_btype_button.

ls_toolbar-disabled = abap_false.

ls_toolbar-text = 'Details'.

  • ls_toolbar-checked = ' '.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDIF.

  • (3) Add new dropdown menu

IF ( p_newddm = abap_true ).

  • Add separator to separate default and new buttons

CLEAR: ls_toolbar.

ls_toolbar-butn_type = cntb_btype_sep. " separator

APPEND ls_toolbar TO e_object->mt_toolbar.

  • Add new dropdown menu "DETAIL"

CLEAR: ls_toolbar.

ls_toolbar-function = 'DDMENU'.

ls_toolbar-icon = icon_detail.

ls_toolbar-quickinfo = 'QuickInfo'.

ls_toolbar-butn_type = cntb_btype_dropdown.

ls_toolbar-disabled = abap_false.

ls_toolbar-text = 'DD-Menu'.

  • ls_toolbar-checked = ' '.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDIF.

ENDMETHOD. "handle_toolbar

ENDCLASS. "lcl_eventhandler IMPLEMENTATION

START-OF-SELECTION.

*----


*

  • MAIN *

*----


*

SELECT * FROM sflight INTO TABLE gt_sflight.

CALL SCREEN 100.

END-OF-SELECTION.

*----


*

  • MODULE PBO OUTPUT *

*----


*

MODULE pbo OUTPUT.

SET PF-STATUS 'MAIN100'.

IF g_custom_container IS INITIAL.

CREATE OBJECT g_custom_container

EXPORTING container_name = g_container.

  • Instantiate ALV grid control

CREATE OBJECT g_grid1

EXPORTING i_parent = g_custom_container.

CALL METHOD g_grid1->set_table_for_first_display

EXPORTING

i_structure_name = 'SFLIGHT'

CHANGING

it_outtab = gt_sflight.

  • Set event handler for event TOOLBAR

SET HANDLER:

lcl_eventhandler=>handle_toolbar FOR g_grid1.

ENDIF.

  • $Comment: Toolbar can be modified on-the-fly

g_grid1->set_toolbar_interactive( ).

ENDMODULE. "PBO OUTPUT

*----


*

  • MODULE PAI INPUT *

*----


*

MODULE pai INPUT.

  • to react on oi_custom_events:

CALL METHOD cl_gui_cfw=>dispatch.

CASE ok_code.

WHEN 'EXIT'.

PERFORM exit_program.

WHEN OTHERS.

  • do nothing

ENDCASE.

CLEAR ok_code.

ENDMODULE. "PAI INPUT

*----


*

  • FORM EXIT_PROGRAM *

*----


*

FORM exit_program.

  • CALL METHOD G_CUSTOM_CONTAINER->FREE.

  • CALL METHOD CL_GUI_CFW=>FLUSH.

LEAVE PROGRAM.

ENDFORM. "EXIT_PROGRAM

Regards

Uwe

4 REPLIES 4
Read only

uwe_schieferstein
Active Contributor
0 Likes
744

Hello Suchitra

Have a look at my sample report

ZUS_SDN_ALV_EVT_TOOLBAR

. Choose either option to inactivate or delete toolbar buttons and execute the report. When the grid is displayed simply push the

ENTER

button repeatedly.

*&----


*

*& Report ZUS_SDN_ALV_EVT_TOOLBAR

*&

*&----


*

*& This sample report explains the handling of event TOOLBAR in order

*% to activate or inactive buttons of the ALV toolbar.

*&

*& Based on: BCALV_GRID_DEMO

*&

*& Procedure: Copy BCALV_GRID_DEMO and replace entire coding OR

  • copy screen '0100' and GUI status 'MAIN100' from

  • BCALV_GRID_DEMO to this report.

*&----


*

REPORT zus_sdn_alv_evt_toolbar.

TYPE-POOLS: abap, cntb, icon.

DATA:

ok_code TYPE ui_func,

gt_sflight TYPE TABLE OF sflight,

*

g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',

g_grid1 TYPE REF TO cl_gui_alv_grid,

g_custom_container TYPE REF TO cl_gui_custom_container.

PARAMETERS:

p_inact RADIOBUTTON GROUP grp1 DEFAULT 'X', " delete buttons

p_dele RADIOBUTTON GROUP grp1. " inactivate buttons

PARAMETERS:

p_newbut AS CHECKBOX DEFAULT ' ', " add new button

p_newddm AS CHECKBOX DEFAULT 'X'. " add dropdown menu

*----


*

  • CLASS lcl_eventhandler DEFINITION

*----


*

*

*----


*

CLASS lcl_eventhandler DEFINITION.

PUBLIC SECTION.

CLASS-DATA:

md_cnt TYPE i.

CLASS-METHODS:

handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING

e_object

e_interactive

sender.

ENDCLASS. "lcl_eventhandler DEFINITION

*----


*

  • CLASS lcl_eventhandler IMPLEMENTATION

*----


*

*

*----


*

CLASS lcl_eventhandler IMPLEMENTATION.

METHOD handle_toolbar.

  • § 2.In event handler method for event TOOLBAR: Append own functions

  • by using event parameter E_OBJECT.

DATA:

ls_toolbar TYPE stb_button,

ls_menu type STB_BTNMNU.

*....................................................................

  • E_OBJECT of event TOOLBAR is of type REF TO CL_ALV_EVENT_TOOLBAR_SET.

  • This class has got one attribute, namly MT_TOOLBAR, which

  • is a table of type TTB_BUTTON. One line of this table is

  • defined by the Structure STB_BUTTON (see data deklaration above).

*

  • A remark to the flag E_INTERACTIVE:

  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • 'e_interactive' is set, if this event is raised due to

  • the call of 'set_toolbar_interactive' by the user.

  • You can distinguish this way if the event was raised

  • by yourself or by ALV

  • (e.g. in method 'refresh_table_display').

  • An application of this feature is still unknown...

ADD 1 TO md_cnt. " a simple counter

  • (1.a) Inactivate toolbar buttons

IF ( p_inact = abap_true ).

LOOP AT e_object->mt_toolbar INTO ls_toolbar FROM 1 TO md_cnt.

ls_toolbar-disabled = 'X'.

MODIFY e_object->mt_toolbar FROM ls_toolbar.

ENDLOOP.

  • (1.b) Delete toolbar buttons

ELSE.

DO md_cnt TIMES.

DELETE e_object->mt_toolbar INDEX 1.

ENDDO.

ENDIF.

  • (2) Add new button

IF ( p_newbut = abap_true ).

  • Add separator to separate default and new buttons

CLEAR: ls_toolbar.

ls_toolbar-butn_type = cntb_btype_sep. " separator

APPEND ls_toolbar TO e_object->mt_toolbar.

  • Add new button "DETAIL"

CLEAR: ls_toolbar.

ls_toolbar-function = 'DETAIL'.

ls_toolbar-icon = icon_detail.

ls_toolbar-quickinfo = 'QuickInfo'.

ls_toolbar-butn_type = cntb_btype_button.

ls_toolbar-disabled = abap_false.

ls_toolbar-text = 'Details'.

  • ls_toolbar-checked = ' '.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDIF.

  • (3) Add new dropdown menu

IF ( p_newddm = abap_true ).

  • Add separator to separate default and new buttons

CLEAR: ls_toolbar.

ls_toolbar-butn_type = cntb_btype_sep. " separator

APPEND ls_toolbar TO e_object->mt_toolbar.

  • Add new dropdown menu "DETAIL"

CLEAR: ls_toolbar.

ls_toolbar-function = 'DDMENU'.

ls_toolbar-icon = icon_detail.

ls_toolbar-quickinfo = 'QuickInfo'.

ls_toolbar-butn_type = cntb_btype_dropdown.

ls_toolbar-disabled = abap_false.

ls_toolbar-text = 'DD-Menu'.

  • ls_toolbar-checked = ' '.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDIF.

ENDMETHOD. "handle_toolbar

ENDCLASS. "lcl_eventhandler IMPLEMENTATION

START-OF-SELECTION.

*----


*

  • MAIN *

*----


*

SELECT * FROM sflight INTO TABLE gt_sflight.

CALL SCREEN 100.

END-OF-SELECTION.

*----


*

  • MODULE PBO OUTPUT *

*----


*

MODULE pbo OUTPUT.

SET PF-STATUS 'MAIN100'.

IF g_custom_container IS INITIAL.

CREATE OBJECT g_custom_container

EXPORTING container_name = g_container.

  • Instantiate ALV grid control

CREATE OBJECT g_grid1

EXPORTING i_parent = g_custom_container.

CALL METHOD g_grid1->set_table_for_first_display

EXPORTING

i_structure_name = 'SFLIGHT'

CHANGING

it_outtab = gt_sflight.

  • Set event handler for event TOOLBAR

SET HANDLER:

lcl_eventhandler=>handle_toolbar FOR g_grid1.

ENDIF.

  • $Comment: Toolbar can be modified on-the-fly

g_grid1->set_toolbar_interactive( ).

ENDMODULE. "PBO OUTPUT

*----


*

  • MODULE PAI INPUT *

*----


*

MODULE pai INPUT.

  • to react on oi_custom_events:

CALL METHOD cl_gui_cfw=>dispatch.

CASE ok_code.

WHEN 'EXIT'.

PERFORM exit_program.

WHEN OTHERS.

  • do nothing

ENDCASE.

CLEAR ok_code.

ENDMODULE. "PAI INPUT

*----


*

  • FORM EXIT_PROGRAM *

*----


*

FORM exit_program.

  • CALL METHOD G_CUSTOM_CONTAINER->FREE.

  • CALL METHOD CL_GUI_CFW=>FLUSH.

LEAVE PROGRAM.

ENDFORM. "EXIT_PROGRAM

Regards

Uwe

Read only

0 Likes
743

Hi Uwe,

I was reading a document which says

To hide the entire toolbar, you can set the field “NO_TOOLBAR” of the layout structure to ‘X’.

I GUESS IF WE PASS THE NO_TOOBAR ='X' to gs_layout that would take care right.

call method grid1->set_table_for_first_display

exporting i_structure_name = 'ZTEST'

is_layout = gs_layout

changing it_outtab = itab.

let me know if iam right and how to do this .

Iam pretty much new to OOPS and i learning it.

I would appreciate your help

Thanks

Read only

0 Likes
743

Hello Suchitra

You are perfectly right. To hide the toolbar entirely set gs_layout-no_toolbar = 'X'.

Regards

Uwe

Read only

Former Member
0 Likes
743

Hi ,

Try and see if the following code helps .

*-- Exclude un-wanted toolbar commands for Address ALV

PERFORM exclude_functions CHANGING it_exclude_adr.

CALL METHOD g_alv_address->set_table_for_first_display

EXPORTING

i_save = 'U'

i_default = c_x

is_layout = g_layout

it_toolbar_excluding = it_exclude_adr

CHANGING

it_outtab = it_adr_out[]

it_fieldcatalog = it_field_cat_adr.

FORM exclude_functions CHANGING p_exclude TYPE ui_functions.

DATA: l_function TYPE ui_func.

*-- If we wanted all the buttons to be excluded in one shot

APPEND cl_gui_alv_grid=>mc_fc_excl_all TO p_exclude.

*-- Exclude only selected buttons

*l_function = cl_gui_alv_grid=>mc_fc_detail.

  • APPEND l_function TO p_exclude.

ENDFORM. " exclude_functions