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: 

NEW vs. VALUE: bug or intended difference?

Volodymyr_S
Explorer

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.

1 ACCEPTED SOLUTION

lenapadeken
Product and Topic Expert
Product and Topic Expert

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

14 REPLIES 14

matt
Active Contributor
0 Kudos

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.

lenapadeken
Product and Topic Expert
Product and Topic Expert

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

matt
Active Contributor

And there was me cynically thinking you'd fix the documentation!

0 Kudos

Thank you, Lena. Does that mean that on-prems edition will not see the fix any time soon?

wow, that was FAST !!! 😄

lenapadeken
Product and Topic Expert
Product and Topic Expert

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 🙂

0 Kudos

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.

lenapadeken
Product and Topic Expert
Product and Topic Expert

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.

matt
Active Contributor

Aha "But we still added a note now in the documentation"

A documentation fix. I knew it. 😉

lenapadeken
Product and Topic Expert
Product and Topic Expert

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....

0 Kudos

Just fixing it in the marble 😉

horst_keller
Product and Topic Expert
Product and Topic Expert

Hearing from Lena is as good as hearing from me 😉

Volodymyr_S
Explorer
0 Kudos

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.

horst_keller
Product and Topic Expert
Product and Topic Expert

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.