DATA: p_ebeln like ekko-ebeln value '6300000000'.
DATA: i_return type table of bapiret2 with header line,
BAPI_TE_MEPOHEADER LIKE BAPI_TE_MEPOHEADER,
BAPI_TE_MEPOHEADERX LIKE BAPI_TE_MEPOHEADERX.
DATA:i_extensionin LIKE bapiparex occurs 0 WITH HEADER LINE.
FIELD-SYMBOLS: <WA> TYPE ANY.
clear i_extensionin.
clear BAPI_TE_MEPOHEADER.
i_extensionin-STRUCTURE = 'BAPI_TE_MEPOHEADER'.
BAPI_TE_MEPOHEADER-po_number = p_ebeln.
BAPI_TE_MEPOHEADER-zzrelstatus = '06'..
ASSIGN i_extensionin-VALUEPART1 TO <WA> CASTING TYPE
BAPI_TE_MEPOHEADER.
<WA> = BAPI_TE_MEPOHEADER.
APPEND i_extensionin.
clear i_extensionin.
clear BAPI_TE_MEPOHEADERX.
i_extensionin-STRUCTURE = 'BAPI_TE_MEPOHEADERX'.
BAPI_TE_MEPOHEADERX-po_number = p_ebeln.
BAPI_TE_MEPOHEADERX-zzrelstatus = 'X'.
ASSIGN i_extensionin-VALUEPART1 TO <WA> CASTING TYPE
BAPI_TE_MEPOHEADERX.
<WA> = BAPI_TE_MEPOHEADERX.
APPEND i_extensionin.
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
PURCHASEORDER = p_ebeln
TABLES
RETURN = I_RETURN
* POITEM = p_poitem
* POITEMX = p_poitemX
EXTENSIONIN = i_extensionin.
read table i_return with key type = 'E'.
if sy-subrc ne 0.
read table i_return with key type = 'A'.
endif.
if sy-subrc ne 0.
* Commit changes to database
call function 'BAPI_TRANSACTION_COMMIT'.
write: 'Call succesful'.
else.
write: / i_return-message.
exit.
endif.