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 logic required

Former Member
0 Likes
1,103

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,058

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

9 REPLIES 9
Read only

former_member217544
Active Contributor
0 Likes
1,058

Hi Mohana,

Can you paste the logic that you already tried for this. So that it is easy to suggest.

Regards,

Swarna Munukoti

Read only

Former Member
0 Likes
1,058

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

Read only

Former Member
0 Likes
1,059

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

Read only

0 Likes
1,058

Thanks Vinod, Problm solvd.. points provided.

Read only

Former Member
0 Likes
1,058

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.

Read only

Former Member
0 Likes
1,058

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.

Read only

Former Member
0 Likes
1,058

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.

Read only

Former Member
0 Likes
1,058

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

Read only

Former Member
0 Likes
1,058

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