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_Transaction_Rollback issue

Former Member
0 Likes
4,838

Hello ABAP Gurus,

I have a problem with the rollback.

Here it is: inside the LOOP statement, I am creating a production order using  COXT_BAPI_ORDER_CREATE. If it is successful, that is, a production order is created, I then call the BAPI_TRANSACTION_COMMIT with WAIT = 'X'. And if there is no production order created, that is the time I call the BAPI_TRANSACATION_ROLLBACK..

Basically, this is what my logic (code) looks like:

LOOP AT i_data

     INTO w_data.

.*****several data processing

*call bapi to create production order

     CALL FUNCTION 'COXT_BAPI_ORDER_CREATE'

           EXPORTING

             is_header        = lx_orderdata

             i_order_category = lv_auftyp

             iv_reset         = 'X'

             iv_commit        = ' '

           IMPORTING

             es_return        = lx_return_create

             e_order_number   = lv_order_number.

         IF lv_order_number IS NOT INITIAL.

           CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

             EXPORTING

               wait = abap_true.

   *******    save the created production order to the custom table  using ENQUEUE and DEQUEUE.

             MODIFY  ZCUSTOM TABLE.... ...

       ELSE.

          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

      ENDIF.

ENDLOOP.

Now, the problem is like this: During the first loop pass, the bapi is successful so the Production Order is created. So, the data is saved to custom table. When the next loop pass results to unsuccessful run - NO Production Order is created.. So, it will pass to the BAPI_TRANSACTION_ROLLBACK statement... what then happened is that.. the previous successful entry that is saved in the custom table will now be deleted after the rollback.

For now, I commented out the BAPI_TRANSACTION_ROLLBACK so that this issue will not occur anymore. But I think this is not the right way.

Can you please help me solve my issue?

Thank you.

9 REPLIES 9
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
3,065

Why are you updating your table inside the loop. Please keep a local internal table and fill it inside loop with sucessful things.

Once loop execute completely then you can modify the database with correct values.

Nabehet

Read only

JJosh
Active Participant
0 Likes
3,065

Hi,

You can comment bapi rollback because it will rollback all the entries posted prior to this statement (In the same LUW).

Also, do not post entries to tables inside a loop.

Regards,

Josh

Read only

Former Member
0 Likes
3,065

Inside loop don`t use roll back....It will roll back all changes......

Read only

venkat_aileni
Contributor
0 Likes
3,065

Hi-

If I understand your question correctly the issue is only while updating your custom table. Please use 'COMMIT WORK AND WAIT' after your MODIFY statement written for updating custom table.

-Venkat

Read only

nishantbansal91
Active Contributor
0 Likes
3,065

HI Onyx Darrius,

Just use the Concept of the Parallel Processing. 

CALL FUNCTION 'COXT_BAPI_ORDER_CREATE' in separate task. " Means every time you must execute the      F.M in the new task or we can say it new LUW.


data task type char5.

Ex.

data idx type task2

Loop at it_itab.


concatenate 'task'idx into task.

insert your logic.

and now call the transcation using

F.M name in Separate Task Task name.

for getting the result you have to put the Receive result from Task name.

if the subrc <> 0. " or any output based on your logic

call Rollback F.M " now this time your function module is used for the particular LUV an your current database is rollback.

endif.


Regards.

Nishant Bansal.

Read only

0 Likes
3,065

Hello Nishant,

Thank you for your suggestion.

By the way, can you please give me an example? I'm not sure if I get your point right.

Thank you.

Regards,

Onyx

Read only

0 Likes
3,065

Hi Onyx

Just do one thing create a local internal table of same type as your database table. Keep appending the sucessful entries to it inside loop.

Once loop has fisnihed just use your modify statement. Only sucessful records will get updated.

Nabheet

Read only

0 Likes
3,065

data task type char6 value 'Task'

LOOP AT i_data

     INTO w_data.

.*****several data processing

*call bapi to create production order

concatenate 'Task' sy-tabix  into task. " New task  name

     CALL FUNCTION 'COXT_BAPI_ORDER_CREATE'  starting New task 'Task1'"

                                                                                 " Task Name  in which u can call the                                                                                                bapi in the New task .

            destination 'NONE'

              performing set_function1_done On end of task " Call your Rollback F.M inside this perform

           EXPORTING

             is_header        = lx_orderdata

             i_order_category = lv_auftyp

             iv_reset         = 'X'

             iv_commit        = ' '

           IMPORTING

             es_return        = lx_return_create

             e_order_number   = lv_order_number.

     endloop.

         IF lv_order_number IS NOT INITIAL.

           CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

             EXPORTING

               wait = abap_true.

   *******    save the created production order to the custom table  using ENQUEUE and DEQUEUE.

             MODIFY  ZCUSTOM TABLE.... ...

       ELSE.

          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

      ENDIF.

ENDLOOP.

For any help follow this link Parallel Processing - ABAP Development - SCN Wiki.

Regards.

Nishant Bansal

Read only

Former Member
0 Likes
3,065

Hi,

    Try to use function module ' BUFFER_REFRESH_ALL' to refresh the buffer. I have the same problem when create business partner inside LOOP.

Regards.

Yang