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

Commit work withour close all open database cursors

former_member216100
Participant
0 Likes
3,152

Dear all, I have following problem...

I do a open cursor and fetch... than after 100000 records I need to save some data in a other table with insert.

when I do the commit work it will close all open database cursors...and the fetch will dump.

Is there not a command or Function Module which only close the database cursor which I did the insert ?

Or a commit work without closing database cursor.

OPEN CURSOR DBCURSOR FOR
    SELECT * FROM Z1
       WHERE f1 EQ P_F1
      and        f2 eq P_F2
      ORDER BYf1 f2 f3.

  CLEAR DB_INDEX.

  DO.
    FETCH NEXT CURSOR DBCURSOR INTO WA1.

    IF SY-SUBRC EQ 0.
      IF DB_INDEX GE 100000.
        INSERT Z1 from it1.
**** commit work ****
       CLEAR DB_INDEX.
       refresh it1.
      ENDIF.
      ADD 1 TO DB_INDEX.
      APPEND WA1 TO IT1.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.

  CLOSE CURSOR DBCURSOR.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,422

Press F1 on OPEN CURSOR and read the option WITH HOLD.

Rob

3 REPLIES 3
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,422

I don't think so. Whenever a COMMIT WORK is encountered all the DB cursors are closed.

Why do you need to do a COMMIT after the INSERT? You can COMMIT the DB changes in a single shot after your CLOSE CURSOR statement.

Read only

Former Member
0 Likes
1,423

Press F1 on OPEN CURSOR and read the option WITH HOLD.

Rob

Read only

0 Likes
1,422

thx, it was the with hold and I forgot only the native sql statement so when I was using FM DB_COMMIT

it was working, thanks a lot