ABAP Keyword Documentation → ABAP - Reference → Processing External Data → ABAP - Database Accesses → Open SQL → Open SQL - Streaming and Locators → Open SQL - Examples forLOB Handles
Write Stream, Fill Database
The example demonstrates how data can be written to a database table using a write stream.
Other versions: 7.31 | 7.40 | 7.54
Source Code
DATA: xline TYPE xstring,
wa TYPE demo_blob_table WRITER FOR COLUMNS picture,
stmnt TYPE REF TO cl_abap_sql_changing_stmnt,
subrc TYPE sy-subrc.
TRY.
wa-name = name.
INSERT demo_blob_table FROM wa.
IF sy-subrc = 4.
subrc = 4.
ELSE.
stmnt = wa-picture->get_statement_handle( ).
LOOP AT pict INTO xline.
wa-picture->write( xline ).
ENDLOOP.
wa-picture->close( ).
IF stmnt->get_db_count( ) <> 1.
subrc = 4.
ENDIF.
ENDIF.
CATCH cx_stream_io_exception cx_close_resource_error.
subrc = 4.
ENDTRY.
IF subrc = 0.
MESSAGE 'One line inserted, you can run DEMO_DB_READER now'
TYPE 'S'.
ELSE.
MESSAGE 'Error during insertion' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
Description
In the main
method, a LOB handle structure is derived from the structure of the DEMO_BLOB_TABLE database table
, whereby the PICTURE component is declared as a
LOB handle component for a binary write stream.
This write stream is created in the INSERT
statement and then sequentially receives
the content of the pict
internal table. After closing the write stream, the content of the internal table is stored in the database table as a binary string.
Here, the content of the internal table is a figure in GIF format, which is retrieved from the Mime Repository using an auxiliary method. The address there is also used as a database table key. An existing row is deleted in the static constructor so that the example always works.
The number of changed rows is checked by an object of the CL_ABAP_SQL_CHANGING_STMNT class.
The content can be read again using the example for read streams.