Application Development and Automation 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: 
Read only

BAPI

Former Member
0 Likes
313

Why BAPIs do not have exceptions?

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
277

Hello Srinivas

BAPIs <b>must not</b> have exceptions because they are primarily intended for remote-access (RFC) to SAP business objects. If a BAPI would raise an exception the RFC connection will break down.

Therefore all BAPIs collect the messages and return them usually in a TABLES parameter RETURN (of structure BAPIRET2).

In order to evaluate the succesful calling of a BAPI add the following coding:

" call BAPI ...  ==> return messages in TABLES parameter RETURN
" Returned messages are stored in itab lt_return

  LOOP AT lt_return TRANSPORTING NO FIELDS
                 WHERE ( type CA 'AEX' ).   " abort, error, dump
    EXIT.
  ENDLOOP. 
  IF ( syst-subrc = 0 ).
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
      DESTINATION '<rfc destination>'.
  ELSE. 
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      DESTINATION '<rfc destination>'.
  ENDIF.

Please note that some BAPI do not return any messages at all in case of success.

Finally, in order to retrieve RFC failures add the following standard exceptions to the BAPI call, e.g.:

  CALL FUNCTION 'BAPI_USER_CREATE1'
      DESTINATION '<rfc destination>'
    ...
   EXCEPTIONS
     system_failure = 1 MESSAGE ld_rfc_msg
     communication_failure = 2 MESSAGE ld_rfc_msg.

Regards

Uwe

1 REPLY 1
Read only

uwe_schieferstein
Active Contributor
0 Likes
278

Hello Srinivas

BAPIs <b>must not</b> have exceptions because they are primarily intended for remote-access (RFC) to SAP business objects. If a BAPI would raise an exception the RFC connection will break down.

Therefore all BAPIs collect the messages and return them usually in a TABLES parameter RETURN (of structure BAPIRET2).

In order to evaluate the succesful calling of a BAPI add the following coding:

" call BAPI ...  ==> return messages in TABLES parameter RETURN
" Returned messages are stored in itab lt_return

  LOOP AT lt_return TRANSPORTING NO FIELDS
                 WHERE ( type CA 'AEX' ).   " abort, error, dump
    EXIT.
  ENDLOOP. 
  IF ( syst-subrc = 0 ).
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
      DESTINATION '<rfc destination>'.
  ELSE. 
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      DESTINATION '<rfc destination>'.
  ENDIF.

Please note that some BAPI do not return any messages at all in case of success.

Finally, in order to retrieve RFC failures add the following standard exceptions to the BAPI call, e.g.:

  CALL FUNCTION 'BAPI_USER_CREATE1'
      DESTINATION '<rfc destination>'
    ...
   EXCEPTIONS
     system_failure = 1 MESSAGE ld_rfc_msg
     communication_failure = 2 MESSAGE ld_rfc_msg.

Regards

Uwe