2023 Jul 13 9:59 AM
Hello Expert,
I have written SQL queries in AMDP. I unable to pass matkl range of data inside of SQL Query.
This is my approach.
ABAP Class builder Code
class ZCL_B_PROJECT_API definition
public
create public .
public section.
types:
tt_matkl TYPE RANGE OF mara-matkl .
types:
BEGIN OF ty_bproj,
matnr TYPE matnr,
maktx TYPE maktx,
maabc TYPE maabc,
lgort TYPE lgort_d,
labst TYPE labst,
amount TYPE verpr,
END OF ty_bproj .
types:
tt_bproj TYPE TABLE OF ty_bproj .
class-methods GET_B_PROJECT
importing
!IV_KEY type MATKL
exporting
!ET_BPROJECT type TT_BPROJ
!EV_TOTAL_PRICE type NETWR .
protected section.
private section.
ENDCLASS.
CLASS ZCL_B_PROJECT_API IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_B_PROJECT_API=>GET_B_PROJECT
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_KEY TYPE MATKL
* | [<---] ET_BPROJECT TYPE TT_BPROJ
* | [<---] EV_TOTAL_PRICE TYPE NETWR
* +--------------------------------------------------------------------------------------</SIGNATURE>
method GET_B_PROJECT.
DATA lt_matkl TYPE tt_matkl.
DATA lv_plant TYPE werks_d.
CONSTANTS : lc_m10 TYPE werks_d VALUE 'M10',
lc_m14 TYPE werks_d VALUE 'M14'.
IF iv_key = 'M14MG'.
lv_plant = lc_m14.
lt_matkl = VALUE #(
( sign = 'I' option = 'BT' low = '030000' high = '064000')
( sign = 'I' option = 'BT' low = '70000' high = '280000') ).
"ev_title = 'M14 B Project'.
ELSEIF iv_key = 'M10MG'.
lv_plant = lc_m10.
lt_matkl = VALUE #(
( sign = 'I' option = 'BT' low = '030000' high = '280000') ).
"ev_title = 'M10 B Project'.
ENDIF.
TRY.
CALL METHOD zcl_b_project_amdp=>get_bproject_amdp
EXPORTING
lta_matkl = lt_matkl
lva_plant = lv_plant
IMPORTING
et_bproj = et_bproject.
LOOP AT et_bproject ASSIGNING FIELD-SYMBOL(<fs_project>).
ev_total_price = ev_total_price + <fs_project>-Amount.
ENDLOOP.
CATCH cx_amdp_error INTO DATA(lv_exp).
WRITE lv_exp->get_text( ).
ENDTRY.
endmethod.
ENDCLASS.
AMDP CLASS
CLASS zcl_b_project_amdp DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
TYPES:
BEGIN OF ty_bproj,
matnr TYPE matnr,
maktx TYPE maktx,
maabc TYPE maabc,
lgort TYPE lgort_d,
labst TYPE labst,
amount TYPE verpr,
END OF ty_bproj .
TYPES tt_bproj TYPE TABLE OF ty_bproj.
TYPES tt_matkl TYPE RANGE OF matkl.
TYPES lt_matkl TYPE tt_matkl.
INTERFACES if_amdp_marker_hdb.
CLASS-METHODS: get_bproject_amdp
IMPORTING
VALUE(lta_matkl) TYPE tt_matkl
VALUE(lva_plant) TYPE werks_d
EXPORTING
VALUE(et_bproj) TYPE tt_bproj
RAISING
cx_amdp_error.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_b_project_amdp IMPLEMENTATION.
METHOD get_bproject_amdp BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT OPTIONS READ-ONLY USING marc makt mard mbew mara.
et_bproj = SELECT
marc.matnr,
makt.maktx,
marc.maabc,
mard.lgort,
mard.labst,
(mard.labst * mbew.verpr) AS amount
FROM
marc
INNER JOIN makt ON marc.matnr = makt.matnr
INNER JOIN mard ON marc.matnr = mard.matnr
INNER JOIN mbew ON marc.matnr = mbew.matnr
INNER JOIN mara ON mara.matnr = marc.matnr
WHERE
mard.lgort != '600' AND
marc.maabc = 'B' AND
marc.werks = :lva_plant AND
mara.matkl IN :lta_matkl
ORDER BY marc.matnr;
ENDMETHOD.
ENDCLASS.
I unable to pass range of material group " mara.matkl IN :lta_matkl".
2023 Jul 13 10:51 AM
Please edit your question (Actions>Edit), select your code and press the button [CODE], which makes the code appear colored/indented, it'll be easier for people to look at it. Thanks!
2023 Jul 13 10:53 AM
Did you search the forum first? I can see many blog posts, answers...