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: 

Comparison operator while doing a Read ITab

Former Member
0 Kudos

Hi Friends,

I am working on a report which takes an uploaded vendor data(legacy data) and compares the SAP Vendor master with names.

So in legacy data itab i have following fields

VendorNum

Name

Address

I retrieve all sap vendors in another Itab_sap and want to show a report of matching vendors with name.

Here i am doing a read on Itab_legacy by looping on itab_sap.


loop at itab_sap into wa_sap.

read itab_legacy into wa_legacy
with key name = wa_sap-name1.

If sy-subrc eq 0.

I am taking this into another itab for matching.

endif.

endloop.

but problem is i have to match with name even if name is half matching.

Eg. If legacy itab is having a name like 'SAP AG' and

data in sap has name1 = 'SAP' still i have to consider such records as matching records.

So can i use control statement like CP in my read statement. I tried but its giving syntax error and i think its not possible in a read statement with key cp.

Is there any better way of doing this?

I can not afford to do a loop inside a loop as data is very large.

Regards,

Simha

8 REPLIES 8

Former Member
0 Kudos

Hi,

Loop at t_ekpo. // item table

w_tabix = sy-tabix.

Read table t_ekko with key ebeln = t_ekpo-ebeln

if sy-subrc = 0.

do your own code...

endif.

read table t_ekpo index w_tabix.

do your own code .....

endloop.

this way we have to do it.

Loop and read is a gud practice.

Use the Substring concept Or String Pattern (CS /CA /CPetc)

while checking the condition.

Thanks & Regards,

Chandralekha.

0 Kudos

unfortunately you got some wrong replies from chandra:

Use the Substring concept Or String Pattern (CS /CA /CPetc)
while checking the condition.

check the length of name in both table.

we cannot use control statement in Read except only =(EQ)

Former Member
0 Kudos

In read sattement you can't use CP.

One way is there

data : text(50).
loop at itab_sap into wa_sap.
 concatenate wa_sap-name1 '*' into text.
loop at itab_legacy into wa_legacy
where name CP text.
 
 
I am taking this into another itab for matching.
 
endloop. 
endloop.

Former Member
0 Kudos

Hi,

instead of going with read table go with loop itab with where condition

eg.

loop at itab into wa

loop at itab1 into wa where <field > CP 'SAP%'.

-


endloop

endloop.

regards

padma

Former Member
0 Kudos

Hi,

If the number of entries in legacy and Vendor master are same then we can go ahead with loop and read. But here the entires may differ. For this after getting the entires of the legacy data intot he internal table cehck the SY-TFILL or SY-DBCNT ie number of the records in internal table and also cehck the number of r entires in Vendor master.

First try to filter the values then check for the where condition.

DO N times.// No. of record times

read table......

ENDDO.

Or

Loop at t_ekpo. // item table

w_tabix = sy-tabix.

Read table t_ekko with key ebeln = t_ekpo-ebeln

if sy-subrc = 0.

do your own code...

endif.

read table t_ekpo index w_tabix.

do your own code .....

endloop.

this way we have to do it.

Loop and read is a gud practice.

Use the Substring concept Or String Pattern (CS /CA /CPetc)

while checking the condition.. move the value to be in other field then we can use the CP/CS.

In your example move the value of SAP table to other field and then while reading the legacy data.

use the CS pr CP in this field

Thanks & Regards,

Chandralekha.

former_member188685
Active Contributor
0 Kudos
loop at itab_sap into wa_sap.
 
read itab_legacy into wa_legacy
with key name = wa_sap-name1.
 
If sy-subrc eq 0.
 
I am taking this into another itab for matching.
 
endif.
 
endloop.

You have live with "=(EQ)" option, so there is no chance of using Patterns here. instead you can try this...but this is loop inside loop.

loop at itab_sap into wa_sap.
 
loop at itab_legacy where  name cs wa_sap-name1.

  exit. "to come out of the loop.
endloop.
"I am taking this into another itab for matching.
 
endloop.

Former Member
0 Kudos

Your task cannot be entirely automated, since you will be using visual-subjective information to match legacy vendor names with SAP source vendor names. I recommend you split the task into 2 simpler tasks.

Task1:

Looping at i_legacy_vendor_list find records where there is a match with i_lfa1 names by read-table on i_lfa1. Take out the matching records from consideration. Put non-matching records in i_legacy_failedMatch.

Task 2:

Set up some validated business rules like the following.

Rule A: 'It is likely that the first 10 characters of SAP vendor name will be contained in the legacy vendor name.

USE contains string [CS] .

data: v_string type string.

Outer loop i_lfa1, inner loop i_legacy_failedmatch. Dont worry about memory usage, you are not making any db access, abap memory will be able to handle.

loop at i_lfa1. "Outerloop.

vSstring = i_lfa1-name1(10).

Inside inner loop check following:

if i_legacy_failedmatch-NAME cs vString.

"probable match found - capture record in separate itab

endif.

endloop

clear v_string.

endloop.

Rule B: set up the reverse of above - ie first 10 char of legacy vendor name is likely to be contained in SAP vendor name.

Additional acclerators.

If you can identify CITY / PINCODE etc in legacy vendor master in the same format as it is maintained in i_LFA1. you may want to sort i_lfa1 by that, and read only those CITY/PINCODE records in an inner loop where the outerloop is on i_legacy_failedmatch.

Since above process is somewhat subjective, it would be a good idea to download the matches allegedly found to an excel [both legacy and SAP records] and have business validate whether they are indeed matching.

Regards

Sasanka

0 Kudos

Dear Sasanka,

Thanks a lot for your insight. what you said make sense and let me try it out.

Dear Friends,

I was stubborn not to use loop inside a loop but it seems there is no better way of doing it than loop inside loop.

Thanks a lot for all your inputs.

Regards,

Simha