双击类
维护类属性
GT_EXTDATA 用于数据交换,类型为ZJIM_TY_T_EXTDATA表类型, 7、 激活以下方法并维护:
method IF_EX_MB_MIGO_BADI~INIT.
* Regristration of BAdI-Implementation:
* Append class attribute GF_CLASS_ID (='MIGO_BADI_IMPLEMENTATION1') to
* regristration table.
APPEND gf_class_id TO ct_init. endmethod.
METHOD IF_EX_MB_MIGO_BADI~PBO_DETAIL .
DATA: ls_extdata TYPE zjim_badi_example_screen_field.
* This check is obligatory, otherwise the program flow is incorrect
* (If there would be more than one implementation of BAdI MB_MIGO_BADI,
* only one subscreen would be displayed). CHECK i_class_id = gf_class_id. * Show screen only if there is an item CHECK i_line_id <> 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'. \t
e_heading = 'ZJIM'(004). \显示标签的名称
endif.
* Set G_LINE_ID (= line_id of item displayed on detail-tabstrip) g_line_id = i_line_id. * Read data
READ TABLE gt_extdata INTO ls_extdata WITH TABLE KEY line_id = i_line_id.
* Export data to function group (for display on subscreen) CALL FUNCTION 'ZJIM_BADI_EXAMPLE_PUT_DATA' EXPORTING
is_migo_badi_screen_fields = ls_extdata.
ENDMETHOD. \
METHOD IF_EX_MB_MIGO_BADI~PAI_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 might
* 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 exists CHECK i_line_id <> 0.
* Get data from external screen
CALL FUNCTION 'ZJIM_BADI_EXAMPLE_GET_DATA' IMPORTING
es_migo_badi_screen_fields = ls_extdata_new. * Compare new data with old data
READ TABLE gt_extdata INTO ls_extdata_old WITH TABLE KEY line_id = i_line_id. ls_extdata_new-line_id = i_line_id. IF ls_extdata_old <> ls_extdata_new.
* If there were any changes, it's obligatory to force MIGO to trigger
* method LINE_MODIFY.
e_force_change = 'X'. ENDIF.
ENDMETHOD. \
METHOD IF_EX_MB_MIGO_BADI~LINE_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.
* Get external data from internal table: READ TABLE gt_extdata INTO ls_extdata_old WITH TABLE KEY line_id = i_line_id. l_subrc = sy-subrc.
* Update data in internal table: IF l_subrc <> 0.
* Line is new: If GOITEM has a reference to a material document, * the already existing external data can be read. IF NOT cs_goitem-mblnr IS INITIAL AND NOT cs_goitem-mjahr IS INITIAL
AND NOT cs_goitem-zeile IS INITIAL.
SELECT SINGLE * FROM zjim_badi_exampl INTO ls_migo_badi_exampl
WHERE mblnr = cs_goitem-mblnr AND mjahr = cs_goitem-mjahr AND zeile = cs_goitem-zeile. IF sy-subrc = 0.
MOVE-CORRESPONDING ls_migo_badi_exampl TO ls_extdata_new. ENDIF. ENDIF.
* ls_extdata_new-sgtxt = cs_goitem-sgtxt. ls_extdata_new-line_id = i_line_id.
INSERT ls_extdata_new INTO TABLE gt_extdata. ELSE.
* Line exists: Get external data entered on BAdI-subscreeen, but only
* if line_modify was called for the item displayed in the
* 'detail tabstrip'. check g_line_id = i_line_id.
CALL FUNCTION 'ZJIM_BADI_EXAMPLE_GET_DATA' IMPORTING
es_migo_badi_screen_fields = ls_extdata_new. ls_extdata_new-line_id = i_line_id.
* if ls_extdata_new-sgtxt <> ls_extdata_old-sgtxt. ** Field was changed on external screen * cs_goitem-sgtxt = ls_extdata_new-sgtxt. * else.
** Take data from GOITEM
* ls_extdata_new-sgtxt = cs_goitem-sgtxt. * endif.
MODIFY TABLE gt_extdata FROM ls_extdata_new. ENDIF.
ENDMETHOD. \
METHOD IF_EX_MB_MIGO_BADI~LINE_DELETE .
DELETE TABLE gt_extdata WITH TABLE KEY line_id = i_line_id. ENDMETHOD. \
METHOD IF_EX_MB_MIGO_BADI~POST_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:
* Any errors here MUST be issued as A-message (better: X-message)
* Copy data from material document into internal table LOOP AT gt_extdata INTO ls_extdata. IF g_cancel IS INITIAL.
READ TABLE it_mseg INTO ls_xmseg
WITH KEY line_id = ls_extdata-line_id. ELSE.
READ TABLE it_mseg INTO ls_xmseg WITH KEY smbln = ls_extdata-mblnr smblp = ls_extdata-zeile sjahr = 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.