Convert BAPI return errors of common types like BAPIRET2, BAPIRET1, BAPIRETURN, BAPIRETURN1, BAPIRETC, etc. into class-based exceptions
Reuse class ZCL_BAPIRET_TO_BAPI_E_FUNCTION (which returns a child of ZCX_NO_CHECK with a getter for all messages of type error):
data(bapi_error_msg) = new zcl_free_message( `Creation of x failed` ).
call function 'BAPI_CREATE_*'
tables
return = return.
data(e) = new zcl_bapiret_to_bapi_e_function( bapi_error_msg )->apply( return ).
if e is bound.
raise exception e.
endif.
data(to_bapi_e) = new zcl_bapiret_to_bapi_e_function( ).
call function 'BAPI_CREATE_*'
tables
return = return.
data(e) = to_bapi_e->apply( return ).
if e is bound.
data(errors) = e->errors( ).
endif.
Or create your own implementation of ZIF_BAPI_TO_EXC_FUNCTION.