09-12-2008 12:11 PM
Hi All,
Tell me how to use 'UNION' in different ways.
Thank you,
Rohit
09-12-2008 12:13 PM
Check this help link:
http://help.sap.com/saphelp_nw70/helpdata/EN/62/10a423384746e8bf5f15ccdd36e8b1/frameset.htm
edit: sorry, I thought it was database tables.
Regards,
Valter Oliveira.
Edited by: Valter Oliveira on Sep 12, 2008 12:18 PM
09-12-2008 12:15 PM
Hi Rohit,
Create a third internal table comtaining common fields in both the internal table. Now loop at one of the internal table and read the other and transfer the fields to the third internal table.
SORT ITAB1 BY F1.
SORT ITAB2 BY F1.
LOOP AT ITAB1 INTO WA1.
MOVE WA1 to WA3.
READ TABEL ITAB2 INTO WA2 WITH KEY F1 = WA1-F1
BINARY SEARCH.
IF SY-SUBRC EQ 0.
MOVE WA2 to WA3.
APPEND WA3 to ITAB3.
ENDIF.
ENDLOOP.
Regards,
Nitin.
09-12-2008 12:15 PM
Hi Rohit,
This is a basic question. Please search forum before u post.
Lets make a habit of following the forum rules:-)
Also do u mean joining internal table or database table?
If it is data base table then Just type JOIN and press F1 in ur report program u get a bunch of documentation with clearly explained examples.
Thanks,
Vinod.
09-12-2008 12:16 PM
combine the records of the two internal tables to one by
Append lines of itab2 to itab1.
Sort itab1.
Delete adjacent duplicates from itab1.
Now itab1 will contain Union of itab1 and itab2.
09-12-2008 12:46 PM
Hi,
If its internal table joining then best is to use APPEND LINES.... statement.
You can also append internal tables to index tables using the following statement:
APPEND LINES OF itab1 TO itab2.
This statement appends the whole of ITAB1 to ITAB2. ITAB1 can be any type of table, but its line type must be convertible into the line type of ITAB2.
When you append an index table to another index table, you can specify the lines to be appended as follows:
APPEND LINES OF itab1 [FROM n1] [TO n2] TO itab2.
n1 and n2 specify the indexes of the first and last lines of ITAB1 that you want to append to ITAB2.
This method of appending lines of one table to another is about 3 to 4 times faster than appending them line by line in a loop. After the APPEND statement, the system field SY-TABIX
contains the index of the last line appended. When you append several lines to a sorted table, you must respect the unique key (if defined), and not violate the sort order. Otherwise, a runtime error will occur.
thanx.
10-16-2008 9:47 AM