1.创建结构和表
结构:ZSMIGO_ITEM
表类型:
表 :ZTMIGO_ITEM(用来保存增强字段的值)
2.创建函数组
TOP里的代码:
FUNCTION-POOL zfg_migo. "MESSAGE-ID ..* INCLUDE LZFG_MIGOD... " Local class definitionTABLES :ztmigo_item.
ZMIGO_ITEM_GET_DATA :行项目数据从screen->BADI
FUNCTION zmigo_item_get_data.
*"----------------------------------------------------------------------
*"*"本地接口:
*" EXPORTING
*" REFERENCE(E_OUTPUT) TYPE ZSMIGO_ITEM
*"----------------------------------------------------------------------MOVE-CORRESPONDING ztmigo_item TO e_output.ENDFUNCTION.
ZMIGO_ITEM_SET_DATA:行项目数据从BADI->SCREEN
FUNCTION zmigo_item_set_data.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(I_INPUT) TYPE ZSMIGO_ITEM
*"----------------------------------------------------------------------MOVE-CORRESPONDING I_INPUT TO ztmigo_item.ENDFUNCTION.
ZMIGO_SAVE_DATA:将增强字段存到自定义表
FUNCTION zmigo_save_data.
*"----------------------------------------------------------------------
*"*"更新函数模块:
*"
*"*"本地接口:
*" TABLES
*" IT_ITEM STRUCTURE ZTMIGO_ITEM
*"----------------------------------------------------------------------MODIFY ztmigo_item FROM TABLE it_item[].IF sy-subrc <> 0.MESSAGE 'Error update ZTMIGO_ITEM' TYPE 'A'.ENDIF.ENDFUNCTION.
创建屏幕:用来显示增强的字段
3.实施BADI:MB_MIGO_BADI
1.属性
GT_EXTDATA Instance Attribute Private Type ZSMIGO_ITEM_T MIGO行项目增强
GT_EXTDATA_MAA Instance Attribute Private Type ZSMIGO_ITEM_T MIGO行项目增强
GF_CLASS_ID Instance Attribute Private Type MIGO_CLASS_ID MIGO 组件的类标识 (外部细节屏幕) 'MIGO_BADI_IMPLEMENTATION1'
G_NO_INPUT Instance Attribute Private Type XFELD 复选框
G_CANCEL Instance Attribute Private Type XFELD 复选框
G_LINE_ID Instance Attribute Private Type MB_LINE_ID 凭证行的唯一标识
IF_EX_MB_MIGO_BADI~INIT
METHOD if_ex_mb_migo_badi~init.APPEND gf_class_id TO ct_init.ENDMETHOD.
IF_EX_MB_MIGO_BADI~PBO_DETAIL
METHOD if_ex_mb_migo_badi~pbo_detail.DATA ls_extdata TYPE zsmigo_item.CHECK i_class_id = gf_class_id.CHECK i_line_id <> 0.IF g_no_input IS INITIAL.e_cprog = 'SAPLZFG_MIGO'. "'SAPL + 'FG Name'e_dynnr = '9001'.e_heading = '客户数据'.g_line_id = i_line_id.READ TABLE gt_extdata INTO ls_extdataWITH TABLE KEY line_id = i_line_id.
*CALL FUNCTION 'ZMIGO_ITEM_SET_DATA'EXPORTINGi_input = ls_extdata.ENDIF.ENDMETHOD.
IF_EX_MB_MIGO_BADI~PAI_DETAIL
METHOD if_ex_mb_migo_badi~pai_detail.DATA: ls_extdata_new TYPE zsmigo_item,ls_extdata_old TYPE zsmigo_item.
*CHECK i_line_id <> 0.
*CALL FUNCTION 'ZMIGO_ITEM_GET_DATA'IMPORTINGe_output = ls_extdata_new.READ TABLE gt_extdata INTO ls_extdata_oldWITH TABLE KEY line_id = i_line_id.ls_extdata_new-line_id = i_line_id.IF ls_extdata_old <> ls_extdata_new.e_force_change = 'X'.ENDIF.ENDMETHOD.
IF_EX_MB_MIGO_BADI~LINE_MODIFY
METHOD if_ex_mb_migo_badi~line_modify.DATA: ls_extdata_old TYPE zsmigo_item,ls_extdata_new TYPE zsmigo_item,ls_migo_badi_exampl TYPE ztmigo_item,l_subrc TYPE sy-subrc.*
* Get external data from internal table:READ TABLE gt_extdata INTO ls_extdata_oldWITH TABLE KEY line_id = i_line_id.l_subrc = sy-subrc.IF l_subrc <> 0.IF NOT cs_goitem-mblnr IS INITIAL AND NOT cs_goitem-mjahr IS INITIALAND NOT cs_goitem-zeile IS INITIAL.SELECT SINGLE * FROM ztmigo_item INTO ls_migo_badi_examplWHERE mblnr = cs_goitem-mblnrAND mjahr = cs_goitem-mjahrAND zeile = cs_goitem-zeile.IF sy-subrc = 0.MOVE-CORRESPONDING ls_migo_badi_exampl TO ls_extdata_new.ENDIF.ENDIF.ls_extdata_new-line_id = i_line_id.INSERT ls_extdata_new INTO TABLE gt_extdata.ELSE.CHECK g_line_id = i_line_id.CALL FUNCTION 'ZMIGO_ITEM_GET_DATA'IMPORTINGe_output = ls_extdata_new.ls_extdata_new-line_id = i_line_id.MODIFY TABLE gt_extdata FROM ls_extdata_new.ENDIF.ENDMETHOD.
IF_EX_MB_MIGO_BADI~LINE_DELETE
METHOD if_ex_mb_migo_badi~line_delete.DELETE TABLE gt_extdata WITH TABLE KEY line_id = i_line_id.ENDMETHOD.
IF_EX_MB_MIGO_BADI~RESET
METHOD if_ex_mb_migo_badi~reset.CLEAR: gt_extdata,g_no_input,
* gs_exdata_header,g_cancel,g_line_id.ENDMETHOD.
IF_EX_MB_MIGO_BADI~POST_DOCUMENT
过账里面的逻辑不在这里写,写在此处只有前台可以触发,为了调bapi时也能触发,需要写在
BADI:MB_DOCUMENT_BADI里面的方法:IF_EX_MB_DOCUMENT_BADI~MB_DOCUMENT_BEFORE_UPDATE