2009 Dec 01 11:46 AM
Hi,
I got a requirement where i am reading some date into 2 internal table say i_1 and i_2.Then i need to loop in i_2 and check if there is a record with the same key fields in table i_1 if so add the value of the key figures from i_2 to i_1.Finally delete all entries from i_2.
can anyone tell me a logic for this.
Regards,
Ravi
2009 Dec 01 11:59 AM
Hi,
Try this
sort it_tab2 by field1 field2. "Assuming field1 and field2 are key fields in it_tab2
sort it_tab1 by field1 field2. "So sort this table with field1 and field2
loop at it_tab2 into wa_tab2.
lv_tabix = sy-tabix.
read table it_tab1 into wa_tab1 with key field1 = it_tab1-field1
field2 = it_tab2-field2 binary search. "Also assuming you have multiple records in it_tab1
loop at it_tab1 into wa_tab1 from sy-tabix.
wa_tab2-field1 = wa_itab2-field1 + wa_itab1-field1.
wa_tab2-field2 = wa_itab2-field2 + wa_itab1-field2.
modify it_tab2 from wa_tab2 index lv_tabix transporting field1 field2.
delete it_tab1 from wa_tab1index sy-tabix. "Re-check this line. I m not sure of the syntax
endloop.
endloop.
Hi,
I got a requirement where i am reading some date into 2 internal table say i_1 and i_2.Then i need to loop in i_2 and check if there is a record with the same key fields in table i_1 if so add the value of the key figures from i_2 to i_1.Finally delete all entries from i_2.
can anyone tell me a logic for this.
Regards,
Ravi
2009 Dec 01 11:53 AM
Hello,
Just convert what ever you asked in to code and it should work. If you still face issues, post the code with what you have tried.
Vikranth
2009 Dec 01 11:59 AM
Hi,
Try this
sort it_tab2 by field1 field2. "Assuming field1 and field2 are key fields in it_tab2
sort it_tab1 by field1 field2. "So sort this table with field1 and field2
loop at it_tab2 into wa_tab2.
lv_tabix = sy-tabix.
read table it_tab1 into wa_tab1 with key field1 = it_tab1-field1
field2 = it_tab2-field2 binary search. "Also assuming you have multiple records in it_tab1
loop at it_tab1 into wa_tab1 from sy-tabix.
wa_tab2-field1 = wa_itab2-field1 + wa_itab1-field1.
wa_tab2-field2 = wa_itab2-field2 + wa_itab1-field2.
modify it_tab2 from wa_tab2 index lv_tabix transporting field1 field2.
delete it_tab1 from wa_tab1index sy-tabix. "Re-check this line. I m not sure of the syntax
endloop.
endloop.
2009 Dec 01 12:00 PM
Hi.
loop in i_2
use read stmt to read i_1 table and check with ur condition
if true...
move this entry
else delete the entry.
2009 Dec 01 12:05 PM
hi,
Declare one more internal table i_3.
Loop at i_2.
read table i_1 with key field1 = i_2-field1.
if sy-subrc eq 0.
move the data of i_2 to other intarnal table say it is i_3.
append i_3.
delete i_2.
endif.
endloop.
Now i_3 will have your required data.
Regards,
Nagaraj
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |