2007 Sep 25 12:09 PM
Hi friends,
I have two internal tables t_tab1 and t_tab2 which are of different structures.
1.t_tab1has the following fields
A_tab1 B_tab1 C_tab1 D_tab1....etc
2.t_tab2 has the following fields,
A_tab2 B_tab2 C_tab2 D_tab2....etc
3.t_tab2 is sorted according to the field B_tab2.
The Key btw the two table is A .(A_tab1 = A_tab2)
Eg.
t_tab1
A_tab1 B_tab1
01.01.2007 1
02.02.2007 2
03.03.2007 3
04.04.2007 4
t_tab2 before sort
A tab2 Btab2
01.01.2007 01.01.2007
02.02.2007 20.01.2007
03.03.2007 3.01.2007
04.04.2007 4.01.2007
sort t_tab2 by B.
t_tab2 after sort
A_tab2 B_tab2
01.01.2007 01.01.2007
03.03.2007 3.01.2007
04.04.2007 4.01.2007
02.02.2007 20.01.2007
Now i want to sort t_tab1 also in this order .
ie.
I want t_tab1 in the following order.
A_tab1 B_tab1
01.01.2007 1
03.03.2007 3
04.04.2007 4
02.02.2007 2
How to sort t_tab1 in the above order.
Points will be given for helpful answers.
Thanks.
Ramya
2007 Sep 25 12:24 PM
Hi
This can be solved in the below mentioned way.
1. After sorting the second table. Read the second table with the condition that the A_tab2 = A_tab1. append that work area into a new internal table.After that you can refresh the first internal table and then t_tab1[] = new internal table.
The first internaltable will have the fields in the order similar to that of second internal table.
Thanks
Mohit
declare itab3 same structure of itab1.
loop at itab2
read table itab1 with key A_ita1 = A_itab2 binary search.
if sy-subrc EQ 0.
itab3 = itab1.
append itab1
clear ita1.
endif.
endloop
refresh itab1.
itab1[] = itab3[].
2007 Sep 25 12:18 PM
declare itab3 same structure of itab1.
loop at itab2
read table itab1 with key A_ita1 = A_itab2 binary search.
if sy-subrc EQ 0.
itab3 = itab1.
append itab1
clear ita1.
endif.
endloop
refresh itab1.
itab1[] = itab3[].
2007 Sep 25 12:19 PM
declare itab3 same structure of itab1.
loop at itab2
read table itab1 with key A_ita1 = A_itab2 binary search.
if sy-subrc EQ 0.
itab3 = itab1.
append itab3
clear ita3.
endif.
endloop
refresh itab1.
itab1[] = itab3[].
2007 Sep 25 12:19 PM
Hi,
pass t__tab1 to a temp t_temp.
Loop at t_tab2.
read t_temp comparing t_tab2-a_tab and t_temp-a_tab.
pass to t_tab1.
endloop.
Reward if useful.
Regards,
Bindu.
2007 Sep 25 12:22 PM
Create another table itab3 of type itab1.
then use this.
loop at t_itab2.
read table itab1 with key A = t_itab2-A
if sy-subrc = 0.
move-corresponding itab1 to itab3.
append itab3.
endif.
endloop.
2007 Sep 25 12:22 PM
hi Ramya,
I think you need another internal table like tab1 (let's call it tab1_copy)
*after sorting of tab2, you go through tab2:
LOOP AT tab2.
*look for the proper recors from tab1
READ TABLE tab1 WITH key a = tab2-a.
*append the record to tab1_copy
APPEND tab1 TO tab1_copy.
ENDLOOP.
afte this in tab1_copy you have the records sorted acc. to tab2 sorting. Of course you can do as well:
tab1[] = tab1_copy[].
Now you have the proper order in tab1.
hope this helps
ec
2007 Sep 25 12:24 PM
define another table tab3 like tab1 and then you can sort data in tab1 like your requirement...
e.g.
data:
t_tab3 like table of t_tab1 with header line.
loop at t_tab2.
read table t_tab1 with key A_tab1 = t_tab2-A_tab2.
if sy-subrc eq 0.
append t_tab1 to t_tab3.
delete t_tab1.
endif.
endloop.
append lines of t_tab1 to t_tab3.
clear: t_tab1,t_tab1[].
t_tab1[] = t_tab3[].
now tab1 will hav sorted data as in tab2.
Reward points if useful, get back in case of query...
Cheers!!!
2007 Sep 25 12:24 PM
Hi
This can be solved in the below mentioned way.
1. After sorting the second table. Read the second table with the condition that the A_tab2 = A_tab1. append that work area into a new internal table.After that you can refresh the first internal table and then t_tab1[] = new internal table.
The first internaltable will have the fields in the order similar to that of second internal table.
Thanks
Mohit
| User | Count |
|---|---|
| 6 | |
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |