TOP:
函数1:ZMIGO_BADI_GET_DATA
FUNCTION zmigo_badi_get_data.
*"----------------------------------------------------------------------
*"*"本地接口:
*" EXPORTING
*" REFERENCE(ES_MIGO_BADI_SCREEN_FIELDS) TYPE
*" ZMIGO_BADI_SCREEN_FIELD
*"----------------------------------------------------------------------
* Get all data from fields of external screen
* First move all customer-fields
MOVE-CORRESPONDING zmigo_badi TO es_migo_badi_screen_fields.
ENDFUNCTION.
函数2:ZMIGO_BADI_PUT_DATA
FUNCTION ZMIGO_BADI_PUT_DATA .
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(IS_MIGO_BADI_SCREEN_FIELDS) TYPE
*" ZMIGO_BADI_SCREEN_FIELD
*"----------------------------------------------------------------------
* Put all data from fields to external screen
* First fill all customer-fields
MOVE-CORRESPONDING is_migo_badi_screen_fields TO zmigo_badi.
ENDFUNCTION.
函数3:ZMIGO_BADI_UPATE_DATA
FUNCTION ZMIGO_BADI_UPATE_DATA.
*"----------------------------------------------------------------------
*"*"更新函数模块:
*"
*"*"本地接口:
*" TABLES
*" IT_ZMIGO_BADI STRUCTURE ZMIGO_BADI
*"----------------------------------------------------------------------
* Databse update:
MODIFY ZMIGO_BADI FROM TABLE IT_ZMIGO_BADI.
IF sy-subrc <> 0.
MESSAGE a398(00) WITH 'Error update ZMIGO_BADI'.
ENDIF.
ENDFUNCTION.
屏幕1:
屏幕2;
增强:MB_MIGO_BADI
属性:
里面代码
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 zmigo_badi_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:
* CASE g_action.
* WHEN 'A01' OR 'A03' OR 'A04' OR 'A07' OR 'A08' OR 'A12'.
IF g_no_input IS INITIAL.
e_cprog = 'SAPLZMIGO_BADI'.
e_dynnr = '0001'. "External fields: Input
e_heading = '客制化屏幕'.
ELSE.
e_cprog = 'SAPLZMIGO_BADI'.
e_dynnr = '0002'. "External fields: Display
e_heading = '客制化屏幕'.
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 'ZMIGO_BADI_PUT_DATA'
EXPORTING
is_migo_badi_screen_fields = ls_extdata.
* WHEN OTHERS.
* ENDCASE.
ENDMETHOD. "IF_EX_MB_MIGO_BADI~PBO_DETAIL
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 zmigo_badi_screen_field,
ls_extdata_old TYPE zmigo_badi_screen_field.
* Only if a line exists
CHECK i_line_id <> 0.
* Get data from external screen
CALL FUNCTION 'ZMIGO_BADI_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. "IF_EX_MB_MIGO_BADI~PAI_DETAIL
METHOD if_ex_mb_migo_badi~line_modify.
DATA: ls_extdata_old TYPE zmigo_badi_screen_field,
ls_extdata_new TYPE zmigo_badi_screen_field,
ls_migo_badi TYPE zmigo_badi,
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 zmigo_badi INTO ls_migo_badi
WHERE mblnr = cs_goitem-mblnr
AND mjahr = cs_goitem-mjahr
AND zeile = cs_goitem-zeile.
IF sy-subrc = 0.
MOVE-CORRESPONDING ls_migo_badi TO ls_extdata_new.
ENDIF.
ENDIF.
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 'ZMIGO_BADI_GET_DATA'
IMPORTING
es_migo_badi_screen_fields = 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_MODIFY
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~LINE_DELETE
METHOD if_ex_mb_migo_badi~reset.
* Clear all internal data:
CLEAR: gt_extdata,
g_no_input,
g_action,
gs_exdata_header,
g_cancel,
g_line_id.
ENDMETHOD. "IF_EX_MB_MIGO_BADI~RESET
METHOD if_ex_mb_migo_badi~post_document.
DATA: ls_zmigo_badi TYPE zmigo_badi,
lt_zmigo_badi TYPE TABLE OF zmigo_badi,
ls_extdata TYPE zmigo_badi_screen_field,
ls_xmseg TYPE mseg.
FIELD-SYMBOLS: <gt_extdata> TYPE zmigo_badi_screen_field.
* Transaction MIGO will now post a material document.
* Any errors here MUST be issued as A-message (better: X-message)
IF gt_extdata_maa IS NOT INITIAL. "Begin of 1987428
* Table gt_extdata_maa is setup in method MAA_LINE_ID_ADJUST.
* Copy data from material document into internal table
LOOP AT gt_extdata_maa 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_zmigo_badi.
MOVE-CORRESPONDING ls_xmseg TO ls_zmigo_badi.
IF ls_xmseg-maa_urzei IS NOT INITIAL.
ls_zmigo_badi-zeile = ls_xmseg-maa_urzei.
ENDIF.
APPEND ls_zmigo_badi TO lt_zmigo_badi.
ENDIF.
ENDLOOP. "End of 1987428
ELSE. "1987428
* 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_zmigo_badi.
MOVE-CORRESPONDING ls_xmseg TO ls_zmigo_badi.
APPEND ls_zmigo_badi TO lt_zmigo_badi.
ENDIF.
ENDLOOP.
ENDIF. "1987428
* The data from external detail screen can be saved now:
CHECK gt_extdata IS NOT INITIAL.
CALL FUNCTION 'ZMIGO_BADI_UPATE_DATA' IN UPDATE TASK
TABLES
it_zmigo_badi = lt_zmigo_badi.
ENDMETHOD. "IF_EX_MB_MIGO_BADI~POST_DOCUMENT
METHOD if_ex_mb_migo_badi~check_item .
DATA: ls_extdata TYPE zmigo_badi_screen_field,
ls_bapiret TYPE bapiret2.
** Refresh return table
* REFRESH: et_bapiret2.
** Read external data
* READ TABLE gt_extdata INTO ls_extdata
* WITH TABLE KEY line_id = i_line_id.
** Check if all entries are done (W-/E-Messages are useful)
* IF ls_extdata-badi_erfmg IS INITIAL.
* ls_bapiret-type = 'E'.
* ls_bapiret-id = 'M7'.
* ls_bapiret-number = '895'.
* ls_bapiret-message_v1 = 'Enter quantity on external screen'(002).
* APPEND ls_bapiret TO et_bapiret2.
* ENDIF.
* IF ls_extdata-badi_erfme IS INITIAL.
* ls_bapiret-type = 'E'.
* ls_bapiret-id = 'M7'.
* ls_bapiret-number = '895'.
* ls_bapiret-message_v1 =
* 'Enter unit of measure on external screen'(003).
* APPEND ls_bapiret TO et_bapiret2.
* ENDIF.
ENDMETHOD. "IF_EX_MB_MIGO_BADI~CHECK_ITEM
METHOD if_ex_mb_migo_badi~mode_set.
* ACTION and REFDOC will discribe the mode of transaction MIGO.
* ----------------------------------------------------------------------
* i_action:
* A01 = Goods receipt
* A02 = Return delivery
* A03 = Cancellation
* A04 = Display
* A05 = Release GR bl.st.
* A06 = Subsequent deliv.
* A07 = Goods issue
*
* i_refdoc:
* R01 = Purchase order
* R02 = Material document
* R03 = Delivery note
* R04 = Inbound delivery
* R05 = Outbound delivery
* R06 = Transport
* R07 = Transport ID code
* R08 = Order
* R09 = Reservation
* R10 = Other GR
*-----------------------------------------------------------------------
g_action = i_action.
* In case of 'DISPLAY' the global field G_NO_INPUT will be set to 'X'.
* The result is that a different external subscreen will be choosen in
* method PBO_DETAIL.
IF i_action = 'A04' OR i_action = 'A03' OR i_action = 'A02'.
g_no_input = 'X'.
ENDIF.
* In case of 'CANCEL' the global field G_CANCEL will be set to 'X'.
* The result is that in method POST_DOCUMENT a different handling is
* used
IF i_action = 'A03'.
g_cancel = 'X'.
ENDIF.
ENDMETHOD. "IF_EX_MB_MIGO_BADI~MODE_SET
表:MIGO_BADI_HOLD
METHOD if_ex_mb_migo_badi~hold_data_save .
DATA: ls_migo_badi_hold TYPE migo_badi_hold.
* Store data cluster (detail data) to data buffer
EXPORT gt_extdata FROM gt_extdata TO DATA BUFFER
ls_migo_badi_hold-hold_string.
* Store data cluster (header data) to data buffer
EXPORT gs_exdata_header FROM gs_exdata_header TO DATA BUFFER
ls_migo_badi_hold-hold_string_head.
ls_migo_badi_hold-guid = i_guid.
* Database update:
INSERT INTO migo_badi_hold VALUES ls_migo_badi_hold.
IF sy-subrc <> 0.
MESSAGE a398(00) WITH '更新时出错:MIGO_BADI_HOLD'.
ENDIF.
ENDMETHOD. "if_ex_mb_migo_badi~hold_data_save
METHOD if_ex_mb_migo_badi~hold_data_load .
DATA: ls_migo_badi_hold TYPE migo_badi_hold.
* Select hold data from database
SELECT SINGLE * FROM migo_badi_hold INTO ls_migo_badi_hold
WHERE guid = i_guid.
* Get internal structure gs_exdata_header from data buffer
IMPORT gs_exdata_header TO gs_exdata_header FROM DATA BUFFER
ls_migo_badi_hold-hold_string_head.
* Get internal table gt_extdata from data buffer
IMPORT gt_extdata TO gt_extdata FROM DATA BUFFER
ls_migo_badi_hold-hold_string.
ENDMETHOD. "if_ex_mb_migo_badi~hold_data_load
METHOD if_ex_mb_migo_badi~hold_data_delete .
* Delete entry from database table
DELETE FROM migo_badi_hold WHERE guid = i_guid.
ENDMETHOD.
METHOD if_ex_mb_migo_badi~maa_line_id_adjust. "Begin of 1987428
* MAA: Business function LOG_MM_MAA_1
* LINE_ID of MAA items was changed in method MAA_ITEM_DUPLICATOR_CANCEL/MAA_ITEM_DUPLICATOR_MIGO
* (Class CL_MMIM_MAA_2). LINE_MODIFY was called with GOITEM-GLOBAL_COUNTER hence table GT_EXTDATA
* was setup with LINE_ID = GOITEM-GLOBAL_COUNTER. GOITEM-GLOBAL_COUNTER is copied to
* IMSEG-GLOBAL_COUNTER and IMSEG-LINE_ID.
* As LINE_ID of MAA items was changed in MAA_ITEM_DUPLICATOR_CANCEL/MAA_ITEM_DUPLICATOR_MIGO the
* external data has to be updated with the new LINE_ID.
* The original data in the global table gt_extdata is kept to ensure that the entered external data
* is still available in case the program returns to the MIGO screen because of en error.
* The global table gt_extdata_maa is setup with the new LINE_ID when the user posts
* the document (OK_POST, OK_POST1). In method POST_DOCUMENT the adjusted data from table
* gt_extdata_maa has to be used to update the external data.
DATA: ls_imseg TYPE imseg,
ls_extdata TYPE zmigo_badi_screen_field.
CLEAR gt_extdata_maa.
IF sy-ucomm = 'OK_POST' OR sy-ucomm = 'OK_POST1'.
LOOP AT gt_extdata INTO ls_extdata.
READ TABLE it_imseg INTO ls_imseg
WITH KEY global_counter = ls_extdata-line_id.
IF sy-subrc = 0.
ls_extdata-line_id = ls_imseg-line_id.
APPEND ls_extdata TO gt_extdata_maa.
ELSE.
"material document item was not selected for posting
CONTINUE.
ENDIF.
ENDLOOP.
ENDIF.
ENDMETHOD. "End of 1987428
标签:德勤,migo,MIGO,extdata,ls,屏幕,data,id,badi From: https://www.cnblogs.com/ZJY-1314/p/17427485.html