I have to save N documents in DB. If an error happens in any document, you should not save any other document, that is, or ALL or NOTHING.
The algorithm is as follows:
Error = ''. LOOP AT .... "For example, 100 times for 100 Documents CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST' EXPORTING ... IMPORTING ... TABLES .... RETURN = BAPI_RETURN_TABLE. LOOP AT BAPI_RETURN_TABLE ASSIGNING <ret>. IF <ret>-TYPE = 'E'. "If an error occurs on a document, do rollback on all the documents "already posted and flow ends. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' IMPORTING RETURN = RETURN. "I do not analyze the error in the ROLBACK RETURN, "because read somewhere that ROLLBACK can not fail. Error = 'X'. "In case of error, flow ends! EXIT. ENDLOOP. IF Error = 'X'. EXIT. ENDIF. ENDLOOP. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING WAIT = 'X' IMPORTING RETURN = RETURN. "In the COMMIT, in case of error, RETURN table has only one record. IF RETURN-TYPE = 'E'. "Point A: I do not know what to do?????? ENDIF.
Questions are:
1. The algorithm is correct?
2. I am not sure that I do in "Point A". How does the COMMIT?
If that could happen:
(a) with COMMIT are written in DB, for example, 30 documents, after that fails COMMIT of 31. document?
(b) If (a) is yes, i do ROLLBACK on other documents (from 31. up to 100.), posted but not saved in DB?
(c) If (b) is yes, at the end, 30 documents are saved and 70 documents are not saved.
This situation does not suit me, because, I repeat, I have to saved all 100 or nothing.
Thanks in advance,
Serena