ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Accesses →  Open SQL →  Open SQL - Streaming and Locators →  Open SQL - Examples forLOB Handles → 

Read Stream, Read Out Database Table

The example demonstrates how data can be read out of a database table using a read stream.

Source Code

REPORT demo_db_reader.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
  PRIVATE SECTION.
    TYPES:
      pict_line(1022) TYPE x,
      pict_tab TYPE STANDARD TABLE OF pict_line .
    CLASS-DATA:
      name TYPE c LENGTH 255
           VALUE '/SAP/PUBLIC/BC/ABAP/Sources/ABAP_Docu_Logo.gif',
      pict TYPE pict_tab.
    CLASS-METHODS show_picture.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.

    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
           INTO reader
           WHERE name = name.

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

    WHILE reader->data_available( ) = 'X'.
      APPEND reader->read( 1022 ) TO pict.
    ENDWHILE.

    reader->close( ).

    show_picture( ).

  ENDMETHOD.
  METHOD show_picture.
    DATA html_str TYPE string.
    DATA ext_data   TYPE cl_abap_browser=>load_tab.
    DATA ext_line   TYPE cl_abap_browser=>load_tab_line.
    html_str = '<html><body><img src="PICT.GIF" ></body></html>'.
    ext_line-name = 'PICT.GIF'.
    ext_line-type = 'image'.
    ext_line-dref = REF #( pict ).
    INSERT ext_line INTO TABLE ext_data.
    cl_abap_browser=>show_html(
      EXPORTING
        html_string = html_str
        format      = cl_abap_browser=>landscape
        size        = cl_abap_browser=>small
        data_table  = ext_data
        check_html  = ' ' ).
  ENDMETHOD.
ENDCLASS.


START-OF-SELECTION.
  demo=>main( ).

Description

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

The internal table pict is then filled sequentially with binary data from the row found. If you are accessing data which was previously written in the example for write streams, this is the data of a figure in the GIF format.

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