Created
June 22, 2020 09:45
-
-
Save captainabap/73a3bab6a39c43a39cb4d45436c4608a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Listing 8.1.abap | |
-- Example of a simple AMDP method | |
CLASS zcl_amdp_demo DEFINITION | |
PUBLIC | |
CREATE PUBLIC . | |
PUBLIC SECTION. | |
INTERFACES if_amdp_marker_hdb. | |
TYPES gty_tt_countries TYPE TABLE OF t005t . | |
METHODS get_countries | |
IMPORTING | |
VALUE(iv_langu) TYPE langu | |
EXPORTING | |
VALUE(et_country) TYPE gty_tt_countries | |
CHANGING | |
VALUE(cv_subrc) TYPE sy-subrc. | |
ENDCLASS. | |
CLASS zcl_amdp_demo IMPLEMENTATION. | |
METHOD get_countries | |
BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT | |
USING t005t. | |
et_country = select * | |
from t005t | |
where spras = :iv_langu; | |
SELECT CASE | |
WHEN COUNT(*) > 0 | |
THEN 0 | |
ELSE 4 | |
END AS subrc | |
INTO cv_subrc | |
FROM :et_country; | |
ENDMETHOD. | |
ENDCLASS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Listing 8.10.abap | |
-- Example for the implementation of a CDS table function | |
CLASS zjb_cl_country DEFINITION PUBLIC. | |
PUBLIC SECTION. | |
INTERFACES if_amdp_marker_hdb. | |
CLASS-METHODS get_country_text | |
FOR TABLE FUNCTION z_country_text. | |
ENDCLASS. | |
CLASS zjb_cl_country IMPLEMENTATION. | |
METHOD get_country_text BY DATABASE FUNCTION | |
FOR HDB LANGUAGE SQLSCRIPT | |
OPTIONS READ-ONLY | |
USING t005t. | |
RETURN SELECT mandt, | |
land1 AS country, | |
landx50 AS text | |
FROM t005t | |
WHERE spras = :sy_langu | |
AND mandt = :mandt; | |
ENDMETHOD. | |
ENDCLASS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Listing 8.11.abap | |
-- ABAP program for testing the CDS table function from the following example | |
REPORT zjb_test . | |
SELECT * | |
FROM z_country_text | |
INTO TABLE @DATA(lt_country) | |
##db_feature_mode[amdp_table_function]. | |
cl_demo_output=>display( lt_country ). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Listing 8.13.abap | |
-- Generated UDF function for the AMDP function | |
create function | |
"ZJB_CL_COUNTRY=>GET_COUNTRY_TEXT" | |
( | |
"MANDT" NVARCHAR (000003), | |
"SY_LANGU" NVARCHAR (000001) | |
) | |
returns table | |
( | |
"MANDT" NVARCHAR (000003) , | |
"COUNTRY" NVARCHAR (000003) , | |
"TEXT" NVARCHAR (000050) | |
) | |
language sqlscript sql security invoker as begin | |
RETURN SELECT mandt, | |
land1 AS country, | |
landx50 AS text | |
FROM "ZJB_CL_COUNTRY=>T005T#covw" | |
WHERE spras = :SY_LANGU | |
AND mandt = :MANDT; | |
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Listing 8.14.abap | |
-- Example for the use of an AMDP function in another AMDP method | |
CLASS zcl_amdp_func DEFINITION PUBLIC. | |
PUBLIC SECTION. | |
TYPES: BEGIN OF ty_s_country, | |
mandt TYPE mandt, | |
country TYPE land1, | |
text TYPE landx50, | |
END OF ty_s_country. | |
TYPES ty_t_country TYPE STANDARD TABLE OF ty_s_country | |
WITH DEFAULT KEY. | |
INTERFACES if_amdp_marker_hdb. | |
METHODS test_amdp_table_function | |
IMPORTING VALUE(iv_langu) TYPE langu | |
VALUE(iv_mandt) TYPE mandt | |
EXPORTING VALUE(et_country) TYPE ty_t_country. | |
PRIVATE SECTION. | |
METHODS get_country_text | |
IMPORTING VALUE(iv_langu) TYPE langu | |
VALUE(iv_mandt) TYPE mandt | |
RETURNING VALUE(rt_country) TYPE ty_t_country. | |
ENDCLASS. | |
CLASS zcl_amdp_func IMPLEMENTATION. | |
METHOD test_amdp_table_function BY DATABASE PROCEDURE | |
FOR HDB LANGUAGE SQLSCRIPT | |
OPTIONS READ-ONLY | |
USING zcl_amdp_func=>get_country_text. | |
et_country = select * | |
from "ZCL_AMDP_FUNC=>GET_COUNTRY_TEXT" | |
( iv_langu => :iv_langu, | |
iv_mandt => :iv_mandt); | |
ENDMETHOD. | |
METHOD get_country_text BY DATABASE FUNCTION | |
FOR HDB LANGUAGE SQLSCRIPT | |
OPTIONS READ-ONLY | |
USING t005t. | |
RETURN SELECT mandt, | |
land1 AS country, | |
landx50 AS text | |
FROM t005t | |
WHERE spras = :iv_langu | |
AND mandt = :iv_mandt; | |
ENDMETHOD. | |
ENDCLASS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Listing 8.5.abap | |
-- Static Factory Method GET_INSTANCE in ABAP | |
METHOD get_instance. | |
DATA lv_classname TYPE classname. | |
CASE sy-dbsys. | |
WHEN 'HDB'. | |
lv_classname = 'ZCL_READ_XYZ_AMDP'. | |
WHEN OTHERS. | |
lv_classname = 'ZCL_READ_XYZ_OSQL'. | |
ENDCASE. | |
CREATE OBJECT ro_instance TYPE (lv_classname). | |
ENDMETHOD. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Listing 8.6.abap | |
-- Calling an AMDP procedure from another AMDP method | |
CLASS zcl_amdp_call DEFINITION PUBLIC. | |
PUBLIC SECTION. | |
TYPES: BEGIN OF ty_s_price, | |
item TYPE numc4, | |
netto TYPE wertv9, | |
brutto TYPE wertv9, | |
mwst TYPE wertv9, | |
waehrs TYPE waers, | |
END OF ty_s_price. | |
TYPES ty_t_price TYPE STANDARD TABLE OF ty_s_price. | |
INTERFACES if_amdp_marker_hdb. | |
METHODS calculate_mwst | |
IMPORTING | |
VALUE(iv_mwst) TYPE int1 | |
CHANGING | |
VALUE(ct_price) TYPE ty_t_price. | |
METHODS calculate_brutto | |
IMPORTING | |
VALUE(iv_mwst) TYPE int1 | |
CHANGING | |
VALUE(ct_price) TYPE ty_t_price. | |
ENDCLASS. | |
CLASS zcl_amdp_call IMPLEMENTATION. | |
METHOD calculate_brutto BY DATABASE PROCEDURE | |
FOR HDB LANGUAGE SQLSCRIPT | |
USING zcl_amdp_call=>calculate_mwst. | |
CALL "ZCL_AMDP_CALL=>CALCULATE_MWST"( | |
iv_mwst => :iv_mwst, | |
ct_price => :ct_price, | |
ct_price__in__ => :ct_price ); | |
ct_price = SELECT item, | |
netto, | |
netto + mwst as brutto, | |
mwst, | |
waehrs | |
FROM :ct_price; | |
ENDMETHOD. | |
METHOD calculate_mwst BY DATABASE PROCEDURE | |
FOR HDB LANGUAGE SQLSCRIPT. | |
ct_price = SELECT item, | |
netto, | |
brutto, | |
netto * :iv_mwst / 100 as mwst, | |
waehrs | |
FROM :ct_price; | |
ENDMETHOD. | |
ENDCLASS. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment