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

Former Member
0 Likes
585

hi,

may i know how to move fieldc in temp internal table to main internal table fieldc and overrite the fieldc in main internal table when fielda and fieldb are the same?

notice that sometimes temp table entry may less. for example fielda 124 is only 1 entry in temp but want to update the corresponding entry in main internal table which has 2 entries.

main internal table

fielda fieldb fieldc

123 10 999

123 10 999

123 10 999

124 10 sss

124 10 sss

temp internal table

fielda fieldb fieldc

123 10 999

123 10 998

123 10 997

124 10 see

thanks

6 REPLIES 6
Read only

Former Member
0 Likes
548

Hi,

I dont find any necessity of using temporary internal table over here. You can directly compare field content of

 fielda

and

 fieldb

and by using <b>modify</b> keyword, we can update the main internal table. So that you can get what expecting.

begin of itab

fielda

fieldb

fieldc

end of itab.

data : wa like itab.

loop at itab into wa.

if wa-fielda = wa-fieldb.

fieldc = 'see'.

modify itab form wa transporting fieldc.

endif.

Dont forget to Reward points.

Regards

Sreenivasa sarma k.

endloop.

Read only

Former Member
0 Likes
548

Try this..

Loop at temp.

if temp-fielda = temp-fieldb.

read table main index sy-tabix.

if sy-subrc = 0.

move temp-fieldc to main-fieldc.

modify main.

clear main.

endif.

endif.

endloop.

Mithun

Read only

Former Member
0 Likes
548

Hi Eliana,

By your example your results may vary or be inaccurate. Main internal table should be your main loop, and temp is your lookup table. Your temp table should be sorted by fielda and fieldb and use binary search. Main will have a header.

loop at main.

..read temp with key fielda = main-fielda and fieldb = main-fieldb binary search.

..if sy-subrc = 0.

....main-fieldc = temp-fieldc.

....modify main.

..endif.

endloop.

In your example, you will have a problem, because in your temp table, you have the same key (fielda, fieldb) 3 times, 123 10. So which value would you want? So I assume this was just an example error. Your temp table should look more like:

123 10 999

123 11 998

123 12 996

124 10 999

Point: you should always use a sorted table and read with binary search, only time you might not is if you have less than 10 records. But generally, use Binary search and don't forget to sort the table or define the table as type sorted.

Hope this helps.

Filler

Read only

gopi_narendra
Active Contributor
0 Likes
548
loop at it_main into is_main.
read table it_temp into is_temp with key fielda = is_main-fielda
                                         fieldb = is_main-fieldb.
if sy-subrc = 0.
  move is_temp-fieldc to is_main-fieldc.
  modify it_main from is_main transporting fieldc.
endif.
clear : is_main, is_temp.
endloop.

if you do this way your ouptu will be this.

fielda fieldb fieldc

123 10 999

123 10 999

123 10 999

124 10 see

124 10 see

But i doubt this is not what you need because in main table you will have duplicate entries.

so make clear ur requirement..before u proceed with my code.

and use / change the code accordingly to meet your requirement.

Regards

Gopi

Read only

0 Likes
548

hi all,

my fielda and fieldb would be repeated. that is the problem i need to ask for help.

temp table entry may less as per my first post.

thanks

Read only

0 Likes
548

use this is the record in ur table is repeated

DELETE ADJACENT DUPLICATES FROM itab.

then with simple read and modify u can tranfer the records from one table to another