‎2010 Apr 12 12:31 PM
Hi Experts,
I have a small problem, In my internal table i want to seperate out single entries. That means in my internal table's few entries are repeating, but few entries are comming only one time. I need the single entries in another table. My internal table looks like below,
The below internal table having 15646 and 15806 as single time only. I need that rows only into anther internal table. Can anyone pls help this.
STLNR IDNRK
15637 7371484
15637 7346069
15637 7344871
15646 7342339
15644 7344585
15644 7344571
15806 21J0055
15644 21J0305
15644 7341860
Mohana
‎2010 Apr 12 12:37 PM
Try this sample Code
DATA : it_mara TYPE STANDARD TABLE OF ty_mara,
wa_mara TYPE ty_mara.
DATA : i_mara TYPE STANDARD TABLE OF ty_mara,
w_mara TYPE ty_mara.
DATA : cnt(2) TYPE n.
LOOP AT it_mara INTO wa_mara.
ON CHANGE OF wa_mara-matkl.
IF cnt = 1.
APPEND w_mara to i_mara.
ENDIF.
cnt = 0.
ENDON.
cnt = cnt + 1.
move wa_mara to w_mara.
ENDLOOP.
IF cnt = 1.
APPEND w_mara to i_mara.
ENDIF.Regards
Vinod
‎2010 Apr 12 12:35 PM
Hi Mohana,
Can you paste the logic that you already tried for this. So that it is easy to suggest.
Regards,
Swarna Munukoti
‎2010 Apr 12 12:35 PM
Hi
Write like this
DELETE ADJACENT DUPLICATES FROM <Internal table name > comparing STLNR.
move corresponding fileds of itab to jtab comparing <field1>.
Regards,
Pravin
Edited by: pravin s. on Apr 12, 2010 1:37 PM
‎2010 Apr 12 12:37 PM
Try this sample Code
DATA : it_mara TYPE STANDARD TABLE OF ty_mara,
wa_mara TYPE ty_mara.
DATA : i_mara TYPE STANDARD TABLE OF ty_mara,
w_mara TYPE ty_mara.
DATA : cnt(2) TYPE n.
LOOP AT it_mara INTO wa_mara.
ON CHANGE OF wa_mara-matkl.
IF cnt = 1.
APPEND w_mara to i_mara.
ENDIF.
cnt = 0.
ENDON.
cnt = cnt + 1.
move wa_mara to w_mara.
ENDLOOP.
IF cnt = 1.
APPEND w_mara to i_mara.
ENDIF.Regards
Vinod
‎2010 Apr 13 10:02 AM
‎2010 Apr 12 12:38 PM
dear mohana,
first create another itab of same type and move data to that itab and then you can use below statement
DELETE ADJACENT DUPLICATES FROM itab COMPARING fieldname.
regards,
srinivas.
‎2010 Apr 12 12:40 PM
Hi..
try this way..
delete adjacent duplicates from it_tab comparing stlnr.
lopp at it_tab1.
move it_tab[] to it_tab1[].
endloop.
here it_tab contains all the records and it_tab1 contains unique stlnr records.
Also define it_tab1 having same structure like it_tab.
Regards,
Lokeswari.
‎2010 Apr 12 12:48 PM
hi mohana,
try like this,
clear count.
loop at itab into wa.
count = count + 1.
at end of strln.
if count EQ 1.
wa1-strln = wa-strln.
wa1-idnkr = wa-idnkr.
append wa1 to itab1. " this internal table will contain the records which have only one entry in itab
clear count.
endat.
endloop.
hope this will help in solving your query.
thanks
tanmaya.
‎2010 Apr 12 12:50 PM
Hi Mohana ,
Please try this logic.
Say suppose your Internal table is ITAB which contains fields STLNR , IDNRK. Create one more Internal table ITAB2 which is of same structure .
sort the first ITAB by STLNR.
Loop Itab into wa_itab.
if sy-tabix NE 1.
if wa_itab-STLNR NE wa_itab_tmp-STLNR . " if the previous and present record are different
append wa_itab_tmp to ITAB2. "Moving the records ( single records to new ITAB2 )
delete Itab where STLNR = wa_itab-STLNR. "Deleting those records from ITAB
endif.
endif.
clear wa_itab_tmp.
wa_itab_tmp = wa_itab. " Moving the previous record here
Endloop.
Edited by: Prasath Arivazhagan on Apr 12, 2010 1:51 PM
Edited by: Prasath Arivazhagan on Apr 12, 2010 2:02 PM
‎2010 Apr 12 1:44 PM
Hi,
Please go through the below program, which will cater your requirement.
data:tabix1 type sy-tabix,tabix2 type sy-tabix.
types:begin of ttab,
stlnr(5) type c,
idnrk(7) type c,
end of ttab.
data: itab type table of ttab,
newtab type table of ttab,
wa type ttab,
temp_wa type ttab.
wa-stlnr = '15637'.wa-idnrk = '7371484'.
append wa to itab.
wa-stlnr = '15637'.wa-idnrk = '7346069'.
append wa to itab.
wa-stlnr = '15637'.wa-idnrk = '7344871'.
append wa to itab.
wa-stlnr = '15646'.wa-idnrk = '7342339'.
append wa to itab.
wa-stlnr = '15644'.wa-idnrk = '7344585'.
append wa to itab.
wa-stlnr = '15644'.wa-idnrk = '7344571'.
append wa to itab.
wa-stlnr = '15806'.wa-idnrk = '21J0055'.
append wa to itab.
wa-stlnr = '15644'.wa-idnrk = '21J0305'.
append wa to itab.
wa-stlnr = '15644'.wa-idnrk = '7341860'.
append wa to itab.
SORT itab by stlnr.
loop at itab into wa.
temp_wa = wa.
AT NEW stlnr.
tabix1 = sy-tabix.
ENDAT.
AT END OF stlnr.
tabix2 = sy-tabix.
if tabix1 = tabix2.
append temp_wa to newtab.
endif.
CLEAR: tabix1,tabix2.
ENDAT.
endloop.
loop at newtab into wa.
write: / wa-stlnr,wa-idnrk.
endloop.
Hope this may help you.
Regards,
Smart Varghese