on 2023 Jun 13 4:26 PM
I have developed a table function AMDP database function, AS ABAP S/4 HANA 1809 system. It is giving me correct result when I debug and wrong result when i execute it directly.
Could you please help with finding the root cause?
Table function definition:
Method definition:
Method Implementation:
Result if debugging was on:
Result of direct execution:
A017 records
Please note: Last record is added today. After which it was still giving 2nd record as output, when I debugged, it showed me correct result(3rd row). Again when I executed it directly without debug, then it is giving 2nd record as output.
Request clarification before answering.
Hi Pradeepkumar,
When you run debuging it runs step by step, when you let a procedure run by itself HANA have the oportunity to rewrite your selection and execute once.
Despite this known behavior, there's one thing missing on your numbering related to order by, you should number it on row_number to be effective.
Change:
SELECT ROW_NUMBER() OVER(PARTITION BY matnr,lifnr ORDER BY DATBI DESC)
The other ORDER BY's on line 53 and 70 have no influence on row_number, only on output.
Regards, Fernando Da Rós
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you, it is correct.
Hi Pradeepkumar,
This seems odd but is an expected behavior, the order by have an influence on the result, see difference of column C1 and C5 on sample https://help.sap.com/docs/HANA_SERVICE_CF/7c78579ce9b14a669c1f3295b0d8ca16/ee3c26a9f6354191800e6d0ba...
The result be correct or not, may depends of your expectation.
Anyhow, is it a real request or just curiosity, because your request doesn't make sense as:
- why you need order by to drive a SUM clause, and why matnr AND werks ?
- why are you partitioning by WERKS, ignoring MATNR you will finish summing different materials, so don't make sense even
...and please post the code to help who want to help you. I rewrote it on 4 "groups" with 2 entries to make things easier to see.
WITH t1 as (
select 'W1' as werks,'M1' as matnr, 2 as menge from dummy union
select 'W1' as werks,'M1' as matnr, 3 as menge from dummy union
select 'W1' as werks,'M2' as matnr, 20 as menge from dummy union
select 'W1' as werks,'M2' as matnr, 30 as menge from dummy union
select 'W2' as werks,'M1' as matnr, 200 as menge from dummy union
select 'W2' as werks,'M1' as matnr, 300 as menge from dummy union
select 'W2' as werks,'M2' as matnr,2000 as menge from dummy union
select 'W2' as werks,'M2' as matnr,3000 as menge from dummy)
select
werks,matnr,sum(menge) over (partition by werks
order by werks,matnr) as menge
from t1 order by werks,matnr;
Regards, Fernando Da Rós
User | Count |
---|---|
74 | |
30 | |
9 | |
7 | |
7 | |
6 | |
6 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.