0% found this document useful (0 votes)
176 views10 pages

Sap Alv-Ida

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
176 views10 pages

Sap Alv-Ida

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

SAP ALV-IDA

The Major class used in SAP IDA is below


1. 1.Cl_salv_gui_table_ida=>create_for_cds_view.
2. cl_salv_gui_table_ida=>create

Simple ALV:
Source Code:
*&---------------------------------------------------------------------*
*& Report zalv_ida_01
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zalv_ida_01 NO STANDARD PAGE HEADING.
INCLUDE:zalv_ida_top,
zalv_ida_class.
*&---------------------------------------------------------------------*
*&Initialization
*&---------------------------------------------------------------------*
INITIALIZATION.
DATA(lo_alv) = NEW lcl_ida( ).
*&---------------------------------------------------------------------*
*&Start of selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.
lo_alv->alv_ida_display(
EXPORTING
view = 'KNA1'
).
*&---------------------------------------------------------------------*
*& Include ZALV_IDA_CLASS
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&Local Call Definitation
*&---------------------------------------------------------------------*
CLASS lcl_ida DEFINITION.
PUBLIC SECTION.
"Constants decleartions
CONSTANTS:c_kunnr TYPE if_salv_gui_types_ida=>y_field_name VALUE 'KUNNR',
c_name1 TYPE if_salv_gui_types_ida=>y_field_name VALUE 'NAME1',
c_land1 TYPE if_salv_gui_types_ida=>y_field_name VALUE 'LAND1',
c_kunnr_no TYPE if_salv_gui_types_ida=>y_header_text VALUE 'Customer No',
c_customer_name TYPE if_salv_gui_types_ida=>y_header_text VALUE 'Customer Name',
c_country TYPE if_salv_gui_types_ida=>y_header_text VALUE 'Country',
c_title TYPE sytitle VALUE 'Customer Report'.
"Decleration
DATA:lo_ro_gui_table TYPE REF TO if_salv_gui_table_ida,
lo_ass_invalid TYPE REF TO cx_salv_ida_associate_invalid,
lo_db_connect TYPE REF TO cx_salv_db_connection,
lo_ida_con_invalid TYPE REF TO cx_salv_ida_condition_invalid,
lo_unknown_name TYPE REF TO cx_salv_ida_unknown_name.
"Methods
METHODS:alv_ida_display IMPORTING view TYPE dbtabl,
field_lable IMPORTING field_name TYPE if_salv_gui_types_ida=>y_field_name
field_text TYPE if_salv_gui_types_ida=>y_header_text
CHANGING if_table_ida TYPE REF TO if_salv_gui_table_ida OPTIONAL,
field_cat,
select_options IMPORTING name TYPE string
it TYPE ANY TABLE
EXPORTING it_select TYPE if_salv_service_types=>yt_named_ranges,
parameter IMPORTING fieldname TYPE fieldname
value TYPE data
EXPORTING ls_condition TYPE REF TO if_salv_ida_condition,
select_parameter IMPORTING it_select TYPE if_salv_service_types=>yt_named_ranges
ls_condition TYPE REF TO if_salv_ida_condition,
handle_fcode FOR EVENT function_selected OF if_salv_gui_toolbar_ida IMPORTING ev_fcode.
ENDCLASS.

*&---------------------------------------------------------------------*
*&Local Call Implementation
*&---------------------------------------------------------------------*
CLASS lcl_ida IMPLEMENTATION.
METHOD alv_ida_display.
TRY.
cl_salv_gui_table_ida=>create(
EXPORTING
iv_table_name = view " Name of table for database access
RECEIVING
ro_alv_gui_table_ida = lo_ro_gui_table " ALV with integrated data access (IDA)
).
CATCH cx_salv_db_connection INTO DATA(lo_db_conn).
MESSAGE lo_db_conn->if_message~get_text( ) TYPE 'E'.
CATCH cx_salv_db_table_not_supported INTO DATA(lo_table_not_supported).
MESSAGE lo_table_not_supported->if_message~get_text( ) TYPE 'E'.
CATCH cx_salv_ida_contract_violation INTO DATA(lo_ida_contract_violation).
MESSAGE lo_ida_contract_violation->if_message~get_text( ) TYPE 'E'.
ENDTRY.
IF lo_ro_gui_table IS BOUND.
TRY.
lo_ro_gui_table->fullscreen( RECEIVING ro_fullscreen = DATA(lo_fullscreen) ).
CATCH cx_salv_ida_contract_violation INTO lo_ida_contract_violation.
MESSAGE lo_ida_contract_violation->if_message~get_text( ) TYPE 'E'.
ENDTRY.
"select-option
me->select_options(
EXPORTING
name = 'KUNNR'
it = s_kunnr[]
IMPORTING
it_select = DATA(it_select)
).
"Parameters
me->parameter(
EXPORTING
fieldname = 'LAND1'
value = p_land1
IMPORTING
ls_condition = DATA(ls_condition)
).
"Select-parameter
me->select_parameter(
EXPORTING
it_select = it_select
ls_condition = ls_condition
).

"Field catalog
me->field_cat( ).
"ALV Reprot title
lo_ro_gui_table->display_options( RECEIVING ro_display_options = DATA(lo_display_options) ).
lo_display_options->set_title( iv_title = c_title ).
"Enable alternate row pattern
lo_display_options->enable_alternating_row_pattern( ).
"Enable alternate row pattern
lo_display_options->enable_alternating_row_pattern( ).
"Disable perticular tool bar
lo_ro_gui_table->standard_functions( )->set_export_active( iv_active = abap_false ).
lo_ro_gui_table->standard_functions( )->set_print_active( iv_active = abap_false ).
lo_ro_gui_table->standard_functions( )->set_filter_active( iv_active = abap_false ).
lo_ro_gui_table->standard_functions( )->set_sort_active( iv_active = abap_false ).
"Enable perticualr tool bar
lo_ro_gui_table->standard_functions( )->set_export_active( iv_active = abap_true ).
lo_ro_gui_table->standard_functions( )->set_print_active( iv_active = abap_true ).
lo_ro_gui_table->standard_functions( )->set_filter_active( iv_active = abap_true ).
lo_ro_gui_table->standard_functions( )->set_sort_active( iv_active = abap_true ).
"To Hide standard tool bar
lo_ro_gui_table->toolbar( )->hide_all_standard_functions( ).
lo_ro_gui_table->toolbar( )->enable_listbox_for_layouts( ).
"To Add Custom button
"Program ID to find icon number RSTXICON
TRY.
lo_ro_gui_table->toolbar( )->add_button(
EXPORTING
iv_fcode = 'EMAIL'
iv_icon = '@1S@' " Name of an Icon
iv_text = 'Email'
* iv_quickinfo =
* iv_is_checked =
* iv_before_standard_functions = abap_false
).
CATCH cx_salv_ida_gui_fcode_reserved INTO DATA(lo_fcode_reserved).
MESSAGE lo_fcode_reserved->if_message~get_text( ) TYPE 'E'.
ENDTRY.
SET HANDLER me->handle_fcode FOR ALL INSTANCES.
"To Disable some perticular functionality
TRY.
lo_ro_gui_table->field_catalog( )->disable_sort( iv_field_name = 'KUNNR' ).
CATCH cx_salv_ida_unknown_name INTO DATA(lo_ida_unknow_name).
MESSAGE lo_ida_unknow_name->if_message~get_text( ) TYPE 'E'.
CATCH cx_salv_call_after_1st_display INTO DATA(lo_after_1st_dispaly).
MESSAGE lo_after_1st_dispaly->if_message~get_text( ) TYPE 'E'.
ENDTRY.
ENDIF.

"Display
IF lo_fullscreen IS BOUND.
lo_fullscreen->display( ).
ENDIF.
ENDMETHOD.
METHOD field_lable.
TRY.
if_table_ida->field_catalog( )->set_field_header_texts(
EXPORTING
iv_field_name = field_name
iv_header_text = field_text
).
CATCH cx_salv_ida_unknown_name INTO DATA(lo_ida_unknow_name).
MESSAGE lo_ida_unknow_name->if_message~get_text( ) TYPE 'E'.
CATCH cx_salv_call_after_1st_display INTO DATA(lo_after_1st_dispaly).
MESSAGE lo_after_1st_dispaly->if_message~get_text( ) TYPE 'E'.
ENDTRY.
ENDMETHOD.
METHOD field_cat.
me->field_lable(
EXPORTING
field_name = c_kunnr
field_text = c_kunnr_no
CHANGING
if_table_ida = lo_ro_gui_table
).
me->field_lable(
EXPORTING
field_name = c_name1
field_text = c_customer_name
CHANGING
if_table_ida = lo_ro_gui_table
).
me->field_lable(
EXPORTING
field_name = c_land1
field_text = c_country
CHANGING
if_table_ida = lo_ro_gui_table
).
ENDMETHOD.

METHOD select_options.
DATA(lo_select) = NEW cl_salv_range_tab_collector( ).
lo_select->add_ranges_for_name(
EXPORTING
iv_name = name
it_ranges = it
).
lo_select->get_collected_ranges(
IMPORTING
et_named_ranges = it_select
).
ENDMETHOD.
METHOD parameter.
TRY.
lo_ro_gui_table->condition_factory( )->equals(
EXPORTING
name = fieldname
value = value
RECEIVING
ro_condition = ls_condition
).
CATCH cx_salv_ida_unknown_name INTO lo_unknown_name.
MESSAGE lo_unknown_name->if_message~get_text( ) TYPE 'E'.
ENDTRY.
ENDMETHOD.
METHOD select_parameter.
TRY.
lo_ro_gui_table->set_select_options(
EXPORTING
it_ranges = it_select
io_condition = ls_condition
).
CATCH cx_salv_ida_associate_invalid INTO lo_ass_invalid.
MESSAGE lo_ass_invalid->if_message~get_text( ) TYPE 'E'.
CATCH cx_salv_db_connection INTO lo_db_connect.
MESSAGE lo_db_connect->if_message~get_text( ) TYPE 'E'.
CATCH cx_salv_ida_condition_invalid INTO lo_ida_con_invalid.
MESSAGE lo_ida_con_invalid->if_message~get_text( ) TYPE 'E'.
CATCH cx_salv_ida_unknown_name INTO lo_unknown_name
MESSAGE lo_unknown_name->if_message~get_text( ) TYPE 'E'.
ENDTRY.
ENDMETHOD.

METHOD handle_fcode.
CASE ev_fcode.
WHEN 'EMAIL'.
MESSAGE 'Email Sent' TYPE 'I' DISPLAY LIKE 'S'.
ENDCASE.
ENDMETHOD.
ENDCLASS.

Interactive ALV:
Source Code:
*&---------------------------------------------------------------------*
*& Report zalv_ida_02
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zalv_ida_02 NO STANDARD PAGE HEADING.
INCLUDE:zalv_ida_02_top,
zalv_ida_02_class.
*&---------------------------------------------------------------------*
*&Initialization
*&---------------------------------------------------------------------*
INITIALIZATION.
DATA(lo_alv) = NEW lcl_ida( ).
*&---------------------------------------------------------------------*
*&Start-of-Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.
CONSTANTS c_view TYPE dbtabl VALUE 'ZDDLs_SAMPLE_01' .
lo_alv->alv_ida_display(
EXPORTING
view = 'ZDDLs_SAMPLE_01'
).
*&---------------------------------------------------------------------*
*& Include ZALV_IDA_02_CLASS
*&---------------------------------------------------------------------*
CLASS lcl_ida DEFINITION.
PUBLIC SECTION.
"Constants
CONSTANTS:c_kunnr TYPE if_salv_gui_types_ida=>y_field_name VALUE 'CUSTOMERNO',
c_name1 TYPE if_salv_gui_types_ida=>y_field_name VALUE 'CUSTOMER_NAME',
c_land1 TYPE if_salv_gui_types_ida=>y_field_name VALUE 'CUSTOMER_COUNTRY',
c_kunnr_no TYPE if_salv_gui_types_ida=>y_header_text VALUE 'Customer No',
c_customer_name TYPE if_salv_gui_types_ida=>y_header_text VALUE 'Customer Name',
c_country TYPE if_salv_gui_types_ida=>y_header_text VALUE 'Country'.
DATA:lo_ro_gui_table TYPE REF TO if_salv_gui_table_ida.
"Methods
METHODS:alv_ida_display IMPORTING view TYPE dbtabl,
field_lable IMPORTING field_name TYPE if_salv_gui_types_ida=>y_field_name
field_text TYPE if_salv_gui_types_ida=>y_header_text
CHANGING if_table_ida TYPE REF TO if_salv_gui_table_ida OPTIONAL,
field_cat,
select IMPORTING iv_name TYPE string
it_ranges TYPE ANY TABLE
EXPORTING it TYPE if_salv_service_types=>yt_named_ranges,
select_parameter IMPORTING it TYPE if_salv_service_types=>yt_named_ranges,
handle_double_click FOR EVENT double_click OF if_salv_gui_table_display_opt IMPORTING
ev_field_name eo_row_data.
ENDCLASS.
CLASS lcl_ida IMPLEMENTATION.
METHOD alv_ida_display.
TRY.
cl_salv_gui_table_ida=>create_for_cds_view(
EXPORTING
iv_cds_view_name = view
RECEIVING
ro_alv_gui_table_ida = lo_ro_gui_table
).
CATCH cx_salv_db_connection INTO DATA(lo_db_conn).
MESSAGE lo_db_conn->if_message~get_text( ) TYPE 'E'.
CATCH cx_salv_db_table_not_supported INTO DATA(lo_table_not_supported).
MESSAGE lo_table_not_supported->if_message~get_text( ) TYPE 'E'.
CATCH cx_salv_ida_contract_violation INTO DATA(lo_ida_contract_violation).
MESSAGE lo_ida_contract_violation->if_message~get_text( ) TYPE 'E'.
CATCH cx_salv_function_not_supported INTO DATA(lo_fun_not_support).
MESSAGE lo_fun_not_support->if_message~get_text( ) TYPE 'E'.
ENDTRY.
TRY.
lo_ro_gui_table->fullscreen( RECEIVING ro_fullscreen = DATA(lo_fullscreen) ).
CATCH cx_salv_ida_contract_violation INTO lo_ida_contract_violation.
MESSAGE lo_ida_contract_violation->if_message~get_text( ) TYPE 'E'.
ENDTRY.
"Select Option
me->select(
EXPORTING
iv_name = 'CUSTOMERNO'
it_ranges = s_kunnr[]
IMPORTING
it = DATA(it)
).
me->select_parameter( it = it ).
"Field catalog
me->field_cat( ).
"Enable alternate row pattern
lo_ro_gui_table->display_options( )->enable_alternating_row_pattern( ).
"Double click
lo_ro_gui_table->display_options( )->enable_double_click( ).
SET HANDLER me->handle_double_click FOR ALL INSTANCES.
"Display
lo_fullscreen->display( ).
ENDMETHOD.
METHOD field_lable.
TRY.
if_table_ida->field_catalog( RECEIVING ro_field_catalog = DATA(lo_field_cat) ).
lo_field_cat->set_field_header_texts(
EXPORTING
iv_field_name = field_name
iv_header_text = field_text
).
CATCH cx_salv_ida_unknown_name INTO DATA(lo_ida_unknow_name).
MESSAGE lo_ida_unknow_name->if_message~get_text( ) TYPE 'E'.
CATCH cx_salv_call_after_1st_display INTO DATA(lo_after_1st_dispaly).
MESSAGE lo_after_1st_dispaly->if_message~get_text( ) TYPE 'E'.
ENDTRY.
ENDMETHOD.
METHOD field_cat.
me->field_lable(
EXPORTING
field_name = c_kunnr
field_text = c_kunnr_no
CHANGING
if_table_ida = lo_ro_gui_table
).
me->field_lable(
EXPORTING
field_name = c_name1
field_text = c_customer_name
CHANGING
if_table_ida = lo_ro_gui_table
).
me->field_lable(
EXPORTING
field_name = c_land1
field_text = c_country
CHANGING
if_table_ida = lo_ro_gui_table
).
ENDMETHOD.
METHOD select.
DATA(lo_select) = NEW cl_salv_range_tab_collector( ).
lo_select->add_ranges_for_name(
EXPORTING
iv_name = iv_name
it_ranges = it_ranges ).
lo_select->get_collected_ranges(
IMPORTING
et_named_ranges = it
).

ENDMETHOD.
METHOD select_parameter.
TRY.
lo_ro_gui_table->set_select_options(
EXPORTING
it_ranges = it
* io_condition =
).
CATCH cx_salv_ida_associate_invalid INTO DATA(lo_ida_associate_invalid).
MESSAGE lo_ida_associate_invalid->if_message~get_text( ) TYPE 'E'.
CATCH cx_salv_db_connection INTO DATA(lo_db_connection).
MESSAGE lo_db_connection->if_message~get_text( ) TYPE 'E'.
CATCH cx_salv_ida_condition_invalid INTO DATA(lo_ida_condition_invalid).
MESSAGE lo_ida_condition_invalid->if_message~get_text( ) TYPE 'E'.
CATCH cx_salv_ida_unknown_name INTO DATA(lo_ida_unknown_name.
MESSAGE lo_ida_unknown_name->if_message~get_text( ) TYPE 'E'.
ENDTRY.
ENDMETHOD.
METHOD handle_double_click.
DATA:ls_kna1 TYPE zddls_sample_01.
CASE ev_field_name.
WHEN 'CUSTOMERNO'.
TRY.
eo_row_data->get_row_data(
* EXPORTING
* iv_request_type =
* its_requested_fields =
IMPORTING
es_row = ls_kna1
).
CATCH cx_salv_ida_contract_violation. " IDA API contract violated by caller
CATCH cx_salv_ida_sel_row_deleted. " Selected Row at UI does no longer exist
CATCH cx_salv_ida_no_selection_at_ui. " No selected row at UI available
CATCH cx_salv_ida_contract_violation. " IDA API contract violated by caller
ENDTRY.
SET PARAMETER ID 'KUN' FIELD ls_kna1-customerno.
CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.

ENDCASE.
ENDMETHOD.
ENDCLASS.

You might also like