Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI is not return sy-subrc then how it handle the errors?

Former Member
0 Kudos

Hi,

BAPI is not return sy-subrc then how can handle the errors? what is BAPI RET2?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

3 REPLIES 3

Former Member
0 Kudos

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

uwe_schieferstein
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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