Retraction BAdI Definition 
The BAdI for retraction is UJD_RETRACT.
Log on to the SAP NetWeaver ABAP system.
Go to Transaction SE18 (BAdI Implementation).
Enter UJD_RETRACT in Enhancement Spot.
Choose Display.
Right-click on BAdI definition.
Choose Create BAdI Implementation.
Choose Create Enhancement Implementation.
Enter the enhancement implementation name and short text.
Enter the BAdI Implementation name, description, and class.
Implement the interface method IF_UJD_RETRACT~RETRACT.
Check and save the method.
Example for cost center retraction
Data: ls_message type line of UJ0_T_Message.
ls_message-MSGID = 'ZDAVY'.
ls_message-MSGTY = 'E'.
ls_message-MSGNO = '000'.
ls_message-MSGV1 = 'MD Retract...'.
ls_message-MSGV2 = I_MORE_DATA.
Append ls_message to ET_message.
FIELD-SYMBOLS: <ls_data> TYPE any,
<lt_data> TYPE STANDARD TABLE,
<lv_ID> TYPE any,
<LV_SCALING> TYPE any.
data lv_ID(4) type c.
data lv_SCALING(1) type c.
data ls_MESSAGE1 TYPE BAPIRET2.
data lv_costcenter(10) type c.
ASSIGN ir_data->* to <lt_data>.
FIELD-SYMBOLS: <l_line> type string,
<l_id> type string.
DATA: lv_dummy(30) TYPE c.
.
data: l_mode type c.
DATA: BEGIN OF data_struc2,
ID(30) TYPE c,
EVDESCRIPTION(30) TYPE c,
SCALING(30) TYPE c,
PARENTH1(30) TYPE c,
END OF data_struc2.
data: BEGIN OF data_index_struc,
tabix type i,
END OF data_index_struc.
FIELD-SYMBOLS: <lt_err> TYPE STANDARD TABLE.
data data_index_table like table of data_index_struc.
Data: ls_message_err type line of UJ0_T_Message.
CREATE DATA er_error_data LIKE TABLE OF data_struc2.
ASSIGN er_error_data->* to <lt_err>.
loop at <lt_data> ASSIGNING <ls_data>.
assign COMPONENT 'LINE' of STRUCTURE <ls_data> to <L_line>.
*N,Cost Center 1001,H1,1,4321,1,,
if sy-subrc = 0.
l_mode = '1'.
split <L_line> at ',' into LV_ID lv_dummy lv_SCALING lv_dummy .
else.
l_mode = '2'.
ASSIGN COMPONENT 'ID' OF STRUCTURE <ls_data> to <lv_ID>.
ASSIGN COMPONENT 'SCALING' OF STRUCTURE <ls_data> to <lv_SCALING>.
lv_ID = <lv_id>.
endif.
clear ls_message_err-MSGV2.
clear lv_costcenter.
if lv_SCALING = 'Y'.
CALL FUNCTION 'ZDAVY_BADI_RETRACT_MD_ERP'
DESTINATION 'Q4ACLNT002'
EXPORTING
IV_COST_CENTER = lv_ID
IV_COMMIT = 'X'
IMPORTING
ES_MESSAGE = ls_MESSAGE1
EV_COSTCENTER = lv_costcenter.
if ls_MESSAGE1 is not initial.
ls_message-MSGID = ls_MESSAGE1-ID.
ls_message-MSGTY = ls_MESSAGE1-type.
ls_message-MSGNO = ls_MESSAGE1-number.
ls_message-MSGV1 = ls_MESSAGE1-message_v1.
ls_message-MSGV2 = ls_MESSAGE1-message_v2.
append ls_message to ET_message.
endif.
if lv_costcenter = '!'. "cost center already exists
ls_message_err-
MSGV2 = ' cost center ID already exists on Target System, reject!'.
else.
*success
lv_costcenter = 'Y'.
endif.
ELSE.
if lv_id = 'ID'.
ls_message_err-MSGV2 = ' header line, reject!'.
else.
ls_message_err-
MSGV2 = ' cost center ID cannot convert to number, reject!'.
endif.
ENDIF.
if lv_ID <> 'ID' and lv_costcenter <> 'Y'. "it is header line
*-------------------------------------------------
*Fill reject data
*-------------------------------------------------
data_index_struc-tabix = sy-tabix.
data_struc2-ID = lv_ID.
APPEND data_struc2 TO <lt_err>.
*-------------------------------------------------
*Fill reject error reason
*-------------------------------------------------
ls_message_err-MSGID = 'ZDAVY'.
ls_message_err-MSGTY = 'E'.
ls_message_err-MSGNO = '000'.
ls_message_err-MSGV1 = lv_ID.
ls_message_err-RECNO = data_index_struc-tabix.
Append ls_message_err to ET_error_reason.
endif.
* else.
* ls_message-MSGID = 'ZDAVY'.
* ls_message-MSGTY = 'E'.
* ls_message-MSGNO = '000'.
* ls_message-MSGV1 = lv_costcenter.
*
* Append ls_message to ET_message.
* endif.
endloop.
Example for transaction data retraction
Data: ls_message type line of UJ0_T_Message.
ls_message-MSGID = 'ZDAVY'.
ls_message-MSGTY = 'E'.
ls_message-MSGNO = '000'.
ls_message-MSGV1 = 'Retract data TC...'.
ls_message-MSGV2 = I_MORE_DATA.
Append ls_message to ET_message.
FIELD-SYMBOLS: <ls_data> TYPE any,
<lt_data> TYPE STANDARD TABLE. .
data lv_P_acct(10) type c.
data lv_signeddata(15) type c.
data lv_curr(3) type c.
data lt_message1 type UJ0_T_Message.
FIELD-SYMBOLS: <l_line> type string.
ASSIGN ir_data->* to <lt_data>.
read table <lt_data> index 1 ASSIGNING <ls_data>.
if sy-subrc = 0.
loop at <lt_data> ASSIGNING <ls_data>.
assign COMPONENT 'LINE' of STRUCTURE <ls_data> to <L_line>.
ls_message-MSGID = 'ZDAVY'.
ls_message-MSGTY = 'E'.
ls_message-MSGNO = '000'.
ls_message-MSGV1 = ''.
ls_message-MSGV2 = ''.
ls_message-MESSAGE = <l_line>.
Append ls_message to ET_message.
endloop.
endif.
Any software coding and/or code lines / strings ("Code") included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended to better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or by its gross negligence.