背景:
使用FPM开发报表时,如果报表字段过多,页面拖拽等操作不方便
处理:
将FPM报表开发简化为类似GUI端ALV的开发过程::定义数据对象,选择屏幕;数据处理;报表展示控制
需要继承基础类并重写对应方法,复制或新建FPM应用,使用新报表对应的类
2. 填写应用命名
4. 创建search UIBB 和list UIBB并填写feeder 类
6. 测试应用
Feeder 类代码部分:
代码:
CLASS zcl_sample_report_base DEFINITION
PUBLIC
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_fpm_guibb .
INTERFACES if_fpm_guibb_search .
INTERFACES if_fpm_guibb_list .
INTERFACES if_fpm_guibb_dynamic_config .
protected section.
types:
BEGIN OF ty_layout,
visible_row_counts TYPE fpmgb_row_count, " 列表行数
title TYPE wdy_conf_transl_text, " title
allow_personalization TYPE fpmgb_allow_pers_ats,
allow_sorting TYPE fpmgb_allow_sorting_ats,
allow_filtering TYPE fpmgb_allow_filtering_ats,
allow_grouping TYPE fpmgb_allow_grouping_ats,
scroll_mode TYPE fpm_s_table_settings-scroll_mode, " S: 滚动 P; 分页 默认滚动
export_to_excel TYPE fpmgb_excel_export, " 允许导出Excel
fit_to_table_width TYPE fpmgb_fit_table_width, " 自适应列宽,为X 时,无横向滚动条,数据条目较多时体验较
END OF ty_layout .
types:
BEGIN OF ty_search_fields,
name TYPE name_komp, " 搜索条件字段
type TYPE string, " 参考数据类型
text TYPE string, " 搜索条件文本
obligatory TYPE boole_d, " 是否必输
no_intervals TYPE boole_d, " 是否无间隔
no_extension TYPE boole_d, " 是否无扩展,即多行
ddic_shlp_name TYPE shlpname, " 是否无扩展,即多行
list_box TYPE fpmgb_t_namevalue, " 下拉框值
END OF ty_search_fields .
types:
tt_search_fields TYPE TABLE OF ty_search_fields .
methods START_OF_SELECTION
importing
!FIELD_SELECTION type RCF_T_FIELD_SELECTION
exporting
!ET_MESSAGES type FPMGB_SEARCH_T_T100_MESSAGE
!DATA type DATA .
methods DATA_DEFINE_AND_SELECT_SCREEN
exporting
!SELECT_FIELDS type TT_SEARCH_FIELDS
!FIELDCAT type LVC_T_FCAT
!LAUOUT type TY_LAYOUT
!OUT_TYPE_STRUC type STRING .
private section.
data GO_LIST_TAB type ref to DATA .
data GO_SEARCH_STRU type ref to DATA .
data GT_SEARCH_FIELD_DESC type FPMGB_T_SEARCHFIELD_DESCR .
data GT_FCAT type LVC_T_FCAT .
data GS_LAYOUT type TY_LAYOUT .
data MR_FPM type ref to IF_FPM .
data GV_CONFIG_ID type WDY_CONFIG_ID .
data GT_COMPS_SEARCH type ABAP_COMPONENT_TAB .
methods ADD_COMP_BY_DATA
importing
!P_DATA type ANY
!IV_NAME type STRING
!IV_AS_INCLUDE type ABAP_BOOL optional
!IV_SUFFIX type C optional
changing
!CT_COMP type ABAP_COMPONENT_TAB .
methods ADD_COMP_BY_NAME
importing
!P_NAME type ANY
!IV_NAME type STRING
!IV_AS_INCLUDE type ABAP_BOOL optional
!IV_SUFFIX type C optional
changing
!CT_COMP type ABAP_COMPONENT_TAB .
methods CREATE_STRUCT
importing
!IT_COMP type ABAP_COMPONENT_TAB
returning
value(RO_DATA) type ref to DATA .
methods GET_SEARCH_RANGE
importing
!IT_FPM_SEARCH_CRITERIA type FPMGB_T_SEARCH_CRITERIA
!IO_SEARCH_CONVERSION type ref to IF_FPM_GUIBB_SEARCH_CONVERSION
returning
value(FIELD_SELECTION) type RCF_T_FIELD_SELECTION .
methods ADD_SELECTION_OPTION
importing
!NAME type NAME_KOMP
!TYPE type STRING
!TEXT type STRING
!OBLIGATORY type BOOLE_D optional
!NO_INTERVALS type BOOLE_D optional
!NO_EXTENSION type BOOLE_D optional
!DDIC_SHLP_NAME type SHLPNAME optional
!LIST_BOX type FPMGB_T_NAMEVALUE optional .
ENDCLASS.
CLASS ZCL_SAMPLE_REPORT_BASE IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_SAMPLE_REPORT_BASE->ADD_COMP_BY_DATA
* +-------------------------------------------------------------------------------------------------+
* | [--->] P_DATA TYPE ANY
* | [--->] IV_NAME TYPE STRING
* | [--->] IV_AS_INCLUDE TYPE ABAP_BOOL(optional)
* | [--->] IV_SUFFIX TYPE C(optional)
* | [<-->] CT_COMP TYPE ABAP_COMPONENT_TAB
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD add_comp_by_data.
DATA ls_comp LIKE LINE OF ct_comp.
ls_comp-type ?= cl_abap_typedescr=>describe_by_data( p_data = p_data ).
ls_comp-name = iv_name.
ls_comp-as_include = iv_as_include.
ls_comp-suffix = iv_suffix.
APPEND ls_comp TO ct_comp.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_SAMPLE_REPORT_BASE->ADD_COMP_BY_NAME
* +-------------------------------------------------------------------------------------------------+
* | [--->] P_NAME TYPE ANY
* | [--->] IV_NAME TYPE STRING
* | [--->] IV_AS_INCLUDE TYPE ABAP_BOOL(optional)
* | [--->] IV_SUFFIX TYPE C(optional)
* | [<-->] CT_COMP TYPE ABAP_COMPONENT_TAB
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD add_comp_by_name.
DATA ls_comp LIKE LINE OF ct_comp.
DATA lo_type TYPE REF TO cl_abap_typedescr.
cl_abap_typedescr=>describe_by_name( EXPORTING p_name = p_name RECEIVING p_descr_ref = lo_type EXCEPTIONS type_not_found = 1 ).
IF sy-subrc = 1." If P_NAME not exist, Using string type
cl_abap_typedescr=>describe_by_name( EXPORTING p_name = 'SMDSTRING' RECEIVING p_descr_ref = lo_type EXCEPTIONS type_not_found = 1 ).
ENDIF.
ls_comp-type ?= lo_type.
ls_comp-name = iv_name.
ls_comp-as_include = iv_as_include.
ls_comp-suffix = iv_suffix.
APPEND ls_comp TO ct_comp.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_SAMPLE_REPORT_BASE->ADD_SELECTION_OPTION
* +-------------------------------------------------------------------------------------------------+
* | [--->] NAME TYPE NAME_KOMP
* | [--->] TYPE TYPE STRING
* | [--->] TEXT TYPE STRING
* | [--->] OBLIGATORY TYPE BOOLE_D(optional)
* | [--->] NO_INTERVALS TYPE BOOLE_D(optional)
* | [--->] NO_EXTENSION TYPE BOOLE_D(optional)
* | [--->] DDIC_SHLP_NAME TYPE SHLPNAME(optional)
* | [--->] LIST_BOX TYPE FPMGB_T_NAMEVALUE(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD add_selection_option.
DATA: ls_descr_attr TYPE fpmgb_s_searchfield_descr.
DATA: lt_oper TYPE fpmgb_t_search_operator,
ls_oper TYPE LINE OF fpmgb_t_search_operator.
CLEAR: ls_descr_attr.
ls_descr_attr-name = name.
ls_descr_attr-text = text.
ls_descr_attr-ddic_shlp_name = ddic_shlp_name.
ls_descr_attr-mandatory = obligatory.
ls_descr_attr-max_1_value = no_extension.
IF list_box IS NOT INITIAL.
ls_descr_attr-enumeration = list_box.
ls_descr_attr-is_of_type = if_fpm_guibb_search=>gc_attribute_types-enumeration.
ENDIF.
ls_descr_attr-ignore_standard_operators = abap_true.
IF no_intervals <> abap_true.
CLEAR ls_oper.
ls_oper-operator_id = if_fpm_guibb_search=>gc_operators-is_between.
APPEND ls_oper TO lt_oper.
ENDIF.
CLEAR ls_oper.
ls_oper-operator_id = if_fpm_guibb_search=>gc_operators-is.
APPEND ls_oper TO lt_oper.
ls_descr_attr-include_operators = lt_oper.
APPEND ls_descr_attr to gt_search_field_desc.
add_comp_by_name( EXPORTING p_name = type iv_name = CONV string( name ) CHANGING ct_comp = gt_comps_search ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_SAMPLE_REPORT_BASE->CREATE_STRUCT
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_COMP TYPE ABAP_COMPONENT_TAB
* | [<-()] RO_DATA TYPE REF TO DATA
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD create_struct.
DATA lr_struct TYPE REF TO cl_abap_structdescr.
lr_struct = cl_abap_structdescr=>create( EXPORTING p_components = it_comp ) .
CREATE DATA ro_data TYPE HANDLE lr_struct.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Protected Method ZCL_SAMPLE_REPORT_BASE->DATA_DEFINE_AND_SELECT_SCREEN
* +-------------------------------------------------------------------------------------------------+
* | [<---] SELECT_FIELDS TYPE TT_SEARCH_FIELDS
* | [<---] FIELDCAT TYPE LVC_T_FCAT
* | [<---] LAUOUT TYPE TY_LAYOUT
* | [<---] OUT_TYPE_STRUC TYPE STRING
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD data_define_and_select_screen.
*----------------------------------------------------------------------*
* SELECT_FIELDS 选择屏幕定义
* FIELDCAT 报表字段属性,无定义由字段参考数据元素获取
* LAUOUT 报表展示布局
* OUT_TYPE_STRUC 报表展示数据结构 ===By Fireworks xie
*----------------------------------------------------------------------*
* DATA: lt_list_box TYPE fpmgb_t_namevalue.
*
* lt_list_box = VALUE #( ( name = '中国' value = 'CN' )
* ( name = '美国' value = 'US' )
* ( name = '德国' value = 'DE' ) ).
*
* " 选择屏幕设置
* APPEND VALUE #( name = 'BUKRS' type = 'BUKRS' text = '公司代码' ) TO select_fields.
* APPEND VALUE #( name = 'DATUM' type = 'DATUM' text = '日期' ) TO select_fields.
* APPEND VALUE #( name = 'LAND1' type = 'LAND1' text = '国家' list_box = lt_list_box ) TO select_fields.
*
* " 报表展示字段及属性
* APPEND VALUE #( fieldname = 'BUTXT' reptext = '公司名称' intlen = 40 ) TO fieldcat.
*
* " 输出报表格式
* lauout-title = 'Company'.
* lauout-fit_to_table_width = abap_true.
* lauout-allow_personalization = abap_true.
* lauout-export_to_excel = abap_true.
*
* " 输出报表数据结构
* out_type_struc = 'ZCL_SAMPLE_REPORT_SAMPLE01=>TY_OUT'.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_SAMPLE_REPORT_BASE->GET_SEARCH_RANGE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_FPM_SEARCH_CRITERIA TYPE FPMGB_T_SEARCH_CRITERIA
* | [--->] IO_SEARCH_CONVERSION TYPE REF TO IF_FPM_GUIBB_SEARCH_CONVERSION
* | [<-()] FIELD_SELECTION TYPE RCF_T_FIELD_SELECTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_search_range.
DATA: lt_fpm_search_criteria TYPE fpmgb_t_search_criteria,
ls_crit TYPE rcf_s_field_selection.
DATA: lr_range_tab_ref TYPE REF TO data.
FIELD-SYMBOLS:
<fpmgb_s_search_criteria> TYPE fpmgb_s_search_criteria,
<lt_range> TYPE ANY TABLE,
<lv_value> TYPE data,
<ls_range> TYPE data.
lt_fpm_search_criteria = it_fpm_search_criteria.
SORT lt_fpm_search_criteria STABLE BY search_attribute ASCENDING.
CLEAR field_selection .
LOOP AT lt_fpm_search_criteria ASSIGNING <fpmgb_s_search_criteria>.
AT NEW search_attribute.
"first: create reference for range
io_search_conversion->create_abap_range_ref( EXPORTING iv_search_attribute = <fpmgb_s_search_criteria>-search_attribute
IMPORTING er_range_tab_ref = lr_range_tab_ref ).
"second: fill range
io_search_conversion->fpm_attribute_into_abap_range( EXPORTING iv_search_attribute = <fpmgb_s_search_criteria>-search_attribute
IMPORTING et_range_tab_ref = lr_range_tab_ref ).
"third: create field ranges that are needed for function module below
ASSIGN lr_range_tab_ref->* TO <lt_range>.
LOOP AT <lt_range> ASSIGNING <ls_range>.
CLEAR: ls_crit.
ls_crit-fieldname = <fpmgb_s_search_criteria>-search_attribute.
ASSIGN COMPONENT 'SIGN' OF STRUCTURE <ls_range> TO <lv_value>.
CHECK sy-subrc = 0.
ls_crit-sign = <lv_value>.
ASSIGN COMPONENT 'OPTION' OF STRUCTURE <ls_range> TO <lv_value>.
CHECK sy-subrc = 0.
ls_crit-option = <lv_value>.
ASSIGN COMPONENT 'LOW' OF STRUCTURE <ls_range> TO <lv_value>.
IF sy-subrc = 0.
ls_crit-low = <lv_value>.
ENDIF.
ASSIGN COMPONENT 'HIGH' OF STRUCTURE <ls_range> TO <lv_value>.
IF sy-subrc = 0.
ls_crit-high = <lv_value>.
ENDIF.
APPEND ls_crit TO field_selection .
ENDLOOP.
ENDAT.
ENDLOOP.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB_DYNAMIC_CONFIG~HAS_DYNAMIC_CONFIGURATION
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RV_HAS_DYNAMIC_CONFIGURATION TYPE ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb_dynamic_config~has_dynamic_configuration.
rv_has_dynamic_configuration = abap_true.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB_LIST~CHECK_CONFIG
* +-------------------------------------------------------------------------------------------------+
* | [--->] IO_LAYOUT_CONFIG TYPE REF TO IF_FPM_GUIBB_LIST_CONFIG
* | [<---] ET_MESSAGES TYPE FPMGB_T_MESSAGES
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb_list~check_config.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB_LIST~FLUSH
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_CHANGE_LOG TYPE FPMGB_T_CHANGELOG
* | [--->] IT_DATA TYPE REF TO DATA
* | [--->] IV_OLD_LEAD_SEL TYPE I(optional)
* | [--->] IV_NEW_LEAD_SEL TYPE I(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb_list~flush.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB_LIST~GET_DATA
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_EVENTID TYPE REF TO CL_FPM_EVENT
* | [--->] IT_SELECTED_FIELDS TYPE FPMGB_T_SELECTED_FIELDS(optional)
* | [--->] IV_RAISED_BY_OWN_UI TYPE BOOLE_D(optional)
* | [--->] IV_VISIBLE_ROWS TYPE I(optional)
* | [--->] IV_EDIT_MODE TYPE FPM_EDIT_MODE(optional)
* | [--->] IO_EXTENDED_CTRL TYPE REF TO IF_FPM_LIST_ATS_EXT_CTRL(optional)
* | [<---] ET_MESSAGES TYPE FPMGB_T_MESSAGES
* | [<---] EV_DATA_CHANGED TYPE BOOLE_D
* | [<---] EV_FIELD_USAGE_CHANGED TYPE BOOLE_D
* | [<---] EV_ACTION_USAGE_CHANGED TYPE BOOLE_D
* | [<---] EV_SELECTED_LINES_CHANGED TYPE BOOLE_D
* | [<---] EV_DND_ATTR_CHANGED TYPE BOOLE_D
* | [<---] EO_ITAB_CHANGE_LOG TYPE REF TO IF_SALV_ITAB_CHANGE_LOG
* | [<-->] CT_DATA TYPE DATA
* | [<-->] CT_FIELD_USAGE TYPE FPMGB_T_FIELDUSAGE
* | [<-->] CT_ACTION_USAGE TYPE FPMGB_T_ACTIONUSAGE
* | [<-->] CT_SELECTED_LINES TYPE RSTABIXTAB
* | [<-->] CV_LEAD_INDEX TYPE SYTABIX
* | [<-->] CV_FIRST_VISIBLE_ROW TYPE I
* | [<-->] CS_ADDITIONAL_INFO TYPE FPMGB_S_ADDITIONAL_INFO(optional)
* | [<-->] CT_DND_ATTRIBUTES TYPE FPMGB_T_DND_DEFINITION(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb_list~get_data.
FIELD-SYMBOLS <fs_table> TYPE STANDARD TABLE.
ASSIGN go_list_tab->* TO <fs_table>.
IF ct_data <> <fs_table>.
ct_data = <fs_table>.
ev_data_changed = abap_true.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB_LIST~GET_DEFAULT_CONFIG
* +-------------------------------------------------------------------------------------------------+
* | [--->] IO_LAYOUT_CONFIG TYPE REF TO IF_FPM_GUIBB_LIST_CONFIG
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb_list~get_default_config.
DATA: lv_column_id TYPE fpm_element_id,
lv_index TYPE i,
lv_fix TYPE fpmgb_list_ats_fixation,
lv_visibility TYPE fpmgb_column_visibility.
IF io_layout_config IS NOT INITIAL.
LOOP AT gt_fcat INTO DATA(ls_fcat).
lv_index = lv_index + 1.
IF ls_fcat-fix_column = abap_true.
lv_fix = '02'.
ELSE.
lv_fix = '01'.
ENDIF.
IF ls_fcat-no_out = 'X'.
lv_visibility = '01'.
ELSE.
lv_visibility = ''.
ENDIF.
TRY.
lv_column_id = io_layout_config->add_column(
EXPORTING
iv_name = ls_fcat-fieldname
iv_display_type = 'TV'
iv_index = lv_index
iv_header = CONV string( ls_fcat-reptext )
iv_width = CONV string( ls_fcat-intlen )
iv_tooltip = CONV string( ls_fcat-scrtext_l )
iv_visibility = lv_visibility
iv_fixed = lv_fix
).
CATCH cx_fpm_configuration .
ENDTRY.
ENDLOOP.
ENDIF.
CALL METHOD io_layout_config->set_settings
EXPORTING
iv_visible_row_counts = gs_layout-visible_row_counts
iv_allow_personalization = gs_layout-allow_personalization
iv_allow_sorting = gs_layout-allow_sorting
iv_allow_filtering = gs_layout-allow_filtering
iv_allow_grouping = gs_layout-allow_grouping
iv_scroll_mode = gs_layout-scroll_mode
iv_export_to_excel = gs_layout-export_to_excel
iv_is_search_result_list = abap_true
iv_fit_to_table_width = gs_layout-fit_to_table_width
iv_allow_search = abap_true.
mr_fpm->set_application_title( gs_layout-title ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB_LIST~GET_DEFINITION
* +-------------------------------------------------------------------------------------------------+
* | [<---] EO_FIELD_CATALOG TYPE REF TO CL_ABAP_TABLEDESCR
* | [<---] ET_FIELD_DESCRIPTION TYPE FPMGB_T_LISTFIELD_DESCR
* | [<---] ET_ACTION_DEFINITION TYPE FPMGB_T_ACTIONDEF
* | [<---] ET_SPECIAL_GROUPS TYPE FPMGB_T_SPECIAL_GROUPS
* | [<---] ES_MESSAGE TYPE FPMGB_S_T100_MESSAGE
* | [<---] EV_ADDITIONAL_ERROR_INFO TYPE DOKU_OBJ
* | [<---] ET_DND_DEFINITION TYPE FPMGB_T_DND_DEFINITION
* | [<---] ET_ROW_ACTIONS TYPE FPMGB_T_ROW_ACTION
* | [<---] ES_OPTIONS TYPE FPMGB_S_LIST_OPTIONS
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb_list~get_definition.
*&---------------------------------------------------------------------*
*& 1. 定义页面元素,按钮等
*&---------------------------------------------------------------------*
DATA: ls_field_description TYPE fpmgb_s_formfield_descr,
ls_action TYPE fpmgb_s_actiondef,
lt_component TYPE abap_compdescr_tab,
ls_component TYPE abap_compdescr,
lo_struc TYPE REF TO cl_abap_structdescr,
ls_field_descr LIKE LINE OF et_field_description.
DEFINE mcr_actions.
ls_action-id = &1.
ls_action-text = &2.
ls_action-enabled = abap_true.
APPEND ls_action TO et_action_definition.
CLEAR ls_action.
END-OF-DEFINITION.
eo_field_catalog ?= cl_abap_typedescr=>describe_by_data_ref( go_list_tab ).
lo_struc ?= eo_field_catalog->get_table_line_type( ).
IF lo_struc->components IS NOT INITIAL.
et_field_description = VALUE #( FOR <ls_struc_component> IN lo_struc->components
(
name = <ls_struc_component>-name
allow_sort = abap_true
allow_filter = abap_true
)
).
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB_LIST~PROCESS_EVENT
* +-------------------------------------------------------------------------------------------------+
* | [--->] IO_EVENT TYPE REF TO CL_FPM_EVENT
* | [--->] IV_RAISED_BY_OWN_UI TYPE BOOLE_D(optional)
* | [--->] IV_LEAD_INDEX TYPE SYTABIX
* | [--->] IV_EVENT_INDEX TYPE SYTABIX
* | [--->] IT_SELECTED_LINES TYPE RSTABIXTAB
* | [--->] IO_UI_INFO TYPE REF TO IF_FPM_LIST_ATS_UI_INFO(optional)
* | [<---] EV_RESULT TYPE FPM_EVENT_RESULT
* | [<---] ET_MESSAGES TYPE FPMGB_T_MESSAGES
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb_list~process_event.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB_SEARCH~CHECK_CONFIG
* +-------------------------------------------------------------------------------------------------+
* | [--->] IO_LAYOUT_CONFIG TYPE REF TO IF_FPM_GUIBB_SEARCH_CONFIG
* | [<---] ET_MESSAGES TYPE FPMGB_T_MESSAGES
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb_search~check_config.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB_SEARCH~FLUSH
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_FPM_SEARCH_CRITERIA TYPE FPMGB_T_SEARCH_CRITERIA
* | [--->] IV_MAX_NUM_RESULTS TYPE I
* | [--->] IT_SELECTED_LINES_OF_RESULT TYPE T_RESULT
* | [--->] IV_RESULT_LEAD_SEL TYPE I(optional)
* | [--->] IO_SEARCH_CONVERSION TYPE REF TO IF_FPM_GUIBB_SEARCH_CONVERSION(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb_search~flush.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB_SEARCH~GET_DATA
* +-------------------------------------------------------------------------------------------------+
* | [--->] IO_EVENT TYPE REF TO CL_FPM_EVENT
* | [--->] IV_RAISED_BY_OWN_UI TYPE BOOLE_D
* | [--->] IT_VISIBLE_ATTRIBUTES TYPE FPMGB_T_SELECTED_FIELDS
* | [--->] IT_SELECTED_COLUMNS_OF_RESULT TYPE FPMGB_T_SELECTED_FIELDS
* | [--->] IT_SELECTED_SEARCH_ATTRIBUTES TYPE FPMGB_T_SELECTED_FIELDS
* | [--->] IO_SEARCH_CONVERSION TYPE REF TO IF_FPM_GUIBB_SEARCH_CONVERSION(optional)
* | [<---] ET_MESSAGES TYPE FPMGB_SEARCH_T_T100_MESSAGE
* | [<---] EV_SEARCH_CRITERIA_CHANGED TYPE BOOLE_D
* | [<---] ET_RESULT_LIST TYPE DATA
* | [<---] EV_RESULT_LIST_TITLE TYPE STRING
* | [<---] EV_FIELD_USAGE_CHANGED TYPE WDY_BOOLEAN
* | [<-->] CT_FPM_SEARCH_CRITERIA TYPE FPMGB_T_SEARCH_CRITERIA
* | [<-->] CT_FIELD_USAGE TYPE FPMGB_T_SEARCH_FIELDUSAGE(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb_search~get_data.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB_SEARCH~GET_DEFAULT_CONFIG
* +-------------------------------------------------------------------------------------------------+
* | [--->] IO_LAYOUT_CONFIG TYPE REF TO IF_FPM_GUIBB_SEARCH_CONFIG
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb_search~get_default_config.
DATA: lv_index TYPE i,
lv_colum TYPE fpm_element_id.
IF io_layout_config IS NOT INITIAL.
LOOP AT gt_search_field_desc INTO DATA(ls_search_field_desc).
lv_index = lv_index + 1.
lv_colum = io_layout_config->add_attribute(
EXPORTING
iv_name = ls_search_field_desc-name
iv_index = lv_index
iv_text = ls_search_field_desc-text
)
.
ENDLOOP.
CALL METHOD io_layout_config->set_settings
EXPORTING
iv_number_of_query_lines = 6
iv_show_button_reset = '01'
iv_show_max_num_result_field = '01'
iv_allow_personalization = '01'
iv_check_mandatory = 'X'
iv_allow_easy_search = abap_true.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB_SEARCH~GET_DEFINITION
* +-------------------------------------------------------------------------------------------------+
* | [<---] EO_FIELD_CATALOG_ATTR TYPE REF TO CL_ABAP_STRUCTDESCR
* | [<---] ET_FIELD_DESCRIPTION_ATTR TYPE FPMGB_T_SEARCHFIELD_DESCR
* | [<---] EO_FIELD_CATALOG_RESULT TYPE REF TO CL_ABAP_TABLEDESCR
* | [<---] ET_FIELD_DESCRIPTION_RESULT TYPE FPMGB_T_SEARCHRESULT_DESCR
* | [<---] EV_RESULT_TABLE_SELECTION_MODE TYPE WDUI_TSMODE
* | [<---] ES_MESSAGE TYPE FPMGB_S_T100_MESSAGE
* | [<---] EV_ADDITIONAL_ERROR_INFO TYPE DOKU_OBJ
* | [<---] ES_OPTIONS TYPE FPMGB_S_SEARCH_OPTIONS
* | [<---] ET_ACTION_DEFINITION TYPE FPMGB_T_ACTIONDEF
* | [<---] ET_SPECIAL_GROUPS TYPE FPMGB_T_SPECIAL_GROUPS
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb_search~get_definition.
eo_field_catalog_attr ?= cl_abap_structdescr=>describe_by_data_ref( go_search_stru ).
et_field_description_attr = gt_search_field_desc.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB_SEARCH~PROCESS_EVENT
* +-------------------------------------------------------------------------------------------------+
* | [--->] IO_EVENT TYPE REF TO CL_FPM_EVENT
* | [--->] IT_FPM_SEARCH_CRITERIA TYPE FPMGB_T_SEARCH_CRITERIA
* | [--->] IV_RAISED_BY_OWN_UI TYPE BOOLE_D
* | [--->] IV_MAX_NUM_RESULTS TYPE I
* | [--->] IO_SEARCH_CONVERSION TYPE REF TO IF_FPM_GUIBB_SEARCH_CONVERSION(optional)
* | [<---] ET_MESSAGES TYPE FPMGB_SEARCH_T_T100_MESSAGE
* | [<---] EV_RESULT TYPE FPM_EVENT_RESULT
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb_search~process_event.
DATA: lt_field_selection TYPE rcf_t_field_selection .
FIELD-SYMBOLS: <fs_data> TYPE STANDARD TABLE.
ASSIGN go_list_tab->* TO <fs_data>.
get_search_range(
EXPORTING
it_fpm_search_criteria = it_fpm_search_criteria
io_search_conversion = io_search_conversion
RECEIVING
field_selection = lt_field_selection
).
CALL METHOD me->start_of_selection
EXPORTING
field_selection = lt_field_selection
IMPORTING
et_messages = et_messages
data = <fs_data>.
READ TABLE et_messages TRANSPORTING NO FIELDS with KEY severity = 'E'.
IF SY-SUBRC = 0.
ev_result = 'FAILED'.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB~GET_PARAMETER_LIST
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RT_PARAMETER_DESCR TYPE FPMGB_T_PARAM_DESCR
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb~get_parameter_list.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_SAMPLE_REPORT_BASE->IF_FPM_GUIBB~INITIALIZE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_PARAMETER TYPE FPMGB_T_PARAM_VALUE
* | [--->] IO_APP_PARAMETER TYPE REF TO IF_FPM_PARAMETER(optional)
* | [--->] IV_COMPONENT_NAME TYPE FPM_COMPONENT_NAME(optional)
* | [--->] IS_CONFIG_KEY TYPE WDY_CONFIG_KEY(optional)
* | [--->] IV_INSTANCE_ID TYPE FPM_INSTANCE_ID(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_fpm_guibb~initialize.
DATA: lt_select_fields TYPE tt_search_fields,
lt_fieldcat TYPE lvc_t_fcat,
ls_lauout TYPE ty_layout,
lv_out_type_struc TYPE string.
DATA: lr_tabdescr TYPE REF TO cl_abap_tabledescr,
lr_strudescr TYPE REF TO cl_abap_structdescr,
lt_dfies TYPE ddfields,
ls_dfies TYPE dfies,
ls_fieldcat TYPE lvc_s_fcat.
CHECK go_search_stru IS INITIAL AND go_list_tab IS INITIAL.
CLEAR: gt_comps_search,gt_fcat,gt_search_field_desc,gv_config_id,gs_layout.
IF mr_fpm IS INITIAL.
mr_fpm = cl_fpm=>get_instance( ).
ENDIF.
" 1. 搜索条件字段
" 2. 报表字段结构及属性,fieldcat 中没设置属性的字段,使用参考数据对象属性
" 3. 报表展示格式
data_define_and_select_screen(
IMPORTING
select_fields = lt_select_fields
fieldcat = lt_fieldcat
lauout = ls_lauout
out_type_struc = lv_out_type_struc
).
LOOP AT lt_select_fields INTO DATA(ls_select_fields).
CALL METHOD me->add_selection_option
EXPORTING
name = ls_select_fields-name
type = ls_select_fields-type
text = ls_select_fields-text
obligatory = ls_select_fields-obligatory
no_intervals = ls_select_fields-no_intervals
no_extension = ls_select_fields-no_extension
ddic_shlp_name = ls_select_fields-ddic_shlp_name
list_box = ls_select_fields-list_box.
ENDLOOP.
gs_layout = ls_lauout.
go_search_stru = create_struct( it_comp = gt_comps_search ).
CREATE DATA go_list_tab TYPE STANDARD TABLE OF (lv_out_type_struc).
lr_tabdescr ?= cl_abap_tabledescr=>describe_by_data_ref( go_list_tab ).
lr_strudescr ?= lr_tabdescr->get_table_line_type( ).
lt_dfies = cl_salv_data_descr=>read_structdescr( lr_strudescr ).
LOOP AT lt_dfies INTO ls_dfies.
CLEAR ls_fieldcat.
READ TABLE lt_fieldcat INTO ls_fieldcat WITH KEY fieldname = ls_dfies-fieldname.
IF sy-subrc = 0.
ELSE.
MOVE-CORRESPONDING ls_dfies TO ls_fieldcat.
ls_fieldcat-reptext = ls_dfies-fieldtext.
ENDIF.
APPEND ls_fieldcat TO gt_fcat.
ENDLOOP.
IF io_app_parameter IS NOT INITIAL.
io_app_parameter->get_value( EXPORTING iv_key = 'SAP-WD-CONFIGID' IMPORTING ev_value = gv_config_id ).
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Protected Method ZCL_SAMPLE_REPORT_BASE->START_OF_SELECTION
* +-------------------------------------------------------------------------------------------------+
* | [--->] FIELD_SELECTION TYPE RCF_T_FIELD_SELECTION
* | [<---] ET_MESSAGES TYPE FPMGB_SEARCH_T_T100_MESSAGE
* | [<---] DATA TYPE DATA
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD start_of_selection.
*----------------------------------------------------------------------*
* Sample 实际使用中填充报表逻辑 ---By Fireworks xie
*----------------------------------------------------------------------*
*
* DATA: lt_out TYPE TABLE OF ty_out.
*
* DATA: lt_bukrs TYPE RANGE OF bukrs,
* ls_bukrs LIKE LINE OF lt_bukrs,
* lt_land1 TYPE RANGE OF land1,
* ls_land1 LIKE LINE OF lt_land1.
*
* LOOP AT field_selection INTO DATA(ls_selection).
* CASE ls_selection-fieldname.
* WHEN 'BUKRS'.
* MOVE-CORRESPONDING ls_selection TO ls_bukrs.
* APPEND ls_bukrs TO lt_bukrs.
* WHEN 'LAND1'.
* MOVE-CORRESPONDING ls_selection TO ls_land1.
* APPEND ls_land1 TO lt_land1.
* WHEN OTHERS.
* ENDCASE.
* ENDLOOP.
*
* SELECT bukrs , CAST( '20230101' AS DATS ) AS datum , land1 , butxt
* FROM t001
* INTO TABLE @lt_out
* WHERE bukrs IN @lt_bukrs
* AND land1 IN @lt_land1.
*
* data = lt_out.
ENDMETHOD.
ENDCLASS.
CLASS zcl_sample_report_sample01 DEFINITION
PUBLIC
INHERITING FROM zcl_sample_report_base
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
TYPES: BEGIN OF ty_out,
bukrs TYPE bukrs,
datum TYPE datum,
land1 TYPE land1,
butxt TYPE butxt,
END OF ty_out .
protected section.
methods START_OF_SELECTION
redefinition .
methods DATA_DEFINE_AND_SELECT_SCREEN
redefinition .
private section.
ENDCLASS.
CLASS ZCL_SAMPLE_REPORT_SAMPLE01 IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Protected Method ZCL_SAMPLE_REPORT_SAMPLE01->DATA_DEFINE_AND_SELECT_SCREEN
* +-------------------------------------------------------------------------------------------------+
* | [<---] SELECT_FIELDS TYPE TT_SEARCH_FIELDS
* | [<---] FIELDCAT TYPE LVC_T_FCAT
* | [<---] LAUOUT TYPE TY_LAYOUT
* | [<---] OUT_TYPE_STRUC TYPE STRING
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD data_define_and_select_screen.
DATA: lt_list_box TYPE fpmgb_t_namevalue.
lt_list_box = VALUE #( ( name = '中国' value = 'CN' )
( name = '美国' value = 'US' )
( name = '德国' value = 'DE' ) ).
" 选择屏幕设置
APPEND VALUE #( name = 'BUKRS' type = 'BUKRS' text = '公司代码' ) TO select_fields.
APPEND VALUE #( name = 'DATUM' type = 'DATUM' text = '日期' ) TO select_fields.
APPEND VALUE #( name = 'LAND1' type = 'LAND1' text = '国家' list_box = lt_list_box ) TO select_fields.
" 报表展示字段及属性
APPEND VALUE #( fieldname = 'BUTXT' reptext = '公司名称' intlen = 40 ) TO fieldcat.
" 输出报表格式
lauout-title = 'Company'.
lauout-fit_to_table_width = abap_true.
lauout-allow_personalization = abap_true.
lauout-export_to_excel = abap_true.
" 输出报表数据结构
out_type_struc = 'ZCL_SAMPLE_REPORT_SAMPLE01=>TY_OUT'.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Protected Method ZCL_SAMPLE_REPORT_SAMPLE01->START_OF_SELECTION
* +-------------------------------------------------------------------------------------------------+
* | [--->] FIELD_SELECTION TYPE RCF_T_FIELD_SELECTION
* | [<---] ET_MESSAGES TYPE FPMGB_SEARCH_T_T100_MESSAGE
* | [<---] DATA TYPE DATA
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD start_of_selection.
DATA: lt_out TYPE TABLE OF ty_out.
DATA: lt_bukrs TYPE RANGE OF bukrs,
ls_bukrs LIKE LINE OF lt_bukrs,
lt_land1 TYPE RANGE OF land1,
ls_land1 LIKE LINE OF lt_land1.
LOOP AT field_selection INTO DATA(ls_selection).
CASE ls_selection-fieldname.
WHEN 'BUKRS'.
MOVE-CORRESPONDING ls_selection TO ls_bukrs.
APPEND ls_bukrs TO lt_bukrs.
WHEN 'LAND1'.
MOVE-CORRESPONDING ls_selection TO ls_land1.
APPEND ls_land1 TO lt_land1.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
SELECT bukrs , CAST( '20230101' AS DATS ) AS datum , land1 , butxt
FROM t001
INTO TABLE @lt_out
WHERE bukrs IN @lt_bukrs
AND land1 IN @lt_land1.
data = lt_out.
ENDMETHOD.
ENDCLASS.