ALV WITH IDA 是一个可以调用外部视图展示的ALV,其功能也比ALV强大很多,复杂很多。
数据准备:创建一个外部视图
至于创建外部视图的方法,需要参考一些其它材料,这里就不再详细介绍了,主要还是看一下ALV WITH IDA的实例
*&---------------------------------------------------------------------*
*& Report Z_ZHANGM_010
*&---------------------------------------------------------------------*
*&描述:ALV WITH IDA
*&---------------------------------------------------------------------*
REPORT z_zhangm_010.
DATA: lo_alv_ida TYPE REF TO if_salv_gui_table_ida.
DATA: lt_excluding_fcode TYPE if_salv_gui_types_ida=>yt_excluding_fcode.
DATA: lt_para TYPE if_salv_gui_types_ida=>yt_parameter,
ls_para LIKE LINE OF lt_para.
DATA: lt_range TYPE if_salv_service_types=>yt_named_ranges,
ls_range LIKE LINE OF lt_range,
lo_cond TYPE REF TO if_salv_ida_condition,
lo_condition_factory TYPE REF TO if_salv_ida_condition_factory.
*
*PARAMETERS: P_PERIOD(6).
INITIALIZATION.
CLASS lcl_alv_fullscreen DEFINITION.
PUBLIC SECTION.
INTERFACES if_salv_ida_calc_field_handler . "增加字段接口
METHODS status_function_selected "--------------------------------------------按钮响应
FOR EVENT function_selected OF if_salv_gui_fullscreen_ida
IMPORTING ev_fcode.
METHODS cell_action "--------------------------------------------字段响应
FOR EVENT cell_action OF if_salv_gui_field_display_opt
IMPORTING ev_field_name eo_row_data.
METHODS double_click "---------------------------------------------双击响应
FOR EVENT double_click OF if_salv_gui_table_display_opt
IMPORTING ev_field_name eo_row_data.
PRIVATE SECTION.
TYPES:
BEGIN OF ys_calc_field, "附加字段
add_field TYPE char10,
icon TYPE c LENGTH 4,
button TYPE lvc_value, "c length 4,
END OF ys_calc_field .
CONSTANTS mc_flag_fcode TYPE ui_func VALUE 'DO_NOTHING'.
ENDCLASS.
CLASS lcl_alv_fullscreen IMPLEMENTATION.
METHOD cell_action.
* display field name of clicked field and line content for all fields
* get clicked line line
TYPES: BEGIN OF lty_line.
INCLUDE TYPE zv_calcu_08.
INCLUDE TYPE ys_calc_field.
TYPES: END OF lty_line.
DATA: ls_wa TYPE lty_line.
eo_row_data->get_row_data( EXPORTING iv_request_type = if_salv_gui_selection_ida=>cs_request_type-all_fields
IMPORTING es_row = ls_wa ).
cl_salv_ida_show_data_row=>display( iv_text = 'CellActionEvent for field:'(001) && ` ` && ev_field_name
is_data = ls_wa ).
ENDMETHOD.
METHOD double_click.
* display field name of double-clicked field and line content for all fields
* get double-clicked line and put into output
DATA: ls_wa TYPE zv_calcu_08.
eo_row_data->get_row_data( EXPORTING iv_request_type = if_salv_gui_selection_ida=>cs_request_type-all_fields
IMPORTING es_row = ls_wa ).
cl_salv_ida_show_data_row=>display( iv_text = 'DoubleClickEvent for field'(002) && ` ` && ev_field_name
is_data = ls_wa ).
ENDMETHOD.
METHOD status_function_selected.
CASE ev_fcode.
WHEN mc_flag_fcode.
MESSAGE i000(0k) WITH 'Own Status Item selected:'(003) ev_fcode.
WHEN 'F03' OR 'F12' OR 'F15'.
lo_alv_ida->fullscreen( )->exit( ).
ENDCASE.
ENDMETHOD.
METHOD if_salv_ida_calc_field_handler~calculate_line.
DATA ls_calc_field TYPE ys_calc_field.
DATA ls_calcu TYPE zv_calcu_08.
ls_calcu = is_data_base_line.
IF ls_calcu-zyar = '2016'.
ls_calc_field-add_field = 'XX'.
ENDIF.
ls_calc_field-icon = icon_yellow_light.
ls_calc_field-button = '@02@'.
es_calculated_fields = ls_calc_field.
ENDMETHOD.
METHOD if_salv_ida_calc_field_handler~get_calc_field_structure.
* define additional fields by returning the structure description
DATA ls_calc_field TYPE ys_calc_field.
ro_calc_field_structure ?= cl_abap_structdescr=>describe_by_data( ls_calc_field ).
ENDMETHOD.
METHOD if_salv_ida_calc_field_handler~get_requested_fields.
ENDMETHOD.
METHOD if_salv_ida_calc_field_handler~start_page.
* buffer which of the calculated fields are displayed
* --> later calculate values only for these fields to save performance
* mt_calc_field_name = its_calc_field_name.
ENDMETHOD.
METHOD if_salv_ida_calc_field_handler~end_page.
" do nothing.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA: lo_calc_field_handler TYPE REF TO lcl_alv_fullscreen.
CREATE OBJECT lo_calc_field_handler.
lo_alv_ida = cl_salv_gui_table_ida=>create( iv_table_name = 'ZV_CALCU_08'
io_calc_field_handler = lo_calc_field_handler ).
"条纹
lo_alv_ida->display_options( )->enable_alternating_row_pattern( ).
***--------------------------------GUI 状态-------------------------------------begin
lo_alv_ida->fullscreen( )->set_pf_status(
iv_pf_status_name = 'STATUS_010'
iv_program_name = 'Z_ZHANGM_010'
it_excluding_fcode = lt_excluding_fcode
).
SET HANDLER lo_calc_field_handler->status_function_selected FOR lo_alv_ida->fullscreen( ).
***--------------------------------GUI 状态-------------------------------------end
TRY.
CALL METHOD lo_alv_ida->set_select_options
EXPORTING
it_ranges = lt_range
io_condition = lo_cond.
CATCH cx_salv_ida_associate_invalid .
CATCH cx_salv_db_connection .
CATCH cx_salv_ida_condition_invalid .
CATCH cx_salv_ida_unknown_name .
ENDTRY.
***------------------混合的条件-------------------------end
***------------------抬头标题---------------------------begin
lo_alv_ida->field_catalog( )->set_field_header_texts(
iv_field_name = 'ZQCKC'
iv_header_text = '期初库存'
iv_tooltip_text = '期初库存'
iv_tooltip_text_long = 'Goods Receive Quanity'
) .
lo_alv_ida->field_catalog( )->set_field_header_texts(
iv_field_name = 'ZQMKC'
iv_header_text = '期末库存'
iv_tooltip_text = '期末库存'
iv_tooltip_text_long = ''
) .
lo_alv_ida->field_catalog( )->set_field_header_texts(
iv_field_name = 'ZBUDAT'
iv_header_text = '日期'
iv_tooltip_text = '日期'
iv_tooltip_text_long = ''
) .
lo_alv_ida->field_catalog( )->set_data_element( iv_field_name = 'MATNR'
iv_data_element_name = 'MATNR' ).
***------------------抬头标题---------------------------end
***---------------------------------------------排除字段------------------------------------------begin
* LO_ALV_IDA->FIELD_CATALOG( )->GET_ALL_FIELDS( IMPORTING ETS_FIELD_NAMES = DATA(LTS_FIELD_NAMES) ).
* DELETE LTS_FIELD_NAMES WHERE TABLE_LINE = 'WERKS'.
* LO_ALV_IDA->FIELD_CATALOG( )->SET_AVAILABLE_FIELDS( LTS_FIELD_NAMES ).
***---------------------------------------------排除字段------------------------------------------end
LO_ALV_IDA->SET_MAXIMUM_NUMBER_OF_ROWS( 100 ). "限制行数
***------------------------------------------------------------权限检查-----------------------------------------------------------begin
* DATA(LO_AUTHORIZATION_PROVIDER) = CL_SADL_COND_PROV_FACTORY_PUB=>CREATE_FOR_AUTHORIZATION( ).
* LO_AUTHORIZATION_PROVIDER->ADD_AUTHORIZATION_FOR_OBJECT( IV_AUTHORIZATION_OBJECT = 'M_BEST_WRK'
* IT_ACTIVITIES = VALUE #( ( AUTH_FIELD = 'ACTVT' VALUE = '03' ) )
* IT_FIELD_MAPPING = VALUE #( ( AUTH_FIELD = 'WERKS' VIEW_FIELD = 'WERKS' ) ) ).
****------------------------------------------------------------权限检查-----------------------------------------------------------end
TRY.
DATA: lts_icon_tooltip TYPE if_salv_gui_types_ida=>yts_icon_tooltip.
INSERT VALUE #( icon = icon_yellow_light
tooltip = 'Less than 10 seats free!'(004) ) INTO TABLE lts_icon_tooltip. "#EC NOTEXT
INSERT VALUE #( icon = icon_green_light
tooltip = 'Enough seats free...'(005) ) INTO TABLE lts_icon_tooltip. "#EC NOTEXT
INSERT VALUE #( icon = icon_red_light
tooltip = 'Sorry, no seats free anymore...'(006) ) INTO TABLE lts_icon_tooltip.
lo_alv_ida->field_catalog( )->display_options( )->set_tooltip_for_icons( iv_field_name = 'ICON'
its_tooltips = lts_icon_tooltip ).
lo_alv_ida->field_catalog( )->set_field_header_texts( iv_field_name = 'ICON'
iv_header_text = 'Icon' ).
lo_alv_ida->field_catalog( )->display_options( )->display_as_link_to_action( iv_field_name = 'ICON' ).
lo_alv_ida->field_catalog( )->display_options( )->set_tooltip_for_icons( iv_field_name = 'BUTTON'
iv_use_standard_tooltip = abap_true ).
lo_alv_ida->field_catalog( )->display_options( )->display_as_button( iv_field_name = 'BUTTON'
iv_hide_if_value_is_initial = abap_true ).
lo_alv_ida->field_catalog( )->set_field_header_texts( iv_field_name = 'BUTTON'
iv_header_text = 'Button' ).
lo_alv_ida->field_catalog( )->set_field_header_texts( iv_field_name = 'ADD_FIELD'
iv_header_text = 'ADD_FIELD' ).
SET HANDLER lo_calc_field_handler->cell_action FOR lo_alv_ida->field_catalog( )->display_options( ).
CATCH cx_salv_ida_unknown_name INTO DATA(lr_ex).
MESSAGE e000(salv_ida) WITH lr_ex->field_name.
ENDTRY.
***------------------------------------双击事件----------------------------------begin
lo_alv_ida->display_options( )->enable_double_click( ).
SET HANDLER lo_calc_field_handler->double_click FOR lo_alv_ida->display_options( ).
***------------------------------------双击事件----------------------------------end
***--------------------------排序---------------------------------------------------------begin
lo_alv_ida->default_layout(
)->set_sort_order( VALUE #( ( field_name = 'MATNR' descending = abap_true ) ) ).
***--------------------------排序---------------------------------------------------------end
lo_alv_ida->standard_functions( )->set_text_search_active( abap_true ). "文本搜索
lo_alv_ida->standard_functions( )->set_export_active( abap_false ). "导出
lo_alv_ida->fullscreen( )->display( ).
展示结果: