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: 

Calling BAPI's one after one

Former Member
0 Kudos

Hi,

As per requirement i need to call 3 BAPI's one after one. If any error throws by any BAPI then all changes should be rollback. Could you please tell me how can i achieve that.

Because if i use transaction commit then its not possible to rollback ...so please advice me.

1 ACCEPTED SOLUTION

valter_oliveira
Active Contributor
0 Kudos

You answered to your own question! Just use BAPI_TRANSACTION_COMMIT if all the 3 bapi's returned success status. Unless they are sequential, this means one need the success of the previous one. In that case, I think you cannot do it.

Regards,

Valter Oliveira.

4 REPLIES 4

valter_oliveira
Active Contributor
0 Kudos

You answered to your own question! Just use BAPI_TRANSACTION_COMMIT if all the 3 bapi's returned success status. Unless they are sequential, this means one need the success of the previous one. In that case, I think you cannot do it.

Regards,

Valter Oliveira.

0 Kudos

So you mean ... only one trasaction_commit after the last BAPI ... in case if no errors found in any of the above BAPI's. ..

is it correct.

0 Kudos

So you mean ... only one trasaction_commit after the last BAPI ... in case if no errors found in any of the above BAPI's...

Yes, give it a try (and post here the result). Otherwise, you cannot achieve your goal.

However, if they are related to each other it won't work, like: create sales order and then create a delivery regarding that salesorder. As I said, in those cases i can only remember of workaround, not good solutions.

Regards,

Valter Oliveira.

former_member585060
Active Contributor
0 Kudos

Read all the RETURN or ERROR_MESSAGE_TABLE values, with MESSAGE_TYPE EQ 'S'.

If condition satisfies call other BAPI, like wise do for all BAPIs

____________________________________________________

CALL FUNCTION 'BAPI_PROJECT_MAINTAIN'

EXPORTING

i_project_definition = ipd

i_project_definition_upd = iup

TABLES

i_method_project = imp

i_wbs_element_table = iwbs

e_message_table = it_return.

READ TABLE it_return INTO wa_return WITH KEY message_type = 'E'.

IF sy-subrc = 0.

LOOP AT it_return INTO wa_return WHERE message_type = 'E'.

WRITE 😕 wa_return-message_id,wa_return-message_type,wa_return-message_text .

ENDLOOP.

ELSE.

READ TABLE it_return INTO wa_return WITH KEY message_type = 'S'.

CALL FUNCTION 'BAPI_XXXXXX_XXXXX'.

READ TABLE it_return INTO wa_return WITH KEY message_type = 'E'.

IF sy-subrc = 0.

LOOP AT it_return INTO wa_return WHERE message_type = 'E'.

WRITE 😕 wa_return-message_id,wa_return-message_type,wa_return-message_text .

ENDLOOP.

LOOP AT it_return INTO wa_return WHERE message_type <> 'S'.

CALL FUNCTION 'BAPI_XXX_XXXXX'

READ TABLE it_return INTO wa_return WITH KEY message_type = 'E'.

IF sy-subrc = 0.

LOOP AT it_return INTO wa_return WHERE message_type = 'E'.

WRITE 😕 wa_return-message_id,wa_return-message_type,wa_return-message_text .

ENDLOOP.

ELSE.

READ TABLE it_return INTO wa_return WITH KEY message_type = 'S'.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

LOOP AT it_return INTO wa_return WHERE message_type <> 'S'.

WRITE 😕 wa_return-message_id,wa_return-message_type,wa_return-message_text .

ENDLOOP.

ENDLOOP.