2007 Sep 12 7:05 PM
Hi,
I am fetching a data say fields X,Y from one table into internal table T1 and fields X,Z from another table into internal table T2. Now here X is primary key and hence to display the concatenated result by means of data from T1 and T2 in third table T3, if an approach is first fetching X,Y into T1 and then using APPEND T1 to T3 and then fetching X,Z and then using APPEND T2 to T3 the data is fetched. However if result is needed as if the records are obtained by concatenating tables T1 and T2 and fetching result X,Y,Z in T3, what is the best method that can be used?
Thanks and Regards
Ameet
2007 Sep 12 7:17 PM
loop at t1.
read t2 with key x.
if sy-subrc eq o.
move t1-x to t3-x.
move t1-y to t3-y.
move t2-z to t3-z.
append t3.
endif.
endlloop.
Hi,
I am fetching a data say fields X,Y from one table into internal table T1 and fields X,Z from another table into internal table T2. Now here X is primary key and hence to display the concatenated result by means of data from T1 and T2 in third table T3, if an approach is first fetching X,Y into T1 and then using APPEND T1 to T3 and then fetching X,Z and then using APPEND T2 to T3 the data is fetched. However if result is needed as if the records are obtained by concatenating tables T1 and T2 and fetching result X,Y,Z in T3, what is the best method that can be used?
Thanks and Regards
Ameet
2007 Sep 12 7:17 PM
loop at t1.
read t2 with key x.
if sy-subrc eq o.
move t1-x to t3-x.
move t1-y to t3-y.
move t2-z to t3-z.
append t3.
endif.
endlloop.
2007 Sep 12 7:17 PM
Why not just use a join?
You don't need internal tables t1 and t2, just load directly to t3, where t3 is defined as containing fields X, Y and Z.
select table1~x table1~y table2~z
into table t3
from table1
inner join table2
on table1~x = table2~x
where <condition>Good luck
Brian
2007 Sep 12 7:27 PM
Hi Brian,
Thanks for the answer and it indeed was meeting my requirement. Is it possible to provide me with answers of the following:-
1) How many types of JOINs we can have in ABAP?
2) Does JOIN cause a problem for performance bottleneck.
3) In what situations JOIN is more preferable over other alternatives available in ABAP?
Thanks and Regards
Ameet
2007 Sep 12 7:41 PM
> Hi Brian,
>
> Thanks for the answer and it indeed was meeting my
> requirement. Is it possible to provide me with
> answers of the following:-
> 1) How many types of JOINs we can have in ABAP?
> 2) Does JOIN cause a problem for performance
> bottleneck.
> 3) In what situations JOIN is more preferable over
> other alternatives available in ABAP?
>
> Thanks and Regards
> Ameet
1) You can do inner joins and left outer joins.
2) Joins, like anything else, can cause bottlenecks if not properly used. You can minimize this by limiting the set of records to join through the intelligent use of the ON and WHERE clauses.
Always try to have the conditions based on primary keys or an index.
The following link has some information on considerations for joins:
http://help.sap.com/saphelp_nw2004s/helpdata/en/aa/47349a0f1c11d295380000e8353423/content.htm
3) Determining whether a join is preferable usually has to be handled on a case by case basis. In this situation, where your result set needs fields from 2 different files a join is probably a good idea.
However, since join bypasses the buffer, there may be times where a view is preferable. You can use SE84 Information System to look at the ABAP dictionary.
In other cases, options such as FOR ALL ENTRIES may be preferable, or even looping constructs as in the response before mine (but not nested SELECTS).
Joins are almost always preferable to nested SELECTS.
You can use various tools to evaluate your code.
The extended program check and code inspector will tell you if there are specific readily identifiable problems with SELECTs, and this can be used to check any SELECT, whether a join is used or not.
In addition, you can use SQL trace and explain tools to see how things are working under the covers, and performance trace and runtime analysis (under System/Utilities) to do comparison testing.
Good luck
Brian
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |