Skip to content

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

AMDP, Access to ABAP Types

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

Other versions: 7.31 | 7.40 | 7.54

Source Code

    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 ).

Description

This example calls the following AMDP method of the 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 the method, a local table variable mytab is declared using DECLARE in SQLScript. All columns of the table variable are declared using 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, where the AMDP macro $ABAP.type is shown as specified 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.