Application Development 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: 

ALV Refresh toolbar after initial display

Former Member
0 Kudos

I have a custom ALV application where after I've executed the set_table_for_first_display method of my instantiated version of cl_gui_alv_grid, under certain conditions I need to modify the field catalog, the layout and the toolbar. I am able to change the field catalog and layout with methods set_frontend_fieldcatalog and set_frontend_layout accordingly. However, I haven't found a public method in cl_gui_alv_grid to modify the toolbar. I would really prefer not to have to re-execute method set_table_for_first_display just for this purpose. Is there another viable option?

Thanks,

Tony

8 REPLIES 8

Former Member
0 Kudos

Tony,

In reviewing your req, the class has no other options for you. The REFRESH_TABLE_DISPLAY method does reference the toolbar object. However, it does not alter it.

You would need to call SET_TABLE_FOR_FIRST_DISPLAY, in this case.

Why not have all buttons available and then just validate IF the button press is appropriate?

From a Windows screen design standard, appearing and disappearing screen objects is not a recommended practice.

0 Kudos

John,

Thanks for the quick response.

The program does not return to PAI when hitting an ALV grid button hence I cannot intercept and validate.

In my case, I have standard toolbar buttons that provide filtered views of the data originally entered in the grid. I don't like the idea of having to call another program passing in the filtered data just so I can manipulate ALV toolbar buttons.

As far as windows design goes if I can alter things like what fields are visible and/or input capable or even the color of a row, then, I don't see why they wouldn't allow the disabling of some of the grid buttons under certain situations. After all, they do allow it after the first time in and there must be some performance advantage to executing refresh_table display instead of set_table_for_first_display. Other areas of SAP allow appearing and dissappearing of objects on a screen after inital display, i.e display v.s edit modes, and often these things are determined in config. I would hope SAP would consider that for the future. For now, I guess I'll make do.

Thanks,

Tony

0 Kudos

Tony,

"The program does not return to PAI when hitting an ALV grid button hence I cannot intercept and validate."

Correct... standard buttons do not return to the PAI module. However, custom buttons do return to the event handler. You can add custom buttons to meet your reqs and then hide any standard buttons that do not apply.

Former Member
0 Kudos

This method will trigger the event toolbar!

This event need to be handled by an Handler and then modify the toolbar!!!

Thanks in advance for your rewardi!

Stephan

0 Kudos

Stephan,

Thanks for the response. Does set_toolbar_interactive just allow me to intercept the standard ALV button ok_codes in PAI or does it aid in allowing me to disable standard ALV buttons? If it is the later of the two, do you have an example?

0 Kudos

This method will allow you to react to the custom toolbar button actions as far as I know. I don't think you will be able to work on the enbling or disabling the standard buttons using this. But you can use something like this when you are calling


    v_ui_func = '&INFO'.
    append v_ui_func to i_toolbar_excluding.
    v_ui_func = '&VIEW'.
    append v_ui_func to i_toolbar_excluding.
  call method lcl_alvgrid_inv->set_table_for_first_display
    exporting
*       I_BYPASSING_BUFFER            =
*       I_BUFFER_ACTIVE               =
*       I_CONSISTENCY_CHECK           =
*       i_structure_name              = 'RLMMQ'
*       IS_VARIANT                    =
*       I_SAVE                        =
*       I_DEFAULT                     = 'X'
        is_layout                     = ls_layout_inv
*       IS_PRINT                      =
*       IT_SPECIAL_GROUPS             =
        it_toolbar_excluding          = i_toolbar_excluding <b><--</b>
*       IT_HYPERLINK                  =
*       IT_ALV_GRAPHICS               =
    changing
        it_outtab                     = <itab>
        it_fieldcatalog               = i_fieldcat_inv
*       IT_SORT                       =
*       IT_FILTER                     =
    exceptions
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        others                        = 4.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
          with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

0 Kudos

Tony,

Create a new program Zsandbox_prog and then create a screen 100 for it with a custom container called W1 on it.

Add this code to the program.

REPORT Zsandbox_prog .

TYPE-POOLS: SYDES.

TABLES: DD04L, DD04T.

data: begin of P1 occurs 0.

include structure vbak.

data: end of P1.

DATA: GRID1 TYPE REF TO CL_GUI_ALV_GRID.

data: tb_exclude type ui_functions.

data: W1 TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

DATA: GT_FIELDCAT1 TYPE LVC_T_FCAT.

data: gt_fieldcat type lvc_t_fcat.

INCLUDE <icon>.

DATA: ok_code LIKE sy-ucomm,

gs_toolbar TYPE stb_button.

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

  • LOCAL CLASSES: Definition

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

CLASS lcl_event_receiver_g1 DEFINITION.

PUBLIC SECTION.

CLASS-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,

HANDLE_DOUBLE_CLICK

FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID

IMPORTING E_ROW E_COLUMN.

PRIVATE SECTION.

ENDCLASS.

CLASS lcl_event_receiver_g1 IMPLEMENTATION.

METHOD handle_toolbar.

  • This code adds custom toolbar button on the ALV grids.

  • In particular, it adds the ADD, DELETE, CHG, and REFRESH buttons.

*

  • append a separator to normal toolbar

CLEAR gs_toolbar.

MOVE 3 TO gs_toolbar-butn_type.

APPEND gs_toolbar TO e_object->mt_toolbar.

  • Add 'ADD' button to the ALV grid.

CLEAR gs_toolbar.

MOVE 'ADD' TO gs_toolbar-function.

move ' Add Co-op' to gs_toolbar-TEXT.

MOVE ICON_INSERT_MULTIPLE_LINES TO gs_toolbar-icon.

MOVE 'Add a co-op'(200) 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.

  • append a separator to normal toolbar

CLEAR gs_toolbar.

MOVE 3 TO gs_toolbar-butn_type.

APPEND gs_toolbar TO e_object->mt_toolbar.

  • Add 'CHG' button to the ALV grid.

CLEAR gs_toolbar.

MOVE 'CHG' TO gs_toolbar-function.

move ' Change Co-op' to gs_toolbar-TEXT.

MOVE ICON_change TO gs_toolbar-icon.

MOVE 'Change a co-op'(200) 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.

  • append a separator to normal toolbar

CLEAR gs_toolbar.

MOVE 3 TO gs_toolbar-butn_type.

APPEND gs_toolbar TO e_object->mt_toolbar.

  • Add DELETE button to the ALV grid.

CLEAR gs_toolbar.

MOVE 'DELETE' TO gs_toolbar-function.

move ' Delete Co-op' to gs_toolbar-TEXT.

MOVE ICON_delete TO gs_toolbar-icon.

MOVE 'Delete co-op(s)'(200) 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.

  • append a separator to normal toolbar

CLEAR gs_toolbar.

MOVE 3 TO gs_toolbar-butn_type.

APPEND gs_toolbar TO e_object->mt_toolbar.

  • Add a REFRESH button.

CLEAR gs_toolbar.

MOVE 'REFR' TO gs_toolbar-function.

move '' to gs_toolbar-TEXT.

MOVE ICON_refresh TO gs_toolbar-icon.

MOVE 'Refresh the grid' 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_user_command.

CASE e_ucomm.

when 'ADD'.

message i000(zz) with 'Add button was pressed.'.

WHEN 'CHG'.

message i000(zz) with 'Change button was pressed.'.

endcase.

ENDMETHOD. "handle_user_command

METHOD handle_double_click.

ENDMETHOD. "HANDLE_DOUBLE_CLICK

ENDCLASS.

start-of-selection.

call screen '0100'.

FORM Prepare_FieldCats .

if w1 is initial.

clear gt_fieldcat.

Perform Build_FieldCats TABLES P1.

gt_fieldcat1[] = gt_fieldcat[].

endif.

endform.

Form Build_Grids.

DATA: GS_LAYOUT TYPE LVC_S_LAYO,

GS_VARIANT TYPE DISVARIANT.

DATA: X_SAVE VALUE 'X'. "for Parameter I_SAVE

gs_layout-zebra = 'X'.

gs_layout-NO_ROWMARK = ' '.

MOVE sy-repid TO gs_variant-report.

CALL FUNCTION 'LVC_VARIANT_DEFAULT_GET'

EXPORTING

i_save = x_save

CHANGING

cs_variant = gs_variant

EXCEPTIONS

WRONG_INPUT = 1

NOT_FOUND = 2

PROGRAM_ERROR = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

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

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

ENDIF.

Perform Build_Exclude_Toolbar_Table .

  • Build Grid1.

CREATE OBJECT w1

EXPORTING container_name = 'W1'.

CREATE OBJECT grid1

EXPORTING i_parent = w1.

gs_layout-grid_title = 'Period 1'.

  • Set the event handlers for the ALV grid1.

SET HANDLER lcl_event_receiver_g1=>handle_user_command

lcl_event_receiver_g1=>handle_toolbar

lcl_event_receiver_g1=>handle_double_click for grid1.

CALL METHOD grid1->set_table_for_first_display

EXPORTING is_variant = gs_variant

i_save = x_save

is_layout = gs_layout

it_toolbar_excluding = tb_exclude

CHANGING it_fieldcatalog = gt_fieldcat1

it_outtab = p1[].

EndForm.

FORM Build_Exclude_Toolbar_Table .

  • delete menu buttons

refresh tb_exclude.

APPEND CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW

TO tb_exclude.

APPEND CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW

TO tb_exclude.

APPEND CL_GUI_ALV_GRID=>MC_FC_LOC_COPY

TO tb_exclude.

APPEND CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW

TO tb_exclude.

APPEND CL_GUI_ALV_GRID=>MC_FC_LOC_CUT

TO tb_exclude.

APPEND CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW

TO tb_exclude.

APPEND CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW

TO tb_exclude.

EndForm.

FORM Build_FieldCats TABLES itab_layout.

DATA: field_name(60) TYPE c,

descr_ref TYPE REF TO cl_abap_typedescr.

DATA: td TYPE sydes_desc,

typeinfo TYPE sydes_typeinfo,

nameinfo TYPE sydes_nameinfo.

DATA: ls_fieldcat TYPE lvc_s_fcat.

DATA: hlp(30) TYPE c.

FIELD-SYMBOLS: <field>.

refresh gt_fieldcat.

  • Initializes the name of the columns

DESCRIBE FIELD itab_layout INTO td.

DELETE td-types INDEX 1.

  • Creates the internal table with field definition

DO.

ASSIGN COMPONENT sy-index OF STRUCTURE itab_layout TO <field>.

IF sy-subrc <> 0. EXIT. ENDIF.

CLEAR ls_fieldcat.

descr_ref = cl_abap_typedescr=>describe_by_data( <field> ).

dd04l-rollname = descr_ref->absolute_name+6(15).

SELECT SINGLE *

FROM dd04l

WHERE rollname = dd04l-rollname.

IF sy-subrc = 0.

SELECT SINGLE *

FROM dd04t

WHERE rollname = dd04l-rollname

AND ddlanguage = sy-langu

AND as4vers = dd04l-as4vers

AND as4local = dd04l-as4local.

READ TABLE td-types INDEX sy-index INTO typeinfo.

READ TABLE td-names INDEX typeinfo-idx_name INTO nameinfo.

ls_fieldcat-coltext = dd04t-SCRTEXT_M. "dd04t-reptext.

ELSE.

READ TABLE td-types INDEX sy-index INTO typeinfo.

READ TABLE td-names INDEX typeinfo-idx_name INTO nameinfo.

ls_fieldcat-coltext = nameinfo-name.

ENDIF.

DESCRIBE FIELD <field> HELP-ID hlp.

IF NOT hlp IS INITIAL.

IF hlp CS '-'.

ls_fieldcat-ref_field = hlp+sy-fdpos(15).

ls_fieldcat-ref_field = ls_fieldcat-ref_field+1(15).

ls_fieldcat-ref_table = hlp+0(sy-fdpos).

ENDIF.

ENDIF.

ls_fieldcat-fieldname = nameinfo-name.

ls_fieldcat-inttype = descr_ref->type_kind.

if ls_fieldcat-inttype = 's'. " SAP ALV func module does not

ls_fieldcat-inttype = 'N'. " handle INT1,INT2,INT4 types

endif. " correctly in 4.6

ls_fieldcat-outputlen = descr_ref->length.

ls_fieldcat-decimals = descr_ref->decimals.

APPEND ls_fieldcat to gt_fieldcat.

  • ADD 1 TO n.

ENDDO.

ENDFORM. " Build_FieldCats

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

select * up to 50 rows from vbak into table P1.

Perform Prepare_FieldCats.

Perform Build_Grids.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

ENDMODULE. " USER_COMMAND_0100 INPUT

0 Kudos

John,

I hit a couple syntax errors that'll I'll work through tomorrow but, I just wanted to say thanks in advance. I greatly appreciate the help and I'll respond with the results as soon as possible.

Thanks again,

Tony