Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How Can I calculate total amount by using loop in AMDP

r199703212
Explorer
0 Kudos
1,038

Hello Expert,

I have written SQL queries in AMDP. I want to calculate the total amount by using a loop.

This is my approach.

CLASS zcl_b_project_amdp DEFINITION

PUBLIC

FINAL

CREATE PUBLIC .

PUBLIC SECTION.

TYPES:

BEGIN OF ty_bproj,

matnr TYPE matnr,

maabc TYPE maabc,

maktx TYPE maktx,

lgort TYPE lgort_d,

labst TYPE labst,

amount TYPE verpr,

END OF ty_bproj .

TYPES:

tt_bproj TYPE TABLE OF ty_bproj .

INTERFACES if_amdp_marker_hdb.

CLASS-METHODS: get_bproject_amdp

EXPORTING

VALUE(et_bproj) TYPE tt_bproj

VALUE(ev_total_price) TYPE NETWR

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.

et_bproj = SELECT

marc.matnr,

marc.maabc,

makt.maktx,

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

WHERE

mard.lgort != '600' AND

--> marc.maabc = 'B' AND

marc.werks = 'M14';

LOOP AT et_bproj ASSIGNING FIELD-SYMBOL(<fs_project>).

ev_total_price = ev_total_price + <fs_project>-Amount.

ENDLOOP.

ENDMETHOD.

ENDCLASS.

Now I am getting an error as "SQLSCRIPT: SQL syntax error: incorrect syntax near "et_bproj""

KIndly help me to correct this syntax error.

1 REPLY 1

jasmin_gruschke
Product and Topic Expert
Product and Topic Expert
0 Kudos
924

Hi,
the coding within the AMDP should be SQLScript (as you defined), see SQLScript Reference.

You may use the SUM function.

However, looking at your coding I don't see the necessity for using SQLScript, AFAIK all this can be expressed using OpenSQL/CDS... might be worthwile to check this option as well.

Best,
Jasmin