‎2021 Feb 15 8:48 AM
Hi Every One
i have one column internal table Like

i want add 2 column with Fixed value Like :

How to do it in the best way ?
‎2021 Feb 15 5:22 PM
Here another solution with CL_ABAP_CORRESPONDING class. It works on ABAP 7.50 . I didn't write any loop. Inside kernel module ab_kmMvcdExecute_752 maybe some loop exist . I am not sure : )
cl_abap_corresponding=>create_with_value(
source = first_table
destination = second_table
mapping = VALUE cl_abap_corresponding=>mapping_table_value(
( level = 0 kind = cl_abap_corresponding=>mapping_component srcname = 'column1' dstname = 'column1' )
( level = 0 kind = cl_abap_corresponding=>mapping_value dstname = 'column2' value = REF #( `X` ) )
( level = 0 kind = cl_abap_corresponding=>mapping_value dstname = 'column3' value = REF #( `Y` ) ) )
)->execute( EXPORTING source = first_table
CHANGING destination = second_table ).<br>
‎2021 Feb 15 9:04 AM
Here's one way to do it when 'x' and 'y' are fixed...
TYPES:
BEGIN OF ty_one_column,
column TYPE i,
END OF ty_one_column.
TYPES:
BEGIN OF ty_three_columns,
column TYPE i,
column_2 TYPE string,
column_3 TYPE string,
END OF ty_three_columns.
DATA one_column_table TYPE STANDARD TABLE OF ty_one_column WITH EMPTY KEY.
DATA three_column_table TYPE STANDARD TABLE OF ty_three_columns WITH EMPTY KEY.
DO 5 TIMES.
INSERT VALUE #( column = sy-index ) INTO TABLE one_column_table.
ENDDO.
three_column_table = CORRESPONDING #( one_column_table ).
MODIFY three_column_table
FROM VALUE #( column_2 = 'x'
column_3 = 'y' )
TRANSPORTING column_2
column_3
WHERE column IS NOT INITIAL.
‎2022 Jul 20 12:26 PM
‎2021 Feb 15 9:08 AM
I'd say there are different possibilities, though you'll end up with a loop somewhere.
Option 1 - in the SQL statement
SELECT column,
'x' as column2,
'Y' as column3
FROM [..]
INTO TABLE @DATA([..])
..Option 2 - the FOR statement
see this blog for different possibilities (though technically, this remains a loop of course)
[table_2] = VALUE #( FOR data
IN [table_1]
( column_1 = data-column_1
column_2 = 'x'
column_3 = 'Y'
)
).
‎2021 Feb 15 9:37 AM
Unfortunately the CORRESPONDING operator will only map field names and not constants like that. That would have been a good one if it hade worked. I know I would have used it many times if it had been supported... 🙂
‎2021 Feb 15 10:25 AM
Yeah, like I wrote in the answer, I wasn't sure the current syntax supports it. I ended up removing the option to prevent minsunderstandings 🙂
‎2021 Feb 15 9:25 AM
‎2021 Feb 15 5:22 PM
Here another solution with CL_ABAP_CORRESPONDING class. It works on ABAP 7.50 . I didn't write any loop. Inside kernel module ab_kmMvcdExecute_752 maybe some loop exist . I am not sure : )
cl_abap_corresponding=>create_with_value(
source = first_table
destination = second_table
mapping = VALUE cl_abap_corresponding=>mapping_table_value(
( level = 0 kind = cl_abap_corresponding=>mapping_component srcname = 'column1' dstname = 'column1' )
( level = 0 kind = cl_abap_corresponding=>mapping_value dstname = 'column2' value = REF #( `X` ) )
( level = 0 kind = cl_abap_corresponding=>mapping_value dstname = 'column3' value = REF #( `Y` ) ) )
)->execute( EXPORTING source = first_table
CHANGING destination = second_table ).<br>