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 update

Former Member
0 Likes
841

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
814

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.

7 REPLIES 7
Read only

uwe_schieferstein
Active Contributor
0 Likes
814

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

Read only

Former Member
0 Likes
814

Hi,

First sort the internal table on some key.

Then use,

DELETE ADJACENT DUPLICATE ENTRIES FROM itab COMPARING fld1 fld2 fld3...

Regards

Subramanian

Read only

0 Likes
814

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.

Read only

0 Likes
814

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

Read only

abdul_hakim
Active Contributor
0 Likes
814

hi

Again:

SORT itab BY code deliverydoc goodsdoc billdoc.

DELETE ADJACENT DUPLICATES FROM itab COMPARING ALL FIELDS.

Cheers,

Hakim

Read only

Former Member
0 Likes
815

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.

Read only

0 Likes
814

Thanks Srinivas. It helped.

Thanks everybody for your time and help.