a month ago
Hi Experts,
Sorry if I have not searched the existing threads but posting it as duplicate or repeated discussion.
I tried but I didn't find the correct one as I expected.
My requirement is to query the FMBL table to fetch and aggregate or sum of the TVAL01 to TVAL12 to one variable by all the previous years based on Measure.
For ex: if my input year is for 2024 and the Measure is 10-12345, then the query must fetch of all the data of Measure less than the year 2024 (we can set start year as 2015).
It will collect all the TVAL01 to TVAL12 of previous 10 years of records of the Measure and sum it to a single variable lv_sum.
I tried with the EXEC SQL statement but it's going run-time error. Instead of approaching the application team as it takes time, I need your help, is there any other way to sum of all the amount fields to a single variable.
Please let me know.
Thanks & Regards.
a month ago
Why using EXEC SQL instead of just SELECT? Try SELECT and if there's an issue tell us the code you have tried and what issue you have.
a month ago
Something like this might work.
SELECT SUM(TVAL01 + TVAL02 + TVAL03 + TVAL04 + TVAL05 + TVAL06 +
TVAL07 + TVAL08 + TVAL09 + TVAL10 + TVAL11 + TVAL12) AS lv_sum
FROM FMBL
WHERE Measure = '10-12345'
AND Year < 2024
AND Year >= 2015;
a month ago
Hi Azeemquadri,
Thanks.
I did the same rather I tried is there any new way to declare it.
I am closing this thread and thanks again for your code help.
a month ago
Hi Sandra_Rossi,
I thought using EXEC SQL helps to simplify the code, so posted a discussion here but resolved with SELECT AND ENDSELECT only.
Thanks for your response.
a month ago
I'm surprised that you have used ENDSELECT. It's to be used only by "experts" after performance issues have been reported. ENDSELECT in other situations should not be used. Probably you have used INTO @structure instead of INTO TABLE @itab.
a month ago
As Azeemquadri and Sandra Rossi replied. I approached the basic SELECT sum statement and it worked.