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

How to use Commit in Cursor

0 Likes
4,738

Hello,

I am trying to use Commit in cursor so that everytime it updates the data into table but after first iteration of cursor , it is giving dump at fetch statement of cursor.

Can anyone help me with any solution, how to commit the changes on each iteration of cursor?

Thanks

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
4,261

So long as your not trying to change the contents of the table you have the cursor, you can use the alternate database connection. R/3* to update another table and commit to it.

https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abenopensql_multiconnect.htm#@@ITOC@@ABEN...

E.g.

DELETE FROM demo_update CONNECTION R/3*my_service_conn.
INSERT demo_update CONNECTION R/3*my_service_conn  
    FROM @( VALUE #( id = 'X'  col1 = 1 col2 = 2 col3 = 3 col4 = 4 ) ).
COMMIT CONNECTION R/3*my_service_conn.
6 REPLIES 6
Read only

matt
Active Contributor
4,262

So long as your not trying to change the contents of the table you have the cursor, you can use the alternate database connection. R/3* to update another table and commit to it.

https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abenopensql_multiconnect.htm#@@ITOC@@ABEN...

E.g.

DELETE FROM demo_update CONNECTION R/3*my_service_conn.
INSERT demo_update CONNECTION R/3*my_service_conn  
    FROM @( VALUE #( id = 'X'  col1 = 1 col2 = 2 col3 = 3 col4 = 4 ) ).
COMMIT CONNECTION R/3*my_service_conn.
Read only

0 Likes
4,261

Thank you so much Matthew .. It worked.

Thanks alot 😊😊

Read only

Sandra_Rossi
Active Contributor
0 Likes
4,261

If you use OPEN CURSOR and CALL FUNCTION 'DB_COMMIT', use the addition "WITH HOLD". The database commit won't close the cursors. NB: COMMIT WORK always closes all opened cursors.

Read only

0 Likes
4,261

I tried that also by using DB_COMMIT in addition with hold but that also causing the same issue. Its not working ..

Have you tried it...if yes please give the example it will be very helpful

Read only

4,261

Yes, I tried, it works, it's explained in the ABAP documentation, answered also in all the same questions in the forum as yours...

DATA l_cursor TYPE cursor.
OPEN CURSOR WITH HOLD ... SELECT ... FROM dbtab1 ...
DO.
  FETCH NEXT CURSOR ... INTO TABLE itab PACKAGE SIZE 1000.
  IF sy-subrc <> 0.
    EXIT.
  ENDIF.
  " itab processing
  INSERT dbtab2 FROM TABLE itab.
  CALL FUNCTION 'DB_COMMIT'.
ENDDO.
CLOSE CURSOR ...

If such a simple example doesn't work in your system, there's a bug in the kernel, raise a ticket at SAP support.

Read only

0 Likes
4,261

Thank you for your support.

I also tried the same only by referring SAP forum but none seems to working thats why i raised the question.