Skip to content

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

AMDP, AMDP Method with Specified Database Connection

The example demonstrates an AMDP method with the input parameter connection.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    IF cl_db_sys=>is_in_memory_db = abap_false.
      cl_demo_output=>display(
        `Example can be executed on SAP HANA Database only` ).
      LEAVE PROGRAM.
    ENDIF.

    DATA connection TYPE dbcon_name VALUE 'R/3*my_conn'.
    cl_demo_input=>request( CHANGING field = connection ).

    TRY.
        NEW cl_demo_amdp_connection(
              )->get_scarr( EXPORTING
                              connection = connection
                             clnt       = sy-mandt
                            IMPORTING
                              carriers = DATA(result) ).
      CATCH cx_amdp_error INTO DATA(amdp_error).
        cl_demo_output=>display( amdp_error->get_text( ) ).
        RETURN.
    ENDTRY.

    cl_demo_output=>display( result ).

Description

A simple SQLScript procedure is implemented in the AMDP method GET_SCARR of the AMDP class CL_DEMO_AMDP:

METHOD get_scarr BY DATABASE PROCEDURE FOR HDB
                      LANGUAGE SQLSCRIPT
                      USING scarr.
  carriers  = select *
                     from scarr
                     WHERE mandt  = clnt;
ENDMETHOD.

The method also has an optional input parameter with the predefined name connection. This is used to specify whether the standard database connection or a service connection is used. If a permitted name such as "DEFAULT" or "R/3*my_conn" is passed, the method is executed using either the standard connection or a service connection. Invalid names raise an exception and an exception is text is displayed.