Inner joins on the tables VAKPA , VBAP and KNA1
HI ,
I have one performance issue.please see the below select query..In order to improve the performance i need to change this select query with out changing the functionality.Can any one of you please suggest me .
SELECT vakpakunde vakpaparvw kna1kunnr kna1name1 kna1~ktokd
vbapvbeln vbapposnr vbaparktx vbapzzclass
vbapmvgr2 vbapmvgr3 vbapmvgr5 vbapzzcanvas_year
vbapmatnr vbapmatkl
FROM vakpa
INNER JOIN vbap ON
vakpavbeln = vbapvbeln
INNER JOIN kna1 ON
vakpakunnr = kna1kunnr
INTO CORRESPONDING FIELDS OF TABLE gt_vbap
WHERE vakpa~kunde IN so_kunnr
AND vakpa~parvw = 'AG'
AND vakpa~vkorg IN so_vkorg
AND ( vbap~zzad_line_status = 'PR' OR
vbap~zzad_line_status = 'RE' )
AND vbap~mvgr5 IN r_ctf
AND vbap~matkl IN so_matkl
AND vbap~matnr IN so_matnr
AND vbap~zzcanvas_year IN so_year.
ENDIF.
Use FOR ALL ENTRIES statement instead of joints.
or
and Remove INTO CORRESPONDING FIELDS by selecting the fields in the orderstored in table
Edited by: kalandar on Dec 4, 2009 7:43 AM
Similar Messages
-
Inner join on Buffred table and not buffered table.
Hi guys,
Can you suggest me how can i write select query using inner join on buffered table and not buffered table. i written like this. is it right?
SELECT a~vbeln
a~vkorg
a~kunnr
a~kunag
a~wadat_ist
a~xblnr
b~bukrs
FROM likp AS a INNER JOIN tvko AS b
ON avkorg = bvkorg BYPASSING BUFFER
INTO TABLE itab_likp
WHERE vbeln = s_vbeln.
Thanks.
RAJHi Raj ,
Please find below my Commentes :
1. When you use "Bypassing buffer" clause in Select statement , the data what is there in the buffer of application sever is always ignored and Read is performed from the Physical database always. This Clause is advisable where you require realtime data (Not recommended generally in reporting)
2. It is advisable that you should not use small table in the innerjoin with big table. In the query you have written there are 2 tables:- LIKP and TVKO outof which TVKO is a master table containing very few records than LIKP (Contains huge data for Delivery header).
So my recommendation will be : -
1. Eliminate the "Bypassing Buffer" clause from your Query
2. Break the select query into 2 select queries breaking the join and with some ABAP logic populate the Internal table "itab_likp".
This will be optimum way inwhich you can write the select query for your senarion. Also Ensure that indexes are being used for better selectivity.
Hope this will help to you.
Regards,
Nikhil -
hi all,
i am facing the problem with the inner join in the select query for 4 tables.
can i use the inner join for tables in SAP 6.0 version,
it is going to dump.
here is my code
SELECT DISTINCT apernr abegda aendda awagetype aamount acurrency
altrctry brufnm banred bvorna bnachn cgroupcode d~vdsk1
FROM pa9011 AS a INNER JOIN pa0002 AS b ON bpernr = apernr
INNER JOIN pa9013 AS c ON cpernr = bpernr
inner join pa0001 as d on dpernr = cpernr
INTO CORRESPONDING FIELDS OF TABLE it_bonus
WHERE a~pernr IN s_pernr AND
a~begda IN s_date AND
a~subty EQ s_subty AND
a~wagetype EQ wa_perbonus AND
a~ltrctry = gc_ind AND
a~amount > 0 AND
b~endda = '99991231' AND
c~groupcode IN s_loc AND
c~endda = '99991231' and
d~endda = '99991231'
ORDER BY a~pernr.hi this is the dump ,
In a SELECT access, the read file could not be placed in the target
field provided.
Either the conversion is not supported for the type of the target field,
the target field is too small to include the value, or the data does not
have the format required for the target field. -
Can anybody give me the table with tcode and its development class
can anybody give me the table with tcode and its development class
Hi phani,
1) First retrieve program name from tstc table I.e field pgmna.
2) Using pgmna retrieve from tadir table by using the following criteria from tadir table
pgmid = 'R3TR'
AND object = 'PROG'
AND obj_name = tstc-pgmna.
We will get development class or package in tadir i.e
tadir-devclass
Thanks,
Naveen Kumar. -
Help reqd to join the table of ADRC and MT001W tables
Hi all,
im working on PO and i need to display the delivery addresses where the records are available in these two tables.
I want to join the table...so pls tell me which primary field key will work out for this...i've taken the record of name field from MT001W table but while i joining with ADRC table thru name2 = g_name2...its not getting printed.
****i've moved the MT001W-name2 to the variable g_name2.
****but when im matching the record with ADRC...its not coming..pls go thru the code once b4 reply.
select name2 from MT001w into g_name2 where WERKS = g_xekpo-werks.
endselect.
if sy-subrc = 0.
*move g_name2 to g_add.
*endif.
select house_num1 street post_code1 from adrc into (g_house , g_street , g_pcode)
where name2 = g_name2 and langu = 'E'.
endselect.
*if
*move g_street to i_street.
endif.
pls do the needful and reply ur comments on urgent basis.
thanks & regards
sankar.hi Madhavi t ,
thanks a lot man....
i've done it....
thansk & regards
sankar. -
dear friends
kna1- kunnr ,name1
vbak - vbeln , erdat
vbap - meins , kwmeng
on above i have given three tables and their fields in front of this
can any one tel me how to give inner join in select statement for the above tablesHi Create an appropriate internal table ITAB
Select VBAK~VBELN
VBAK~ERDAT
VBAP~POSNR
VBAP~MEINS
VBAP~kwmeng
KNA1~KUNNR
KNA1~NAME1
From VBAK
Into Table ITAB
Inner Join VBAP On VBAKVBELN = VBAPVBELN
Inner Join KNA1 On VBAK~KUNNR = KNA1-KUNNR
Where VBAK~VBELN In S_VBELN.
Santhosh -
Problem when doing inner join for three tables....
DATA: V3 TYPE VBAP-MAKTL.
SELECT single vbap~matkl into V3
from VBAP
inner join VBFA
inner join LIPS
on LIPSPOSNR = VBFAPOSNN
and vbapvbeln = vbfavbelv
and vbapposnr = vbfaposnv
where LIPSVBELN = VBFAVBELN = '0080000834'
and vbfa~vbtyp_n = 'J'
and LIPS~J_3ASIZE = '0884'.
Error: Wrong expression "INNER" in from clause...Hello Tushar,
Why you are using the 3 table inner join. If the volume of data is big then this statement will give to time out. Use "for all entries" statement to select the data from the table.
Like
select field1 field2 from LIPS into i_lips
where LIPS~J_3ASIZE = '0884'.
select f3 f4 from vbfa into i_vbfa for all entries in i_lips where field1 = i_lips-field1 and so on
and
use same to select data from VBAP.
Hope this will help -
Inner Join of 3 tables is correct or not?
Hi Guys ,
I have a requirement where i have to join 3 tables i dont know whether the inner Join which i wrote for 3 tables is correct or not.I am not getting any Syntax error but whether the logci below which i wrote gets all the records or not.
The Requirement is
"c. Select the BOL Number entered in the screen and query the table LIKP with the BOL number in the field LIKP-BOLNR. Gather the list of ALL delivery documents (LIKP-VBELN) that is outputted.
d. Query the list of the delivery documents obtained into the table VBFA in the field VBFA- VBELV. From the output that is displayed, select the Follow-On Document Field (VBFA-VBELN) for that item whose Subsequent Document Category (VBFA- VBTYP_N) is R and the Movement Type (VBFA- BWART) is 641. Get the Follow-On document number for each of the above Delivery Document number.
e. Query the table EKBE with the Follow On document obtained above in the field Material Document (EKBE- BELNR). Perform this activity for each of the follow on document obtained above. Get the resultant Purchase Order (EKBE-EBELN) and Item Number (EKBE-EBELP) from the query. After querying will all the Follow-On Documents, get the unique list of PO number and Item Number.
The logic which i wrote is
Begin of t_PoolSTO_out,
BOLNR type LIKP-BOLNR,
EBELN type EKBE-EBELN,
EBELP type EKBE-EBELP,
VBELN type LIKP-VBELN,
VBELNV type VBFA-VBELN,
End of t_PoolSTO_out.
Data: i_PoolSTO type Standard table of t_PoolSTO_out.
Select
a~BOLNR
c~EBELN
c~EBELP
a~VBELN
b~VBELN
from LIKP as a
Inner Join VBFA as b on aVBELN = bVBELV
Inner Join EKBE as c on bVBELN = cBELNR
into Table i_PoolSTO
Where a~BOLNR in S_LBLNE and
b~VBTYP_N = 'R' and
b~BWART = '641'.
My doubt is whether the logic works or not i Mean does i getall the rrecords based on the requirement.?
If not please tell any alternative logic?
Thanks,
Gopi Anne.Hi Gopi,
Your code is Good.
But try to avoid Inner join with more number of Tables ...because this is a performance issue..
try to use..
select (primary key fields mainly,other fields) from LIKP into itab where bolnr in p_bolnr(paramater).
next try to use for all entries option..
select (primary key fields mainly,other fields) from VBFA for all entries in itab where (give the condition)....
simillarly do for the other select ....ok this will try to reduce the performance issue....
<b><REMOVED BY MODERATOR></b>
Message was edited by:
Alvaro Tejada Galindo -
Confusion in Select query having a inner join on single table
Hi,
I was going through coding and came a accross a select query which has a inner join on a single table. I am getting confused while analysing this . Please someone can help me analysing this query.
select
m~MATERIAL
s~NUMERATOR s~DENOMINTR
m~GROSS_WT m~UNIT_OF_WT
into table itab
from ( table1as s
inner join table1 as m
on m~MATERIAL = s~MATERIAL
and m~MAT_UNIT = 'CS'
and m~SOURSYSTEM = s~SOURSYSTEM )
where s~MAT_UNIT = 'EA'
and s~SOURSYSTEM = 'LD'
and s~OBJVERS = 'A'
and s~MATERIAL IN ( Select mat_sales
from Table2 group by mat_sales ).
Thank you
KusumaI don't see any use of the INNER JOIN here.
But what's the meaning of the last selection clause?
s~MATERIAL IN ( Select mat_sales
from Table2 group by mat_sales ).
Is that native SQL or something?
Pushpraj -
INNER join with dynamic table name ?
Hi,
I have a problem with this statement.
DATA: g_dso_bic_dofr TYPE tabname.
SELECT t1~/bic/ziparomr
t2~/bic/zifremom
INTO (wa_rater_paromr-/bic/ziparomr,
wa_rater_paromr-/bic/zifremom)
* FROM /bic/azd0bfr5100 AS t1 "equivalent to the dynamic statement below
" this is the problem
FROM (g_dso_bic_dofr )AS t1
INNER JOIN /bic/pzifremom AS t2
ON t1~/bic/ziparomr = t2~/bic/ziparomr
" --- to here
WHERE t1~/bic/zikom = v_kommune
The compile check doesnt work when i use the variable table name.
I get
"Wrong expression "INNER" in FROM clause. WHERE condition."
Can anyone help me.
Br Rasmus." this is the problem
* FROM (g_dso_bic_dofr )AS t1 "<<--- check spaces in here
FROM (g_dso_bic_dofr) AS t1 "<<--- and here
INNER JOIN /bic/pzifremom AS t2
ON t1~/bic/ziparomr = t2~/bic/ziparomr
" --- to here
I think there's the problem, the space behind the parenthesis.
Regards -
Outer join - inner joins at the level of the microcube between 2 queries
I have a very simple question.
If i build 2 queries in webi on the top of the same BW query
Query 1: Country and Revenue and we do put a filter on the query base of country = US
Query 2: Country and Revenue and we do not have any filter on this one
so in webi here is what happen you will get 2 tables
one table for query 1 where you will see only data for US and then Revenue
the second table query 2 will only retrieve data for all the countries and their revenue
Now if i do some merging .. it sounds like it is doing an inner join
is there a way to get the outer join or the left outer part of it or even the right out part ?
Thanks in advance
PhilippeHi Philippe,
Yes you can. Make sure that the Country coming from Query 2 is the one on the report. Then make sure the Revenue on the report is coming from Query 1. This should give you what you want.
Hope that helps!
Thanks -
Can I di Inner Join on 2 tables by using only 1 key field?
Hello,
I hv 2 Std. SAP tables, KNVV, KNKK.
- KNVV - does hv 2 key fields (KUNNR and some other, say X)
- KNKK - does hv 2 key fields (KUNNR and some other,say Y)
I want to build a inner join on these 2 tables.
So, Can I do a INNER JOIN on these 2 tables by using ONLY one key field (its KUNNR)? bcoz, there is ONLY common field!!
thank youHi,
The correctness depends on your bussiness requirement. If the common key field is not a primary key, you may end up fetching duplicate entries which you may have to delete after the select query. You dont have to take of any extra precautions in a inner join select query compared to a ordinary select query. Just make sure you use most of the primary key fields of both the tables in the where clause of the select query for better performance
Vikranth -
HI all,
How to access data from two internal table using join condition ?
suppose i have tow internal table itab and jtab and i want to access data by using inner join on this tow table.
please tell .
thanx..hi,
You can use PROVIDE ENDPROVIDE statements in ABAP to achive this.
Check the below documenttaion.
PROVIDE
Syntax
PROVIDE FIELDS {*|{comp1 comp2 ...}}
FROM itab1 INTO wa1 VALID flag1
BOUNDS intliml1 AND intlimu1
[WHERE log_exp1]
FIELDS {*|{comp1 comp2 ...}}
FROM itab2 INTO wa2 VALID flag2
BOUNDS intliml2 AND intlimu2
[WHERE log_exp2]
BETWEEN extliml AND extlimu
[INCLUDING GAPS].
ENDPROVIDE.
Effect
The statements PROVIDE and ENDPROVIDE define a loop through a statement block. In this loop, any number of internal tables itab1 itab2 ... are processed together. A single table can appear several times. For every table itab you must specify a FIELDS clause. After FIELDS you must specify the character * for all components or a list comp1 comp2 ... for specific components of the relevant table. The names of the components comp1 comp2 ... can only be specified directly.
To be able to process internal tables using PROVIDE, all tables itab1 itab2 ... must be fully typed index tables and contain two special columns that have the same data type (d, i, n, or t) for all relevant tables. For every table you must specify the names intliml1 intliml2 ... and intlimu1 intlimu2 ... of these columns using the addition BOUNDS.
The columns intliml1 intliml2 ... and intlimu1 intlimu2 ... in every row of the relevant internal tables must contain values that can be interpreted as limits of closed intervals. Within a table, the intervals specified in these columns must not overlap and must be sorted in ascending order. The intervals therefore make up a unique key for every row.
For every table you must specify a work area wa1 wa2 ... compatible with the row type and a variable flag1 flag2 ..., for which a character-type data type with length 1 is expected. In the PROVIDE loop, the components specified after FIELDS are filled with values in the relevant work areas wa1 wa2 ... for every specified internal table. The variables flag1 flag2 ... are also filled. A work area wa1 wa2 ... or a variable flag1 flag2 ... cannot be specified more than once.
With the BETWEEN addition you must specify an interval extliml, extlimu. It must be possible to convert the data objects extliml and extlimu into the data types of the respective columns intliml1 intliml2 ... and intlimu1 intlimu2 ... of the individual tables.
The interval limits intliml1 intliml2 ... and intlimu1 intlim2 for every row of all relevant internal tables itab1 itab2 ... that are within the closed interval made up by extliml and extlimu divide the latter into new intervals and every interval limit closes one interval in the original direction. If, within a relevant table, a lower interval limit follows an upper interval limit with no space or gap between them and the components of the corresponding rows specified after FIELDS have the same content, the two intervals are combined and the corresponding interval limits intliml1 intliml2 ... and intlimu1 intlimu2 ... are ignored for the new intervals.
For every interval that is created in such a way and overlaps with at least one of the intervals of a table involved, the PROVIDE loop is passed once. The components of every work area wa1 wa2 ... specified after FIELDS and the variables flag1 flag2 ... are filled with values as follows:
The components intliml1 intliml2 ... and intlimu1 intlimu2 ... of every work area wa1 wa2 ... are filled with the interval limits of the current interval.
If the current interval overlaps with one of the intervals of an involved table, the remaining components of the corresponding work area are assigned the contents of the relevant components of this table row and the variable flag1 flag2 ... is set to the value "X". Otherwise, the work area components and the variables flag1 flag2 ... are set to their Initial value.
Except for intliml1 intliml2 ... and intlimu1 intlimu2 ..., the components not specified after FIELDS are always set to their initial value. The components intliml1 intliml2 ... and intlimu1 intlimu2 ... are always assigned.
The ABAP runtime environment checks for every table involved, whether the condition of sorted and non-overlapping intervals is met within the interval made up by extliml and extlimu and, if necessary, triggers an exception that can be handled.
If the INCLUDING GAPS addition is specified, the system passes the PROVIDE loop for every interval, that is also when the current interval does not overlap with at least one of the intervals of an involved table. In the latter case, the variable flag is of initial value for every relevant table.
You can use the WHERE addition to specify a condition for every table itab1 itab2 ... involved. After WHERE, you can specify any logical expression log_exp1 log_exp2 ... ; the first operand of every comparison must be a component of the internal table. As such, all logical expressions except for IS ASSIGNED, IS REQUESTED, and IS SUPPLIED are possible. You can only specify components that are in the list after FIELDS. Here it is not possible to specify a component using character-type data objects in brackets. The table entries for which the condition is not met are ignored by the PROVIDE loop. You can leave the PROVIDE loop following the instructions in the section Leaving loops.
System fields
The system fields sy-subrc and sy-tabix are set to the value 0 before every loop pass and at ENDPROVIDE. Only if the loop is not passed once, is sy-subrc set to 4 at ENDPROVIDE.
Notes
The relevant internal tables should not be modified in the PROVIDE loop.
The WHERE condition can be used to remove overlaps between the tables involved or to ensure the sorting of the intervals.
In two tables itab1 and itab2, the respective columns col1 and col2 are interval limits of type i. The filling of the internal tables results in the following intervals (rows two and three):
|01|02|03|04|05|06|07|08|09|10|11|12|13|14|
| Itab1 Int1 | |Itab1 Int2 | |
| | Itab2 Int1 | |
| | ... BETWEEN ... |
| | i1 | i2 | i3 | i4 |i5| |
The interval specified in the BETWEEN addition to the PROVIDE statement is shown in the fourth row. It serves as a basis for the five intervals in the fifth row represented by i1 to i5. These can be processed in the PROVIDE loop.
Because each of the five intervals overlaps with one of the intervals from rows two and three, the PROVIDE loop is passed five times.
Only the component col3 of wa1 is filled in the first pass, only the component col3 of wa2 in the third pass, and the components col3 of both work areas in the second and fourth passes. The fields valid1 and valid2 are set accordingly.
DATA: BEGIN OF wa1,
col1 TYPE i,
col2 TYPE i,
col3 TYPE string,
END OF wa1.
DATA: BEGIN OF wa2,
col1 TYPE i,
col2 TYPE i,
col3 TYPE string,
END OF wa2.
DATA: itab1 LIKE STANDARD TABLE OF wa1,
itab2 LIKE STANDARD TABLE OF wa2.
DATA: flag1(1) TYPE c,
flag2(1) TYPE c.
wa1-col1 = 1.
wa1-col2 = 6.
wa1-col3 = 'Itab1 Int1'.
APPEND wa1 TO itab1.
wa1-col1 = 9.
wa1-col2 = 12.
wa1-col3 = 'Itab1 Int2'.
APPEND wa1 TO itab1.
wa2-col1 = 4.
wa2-col2 = 11.
wa2-col3 = 'Itab2 Int1'.
PROVIDE FIELDS col3 FROM itab1 INTO wa1
VALID flag1
BOUNDS col1 AND col2
FIELDS col3 FROM itab2 INTO wa2
VALID flag2
BOUNDS col1 AND col2
BETWEEN 2 AND 14.
WRITE: / wa1-col1, wa1-col2, wa1-col3, flag1.
WRITE: / wa2-col1, wa2-col2, wa2-col3, flag2.
SKIP.
ENDPROVIDE.
The list output is as follows:
2 3 Itab1 Int1 X
2 3
4 6 Itab1 Int1 X
4 6 Itab2 Int1 X
7 8
7 8 Itab2 Int1 X
9 11 Itab1 Int2 X
9 11 Itab2 Int1 X
12 12 Itab1 Int2 X
12 12
Exceptions
Catchable Exceptions
CX_SY_PROVIDE_INTERVAL_OVERLAP
Cause: In one of the involved tables there are overlapping intervals within extlim1 and extlim2.
Runtime Error: UNCAUGHT_EXCEPTION
CX_SY_PROVIDE_TABLE_NOT_SORTED
Cause: One of the involved tables is not sorted in ascending order by the intervals within extlim1 and extlim2.
Runtime Error: UNCAUGHT_EXCEPTION
Edited by: Velangini Showry Maria Kumar Bandanadham on Apr 28, 2008 1:36 PM -
What is the table for catalogs and codes complete list???
Dear Experts,
How to retrieve the total list of catalogs and codes by using table??
can any one give me the table name to retrieve the complete list of catalogs and codes ??
Please do the needful.
Thanks ,
Sunil BoyaSunil,
See this document. Catalog Profile and Catalogs & Codes
If you see this join picture you'd understand that the answer to your question is tables: T352C, QPGR, QPCD.
If you are looking for individual tables then
VIQMFE - for Object part and Damage
VIQMUR - for Causes
VIQMSM - for Tasks
VIQMMA - for Activites
QPGT - for Code Group texts
QPCT - for Code texts
If you want to know more you may ask.
Best of Luck
Jogeswara Rao K -
Need To Create a table in Sql Server and do some culculation into the table from Oracle and Sql
Hello All,
I'm moving a data from Oracle to Sql Server with ETL (80 tables with data) and i want to track the number of records that i moving on the daily basis , so i need to create a table in SQL Server, wilth 4 columns , Table name, OracleRowsCount, SqlRowCount,
and Diff(OracleRowsCount - SqlRowCount) that will tell me the each table how many rows i have in Oracle, how many rows i have in SQL after ETL load, and different between them, something like that:
Table Name OracleRowsCount SqlRowCount Diff
Customer 150 150
0
Sales 2000 1998
2
Devisions 5 5
0
(I can add alot of SQL Tasks and variables per each table but it not seems logicly to do that, i tryid to find a way to deal with that in vb but i didn't find)
What the simplest way to do it ?
Thank you
Best Regards
DanielHi Daniel,
According to your description, what you want is an indicator to show whether all the rows are inserted to the destination table. To achieve your goal, you can add a Row Count Transformation following the OLE DB Destination, and redirect bad rows to the Row
Count Transformation. This way, we can get the count of the bad rows without redirecting these rows. Since the row count value is stored in a variable, we can create another string type variable to retrieve the row count value from the variable used by the
Row Count Transformation, and then use a Send Mail Task to send the row count value in an email message body. You can also insert the row count value to the SQL Server table through Execute SQL Task. Then, you can check whether bad rows were generated in the
package by querying this table.
Regards,
Mike Yin
TechNet Community Support
Maybe you are looking for
-
Cannot post Cancellation billing document (S1)to Accounting!
Hello SAP Gurus, I need your help. We have upgraded from 4.7 to 5.0 ECC couple of months back. We are able to create cancellation billing documents for billing documents created before upgrade but are not able to release them to accounting. The error
-
Steps to upgrade 10.2.0.4 to 11.2.0.2.0
Hi all please help me for below mention issue. in our developement server we have four database and one ASM instance we have to upgrade two database from 10.2.0.4 to 11.2.0.2.0 .one databasae is mount on ASM instance others are normal OS is AIX 5.3 p
-
Why does MM accept 13 as a month??? Does it really do this? What can I do to prevent this from happening? By the way, if it would matter, my formatter isLenient(false); thanks in advance!
-
How to create code in another Project's package
In 11.5.10 jDeveloper 9.0.3 OA I've created a custom package in a project and put a VO into it. I've deployed that code to Oracle Applications. I now want to create new customizations within that same package but would like to do so in a new project.
-
How can one counter be sources (or gated) with the output of the other?
I'm trying to use the counters to generate a square pulse train that contains a certain number of pulses (on 6036E). For that I need to gate counter0 with the output of counter1. The manual seems to indicate that I need to use GPCTR_Change_Parameter