Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

hide toolbar in ALV

Hi,

I think its possible only in oops.

u have to fill a structure LVC_S_LAYO for alv in oops.

in that structure we havea field called no_toolbar.

use this field to hide and display toolbar in alv.

Regards

krishna

Former Member
Former Member replied

hi

By using this function no_toolbar you can hide tool bar

Defining GUI Elements in the Toolbar

Process Flow

1. Define an event handler method for event TOOLBAR.

2. Declare a structure for defining a toolbar element:

data: ls_toolbar TYPE stb_button.

3. For a pushbutton, for example, you would fill the following fields:

CLEAR ls_toolbar. MOVE 0 TO ls_toolbar-butn_type. MOVE 'BOOKINGS' TO ls_toolbar-function. MOVE icon_employee TO ls_toolbar-icon. MOVE 'Show Bookings'(111) TO ls_toolbar-quickinfo. MOVE SPACE TO ls_toolbar-disabled.

In the butn_type field, you specify the type of the GUI element for the ALV Grid Control. For possible values, see the value range of domain TB_BTYPE.

4. Use event parameter E_OBJECT to append the new definition to table mt_toolbar:

APPEND ls_toolbar TO e_object->mt_toolbar.

5. If you want to define additional elements, go back to step 3.

6. Call method set_toolbar_interactive, if you want to rebuild the toolbar.

Result

In the event handler method of event USER_COMMAND, you can query the function code you specified in field function to implement the associated function.

See also report BCALV_GRID_05 in development class SLIS.

set_toolbar_interactive

Use

This method triggers the toolbar event. If you add self-defined functions to the toolbar, you use this method to recreate the toolbar (see also: Defining GUI Elements in the Toolbar ).

Features

CALL METHOD .

TABLES: lfa1, lfb1, ekko, ekpo.

TYPE-POOLS: slis.

DATA: ok_code LIKE sy-ucomm,

g_container TYPE scrfname VALUE 'CONTAINER',

grid1 TYPE REF TO cl_gui_alv_grid,

g_custom_container TYPE REF TO cl_gui_custom_container.

DATA: repname LIKE sy-repid.

DATA: t_disvariant TYPE TABLE OF disvariant WITH HEADER LINE.

DATA: t_fieldtab TYPE lvc_t_fcat.

DATA: t_layout TYPE lvc_s_layo.

DATA: gs_toolbar TYPE stb_button.

DATA: t_rows TYPE lvc_t_row WITH HEADER LINE.

*----

-


  • TABLA DE DATOS

*----

-


DATA: BEGIN OF ti_acred OCCURS 0,

bukrs LIKE lfb1-bukrs,

lifnr LIKE lfa1-lifnr,

land1 LIKE lfa1-land1,

name1 LIKE lfa1-name1,

ort01 LIKE lfa1-ort01,

pstlz LIKE lfa1-pstlz,

regio LIKE lfa1-regio,

sortl LIKE lfa1-sortl,

stras LIKE lfa1-stras,

adrnr LIKE lfa1-adrnr,

END OF ti_acred.

DATA i_salida LIKE ti_acred OCCURS 0.

DATA: d_bukrs LIKE t001-bukrs.

DATA container.

DATA save VALUE 'X'.

*----


*

*----


Pantalla de Selección -


*

*----


*

SELECTION-SCREEN BEGIN OF BLOCK bloq1 WITH FRAME TITLE text-001.

SELECT-OPTIONS : lifnr FOR lfa1-lifnr,

bukrs FOR lfb1-bukrs.

SELECTION-SCREEN END OF BLOCK bloq1.

SELECTION-SCREEN BEGIN OF BLOCK bloq3 WITH FRAME TITLE text-003.

PARAMETERS: p_alvasg TYPE slis_vari. " Disposición ALV

SELECTION-SCREEN END OF BLOCK bloq3.

****************************************************************

  • LOCAL CLASSES: Definition

****************************************************************

*===============================================================

  • class lcl_event_receiver: local class to

  • define and handle own functions.

*

  • Definition:

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

CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

CLASS-METHODS:

handle_toolbar

FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING e_object e_interactive,

handle_menu_button

FOR EVENT menu_button OF cl_gui_alv_grid

IMPORTING e_object e_ucomm,

handle_user_command

FOR EVENT user_command OF cl_gui_alv_grid

IMPORTING e_ucomm.

PRIVATE SECTION.

ENDCLASS.

*

  • lcl_event_receiver (Definition)

*===============================================================

****************************************************************

  • LOCAL CLASSES: Implementation

****************************************************************

*===============================================================

  • class lcl_event_receiver (Implementation)

*

*

CLASS lcl_event_receiver IMPLEMENTATION.

METHOD handle_toolbar.

  • § 2.At event TOOLBAR define a toolbar element of type 1 by using

  • event paramenter E_OBJECT. Remember its function code.

*.......

  • Part I: Define a menu button including a function code that

  • is evaluated in 'handle_MENU_BUTTON

*.......

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

  • append a menu with default button (Type 1)

  • The function code of the default button is the same as

  • the one for the menu.

  • If the user klicks on the default button ALV raises

  • directly event BEFORE_USER_COMMAND

  • (then USER_COMMAND, AFTER_USER_COMMAND).

  • If the user klicks on the menu button ALV raises event MENU_BUTTON.

CLEAR gs_toolbar.

MOVE 'MODIFY' TO gs_toolbar-function.

  • --> This function code is evaluated in 'handle_menu_button'

MOVE icon_change TO gs_toolbar-icon.

MOVE 'Modificar' TO gs_toolbar-quickinfo.

MOVE 0 TO gs_toolbar-butn_type.

MOVE space TO gs_toolbar-disabled.

APPEND gs_toolbar TO e_object->mt_toolbar.

ENDMETHOD.

*----

-


METHOD handle_menu_button.

  • § 3.At event MENU_BUTTON query your function code and define a

  • menu in the same way as a context menu.

*..........

  • Part II: Evaluate 'e_ucomm' to see which menu button of the toolbar

  • has been clicked on.

  • Define then the corresponding menu.

  • The menu contains function codes that are evaluated

  • in 'handle_user_command'.

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

  • query e_ucomm to find out which menu button has been clicked on

IF e_ucomm = 'MODIFY'.

CALL METHOD e_object->add_function

EXPORTING fcode = 'MODIFY'

text = 'Modificar'. "modificar

  • § 3a.) choose a default function and define the same function code

  • as used for the menu.

  • CALL METHOD e_object->add_function

  • EXPORTING fcode = 'DECISION'

  • text = 'Decisión de empleo'. "Decisión

  • "de empleo

*

ENDIF.

ENDMETHOD.

*----

-


METHOD handle_user_command.

  • § 4.At event USER_COMMAND query the function code of each function

  • defined in step 3.

*.........

  • Part III : Evaluate user command to invoke the corresponding

  • function.

*.........

DATA: lt_rows TYPE lvc_t_row.

  • get selected row

CALL METHOD grid1->get_selected_rows

IMPORTING et_index_rows = lt_rows.

CALL METHOD cl_gui_cfw=>flush.

IF sy-subrc NE 0.

  • add your handling, for example

CALL FUNCTION 'POPUP_TO_INFORM'

EXPORTING

titel = repname

txt2 = sy-subrc

txt1 = 'Error in Flush'(500).

ENDIF.

  • go to other table

CASE e_ucomm.

  • WHEN 'DECISION'.

  • REFRESH T_ROWS.

  • PERFORM SELECCION_LINEAS_DECISION TABLES lt_rows.

WHEN 'MODIFY'.

REFRESH t_rows.

  • PERFORM SELECCION_LINEAS_modify TABLES lt_rows.

  • CALL SCREEN 200.

ENDCASE.

ENDMETHOD. "handle_user_command

ENDCLASS.

*

  • lcl_event_receiver (Implementation)

*===================================================================

************************************************************************

*----


*

*----


INITIALIZATION -


*

*----


*

INITIALIZATION.

repname = sy-repid.

PERFORM initialize_fieldcat.

PERFORM initializa_layout.

*----


*

*----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_alv -


*

*----


*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_alvasg.

PERFORM alvl_value_request USING p_alvasg ' '.

*----


*

*----


START-OF-SELECTION -


*

*----


*

START-OF-SELECTION.

PERFORM obtener_datos.

*----


*

*----


END-OF-SELECTION -


*

*----


*

END-OF-SELECTION.

CALL SCREEN 9010.

*----


*

*----


Subrutinas -


*

*----


*

*----


*

  • Form obtener_datos

*----


*

FORM obtener_datos.

REFRESH ti_acred.

CLEAR ti_acred.

SELECT * INTO CORRESPONDING FIELDS OF TABLE ti_acred

FROM lfa1

WHERE lifnr IN lifnr.

LOOP AT ti_acred.

SELECT SINGLE bukrs INTO ti_acred-bukrs FROM lfb1

WHERE lifnr = ti_acred-lifnr.

MODIFY ti_acred.

ENDLOOP.

i_salida[] = ti_acred[].

ENDFORM.

*----


*

  • MODULE PBO OUTPUT *

*----


*

MODULE status_9010 OUTPUT.

DATA it_toolbar_excluding TYPE ui_func.

SET PF-STATUS 'EMPRESA'.

  • CLEAR g_custom_container.

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 = 'I_SALIDA'

is_variant = t_disvariant

i_save = save

  • I_DEFAULT = ' '

is_layout = t_layout

CHANGING it_outtab = i_salida

it_fieldcatalog = t_fieldtab.

SET HANDLER lcl_event_receiver=>handle_user_command

lcl_event_receiver=>handle_menu_button

lcl_event_receiver=>handle_toolbar FOR ALL INSTANCES.

CALL METHOD grid1->set_toolbar_interactive.

ELSE.

CALL METHOD grid1->refresh_table_display.

ENDIF.

ENDMODULE.

*----

-


  • Module EXIT INPUT

*----

-


MODULE exit INPUT.

  • REFRESH i_salida.

  • CLEAR i_salida.

SET SCREEN 0.

LEAVE SCREEN.

ENDMODULE. " EXIT INPUT

*----


*

  • Form initialize_fieldcat

*----


*

FORM initialize_fieldcat.

DATA: l_fieldcat TYPE lvc_t_fcat WITH HEADER LINE.

REFRESH t_fieldtab.

    • Catálogo de Campos

CLEAR l_fieldcat.

l_fieldcat-tabname = 'I_SALIDA'.

l_fieldcat-fix_column = 'X'.

l_fieldcat-no_out = 'O'.

l_fieldcat-key = 'X'.

l_fieldcat-ref_field = 'BUKRS'.

l_fieldcat-ref_table = 'LFB1'.

l_fieldcat-fieldname = 'BUKRS'.

APPEND l_fieldcat TO t_fieldtab.

CLEAR l_fieldcat.

l_fieldcat-tabname = 'I_SALIDA'.

l_fieldcat-fix_column = 'X'.

l_fieldcat-no_out = 'O'.

l_fieldcat-key = 'X'.

l_fieldcat-ref_field = 'LIFNR'.

l_fieldcat-ref_table = 'LFA1'.

l_fieldcat-fieldname = 'LIFNR'.

APPEND l_fieldcat TO t_fieldtab.

CLEAR l_fieldcat.

l_fieldcat-tabname = 'I_SALIDA'.

l_fieldcat-fix_column = 'X'.

l_fieldcat-no_out = 'O'.

  • l_fieldcat-edit = 'X'.

l_fieldcat-ref_field = 'NAME1'.

l_fieldcat-ref_table = 'LFA1'.

l_fieldcat-fieldname = 'NAME1'.

APPEND l_fieldcat TO t_fieldtab.

CLEAR l_fieldcat.

l_fieldcat-tabname = 'I_SALIDA'.

l_fieldcat-fix_column = 'X'.

l_fieldcat-no_out = 'O'.

  • l_fieldcat-edit = 'X'.

l_fieldcat-ref_field = 'LAND1'.

l_fieldcat-ref_table = 'LFA1'.

l_fieldcat-fieldname = 'LAND1'.

APPEND l_fieldcat TO t_fieldtab.

CLEAR l_fieldcat.

l_fieldcat-tabname = 'I_SALIDA'.

l_fieldcat-fix_column = 'X'.

l_fieldcat-no_out = 'O'.

  • l_fieldcat-edit = 'X'.

l_fieldcat-ref_field = 'ORT01'.

l_fieldcat-ref_table = 'LFA1'.

l_fieldcat-fieldname = 'ORT01'.

APPEND l_fieldcat TO t_fieldtab.

CLEAR l_fieldcat.

l_fieldcat-tabname = 'I_SALIDA'.

l_fieldcat-fix_column = 'X'.

l_fieldcat-no_out = 'O'.

  • l_fieldcat-edit = 'X'.

l_fieldcat-ref_field = 'PSTLZ'.

l_fieldcat-ref_table = 'LFA1'.

l_fieldcat-fieldname = 'PSTLZ'.

APPEND l_fieldcat TO t_fieldtab.

CLEAR l_fieldcat.

l_fieldcat-tabname = 'I_SALIDA'.

l_fieldcat-fix_column = 'X'.

l_fieldcat-no_out = 'O'.

  • l_fieldcat-edit = 'X'.

l_fieldcat-ref_field = 'REGIO'.

l_fieldcat-ref_table = 'LFA1'.

l_fieldcat-fieldname = 'REGIO'.

APPEND l_fieldcat TO t_fieldtab.

CLEAR l_fieldcat.

l_fieldcat-tabname = 'I_SALIDA'.

l_fieldcat-fix_column = 'X'.

l_fieldcat-no_out = 'O'.

  • l_fieldcat-edit = 'X'.

l_fieldcat-ref_field = 'SORTL'.

l_fieldcat-ref_table = 'LFA1'.

l_fieldcat-fieldname = 'SORTL'.

APPEND l_fieldcat TO t_fieldtab.

CLEAR l_fieldcat.

l_fieldcat-tabname = 'I_SALIDA'.

l_fieldcat-fix_column = 'X'.

l_fieldcat-no_out = 'O'.

  • l_fieldcat-edit = 'X'.

l_fieldcat-ref_field = 'STRAS'.

l_fieldcat-ref_table = 'LFA1'.

l_fieldcat-fieldname = 'STRAS'.

APPEND l_fieldcat TO t_fieldtab.

CLEAR l_fieldcat.

l_fieldcat-tabname = 'I_SALIDA'.

l_fieldcat-fix_column = 'X'.

l_fieldcat-no_out = 'O'.

l_fieldcat-key = 'X'.

l_fieldcat-ref_field = 'ADRNR'.

l_fieldcat-ref_table = 'LFA1'.

l_fieldcat-fieldname = 'ADRNR'.

APPEND l_fieldcat TO t_fieldtab.

ENDFORM. " initialize_fieldcat

*----


*

  • Form initializa_layout

*----


*

FORM initializa_layout.

t_layout-zebra = 'X'.

t_layout-cwidth_opt = 'X'.

t_layout-no_toolbar = 'X'.

  • T_LAYOUT-EDIT = 'X'.

T_LAYOUT-DETAILINIT = 'X'.

T_LAYOUT-CWIDTH_OPT = 'X'.

T_LAYOUT-TOTALS_BEF = 'X'.

T_LAYOUT-NUMC_TOTAL = 'X'.

ENDFORM. " initializa_layout

*----


*

  • Module USER_COMMAND_9010 INPUT

*----


*

MODULE user_command_9010 INPUT.

CASE sy-ucomm.

WHEN 'SAVE'.

CALL FUNCTION 'POPUP_TO_CONFIRM'

EXPORTING

  • TITLEBAR = ' '

  • DIAGNOSE_OBJECT = ' '

text_question = 'Pulsaste SAVE'

  • TEXT_BUTTON_1 = 'Ja'(001)

  • ICON_BUTTON_1 = ' '

  • TEXT_BUTTON_2 = 'Nein'(002)

  • ICON_BUTTON_2 = ' '

  • DEFAULT_BUTTON = '1'

  • DISPLAY_CANCEL_BUTTON = 'X'

  • USERDEFINED_F1_HELP = ' '

  • START_COLUMN = 25

  • START_ROW = 6

  • POPUP_TYPE =

  • IMPORTING

  • ANSWER =

  • TABLES

  • PARAMETER =

  • EXCEPTIONS

  • TEXT_NOT_FOUND = 1

  • OTHERS = 2

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDCASE.

ENDMODULE. " USER_COMMAND_9010 INPUT

*----


*

  • Form alvl_value_request

*----


*

FORM alvl_value_request USING pi_alv

value(p_0158).

DATA: l_disvariant TYPE disvariant.

  • Wertehilfe

l_disvariant-report = sy-cprog.

  • l_disvariant-report(1) = 'A'.

l_disvariant-variant = pi_alv.

l_disvariant-log_group = p_0158.

CALL FUNCTION 'LVC_VARIANT_SAVE_LOAD'

EXPORTING

i_save_load = 'F'

i_tabname = '1'

CHANGING

cs_variant = l_disvariant

EXCEPTIONS

OTHERS = 1.

IF sy-subrc = 0.

pi_alv = l_disvariant-variant.

ELSE.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " ALVL_VALUE_REQUEST

Regards

Pavan

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question