【SAP Abap】SAP财务报表 FBL1N/FBL3N/FBL5N/FBL1H/FBL3H/FBL5H/FAGLL03/FAGLL03H ALV增加自定义字段的方法总结
1、FBL1N/FBL3N/FBL5N
(1)增强结构:RFPOS、RFPOSX,添加“附加结构…”,定义自定义字段,如下图:
(2)执行SE38程序:RFPOSXEXTEND,实现将上述新增字段添加到结构RFPOSXEXT中(这一步在后续发布的系统里也要执行,否则第三步会报错,找不到相应字段)。
(3)实施BADI增强:FI_ITEMS_CH_DATA,
代码如下:
METHOD IF_EX_FI_ITEMS_CH_DATA~CHANGE_ITEMS.
FIELD-SYMBOLS: <FS_ITEMS> LIKE LINE OF CT_ITEMS.
WITH +I AS ( SELECT DISTINCT BUKRS, BELNR, GJAHR, MONAT FROM @CT_ITEMS AS T )
SELECT ZTFI057~BUKRS,
ZTFI057~BELNR,
ZTFI057~GJAHR,
ZTFI057~MONAT,
ZTFI057~ZPZLSH
FROM ZTFI057
JOIN +I AS I ON I~BUKRS = ZTFI057~BUKRS
AND I~BELNR = ZTFI057~BELNR
AND I~GJAHR = ZTFI057~GJAHR
AND I~MONAT = ZTFI057~MONAT
INTO TABLE @DATA(LT_ZTFI057).
SORT LT_ZTFI057 BY BUKRS BELNR GJAHR MONAT.
LOOP AT CT_ITEMS ASSIGNING <FS_ITEMS>.
READ TABLE LT_ZTFI057 INTO DATA(LS_ZTFI057) WITH KEY
BUKRS = <FS_ITEMS>-BUKRS
BELNR = <FS_ITEMS>-BELNR
GJAHR = <FS_ITEMS>-GJAHR
MONAT = <FS_ITEMS>-MONAT BINARY SEARCH.
IF SY-SUBRC = 0.
<FS_ITEMS>-ZZPZLSH = LS_ZTFI057-ZPZLSH.
ENDIF.
ENDLOOP.
ENDMETHOD.
2、FAGLL03
(1)增强结构:FAGLPOSX,在 CI_FAGLPOSX 中增加自定义字段,如下图:
(2)实施BADI:FAGL_ITEMS_CH_DATA(代码同上)
3、FBL1H/FBL3H/FBL5H/FAGLL03H
参考:Seele_1018的原创文章,ABAP FAGLL03H加字段,感谢分享。
(1)增强结构:
FAGLL03H:对应视图:V_GLPOS_N_GL_CT,对应结构:SGLPOS_N_GL_CT、SGLPOS_N_CT;
FBL1H:对应视图:V_GLPOS_C_VEN_CT,对应结构:SGLPOS_C_VEN_CT;
FBL3H:对应视图:V_GLPOS_C_GL_CT,对应结构:SGLPOS_C_GL_CT、SGLPOS_C_CT;
FBL5H:对应视图:V_GLPOS_C_DEB_CT,对应结构:SGLPOS_C_DEB_CT;
(2)使用事务码 HDBVIEWS 生成对应视图
(2)实施BADI:FAGL_LIB,修改实现类的select_data方法
METHOD if_fagl_lib~select_data.
TYPES: BEGIN OF ty_data,
" 前台关联字段
bukrs TYPE ztfi057-bukrs,
belnr TYPE ztfi057-belnr,
gjahr TYPE ztfi057-gjahr,
monat TYPE ztfi057-monat,
" 自定义描述字段
zpzlsh TYPE ztfi057-zpzlsh,
END OF ty_data.
" 容器字段
FIELD-SYMBOLS: <fs_data> TYPE any,
<fs_cell_data> TYPE any.
DATA: ls_component LIKE LINE OF it_component.
DATA: lr_data TYPE REF TO data,
lo_descr TYPE REF TO cl_abap_typedescr,
lo_str_descr_in TYPE REF TO cl_abap_structdescr,
ls_abap_comp_descr TYPE abap_compdescr.
" 前台关联字段
DATA: lv_bukrs TYPE ztfi057-bukrs,
lv_belnr TYPE ztfi057-belnr,
lv_gjahr TYPE ztfi057-gjahr,
lv_monat TYPE ztfi057-monat.
" 自定义字段
DATA: lv_zpzlsh_f TYPE c,
lv_zpzlsh TYPE ztfi057-zpzlsh.
DATA: lt_data TYPE TABLE OF ty_data.
*&--获取ct_data的表结构
CREATE DATA lr_data LIKE LINE OF ct_data.
ASSIGN lr_data->* TO <fs_data>.
* Get structure description of data table
CALL METHOD cl_abap_structdescr=>describe_by_data
EXPORTING
p_data = <fs_data>
RECEIVING
p_descr_ref = lo_descr.
lo_str_descr_in ?= lo_descr.
LOOP AT lo_str_descr_in->components INTO ls_abap_comp_descr.
CASE ls_abap_comp_descr-name.
WHEN 'ZPZLSH'.
lv_zpzlsh_f = 'X'.
WHEN OTHERS.
CONTINUE.
ENDCASE.
ENDLOOP.
*&--获取前台关联字段以查询自定义字段
MOVE-CORRESPONDING ct_data TO lt_data.
WITH +i AS ( SELECT DISTINCT bukrs,belnr ,gjahr,monat FROM @lt_data AS g )
SELECT ztfi057~bukrs,
ztfi057~belnr,
ztfi057~gjahr,
ztfi057~monat,
ztfi057~zpzlsh
FROM ztfi057
JOIN +i AS i ON i~bukrs = ztfi057~bukrs
AND i~belnr = ztfi057~belnr
and i~gjahr = ztfi057~gjahr
and i~monat = ztfi057~monat
INTO TABLE @DATA(lt_ztfi057).
SORT lt_ztfi057 BY bukrs belnr gjahr monat.
*&-- 循环ct_data给自定义字段赋值
LOOP AT ct_data ASSIGNING <fs_data>.
" 获取前台关键字段
LOOP AT lo_str_descr_in->components INTO ls_abap_comp_descr.
" 根据字段名找到字段
ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <fs_data> TO <fs_cell_data>.
CASE ls_abap_comp_descr-name.
WHEN 'BUKRS'.
lv_bukrs = <fs_cell_data>.
WHEN 'BELNR'.
lv_belnr = <fs_cell_data>.
WHEN 'GJAHR'.
lv_gjahr = <fs_cell_data>.
WHEN 'MONAT'.
lv_monat = <fs_cell_data>.
WHEN OTHERS.
CONTINUE.
ENDCASE.
ENDLOOP.
" 账户号描述
IF lv_bukrs IS NOT INITIAL AND
lv_belnr IS NOT INITIAL AND
lv_zpzlsh_f IS NOT INITIAL.
READ TABLE lt_ztfi057 INTO DATA(ls_ztfi057) WITH KEY bukrs = lv_bukrs
belnr = lv_belnr
gjahr = lv_gjahr
monat = lv_monat BINARY SEARCH.
IF sy-subrc = 0.
lv_zpzlsh = ls_ztfi057-zpzlsh.
ENDIF.
" 根据字段名找到字段
ASSIGN COMPONENT 'ZPZLSH' OF STRUCTURE <fs_data> TO <fs_cell_data>.
<fs_cell_data> = lv_zpzlsh.
ENDIF.
ENDLOOP.
ENDMETHOD.
原创文章,转载请注明来源-X档案