ARTICLE
INSERT, UPDATE, MODIFY dbtab - LOB Handle s
In the INSERT ,
UPDATE , or MODIFY statements,
LOB handle s can be created as
writer streams and specified as
locators .
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
CLOB s .
CL_ABAP_DB_X_WRITER or
CL_ABAP_DB_X_LOCATOR in the case of
BLOB s .
The stream type or
locator type must match the data
type of the LOB s.
Rules
Unlike for read accesses , the
behavior is not the same for streams and locators .
Changing Accesses Using Writer 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 writer 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
writer stream. When connecting an LOB to a writer 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 and sy-dbcnt
respectively are set immediately and no writer stream is created for the
LOB handle components. If the rows can be added or changed,
writer streams are created and their content is passed to the database
when closing the last writer 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, writer 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 writer 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 and sy-dbcnt is set to -1
after the execution of the statement. Before a writer stream is closed,
a reference to an object from the class
CL_ABAP_SQL_CHANGING_STMNT , a subclass of
CL_ABAP_SQL_STATEMENT_HANDLE , from
the interface IF_ABAP_DB_WRITER ,
can be obtained 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 writer 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 writer 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 writer 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 writer 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 writer
stream.
When using writer streams, an unhandleable exception is raised in the
following cases:
If a writer stream is still open when closing a
database LUW using a
database commit .
When accessing a writer stream that is already closed.
Notes
Exactly when the data of a writer stream is passed to the database is
not defined. The data is passed at the latest when the last writer
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 writer 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
oder FETCH
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 .
Note
Always close a LOB handle as soon as possible using its method
CLOSE . Also refer to Streaming
and Locators .
Examples
Writer stream, fill database
Locator , copy column
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved