Is it possible to call a BAPI and then do something to prevent the BAPI from committing the database change?
I need to make something like a test mode for my report and don't want to commit anything to the database.
Depends on the BAPI.
Some BAPIs require an additional call of BAPI_COMMIT before any changes made by the former are sent to the database.
This means, for example, you can debug the BAPI call to your heart's content (it will return all result or error messages regardless), and then when the report is otherwise ready for production, add in the BAPI_COMMIT call, and verify that whatever action was successfully enacted.
Chuck a checkbox onto your screen and do something rough like below works. Bare in mind this is a quick and dirty example.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK .
LOOP AT lt_return INTO wa_return.
IF wa_return-type EQ 'E'.
lv_err_flag = 'X'.
EXIT.
ENDIF.
ENDLOOP.
IF lv_err_flag IS INITIAL.
"Success!
"Is this a test or for real?
IF lv_test IS INITIAL.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST
.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT
.
ELSE.
"Write some output to screen instead of posting/commiting as its a test run
ENDIF.
ELSE.
"Fail!
"Fail logic and output.
ENDIF.
BAPI_TRANSACTION_COMMITis called. - JaggerBAPI_TRANSACTION_COMMIT. - Eric