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

deletign duplicate entries

Former Member
0 Likes
836

Hi,

i am having records like this...

MATNR VKORG VTWEG TEXT

865498 0012 00654 test1

865498 0012 00654 test2

865498 0012 00654 test3

865498 0012 00654 test4

865498 0012 00654 test5

865498 0012 00654 test6

865498 0012 00654 test7

in the above test data MATNR , VKORG, VTWEG records are same but TEXT is different.

Now my requirement is , i need to upload the data in to another internal table like below..

MATNR VKORG VTWEG TEXT

865498 0012 00654 test1test2test3test4test5test6test7

how can i handle it?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
803

Hi,

Try this code.

types : begin of tab,

matnr(18),

vkorg type vkorg,

vtweg(5),

text(50),

end of tab.

data: itab type table of tab,

newtab type table of tab,

wa type tab,

newa type tab,

newb type tab.

  • Appending values to the internal table

wa-matnr = '865498'.wa-vkorg = '0012'. wa-vtweg = '00654'. wa-text = 'test1'.

append wa to itab.

wa-matnr = '865498'.wa-vkorg = '0012'. wa-vtweg = '00654'. wa-text = 'test2'.

append wa to itab.

wa-matnr = '865498'.wa-vkorg = '0012'. wa-vtweg = '00654'. wa-text = 'test3'.

append wa to itab.

wa-matnr = '865498'.wa-vkorg = '0012'. wa-vtweg = '00654'. wa-text = 'test4'.

append wa to itab.

wa-matnr = '865498'.wa-vkorg = '0012'. wa-vtweg = '00654'. wa-text = 'test5'.

append wa to itab.

wa-matnr = '865498'.wa-vkorg = '0012'. wa-vtweg = '00654'. wa-text = 'test6'.

append wa to itab.

wa-matnr = '865498'.wa-vkorg = '0012'. wa-vtweg = '00654'. wa-text = 'test7'.

append wa to itab.

*Processing data for the new internal table

LOOP AT itab into wa.

newa = wa.

AT NEW vtweg.

newb-matnr = newa-matnr.

newb-vkorg = newa-vkorg.

newb-vtweg = newa-vtweg.

ENDAT.

concatenate newb-text newa-text into newb-text.

AT END OF vtweg.

APPEND newb to newtab.

CLEAR newb.

ENDAT.

ENDLOOP.

*Loop to display your final table

LOOP AT newtab into newb.

WRITE : newb-matnr,newb-vkorg,newb-vtweg,newb-text.

ENDLOOP.

Regards,

Smart

7 REPLIES 7
Read only

antony_paul2
Active Participant
0 Likes
803

SORT ITAB MATNR VKORG VTWEG.
LOOP AT ITAB INTO WA.
WA_NEW-MATNR  = WA-MATNR.
WA_NEW-VKORG = WA-VKORG.
WA_NEW-VTWEG = WA-VTWEG.
CONCATENATE WA-TEXT INTO WA_NEW-TEXT.

AT END OF VTWEG.
APPEND WA_NEW TO ITAB_NEW.
CLEAR WA_NEW.
ENDAT.

ENDLOOP.
Read only

Former Member
0 Likes
803

Hi,

Try below code.

declare new itab & workarea with fields which will hold the final data

sort <itab> by matnr vkorg vtweg.
matnr type matnr, 
vkorg type vkorg, 
vtweg type vtweg, 
m_texttext type char1024


data : m_matnr type matnr.
data : m_vkorg type vkorg.
data : m_vtweg type vtweg.
data : m_text type char1024.
loop at itab
 if m_matnr ne itab-matnr or
    m_vkorg ne itab-vkorg or
    m_vtweg ne itab-vtweg.
     move m_matnr to <workarea>-matnr.
     move m_vtweg to <workarea>-vtweg.
     move m_vkorg to <workarea>-vkorg.
     move m_text  to <workarea>-mtext.
     append <workarea> to <newitab>.
     clear m_text.
  endif.
  concatenate m_text <itab>-text into m_text.
  move <itab>-matnr to m_matnr.
  move <itab>-vtweg to m_vtweg.
  move <itab>-vkorg to m_vkorg.
endloop.
move m_matnr to <workarea>-matnr.
move m_vtweg to <workarea>-vtweg.
move m_vkorg to <workarea>-vkorg.
move m_text  to <workarea>-mtext.
append <workarea> to <newitab>.

Regards

Vinod

Read only

0 Likes
803

Hi All

Do we need such a complicated code for this ;).

Just a control break would do this

Antnys code looks very fine

Read only

Former Member
0 Likes
803

Let say all ur entries are in internal table ITAB.now do the below code.

ITAB1 is as the same type as ITAB.

ITAB1 [] = ITAB[].

Delete adjacent duplicates from ITAB comparing MATNR VKORG VTWEG.

loop at itab.

loop at itab1 where MATNR = itab-MATNR vkorg = itab-vkorg vtweg = itab-vtweg.

concatenate itab1-text itab3-text into itab3-text.

endloop.

itab3-matnr = itab1-matnr.

itab3-vkorg = itab1-vkorg.

itab3-vtweg = itab1-vtweg.

APPEND ITAB3.

CLEAR ITAB3.

endloop.

The above is the code for ur scenario.

Read only

Former Member
0 Likes
803

sort the first table by MATNR VKORG VTWEG.

loop 1sttab into wa_first_tab.

at new vtweg.

 "set matnr vkorg and vtweg and appned.

append wa_second_tab to 2ndtab.


endat.


read table 2ndtab
assigning <2ndtab>
with key matnr =  wa_first_tab-matnr
              vkorg = wa_first_tab-vkorg
             vtweg = wa_first_tab-vtweg.

concatenate <2ndtab>-text a_first_tab-text into <2ndtab>-text .


endloop.

Read only

Former Member
0 Likes
804

Hi,

Try this code.

types : begin of tab,

matnr(18),

vkorg type vkorg,

vtweg(5),

text(50),

end of tab.

data: itab type table of tab,

newtab type table of tab,

wa type tab,

newa type tab,

newb type tab.

  • Appending values to the internal table

wa-matnr = '865498'.wa-vkorg = '0012'. wa-vtweg = '00654'. wa-text = 'test1'.

append wa to itab.

wa-matnr = '865498'.wa-vkorg = '0012'. wa-vtweg = '00654'. wa-text = 'test2'.

append wa to itab.

wa-matnr = '865498'.wa-vkorg = '0012'. wa-vtweg = '00654'. wa-text = 'test3'.

append wa to itab.

wa-matnr = '865498'.wa-vkorg = '0012'. wa-vtweg = '00654'. wa-text = 'test4'.

append wa to itab.

wa-matnr = '865498'.wa-vkorg = '0012'. wa-vtweg = '00654'. wa-text = 'test5'.

append wa to itab.

wa-matnr = '865498'.wa-vkorg = '0012'. wa-vtweg = '00654'. wa-text = 'test6'.

append wa to itab.

wa-matnr = '865498'.wa-vkorg = '0012'. wa-vtweg = '00654'. wa-text = 'test7'.

append wa to itab.

*Processing data for the new internal table

LOOP AT itab into wa.

newa = wa.

AT NEW vtweg.

newb-matnr = newa-matnr.

newb-vkorg = newa-vkorg.

newb-vtweg = newa-vtweg.

ENDAT.

concatenate newb-text newa-text into newb-text.

AT END OF vtweg.

APPEND newb to newtab.

CLEAR newb.

ENDAT.

ENDLOOP.

*Loop to display your final table

LOOP AT newtab into newb.

WRITE : newb-matnr,newb-vkorg,newb-vtweg,newb-text.

ENDLOOP.

Regards,

Smart

Read only

umashankar_sahu
Active Participant
0 Likes
803

Hi Dear

Please Check it out it will definatelly work.

DATA : BEGIN OF it_test OCCURS 0,

MATNR TYPE MATNR,

VKORG TYPE VKORG,

VTWEG(4) TYPE C,

TEXT1 TYPE STRING,

END OF it_test.

DATA : wa_test LIKE LINE OF it_test.

DATA : text2 TYPE string,

text3 TYPE string.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'C:\Users\Swastik\Desktop\TEST.txt'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = it_test

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF SY-SUBRC = 0.

SORT it_test by matnr vkorg vtweg.

DATA : n TYPE i,

q TYPE i,

p TYPE i.

n = 1.

LOOP AT it_test.

p = n + 1.

q = sy-tabix.

READ TABLE it_test into wa_test INDEX n.

IF sy-subrc = 0 and q = P.

IF it_test-matnr = wa_test-matnr and

it_test-vkorg = wa_test-vkorg and

it_test-vtweg = wa_test-vtweg .

IF text2 is INITIAL.

MOVE : WA_TEST-TEXT1 to text2.

ENDIF.

MOVE : it_test-text1 to text3.

CONDENSE : text2,text3.

CONCATENATE text2 text3 INTO text2.

DELETE TABLE it_test[] FROM it_test.

move text2 to it_test-TEXT1.

MODIFY it_test[] INDEX n FROM it_test TRANSPORTING text1.

CLEAR text3.

ELSE.

n = n + 1.

CLEAR : text2,text3.

READ TABLE it_test into wa_test INDEX n.

ENDIF.

ELSEIF not n = q .

n = n + 1.

READ TABLE it_test into wa_test INDEX n.

CLEAR : text2,text3.

ENDIF.

ENDLOOP.

ENDIF.