09-06-2008 2:31 PM
Hi,
BAPI is not return sy-subrc then how can handle the errors? what is BAPI RET2?
09-06-2008 2:45 PM
Hi,
BAPI will always return messages in a internal table called "RETURN", so we need to loop at that internal table after BAPI execution and see whether data is uploaded correctly.
Only after that we need to call BAPI_TRANSACTION_COMMIT.
Regards
Karthik D
09-06-2008 2:45 PM
Hi,
BAPI will always return messages in a internal table called "RETURN", so we need to loop at that internal table after BAPI execution and see whether data is uploaded correctly.
Only after that we need to call BAPI_TRANSACTION_COMMIT.
Regards
Karthik D
09-06-2008 3:26 PM
Hello Pravin
BAPIs must not raise exceptions because this will result in a dump if it is called remotely.
Instead, you need to evaluate the messages that are returned (either single message or multiple messages, usually in an EXPORTING or TABLES parameter RETURN).
The most up-to-date structure for message is BAPIRET2 (older ones are BAPIRETURN1):
" Evaluate message itab returned by BAPI:
LOOP AT lt_messages TRANSPORTING NO FIELDS
WHERE ( type CA 'AEX' ). " Abort, Error, or Dump
EXIT.
ENDLOOP.
IF ( syst-subrc = 0 ).
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
Please note that some BAPIs do not return any message in case of a successful call.
Regards
Uwe
09-08-2008 4:55 PM
Hi,
Using return table, you can do error handling and could display proper error messages.
Error Message Handling
CLEAR gv_count.
LOOP AT gt_ret INTO gs_ret WHERE type = 'E' OR type = 'A'. "Where GT_RET is of type table BAPIRET2
WRITE: / gs_ret-message.
ENDLOOP.
IF sy-subrc <> 0.
Use BAPI_TRANSACTION_COMMIT to commit the data.
Write: / 'Success'.
ELSE.
USe BAPI_TRANSACTION_ROLLBACK to revert the transactional changes.
ENDIF.
Note : BAPI doesnt return any success messages. In case of success, return table is empty.
Thanks,
Kartavya