Skip to content

ABAP Keyword Documentation →  ABAP - Dictionary →  Classic Objects in ABAP Dictionary →  Database Tables →  Global Temporary Tables 

Global Temporary Tables, Access

This example demonstrates how global temporary tables in ABAP Dictionary are accessed.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA(o) = cl_demo_output=>new( ).

    DATA delete TYPE abap_bool.
    cl_demo_input=>request(
      EXPORTING text         = `Delete lines before implicit commit`
                as_checkbox = abap_true
      CHANGING  field       = delete ).

    "Fill GTT with Open SQL
    INSERT demo_gtt FROM @( VALUE #( id = 'X' col = 111 ) ).
    SELECT SINGLE * FROM demo_gtt INTO @DATA(wa).
    o->write( COND #( WHEN sy-subrc = 0
                      THEN `Line found after open insert`
                      ELSE `No line found after open insert` ) ).
    IF delete = abap_true.
      DELETE FROM demo_gtt.
    ENDIF.
    WAIT UP TO 1 SECONDS.
    SELECT SINGLE * FROM demo_gtt INTO @wa.
    o->write( COND #( WHEN sy-subrc = 0
                      THEN `Line found after implicit commit`
                      ELSE `No line found after implicit commit` ) ).

    "Fill GTT with Native SQL (for demonstration only!)
    wa = VALUE demo_gtt( id = 'X' col = 111 ).
    EXEC SQL.
      INSERT INTO DEMO_GTT VALUES ( :wa-id, :wa-col )
    ENDEXEC.
    SELECT SINGLE * FROM demo_gtt INTO @wa.
    o->write( COND #( WHEN sy-subrc = 0
                      THEN `Line found after native insert`
                      ELSE `No line found after native insert` ) ).
    WAIT UP TO 1 SECONDS.
    SELECT SINGLE * FROM demo_gtt INTO @wa.
    o->write( COND #( WHEN sy-subrc = 0
                      THEN `Line found after implicit commit`
                      ELSE `No line found after implicit commit` ) ).

    o->display( ).

Description

ABAP SQL and Native SQL are used to access a global temporary table (GTT) DEMO_GTT:

  • After the GTT is filled using the ABAP SQL statement INSERT, the table is cleared again (after user input) using the ABAP SQL statement DELETE FROM without a WHERE condition. If the DELETE statement is not executed, the statement WAIT UP TO (which performs an implicit database commit) produces the runtime error COMMIT_GTT_ERROR, which can be found in the ABAP dump analysis (ST22).
  • After the GTT has been filled using a static native INSERT statement between EXEC SQL - ENDEXEC, the table is not cleared explicitly. Instead it is cleared in most database platforms using an implicit database commit raised by the statement WAIT UP TO.


Note

Native SQL is used to fill the GTT here for demonstration purposes only. Only ABAP SQL should be used to access GTTs.