Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Reads →  SELECT clauses →  SELECT - INTO, APPENDING 

SELECT - LOB Handles

In a standalone SELECT statement or a WITH statement (but not in a FETCH statement), LOB handles can be created as reader streams and as locators in the INTO clause.

Other versions: 7.31 | 7.40 | 7.54

Prerequisites

An LOB from the results set can be assigned to an LOB handle component of a work area, or to an individual reference variable for an LOB handle. The static type of all LOB handle components must contain the interface IF_ABAP_DB_LOB_HANDLE and match the corresponding data source component; this means they must be less specific or the same as one of the following system classes for streaming or locators:

  • CL_ABAP_DB_C_READER or CL_ABAP_DB_C_LOCATOR in the case of CLOBs.
  • CL_ABAP_DB_X_READER 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

If an LOB from the results set of a selection is assigned to an LOB handle component of a work area or to an individual reference variable for an LOB handle, either

  • a reader stream is created as an instance of one of the classes CL_ABAP_DB_C_READER, CL_ABAP_DB_X_READER or,
  • a locator is created as an instance of one of the classes CL_ABAP_DB_C_LOCATOR or CL_ABAP_DB_X_LOCATOR

and after the execution of the SELECT statement the reference variable points to the object. The class used is determined using the data type of the column of the result sets and the static type of the target variable, or using the addition CREATING if required. The LOB to be read can be evaluated or forwarded using LOB handle methods.

A LOB handle created in this way, that is a reader stream or a locator, exists until it:

  • is closed explicitly using its CLOSE method from the IF_ABAP_CLOSE_RESOURCE interface,
  • is closed implicitly at the end of the current database LUW.

Reader streams, but not locators, are also closed implicitly by the statement ENDSELECT.

Accessing a closed LOB handle produces a runtime error.

Special properties of open reader streams and locators:

  • As long as a reader stream for an ABAP SQL statement is still open, the corresponding database is not closed. This can only occur with SELECT SINGLE, since there is no implicit termination of the reader stream using ENDSELECT. In this case, a reference to an object of the class CL_ABAP_SQL_SELECT_STATEMENT (a subclass of CL_ABAP_SQL_STATEMENT_HANDLE) can be obtained from the interface IF_ABAP_DB_READER using the method GET_STATEMENT_HANDLE before closing the reader stream. The methods of the abstract superclass implemented there can be used to check the state of the ABAP SQL statement, and all streams that are still open can be closed.
  • It is guaranteed that, once created, a locator always works with the same LOB data. If the associated LOB column is modified while a locator is open, an internal copy of the LOB data for the locator is created on the database first.

Restrictions

The following restrictions apply:

  • A maximum of 16 data streams can be opened for an ABAP SQL statement.
  • In a database LUW there can be a maximum of 16 ABAP SQL statements whose data streams are open at the same time.
  • A maximum of 1000 LOB handles can be open in a database LUW.
  • If LOB handles are created using the addition SINGLE, all primary key fields in logical expressions joined using AND in the WHERE condition are checked for equality.


Note

Always close a LOB handle as soon as possible using its method CLOSE. Also refer to Streaming and Locators.

Examples


Example

Reads a BLOB to a reader stream.

DATA reader TYPE REF TO cl_abap_db_x_reader. 

SELECT SINGLE picture 
       FROM demo_blob_table 
       WHERE name = '...' 
       INTO @reader.

Executable Examples

Continue

SELECT - CREATING