‎2008 Jan 18 4:40 AM
Dear all,
I am new in ABAP.
Now i got one report in which 5 tables are there.Can you suggest me that Can I use inner join.OR is there any other method.please tell me with example.
Thanks in advance.
‎2008 Jan 18 4:45 AM
hi
rather than using inner joins use select for all entries iit increases performance
for example and syntax search in formus
ok
‎2008 Jan 18 4:45 AM
Joining 5 tables is not preferred.. performance point of view..
IF NOT lt_vbak[] IS INITIAL.
SELECT vbeln vposn vbegreg vendreg vabndat vuntdat vlaufz vlauez vbegdat
venddat vlaufk FROM veda
INTO TABLE lt_veda
FOR ALL ENTRIES IN lt_vbak
WHERE vbeln EQ lt_vbak-vbeln.
-
SELECT avbeln bposnr aauart avkorg avtweg aspart a~ktext
aguebg agueen afaksk aaudat awaerk aabrvw bmvgr4 bmatnr
a~knumv
INTO TABLE lt_vbak " all header items
FROM vbak AS a
JOIN vbap AS b
ON avbeln = bvbeln
WHERE a~vbeln IN so_vbeln
AND a~erdat IN so_cdat
AND a~auart IN ('ZCMV', 'ZCSE', 'ZCSS')
AND a~vkorg IN so_vkorg.
Award points if helpful
‎2008 Jan 18 4:46 AM
Hi,
Inner join: If you have common fields between 2 or more tables, its betterto use Inner join.
Check the below example:
VBAK & VBAP table has common fields, hence we can use inner join.
SELECT akunnr avbeln anetwr abnddt a~knumv
avkbur aerdat avdatu aaugru
aktext bmatnr barktx bkwmeng b~kzwi6
bvolum bposnr b~kdmat
INTO CORRESPONDING FIELDS OF TABLE g_t_quot
FROM vbak AS a INNER JOIN vbap AS b
ON avbeln = bvbeln
WHERE a~vbeln IN so_vbeln
AND a~trvog ='2'
AND a~vkorg IN so_vkorg
AND a~vtweg IN so_vtweg
AND a~vkbur IN so_vkbur
AND a~audat IN so_audat
AND a~kunnr IN so_kunag.
FOR ALL ENTRIES:
If you get some data into one internal table and if you want to fetch data from other table based on it, use FOR ALL ENTRIES.
g_t_quot is an internal table.
SELECT spras augru bezei FROM tvaut INTO TABLE g_t_tvaut
FOR ALL ENTRIES IN g_t_quot
WHERE augru = g_t_quot-augru AND spras = sy-langu.
‎2008 Jan 18 4:59 AM
select t1field1 t1field2 t2field1 t2field2 t3field1 t3field2 t4field1 t4field2 t5field1 t5field2 into itab from (((( tabname1 as t1 inner join tabname2 as t2 on t1field = t2field) inner join tabname3 as t3 on t2field = t3field) inner join tabname4 as t4 on t3field = t4field) inner join tabname5 as t5 on t4field = t5field)
‎2008 Jan 18 5:15 AM
Hi amar,
Don't use inner join for 5 tables because if use then ur program performance will decrease.So better use For All Entries.Then it will join not only 5 tables more than 5 also.For example below program is mine.Just check it once.
SELECT dokar
doknr
dokvr
dokst
zdm_doc_owner_id
FROM draw
INTO CORRESPONDING FIELDS OF TABLE it_doc_details
WHERE dokst = 'RL'
AND dokar IN (c_00,c_12,c_68,c_70,c_frm,c_pol,c_cs,c_qa). " retrieve the data from Draw table.
IF sy-subrc = 0.
Retrieving the release dates from the Drap table.*********************************************
SELECT dokar
doknr
dokvr
stzae
datum
FROM drap
INTO CORRESPONDING FIELDS OF TABLE it_drap
FOR ALL ENTRIES IN it_doc_details
WHERE dokar = it_doc_details-dokar
AND doknr = it_doc_details-doknr
AND dokvr = it_doc_details-dokvr. " retrieve the data from Drap table and join to it_doc_details.
IF sy-subrc = 0.
SORT it_drap BY dokar doknr dokvr stzae DESCENDING .
DELETE ADJACENT DUPLICATES FROM it_drap COMPARING dokar doknr dokvr .
Retrieving the documents description from the Drat table.*********************************************
SELECT dokar
doknr
dokvr
dktxt
FROM drat INTO CORRESPONDING FIELDS OF TABLE it_drat
FOR ALL ENTRIES IN it_doc_details
WHERE dokar = it_doc_details-dokar
AND doknr = it_doc_details-doknr
AND dokvr = it_doc_details-dokvr. " retrieve the data from Drat table and join to it_doc_details.
Here i showed only 3 tables. In the same fashion you can use 5 tables also.
if it is ok Reward me
‎2008 Jan 18 8:38 AM
hi amar,
you can use joins. for all entries is the second alternative for joins.
because when you use joins you write single select query to get the data from multiple tables, so you hit the database server one time only. where in case of for all entries, you will write multiple select queries depending on the no.of tables you want to fetch the data.
so joins results less trafic when compared to for all entries