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: 

Need duplicate records of ITAB1 into ITAB2 and unique records into ITAB3

Former Member
0 Kudos

HI....

I have one internal table with list of users, i need duplicate users into one internal table and unique users into another internal table..

Unique key to identify users is user mail id....

I dont want to use DELETE ADJACENT statement...

Pls Help

Thanks

Ram

5 REPLIES 5

Former Member
0 Kudos

Hi..

Ex: U have ITAB1 - Email is one of the field

1. SORT ITAB1BY EMAIL.

2. DECLARE WF_EMAIL TYPE EMAIL.


 LOOP AT ITAB1.
  AT FIRST.
WF_EMAIL = ITAB1-EMAIL.
  ENDAT.
IF NOT WF_EMAIL = ITAB1-EMAIL.
  APPEND ITAB3.  " passing unique entry
   WF_EMAIL = ITAB1-EMAIL.
ENDIF.

* pass the values to ITAB2 and APPEND for duplicate all records
 ENDLOOP.

Hope this Helps,

Nag

Edited by: Naga Mohan Kummara on Dec 14, 2009 11:46 AM

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Sort itab by field1.

itab1[] = itab[].

loop at itab1.

loop at itab1 where field1 = itab1-field1.

append itab1 to itab2.

delete itab1 where field1 = itab1-field1.

endloop.

endloop.

After this, itab1 will have unique values and itab2 have duplicate values.

0 Kudos

Define a Unique key for ITAB3 and appent the records and ON SUBRC return value update ITAB2 for duplicate records

Former Member
0 Kudos

Hi,

Try following,

Sort Itab by mail.

Loop at itab.

On change of itab-mail.

**move required fields to itab1

itab2-mail = itab-mail.

append itab1. " itab1 will have unique records

else.

**move required fields to itab2

itab2-mail = itab-mail.i " tab12 will have duplicate records

append itab2.

endon.

endloop.

Former Member
0 Kudos

HI,

LOOP AT ITAB1 INTO WA_ITAB1

IF WA_ITAB1-EMAIL NE WA_ITAB1_TMP-EMAIL.

WA_ITAB1_TMP = WA_ITAB1.

APPEND WA_ITAB1 TO I_ITAB1.

ELSE.

APPEND WA_ITAB1 TO I_ITAB2.

ENDIF.

ENDLOOP.