Skip to content

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

AMDP Method with Specified Service Connection

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

Other versions: 7.31 | 7.40 | 7.54

Source Code

    IF NOT cl_abap_dbfeatures=>use_features(
          EXPORTING
            requested_features =
              VALUE #( ( cl_abap_dbfeatures=>call_amdp_method ) ) ).
      cl_demo_output=>display(
        `Current database system does not support AMDP procedures` ).
      RETURN.
    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_CONNECTION:

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