前言
业务场景:FPM LIST组件设置动态列
实现代码
IF_FPM_GUIBB_LIST~GET_DEFINITION: 代码:
METHOD if_fpm_guibb_list~get_definition.
DATA: ls_field_descr TYPE fpmgb_s_listfield_descr,
lo_structdescr TYPE REF TO cl_abap_structdescr,
lt_component TYPE abap_component_tab.
DATA: lt_field_name TYPE STANDARD TABLE OF x031l,
ls_field_name TYPE x031l.
DATA: ls_row_action LIKE LINE OF et_action_definition.
FIELD-SYMBOLS:
<fs_component> LIKE LINE OF lt_component.
FIELD-SYMBOLS:
<fs_field_descr> TYPE fpmgb_s_listfield_descr.
*
set_list_struct( IMPORTING eo_field_catalog = eo_field_catalog
et_field_description = et_field_description ).
LOOP AT et_field_description ASSIGNING <fs_field_descr>.
IF <fs_field_descr>-name NE 'COACCOUNT' AND <fs_field_descr>-name NE 'SX' AND <fs_field_descr>-name NE 'REMARK' AND <fs_field_descr>-name NE 'WAERS'
AND <fs_field_descr>-name NE 'STABIX' AND <fs_field_descr>-name NE 'READONLY' AND <fs_field_descr>-name NE 'ZTOTAL'.
<fs_field_descr>-read_only_ref = 'READONLY'.
ENDIF.
ENDLOOP.
*
DATA: ls_action_definition TYPE fpmgb_s_actiondef.
DEFINE add_action.
CLEAR ls_action_definition.
ls_action_definition-id = &1.
ls_action_definition-enabled = abap_true.
ls_action_definition-text = &2.
ls_action_definition-visible = '02'.
APPEND ls_action_definition TO ET_ACTION_DEFINITION.
END-OF-DEFINITION.
add_action:
'BTN_UPLOAD' text-001, "上载数据
'BTN_DOWNLOAD' text-002. "下载模板
ENDMETHOD.
(重点 )set_list_struct方法: (其实主要就是利用动态的数据创建对应需要的的结构与内表)
METHOD set_list_struct.
FIELD-SYMBOLS <fs_listfield_descr> TYPE fpmgb_s_listfield_descr.
DATA lv_division TYPE zde_division.
DATA ls_acc_result TYPE ztest_s_acc_version.
* DATA lo_srv_mgr TYPE REF TO /bobf/if_tra_service_manager.
DATA lt_selection_parameters TYPE /bobf/t_frw_query_selparam.
DATA ls_selection_parameters TYPE /bobf/s_frw_query_selparam.
DATA: ls_field_descr TYPE fpmgb_s_listfield_descr,
lo_structdescr TYPE REF TO cl_abap_structdescr,
lo_linetype TYPE REF TO cl_abap_structdescr,
lt_basic TYPE abap_component_tab ,"abap_compdescr_tab ,"abap_component_tab .
lt_component TYPE abap_component_tab ."abap_compdescr_tab ."abap_component_tab .
* DATA ls_field TYPE ts_field_struct.
DATA lv_num(2) TYPE n.
DATA lv_desc TYPE string.
DATA lv_fname TYPE fieldname.
DATA: lv_pspid TYPE ztest_xm.
DATA: lt_vdata TYPE STANDARD TABLE OF ztest_s_010_dyncost_list.
DATA:
lo_srv_mgr TYPE REF TO /bobf/if_tra_service_manager,
lt_root TYPE ztest_t_investment_report,
lt_key TYPE ztest_if_ao_constants=>tt_key,
ls_key TYPE ztest_if_ao_constants=>ts_key.
DATA:lt_yt TYPE ztest_t_item_yt,
ls_yt TYPE ztest_s_item_yt.
TYPES:BEGIN OF ts_ytname,
db_key TYPE /bobf/conf_key,
parent_key TYPE /bobf/conf_key,
ytbm TYPE ztest_yt,
yt_name TYPE char100,
END OF ts_ytname.
DATA:ls_ytname TYPE ts_ytname,
lt_ytname TYPE TABLE OF ts_ytname.
FIELD-SYMBOLS: <fs_component> LIKE LINE OF lt_component.
FIELD-SYMBOLS: <fs_basic> LIKE LINE OF lt_component,
* <fs_yt> TYPE ztest_s_tzyc_dyncost_list.
<fs_yt> TYPE ztest_s_item_yt.
*&***************************************************
*@ version 1.0 设置列属性
*&***************************************************
DEFINE set_field.
APPEND INITIAL LINE TO ET_FIELD_DESCRIPTION ASSIGNING <FS_LISTFIELD_DESCR>.
<FS_LISTFIELD_DESCR>-NAME = &1.
<FS_LISTFIELD_DESCR>-TEXT = &2.
<FS_LISTFIELD_DESCR>-allow_filter = abap_true.
<FS_LISTFIELD_DESCR>-allow_aggregation = abap_true.
<FS_LISTFIELD_DESCR>-allow_sort = abap_true.
<FS_LISTFIELD_DESCR>-VISIBILITY = '02'.
IF <fs_listfield_descr>-name = 'WAERS' or <fs_listfield_descr>-name = 'STABIX' or <fs_listfield_descr>-name = 'READONLY'.
<FS_LISTFIELD_DESCR>-VISIBILITY = '01'.
ENDIF.
* IF <fs_listfield_descr>-name cs 'AMOUNTC'.
* <FS_LISTFIELD_DESCR>-read_only = abap_false.
* else.
<FS_LISTFIELD_DESCR>-read_only = abap_true.
* endif.
<FS_LISTFIELD_DESCR>-header_label_by_ddic = abap_false.
<FS_LISTFIELD_DESCR>-header_label = &2.
<FS_LISTFIELD_DESCR>-allow_sort = abap_true.
END-OF-DEFINITION.
lo_structdescr ?= cl_abap_structdescr=>describe_by_name( 'ZTEST_BASE' ).
lt_basic = lo_structdescr->get_components( ).
LOOP AT lt_basic ASSIGNING <fs_basic>.
CASE <fs_basic>-name.
WHEN 'COACCOUNT'.
set_field <fs_basic>-name text-003.
APPEND <fs_basic> TO lt_component.
WHEN 'SX'.
set_field <fs_basic>-name text-004.
APPEND <fs_basic> TO lt_component.
WHEN 'REMARK'.
set_field <fs_basic>-name text-005.
APPEND <fs_basic> TO lt_component.
ENDCASE.
ENDLOOP.
IF ztest_header=>gs_data-key IS NOT INITIAL.
lo_srv_mgr = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( ztest_report=>sc_bo_key ).
CLEAR:lt_key.
ls_key-key = ztest_header=>gs_data-key.
APPEND ls_key TO lt_key.
CALL METHOD lo_srv_mgr->retrieve_by_association
EXPORTING
iv_node_key = ztest_report=>sc_node-root
it_key = lt_key
iv_association = ztest_report=>sc_association-root-ztset_yt
iv_fill_data = abap_true
IMPORTING
et_data = lt_yt.
ENDIF.
IF sy-subrc EQ 0 AND lt_yt IS NOT INITIAL.
DATA:lt_yt_temp TYPE ztest_t_item_yt.
CLEAR:lt_yt_temp.
MOVE-CORRESPONDING lt_yt TO lt_yt_temp.
SORT lt_yt_temp BY zytdl zytxl zytgd zzxlx zdwlyt.
DELETE ADJACENT DUPLICATES FROM lt_yt_temp COMPARING zytdl zytxl zytgd zzxlx zdwlyt.
IF sy-subrc EQ 0.
CLEAR:ms_message.
ms_message-msgid = 'ZPS'.
ms_message-msgno = '516'.
ms_message-severity = 'E'.
CLEAR:lt_yt.
ELSE.
CLEAR:ms_message.
ENDIF.
LOOP AT lt_yt ASSIGNING <fs_yt>.
IF <fs_yt>-zytdl IS INITIAL OR <fs_yt>-zytxl IS INITIAL OR <fs_yt>-zytgd IS INITIAL OR <fs_yt>-zzxlx IS INITIAL OR <fs_yt>-zdwlyt IS INITIAL.
CONTINUE.
ENDIF.
* 拼凑业态
CALL METHOD zcl_ps_helper=>count_wjyt_name
EXPORTING
ex_ytdl = <fs_yt>-zytdl
ex_ytxl = <fs_yt>-zytxl
ex_ytgd = <fs_yt>-zytgd
ex_zxlx = <fs_yt>-zzxlx
ex_dwlyt = <fs_yt>-zdwlyt
IMPORTING
iv_name = ls_ytname-yt_name
iv_zhyt = ls_ytname-ytbm.
IF sy-subrc EQ 0.
ls_ytname-parent_key = mv_cn_key.
APPEND ls_ytname TO lt_ytname.
ENDIF.
ENDLOOP.
IF lt_ytname IS NOT INITIAL.
* SORT lt_ytname BY ytbm. "SORT THE LIST
LOOP AT lt_ytname INTO ls_ytname.
READ TABLE lt_basic ASSIGNING <fs_basic> WITH KEY name = 'AMOUNT'.
IF sy-subrc EQ 0.
APPEND INITIAL LINE TO lt_component ASSIGNING <fs_component>.
MOVE-CORRESPONDING <fs_basic> TO <fs_component>.
<fs_component>-name = ls_ytname-ytbm.
set_field <fs_component>-name ls_ytname-yt_name.
ENDIF.
ENDLOOP.
READ TABLE lt_basic ASSIGNING <fs_basic> WITH KEY name = 'AMOUNT'.
IF sy-subrc EQ 0.
APPEND INITIAL LINE TO lt_component ASSIGNING <fs_component>.
MOVE-CORRESPONDING <fs_basic> TO <fs_component>.
<fs_component>-name = 'ZTOTAL'.
set_field 'ZTOTAL' text-006.
ENDIF.
ENDIF.
ENDIF.
LOOP AT lt_basic ASSIGNING <fs_basic>.
CASE <fs_basic>-name.
WHEN 'WAERS'.
set_field <fs_basic>-name text-007 .
APPEND <fs_basic> TO lt_component.
WHEN 'STABIX'.
set_field <fs_basic>-name text-003 .
APPEND <fs_basic> TO lt_component.
WHEN 'READONLY'.
set_field <fs_basic>-name text-008 .
APPEND <fs_basic> TO lt_component.
ENDCASE.
ENDLOOP.
IF lt_component IS NOT INITIAL.
lo_linetype ?= cl_abap_structdescr=>create( p_components = lt_component ).
eo_field_catalog = cl_abap_tabledescr=>create( p_line_type = lo_linetype ).
mo_field_table = eo_field_catalog.
mo_field_line = lo_linetype.
mt_list_desc = et_field_description.
ENDIF.
ENDMETHOD.
效果展示:列名由另外地方带入
总结
希望对你有所帮助
|