2006 Jun 08 3:15 AM
Hello ABAP Experts,
I have two internal tables
itab1
itab2: is the lookup table
itab1 contains field1, field2
itab2 contains field11,field12 and field3
i need to write a logic similar to this
loop itab1 into itab_wa
select the record from itab2 where itab1_wa-field1 lies in between itab2-field11 and itab2-field12
and then assign itab1_wa-field2 = itab2-field3
modify itab1 from itab1_wa
endloop.
Any suggestions highly appreciated.
Thanks,
BWer
2006 Jun 08 3:26 AM
try this..
assuming itab1 & itab2 have the same no of recs.
data w_index type sy-tabix.
loop itab1 into itab1_wa.
w_index = sy-tabix.
read table itab2 index w_index.
if sy-subrc eq 0.
if itab1_wa-field1 ge itab2-field11 and
itab1_wa-field1 le itab2-field12.
itab1_wa-field2 = itab2-field3
modify itab1 from itab1_wa.
endif.
endif.
endloop.
Regards,
Suresh Datti
Hello ABAP Experts,
I have two internal tables
itab1
itab2: is the lookup table
itab1 contains field1, field2
itab2 contains field11,field12 and field3
i need to write a logic similar to this
loop itab1 into itab_wa
select the record from itab2 where itab1_wa-field1 lies in between itab2-field11 and itab2-field12
and then assign itab1_wa-field2 = itab2-field3
modify itab1 from itab1_wa
endloop.
Any suggestions highly appreciated.
Thanks,
BWer
2006 Jun 08 3:26 AM
try this..
assuming itab1 & itab2 have the same no of recs.
data w_index type sy-tabix.
loop itab1 into itab1_wa.
w_index = sy-tabix.
read table itab2 index w_index.
if sy-subrc eq 0.
if itab1_wa-field1 ge itab2-field11 and
itab1_wa-field1 le itab2-field12.
itab1_wa-field2 = itab2-field3
modify itab1 from itab1_wa.
endif.
endif.
endloop.
Regards,
Suresh Datti
2006 Jun 08 3:46 AM
Thanks suresh,
but both the tables are different in number of records.. and other contents..
Please suggest.
Thanks,
BWer
2006 Jun 08 3:34 AM
Hi BWer,
Here you go,
Loop itab1 into itab1_wa.
select * from itab2
into itab2_wa
where field11 > itab1_wa-field1
and field12 < itab1_wa-field1.
if sy-subrc = 0.
itab1_wa-field2 = itab2_wa-field3.
modify itab1 from itab1_wa.
endif.
endloop.
Cheers,
Patrick
Message was edited by: Patrick Teo
2006 Jun 08 3:46 AM
Thanks Patrick,
just wondering if we can use select statement on a internal table..
please suggest.
Thanks,
BWer
2006 Jun 08 3:48 AM
>>>select * from itab2?
SELECT is for only database tables & cannot be used on internal tables. You either have to LOOP AT or READ an itab.
>>>but both the tables are different in number of records.. and other contents..
IF the contents are different, how do you link itab1 & itab2. You could be looping that many times...
Regards,
Suresh Datti
2006 Jun 08 3:52 AM
Hi BWer,
Unfortunately, we cannot use select statement on an internal table, Suresh is right, perhaps you can use LOOP or READ statement on internal table after the data retrieval from database using SELECT statement upfront.
Cheers,
Patrick
2006 Jun 08 5:06 AM
loop itab1 into itab1_wa
loop at itab2 into itab2_wa where
itab1_wa-field1 > itab2_wa-field11 and
itab1_wa-field1 < itab2_wa-field12.
itab1_wa-field2 = itab2_wa-field3.
modify itab1 from itab1_wa transporting field2.
endif.
endloop.
endloop.
2006 Jun 08 5:16 AM
Hi,
The code snippet can be like this :
loop at itab1 into itab_wa.
loop at itab2 where field11 < itab_wa-field1 and
field12 > itab_wa-field1.
if sy-subrc = 0.
itab_wa-field2 = itab2-field3.
modify itab1 from itab1_wa.
endif.
endloop.
endloop.
Cheers,
Vikram
Pls reward for helpful replies!!