2020 Feb 23 6:56 AM
Hello Guys
I would like to append the entries from one table to an another table which has the same structure but append should skip the duplicate entries. How can I achieve it using new ABAP Coding?
Sample Code: Image1

Expected Result: Image 2

Regards,
Abhishek
2020 Feb 24 10:33 AM
That could be done quite simply with COLLECT, but as you want to do something with the "new" constructor expressions...
You need to mix a non-sorted list and a sorted list, so let's go for a table with a standard primary key and a unique (hashed here) secondary key, and a hack using CORRESPONDING DISCARDING DUPLICATES:
TYPES: BEGIN OF ty_header,
vbeln TYPE vbeln_va,
END OF ty_header.
TYPES gtt_header TYPE STANDARD TABLE OF ty_header WITH DEFAULT KEY
WITH UNIQUE HASHED KEY by_dummy COMPONENTS vbeln.
DATA(gt_vbeln) = VALUE gtt_header(
( vbeln = '4500000029' )
( vbeln = '4500000028' )
( vbeln = '4500000027' ) ).
DATA(gt_vbeln1) = VALUE gtt_header(
( vbeln = '4500000026' )
( vbeln = '4500000030' )
( vbeln = '4500000029' ) ).
gt_vbeln = CORRESPONDING #( BASE ( gt_vbeln ) gt_vbeln1 DISCARDING DUPLICATES ).
ASSERT gt_vbeln = VALUE gtt_header(
( vbeln = '4500000029' )
( vbeln = '4500000028' )
( vbeln = '4500000027' )
( vbeln = '4500000026' )
( vbeln = '4500000030' ) ).
2020 Feb 23 7:44 AM
Hello Here you go
TYPES: BEGIN OF ty_vbeln,
vbeln TYPE vbeln,
END OF ty_vbeln,
ty_t_vbeln TYPE SORTED TABLE OF ty_vbeln WITH UNIQUE KEY vbeln.
DATA(gt_vbeln) = VALUE ty_t_vbeln( ( vbeln = '10' ) ( vbeln = '11' ) ( vbeln = '12' ) ) .
DATA(gt_vbeln1) = VALUE ty_t_vbeln( ( vbeln = '14' ) ( vbeln = '11' ) ( vbeln = '12' ) ) .
INSERT LINES OF FILTER #( gt_vbeln1 EXCEPT IN gt_vbeln WHERE vbeln = vbeln ) INTO TABLE gt_vbeln.
2020 Feb 23 8:05 AM
Hello peranandam
Thank you so much for your response, but I don't want to disturb the order of table lt_header. As you can see in Image2, I want the exact output. The unique entries from Lt_header1 should simply need to be appended in lt_header1 and lt_header cannot be sorted.
Regards
Abhishek
2020 Feb 23 8:41 AM
Please post the code as text instead of image, so that one can easily answer by modifying portions of your code.
2020 Feb 23 8:54 AM
Mentioning "without sorting" discards the interest of the question, how could the code find the duplicates efficiently without impairing the performance?
2020 Feb 23 9:12 AM
To help you, to help others, thank you to peranandam:
TYPES: BEGIN OF ty_header,
vbeln TYPE vbeln_va,
END OF ty_header.
TYPES gtt_header TYPE STANDARD TABLE OF ty_header WITH DEFAULT KEY.
DATA(gt_vbeln) = VALUE gtt_header(
( vbeln = '4500000029' )
( vbeln = '4500000028' )
( vbeln = '4500000027' ) ).
DATA(gt_vbeln1) = VALUE gtt_header(
( vbeln = '4500000026' )
( vbeln = '4500000030' )
( vbeln = '4500000029' ) ).
2020 Feb 24 8:27 AM
you could copy the content of your internal table into another temporary internal table. Do a sort, check entry and add it to the final table.
2020 Feb 24 10:33 AM
That could be done quite simply with COLLECT, but as you want to do something with the "new" constructor expressions...
You need to mix a non-sorted list and a sorted list, so let's go for a table with a standard primary key and a unique (hashed here) secondary key, and a hack using CORRESPONDING DISCARDING DUPLICATES:
TYPES: BEGIN OF ty_header,
vbeln TYPE vbeln_va,
END OF ty_header.
TYPES gtt_header TYPE STANDARD TABLE OF ty_header WITH DEFAULT KEY
WITH UNIQUE HASHED KEY by_dummy COMPONENTS vbeln.
DATA(gt_vbeln) = VALUE gtt_header(
( vbeln = '4500000029' )
( vbeln = '4500000028' )
( vbeln = '4500000027' ) ).
DATA(gt_vbeln1) = VALUE gtt_header(
( vbeln = '4500000026' )
( vbeln = '4500000030' )
( vbeln = '4500000029' ) ).
gt_vbeln = CORRESPONDING #( BASE ( gt_vbeln ) gt_vbeln1 DISCARDING DUPLICATES ).
ASSERT gt_vbeln = VALUE gtt_header(
( vbeln = '4500000029' )
( vbeln = '4500000028' )
( vbeln = '4500000027' )
( vbeln = '4500000026' )
( vbeln = '4500000030' ) ).
2020 Feb 25 4:55 AM
Hello Sandra
This is what I was expecting. Thankyou so much. It works like a charm in my main Logic.
Regards
Abhishek