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

Internal table

Former Member
0 Likes
496

Hi,

i have an internal table with several fields. those have name, number and code along with others.

The value in number field may or may not exist and if exists i have to check whether there are any duplicates with the same 'number and code' and i have to delete those.

could some one give me an efficient approach to do this. your help would be appreciated

Thanks

kranthi.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
351

What Serder suggested and what Rich would have suggested will work for you, but it will also delete the ones that don't have a number. I think your requirement is to delete duplicates only if the number field is filled in.

You need to prepare two internal tables of the same structure. In one you will have records that have the number field filled in and the other will have records that don't have the number field filled in.

NO_NUMBER_ITAB[] = SOURCE_ITAB[].

DELETE NO_NUMBER_ITAB WHERE NOT NUMBER IS INITIAL.

NUMBER_FILLED_ITAB[] = SOURCE_ITAB[].

DELETE NUMBER_FILLED_ITAB WHERE IS INITIAL.

SORT NUMBER_FILLED_ITAB BY NUMBER CODE.

DELETE ADJACENT DUPLICATES FROM NUMBER_FILLED_ITAB COMPARING NUMBER CODE.

REFRESH SOURCE_ITAB.

APPEND LINES OF NUMBER_FILLED_ITAB TO SOURCE_ITAB.

APPEND LINES OF NO_NUMBER_ITAB TO SOURCE_ITAB.

Hope this works,

Srinivas

3 REPLIES 3
Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
351

Hi Kranthi

Do not know whether Rich is at the moment writing for the answer but you can use

SORT itab BY number code .
DELETE ADJACENT DUPLICATES FROM itab COMPARING number code .

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

Read only

0 Likes
351

No, I wasn't. But that is exactly what I would have suggested.....

Regards,

Rich Heilman

Read only

Former Member
0 Likes
352

What Serder suggested and what Rich would have suggested will work for you, but it will also delete the ones that don't have a number. I think your requirement is to delete duplicates only if the number field is filled in.

You need to prepare two internal tables of the same structure. In one you will have records that have the number field filled in and the other will have records that don't have the number field filled in.

NO_NUMBER_ITAB[] = SOURCE_ITAB[].

DELETE NO_NUMBER_ITAB WHERE NOT NUMBER IS INITIAL.

NUMBER_FILLED_ITAB[] = SOURCE_ITAB[].

DELETE NUMBER_FILLED_ITAB WHERE IS INITIAL.

SORT NUMBER_FILLED_ITAB BY NUMBER CODE.

DELETE ADJACENT DUPLICATES FROM NUMBER_FILLED_ITAB COMPARING NUMBER CODE.

REFRESH SOURCE_ITAB.

APPEND LINES OF NUMBER_FILLED_ITAB TO SOURCE_ITAB.

APPEND LINES OF NO_NUMBER_ITAB TO SOURCE_ITAB.

Hope this works,

Srinivas