SAP IUM LOB



Get Example source ABAP code based on a different SAP table
  



INSERT, UPDATE, MODIFY dbtab, LOB Handles
In the INSERT, UPDATE, or MODIFY statements, LOB handles can be created as writer streams and specified as locators.
ITOC

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 in reads, the behavior for streams does not match the behavior for locators.

Writes Using Writer Streams
If, in a changing access, an LOB is linked with 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 processed using the methods of the writer stream. When an LOB is linked with a writer stream that 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 that are not LOB handle components are written directly to the database when executing the statement. If the rows cannot be inserted 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 inserted or changed, writer streams are created and their content is passed to the database when closing the last writer stream of the AB-SQL statement at the latest.
On other database systems, the components of the work area that 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 content of the remaining components is also delayed, that is, it is passed when closing the last writer stream of the AB-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 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 AB-SQL statement and the GET_DB_COUNT method returns the number of inserted or changed rows after the last writer stream of the AB-SQL statement was closed. The methods of the abstract superclass can be used to check the status of the AB-SQL statement and all streams that are still open can be closed. If the AB-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 AB-SQL statement is still open, the corresponding database operation is not completed. The state of the AB-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 uncatchable 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.



Latest 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 sufficient.
A writer stream should always be closed explicitly and as soon as possible using its method CLOSE. See also Streaming and Locators.
NON_V5_HINTS
ABAP_HINT_END

Changing Accesses Using Locators
If, in a changing access, an LOB is linked with a reference variable of type CL_ABAP_DB_C_LOCATOR or CL_ABAP_DB_X_LOCATOR, this variable must point to an appropriate locator, created in a statement SELECT for a LOB in a different DDIC 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.
BEGIN_SECTION SAP_INTERNAL_HINT
In an upcoming release locators should be created also by FETCH.
END_SECTION SAP_INTERNAL_HINT