‎2007 Jan 22 8:53 PM
Hi Experts,
I need to modify an internal table in a program.
The contents of the itab are like this:
Code|Deliverydoc|GoodsDoc|BillDoc|
-
U220|0080663853|49000610|
U220|0080663854|49000611|
U220|0080663655|49000612|
U220|0080663655|XXXXXXXX|9112565
U220|0080663656|49000613|
U220|0080663656|XXXXXXXX|9112566
Now I need to delete the duplicates and have them in one line.
Could you please suggest me how can I do that?
Thanks much.
null
‎2007 Jan 22 9:42 PM
There is no simple command to do what you want. You have to create a copy of this internal table and introduce a loop to get it to the form you want.
itab[] = itab_copy[].
SORT itab_copy[] BY deliverydoc.
DELETE ADJACENT DUPLICATES FROM itab_copy COMPARING deliverydoc.
LOOP AT itab_copy.
LOOP AT itab WHERE deliverydoc = itab_copy-deliverydoc.
IF NOT itab-goodsdoc IS INITIAL.
MOVE itab-goodsdoc TO itab_copy-goodsdoc.
ENDIF.
IF NOT itab-billdoc IS INITIAL.
MOVE itab-billdoc TO itab_copy-billdoc.
ENDIF.
ENDLOOP.
MODIFY itab_copy
ENDLOOP.itab_copy should have the records in the way you want.
‎2007 Jan 22 8:54 PM
Hello
Simply use the following statements:
SORT itab BY code deliverydoc goodsdoc billdoc.
DELETE ADJACENT DUPLICATES FROM itab
COMPARING code deliverydoc goodsdoc billdoc.Regards
Uwe
‎2007 Jan 22 8:55 PM
Hi,
First sort the internal table on some key.
Then use,
DELETE ADJACENT DUPLICATE ENTRIES FROM itab COMPARING fld1 fld2 fld3...
Regards
Subramanian
‎2007 Jan 22 9:01 PM
Thanks for the replies.
But I not only want to delete the duplicates, but also to merge them into one line.
For eg: I want the '9112565' to have in the first line and then delete the 2nd line.
U220|0080663655|49000612|
U220|0080663655|XXXXXXXX|9112565
Sorry for not giving you the clear details.
Thanks again.
‎2007 Jan 22 9:11 PM
HI,
Try this:
itab_1[] = itab[].
Loop at itab.
ws_tabix = sy-tabix.
move-corresponding itab to itab_tmp.
ws_tabix = ws_tabix + 1.
read table itab_1[] index ws_tabix.
if itab-fld1 = itab_1-fld1
and itab-fld2 = itab_1-fld2.
itab_tmp-fld3 = itab_1-fld3.
sy-tabix = ws_tabix.
endif.
append itab_tmp.
clear: itab_tmp, ws_tabix.
endloop.
Now itab_tmp should have all your required data.
Try and let us know if this works.
Regards
Subramanian
‎2007 Jan 22 8:59 PM
hi
Again:
SORT itab BY code deliverydoc goodsdoc billdoc.
DELETE ADJACENT DUPLICATES FROM itab COMPARING ALL FIELDS.
Cheers,
Hakim
‎2007 Jan 22 9:42 PM
There is no simple command to do what you want. You have to create a copy of this internal table and introduce a loop to get it to the form you want.
itab[] = itab_copy[].
SORT itab_copy[] BY deliverydoc.
DELETE ADJACENT DUPLICATES FROM itab_copy COMPARING deliverydoc.
LOOP AT itab_copy.
LOOP AT itab WHERE deliverydoc = itab_copy-deliverydoc.
IF NOT itab-goodsdoc IS INITIAL.
MOVE itab-goodsdoc TO itab_copy-goodsdoc.
ENDIF.
IF NOT itab-billdoc IS INITIAL.
MOVE itab-billdoc TO itab_copy-billdoc.
ENDIF.
ENDLOOP.
MODIFY itab_copy
ENDLOOP.itab_copy should have the records in the way you want.
‎2007 Jan 22 11:04 PM
Thanks Srinivas. It helped.
Thanks everybody for your time and help.