ABAP - Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  AMDP - ABAP Managed Database Procedures →  AMDP - Examples → 

AMDP, Access to ABAP Types

The example demonstrates how to access ABAP types via the AMDP macro $ABAP.type.

Source Code

REPORT demo_amdp_abap_types.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.
    DATA itab TYPE cl_demo_amdp_abap_types=>itab.

    cl_demo_amdp_abap_types=>demo_abap_types( IMPORTING itab = itab ).

    cl_demo_output=>display( itab ).
  ENDMETHOD.
ENDCLASS.

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

Description

This example calls the following AMDP method of class CL_DEMO_AMDP_ABAP_TYPES:

METHOD demo_abap_types BY DATABASE PROCEDURE
                       FOR HDB LANGUAGE SQLSCRIPT.

  DECLARE mytab table( mandt  "$ABAP.type( mandt )",
                       uname  "$ABAP.type( syst_uname )",
                       langu  "$ABAP.type( syst_langu )",
                       datum  "$ABAP.type( syst_datum )",
                       text   "$ABAP.type( line-text )",
                       number "$ABAP.type( f )" );

  mytab.mandt[1]  := session_context('CLIENT');
  mytab.uname[1]  := session_context('APPLICATIONUSER');
  mytab.langu[1]  := session_context('LOCALE_SAP');
  mytab.datum[1]  := session_context('SAP_SYSTEM_DATE');
  mytab.text[1]   := cast( 0123456789 as "$ABAP.type( line-text )" );
  mytab.number[1] := 333 ;

  itab = select * from :mytab;
ENDMETHOD.

In SQLScript a local table variable mytab is declared with DECLARE in the method. All columns of the table variable are declared via the AMDP macro $ABAP.type with reference to ABAP types. The first four ABAP types MANDT, SYST_UNAME, SYST_LANGU and SYST_DATUM are defined in ABAP Dictionary. Type line_text comes from a TYPES statement of its own class. f stands for the built-in numeric ABAP type.

The table variable is filled using assignments to columns with one row, whereby the specification of the AMDP macro $ABAP.type is displayed in a CAST expression. Finally, the content of the table variable is imported into the tabular output parameter itab, whose row type is made up of components of the same ABAP types, which are used to define the table variable.