Friday, May 29, 2026

IDA 9: Add Custom Button in ALV Tool bar

SAP code:

*&---------------------------------------------------------------------*

*& Report ZIDA_PROGRAM

*&---------------------------------------------------------------------*

REPORT zida_program.


DATA: lv_carrid TYPE sflight-carrid.


SELECT-OPTIONS: s_carrid FOR lv_carrid.

PARAMETERS: p_connid TYPE sflight-connid.


CLASS lcl_ida_program DEFINITION.

PUBLIC SECTION.

METHODS display_cds_data.

PROTECTED SECTION.

METHODS button_toolbar FOR EVENT function_selected OF if_salv_gui_toolbar_ida "Define event for Custom Button

IMPORTING ev_fcode.

ENDCLASS.


CLASS lcl_ida_program IMPLEMENTATION.


METHOD display_cds_data.

*&... Get the reference of IDA ALV Object

TRY.

DATA(lo_alv_ida_cds) = cl_salv_gui_table_ida=>create_for_cds_view( iv_cds_view_name = 'DEMO_SFLIGHT' ).

CATCH cx_salv_db_connection INTO FINAL(lx_salv_db_connection).

CATCH cx_salv_db_table_not_supported INTO FINAL(lx_salv_not_supported).

CATCH cx_salv_ida_contract_violation INTO DATA(lx_salv_cont_violation).

CATCH cx_salv_function_not_supported INTO FINAL(lx_salv_fun_not_supported).

ENDTRY.

IF lo_alv_ida_cds IS BOUND.


lo_alv_ida_cds->toolbar( RECEIVING ro_toolbar = DATA(lo_toolbar) ).

TRY.

"Add Custom Button

lo_toolbar->add_button( iv_fcode = 'OK'

iv_icon = '@01@' "Get the ICon code from Report Program: RSTXICON

iv_text = 'Continue'

iv_quickinfo = 'Continue' ).

CATCH cx_salv_ida_gui_fcode_reserved INTO DATA(lx_fcode_reserved).

ENDTRY.


"Register Events

IF lo_toolbar IS BOUND.

SET HANDLER button_toolbar FOR ALL INSTANCES.

ENDIF.


*&... Get the reference of ALV Full Screen mode

TRY.

DATA(lo_fullscreen_cds) = lo_alv_ida_cds->fullscreen( ).

CATCH cx_salv_ida_contract_violation INTO lx_salv_cont_violation. " IDA API contract violated by caller

ENDTRY.


*&... Display data on UI

IF lo_alv_ida_cds IS BOUND.

lo_fullscreen_cds->display( ).

ENDIF.

ENDIF.

ENDMETHOD.


METHOD button_toolbar.

CASE ev_fcode.

WHEN 'OK'.

MESSAGE 'Continue button testing' TYPE 'I'.

ENDCASE.

ENDMETHOD.


ENDCLASS.


START-OF-SELECTION.


DATA(lo_ida_class) = NEW lcl_ida_program( ).

lo_ida_class->display_cds_data( ).


Output:





























Key Concept:



RAP8: Early numbering

In this post will show you how to use early numbering . Step 1: Add early numbering key word in interface behavior definition and activate b...