Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Streaming and Locators →  ABAP SQL - Examples of LOB Handles 

Reader Stream, Read Database Table

This example demonstrates how data can be read from a database table using a reader stream.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA reader TYPE REF TO cl_abap_db_x_reader.

    cl_demo_input=>request( CHANGING field = demo=>name ).

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

    IF sy-subrc <> 0.
      MESSAGE 'Nothing found, run DEMO_DB_WRITER first!'
              TYPE 'S' DISPLAY LIKE 'E'.
      RETURN.
    ENDIF.

    pict = VALUE #( FOR j = 1 WHILE reader->data_available( )
                    ( reader->read( 1022 ) ) ).

    reader->close( ).

    show_picture( ).

Description

In the method main, a reference variable reader is declared for a reader stream. This reader stream is then created in a SELECT statement.

The internal table pict is then filled iteratively with binary data from the row found. If data previously written in the executable writer stream example is read, this is the data of a figure in the GIF format.

The auxiliary method show_picture displays the figure in an HTML browser.