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

Tool bar

Former Member
0 Likes
377

Hi,

Good day experts,

I've created the Report which is used with OOPs. i want the Tool bar which is customised. I dont need the system generat tool bar.

How to do it? Plz give me solution for this one.

regards,

kk

2 REPLIES 2
Read only

Former Member
0 Likes
354

Hi Kiran,

Thouroughly check this sample program. In this i have created two buttons 'PRINT' and 'PHONE' on the tool bar. Try to implement it in your code.

REPORT Z_44072_ALV_OOPS .

TABLES : MARA.

TYPE-POOLS : ICON.

CLASS lcl_event_receiver DEFINITION DEFERRED.

DATA : CH_GRID TYPE REF TO CL_GUI_ALV_GRID.

DATA : CH_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

DATA : IT_MARA LIKE MARA OCCURS 0 WITH HEADER LINE.

DATA : o_event_receiver TYPE REF TO lcl_event_receiver.

DATA : CH_GRID1 TYPE REF TO CL_GUI_ALV_GRID.

DATA : CH_CONTAINER1 TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

DATA : IT_MAKT LIKE MAKT OCCURS 0 WITH HEADER LINE.

DATA : gs_layout TYPE lvc_s_layo,

ok_code LIKE sy-ucomm.

SELECT * FROM MARA INTO TABLE IT_MARA.

CALL SCREEN 100.

*----


  • C L A S S E S

*----


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.

CLASS lcl_event_receiver IMPLEMENTATION.

METHOD handle_toolbar.

  • Event handler method for event toolbar.

CONSTANTS:

  • Constants for button type

c_button_normal TYPE i VALUE 0,

c_menu_and_default_button TYPE i VALUE 1,

c_menu TYPE i VALUE 2,

c_separator TYPE i VALUE 3,

c_radio_button TYPE i VALUE 4,

c_checkbox TYPE i VALUE 5,

c_menu_entry TYPE i VALUE 6.

DATA: ls_toolbar TYPE stb_button.

  • Append seperator to the normal toolbar

CLEAR ls_toolbar.

MOVE c_separator TO ls_toolbar-butn_type..

APPEND ls_toolbar TO e_object->mt_toolbar.

  • Append a new button that to the toolbar. Use E_OBJECT of

  • event toolbar. E_OBJECT is of type CL_ALV_EVENT_TOOLBAR_SET.

  • This class has one attribute MT_TOOLBAR which is of table type

  • TTB_BUTTON. The structure is STB_BUTTON

CLEAR ls_toolbar.

MOVE 'PRINT' TO ls_toolbar-function.

MOVE ICON_PRINT TO ls_toolbar-icon.

MOVE 'Print' TO ls_toolbar-quickinfo.

MOVE 'Print' TO ls_toolbar-text.

MOVE ' ' TO ls_toolbar-disabled.

APPEND ls_toolbar TO e_object->MT_toolbar.

CLEAR ls_toolbar.

MOVE 'PHONE' TO ls_toolbar-function.

MOVE ICON_PHONE TO ls_toolbar-icon.

MOVE 'Phone' TO ls_toolbar-quickinfo.

MOVE 'Phone' TO ls_toolbar-text.

MOVE ' ' TO ls_toolbar-disabled.

APPEND ls_toolbar TO e_object->MT_toolbar.

ENDMETHOD.

METHOD handle_user_command.

  • Handle own functions defined in the toolbar

CASE e_ucomm.

WHEN 'CHANGE'.

  • PERFORM change_flight.

  • LEAVE TO SCREEN 0.

ENDCASE.

ENDMETHOD.

ENDCLASS.

CLASS CH_EVENT DEFINITION.

PUBLIC SECTION.

METHODS : DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID

IMPORTING E_ROW E_COLUMN.

PRIVATE SECTION.

ENDCLASS.

CLASS CH_EVENT IMPLEMENTATION.

METHOD DOUBLE_CLICK.

PERFORM DOUBLE_CLICK USING E_ROW E_COLUMN.

ENDMETHOD.

ENDCLASS.

DATA : EVENT TYPE REF TO CH_EVENT.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


module STATUS_0100 output.

SET PF-STATUS 'CH1'.

  • SET TITLEBAR 'xxx'.

PERFORM DISPLAY_ALV.

CREATE OBJECT EVENT.

SET HANDLER EVENT->DOUBLE_CLICK FOR CH_GRID.

endmodule. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


module USER_COMMAND_0100 input.

CASE SY-UCOMM.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

endmodule. " USER_COMMAND_0100 INPUT

&----


*& Form DISPLAY_ALV

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form DISPLAY_ALV .

IF CH_CONTAINER IS INITIAL.

CREATE OBJECT CH_CONTAINER

EXPORTING

CONTAINER_NAME = 'CH_CONTAINER'.

CREATE OBJECT CH_GRID

EXPORTING

I_PARENT = CH_CONTAINER.

gs_layout-zebra = 'X'.

gs_layout-keyhot = 'X'.

CREATE OBJECT o_event_receiver.

SET HANDLER o_event_receiver->handle_user_command FOR CH_GRID.

SET HANDLER o_event_receiver->handle_toolbar FOR CH_GRID.

CALL METHOD CH_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

I_STRUCTURE_NAME = 'MARA'

is_layout = gs_layout

CHANGING

IT_OUTTAB = IT_MARA[].

ENDIF.

CALL METHOD CH_GRID->set_toolbar_interactive.

CALL METHOD cl_gui_control=>set_focus EXPORTING control = CH_GRID.

endform. " DISPLAY_ALV

&----


*& Form DOUBLE_CLICK

&----


  • text

----


  • -->P_E_ROW text

  • -->P_E_COLUMN text

----


form DOUBLE_CLICK using p_e_row

p_e_column.

READ TABLE IT_MARA INDEX P_E_ROW.

IF SY-SUBRC = 0.

CLEAR IT_MAKT.

REFRESH IT_MAKT.

SELECT * FROM MAKT INTO TABLE IT_MAKT

WHERE MATNR = IT_MARA-MATNR.

CALL SCREEN 200.

ENDIF.

endform. " DOUBLE_CLICK

&----


*& Module STATUS_0200 OUTPUT

&----


  • text

----


module STATUS_0200 output.

SET PF-STATUS 'MNU2'.

  • SET TITLEBAR 'xxx'.

PERFORM DISPLAY_GRID2.

endmodule. " STATUS_0200 OUTPUT

&----


*& Module USER_COMMAND_0200 INPUT

&----


  • text

----


module USER_COMMAND_0200 input.

CASE SY-UCOMM.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

endmodule. " USER_COMMAND_0200 INPUT

&----


*& Form DISPLAY_GRID2

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form DISPLAY_GRID2 .

IF CH_CONTAINER1 IS INITIAL.

CREATE OBJECT CH_CONTAINER1

EXPORTING

CONTAINER_NAME = 'CH_CONTAINER1'.

CREATE OBJECT CH_GRID1

EXPORTING

I_PARENT = CH_CONTAINER1.

CALL METHOD CH_GRID1->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

I_STRUCTURE_NAME = 'MAKT'

CHANGING

IT_OUTTAB = IT_MAKT[].

ENDIF.

endform. " DISPLAY_GRID2

Read only

Former Member
0 Likes
354

Please refer the link below :

http://www.sapdev.co.uk/reporting/alv/alvgrid_pfstatus.htm

Regards.