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 searching...

naimkhans_babi
Active Participant
0 Likes
468

Dear firends!!!

I am working on a problem in which i am supposed to collect exact similar records and almost similar record in two seprate internal table... say for example i have 7 fields if they are match 7/7 they should move to one internal table where i have 6/7 matching fields then they should move to another internal table here i have the 7/7 matching fields in one internal tale but where i am trying to fetch another 6/7 it gives me all the matching entries where i am supposed to have only entries which are 6/7 matching... if 5/7 is there the i am not supposed to transfer the entries... i am giving you my code... please help me in this regards.

Types: begin of L_ST_BP_P,

partner like but000-partner, " BP ID

title like but000-title, " Title

initials like but000-initials, " Initials

name_last type But000-NAME_LAST,"Surname

idnumber like but0id-idnumber,"ID Number

idtype type but0id-type," ID type

rbcode like but0is-istype,

f50code like but0is-istype,

end of l_st_bp_p.

Data: i_bp_p100 type standard table of l_st_bp_p with header line,"Internal table for 100% matching persons.

i_bp_p90 type standard table of l_st_bp_p with header line, "Internal table for 90% matching persons.

i_bp_p type standard table of l_st_bp_p with header line, " Internal table for similar records

i_bp_p2 type standard table of l_st_bp_p with header line. "Internal table for similar records

----


  • Data Classification *

----


  • Data Classification for person. *

  • Similar record searching from the internal table and populating the *

*i_bp_p internal table fro further 100% matching and 90 % matching operations *

----


sort i_but000 by partner.

sort i_but0id by partner.

sort i_but0is by partner.

sort i_profile by partner.

Loop at i_but000 into wa_but000.

lv_tabix = sy-tabix.

lv_tabix = lv_tabix + 1.

read table i_but000 index lv_tabix into wa_but000.

read table i_but0id into wa_but0id with key partner = wa_but000-partner.

read table i_but0is into wa_but0is with key partner = wa_but000-partner.

  • read table i_profile into wa_profile with key partner = wa_but000-partner.

if sy-subrc = 0.

move-corresponding wa_but000 to i_bp_p.

move-corresponding wa_but0id to i_bp_p.

move-corresponding wa_but0is to i_bp_p.

  • move-corresponding wa_profile to i_bp_p.

append i_bp_p.

clear i_bp_p.

endif.

endloop.

----


  • Searching for 100% match and 90% matching. *

----


  • 100 % matching records.

sort i_bp_p by title initials name_last idnumber idtype f50code rbcode. "acc_num.

data: wa_i_bp_p_read1 like wa_i_bp_p.

loop at i_bp_p into wa_i_bp_p.

lv_tabix = sy-tabix.

lv_tabix = lv_tabix + 1.

read table i_bp_p index lv_tabix into wa_i_bp_p_read1

comparing idnumber

idtype

title

initials

name_last

f50code

rbcode

transporting partner

idnumber

idtype

title

initials

name_last

f50code

rbcode.

if sy-subrc = 0.

move-corresponding wa_i_bp_p to i_bp_p100.

append i_bp_p100.

clear i_bp_p100.

move-corresponding wa_i_bp_p_read1 to i_bp_p100.

append i_bp_p100.

clear i_bp_p100.

endif.

  • 90% matching records. .

if sy-subrc ne 0.

move-corresponding wa_i_bp_p to i_bp_p2.

append i_bp_p2.

clear i_bp_p2.

endif.

sort i_bp_p2 by idnumber idtype title initials name_last f50code rbcode.

read table i_bp_p2 into wa_i_bp_p2 with key idnumber = wa_i_bp_p-idnumber

idtype = wa_i_bp_p-idtype

f50code = wa_i_bp_p-f50code

rbcode = wa_i_bp_p-rbcode

name_last = wa_i_bp_p-name_last

initials = wa_i_bp_p-initials

title = wa_i_bp_p-title.

if sy-subrc = 0.

move-corresponding wa_i_bp_p2 to i_bp_p90.

append i_bp_p90.

clear i_bp_p90.

endif.

if sy-subrc ne 0.

sort i_bp_p2 by idnumber idtype title initials name_last f50code.

read table i_bp_p2 into wa_i_bp_p2 with key idnumber = wa_i_bp_p-idnumber

idtype = wa_i_bp_p-idtype

f50code = wa_i_bp_p-f50code

title = wa_i_bp_p-title

name_last = wa_i_bp_p-name_last

initials = wa_i_bp_p-initials.

if sy-subrc = 0.

move-corresponding wa_i_bp_p2 to i_bp_p90.

append i_bp_p90.

clear i_bp_p90.

endif.

elseif sy-subrc ne 0.

sort i_bp_p2 by idnumber idtype title initials name_last.

read table i_bp_p2 into wa_i_bp_p2 with key idnumber = wa_i_bp_p-idnumber

idtype = wa_i_bp_p-idtype

name_last = wa_i_bp_p-name_last

initials = wa_i_bp_p-initials

title = wa_i_bp_p-title.

if sy-subrc = 0.

move-corresponding wa_i_bp_p2 to i_bp_p90.

append i_bp_p90.

clear i_bp_p90.

endif.

elseif sy-subrc ne 0.

sort i_bp_p2 by idnumber idtype title initials.

read table i_bp_p2 into wa_i_bp_p2 with key idnumber = wa_i_bp_p-idnumber

idtype = wa_i_bp_p-idtype

initials = wa_i_bp_p-initials

title = wa_i_bp_p-title.

if sy-subrc = 0.

move-corresponding wa_i_bp_p2 to i_bp_p90.

append i_bp_p90.

clear i_bp_p90.

endif.

elseif sy-subrc ne 0.

sort i_bp_p2 by idnumber idtype title.

read table i_bp_p2 into wa_i_bp_p2 with key idnumber = wa_i_bp_p-idnumber

idtype = wa_i_bp_p-idtype

title = wa_i_bp_p-title.

if sy-subrc = 0.

move-corresponding wa_i_bp_p2 to i_bp_p90.

append i_bp_p90.

clear i_bp_p90.

endif.

elseif sy-subrc ne 0.

sort i_bp_p2 by idnumber idtype.

read table i_bp_p2 into wa_i_bp_p2 with key idnumber = wa_i_bp_p-idnumber

idtype = wa_i_bp_p-idtype.

if sy-subrc = 0.

move-corresponding wa_i_bp_p2 to i_bp_p90.

append i_bp_p90.

clear i_bp_p90.

endif.

elseif sy-subrc ne 0.

sort i_bp_p2 by idnumber.

read table i_bp_p2 into wa_i_bp_p2 with key idnumber = wa_i_bp_p-idnumber.

if sy-subrc = 0.

move-corresponding wa_i_bp_p2 to i_bp_p90.

append i_bp_p90.

clear i_bp_p90.

endif.

endif.

endloop.

delete adjacent duplicates from i_bp_p100.

delete adjacent duplicates from i_bp_p90.

sort i_bp_p90 by partner

here i have the 100% matching records but dont have the 90% matching record...

please help me...

regards,

Naim

1 ACCEPTED SOLUTION
Read only

christian_wohlfahrt
Active Contributor
0 Likes
433

Hi Naim!

Indeed a tricky task.

One option (but sounds very slow): Do the same you did for 7 matches again - but this time only comparing the first 6 fields. Then sort again, compare leave the next field out of the comparison and so on (you need to select your 'current' entry again after the sorting).

Different way.

Make two tables with same content (and sorting). First will be 'source', in the second you will search for matches.

loop at source.
  l_tabix_src = sy-tabix + 1
  loop at second from l_tabix_src.
    clear l_cnt.
    if source-name = second-name.
      add 1 to l_cnt.
    endif.
" check for the other fields ...

    if l_cnt = 7.
      append source to match_100.  "?
      append second to match_100.
      continue.
    endif.
    if l_cnt = 6.
      append source to match_90.  "?
      append second to match_90.
    endif.
  endloop.
endloop.

I don't know, how you will present the results - maybe you have to adjust the 'match'-table filling a little bit.

But at least you compare everything somehow.

With ... from l_tabix_src you will compare the first entry with every other entry. The second (source) entry only starting from line 3 - because 1 - 2 was already checked, no need to check 2 - 1 again.

Should be easy to implement and reasonable fast.

Regards,

Christian

3 REPLIES 3
Read only

christian_wohlfahrt
Active Contributor
0 Likes
434

Hi Naim!

Indeed a tricky task.

One option (but sounds very slow): Do the same you did for 7 matches again - but this time only comparing the first 6 fields. Then sort again, compare leave the next field out of the comparison and so on (you need to select your 'current' entry again after the sorting).

Different way.

Make two tables with same content (and sorting). First will be 'source', in the second you will search for matches.

loop at source.
  l_tabix_src = sy-tabix + 1
  loop at second from l_tabix_src.
    clear l_cnt.
    if source-name = second-name.
      add 1 to l_cnt.
    endif.
" check for the other fields ...

    if l_cnt = 7.
      append source to match_100.  "?
      append second to match_100.
      continue.
    endif.
    if l_cnt = 6.
      append source to match_90.  "?
      append second to match_90.
    endif.
  endloop.
endloop.

I don't know, how you will present the results - maybe you have to adjust the 'match'-table filling a little bit.

But at least you compare everything somehow.

With ... from l_tabix_src you will compare the first entry with every other entry. The second (source) entry only starting from line 3 - because 1 - 2 was already checked, no need to check 2 - 1 again.

Should be easy to implement and reasonable fast.

Regards,

Christian

Read only

Former Member
0 Likes
433

Check the following solution

count = 0.

loop at itab1 into wa1.

read table itab2 into wa2

with key f1 = itab1-f1.

if sy-subrc = 0.

count = count + 1.

endif.

read table itab2 into wa2

with key f2 = itab1-f2.

if sy-subrc = 0.

count = count + 1.

endif.

--

--

read table itab2 into wa2

with key f7 = itab1-f7.

if sy-subrc = 0.

count = count + 1.

endif.

  • depending upon count insert the record into itab7by7 or itab6by7 etc

case count.

when 7.

append wa1 to itab7by7.

when 6.

...

endcase.

endloop.

hope it helps.

Regards,

kinshuk

Read only

0 Likes
433

Hi Kinshuk!

Sorry, but won't work.

a) you would find the IDENTICAL entry all the time... but you could avoid this somehow

b) you compare with ANY entry - instead of counting, if ONE other entry matches 7 criteria, you would count if (maybe) SEVEN other entries match ONE criteria. Somehow the other way around...

Still thanks for your thoughts and checking!

Christian