Do not use explicit or implicit commit in the SELECT … ENDSELECT statement, the database cursor will be lost and the runtime error DBIF_RSQL_INVALID_CURSOR with exception CX_SY_OPEN_SQL_DB will occur.
* Bad example
DATA:
ls_usr02 TYPE usr02.
SELECT *
INTO ls_usr02
FROM usr02.
* ...
COMMIT WORK.
ENDSELECT.
Store the data in internal table and process it with LOOP.
* Correct example
DATA:
lt_usr02 TYPE TABLE OF usr02,
ls_usr02 TYPE usr02.
SELECT *
INTO TABLE lt_usr02
FROM usr02.
LOOP AT lt_usr02 INTO ls_usr02.
* ...
COMMIT WORK.
ENDLOOP.
See other related notes on my website:
- Information about amount of read records returned by SELECT, SELECT SINGLE, SELECT COUNT, etc.
- Package processing of mass data with database commit and SELECT statement
- SQL inner join vs. join of internal tables
- Select-Options in dynamic WHERE condition called per RFC
- Package processing of mass data with COMMIT WORK and SELECT statement