1、以下根据系统实例做的最终效果:1、 SE11 建立数据表,主要是用于存放附加的数据;MANDT MANDT CLNT 3 0 客户端 MBLNR MBLNR CHAR 10 0 物料凭证编号MJAHR MJAHR NUMC 4 0 物料凭证年度ZEILE MBLPO NUMC 4 0 物料凭证中的项目BADI_ERFMG ERFMG QUAN 13 3 以输入单位计的数量 BADI_ERFME ERFME UNIT 3 0 条目单位2、 建立结构,在屏幕数据交换时使用3、 建立表类型设置关键字段:4、 SE80 建立函数组创建屏幕 1000,设计格式,插入附加字段创建 function: ZJ
2、IM_BADI_EXAMPLE_GET_DATA*“-*“*“Local interface:*“ EXPORTING*“ REFERENCE(ES_MIGO_BADI_SCREEN_FIELDS) TYPE*“ ZJIM_BADI_EXAMPLE_SCREEN_FIELD*“-* Get all data from fields of external screen* First move all customer-fieldsMOVE-CORRESPONDING zjim_badi_exampl TO es_migo_badi_screen_fields.* Second move all
3、 GOITEM-fields (displayed on external screen)function: ZJIM_BADI_EXAMPLE_PUT_DATA*“-*“*“Local interface:*“ IMPORTING*“ REFERENCE(IS_MIGO_BADI_SCREEN_FIELDS) TYPE*“ ZJIM_BADI_EXAMPLE_SCREEN_FIELD*“-* Put all data from fields to external screen* First fill all customer-fieldsMOVE-CORRESPONDING is_migo
4、_badi_screen_fields TO ZJIM_badi_exampl.* second fill all GOITEM-fields (displayed on external screen)function: ZJIM_BADI_EXAMPLE_UPDATE_DATA*“-*“*“Update function module:*“*“*“Local interface:*“ TABLES*“ IT_MIGO_BADI_EXAMPLE STRUCTURE ZJIM_BADI_EXAMPL*“-* Databse update:INSERT zjim_BADI_EXAMPL FROM
5、 TABLE IT_MIGO_BADI_EXAMPLE.IF sy-subrc 0.* External subscreen:* The content of global field G_NO_INPUT (set in method MODE_SET) will* influence the number of external subsreen:if g_no_input is initial.e_cprog = SAPLZJIM_BADI001(006). “程序名为定义的函数组的名称前加 “SAPL“。e_dynnr = 1000. “External fields: Inpute_
6、heading = ZJIM(004). “显示标签的名称endif.* Set G_LINE_ID (= line_id of item displayed on detail-tabstrip)g_line_id = i_line_id.* Read dataREAD TABLE gt_extdata INTO ls_extdataWITH TABLE KEY line_id = i_line_id.* Export data to function group (for display on subscreen)CALL FUNCTION ZJIM_BADI_EXAMPLE_PUT_DA
7、TAEXPORTINGis_migo_badi_screen_fields = ls_extdata.ENDMETHOD. “IF_EX_MB_MIGO_BADIPBO_DETAILMETHOD IF_EX_MB_MIGO_BADIPAI_DETAIL .*-* Changing parameter E_FORCE_CHANGE can be set to X. In this case* method LINE_MODIFY is called.* ATTENTION:* DO NOT SET parameter E_FORCE_CHANGE = . In this case you mig
8、ht* overwrite parameter E_FORCE_CHANGE of another BAdI implementation.*-DATA: ls_extdata_new TYPE zjim_badi_example_screen_field,ls_extdata_old TYPE zjim_badi_example_screen_field.* Only if a line existsCHECK i_line_id ls_extdata_new.* If there were any changes, its obligatory to force MIGO to trigg
9、er* method LINE_MODIFY.e_force_change = X.ENDIF.ENDMETHOD. “IF_EX_MB_MIGO_BADIPAI_DETAILMETHOD IF_EX_MB_MIGO_BADILINE_MODIFY .DATA: ls_extdata_old TYPE zjim_badi_example_screen_field,ls_extdata_new TYPE zjim_badi_example_screen_field,ls_migo_badi_exampl TYPE zjim_badi_exampl,l_subrc TYPE sy-subrc.*
10、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.* Update data in internal table:IF l_subrc ls_extdata_old-sgtxt.* Field was changed on external screen* cs_goitem-sgtxt = ls_extdata_new-sgtxt.* else.* Take data from
11、GOITEM* ls_extdata_new-sgtxt = cs_goitem-sgtxt.* endif.MODIFY TABLE gt_extdata FROM ls_extdata_new.ENDIF.ENDMETHOD. “IF_EX_MB_MIGO_BADILINE_MODIFYMETHOD IF_EX_MB_MIGO_BADILINE_DELETE .DELETE TABLE gt_extdata WITH TABLE KEY line_id = i_line_id.ENDMETHOD. “IF_EX_MB_MIGO_BADILINE_DELETEMETHOD IF_EX_MB_
12、MIGO_BADIPOST_DOCUMENT .DATA: ls_migo_badi_example TYPE ZJIM_badi_exampl,lt_migo_badi_example TYPE TABLE OF zjim_badi_exampl,ls_extdata TYPE zjim_badi_example_screen_field,ls_xmseg TYPE mseg.FIELD-SYMBOLS: TYPE migo_badi_example_screen_field.* Transaction MIGO will now post a material document.* Any
13、 errors here MUST be issued as A-message (better: X-message)* Copy data from material document into internal tableLOOP AT gt_extdata INTO ls_extdata.IF g_cancel IS INITIAL.READ TABLE it_mseg INTO ls_xmsegWITH KEY line_id = ls_extdata-line_id.ELSE.READ TABLE it_mseg INTO ls_xmsegWITH KEY smbln = ls_extdata-mblnrsmblp = ls_extdata-zeilesjahr = ls_extdata-mjahr.ENDIF.IF sy-subrc IS INITIAL.MOVE-CORRESPONDING ls_extdata TO ls_migo_badi_example.MOVE-CORRESPONDING ls_xmseg TO ls_migo_badi_example.APPEND ls_migo_badi_example TO lt_migo_badi_example.ENDIF.ENDLOOP.