Application Development and Automation 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: 
Read only

[ABAP 7.40] NEW syntax

guillaume-hrc
Active Contributor
66,042

Hi,

With all the new additions in ABAP 7.40 language, I can't manage to append a new line with values to an internal table in a single line??

This works:


DATA: lt_users TYPE STANDARD TABLE OF usr03.  " User address

DATA(ls_user) = NEW usr03( bname = 'ATURING'

                             name1 = 'Alan TURING' ).

APPEND ls_user->* TO lt_users[].

But the following does NOT:


DATA: lt_users TYPE STANDARD TABLE OF usr03.  " User address

lt_users[ 0 ] = NEW usr03( bname = 'ATURING'

                             name1 = 'Alan TURING' )->*.

I thought the table expressions could be LHS (Left Hand Side) but what about the case of a new line?

Thanks in advance for correcting me.


Best regards,

Guillaume

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
42,142

Hello Guillaume,

Finally an ABAP 740 syntax related question

Why do you want to build the table using NEW? The operator VALUE does exactly what you want.


I can't manage to append a new line with values to an internal table in a single line??


DATA: lt_users TYPE STANDARD TABLE OF usr03.  " User address

lt_users = VALUE #(

                    ( bname = 'ATURING'  name1 = 'Alan TURING')      "Line 1

                    ( bname = 'GGARCIA'  name1 = 'Guillaume GARCIA') "Line 2

                  ). 

BR,

Suhas

4 REPLIES 4
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
42,143

Hello Guillaume,

Finally an ABAP 740 syntax related question

Why do you want to build the table using NEW? The operator VALUE does exactly what you want.


I can't manage to append a new line with values to an internal table in a single line??


DATA: lt_users TYPE STANDARD TABLE OF usr03.  " User address

lt_users = VALUE #(

                    ( bname = 'ATURING'  name1 = 'Alan TURING')      "Line 1

                    ( bname = 'GGARCIA'  name1 = 'Guillaume GARCIA') "Line 2

                  ). 

BR,

Suhas

Read only

0 Likes
42,142

Hi Suhas,

Thanks.

But let's say I am within a loop, the VALUE is going to crush all existing entries in LT_USERS every single time, right?

How would you proceed to append new lines then?.

Thanks in advance.

Best regards,

Guillaume

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
42,142

Not so difficult VALUE can also be used in operand position and you can use it as follows


DO 2 TIMES.

    APPEND VALUE #( bname = |ATURING { sy-index }|

                    name1 = |Alan TURING { sy-index }|

                      )

        TO lt_users.

ENDDO.

BR,

Suhas

Read only

0 Likes
42,142

Nice!

Not accustomed to the expression power yet!  

Thanks!

Best regards,

Guillaume