Commit Work in SELECT statement

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:

Scroll to Top