Application Development 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: 

internal table searching

naimkhans_babi
Active Participant
0 Kudos

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. I search the records this way.

// for 90% matching records.

Copy the contents of i_bp_p into another table say i_bp_p_temp.

First sort i_bp_p_temp by 7 fields.

loop at i_bp_p.

read table i_bp_p_temp using KEY addition for the 7 fields.

if sy-subrc ne 0.

sort i_bp_p_temp again .. this time with 6 fields.

do read again.

if sy-subrc ne 0.

sort i_bp_p_temp again .. this time with 5 fields.

do read again.

.

.

.

endloop.

Table1

Id idnumber name Surname account

A 123456 Mr ABC XYZ A12345

B 123456 Mr ABC XYZ A12345

D 123457 Mr DEF ZXY A12346

E 123457 Miss DEF ZXY A12346

F 123457 Mr DEF ZXY A12347

G 123458 Mr ABD BCA A12348

Table2 “ 100% matching

Id idnumber name Surname account

A 123456 Mr ABC XYZ A12345

B 123456 Mr ABC XYZ A12345

Table3 “ 90% matching

D 123457 Mr DEF ZXY A12346

E 123457 Miss DEF ZXY A12346

F 123457 Mr DEF ZXY A12347

So in the above scenario I have 100 matching record in the table 1 but I don’t have the rest 90% match records… it gaves me all the remaining entries plus one entry from the 100% match record this ways

Table3 “ 90% matching

D 123457 Mr DEF ZXY A12346

E 123457 Miss DEF ZXY A12346

F 123457 Mr DEF ZXY A12347

G 123458 Mr ABD BCA A12348

B 123456 Mr ABC XYZ A12345

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Naim,

Best Possible solution is u add addtional field to the internal table.

Tab Field

Field1----->Any Data Type

Field2----->Any Data Type

Field3----->Any Data Type

Field4----->Any Data Type

Field5----->Any Data Type

Match_ind--> Type I to indicate number of match.

Let this is ur table ( With Data )

Field1Field2Field3Field4Field5Match_ind

--Data --Data --Data --Data --Data --7

--Data --Data --Data --Data --Data --7

--Data --Data --Data --Data --Data --6

--Data --Data --Data --Data --Data --5

--Data --Data --Data --Data --Data --3

--Data --Data --Data --Data --Data --2

--Data --Data --Data --Data --Data --1

--Data --Data --Data --Data --Data --7

Suppose if u want read data with 7 Matching Field

Loop at atab where Match_ind = 7.

-


Ur Logic

Endloop.

Suppose if u want read data with 5 Matching Field

Loop at atab where Match_ind = 5.

-


Ur Logic

Endloop.

and so on .

in this way u will be able to maintain only one table

and retrieve data as per need.

I have seen ur previous post but wasnt ;

can u paste the code so i can comment on ur code

for matching BP.

feel free to ask further question.

Regards.

email @

manoj.baijnath@wipro.com

5 REPLIES 5

Former Member
0 Kudos

Hi Naim,

loop at itab1 into wa_itab1.

loop at itab2 into wa_itab2.

if wa_itab1 = wa_itab2.

append wa_itab1 into itab3.

delete from itab2.

endif.

endloop.

endloop.

rgds,

Prakash

Former Member
0 Kudos

Probably you can make use if Key word

<b>SEARCH itab FOR g.</b> where sy-fdpos will return 0 if <b>g</b> is found. Using the <b>tabix</b> you will get the position and can reterive the record.

rgds,

TM

Former Member
0 Kudos

Hi Naim,

Best Possible solution is u add addtional field to the internal table.

Tab Field

Field1----->Any Data Type

Field2----->Any Data Type

Field3----->Any Data Type

Field4----->Any Data Type

Field5----->Any Data Type

Match_ind--> Type I to indicate number of match.

Let this is ur table ( With Data )

Field1Field2Field3Field4Field5Match_ind

--Data --Data --Data --Data --Data --7

--Data --Data --Data --Data --Data --7

--Data --Data --Data --Data --Data --6

--Data --Data --Data --Data --Data --5

--Data --Data --Data --Data --Data --3

--Data --Data --Data --Data --Data --2

--Data --Data --Data --Data --Data --1

--Data --Data --Data --Data --Data --7

Suppose if u want read data with 7 Matching Field

Loop at atab where Match_ind = 7.

-


Ur Logic

Endloop.

Suppose if u want read data with 5 Matching Field

Loop at atab where Match_ind = 5.

-


Ur Logic

Endloop.

and so on .

in this way u will be able to maintain only one table

and retrieve data as per need.

I have seen ur previous post but wasnt ;

can u paste the code so i can comment on ur code

for matching BP.

feel free to ask further question.

Regards.

email @

manoj.baijnath@wipro.com

Former Member
0 Kudos

Hi Naim,

check the following logic.


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

hope it helps.

Regards,

kinshuk

dani_mn
Active Contributor
0 Kudos

Hi,

for 7/7 match write.

READ TABLE i_bp_p_temp WITH KEY f1 = f1

f2 = f2

f3 = f3

f4 = f4

f5 = f5

f6 = f6

f7 = f7.

for 6/7 match

Match the six field with equal and last with unequal

LIKE.

READ TABLE i_bp_p_temp WITH KEY f1 = f1

f2 = f2

f3 = f3

f4 = f4

f5 = f5

f6 = f6

f7 <> f7.

FOR 5/7 match write.

READ TABLE i_bp_p_temp WITH KEY f1 = f1

f2 = f2

f3 = f3

f4 = f4

f5 = f5

f6 <> f6

f7 <> f7.

Regards,

Wasim Ahmed