2023 Oct 24 6:54 AM
According to SAP documentation, constructor operator NEW supports table comprehensions via FOR. There are no hints of any limitations of table comprehensions in that section of the documentation. However, i discovered that NEW doesn't support GROUP BY in FOR expressions. That is, both VALUE and NEW should behave the same way for the same iteration expression. Nevertheless, NEW with GROUP BY showed a syntax error:
> Field "FOR" is unknown.
When i replaced NEW with VALUE, syntax error was gone. I prepared a demo code snippet which one can use for testing:
types: begin of ty_line_1,
key1 type i,
key2 type i,
cnt type i,
end of ty_line_1,
ty_lines_1 type standard table of ty_line_1 with empty key.
types: begin of ty_line_2,
key1 type i,
cnt type i,
end of ty_line_2,
ty_lines_2 type standard table of ty_line_2 with empty key.
data(src) = value ty_lines_1( ( key1 = 1 key2 = 1 cnt = 10 )
( key1 = 1 key2 = 2 cnt = 20 )
( key1 = 2 key2 = 100 cnt = 30 ) ).
data(aggr) = new ty_lines_2( for groups <g> of <l1> in src
group by ( id = <l1>-key1 sz = group size )
( key1 = <g>-id
cnt = reduce #( init total type i
for <l1_dtl> in group <g>
next total += <l1_dtl>-cnt ) ) ).
This snippet will give an error as specified above. If NEW is replaced with VALUE in line data(aggr) = new ty_lines_2(..., then syntax error will be gone, and the program will be activated.
Is this a bug, or is documentation simply not up to date? Would be great to hear from horst.keller.
Thanks.
Kind regards,
Vlad.
P.S. SAP_BASIS version is 7.56, system is S4HANA ON PREMISE 2021 FPS02.
2023 Oct 25 11:26 AM
Hi Vlad,
Thank you for reporting this bug. We informed development and the NEW operator is corrected with ABAP Release 7.96 (SAP BTP ABAP Environment 2405).
Best regards,
Lena
2023 Oct 24 7:54 AM
The NEW operator documentation specifically links to Table Iterations - which includes FOR GROUPS.
What would be interesting would be to see a syntax diagram of NEW and VALUE.
2023 Oct 25 11:26 AM
Hi Vlad,
Thank you for reporting this bug. We informed development and the NEW operator is corrected with ABAP Release 7.96 (SAP BTP ABAP Environment 2405).
Best regards,
Lena
2023 Oct 25 11:41 AM
And there was me cynically thinking you'd fix the documentation!
2023 Oct 25 1:12 PM
Thank you, Lena. Does that mean that on-prems edition will not see the fix any time soon?
2023 Oct 25 2:47 PM
2023 Oct 25 3:29 PM
Yes, for on-premise you'll have to wait. But we still added a note now in the documentation, so you'll see it there 🙂
2023 Oct 26 12:25 AM
Hi lenapadeken , i checked the doco that i shared in my original post and didn't see anything pointing to an SNote. Can you please share the link where the change can be seen? I'd like to see that note if it's not for SAP internal use (:
Thanks.
2023 Oct 26 10:54 AM
Unfortunately, we just uploaded the latest version for on-premise, and this will most likely not change for the next two years. If you don't mind, you can have a look at the Cloud version in a few months (https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm).
The content added looks like this: Currently, the variant FOR GROUPS ... OF is not supported for the NEW operator.
I hope this helps.
2023 Oct 26 3:08 PM
Aha "But we still added a note now in the documentation"
A documentation fix. I knew it. 😉
2023 Oct 27 12:26 PM
Yes, still a fix in the documentation 🙂
And now, good news, vlad_s, we had to fix the latest version and so, the note is available here: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abennew_constructor_p....
2023 Oct 27 4:04 PM
2023 Oct 25 12:29 PM
2023 Oct 25 12:57 PM
Glad to see you here, Horst! Main reason why I tagged you was to confirm that I understood the doco correctly - after all, English isn't my native language. If my understanding is correct that the only difference between VALUE and NEW in terms of table comprehensions is that the former produced the object itself (a table in this case), while the latter, a reference to the object, then the observed behaviour is a bug.
2023 Oct 25 1:37 PM
Hi Vlad. Yes ,you got that right. The observed behavior is a gap/bug the documentation was not aware of (otherwise it would have been corrected much earlier). Unfortunately, the fix will not be patched to former releases.