Skip to content

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

AMDP, AMDP Methods in Interfaces and Superclasses

This example demonstrates how AMDP methods are implemented from interfaces and superclasses.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA: iref TYPE REF TO if_demo_amdp_interface,
          cref TYPE REF TO cl_demo_amdp_superclass.

    IF cl_abap_dbfeatures=>use_features(
          EXPORTING
            requested_features =
              VALUE #( ( cl_abap_dbfeatures=>call_amdp_method ) ) ).
      cref = NEW cl_demo_amdp_subclass_hdb( ).
      iref = NEW cl_demo_amdp_implement_hdb( ).
    ELSE.
      cref = NEW cl_demo_amdp_subclass_open( ).
      iref = NEW cl_demo_amdp_implement_open( ).
    ENDIF.

    TRY.
        iref->get_scarr( EXPORTING clnt     = sy-mandt
                         IMPORTING carriers = DATA(result1) ).
        cref->get_scarr( EXPORTING clnt     = sy-mandt
                         IMPORTING carriers = DATA(result2) ).
      CATCH cx_amdp_error INTO DATA(amdp_error).
        cl_demo_output=>display( amdp_error->get_text( ) ).
        RETURN.
    ENDTRY.

    ASSERT result1 = result2.

    cl_demo_output=>display( name = 'Result'
                             data = result1 ).

Description

An interface IF_DEMO_AMDP_INTERFACE and an abstract superclass CL_DEMO_AMDP_SUPERCLASS implement the tag interface IF_AMDP_MARKER_HDB and contain the method GET_CARRIER, which meets the prerequisites of an AMDP method.

The interface method is implemented once as an AMDP method and once as a regular method in the classes CL_DEMO_AMDP_IMPLEMENT_HDB and CL_DEMO_AMDP_IMPLEMENT_OPEN. In the same way, the method of the abstract superclass is redefined in the fixed subclasses CL_DEMO_AMDP_SUBCLASS_HDB and CL_DEMO_AMDP_SUBCLASS_OPEN.

This program demonstrates how objects are created using either the AMDP method or the regular method and called polymorphically, as specified by the current database.