Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarations →  Declaration Statements →  Data Types and Data Objects →  Declaring Data Types →  TYPES →  TYPES - LOB HANDLE 

Deriving LOB Handle Structures

The example demonstrates the derivation of LOB handle structures using the TYPES statement.

Other versions: 7.31 | 7.40 | 7.54

Source Code

REPORT demo_types_lob_handle.

CLASS demo_lob_handles DEFINITION.
  PUBLIC SECTION.
    TYPES:

      lob_handle_structure_1 TYPE demo_lob_table
                            READER      FOR COLUMNS clob1 blob1,


      lob_handle_structure_2 TYPE demo_lob_table
                             LOB HANDLE  FOR ALL COLUMNS,

      lob_handle_structure_3 TYPE demo_lob_table
                            LOCATOR     FOR ALL BLOB COLUMNS
                            WRITER      FOR ALL CLOB COLUMNS,

      lob_handle_structure_4 TYPE demo_lob_table
                            READER      FOR COLUMNS clob1 clob2
                             LOB HANDLE  FOR ALL BLOB COLUMNS
                            LOCATOR     FOR ALL OTHER CLOB COLUMNS,

      lob_handle_structure_5 TYPE demo_lob_table
                            READER      FOR COLUMNS blob1 blob2 blob3
                            LOCATOR     FOR COLUMNS clob1 clob2 clob3
                             LOB HANDLE  FOR ALL OTHER COLUMNS,

      lob_handle_structure_6 TYPE demo_lob_table
                            READER      FOR COLUMNS blob1
                            LOCATOR     FOR COLUMNS blob2
                             LOB HANDLE  FOR COLUMNS blob3
                             LOB HANDLE  FOR ALL CLOB COLUMNS.

    CLASS-METHODS main.

  PRIVATE SECTION.
    CLASS-DATA out TYPE REF TO if_demo_output.
    CLASS-METHODS output_type IMPORTING struct TYPE string.
ENDCLASS.

CLASS demo_lob_handles IMPLEMENTATION.
  METHOD main.
    out = cl_demo_output=>new( ).
    output_type( 'LOB_HANDLE_STRUCTURE_1' ).
    output_type( 'LOB_HANDLE_STRUCTURE_2' ).
    output_type( 'LOB_HANDLE_STRUCTURE_3' ).
    output_type( 'LOB_HANDLE_STRUCTURE_4' ).
    output_type( 'LOB_HANDLE_STRUCTURE_5' ).
    output_type( 'LOB_HANDLE_STRUCTURE_6' ).
    out->display( ).
  ENDMETHOD.
  METHOD output_type.
    DATA components TYPE abap_compdescr_tab.
    DATA component  LIKE LINE OF components.
    DATA typedescr  TYPE REF TO cl_abap_typedescr.
    DATA name       TYPE string.
    DATA: BEGIN OF result,
            component_name TYPE string,
            absolute_name  TYPE string,
          END OF result,
          results LIKE TABLE OF result.

    components =
      CAST cl_abap_structdescr(
             cl_abap_structdescr=>describe_by_name( struct )
             )->components.
    out->begin_section( struct ).
    LOOP AT components INTO component.
      TRY.
          name = struct && '-' && component-name.
          typedescr =
            CAST cl_abap_refdescr(
                   cl_abap_typedescr=>describe_by_name( name )
                   )->get_referenced_type( ).
          result-component_name = component-name.
          result-absolute_name = typedescr->absolute_name.
          APPEND result TO results.
        CATCH cx_sy_move_cast_error.
      ENDTRY.
    ENDLOOP.
    out->write_data( results ).
    out->end_section(  ).
  ENDMETHOD.
ENDCLASS.

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

Description

The package-visible area of the demo_lob_handles class contains various derivations of LOB handle structures from the DEMO_LOB_TABLE database table. The methods of the class are used for the output of the static type of the derived LOB handle components.

The DEMO_LOB_TABLE database table contains a key field of type INT4, as well as three columns CLOB1, CLOB2, CLOB3 of type STRING and three columns BLOB1, BLOB2, BLOB3 of type RAWSTRING.

The derivations listed here function as follows:

  • In the structured type lob_handle_structure_1, clob1 and blob1 become LOB handle components using direct column specification after READER. The component clob1 contains the static type CL_ABAP_DB_C_READER and blob1 contains the static type CL_ABAP_DB_X_READER. All other components are displayed according to the normal rules for their predefined types.
  • In the structured type lob_handle_structure_2, all components are turned into LOB components by specifying FOR ALL COLUMNS for LOB handle components. The static type of the components of type STRING is IF_ABAP_DB_CLOB_HANDLE and the static type for the components of type RAWSTRING is IF_ABAP_DB_BLOB_HANDLE.
  • In the structured type lob_handle_structure_3, all components are converted into LOB components for LOB handle components. The static type of the component of type STRING is converted into CL_ABAP_DB_C_WRITER by specifying WRITER FOR ALL CLOB COLUMNS and the static type for the components of type RAWSTRING is converted into CL_ABAP_DB_X_LOCATOR by specifying LOCATOR FOR ALL BLOB COLUMNS.
  • In the structured type lob_handle_structure_4, all components are converted into LOB components for LOB handle components. The static type of the components clob1 and clob2 is converted into CL_ABAP_DB_C_READER by directly specifying READER. All components of the type RAWSTRING are converted into reference types for IF_ABAP_DB_BLOB_HANDLE by specifying LOB HANDLE FOR ALL BLOB COLUMNS. The other components of the type STRING are converted into reference types for CL_ABAP_DB_C_LOCATOR by specifying LOCATOR FOR ALL OTHER CLOB COLUMNS.
  • In the structured type lob_handle_structure_5, all LOB components are listed directly and thereby converted into the corresponding LOB handle components with the static types CL_ABAP_DB_C_LOCATOR for clob1, clob2, and clob3 and CL_ABAP_DB_X_READER for blob1, blob2, and blob3. Specifying LOB HANDLE FOR ALL OTHER COLUMNS has no direct effect, but instead works on possible enhancements to the database table of further LOBs, which then preserve their appropriate interface reference type.
  • In the structured type lob_handle_structure_6, all components are converted into LOB components for LOB handle components, whereby here the maximum number of column specifications is demonstrated. The specification of FOR ALL CLOB COLUMNS is only possible since no components of type STRING were recorded by the previous specifications.