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

select the record from the internal table

Former Member
0 Likes
975

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

1 ACCEPTED SOLUTION
Read only

suresh_datti
Active Contributor
0 Likes
945

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

8 REPLIES 8
Read only

suresh_datti
Active Contributor
0 Likes
946

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

Read only

0 Likes
945

Thanks suresh,

but both the tables are different in number of records.. and other contents..

Please suggest.

Thanks,

BWer

Read only

Former Member
0 Likes
945

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

Read only

0 Likes
945

Thanks Patrick,

just wondering if we can use select statement on a internal table..

please suggest.

Thanks,

BWer

Read only

0 Likes
945

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

Read only

0 Likes
945

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

Read only

hymavathi_oruganti
Active Contributor
0 Likes
945

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.

Read only

Former Member
0 Likes
945

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!!