Skip to content

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

AMDP, Calling an AMDP Procedure from SQLScript

This example demonstrates how an AMDP procedure is called from an AMDP procedure.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA incprice TYPE sflight-price.
    DATA price_before TYPE sflight-price.
    DATA price_after TYPE sflight-price.

    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.

    cl_demo_input=>request( CHANGING field = incprice ).
    IF incprice IS INITIAL.
      RETURN.
    ENDIF.

    SELECT SINGLE price FROM sflight INTO @price_before.

    TRY.
        cl_demo_amdp_call_amdp=>increase_price( clnt     = sy-mandt
                                               incprice = incprice ).
      CATCH cx_amdp_error INTO DATA(amdp_error).
        cl_demo_output=>display( amdp_error->get_text( ) ).
        RETURN.
    ENDTRY.


    SELECT SINGLE price FROM sflight INTO @price_after.
    IF price_after - price_before = incprice.
      cl_demo_output=>display( `Price increased succesfully` ).
    ENDIF.

Description

The SQLScript procedure of the AMDP method INCREASE_PRICE of the AMDP class CL_DEMO_AMDP_CALL_AMDP calls a further AMDP procedure implemented in the private AMDP method INCREASE_PRICE_AMDP in the same class:

METHOD increase_price BY DATABASE PROCEDURE
                      FOR HDB LANGUAGE SQLSCRIPT
                      USING cl_demo_amdp_call_amdp=>increase_price_amdp.
  call "CL_DEMO_AMDP_CALL_AMDP=>INCREASE_PRICE_AMDP"(
    CLNT => :CLNT, INCPRICE => :INCPRICE );
ENDMETHOD.
METHOD increase_price_amdp BY DATABASE PROCEDURE
                           FOR HDB LANGUAGE SQLSCRIPT
                           USING sflight.
  update sflight set price = price + incprice
               where mandt = clnt;
ENDMETHOD.

The called database procedure must be specified after the addition USING of the statement METHOD. Compare the example for calling a further database procedure not managed using AMDP.