This commit is contained in:
danrega
2024-04-26 15:27:51 +02:00
parent 19395c61e7
commit 8ad91b2f43
13 changed files with 667 additions and 562 deletions

View File

@@ -1781,23 +1781,18 @@ The type properties are represented by attributes that are accessible through th
> - For each type category (elementary type, table, and so on), there is a type description class (e.g. `CL_ABAP_STRUCTDESCR` for structures, as shown in the hierarchy tree above) that has special attributes (i.e. the properties of the respective types). > - For each type category (elementary type, table, and so on), there is a type description class (e.g. `CL_ABAP_STRUCTDESCR` for structures, as shown in the hierarchy tree above) that has special attributes (i.e. the properties of the respective types).
> - References to type description objects can be used, for example, after the `TYPE HANDLE` addition of the `CREATE DATA` and `ASSIGN` statements. > - References to type description objects can be used, for example, after the `TYPE HANDLE` addition of the `CREATE DATA` and `ASSIGN` statements.
The following examples show the retrieval of type information. Instead of the extra declaration of data reference variables, you can use
[inline declarations](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninline_declaration_glosry.htm "Glossary Entry").
[Method chaining](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenmethod_chaining_glosry.htm "Glossary Entry")
comes in handy, too.
The following example explores the RTTI type hierarchy and demonstrates how to retrieve various pieces of type information using RTTI attributes and methods. You can create a demo class (adapt the class name if needed), copy and paste the code, run the class with F9 in ADT, and check the output in the console. The following example explores the RTTI type hierarchy and demonstrates how to retrieve various pieces of type information using RTTI attributes and methods. You can create a demo class (adapt the class name if needed), copy and paste the code, run the class with F9 in ADT, and check the output in the console.
The example includes demo objects that are added to an internal table. This table is then looped over to retrieve type information for all objects. To retrieve a type description object, you have multiple options. One option is to use the static methods of the `cl_abap_typedescr` class, which is the root class of the RTTI hierarchy. These methods include: The example includes demo objects that are added to an internal table. This table is then looped over to retrieve type information for all objects. To retrieve a type description object, you have multiple options. You can use the static methods of the `cl_abap_typedescr` class, which is the root class of the RTTI hierarchy. These methods include:
- `describe_by_data`: Returns an object reference in one of the classes `cl_abap_elemdescr`, `cl_abap_enumdescr`, `cl_abap_refdescr`, `cl_abap_structdescr`, or `cl_abap_tabledsecr`. - `describe_by_data`: Returns an object reference in one of the classes `cl_abap_elemdescr`, `cl_abap_enumdescr`, `cl_abap_refdescr`, `cl_abap_structdescr`, or `cl_abap_tabledsecr`.
- `describe_by_object_ref`: Returns the type that an object reference variable points to. - `describe_by_object_ref`: Returns the type that an object reference variable points to.
- `describe_by_data_ref`: Returns the type that a data reference variable points to. - `describe_by_data_ref`: Returns the type that a data reference variable points to.
- `describe_by_name`: Returns a type description object when providing the relative or absolute name of a type. - `describe_by_name`: Returns a type description object when providing the relative or absolute name of a type.
Notes: Notes:
- The `*_ref` methods return objects of the dynamic type. - The `*_ref` methods return objects of the dynamic type.
- In the bigger example of the demo class, we do not use type names, but rather objects (`describe_by_name` is used in the smaller example in the demo class). Therefore, we first try to get a type description object using the `describe_by_object_ref` method to obtain an instance of `cl_abap_objectdescr`. If this fails, it means we have an instance of `cl_abap_datadescr`, which is the next subclass in the hierarchy. We can retrieve this using the `describe_by_data` method. - In the bigger example of the demo class (the first `LOOP` statement), type names are not used, but rather objects. First, an attempt is made to get a type description object using the `describe_by_object_ref` method to obtain an instance of `cl_abap_objectdescr`. If this fails, it means it is an instance of `cl_abap_datadescr`, which is the next subclass in the hierarchy. It can be retrieved using the `describe_by_data` method. `describe_by_name` is used in the smaller example in the demo class (the second `LOOP` statement).
- The `describe_by_data` method also works for references, including object/interface reference variables. In these cases, the returned object points to `cl_abap_refdescr`. We can then use the `get_referenced_type` method to obtain more details about the actual reference. - The `describe_by_data` method also works for references, including object/interface reference variables. In these cases, the returned object points to `cl_abap_refdescr`. The `get_referenced_type` method can then be used to obtain more details about the actual reference.
- The example also demonstrates the dynamic creation of data objects using the retrieved type description objects and the `HANDLE` addition to the `CREATE DATA` statement. It also shows dynamic creations using the dynamic specification of the type and the absolute name. The latter is also possible with the `CREATE OBJECT` statement to create objects dynamically. In ABAP for Cloud Development, absolute names having the pattern `\TYPE=%_...` (an internal technical name that is available for [bound data types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbound_data_type_glosry.htm)) cannot be used for the dynamic creation. - The example also demonstrates the dynamic creation of data objects using the retrieved type description objects and the `HANDLE` addition to the `CREATE DATA` statement. It also shows dynamic creations using the dynamic specification of the type and the absolute name. The latter is also possible with the `CREATE OBJECT` statement to create objects dynamically. In ABAP for Cloud Development, absolute names having the pattern `\TYPE=%_...` (an internal technical name that is available for [bound data types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbound_data_type_glosry.htm)) cannot be used for the dynamic creation.
- To visualize the retrieved information, many values are added to a string table. Note that this example is tailored to cover all subclasses of the RTTI hierarchy, but it does not explore all available options for information retrieval. - To visualize the retrieved information, many values are added to a string table. Note that this example is tailored to cover all subclasses of the RTTI hierarchy, but it does not explore all available options for information retrieval.
- The example uses artifacts from the ABAP cheat sheet repository. - The example uses artifacts from the ABAP cheat sheet repository.
@@ -1830,7 +1825,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"Elementary type "Elementary type
DATA elem_dobj TYPE c LENGTH 4 VALUE 'ABAP'. DATA elem_dobj TYPE c LENGTH 4 VALUE 'ABAP'.
"Enumeration type "Enumerated type
TYPES: BEGIN OF ENUM enum_t, TYPES: BEGIN OF ENUM enum_t,
enum1, enum1,
enum2, enum2,
@@ -1947,18 +1942,18 @@ CLASS zcl_some_class IMPLEMENTATION.
IF tdo IS INSTANCE OF cl_abap_elemdescr. IF tdo IS INSTANCE OF cl_abap_elemdescr.
INSERT |{ tabix } Is instance of cl_abap_elemdescr| INTO TABLE str_tab. INSERT |{ tabix } Is instance of cl_abap_elemdescr| INTO TABLE str_tab.
"Enumeration types "Enumerated types
IF tdo IS INSTANCE OF cl_abap_enumdescr. IF tdo IS INSTANCE OF cl_abap_enumdescr.
INSERT |{ tabix } Is instance of cl_abap_enumdescr| INTO TABLE str_tab. INSERT |{ tabix } Is instance of cl_abap_enumdescr| INTO TABLE str_tab.
DATA(enum) = CAST cl_abap_enumdescr( tdo ). DATA(enum) = CAST cl_abap_enumdescr( tdo ).
"Various type-specific information retrieval "Various type-specific information retrieval
"Base type of enumeration type "Base type of enumerated type
DATA(enum_base_type_kind) = enum->base_type_kind. DATA(enum_base_type_kind) = enum->base_type_kind.
INSERT |{ tabix } Base type: { enum_base_type_kind }| INTO TABLE str_tab. INSERT |{ tabix } Base type: { enum_base_type_kind }| INTO TABLE str_tab.
"Elements of the enumeration type "Elements of the enumerated type
DATA(enum_elements) = enum->members. DATA(enum_elements) = enum->members.
INSERT |{ tabix } Elements:| && INSERT |{ tabix } Elements:| &&
| { REDUCE string( INIT str = `` FOR <l> IN enum_elements NEXT str = |{ str }{ COND #( WHEN str IS NOT INITIAL THEN ` / ` ) }| && | { REDUCE string( INIT str = `` FOR <l> IN enum_elements NEXT str = |{ str }{ COND #( WHEN str IS NOT INITIAL THEN ` / ` ) }| &&
@@ -1988,7 +1983,7 @@ CLASS zcl_some_class IMPLEMENTATION.
INSERT |{ tabix } Dynamic data object creation error: { err_enum->get_text( ) }| INTO TABLE str_tab. INSERT |{ tabix } Dynamic data object creation error: { err_enum->get_text( ) }| INTO TABLE str_tab.
ENDTRY. ENDTRY.
"Elementary types other than enumeration types "Elementary types other than enumerated types
ELSE. ELSE.
DATA(elem) = CAST cl_abap_elemdescr( tdo ). DATA(elem) = CAST cl_abap_elemdescr( tdo ).
@@ -2111,8 +2106,7 @@ CLASS zcl_some_class IMPLEMENTATION.
DATA(struc_components) = struc->components. DATA(struc_components) = struc->components.
INSERT |{ tabix } Components 1: | && INSERT |{ tabix } Components 1: | &&
|{ REDUCE string( INIT str = `` FOR <comp1> IN struc_components NEXT str = |{ str }| && |{ REDUCE string( INIT str = `` FOR <comp1> IN struc_components NEXT str = |{ str }| &&
|{ COND #( WHEN str IS NOT INITIAL THEN ` / ` ) }{ <comp1>-name } ({ <comp1>-type_kind })| ) }| |{ COND #( WHEN str IS NOT INITIAL THEN ` / ` ) }{ <comp1>-name } ({ <comp1>-type_kind })| ) }| INTO TABLE str_tab.
INTO TABLE str_tab.
"Structure components (more details) "Structure components (more details)
"The following method also returns a table with component information. In this case, "The following method also returns a table with component information. In this case,
@@ -2121,8 +2115,7 @@ CLASS zcl_some_class IMPLEMENTATION.
DATA(struc_components_tab) = struc->get_components( ). DATA(struc_components_tab) = struc->get_components( ).
INSERT |{ tabix } Components 2: | && INSERT |{ tabix } Components 2: | &&
|{ REDUCE string( INIT str = `` FOR <comp2> IN struc_components_tab NEXT str = |{ str }| && |{ REDUCE string( INIT str = `` FOR <comp2> IN struc_components_tab NEXT str = |{ str }| &&
|{ COND #( WHEN str IS NOT INITIAL THEN ` / ` ) }{ <comp2>-name } ({ <comp2>-type->type_kind })| ) }| |{ COND #( WHEN str IS NOT INITIAL THEN ` / ` ) }{ <comp2>-name } ({ <comp2>-type->type_kind })| ) }| INTO TABLE str_tab.
INTO TABLE str_tab.
"Checking if the structure has includes "Checking if the structure has includes
DATA(struc_has_include) = struc->has_include. DATA(struc_has_include) = struc->has_include.
@@ -2133,16 +2126,14 @@ CLASS zcl_some_class IMPLEMENTATION.
DATA(struc_incl_view) = struc->get_included_view( ). DATA(struc_incl_view) = struc->get_included_view( ).
INSERT |{ tabix } Included view: | && INSERT |{ tabix } Included view: | &&
|{ REDUCE string( INIT str = `` FOR <comp3> IN struc_incl_view NEXT str = |{ str }| && |{ REDUCE string( INIT str = `` FOR <comp3> IN struc_incl_view NEXT str = |{ str }| &&
|{ COND #( WHEN str IS NOT INITIAL THEN `, ` ) }{ <comp3>-name }| ) }| |{ COND #( WHEN str IS NOT INITIAL THEN `, ` ) }{ <comp3>-name }| ) }| INTO TABLE str_tab.
INTO TABLE str_tab.
"Returning component names of all components and substructures in included "Returning component names of all components and substructures in included
"structures that contain included structures "structures that contain included structures
DATA(struc_all_incl) = struc->get_symbols( ). DATA(struc_all_incl) = struc->get_symbols( ).
INSERT |{ tabix } Included view: | && INSERT |{ tabix } Included view: | &&
|{ REDUCE string( INIT str = `` FOR <comp4> IN struc_all_incl NEXT str = |{ str }| && |{ REDUCE string( INIT str = `` FOR <comp4> IN struc_all_incl NEXT str = |{ str }| &&
|{ COND #( WHEN str IS NOT INITIAL THEN `, ` ) }{ <comp4>-name }| ) }| |{ COND #( WHEN str IS NOT INITIAL THEN `, ` ) }{ <comp4>-name }| ) }| INTO TABLE str_tab.
INTO TABLE str_tab.
ENDIF. ENDIF.
"Checking the type compatibility of the data object "Checking the type compatibility of the data object
@@ -2203,8 +2194,7 @@ CLASS zcl_some_class IMPLEMENTATION.
INSERT |{ tabix } Table keys: { REDUCE string( INIT str = `` FOR <key2> IN tab_keys NEXT str = |{ str }| && INSERT |{ tabix } Table keys: { REDUCE string( INIT str = `` FOR <key2> IN tab_keys NEXT str = |{ str }| &&
|{ COND #( WHEN str IS NOT INITIAL THEN `, ` ) }{ REDUCE string( INIT str2 = `` FOR <key3> IN <key2>-components NEXT str2 = |{ str2 }| && |{ COND #( WHEN str IS NOT INITIAL THEN `, ` ) }{ REDUCE string( INIT str2 = `` FOR <key3> IN <key2>-components NEXT str2 = |{ str2 }| &&
|{ COND #( WHEN str2 IS NOT INITIAL THEN `/` ) }{ <key3>-name }| ) } (is primary: "{ <key2>-is_primary }", | && |{ COND #( WHEN str2 IS NOT INITIAL THEN `/` ) }{ <key3>-name }| ) } (is primary: "{ <key2>-is_primary }", | &&
|is unique: "{ <key2>-is_unique }", key kind: "{ <key2>-key_kind }", access kind: "{ <key2>-access_kind }")| ) }| |is unique: "{ <key2>-is_unique }", key kind: "{ <key2>-key_kind }", access kind: "{ <key2>-access_kind }")| ) }| INTO TABLE str_tab.
INTO TABLE str_tab.
DATA(tab_keys_aliases) = tab->get_key_aliases( ). DATA(tab_keys_aliases) = tab->get_key_aliases( ).
IF tab_keys_aliases IS NOT INITIAL. IF tab_keys_aliases IS NOT INITIAL.
@@ -2292,8 +2282,7 @@ CLASS zcl_some_class IMPLEMENTATION.
DATA(obj_ref_attributes) = obj_ref->attributes. DATA(obj_ref_attributes) = obj_ref->attributes.
INSERT |{ tabix } Attributes: { REDUCE string( INIT str = `` FOR <attr> IN obj_ref_attributes NEXT str = |{ str }| && INSERT |{ tabix } Attributes: { REDUCE string( INIT str = `` FOR <attr> IN obj_ref_attributes NEXT str = |{ str }| &&
|{ COND #( WHEN str IS NOT INITIAL THEN `, ` ) }{ <attr>-name } (vis: "{ <attr>-visibility }", static: "{ <attr>-is_class }")| ) }| |{ COND #( WHEN str IS NOT INITIAL THEN `, ` ) }{ <attr>-name } (vis: "{ <attr>-visibility }", static: "{ <attr>-is_class }")| ) }| INTO TABLE str_tab.
INTO TABLE str_tab.
"Getting the interfaces implemented "Getting the interfaces implemented
DATA(obj_ref_interfaces) = obj_ref->interfaces. DATA(obj_ref_interfaces) = obj_ref->interfaces.
@@ -2341,8 +2330,7 @@ CLASS zcl_some_class IMPLEMENTATION.
IF absolute_name CS '\CLASS=ZCL_DEMO_ABAP_OBJECTS' AND err_obj IS INITIAL. IF absolute_name CS '\CLASS=ZCL_DEMO_ABAP_OBJECTS' AND err_obj IS INITIAL.
INSERT |{ tabix } Dynamic attribute access: { REDUCE string( INIT str = `` FOR <m> IN obj_ref_attributes NEXT str = |{ str }| && INSERT |{ tabix } Dynamic attribute access: { REDUCE string( INIT str = `` FOR <m> IN obj_ref_attributes NEXT str = |{ str }| &&
|{ COND #( WHEN str IS NOT INITIAL AND <m>-visibility = 'U' THEN ` / ` ) }| && |{ COND #( WHEN str IS NOT INITIAL AND <m>-visibility = 'U' THEN ` / ` ) }| &&
|{ COND #( WHEN <m>-visibility = 'U' THEN <m>-name && ` ("` && CONV string( dyn_obj->(<m>-name) ) && `")` ) }| ) }| |{ COND #( WHEN <m>-visibility = 'U' THEN <m>-name && ` ("` && CONV string( dyn_obj->(<m>-name) ) && `")` ) }| ) }| INTO TABLE str_tab.
INTO TABLE str_tab.
ENDIF. ENDIF.
"----------------------------------------------------------------------- "-----------------------------------------------------------------------
@@ -2456,7 +2444,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"Elementary type "Elementary type
TYPES packed TYPE p LENGTH 8 DECIMALS 2. TYPES packed TYPE p LENGTH 8 DECIMALS 2.
"Enumeration type "Enumerated type
TYPES: BEGIN OF ENUM enum_type, TYPES: BEGIN OF ENUM enum_type,
enum_a, enum_a,
enum_b, enum_b,
@@ -2474,7 +2462,9 @@ CLASS zcl_some_class IMPLEMENTATION.
"Internal table types "Internal table types
TYPES int_tab_type TYPE TABLE OF i WITH EMPTY KEY. TYPES int_tab_type TYPE TABLE OF i WITH EMPTY KEY.
TYPES sorted_tab_type TYPE SORTED TABLE OF flat_struc_type WITH UNIQUE KEY a WITH NON-UNIQUE SORTED KEY sec_key ALIAS sk COMPONENTS b c. TYPES sorted_tab_type TYPE SORTED TABLE OF flat_struc_type
WITH UNIQUE KEY a
WITH NON-UNIQUE SORTED KEY sec_key ALIAS sk COMPONENTS b c.
TYPES itab_der_type TYPE TABLE FOR UPDATE zdemo_abap_rap_ro_m. TYPES itab_der_type TYPE TABLE FOR UPDATE zdemo_abap_rap_ro_m.
"Reference types "Reference types
@@ -2482,20 +2472,20 @@ CLASS zcl_some_class IMPLEMENTATION.
TYPES gen_dref_type TYPE REF TO data. TYPES gen_dref_type TYPE REF TO data.
"Class and interface names are specified directly "Class and interface names are specified directly
DATA(type_names) = VALUE string_table( ( `PACKED` ) "Elementary type (1) DATA(type_names) = VALUE string_table( ( `PACKED` ) "Elementary type (1)
( `TIMESTAMPL` ) "Elementary type, global DDIC type/data element (2) ( `TIMESTAMPL` ) "Elementary type, global DDIC type/data element (2)
( `ENUM_TYPE` ) "Enumeration type (3) ( `ENUM_TYPE` ) "Enumerated type (3)
( `FLAT_STRUC_TYPE` ) "Structured type, flat structure (4) ( `FLAT_STRUC_TYPE` ) "Structured type, flat structure (4)
( `STR_DER_TYPE` ) "Structured type, BDEF derived type (5) ( `STR_DER_TYPE` ) "Structured type, BDEF derived type (5)
( `INT_TAB_TYPE` ) "Table type, elementary line type (6) ( `INT_TAB_TYPE` ) "Table type, elementary line type (6)
( `SORTED_TAB_TYPE` ) "Table type, structured line type (7) ( `SORTED_TAB_TYPE` ) "Table type, structured line type (7)
( `ITAB_DER_TYPE` ) "Table type, BDEF derived type (8) ( `ITAB_DER_TYPE` ) "Table type, BDEF derived type (8)
( `INT_DREF_TYPE` ) "Reference type (9) ( `INT_DREF_TYPE` ) "Reference type (9)
( `GEN_DREF_TYPE` ) "Reference type, generic type (10) ( `GEN_DREF_TYPE` ) "Reference type, generic type (10)
( `CL_ABAP_TYPEDESCR` ) "Class name (11) ( `CL_ABAP_TYPEDESCR` ) "Class name (11)
( `CL_ABAP_CORRESPONDING` ) "Class name (12) ( `CL_ABAP_CORRESPONDING` ) "Class name (12)
( `IF_OO_ADT_CLASSRUN` ) "Interface name (13) ( `IF_OO_ADT_CLASSRUN` ) "Interface name (13)
( `ZDEMO_ABAP_OBJECTS_INTERFACE` ) "Interface name (14) ( `ZDEMO_ABAP_OBJECTS_INTERFACE` ) "Interface name (14)
). ).
LOOP AT type_names INTO DATA(type_name). LOOP AT type_names INTO DATA(type_name).
@@ -2542,7 +2532,8 @@ ENDCLASS.
#### Excursion: Inline Declaration, CAST Operator, Method Chaining #### Excursion: Inline Declaration, CAST Operator, Method Chaining
As shown in the example above, you can use inline declaration, the `CAST` operator for casting, and method chaining to write more concise code and avoid declaring helper variables. However, also consider the code's debuggability, maintainability, and readability. As shown in the example above, you can use [inline declarations](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninline_declaration_glosry.htm "Glossary Entry"), the [`CAST`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_cast.htm) operator for casting, and [method chaining](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenmethod_chaining_glosry.htm "Glossary Entry") to write more concise code and avoid declaring helper variables. However, also consider the code's debuggability, maintainability, and readability.
```abap ```abap
DATA some_struc TYPE zdemo_abap_carr. DATA some_struc TYPE zdemo_abap_carr.

View File

@@ -1,451 +1,421 @@
<a name="top"></a> <a name="top"></a>
# ABAP Managed Database Procedures (AMDP) # ABAP Managed Database Procedures (AMDP)
- [ABAP Managed Database Procedures (AMDP)](#abap-managed-database-procedures-amdp) - [ABAP Managed Database Procedures (AMDP)](#abap-managed-database-procedures-amdp)
- [Introduction](#introduction) - [Introduction](#introduction)
- [AMDP Classes](#amdp-classes) - [AMDP Classes](#amdp-classes)
- [AMDP Methods](#amdp-methods) - [AMDP Methods](#amdp-methods)
- [AMDP Procedures](#amdp-procedures) - [AMDP Procedures](#amdp-procedures)
- [AMDP Functions](#amdp-functions) - [AMDP Functions](#amdp-functions)
- [CDS Table Functions](#cds-table-functions) - [CDS Table Functions](#cds-table-functions)
- [More Information](#more-information) - [More Information](#more-information)
- [Executable Example](#executable-example) - [Executable Example](#executable-example)
This cheat sheet gathers basic information on [ABAP Managed Database This cheat sheet gathers basic information on [ABAP Managed Database
Procedures Procedures
(AMDP)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_managed_db_proc_glosry.htm "Glossary Entry"). (AMDP)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_managed_db_proc_glosry.htm "Glossary Entry").
Find more details Find more details
[here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp.htm) [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp.htm)
in the ABAP Keyword Documentation. in the ABAP Keyword Documentation.
## Introduction ## Introduction
- AMDP are a class-based framework for managing and calling - AMDP are a class-based framework for managing and calling
- [database - [database
procedures](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendatabase_procedure_glosry.htm "Glossary Entry") procedures](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendatabase_procedure_glosry.htm "Glossary Entry")
(which is a synonym for [stored (which is a synonym for [stored
procedures](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstored_procedure_glosry.htm "Glossary Entry"), i. procedures](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstored_procedure_glosry.htm "Glossary Entry"), i.
e. the procedures are stored in the database - the [SAP HANA e. the procedures are stored in the database - the [SAP HANA
database](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenhana_database_glosry.htm "Glossary Entry") database](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenhana_database_glosry.htm "Glossary Entry")
in this case - and executed there) in this case - and executed there)
- [database - [database
functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendatabase_function_glosry.htm "Glossary Entry") functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendatabase_function_glosry.htm "Glossary Entry")
(which are [SQLScript (which are [SQLScript
functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_script_function_glosry.htm "Glossary Entry") functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_script_function_glosry.htm "Glossary Entry")
in the SAP HANA database) in the SAP HANA database)
in [AS ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenas_abap_glosry.htm "Glossary Entry"). in [AS ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenas_abap_glosry.htm "Glossary Entry").
- "ABAP managed" enters the picture in ABAP with the option of - "ABAP managed" enters the picture in ABAP with the option of
implementing special [AMDP implementing special [AMDP
procedures](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_procedure_glosry.htm "Glossary Entry") procedures](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_procedure_glosry.htm "Glossary Entry")
as database procedures and [AMDP as database procedures and [AMDP
functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_function_glosry.htm "Glossary Entry") functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_function_glosry.htm "Glossary Entry")
as database functions. as database functions.
- The implementations are programmed using a database-specific - The implementations are programmed using a database-specific
language. Currently, AMDP only supports database procedures and language. Currently, AMDP only supports database procedures and
functions from the SAP HANA database. That is, functions from the SAP HANA database. That is,
[SQLScript](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_script_glosry.htm "Glossary Entry") [SQLScript](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_script_glosry.htm "Glossary Entry")
is the programming language of choice. is the programming language of choice.
- AMDP procedures and functions are part of a dedicated [AMDP - AMDP procedures and functions are part of a dedicated [AMDP
class](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_class_glosry.htm "Glossary Entry") class](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_class_glosry.htm "Glossary Entry")
and declared and implemented as part of a method. The classes and and declared and implemented as part of a method. The classes and
methods have certain characteristics as outlined further down. methods have certain characteristics as outlined further down.
- The AMDP framework replicates the procedure or function to the - The AMDP framework replicates the procedure or function to the
database system, i. e. despite the fact that the programming happens database system, i. e. despite the fact that the programming happens
in an AMDP class (which is an [ABAP in an AMDP class (which is an [ABAP
Repository](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_repository_glosry.htm "Glossary Entry") Repository](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_repository_glosry.htm "Glossary Entry")
object as other global classes, too), the (SQLScript) code is object as other global classes, too), the (SQLScript) code is
executed only on the (SAP HANA) database and not in AS ABAP, i. e. executed only on the (SAP HANA) database and not in AS ABAP, i. e.
method calls are sent to the database procedure or function. method calls are sent to the database procedure or function.
> **💡 Note**<br> > **💡 Note**<br>
>- The use of AMDP is not recommended if the same task can be >- The use of AMDP is not recommended if the same task can be
achieved using [ABAP achieved using [ABAP
SQL](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql_glosry.htm "Glossary Entry"). SQL](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql_glosry.htm "Glossary Entry").
>- AMDP classes can only be edited with the [ABAP development tools for Eclipse >- AMDP classes can only be edited with the [ABAP development tools for Eclipse
(ADT)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenadt_glosry.htm "Glossary Entry"). (ADT)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenadt_glosry.htm "Glossary Entry").
<p align="right"><a href="#top">⬆️ back to top</a></p> <p align="right"><a href="#top">⬆️ back to top</a></p>
## AMDP Classes ## AMDP Classes
- As mentioned above, an [AMDP - As mentioned above, an [AMDP
class](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_class_glosry.htm "Glossary Entry") class](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_class_glosry.htm "Glossary Entry")
is an [ABAP is an [ABAP
Repository](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_repository_glosry.htm "Glossary Entry") Repository](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_repository_glosry.htm "Glossary Entry")
object like other global classes. object like other global classes.
- However, an AMDP class includes the specification of the interface - However, an AMDP class includes the specification of the interface
`IF_AMDP_MARKER_HDB` for the SAP HANA `IF_AMDP_MARKER_HDB` for the SAP HANA
database (indicated by `HDB`), which is currently the database (indicated by `HDB`), which is currently the
only possible database. only possible database.
- An AMDP class can contain both (one or more) [AMDP - An AMDP class can contain both (one or more) [AMDP
methods](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_method_glosry.htm "Glossary Entry") methods](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_method_glosry.htm "Glossary Entry")
and non-AMDP methods. and non-AMDP methods.
Example for a [declaration part](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendeclaration_part_glosry.htm "Glossary Entry") Example for a [declaration part](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendeclaration_part_glosry.htm "Glossary Entry")
of an AMDP class: of an AMDP class:
```abap ```abap
CLASS cl_some_amdp_class DEFINITION CLASS cl_some_amdp_class DEFINITION
  PUBLIC   PUBLIC
  FINAL   FINAL
  CREATE PUBLIC.   CREATE PUBLIC.
  PUBLIC SECTION.   PUBLIC SECTION.
    "Specifying the interface is mandatory     "Specifying the interface is mandatory
INTERFACES if_amdp_marker_hdb. INTERFACES if_amdp_marker_hdb.
... ...
ENDCLASS. ENDCLASS.
``` ```
<p align="right"><a href="#top">⬆️ back to top</a></p> <p align="right"><a href="#top">⬆️ back to top</a></p>
## AMDP Methods ## AMDP Methods
- Can be created as [instance - Can be created as [instance
methods](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninstance_method_glosry.htm "Glossary Entry") methods](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninstance_method_glosry.htm "Glossary Entry")
using <code>METHODS</code> or [static using <code>METHODS</code> or [static
methods](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstatic_method_glosry.htm "Glossary Entry") methods](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstatic_method_glosry.htm "Glossary Entry")
using <code>CLASS-METHODS</code> in any visibility section. using <code>CLASS-METHODS</code> in any visibility section.
- Cannot be identified as AMDP methods in the declaration part of the - Cannot be identified as AMDP methods in the declaration part of the
class since there are no specific additions to the methods. class since there are no specific additions to the methods.
Exceptions: AMDP function implementations that implement any [CDS table functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_table_function_glosry.htm "Glossary Entry") Exceptions: AMDP function implementations that implement any [CDS table functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_table_function_glosry.htm "Glossary Entry")
as shown further down and method declarations using [`AMDP as shown further down and method declarations using [`AMDP
OPTIONS`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmethods_amdp_options.htm) OPTIONS`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmethods_amdp_options.htm)
that are not dealt with here. that are not dealt with here.
AMDP method declarations in any visibility section like non-AMDP AMDP method declarations in any visibility section like non-AMDP
methods: methods:
```abap ```abap
... ...
PUBLIC SECTION. PUBLIC SECTION.
METHODS some_amdp_meth METHODS some_amdp_meth
    ... "Here go the parameters     ... "Here go the parameters
PRIVATE SECTION. PRIVATE SECTION.
CLASS-METHODS another_amdp_meth CLASS-METHODS another_amdp_meth
    ... "Here go the parameters     ... "Here go the parameters
... ...
``` ```
<p align="right"><a href="#top">⬆️ back to top</a></p> <p align="right"><a href="#top">⬆️ back to top</a></p>
## AMDP Procedures ## AMDP Procedures
Despite the fact that AMDP methods cannot be identified as such from the Despite the fact that AMDP methods cannot be identified as such from the
[declaration [declaration
part](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendeclaration_part_glosry.htm "Glossary Entry") part](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendeclaration_part_glosry.htm "Glossary Entry")
(apart from the exceptions mentioned above), the declaration part of (apart from the exceptions mentioned above), the declaration part of
[AMDP [AMDP
procedures](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_procedure_glosry.htm "Glossary Entry") procedures](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_procedure_glosry.htm "Glossary Entry")
has special characteristics: has special characteristics:
- Parameters must be [passed by - Parameters must be [passed by
value](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenpass_by_value_glosry.htm "Glossary Entry") value](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenpass_by_value_glosry.htm "Glossary Entry")
using <code>VALUE(...)</code>. [Passing by using <code>VALUE(...)</code>. [Passing by
reference](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenpass_by_reference_glosry.htm "Glossary Entry") reference](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenpass_by_reference_glosry.htm "Glossary Entry")
is not allowed. is not allowed.
- Parameter types ... - Parameter types ...
- must not be generic. - must not be generic.
- can only be [elementary data - can only be [elementary data
types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenelementary_data_type_glosry.htm "Glossary Entry") types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenelementary_data_type_glosry.htm "Glossary Entry")
and [table and [table
types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentable_type_glosry.htm "Glossary Entry") types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentable_type_glosry.htm "Glossary Entry")
with a structured row type (and this type can only contain with a structured row type (and this type can only contain
elementary data types as components). elementary data types as components).
- Return values cannot be declared using <code>RETURNING</code>. - Return values cannot be declared using <code>RETURNING</code>.
- Only input parameters can be flagged as optional parameters. - Only input parameters can be flagged as optional parameters.
Example for an AMDP procedure's declaration part: Example for an AMDP procedure's declaration part:
```abap ```abap
... ...
PUBLIC SECTION. PUBLIC SECTION.
  "Table type with a structured row type   "Table type with a structured row type
TYPES tab_type TYPE STANDARD TABLE OF dbtab WITH EMPTY KEY. TYPES tab_type TYPE STANDARD TABLE OF dbtab WITH EMPTY KEY.
METHODS amdp_meth METHODS amdp_meth
IMPORTING VALUE(num) TYPE i, IMPORTING VALUE(num) TYPE i,
EXPORTING VALUE(tab) TYPE tab_type. EXPORTING VALUE(tab) TYPE tab_type.
... ...
``` ```
In contrast to the declaration part, the [implementation In contrast to the declaration part, the [implementation
part](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_procedure_method_glosry.htm "Glossary Entry") part](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_procedure_method_glosry.htm "Glossary Entry")
of an AMDP method has multiple special additions for AMDP purposes of an AMDP method has multiple special additions for AMDP purposes
following <code>METHOD</code> and the method name: following <code>METHOD</code> and the method name:
```abap ```abap
... ...
METHOD amdp_meth METHOD amdp_meth
BY DATABASE PROCEDURE BY DATABASE PROCEDURE
FOR HDB   FOR HDB  
LANGUAGE SQLSCRIPT   LANGUAGE SQLSCRIPT  
OPTIONS READ-ONLY OPTIONS READ-ONLY
USING db_object. "see comments further down USING db_object. "see comments further down
                                     
"Beginning of the SQLScript code (note that it is not ABAP code although it looks similar) "Beginning of the SQLScript code (note that it is not ABAP code although it looks similar)
  ... "Here goes SQLScript code   ... "Here goes SQLScript code
      "Note that an AMDP method implementation must not be empty.       "Note that an AMDP method implementation must not be empty.
"End of the SQLScript code "End of the SQLScript code
ENDMETHOD. ENDMETHOD.
... ...
"Comments: "Comments:
" BY DATABASE PROCEDURE -> Flags the AMDP method as AMDP procedure " BY DATABASE PROCEDURE -> Flags the AMDP method as AMDP procedure
" FOR HDB   -> Definess the database system where the method is to be used; " FOR HDB   -> Definess the database system where the method is to be used;
"             currently, only HDB (SAP HANA database) is possible "             currently, only HDB (SAP HANA database) is possible
" LANGUAGE SQLSCRIPT   -> Defines the programming language of the database system " LANGUAGE SQLSCRIPT   -> Defines the programming language of the database system
" OPTIONS READ-ONLY -> Specifies database-specific options " OPTIONS READ-ONLY -> Specifies database-specific options
" USING db_object. -> Optional addition; specifies database objects; " USING db_object. -> Optional addition; specifies database objects;
"                    can also be AMDP procedures and functions "                    can also be AMDP procedures and functions
``` ```
Note: Note:
- In the [restricted ABAP language - In the [restricted ABAP language
version](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrestricted_version_glosry.htm "Glossary Entry") version](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrestricted_version_glosry.htm "Glossary Entry")
scope, only reads are allowed. Hence, the addition `OPTIONS READ-ONLY` is mandatory. Furthermore, you must make sure scope, only reads are allowed. Hence, the addition `OPTIONS READ-ONLY` is mandatory. Furthermore, you must make sure
that the database objects that are specified after `USING` are accessible. that the database objects that are specified after `USING` are accessible.
- Generally, in the [unrestricted ABAP language - Generally, in the [unrestricted ABAP language
version](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenunrestricted_version_glosry.htm "Glossary Entry") version](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenunrestricted_version_glosry.htm "Glossary Entry")
scope ([ABAP for Cloud Development](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_for_sap_cloud_glosry.htm)), more syntax options are allowed for AMDP method declaration scope ([ABAP for Cloud Development](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_for_sap_cloud_glosry.htm)), more syntax options are allowed for AMDP method declaration
and implementation parts. Check the ABAP Keyword Documentation for and implementation parts. Check the ABAP Keyword Documentation for
more details as covered further down. more details as covered further down.
<p align="right"><a href="#top">⬆️ back to top</a></p> <p align="right"><a href="#top">⬆️ back to top</a></p>
## AMDP Functions ## AMDP Functions
[Scalar](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_scalar_function_glosry.htm "Glossary Entry") [Scalar](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_scalar_function_glosry.htm "Glossary Entry")
and [table and [table
functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentable_function_glosry.htm "Glossary Entry") functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentable_function_glosry.htm "Glossary Entry")
can be managed as [AMDP can be managed as [AMDP
functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_function_glosry.htm "Glossary Entry"). functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_function_glosry.htm "Glossary Entry").
Such [AMDP table Such [AMDP table
functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_table_function_glosry.htm "Glossary Entry") functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_table_function_glosry.htm "Glossary Entry")
have, as the name implies, a tabular [return have, as the name implies, a tabular [return
value](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreturn_value_glosry.htm "Glossary Entry") value](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreturn_value_glosry.htm "Glossary Entry")
whereas AMDP scalar functions have a scalar or elementary return value whereas AMDP scalar functions have a scalar or elementary return value
(more information (more information
[here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_function_methods.htm)). [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_function_methods.htm)).
Regarding AMDP table functions, there are two types available: Regarding AMDP table functions, there are two types available:
- Functions that can only be accessed in other AMDP methods (i. e. - Functions that can only be accessed in other AMDP methods (i. e.
other AMDP functions or procedures) and cannot be called directly in other AMDP functions or procedures) and cannot be called directly in
ABAP ABAP
- Functions that implement [CDS table - Functions that implement [CDS table
functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_table_function_glosry.htm "Glossary Entry") functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_table_function_glosry.htm "Glossary Entry")
that can be accessed in ABAP SQL that can be accessed in ABAP SQL
Characteristics of method declaration parts of AMDP functions: Characteristics of method declaration parts of AMDP functions:
- Similar to AMDP procedures, the methods can be declared as static or - Similar to AMDP procedures, the methods can be declared as static or
instance methods in any visibility section. instance methods in any visibility section.
- The method parameters must include a return value using - The method parameters must include a return value using
<code>RETURNING</code> and having a tabular data type. <code>RETURNING</code> and having a tabular data type.
- Additionally, the parameters can include elementary and tabular - Additionally, the parameters can include elementary and tabular
input parameters. input parameters.
- No class-based exceptions can be declared using <code>RAISING</code>. - No class-based exceptions can be declared using <code>RAISING</code>.
Example for an AMDP function's declaration part: Example for an AMDP function's declaration part:
```abap ```abap
... ...
PUBLIC SECTION. PUBLIC SECTION.
  "Table type with a structured row type   "Table type with a structured row type
TYPES tab_type TYPE STANDARD TABLE OF dbtab WITH EMPTY KEY. TYPES tab_type TYPE STANDARD TABLE OF dbtab WITH EMPTY KEY.
METHODS amdp_func METHODS amdp_func
IMPORTING VALUE(num)       TYPE i, IMPORTING VALUE(num)       TYPE i,
VALUE(some_elem) TYPE c LENGTH 3, VALUE(some_elem) TYPE c LENGTH 3,
RETURNING VALUE(tab)       TYPE tab_type. RETURNING VALUE(tab)       TYPE tab_type.
... ...
``` ```
The implementation part of an AMDP function is similar to the one of The implementation part of an AMDP function is similar to the one of
AMDP procedure as shown above. The difference is the use of `BY DATABASE FUNCTION` instead of `BY DATABASE PROCEDURE`: AMDP procedure as shown above. The difference is the use of `BY DATABASE FUNCTION` instead of `BY DATABASE PROCEDURE`:
```abap ```abap
... ...
METHOD amdp_func METHOD amdp_func
BY DATABASE FUNCTION     BY DATABASE FUNCTION    
FOR HDB FOR HDB
LANGUAGE SQLSCRIPT LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY OPTIONS READ-ONLY
USING db_object. USING db_object.
"Beginning of the SQLScript code (note that it is not ABAP code although it looks similar) "Beginning of the SQLScript code (note that it is not ABAP code although it looks similar)
  ... "Here goes SQLScript code;   ... "Here goes SQLScript code;
      "AMDP table function to be called by other AMDP methods only       "AMDP table function to be called by other AMDP methods only
"End of the SQLScript code "End of the SQLScript code
ENDMETHOD. ENDMETHOD.
"Comment: "Comment:
"  BY DATABASE FUNCTION    -> Flags the AMDP method as AMDP function "  BY DATABASE FUNCTION    -> Flags the AMDP method as AMDP function
... ...
``` ```
<p align="right"><a href="#top">⬆️ back to top</a></p> <p align="right"><a href="#top">⬆️ back to top</a></p>
### CDS Table Functions ### CDS Table Functions
- Each [CDS table - Each [CDS table
function](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_table_function_glosry.htm "Glossary Entry") function](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_table_function_glosry.htm "Glossary Entry")
is linked with an AMDP function in which it is implemented using is linked with an AMDP function in which it is implemented using
SQLScript. SQLScript.
- Can be used as data sources of ABAP SQL read statements. - Can be used as data sources of ABAP SQL read statements.
- Characteristics for method declaration and implementation parts - Characteristics for method declaration and implementation parts
regarding AMDP functions for CDS table functions: regarding AMDP functions for CDS table functions:
- Method can only be declared as a static method in the public visibility section of - Method can only be declared as a static method in the public visibility section of
an AMDP class using `CLASS-METHODS`. an AMDP class using `CLASS-METHODS`.
- For the declaration, there is a special form with the addition - For the declaration, there is a special form with the addition
`FOR TABLE FUNCTION`. `FOR TABLE FUNCTION`.
- The [parameter - The [parameter
interface](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenparameter_interface_glosry.htm "Glossary Entry") interface](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenparameter_interface_glosry.htm "Glossary Entry")
is not specified. Instead, the input parameters are determined is not specified. Instead, the input parameters are determined
by the [input by the [input
parameters](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninput_parameter_glosry.htm "Glossary Entry") parameters](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninput_parameter_glosry.htm "Glossary Entry")
of the CDS table function (i. e. the names and data types - of the CDS table function (i. e. the names and data types -
which are always elementary - specified there are used). As the which are always elementary - specified there are used). As the
return value, a standard table with an empty key is generated return value, a standard table with an empty key is generated
based on the structured row type including the components as based on the structured row type including the components as
specified in the CDS table function. specified in the CDS table function.
Example for an AMDP functions declaration implementing a CDS table Example for an AMDP functions declaration implementing a CDS table
function: function:
```abap ```abap
... ...
PUBLIC SECTION. PUBLIC SECTION.
CLASS-METHODS: CLASS-METHODS:
table_func FOR TABLE FUNCTION some_ddl_source. table_func FOR TABLE FUNCTION some_ddl_source.
... ...
``` ```
Notes on the [CDS Notes on the [CDS
DDL](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_ddl_glosry.htm "Glossary Entry") DDL](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_ddl_glosry.htm "Glossary Entry")
source of a CDS table function: source of a CDS table function:
- You have defined (and activated) a CDS DDL source, i. e. a [CDS - You have defined (and activated) a CDS DDL source, i. e. a [CDS
entity](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_entity_glosry.htm "Glossary Entry"), entity](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_entity_glosry.htm "Glossary Entry"),
with the notation `DEFINE TABLE FUNCTION` with the notation `DEFINE TABLE FUNCTION`
- You can specify optional input parameters using `... WITH PARAMETERS parameter1, parameter2, ...` - You can specify optional input parameters using `... WITH PARAMETERS parameter1, parameter2, ...`
- You must specify an element list using `... RETURNS { element1; element2; ...; } ...`. The elements determine the - You must specify an element list using `... RETURNS { element1; element2; ...; } ...`. The elements determine the
components of the structured data type represented by a CDS table components of the structured data type represented by a CDS table
function. function.
- You have specified the `IMPLEMENTED BY METHOD` addition - You have specified the `IMPLEMENTED BY METHOD` addition
followed by a fully qualified method name in the form of followed by a fully qualified method name in the form of
`amdp_class=>amdp_method` using the names of the AMDP `amdp_class=>amdp_method` using the names of the AMDP
class and method. class and method.
- More information - More information
[here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_table_functions.htm). [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_table_functions.htm).
The CDS DDL source might look like this: The CDS DDL source might look like this:
``` ```
//Here go annotations. //Here go annotations.
define table function some_ddl_source define table function some_ddl_source
  returns   returns
  {   {
    client : abap.clnt;     client : abap.clnt;
    field1 : abap.char(5);     field1 : abap.char(5);
    field2 : abap.char(5);     field2 : abap.char(5);
  }   }
  implemented by method amdp_class=>amdp_method;   implemented by method amdp_class=>amdp_method;
``` ```
You can then use the CDS table function as source for a You can then use the CDS table function as source for a
`SELECT` statement, for example: `SELECT * FROM some_ddl_source INTO ...`. `SELECT` statement, for example: `SELECT * FROM some_ddl_source INTO ...`.
<p align="right"><a href="#top">⬆️ back to top</a></p> <p align="right"><a href="#top">⬆️ back to top</a></p>
## More Information ## More Information
Notes on using AMDP in environments with restricted language version (in **... on AMDP in ABAP for Cloud Development**
contrast unrestricted language version):
Find more information in the subtopics of the [ABAP Keyword Documentation (ABAP for Cloud Development)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp.htm).
AMDP methods ...
> **💡 Note**<br>
- must include the addition <code>OPTIONS READ-ONLY</code> in the > - In ABAP for Cloud Development, AMDP methods must be client-safe. This means that the SQLScript code should only access artifacts that restrict access to a single client, such as CDS view entities, or are client-independent. Therefore, all objects used in the `USING` list must be client-safe. This also applies to CDS table functions implemented as AMDP methods. Accessing client-dependent data using methods like Native SQL is not supported in ABAP for Cloud Development.
declaration part. > - The AMDP example for ABAP for Cloud Development is designed differently compared to the AMDP example for Standard ABAP. Instead of using demo database tables, CDS view entities are used in the `USING` list. Additionally, the client handling is adjusted for the AMDP methods by including appropriate additions in the AMDP method declaration part.
- must be implemented in SQLScript in any case.
- cannot use the additions [`USING SCHEMA` (F1 documentation for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapmethod_by_db_proc.htm#!ABAP_ADDITION_5@5@) **... on AMDP in Standard ABAP**
and [`SUPPRESS SYNTAX ERRORS` (F1 documentation for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapmethod_by_db_proc.htm#!ABAP_ADDITION_3@3@)
in the method implementation part Find more information in the subtopics of the [ABAP Keyword Documentation (Standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenamdp.htm).
- cannot use [AMDP
macros](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_macros.htm) > **✔️ Hint**<br>
and call hints. > Checking if AMDP is supported on the system:
- can only use your own entities and entities that are released for > ```abap
the restricted language version after <code>USING</code>. > IF NOT cl_abap_dbfeatures=>use_features(
- cannot use > EXPORTING requested_features =
[`CONNECTION` (F1 documentation for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenamdp_db_connections.htm) > VALUE #( ( cl_abap_dbfeatures=>call_amdp_method ) ) ).
parameters. >
- cannot raise the >   "Result: Current database system does not support AMDP procedures
`CX_AMDP_CONNECTION_ERROR` exception since > RETURN.
the `CONNECTION` parameter is not allowed. > ENDIF.
> ```
As mentioned above and hinted in the bullet points above, AMDP has more
options regarding the unrestricted language version. Check the subtopics <p align="right"><a href="#top">⬆️ back to top</a></p>
[here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp.htm).
A fundamental question in [classic ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassic_abap_glosry.htm) with an unrestricted ## Executable Example
language scope can be whether AMDP is supported at all. The constant
`CALL_AMDP_METHOD` of the class [zcl_demo_abap_amdp](./src/zcl_demo_abap_amdp.clas.abap)
`CL_ABAP_DBFEATURES` can be used to query
whether the current database supports AMDP methods. See the following > **💡 Note**<br>
snippet: > - The executable example covers the following topics:
> - AMDP procedures, calling AMDP procedures from SQLScript
```abap > - AMDP table functions for AMDP methods
IF NOT cl_abap_dbfeatures=>use_features( > - AMDP table functions for CDS table functions
EXPORTING requested_features = > - The steps to import and run the code are outlined [here](README.md#-getting-started-with-the-examples).
VALUE #( ( cl_abap_dbfeatures=>call_amdp_method ) ) ).
  "Result: Current database system does not support AMDP procedures
RETURN.
ENDIF.
```
This check is not required (and possible) for [ABAP Cloud](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_cloud_glosry.htm) since it is SAP HANA-only anyway and database connections are not
possible. Furthermore, another topic that should be noted is that AMDP
does not support [implicit client
handling](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql_client_handling.htm).
Therefore, the parameter interface of AMDP methods usually contains an
input parameter for the client ID. See more information
[here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_client_handling.htm) (or [here for the F1 docu for standard ABAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenamdp_client_handling.htm)).
The client handling is not dealt with in this cheat sheet and not
relevant in the executable example.
<p align="right"><a href="#top">⬆️ back to top</a></p>
## Executable Example
[zcl_demo_abap_amdp](./src/zcl_demo_abap_amdp.clas.abap)
> **💡 Note**<br>
> - The executable example ...
> - covers the following topics:
> - AMDP procedures, calling AMDP procedures from SQLScript
> - AMDP table functions for AMDP methods
> - AMDP table functions for CDS table functions
> - The steps to import and run the code are outlined [here](README.md#-getting-started-with-the-examples).
> - [Disclaimer](README.md#%EF%B8%8F-disclaimer) > - [Disclaimer](README.md#%EF%B8%8F-disclaimer)

View File

@@ -59,17 +59,17 @@ CLASS zcl_demo_abap_amdp DEFINITION
"Various internal table type specifications for the parameters of AMDP methods "Various internal table type specifications for the parameters of AMDP methods
"Note: Only table and elementary data types are possible for the parameters. "Note: Only table and elementary data types are possible for the parameters.
TYPES carr_tab TYPE STANDARD TABLE OF zdemo_abap_carr WITH EMPTY KEY. TYPES carr_tab TYPE STANDARD TABLE OF zdemo_abap_carr_ve WITH EMPTY KEY.
TYPES fli_tab TYPE STANDARD TABLE OF zdemo_abap_fli WITH EMPTY KEY. TYPES fli_tab TYPE STANDARD TABLE OF zdemo_abap_fli_ve WITH EMPTY KEY.
TYPES: TYPES:
"Structured data type as basis for the table type below "Structured data type as basis for the table type below
BEGIN OF carr_fli_struc, BEGIN OF carr_fli_struc,
carrname TYPE zdemo_abap_carr-carrname, carrname TYPE zdemo_abap_carr_ve-carrname,
connid TYPE zdemo_abap_flsch-connid, connid TYPE zdemo_abap_flsch_ve-connid,
cityfrom TYPE zdemo_abap_flsch-cityfrom, cityfrom TYPE zdemo_abap_flsch_ve-cityfrom,
cityto TYPE zdemo_abap_flsch-cityto, cityto TYPE zdemo_abap_flsch_ve-cityto,
END OF carr_fli_struc, END OF carr_fli_struc,
"Internal table type "Internal table type
@@ -77,15 +77,15 @@ CLASS zcl_demo_abap_amdp DEFINITION
"Structured data type as basis for the table type below "Structured data type as basis for the table type below
BEGIN OF fli_struc, BEGIN OF fli_struc,
carrid TYPE zdemo_abap_flsch-carrid, carrid TYPE zdemo_abap_flsch_ve-carrid,
connid TYPE zdemo_abap_flsch-connid, connid TYPE zdemo_abap_flsch_ve-connid,
cityfrom TYPE zdemo_abap_flsch-cityfrom, cityfrom TYPE zdemo_abap_flsch_ve-cityfrom,
cityto TYPE zdemo_abap_flsch-cityto, cityto TYPE zdemo_abap_flsch_ve-cityto,
fltime TYPE zdemo_abap_flsch-fltime, fltime TYPE zdemo_abap_flsch_ve-fltime,
END OF fli_struc, END OF fli_struc,
"Internal table type "Internal table type
flsch_tab TYPE STANDARD TABLE OF zdemo_abap_flsch WITH EMPTY KEY. flsch_tab TYPE STANDARD TABLE OF zdemo_abap_flsch_ve WITH EMPTY KEY.
"Various instance method declarations "Various instance method declarations
"The selection for instance and static methods is irrelevant for the example. "The selection for instance and static methods is irrelevant for the example.
@@ -96,6 +96,7 @@ CLASS zcl_demo_abap_amdp DEFINITION
"Note the parameter declaration that includes the mandatory passing by value. "Note the parameter declaration that includes the mandatory passing by value.
"This is true for all of the AMDP method declarations. "This is true for all of the AMDP method declarations.
METHODS select_carriers METHODS select_carriers
AMDP OPTIONS READ-ONLY CDS SESSION CLIENT dependent
EXPORTING VALUE(carr_tab) TYPE carr_tab. EXPORTING VALUE(carr_tab) TYPE carr_tab.
"AMDP procedure to call an AMDP table function "AMDP procedure to call an AMDP table function
@@ -103,7 +104,8 @@ CLASS zcl_demo_abap_amdp DEFINITION
"AMDP table function get_carr_fli. AMDP table functions can only be called "AMDP table function get_carr_fli. AMDP table functions can only be called
"by other AMDP methods. "by other AMDP methods.
METHODS select_get_carr_fli METHODS select_get_carr_fli
IMPORTING VALUE(carrid) TYPE zdemo_abap_fli-carrid AMDP OPTIONS READ-ONLY CDS SESSION CLIENT dependent
IMPORTING VALUE(carrid) TYPE zdemo_abap_fli_ve-carrid
EXPORTING VALUE(carr_fli_tab) TYPE carr_fli_tab. EXPORTING VALUE(carr_fli_tab) TYPE carr_fli_tab.
"Various static method declarations "Various static method declarations
@@ -118,7 +120,8 @@ CLASS zcl_demo_abap_amdp DEFINITION
"in the same AMDP class. The method declaration includes the addition RAISING with an "in the same AMDP class. The method declaration includes the addition RAISING with an
"exception class for AMDP-specific exceptions. "exception class for AMDP-specific exceptions.
CLASS-METHODS get_flights CLASS-METHODS get_flights
IMPORTING VALUE(carrid) TYPE zdemo_abap_fli-carrid AMDP OPTIONS READ-ONLY CDS SESSION CLIENT dependent
IMPORTING VALUE(carrid) TYPE zdemo_abap_fli_ve-carrid
EXPORTING VALUE(fli_tab) TYPE fli_tab EXPORTING VALUE(fli_tab) TYPE fli_tab
RAISING cx_amdp_execution_error. RAISING cx_amdp_execution_error.
@@ -134,7 +137,8 @@ CLASS zcl_demo_abap_amdp DEFINITION
"AMDP procedure "AMDP procedure
"This method demonstrates the calling of an AMDP procedure from SQLScript as mentioned above. "This method demonstrates the calling of an AMDP procedure from SQLScript as mentioned above.
CLASS-METHODS get_flights_amdp CLASS-METHODS get_flights_amdp
IMPORTING VALUE(carrid) TYPE zdemo_abap_fli-carrid AMDP OPTIONS READ-ONLY CDS SESSION CLIENT dependent
IMPORTING VALUE(carrid) TYPE zdemo_abap_fli_ve-carrid
EXPORTING VALUE(fli_tab) TYPE fli_tab EXPORTING VALUE(fli_tab) TYPE fli_tab
RAISING cx_amdp_execution_error. RAISING cx_amdp_execution_error.
@@ -142,15 +146,16 @@ CLASS zcl_demo_abap_amdp DEFINITION
"AMDP table functions can only be called by other AMDP methods. In this example, "AMDP table functions can only be called by other AMDP methods. In this example,
"the AMDP procedure select_get_carr_fli calls this AMDP table function. "the AMDP procedure select_get_carr_fli calls this AMDP table function.
METHODS get_carr_fli METHODS get_carr_fli
IMPORTING VALUE(carrid) TYPE zdemo_abap_flsch-carrid AMDP OPTIONS READ-ONLY CDS SESSION CLIENT dependent
IMPORTING VALUE(carrid) TYPE zdemo_abap_flsch_ve-carrid
RETURNING VALUE(carr_fli_tab) TYPE carr_fli_tab. RETURNING VALUE(carr_fli_tab) TYPE carr_fli_tab.
CONSTANTS nl TYPE string value cl_abap_char_utilities=>newline. CONSTANTS nl TYPE string VALUE cl_abap_char_utilities=>newline.
ENDCLASS. ENDCLASS.
CLASS ZCL_DEMO_ABAP_AMDP IMPLEMENTATION. CLASS zcl_demo_abap_amdp IMPLEMENTATION.
METHOD class_constructor. METHOD class_constructor.
@@ -164,26 +169,26 @@ CLASS ZCL_DEMO_ABAP_AMDP IMPLEMENTATION.
FOR HDB FOR HDB
LANGUAGE SQLSCRIPT LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY OPTIONS READ-ONLY
USING zdemo_abap_flsch "Two database tables are used and must both be specified here. USING zdemo_abap_flsch_ve
zdemo_abap_carr. zdemo_abap_carr_ve.
* Reading data from two database tables * Reading data from two CDS view entities
itab_cities = itab_cities =
select DISTINCT select DISTINCT
zdemo_abap_flsch.mandt as client, zdemo_abap_flsch_ve.mandt as client,
zdemo_abap_flsch.carrid as carrier_id, zdemo_abap_flsch_ve.carrid as carrier_id,
zdemo_abap_flsch.airpfrom as airport_from, zdemo_abap_flsch_ve.airpfrom as airport_from,
zdemo_abap_flsch.airpto as airport_to, zdemo_abap_flsch_ve.airpto as airport_to,
zdemo_abap_flsch.fltime as flight_time, zdemo_abap_flsch_ve.fltime as flight_time,
zdemo_abap_flsch.distance as flight_distance, zdemo_abap_flsch_ve.distance as flight_distance,
zdemo_abap_flsch.distid as unit zdemo_abap_flsch_ve.distid as unit
from zdemo_abap_flsch; from zdemo_abap_flsch_ve;
itab_carrier_names = itab_carrier_names =
select distinct select distinct
zdemo_abap_carr.mandt as client, zdemo_abap_carr_ve.mandt as client,
zdemo_abap_carr.carrid as carrier_id, zdemo_abap_carr_ve.carrid as carrier_id,
zdemo_abap_carr.carrname as carrier_name zdemo_abap_carr_ve.carrname as carrier_name
from zdemo_abap_carr; from zdemo_abap_carr_ve;
* Returning joined data using an inner join * Returning joined data using an inner join
return return
@@ -211,13 +216,13 @@ CLASS ZCL_DEMO_ABAP_AMDP IMPLEMENTATION.
FOR HDB FOR HDB
LANGUAGE SQLSCRIPT LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY OPTIONS READ-ONLY
USING zdemo_abap_carr zdemo_abap_flsch. USING zdemo_abap_carr_ve zdemo_abap_flsch_ve.
* AMDP table function to be called by other AMDP methods only. * AMDP table function to be called by other AMDP methods only.
* In the example, joined data from two database table are returned. * In the example, joined data from two CDS view entities are returned.
RETURN RETURN
SELECT ca.carrname, fl.connid, fl.cityfrom, fl.cityto SELECT ca.carrname, fl.connid, fl.cityfrom, fl.cityto
FROM zdemo_abap_carr as ca FROM zdemo_abap_carr_ve as ca
INNER JOIN zdemo_abap_flsch as fl INNER JOIN zdemo_abap_flsch_ve as fl
ON ca.carrid = fl.carrid ON ca.carrid = fl.carrid
WHERE fl.carrid = :carrid WHERE fl.carrid = :carrid
ORDER BY ca.mandt, ca.carrname, fl.connid; ORDER BY ca.mandt, ca.carrname, fl.connid;
@@ -242,10 +247,12 @@ CLASS ZCL_DEMO_ABAP_AMDP IMPLEMENTATION.
FOR HDB FOR HDB
LANGUAGE SQLSCRIPT LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY OPTIONS READ-ONLY
USING zdemo_abap_fli. USING zdemo_abap_fli_ve.
* Simple data selection * Simple data selection
fli_tab = SELECT * fli_tab = SELECT carrid, connid, fldate, price, currency, planetype,
FROM "ZDEMO_ABAP_FLI" seatsmax, seatsocc, paymentsum, seatsmax_b, seatsocc_b,
seatsmax_f, seatsocc_f
FROM "ZDEMO_ABAP_FLI_VE"
WHERE carrid = :carrid WHERE carrid = :carrid
ORDER BY carrid; ORDER BY carrid;
ENDMETHOD. ENDMETHOD.
@@ -253,7 +260,7 @@ CLASS ZCL_DEMO_ABAP_AMDP IMPLEMENTATION.
METHOD if_oo_adt_classrun~main. METHOD if_oo_adt_classrun~main.
out->write( `ABAP Cheat Sheet Example: ABAP AMDP` ). out->write( `ABAP Cheat Sheet Example: AMDP` ).
out->write( |\n1) AMDP Procedure\n\n| ). out->write( |\n1) AMDP Procedure\n\n| ).
@@ -279,17 +286,13 @@ CLASS ZCL_DEMO_ABAP_AMDP IMPLEMENTATION.
"As can be seen in the method implementation part, this AMDP procedure "As can be seen in the method implementation part, this AMDP procedure
"includes an AMDP procedure call from SQLScript. "includes an AMDP procedure call from SQLScript.
"In this example, the AMDP procedure get_flights_amdp is called by "In this example, the AMDP procedure get_flights_amdp is called by
"get_flights which is meant to select data from a database table. "get_flights which is meant to select data from a CDS view entity.
"The returned result is displayed. "The returned result is displayed.
TRY. TRY.
zcl_demo_abap_amdp=>get_flights( EXPORTING carrid = 'LH' zcl_demo_abap_amdp=>get_flights( EXPORTING carrid = 'LH'
IMPORTING fli_tab = DATA(call_amdp_res) ). IMPORTING fli_tab = DATA(call_amdp_res) ).
CATCH cx_amdp_execution_error INTO DATA(error1). CATCH cx_amdp_execution_error INTO DATA(error1).
out->write( error1->get_text( ) ). out->write( error1->get_text( ) ).
ENDTRY. ENDTRY.
out->write( data = call_amdp_res name = `call_amdp_res` ). out->write( data = call_amdp_res name = `call_amdp_res` ).
@@ -303,15 +306,11 @@ CLASS ZCL_DEMO_ABAP_AMDP IMPLEMENTATION.
"get_carr_fli in the implementation part. AMDP table functions can "get_carr_fli in the implementation part. AMDP table functions can
"only be called by other AMDP methods. "only be called by other AMDP methods.
TRY. TRY.
NEW zcl_demo_abap_amdp( )->select_get_carr_fli( NEW zcl_demo_abap_amdp( )->select_get_carr_fli(
EXPORTING carrid = 'LH' EXPORTING carrid = 'LH'
IMPORTING carr_fli_tab = DATA(amdp_tab_func) ). IMPORTING carr_fli_tab = DATA(amdp_tab_func) ).
CATCH cx_amdp_execution_error INTO DATA(error2). CATCH cx_amdp_execution_error INTO DATA(error2).
out->write( error2->get_text( ) ). out->write( error2->get_text( ) ).
ENDTRY. ENDTRY.
out->write( data = amdp_tab_func name = `amdp_tab_func` ). out->write( data = amdp_tab_func name = `amdp_tab_func` ).
@@ -333,7 +332,7 @@ CLASS ZCL_DEMO_ABAP_AMDP IMPLEMENTATION.
"In this example, the CDS table function is implemented in a way to "In this example, the CDS table function is implemented in a way to
"return accumulated data. "return accumulated data.
"In the method implementation for flight_analysis, first two kinds of "In the method implementation for flight_analysis, first two kinds of
"data sets from two database tables are gathered. These data sets are "data sets from two CDS view entities are gathered. These data sets are
"joined using an inner join. There, some expressions are included "joined using an inner join. There, some expressions are included
"(strings are aggregated, average values are determined). "(strings are aggregated, average values are determined).
@@ -350,10 +349,10 @@ CLASS ZCL_DEMO_ABAP_AMDP IMPLEMENTATION.
FOR HDB FOR HDB
LANGUAGE SQLSCRIPT LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY OPTIONS READ-ONLY
USING zdemo_abap_carr. USING zdemo_abap_carr_ve.
* Simple data selection * Simple data selection
carr_tab = SELECT * carr_tab = SELECT carrid, carrname, currcode, url
FROM "ZDEMO_ABAP_CARR" FROM "ZDEMO_ABAP_CARR_VE"
ORDER BY carrid; ORDER BY carrid;
ENDMETHOD. ENDMETHOD.

View File

@@ -0,0 +1,9 @@
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view entity ZDEMO_ABAP_CARR_VE
as select from zdemo_abap_carr
{
key carrid,
carrname,
currcode,
url
}

View File

@@ -0,0 +1,19 @@
{
"BASEINFO":
{
"FROM":
[
"ZDEMO_ABAP_CARR"
],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DDLS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DDLS>
<DDLNAME>ZDEMO_ABAP_CARR_VE</DDLNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<DDTEXT>Demo CDS view entity</DDTEXT>
<SOURCE_TYPE>W</SOURCE_TYPE>
</DDLS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,18 @@
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view entity ZDEMO_ABAP_FLI_VE
as select from zdemo_abap_fli
{
key carrid,
key connid,
key fldate,
price,
currency,
planetype,
seatsmax,
seatsocc,
paymentsum,
seatsmax_b,
seatsocc_b,
seatsmax_f,
seatsocc_f
}

View File

@@ -0,0 +1,19 @@
{
"BASEINFO":
{
"FROM":
[
"ZDEMO_ABAP_FLI"
],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DDLS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DDLS>
<DDLNAME>ZDEMO_ABAP_FLI_VE</DDLNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<DDTEXT>Demo CDS view entity</DDTEXT>
<SOURCE_TYPE>W</SOURCE_TYPE>
</DDLS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,20 @@
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view entity ZDEMO_ABAP_FLSCH_VE
as select from zdemo_abap_flsch
{
key carrid,
key connid,
countryfr,
cityfrom,
airpfrom,
countryto,
cityto,
airpto,
fltime,
deptime,
arrtime,
distance,
distid,
fltype,
period
}

View File

@@ -0,0 +1,19 @@
{
"BASEINFO":
{
"FROM":
[
"ZDEMO_ABAP_FLSCH"
],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DDLS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DDLS>
<DDLNAME>ZDEMO_ABAP_FLSCH_VE</DDLNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<DDTEXT>Demo CDS view entity</DDTEXT>
<SOURCE_TYPE>W</SOURCE_TYPE>
</DDLS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -1,13 +1,15 @@
@AccessControl.authorizationCheck: #NOT_REQUIRED @AccessControl.authorizationCheck: #NOT_REQUIRED
define table function ZDEMO_ABAP_TABLE_FUNCTION @ClientHandling.type: #CLIENT_DEPENDENT
returns @ClientHandling.algorithm: #SESSION_VARIABLE
{ define table function ZDEMO_ABAP_TABLE_FUNCTION
client : abap.clnt; returns
carrier_id : abap.char(3); {
carrier_name : abap.char(20); client : abap.clnt;
connections : abap.string; carrier_id : abap.char(3);
avg_flight_time : abap.dec( 10, 2 ); carrier_name : abap.char(20);
avg_distance : abap.dec( 10, 2 ); connections : abap.string;
} avg_flight_time : abap.dec( 10, 2 );
implemented by method avg_distance : abap.dec( 10, 2 );
zcl_demo_abap_amdp=>flight_analysis; }
implemented by method
zcl_demo_abap_amdp=>flight_analysis;