Question

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.

Was it helpful?

Solution

For "old" bapis < 3.1 there was no possibility to prevent a commit of a bapi: all bapis did their commit by themselves. Since 4.6 all DB changing bapis have to be called explicitely via bapi commit. If you dont call it your changes wont be saved

OTHER TIPS

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.

For FI documents you can use the BAPI_ACC_DOCUMENT_CHECK just to check if all items are correct, it doesn't change the database.

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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top