ABAP Keyword Documentation → ABAP - Reference → Processing External Data → ABAP - Database Accesses → Open SQL → Open SQL - Write Accesses
INSERT, UPDATE, MODIFY dbtab - LOB Handles
In the INSERT
,
UPDATE
, or MODIFY
statements,
LOB handles can be created as
write streams and specified as locators.
Other versions:
7.31 | 7.40 | 7.54
Prerequisites
An LOB in a row to be inserted or changed can be supplied from an
LOB handle component of
a work area or an individual reference variable for an LOB handle (at UPDATE
with SET
). The static type of each LOB handle component must be one of the following system classes for
streaming or locators:
- CL_ABAP_DB_C_WRITER or CL_ABAP_DB_C_LOCATOR in the case of CLOBs.
- CL_ABAP_DB_X_WRITER or CL_ABAP_DB_X_LOCATOR in the case of BLOBs.
The stream type or locator type must match the data type of the LOBs.
Rules
Unlike for read accesses, the behavior is not the same for streams and locators.
Changing Accesses Using Write Streams
If, for a changing access, an LOB is linked to a reference variable of the type CL_ABAP_DB_C_WRITER or CL_ABAP_DB_X_WRITER, a corresponding write stream is usually created and the reference variable points to the object after execution. The LOB to be changed can be edited using the methods of the write stream. When connecting an LOB to a write stream which is referenced by an LOB handle component from the source work area, the following various platform-dependent behavior may occur:
- On some database systems (MaxDB, Oracle), the components of the work area which are not LOB handle
components are written directly to the database when executing the statement. If the rows cannot be
added or changed,
sy-subrc
andsy-dbcnt
respectively are set immediately and no write stream is created for the LOB handle components. If the rows can be added or changed, write streams are created and their content is passed to the database when closing the last write stream of the Open SQL statement at the latest.
- On other database systems, the components of the work area which are not LOB handle components are
not written directly to the database when executing the statement. Instead, write streams are always
created for the LOB handle components. The contents of the remaining components are also delayed, that
is, they are passed when closing the last write stream of the Open SQL statement at the latest. Between
executing the statement and actually writing the remaining components, the status is undefined since
it is not yet determined whether the operation can be executed at all. In this case,
sy-subrc
statement is set to the value 2 andsy-dbcnt
is set to -1 after the execution of the statement. Before closing a write stream, you can get a reference to an object from the CL_ABAP_SQL_CHANGING_STMNT class, a subclass of CL_ABAP_SQL_STATEMENT_HANDLE, from the IF_ABAP_DB_WRITER interface using the method GET_STATEMENT_HANDLE. The GET_STATE method provides information about the status of the Open SQL statement, and the GET_DB_COUNT method returns the number of added or changed rows after the last write stream of the Open SQL statement was closed. The methods of the abstract superclass can be used to check the status of the Open SQL statement and all streams that are still open can be closed. if the Open SQL statement is not closed by the closing of the last write stream, GET_DB_COUNT also returns the value -1. If the operation cannot be executed, for example due to duplicate key entries, the exception CX_STREAM_IO_EXCEPTION or CX_CLOSE_RESOURCE_ERROR is raised when the data is passed to the database, depending on exactly when the data is passed.
A write stream created in this way exists until it is explicitly closed using its method CLOSE from the IF_ABAP_CLOSE_RESOURCE interface. As long as a write stream for an Open SQL statement is still open, the corresponding database operation is not finished. The state of the Open SQL statement is described using an object of the CL_ABAP_SQL_STATEMENT_HANDLE class, for which the GET_STATEMENT_HANDLE method returns a reference for every write stream.
When using writer streams, an unhandleable exception is raised in the following cases:
- If a write stream is still open when closing a database LUW using a database commit.
- When accessing a write stream that is already closed.
Notes
- Exactly when the data of a write stream is passed to the database is not defined. The data is passed at the latest when the last write stream is closed but can also occur during writing in the stream, for example because a buffer is no longer large enough.
- Always close a write stream explicitly and as soon as possible using its method CLOSE. Also refer to Streaming and Locators.
Changing Accesses Using Locators.
If, in a change access, an LOB
is associated with a reference variable of type CL_ABAP_DB_C_LOCATOR or CL_ABAP_DB_X_LOCATOR, then this variable must point to an appropriate locator,
created in a statement SELECT
for a LOB in a different database table or the same table. If the statement can be executed
(sy-subrc
is 0), the LOB to be changed is replaced directly in the database system using the complete LOB of the locator.
Restrictions
The following restrictions apply:
- A maximum of 16 data streams can be opened for an Open SQL statement.
- In a database LUW there can be a maximum of 16 Open SQL statements whose streams are open at the same time.
- A maximum of 1000 LOB handles can be open in a database LUW.
Note
Always close a LOB handle as soon as possible using its method CLOSE. Also refer to Streaming and Locators.