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

filtering the internal table

naimkhans_babi
Active Participant
0 Likes
1,081

Dear friends

I am trying to filter the internal table but it gaves me not proper values...

say i have three internal table

itab1 itab2 itab3

id details id details id details

1 ABCD 1 ABCD 2 EFGH

2 EFGH 3 IJKL

3 IJKL

here the above scenario i have main internal table called itab1 which has 3 entries where itab2 has 1 entry. I wish to move all the entry which is not in the itab2 from the itab1.

i have return a code but it gaves me repetative not correct entries... say

1 3 4 are the correct entries.. but after that it gaves me

5 1 2 3 4... in this manner 1 3 4 5 1 2 3 4... instead of this it should 1 3 4 ... please help me to sort out this problem .... any suggestion or code will be greate help of mine... I am giving you my code...

loop at itab_new into wa_itab_new.

loop at itab into wa_itab where id ne wa_itab_new-id.

move-corresponding wa_itab to itab2.

append itab2.

endloop.

endloop.

Regards

Naim

1 ACCEPTED SOLUTION
Read only

dani_mn
Active Contributor
0 Likes
993

Hi try this.

loop at itab into wa_itab.

READ table itab_new with key id = wa_itab-id.

IF sy-subrc <> 0.

move-corresponding wa_itab to itab2.

append itab2.

ENDIF.

endloop.

Regards,

Wasim Ahmed

Hi try this.

loop at itab into wa_itab.

READ table itab_new with key id = wa_itab-id.

IF sy-subrc <> 0.

move-corresponding wa_itab to itab2.

append itab2.

ENDIF.

endloop.

Regards,

Wasim Ahmed

4 REPLIES 4
Read only

Former Member
0 Likes
993

Hi

I believe the problem is in WHERE condition, infact:

if you have 1 2 3 4 5 6 in first table 4 5 6 in second table, in the first loop the system'll load all record not equal to 4 (so 1,2,3,5,6), for the secod loop all record not equal to 5 (so 1,2,3,4,6) and so.....

loop at itab_new into wa_itab_new.

  • Check all records with ID not equal to NEW_ID

loop at itab into wa_itab where id ne wa_itab_new-id.

  • Now check if the ID isn't in ITAB_NEW

READ TABLE ITAB_NEW WITH KEY ID = WA_ITAB-ID

TRANSPORTING NO FIELDS.

IF SY-SUBRC <> 0.

  • Here you're sure this ID isn't in new table

READ TABLE ITAB2 WITH KEY ID = = WA_ITAB-ID

TRANSPORTING NO FIELDS.

IF SY-SUBRC <> 0.

  • Here you're sure this ID is loaded once

move-corresponding wa_itab to itab2.

append itab2.

ENDIF.

endif.

endloop.

endloop.

max

Read only

dani_mn
Active Contributor
0 Likes
994

Hi try this.

loop at itab into wa_itab.

READ table itab_new with key id = wa_itab-id.

IF sy-subrc <> 0.

move-corresponding wa_itab to itab2.

append itab2.

ENDIF.

endloop.

Regards,

Wasim Ahmed

Read only

santhosh_patil
Contributor
0 Likes
993

try this code it may work.....

itab1-id = 1.

itab1-detail = 'abcd'.

append itab1.

itab1-id = 2.

itab1-detail = 'hhhh'.

append itab1.

itab1-id = 3.

itab1-detail = 'gggg'.

append itab1.

itab1-id = 4.

itab1-detail = 'rere'.

append itab1.

itab2-id = 1.

itab2-detail = 'abcd'.

append itab2.

<b>loop at itab1.

read table itab2 with key id = itab1-id.

if sy-subrc <> 0.

move-corresponding itab1 to itab2.

append itab2.

endif.

endloop.</b>

Read only

Former Member
0 Likes
993

Hi,

Do the following

SORT ITAB BY ID.

loop at ITAB_NEW into wa_itab_new.

  • Now check if the ID is in ITAB or not

READ TABLE ITAB WITH KEY ID = WA_ITAB_NEW-ID

BINARY SEARCH.

IF SY-SUBRC <> 0.

  • Here you're sure this ID isn't in ITAB

move-corresponding wa_itab_new to itab2.

ENDIF.

endloop.

Sameena

Message was edited by: sameena attarwala