LEFT(MVKE~PRODH,5) IN SELECT STATEMENT
Hello ABAP-ers!
In my SELECT STATEMENT i must JOIN table MVKE (MVKEPRODH - material hierarchy), with custom table where i have 1st level of hierarchy (ZTABLEHIER1). These two fields have sort of similar data - PRODH is second level of hierarchy for material, while HIER1 field has 1st level of hierarchy, so i have to trim down PRODH field to first 5 chars in my SELECT statement.
Example:
MVKE~PRODH = 0010000001
ZTABLE~HIER1= 00100
So, i need to take only first 5 characters from PRODH field and compare it with ZTABLE~HIER1 field.
I thought to use ...JOIN ZTABLE ON left(mvkeprodh, 5) = ztablehier1 but i knew it wouldn't work, and as i don't know of any way to do it so i must ask here.
Do you have any suggestion on how to do this?
Thanks,
Mihailo
Hi Clemens,
thank you for your reply, i just have one more question.
How do i use this in a where clause?
- field in my ZTABLE - HIJE1 = '00100%' - I use % in the end because that's where i need a wildcard in LIKE clause
- filed PRODH = '0010000001' second level material hierarchy
Ok, i've used it and seems like i'm near the solution... the problem is like on the pic:
http://s7.postimage.org/mqj2kq5qj/a1234.jpg
I have the '00100%' in ZHIJERARHIJA but it doesn't let me use it in LIKE clause it asks for v_zhijerarhija (i'm inserting that value in).
Please help!
Ok, I solved it with nested select statements between which i used left(prodh,5) which gave me the first level of hierarchy.
Thanks.
Edited by: mihailosundic on Feb 18, 2012 10:52 PM
Similar Messages
-
HOW CAN I USE MULTIPLE INNERJOINS IN A SINGLE SELECT STATEMENT?
HI,
I AM SHABEER AHMED,
I AM GETTING AN ERROR WHILE I ATTEMPT TO EXECUTE A SELECT STATEMENT WITH MULTIPLE INNER JOINS . BECOZ I WANT TO FETCH ITEM DATA, PARTNER DATA BASED ON HEADER DATA .
THEN OF COURSE I HAVE FETCH DATA FROM VBAK VBAP VBKD SO LZ SEND ME THE SOLUTION.
BYEHi,
1.Just see this:
SELECT * INTO CORRESPONDING FIELD OF TABLE itab
FROM t1 INNER JOIN t2 ON t1f4 EQ t2f4
INNER JOIN t3 ON t2f5 EQ t3f5 AND
t2f6 EQ t3f6 AND
t2f7 EQ t3f7.
2.But better to use for all entries.It increases the performance.
FOR ALL ENTRIES
Tabular Conditions
The WHERE clause of the SELECT statement has a special variant that allows you to derive conditions from the lines and columns of an internal table:
SELECT ... FOR ALL ENTRIES IN <itab> WHERE <cond> ...
<cond> may be formulated as described above. If you specify a field of the internal table <itab> as an operand in a condition, you address all lines of the internal table. The comparison is then performed for each line of the internal table. For each line, the system selects the lines from the database table that satisfy the condition. The result set of the SELECT statement is the union of the individual selections for each line of the internal table. Duplicate lines are automatically eliminated from the result set. If <itab> is empty, the addition FOR ALL ENTRIES is disregarded, and all entries are read.
The internal table <itab> must have a structured line type, and each field that occurs in the condition <cond> must be compatible with the column of the database with which it is compared. Do not use the operators LIKE, BETWEEN, and IN in comparisons using internal table fields. You may not use the ORDER BY clause in the same SELECT statement.
You can use the option FOR ALL ENTRIES to replace nested select loops by operations on internal tables. This can significantly improve the performance for large sets of selected data.
Example for ALL ENTRIES
DATA: TAB_SPFLI TYPE TABLE OF SPFLI,
TAB_SFLIGHT TYPE SORTED TABLE OF SFLIGHT
WITH UNIQUE KEY TABLE LINE,
WA LIKE LINE OF TAB_SFLIGHT.
SELECT CARRID CONNID
INTO CORRESPONDING FIELDS OF TABLE TAB_SPFLI
FROM SPFLI
WHERE CITYFROM = 'NEW YORK'.
SELECT CARRID CONNID FLDATE
INTO CORRESPONDING FIELDS OF TABLE TAB_SFLIGHT
FROM SFLIGHT
FOR ALL ENTRIES IN TAB_SPFLI
WHERE CARRID = TAB_SPFLI-CARRID AND
CONNID = TAB_SPFLI-CONNID.
LOOP AT TAB_SFLIGHT INTO WA.
AT NEW CONNID.
WRITE: / WA-CARRID, WA-CONNID.
ENDAT.
WRITE: / WA-FLDATE.
ENDLOOP.
INNER JOINS
In a relational database, you normally need to read data simultaneously from more than one database table into an application program. You can read from more than one table in a single SELECT statement, such that the data in the tables all has to meet the same conditions, using the following join expression:
SELECT...
FROM <tab> INNER JOIN <dbtab> AS <alias> ON <cond> <options>
where <dbtab> is a single database table and <tab> is either a table or another join expression. The database tables can be specified statically or dynamically as described above. You may also use aliases. You can enclose each join expression in parentheses. The INNER addition is optional.
A join expression links each line of <tab> with the lines in <dbtab> that meet the condition <cond>. This means that there is always one or more lines from the right-hand table that is linked to each line from the left-hand table by the join. If <dbtab> does not contain any lines that meet the condition <cond>, the line from <tab> is not included in the selection.
The syntax of the <cond> condition is like that of the WHERE clause, although individual comparisons can only be linked using AND. Furthermore, each comparison must contain a column from the right-hand table <dbtab>. It does not matter on which side of the comparison it occurs. For the column names in the comparison, you can use the same names that occur in the SELECT clause, to differentiate columns from different database tables that have the same names.
The comparisons in the condition <cond> can appear in the WHERE clause instead of the ON clause, since both clauses are applied equally to the temporary table containing all of the lines resulting from the join. However, each join must contain at least one comparison in the condition <cond>.
Example for INNER JOINS
REPORT demo_select_inner_join.
DATA: BEGIN OF wa,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
fldate TYPE sflight-fldate,
bookid TYPE sbook-bookid,
END OF wa,
itab LIKE SORTED TABLE OF wa
WITH UNIQUE KEY carrid connid fldate bookid.
SELECT pcarrid pconnid ffldate bbookid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( spfli AS p
INNER JOIN sflight AS f ON pcarrid = fcarrid AND
pconnid = fconnid )
INNER JOIN sbook AS b ON bcarrid = fcarrid AND
bconnid = fconnid AND
bfldate = ffldate )
WHERE p~cityfrom = 'FRANKFURT' AND
p~cityto = 'NEW YORK' AND
fseatsmax > fseatsocc.
LOOP AT itab INTO wa.
AT NEW fldate.
WRITE: / wa-carrid, wa-connid, wa-fldate.
ENDAT.
WRITE / wa-bookid.
ENDLOOP.
Regards,
Shiva Kumar(Reward if helpful). -
Intersection in Select statement
Hi,
Do any one know about some intersection option in select statement.
My case is : I have 2 database tables say TAB1 and TAB2 . TAB1 has data (A, B, C, D) and TAB2 has data (B, D) now I want the output as (A and C) after joining these 2 tables and selecting.
That is I want the values of Table1 which are not there in Table2.
I have the option of selecting Table1 and then for all entries fetch Table2, then Loop at the Table & delete if record exists.
But this is creating performance issue as the number of records in both tables are in Lakhs.
So I wanted to know is there any option like Left Intersecion or some thing like left outer join and all, so that I can pick the dat in one select.
Thanks,
SameerIssue solved :
Sample Code
TYPES : BEGIN OF X_VBAK,
VBELN TYPE VBAK-VBELN,
AUBEL TYPE VBRP-AUBEL.
TYPES : END OF X_VBAK.
DATA : I_VBAK TYPE STANDARD TABLE OF X_VBAK.
DATA : I_VBAS TYPE STANDARD TABLE OF X_VBAK.
SELECT AVBELN BAUBEL INTO CORRESPONDING FIELDS OF TABLE I_VBAK FROM ( VBAK AS A
LEFT OUTER JOIN VBRP AS B ON AVBELN EQ BAUBEL ).
SORT I_VBAK BY VBELN.
delete ADJACENT DUPLICATES FROM i_vbak COMPARING ALL FIELDS.
DELETE I_VBAK WHERE AUBEL NE ''.
SORT I_VBAK BY VBELN.
SORT I_VBAS BY VBELN. -
How to increment variable value in single select statement
Hi guys
in this select statement i have hard coded date value but i need to put variable instead of hard coded date and then i want to increment that variable value till sysdate.. i have tried using curser , type tables but they are very very slow .. any experiance guys can give me good hint what should i use.
my query
select
start_dt,
end_dt,
hi_start_dt,
hi_end_dt,
ph_start_dt,
ph_end_dt,
h_start_date,
h_end_date,
g_code,
emp_det.ref,
u_code,
costing,
emp_nm,
emp_no
from
emp_det,
emp_ph_det,
emp_hi_det,
emp_h_det
where
emp_det.ref(+) = emp_ph_det.ref
and emp_hi_det.p_ref(+) = emp_ph_det.p_ref
and emp_h_det.ph_ref = emp_ph_det.ph_ref
and emp_h_det.ph_st_dt(+) = emp_hi_det.st_date;
and to_date('01-MAR-2008') between i.start_dt and nvl(i.end_dt, to_date('01-MAR-2008') +1)
and to_date('01-MAR-2008') between i.hi_start_dt and nvl(i.hi_end_dt, to_date('01-MAR-2008') + 1)
and to_date('01-MAR-2008') between i.ph_start_dt and nvl(i.ph_end_dt, to_date('01-MAR-2008') + 1)
and to_date('01-MAR-2008') between i.h_start_date and nvl(i.h_end_date, to_date('01-MAR-2008') + 1)
or
(----emp has left this month
i.start_dt < i.emp_end_dt
and i.end_dt between add_months(to_date('01-MAR-2008'), -1) + 1 and to_date('01-MAR-2008')
and i.hi_start_dt < i.hi_end_dt
and i.hi between add_months(to_date('01-MAR-2008'), -1) + 1 and to_date('01-MAR-2008')
and i.ph_start_dt < i.ph_end_dt
and i.ph_end_dt between add_months(to_date('01-MAR-2008'), -1) + 1 and to_date('01-MAR-2008')
and i.h_start_date < i.h_end_date
and i.h_end_date between add_months(to_date('01-MAR-2008'), -1) + 1 and to_date('01-MAR-2008')Hi Anurag
Thanks for the reply.please find my sample data below . below i am only showing data for one employee only.. i want to write a query where i will query for a month like march 2008 and then i need to find out the record for employe where this month march 2008 is between all the start and end dates like it should be between start_dt and end_dt and h_start_date and h_end_date and hi_strt_dt and hi_end_dt and ph_start_dt and ph_end_dt and where all the combination are true show me that record only .. i don't want any other record.
h_start h_end_
start_dt end_dt date date histrt_dt hi_end_dt ph_start_dt ph_end_dt
1-Sep-07 31-Dec-08 8-Feb-08 31-Aug-08 1-Sep-07 31-Dec-07 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 1-Sep-07 31-Dec-07 1-Sep-07 31-Dec-07 1-Sep-07 31-Dec-07
1-Sep-07 31-Dec-08 1-Sep-08 31-Dec-08 1-Sep-07 31-Dec-07 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 8-Feb-08 31-Aug-08 1-Aug-08 31-Aug-08 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 1-Sep-07 31-Dec-07 1-Aug-08 31-Aug-08 1-Sep-07 31-Dec-07
1-Sep-07 31-Dec-08 1-Sep-08 31-Dec-08 1-Aug-08 31-Aug-08 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 8-Feb-08 31-Aug-08 1-Oct-08 31-Dec-08 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 1-Sep-07 31-Dec-07 1-Oct-08 31-Dec-08 1-Sep-07 31-Dec-07
1-Sep-07 31-Dec-08 1-Sep-08 31-Dec-08 1-Oct-08 31-Dec-08 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 8-Feb-08 31-Aug-08 1-Sep-08 30-Sep-08 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 1-Sep-07 31-Dec-07 1-Sep-08 30-Sep-08 1-Sep-07 31-Dec-07
1-Sep-07 31-Dec-08 1-Sep-08 31-Dec-08 1-Sep-08 30-Sep-08 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 8-Feb-08 31-Aug-08 8-Feb-08 31-Jul-08 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 1-Sep-07 31-Dec-07 8-Feb-08 31-Jul-08 1-Sep-07 31-Dec-07
1-Sep-07 31-Dec-08 1-Sep-08 31-Dec-08 8-Feb-08 31-Jul-08 8-Feb-08 31-Dec-08 -
"Check Statistics" in the Performance tab. How to see SELECT statement?
Hi,
In a previous mail on SDN, it was explained (see below) that the "Check Statistics" in the Performance tab, under Manage in the context of a cube, executes the SELECT stament below.
Would you happen to know how to see the SELECT statements that the "Check Statistics" command executes as mentioned in the posting below?
Thanks
====================================
When you hit the Check Statistics tab, it isn't just the fact tables that are checked, but also all master data tables for all the InfoObjects (characteristics) that are in the cubes dimensions.
Checking nbr of rows inserted, last analyzed dates, etc.
SELECT
T.TABLE_NAME, M.PARTITION_NAME, TO_CHAR (T.LAST_ANALYZED, 'YYYYMMDDHH24MISS'), T.NUM_ROWS,
M.INSERTS, M.UPDATES, M.DELETES, M.TRUNCATED
FROM
USER_TABLES T LEFT OUTER JOIN USER_TAB_MODIFICATIONS M ON T.TABLE_NAME = M.TABLE_NAME
WHERE
T.TABLE_NAME = '/BI0/PWBS_ELEMT' AND M.PARTITION_NAME IS NULL
When you Refresh the stats, all the tables that need stats refreshed, are refreshed again. SInce InfoCube queries access the various master data tables in quereis, it makes sense that SAP would check their status.
In looking at some of the results in 7.0, I'm not sure that the 30 day check is being doen as it was in 3.5. This is one area SAP retooled quite a bit.
Yellow only indicates that there could be a problem. You could have stale DB stats on a table, but if they don't cause the DB optimizer to choose a poor execution plan, then it has no impact.
Good DB stats are vital to query performance and old stats could be responsible for poor performance. I'm just syaing that the Statistics check yellow light status is not a definitive indicator.
If your DBA has BRCONNECT running daily, you really should not have to worry about stats collection on the BW side except in cases immediately after large loads /deletes, and the nightly BRCONNECT hasn't run.
BRCONNECT should produce a lof every time it runs showing you all the tables that it determeined should have stats refreshed. That might be worth a review. It should be running daily. If it is not being run, then you need to look at running stats collection from the BW side, either in Process Chains or via InfoCube automatisms.
Best bet is to use ST04 to get Explain Plans of a poor running InfoCube query and then it can be reviewed to see where the time is being spent and whether stats ate a culprit.Hi,
Thanks, this is what I came up with:
st05,
check SQL Trace, Activate Trace
Now, in Rsa1
on Cube, Cube1,
Manage, Performance tab, Check Statistics
Again, back to st05
Deactivate Trace
then click on Displace Trace
Now, in the trace display, after scanning through the output,
how do I see the SELECT statements that the "Check Statistics" command executes
I will appreciate your help. -
Selected state issue with Menu Module V2
OK so I am getting an issue with Menu Module V2. I have used this before with success but this time I have hit a wall. I possed this question to BC live chat and they bugged out real quick.
The site in construction is http://www.urbanista.com.au
What is happening is that in the top right tools nav with the headings Home, Services, People, Contact Us using Menu Module V2. The Heading Services has a drop down and this is where the issue resides. Roll over any of these nav devices and you will see they will highlight orange. Home is already auto activating its Selcted state. Click on Contact Us and it will do the same. Roll over and click on Services and it appears to have worked. While in Services roll over the drop down again and you will see all links have activated the Selected state. This is the issue. If you view the code of the Services UL you will see only the Services state has been alocated the Slected state. See below:
<li id="Services" class="selected">
<a href="/services.htm">Services</a>
<ul>
<li id="tools-panningdev">
<li id="tools-housing">
<li id="tools-urban-renewal">
<li id="tools-project-management">
<li id="tools-feasibility-tools">
<li id="tools-governance-systems">
<li id="tools-communications">
<li id="tools-projects">
</ul>
</li>
The CSS that runs the nav is as follows:
ul.dropdown {
font-weight: normal;
font-family: Arial, Helvetica, sans-serif;
font-style: normal;
text-decoration: none;
ul.dropdown li {
background-color: transparent;
color: #999;
padding-top: 5px;
padding-right: 10px;
padding-bottom: 5px;
padding-left: 10px;
font-size: 12px;
ul.dropdown li.hover,
ul.dropdown li:hover {
background-color: transparent;
color: #FFF;
ul.dropdown a:link,
ul.dropdown a:visited {
color: #FFF;
text-decoration: none;
ul.dropdown a:hover { color: #ff871f; }
ul.dropdown a:active {
color: #b33b00;
/* -- level mark -- */
ul.dropdown ul {
width: 150px;
margin-top: 1px;
background-image: url(/images/nav-transparency.png);
background-repeat: repeat;
color: #FFF;
ul.dropdown ul li {
font-weight: normal;
ul.dropdown li.selected a {
color: #ff871f;
The last entry 'ul.dropdown li.selected a {color: #ff871f;}' is required in order to allocate a Slected State. Without it not Selected state is active and the links al remian white.
I have tried all manner of combinations and additonal tags with no success. Any suggestions greatly appreciated. I have not modified the default Javascript provided by BC in the system apart from allocating the required ulTagClass as specified. The Javascript in the supplied 'container.html' is as follows:
<script type="text/javascript" >
// ids need to be unique per page, use different ones if you are including multiple menus in the same page
// id of the nav tag, used above
var divTagId = "myMenu1";
// desired id for 1st <ul> tag
var ulTagId = "myMenu1List";
// desired class for 1st <ul> tag
var ulTagClass = "dropdown dropdown-vertical";
if ((null !== ulTagId) && ("" !== ulTagId)) {
document.getElementById(divTagId).getElementsByTagName("ul")[0].setAttribute("id",ulTagId );
if ((null !== ulTagClass) && ("" !== ulTagClass)) {
document.getElementById(divTagId).getElementsByTagName("ul")[0].className = ulTagClass;
// this will set the selected state
if ((null !== ulTagId) && ("" !== ulTagId)) {
catSetSelectedCSSItem(ulTagId);
</script>
Lastly this is one of the recomended navs by BC at the following address: http://lwis.net/free-css-drop-down-menu/
I have used these before with success but for the life of me this has stumped me big time.Hi Matthew,
Having a super quick look at the code I'd say it's because of:
ul.dropdown li.selected a {
color: #ff871f;
This affects all the child elements.
To override this down the line you could do something like:
ul.dropdown li.selected ul li a {
color: #fff;
This would override the parent link color when selected.
You could probably then also add:
ul.dropdown li.selected ul li.selected a {
color: #ff871f;
For the dropdown selected states.
That's a quick look though so don't quote me too much -
Toplink Essentials creates not usable select statement
My problem is the following:
I have the following NamedQuery statement in an JPA Entity Class:
@NamedQuery(name = "Leasingteilvertrag.findSearch",
query = "select distinct o " +
" from Leasingteilvertrag o " +
" left outer join o.sachbearbeiterList s " +
" where (:wtvStatusBearb1 is null or :wtvStatusBearb2 = -1 or o.wtvStatusBearb =
:wtvStatusBearb3)" +
" and (:wtvStatusVerwert1 is null or :wtvStatusVerwert2 = -1 or o.wtvStatusVerwert = :wtvStatusVerwert3)" +
" and (:wtvAdressNr1 is null or :wtvAdressNr2 = -1 or o.wtvAdressNr =
:wtvAdressNr3)" +
" and (:wtvEingangsdatum1 is null or o.wtvEingangsdatum >= :wtvEingangsdatum2)" +
" and (:wtvEingangsdatumBis1 is null or o.wtvEingangsdatum <= :wtvEingangsdatumBis2)"
+
" and (:wtvLlvNr1 is null or o.wtvLlvNr = :wtvLlvNr2)" +
" and (:wtvFirma1 is null or o.wtvFirma = :wtvFirma2)" +
" and (:wsbId1 is null or :wsbId2 = -1 or s.wsbSbId = :wsbId3)")
Oracle Toplink translates this (according to to opmn log of the Application Server)
to:
SELECT DISTINCT t0.WTV_ID, t0.WTV_SL_PLUS_KNZ, t0.WTV_ABGESCHLOSSENDATUM, t0.WTV_SL_TECHNIK_DATE, t0.WTV_ADRESS_POOL, t0.WTV_SL_TECHNIK_KNZ,
t0.WTV_AKTENZEICHEN_RA, t0.WTV_SONDERAFA_OBJEKTE_AKTUELL,
t0.WTV_ANZAHLRUECKSTAENDIGERRATEN, t0.WTV_SONDERAFA_OBJEKTE_GEBUCHT,
t0.WTV_BANKAUSKUNFT_KNZ, t0.WTV_STATUS_BEARB, t0.WTV_EINGANGSDATUM,
t0.WTV_STATUS_BEARB_DATUM, t0.WTV_EINSCHAETZUNG_BONI, t0.WTV_STATUS_VERWERT,
t0.WTV_EWB_DATUM_ERFASSUNG, t0.WTV_STATUS_VERWERT_DATUM, t0.WTV_EWB_GEBUCHT,
t0.WTV_STATUS_FREIGABE, t0.WTV_EWB_SB_ERFASSUNG, t0.WTV_STATUS_FREIGABE_DATUM,
t0.WTV_FIRMA, t0.WTV_VERBLEIB_AKTE, t0.WTV_WAEHRUNG_AUSFALL,
t0.WTV_KUENDIGUNGSFORDERUNG, t0.WTV_WAEHRUNG_EWB, t0.WTV_LLV_NR,
t0.WTV_WAEHRUNG_RUECKST_ANR, t0.WTV_LTV_NR, t0.WTV_WAEHRUNG_SONDERAFA_OBJEKTE,
t0.WTV_PROZESSKOSTEN_RISIKO, t0.WTV_WAE_EINSCHAETZUNG_BONI,
t0.WTV_RUECKST_ANRECHNUNG_GEBUCHT, t0.WTV_WAE_KUENDIGUNGSFORDERUNG,
t0.WTV_SL_KASKO_DATE, t0.WTV_WIEDERGESUNDUNGSDATUM, t0.WTV_SL_PLUS_DATE,
t0.WTV_ABGESCHLOSSEN_KNZ, t0.WTV_AKTENZEICHEN_FAV, t0.WTV_TEILRISIKO_KNZ,
t0.WTV_AUSFALL, t0.WTV_BETRUG_KNZ, t0.WTV_EINGANGSDATUM_ALT,
t0.WTV_CHANGE_USER, t0.WTV_EWB_DATUM_FREIGABE, t0.WTV_CHANGE_DATE,
t0.WTV_EWB_SB_FREIGABE, t0.WTV_FREIGABE_KOMMENTAR, t0.WTV_KUENDIGUNGSDATUM,
t0.WTV_ADRESS_NR, t0.WTV_ALTFALL_KNZ, t0.WTV_OPERATIONELLES_RISIKO,
t0.WTV_BEMERKUNG, t0.WTV_SACHSTAND, t0.WTV_EWB_AKTUELL,
t0.WTV_LLV_NR_UMFINANZIERUNG, t0.WTV_EWB_KORREKTUR, t0.WTV_SL_KASKO_KNZ,
t0.WTV_FIRMA_UMFINANZIERUNG, t0.WTV_RUECKST_ANRECHNUNG_AKTUELL,
t0.WTV_KUENDIGUNGSFORDERUNG_ALT, t0.WTV_LEASINGVERTRAG_ID,
t0.WTV_RUECKST_ANRECHNUNG_BUC_ID, t0.WTV_EWB_BUC_ID,
t0.WTV_SONDERAFA_OBJEKTE_BUC_ID FROM VWDB_LEASINGTEILVERTRAG t0,
VWDB_LEASINGTEILVERTRAG t2, VWDB_SACHBEARBEITER t1 WHERE (((((((((((? IS NULL)
OR (? = (? - ?))) OR (t0.WTV_STATUS_BEARB = ?)) AND (((? IS NULL) OR (? = (? -
?))) OR (t0.WTV_STATUS_VERWERT = ?))) AND (((? IS NULL) OR (? = (? - ?))) OR
(t0.WTV_ADRESS_NR = ?))) AND ((? IS NULL) OR (t0.WTV_EINGANGSDATUM > ?))) AND
((? IS NULL) OR (t0.WTV_EINGANGSDATUM < ?))) AND ((? IS NULL) OR (t0.WTV_LLV_NR
= ?))) AND ((? IS NULL) OR (t0.WTV_FIRMA = ?))) AND (((? IS NULL) OR (? = (? -
?))) OR (t1.WSB_SB_ID = ?))) AND (t1.WSB_LTV_ID (+) = t0.WTV_ID))
The Problem is the "VWDB_LEASINGTEILVERTRAG t2" entry in the FROM clause of the generated select statement. This causes the select to generate the cartesian product.
Has anyone had such a problem before? How can this be solved?Hello,
I have exactly the same problem (with a simpler query though). I'm running my webapp on a GlassFish V2 (build b09d-fcs), Toplink Essentials JPA impl. and a MySQL 6.0.4 database server.
I'm trying to run the following JPQL query: select f from Foo f where (1=1) and f.title = :title
After having set persistence log levels to FINE, the following SQL is displayed:
select t0.XXX, t0.YYY from Foo t0, Foo t1 where ((?=?) and (t0.title= ?))
bind => [1, 1, Bar]
(1 = 1) is used because of dynamic query generation (application code)
The problem is that the additional from clause is generating a cartesian product on my Foo table, which causes many duplicated results to be returned.
I have simplified the select part of the query but the actual query is of the same kind: no join, only 1 entity, no inheritance, a single N:1 lazy-initialized entity (*Foo-1FooParent). The only "exotic" facet of my Foo mapping is the use of an @Enumerated column.
Is it the expected behavior?
-Titix -
Last night I attempted to roll a Crystal Reports .NET project to my production web server. This app has 3 new Crystal Reports. The Reports are all based upon the same Oracle Views on the same Oracle Database. Two of the reports work while the third report returns an ORA-24333 error. The exact reports and .NET code, connecting to the same Oracle database work fine in Preview mode and when published to my development IIS web server. The ONLY thing that is different is that the report is now being run on the production IIS web server. (But it is still the same Oracle Database we are connecting to in all environments.)
Here is the Command used for the Crystal Report that fails. Sorry it is so long. Basically, it is 4 Select statements joined together with Unions. Stuff in {} are parameters that are passed to it.
SELECT A.Custno as Custno, C.CUST_NAME as Cust_Name, D.CONTACT_NAME as Contact_Name, A.FISCALPRD as FiscalPrd, A.PROJECTNAME as ProjectName, A.INVOICENO as InvoiceNO, A.INVDATE, A.PAYDATE, A.ORDERNO as OrderNo, A.TOTALAMT as TotalAmt, A.ELIGIBLEAMT as EligibleAmt, A.SALESPOINTERD as SalesPointErd, 0 as FORFEIT, 0 as BONUSPOINTERD, 0 as PAYPTSEARNED, P.POINTPERCD as POINTPERCD, case when A.PAYDATE is null and A.INVDATE>SYSDATE-30 then round(P.POINTPERCD*A.ELIGIBLEAMT/100,0) else 0 end as PAYPTSELIG, case when A.PAYDATE is null and A.INVDATE>SYSDATE-30 then TO_CHAR(A.INVDATE+30,'MM/DD/YYYY') else '' end as PAYBYforPAYPTS
FROM VW_TRIPPOINTS A
left join VW_POINTS P on A.COMPANY=P.COMPANY and substr(A.FISCALPRD,1,4)=to_char(P.FISCALYEAR) and P.CODE='P'
join VW_CUSTOMERS C on (C.COMPANY=A.COMPANY or A.custno='313243') and C.CUST_NUMB=A.custno
join VW_SALESMEN D on C.DIST_MGR=D.CONTACT_NUMBER
where A.POINTCODE='S' and A.COMPANY='30' and A.ELIGIBLEAMT<>0 and A.custno='{?@Cust_ID}' and A.FISCALPRD>={?@BegPeriod} and A.FISCALPRD<={?@EndPeriod}
Union --Bonus Points
SELECT A.Custno as Custno, C.CUST_NAME as Cust_Name, D.CONTACT_NAME as Contact_Name, A.FISCALPRD as FiscalPrd, A.Notes as ProjectName, Cast((Row_Number() over (Order By CustNo, OrderNo, InvoiceNo, IDKey)) as varchar(10)) as InvoiceNO, A.INVDATE, Null as PAYDATE, Cast((Row_Number() over (Order By IDKey)) as varchar(10)) as ORDERNO, Coalesce(A.TOTALAMT,0) as TotalAmt, Coalesce(A.ELIGIBLEAMT,0) as EligibleAmt, Coalesce(A.SALESPOINTERD,0) as SalesPointErd, 0 as FORFEIT, A.BONUSPOINTERD as BonusPointErd, 0 as PAYPTSEARNED, 0 as POINTPERCD, 0 as PAYPTSELIG, '' as PAYBYforPAYPTS
FROM VW_TRIPPOINTS A
join VW_CUSTOMERS C on (C.COMPANY=A.COMPANY or A.custno='313243') and C.CUST_NUMB=A.custno
join VW_SALESMEN D on C.DIST_MGR=D.CONTACT_NUMBER
where A.POINTCODE='B' and A.COMPANY='30' and A.custno='{?@Cust_ID}' and A.FISCALPRD>={?@BegPeriod} and A.FISCALPRD<={?@EndPeriod}
Union --Pay Points
SELECT A.Custno as Custno, C.CUST_NAME as Cust_Name, D.CONTACT_NAME as Contact_Name, A.FISCALPRD as FiscalPrd, A.PROJECTNAME as ProjectName, A.INVOICENO as InvoiceNO, A.INVDATE, A.PAYDATE, A.ORDERNO as OrderNo, 0 as TotalAmt, 0 as EligibleAmt, 0 as SALESPOINTERD, 0 as FORFEIT, 0 as BONUSPOINTERD, coalesce(A.PAYPOINTERD,0) as PAYPTSEARNED, 0 as POINTPERCD, 0 as PAYPTSELIG, '' as PAYBYforPAYPTS
FROM VW_TRIPPOINTS A
join VW_CUSTOMERS C on (C.COMPANY=A.COMPANY or A.custno='313243') and C.CUST_NUMB=A.custno
join VW_SALESMEN D on C.DIST_MGR=D.CONTACT_NUMBER
where (A.POINTCODE='P' or A.POINTCODE='C') and A.COMPANY='30' and A.PAYPOINTERD<>0 and A.custno='{?@Cust_ID}' and A.FISCALPRD>={?@BegPeriod} and A.FISCALPRD<={?@EndPeriod}
Union --Sales Points Forfeited
SELECT A.Custno as Custno, C.CUST_NAME as Cust_Name, D.CONTACT_NAME as Contact_Name, A.FISCALPRD as FiscalPrd, A.PROJECTNAME as ProjectName, A.INVOICENO as InvoiceNO, A.INVDATE, A.PAYDATE, A.ORDERNO as OrderNo, 0 as TotalAmt, 0 as EligibleAmt, 0 as SalesPointErd, Coalesce(A.SalesPointErd,0) as FORFEIT, 0 as BONUSPOINTERD, 0 as PAYPTSEARNED, 0 as POINTPERCD, 0 as PAYPTSELIG, '' as PAYBYforPAYPTS
FROM VW_TRIPPOINTS A
join VW_CUSTOMERS C on (C.COMPANY=A.COMPANY or A.custno='313243') and C.CUST_NUMB=A.custno
join VW_SALESMEN D on C.DIST_MGR=D.CONTACT_NUMBER
where A.POINTCODE='R' and A.COMPANY='30' and A.SalesPointErd<>0 and A.custno='{?@Cust_ID}' and A.FISCALPRD>={?@BegPeriod} and A.FISCALPRD<={?@EndPeriod}
order by custno, OrderNo, InvoiceNoBecause we don't all have the Oracle error numbers and messages memorized:
ORA-24333: zero iteration count
Cause: An iteration count of zero was specified for the statement
Action: Specify the number of times this statement must be executed -
Convert NVARCHAR2 to VARCHAR2 in select statement
I need to convert NVARCHAR2 values to VARCHAR2 in a select statement. Is this possible? The COUNTY_PARCEL_DATA colums are the NVARCHAR2 columns that need converting. I've tried TRANSLATE(COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER USING CHAR_CS), CAST(COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER AS VARCHAR2(100)), CONVERTCS(COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER, 'CHAR_CS') and others directly in the statement for each column. Anything I'm missing? Thanks.
SELECT BENEFICIARY.NAME_FIRST || ' ' || BENEFICIARY.NAME_LAST AS NAME,
COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER
|| ' '
|| COUNTY_PARCEL_DATA.SITUS_STREET_DIRECTION
|| ' '
|| COUNTY_PARCEL_DATA.SITUS_STREET_NAME
|| ' '
|| COUNTY_PARCEL_DATA.SITUS_STREET_TYPE
AS ADDRESS,
COUNTY_PARCEL_DATA.SITUS_CITY AS CITY,
'AZ' AS STATE,
COUNTY_PARCEL_DATA.SITUS_ZIP AS ZIP,
'T4' AS TRACER
FROM BENEFICIARY
LEFT OUTER JOIN
VARS_PARCEL
ON BENEFICIARY.AVNUM = VARS_PARCEL.AVNUM
LEFT OUTER JOIN
COUNTY_PARCEL_DATA
ON VARS_PARCEL.APN = COUNTY_PARCEL_DATA.APN
LEFT OUTER JOIN
OWNER
ON BENEFICIARY.BENEFICIARY_ID = OWNER.BENEFICIARY_ID
WHERE (SUBSTR (VARS_PARCEL.AVNUM, 0, 4) IN
(SELECT COLUMN_VALUE
FROM TABLE(SPLIT_STRING (
R_VARS_MAILING_NOTICES.NEIGHBORHOODS
OR R_VARS_MAILING_NOTICES.NEIGHBORHOODS IS NULL)
AND BENEFICIARY.BENEFICIARY_TYPE = 'Tenant';
Edited by: Guddie on Apr 6, 2010 12:23 PMAre you doing the NVARCHAR2 to VARCHAR2 conversions everywhere, see comments below
SELECT BENEFICIARY.NAME_FIRST || ' ' || BENEFICIARY.NAME_LAST AS NAME,
COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER <==== Here, obviously
|| ' '
|| COUNTY_PARCEL_DATA.SITUS_STREET_DIRECTION <==== Here
|| ' '
|| COUNTY_PARCEL_DATA.SITUS_STREET_NAME <==== Here
|| ' '
|| COUNTY_PARCEL_DATA.SITUS_STREET_TYPE <==== Here
AS ADDRESS,
COUNTY_PARCEL_DATA.SITUS_CITY AS CITY, <==== Here
'AZ' AS STATE,
COUNTY_PARCEL_DATA.SITUS_ZIP AS ZIP, <==== Here
'T4' AS TRACER
FROM BENEFICIARY
LEFT OUTER JOIN
VARS_PARCEL
ON BENEFICIARY.AVNUM = VARS_PARCEL.AVNUM
LEFT OUTER JOIN
COUNTY_PARCEL_DATA
ON VARS_PARCEL.APN = COUNTY_PARCEL_DATA.APN <==== Here, maybe not so obvious
LEFT OUTER JOIN
OWNER
ON BENEFICIARY.BENEFICIARY_ID = OWNER.BENEFICIARY_ID
WHERE (SUBSTR (VARS_PARCEL.AVNUM, 0, 4) IN
(SELECT COLUMN_VALUE
FROM TABLE(SPLIT_STRING (
R_VARS_MAILING_NOTICES.NEIGHBORHOODS
OR R_VARS_MAILING_NOTICES.NEIGHBORHOODS IS NULL)
AND BENEFICIARY.BENEFICIARY_TYPE = 'Tenant';This is assuming that all fields in COUNTY_PARCEL_DATA are NVARCHAR2.
Edited by: AlanWms on Apr 6, 2010 3:53 PM changed "joins" to "conversions" in 1st sentence. -
Inline select statement and SQL optimizatino
Hi everyone,
I am trying to optimze a script but can't get the fulle explainplan in PL/SQL.
The problem is that the select statements in de column defenition is not explained. below are the 2 scripts I want to compare:
SQL1:
Select
z.title
, (select name from members where id =z.id) as name
, z.id
from job z
SQL2
Select
z.title
, d.name
, z.id
from job z
left outer join members d on z.id=d.id
My question is: what is the effect on performance and cost of the 'inline select' statement of name in SQL1
hope to hear form you soon
Harm
Edited by: HALI on 25-nov-2010 1:14In respons to your question below is the output:
I altered the used names, tablenames etc. according to our privacy pollacy.
A far as I can see the inline statement is not traced.
The query with ansi-join:
xplain plan for
select
id as Interne
, mv.ie_id as Act
, 'H_W' as Rl
from testing i
left outer join resutino m on i.hand=m.id
left outer join vert mv on m.voor || case when m.voeg is not null then ' '|| m.voeg end ||' '||m.naam = mv.source and mv.field = 'employee'
explain plan succeeded.
select * from table(dbms_xplan.display)
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 684 | 47880 | 19 |
| 1 | HASH JOIN OUTER | | 684 | 47880 | 19 |
| 2 | HASH JOIN OUTER | | 684 | 22572 | 15 |
| 3 | TABLE ACCESS FULL | testing | 684 | 5472 | 7 |
| 4 | TABLE ACCESS FULL | resutino | 308 | 7700 | 7 |
| 5 | TABLE ACCESS FULL | VERT | 166 | 6142 | 3 |
Note: cpu costing is off, 'PLAN_TABLE' is old version
13 rows selected
The inline select query:
xplain plan for
SELECT
case when (select ie_id from vert xov where xov.field = 'field' and source in
(select m.voor || case when m.voeg is not null then ' '|| m.voegend ||' '||m.naam from resultino m where i.hand= m.id)) is not null then
'X'||(select ie_id from vert xov where xov.field = 'field' and source in
(select m.voor || case when m.voeg is not null then ' '|| m.voegend ||' '||m.naam from resultino m where i.hand= m.id))
else 'X' || (select ie_id from vert xov where xov.source = 'none' and xov.veld = 'employee')
end as Act,
'ADM' as Rol,
i.id as Interne
FROM testing i
explain plan succeeded.
select * from table(dbms_xplan.display)
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 684 | 5472 | 7 |
| 1 | TABLE ACCESS FULL | testing | 684 | 5472 | 7 |
Note: cpu costing is off, 'PLAN_TABLE' is old version
9 rows selected -
Select Statement -- Where Clause Execution Order
What is the order of execution of the "AND" and "OR" in the WHERE clause of a Select statement?
Are the "AND"'s executed from the top down, left to right? Is it the same for the "OR"'s execution?
Thanks for any help...Not clear why you care. There is an order in which the optimizer parses the SQL (which may change from ver to ver), but this is a fairly quick operation. The order in which tables are visited and predicates evaluated is dependent on what the op[timizer does with the SQL.
Ken -
Hello to all
Here in my requirement i did one select query logic
bt performance wise it is not working proper way
if u find any changes relevant to below select statement plz reply me
here is my Select Query
Extract all the data from the database tables .
Retrieving data from table MARA .
SELECT * FROM mara
INTO CORRESPONDING FIELDS OF TABLE it_mara
WHERE matnr IN s_matnr AND mtart IN s_mtart AND ernam IN s_ernam.
sort it_mara by matnr.
DELETE ADJACENT DUPLICATES FROM it_mara comparing all fields.
IF sy-subrc NE 0.
MESSAGE s005(zmm).
REFRESH: it_marc.
STOP.
ENDIF.
Retrieving data of Product Group Level3 on the condition that ZZPARENT should not be empty .
IF wa_mara-zzparent NE ' '.
READ TABLE it_mara INTO wa_mara WITH KEY matnr = wa_mara-matnr.
MOVE wa_mara-zzparent TO wa_final-prodh3.
ENDIF.
SELECT matnr werks mtvfp mfrgr ladgr prctr sernp stawn ekgrp dismm lgfsb insmk
FROM marc
INTO CORRESPONDING FIELDS OF TABLE it_marc
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-matnr
AND werks IN s_werks .
sort it_marc by matnr werks.
DELETE ADJACENT DUPLICATES FROM it_marc.
IF sy-subrc NE 0.
MESSAGE s005(zmm).
REFRESH: it_marc.
STOP.
ENDIF.
Retrieving data from table MVKE .
SELECT matnr vkorg vtweg dwerk kondm ktgrm mtpos mvgr1 mvgr2 mvgr3 mvgr4 mvgr5
FROM mvke
INTO CORRESPONDING FIELDS OF TABLE it_mvke
FOR ALL ENTRIES IN IT_MARA
where matnr = it_mara-matnr and
vkorg IN s_vkorg.
IF sy-subrc NE 0.
MESSAGE s005(zmm).
REFRESH: it_marc.
STOP.
ENDIF.
Retrieving data from table MARM, satisfying the condition for Case Pack Factor as CS .
SELECT MATNR meinh umrez laeng breit hoehe meabm volum voleh brgew
FROM marm
INTO CORRESPONDING FIELDS OF TABLE it_marm
FOR ALL ENTRIES IN IT_MARA
WHERE MATNR = IT_MARA-MATNR
AND meinh = 'CS'.
Retrieving data from table MAKT .
SELECT matnr maktx
FROM makt
INTO CORRESPONDING FIELDS OF TABLE it_makt
WHERE matnr IN s_matnr .
Retrieving data from table AMPL and fetching data for field GPCCODE .
SELECT bmatn ematn
FROM ampl
INTO CORRESPONDING FIELDS OF TABLE it_ampl
FOR ALL ENTRIES IN it_mara
WHERE bmatn = it_mara-matnr
AND datuv LE sy-datum
AND datub GE sy-datum.
IF NOT wa_ampl IS INITIAL.
READ TABLE it_ampl INTO wa_ampl WITH KEY bmatn = wa_mara-matnr.
MOVE wa_ampl-ematn TO wa_final-gpccode.
ELSE.
SELECT bmatn ematn
FROM ampl
INTO CORRESPONDING FIELDS OF TABLE it_ampl
FOR ALL ENTRIES IN it_mara
WHERE bmatn = it_mara-matnr.
IF NOT wa_ampl IS INITIAL.
READ TABLE it_ampl INTO wa_ampl WITH KEY bmatn = wa_ampl-bmatn.
MOVE wa_mara-mfrpn TO wa_final-gpccode.
ELSE.
wa_final-gpccode = ' '.
ENDIF.
ENDIF.
Moving Relevant data to IT_FINAL (Final Internal Table ) .
LOOP AT it_mara INTO wa_mara .
MOVE-CORRESPONDING wa_mara TO wa_final.
MOVE : wa_mara-zzparent TO wa_final-prodh3.
READ TABLE it_mvke INTO wa_MVKE with key vkorg = wa_mvke-vkorg.
MOVE : wa_mvke-vkorg TO wa_final-vkorg,
wa_mvke-vtweg TO wa_final-vtweg,
wa_mvke-dwerk TO wa_final-dwerk,
wa_mvke-kondm TO wa_final-kondm,
wa_mvke-ktgrm TO wa_final-ktgrm,
wa_mvke-mtpos TO wa_final-mtpos,
wa_mvke-mvgr1 TO wa_final-mvgr1,
wa_mvke-mvgr2 TO wa_final-mvgr2,
wa_mvke-mvgr3 TO wa_final-mvgr3,
wa_mvke-mvgr4 TO wa_final-mvgr4,
wa_mvke-mvgr5 TO wa_final-mvgr5.
READ TABLE it_marc INTO wa_marc WITH KEY matnr = wa_marc-matnr .
MOVE : wa_marc-mtvfp TO wa_final-mtvfp,
wa_marc-mfrgr TO wa_final-mfrgr,
wa_marc-ladgr TO wa_final-ladgr,
wa_marc-prctr TO wa_final-prctr,
wa_marc-sernp TO wa_final-sernp,
wa_marc-stawn TO wa_final-stawn,
wa_marc-ekgrp TO wa_final-ekgrp,
wa_marc-dismm TO wa_final-dismm,
wa_marc-lgfsb TO wa_final-lgfsb,
wa_marc-insmk TO wa_final-insmk.
READ TABLE it_ampl INTO wa_ampl WITH KEY bmatn = wa_mara-matnr BINARY SEARCH.
MOVE : wa_ampl-bmatn TO wa_final-bmatn.
READ TABLE it_marm INTO wa_marm WITH KEY matnr = wa_mara-matnr BINARY SEARCH.
MOVE: wa_marm-meinh TO wa_final-meinh,
wa_marm-umrez TO wa_final-umrez,
wa_marm-laeng TO wa_final-laeng,
wa_marm-breit TO wa_final-breit,
wa_marm-hoehe TO wa_final-hoehe,
wa_marm-meabm TO wa_final-meabm,
wa_marm-volum TO wa_final-volum,
wa_marm-brgew TO wa_final-brgew.
READ TABLE it_makt INTO wa_makt WITH KEY matnr = wa_mara-matnr.
MOVE wa_makt-maktx TO wa_final-maktx.
*******************************FOR SALE ORGANIZATION CHECK BOX***************
IF c_sodata = 'X'.
SELECT matnr vkorg lvorm
FROM mvke
INTO CORRESPONDING FIELDS OF TABLE it_checkselected
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-matnr
AND vkorg IN s_vkorg
AND vkorg NE 'YMUS'
AND lvorm EQ ' '.
IF sy-subrc NE 0.
MESSAGE s005(zmm).
STOP.
ENDIF.
LOOP AT it_checkselected INTO wa_checkselected.
READ TABLE it_checkselected INDEX sy-index INTO wa_checkselected .
MOVE : wa_checkselected-vkorg TO wa_final-vkorg,
wa_checkselected-lvorm TO wa_final-lvorm.
ENDLOOP.
ENDIF.
***************************FOR PLANT CHECK BOX*****************************
Retrieving data if check box for Plantdata is Enabled .
IF c_pdata = 'X'.
SELECT matnr werks mtvfp mfrgr ladgr prctr sernp stawn ekgrp dismm lgfsb insmk
FROM marc
INTO CORRESPONDING FIELDS OF TABLE it_marc
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-matnr
AND werks IN s_werks .
READ TABLE it_marc INTO wa_marc WITH KEY matnr = wa_marc-matnr BINARY SEARCH.
MOVE : wa_marc-werks TO wa_final-werks,
wa_marc-mtvfp TO wa_final-mtvfp,
wa_marc-mfrgr TO wa_final-mfrgr,
wa_marc-ladgr TO wa_final-ladgr,
wa_marc-prctr TO wa_final-prctr,
wa_marc-sernp TO wa_final-sernp,
wa_marc-stawn TO wa_final-stawn,
wa_marc-ekgrp TO wa_final-ekgrp,
wa_marc-dismm TO wa_final-dismm,
wa_marc-lgfsb TO wa_final-lgfsb,
wa_marc-insmk TO wa_final-insmk.
SELECT werks lgnum
FROM t320
INTO CORRESPONDING FIELDS OF TABLE it_t320
FOR ALL ENTRIES IN it_marc
WHERE werks = it_marc-werks
AND werks IN s_werks.
SELECT matnr lgnum ltkza ltkze lgbkz block lhmg1 lhme1 lety1 zzcase_orient
FROM mlgn
INTO CORRESPONDING FIELDS OF TABLE it_mlgn
FOR ALL ENTRIES IN it_t320
WHERE lgnum = it_t320-lgnum
AND matnr IN s_matnr.
READ TABLE it_mlgn INTO wa_mlgn WITH KEY lgnum = wa_t320-lgnum BINARY SEARCH.
MOVE: wa_mlgn-lgnum TO wa_final-lgnum,
wa_mlgn-ltkza TO wa_final-ltkza,
wa_mlgn-ltkze TO wa_final-ltkze,
wa_mlgn-lgbkz TO wa_final-lgbkz,
wa_mlgn-block TO wa_final-block,
wa_mlgn-lhmg1 TO wa_final-lhmg1,
wa_mlgn-lhme1 TO wa_final-lhme1,
wa_mlgn-lety1 TO wa_final-lety1,
wa_mlgn-zzcase_orient TO wa_final-zzcase_orient.
SELECT matnr bklas
FROM mbew
INTO TABLE it_mbew
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-matnr.
READ TABLE it_mbew INTO wa_mbew WITH KEY matnr = wa_mara-matnr BINARY SEARCH.
MOVE wa_mbew-bklas TO wa_final-bklas.
ENDIF.
APPEND wa_final TO it_final .
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM it_final comparing all fields.
IF sy-subrc NE 0.
MESSAGE s005(zmm).
STOP.
CLEAR sy-subrc.
ENDIF.
REFRESH: it_mara,it_marc,it_mvke,it_mlgn,it_ampl,it_t320,
it_checkselected.
plese help me its an urgent requirement
Points will be rewarded fro satisfying answer
Regards
ASLAMselect only those fields which u want in ur program, in the first select statement u are selecting all fields, u can avoiid that.
secondly u are using into corresponding fields of table, try to avoid that also
define the IT with fields which u r retrieving from the select statement and use into table, its more efficient that into corresponding fields
try to avoid select inside loop statement.
bye -
SQL column as select statement to be referenced into a group by
Is there a notation or solution to be able to reference a column that is a inline select statement within a group by as detailed below? The group by will not accept the alias. I also tried to make the SQL a MAX to remove the need for the group by reference and this returned invalid expression.
SELECT DISTINCT hdr.BUSINESS_UNIT,
hdr.SESSN_ID,
hdr.STREAM_ROOT_ID,
hdr.SESSN_STS_CD,
hdr.SESSN_CRE_DTTM,
CASE
WHEN C.OPRID <> ' ' THEN C.OPRID
ELSE S.OPERATOR
END OPRID,
strm.QS_APP_CONTEXT,
RECV.QTY_SH_RECVD Quantity_Received,
CASE
WHEN hdr.BUSINESS_UNIT = 'MFG01' THEN MAX(G.MFDS_SGRP_SIZE)
ELSE MAX(S.SESSN_SGRP_SIZE)
END Quantity_Inspected,
MAX(S.QS_VALUEREADING_1) Defect_Count,
CASE
WHEN MAX(S.QS_VALUEREADING_1) = 0 THEN ' '
ELSE MAX(G.MFDS_NAME)
END Characteristic,
MAX(CMNT.QS_COMMENT2) COMMENTS,
strm.INV_ITEM_ID,
itm.DESCR,
strm.WORK_CENTER_CODE,
strm.VENDOR_ID,
*(SELECT V.NAME1 FROM PS_VENDOR V WHERE strm.VENDOR_ID = V.VENDOR_ID AND V.SETID = (SELECT SETID FROM PS_SET_CNTRL_REC*
WHERE RECNAME = 'VENDOR'
AND SETCNTRLVALUE = strm.BUSINESS_UNIT)) VENDOR_NAME,
strm.PRDN_AREA_CODE,
strm.COMPL_OP_SEQ,
strm.PRODUCTION_TYPE,
C.RECEIVER_ID,
C.RECV_LN_NBR,
RECV.PO_ID,
RECV.LINE_NBR,
RECV.SCHED_NBR,
C.PRODUCTION_ID,
C.SERIAL_ID,
C.INV_LOT_ID
FROM PS_QS_SESSN_HDR8 hdr
LEFT OUTER JOIN PS_QS_SESSN_TRACE8 C
ON hdr.BUSINESS_UNIT = C.BUSINESS_UNIT
AND hdr.SESSN_ID = C.SESSN_ID
LEFT OUTER JOIN PS_RECV_INSPDTL_VW RECV
ON C.BUSINESS_UNIT = RECV.BUSINESS_UNIT
AND C.RECEIVER_ID = RECV.RECEIVER_ID
AND C.RECV_LN_NBR = RECV.RECV_LN_NBR
LEFT OUTER JOIN PS_QS_STREAM_ROOT strm
ON hdr.STREAM_ROOT_ID = strm.STREAM_ROOT_ID
AND hdr.BUSINESS_UNIT = strm.BUSINESS_UNIT
LEFT OUTER JOIN PS_QS_STREAM8_VW G
ON strm.STREAM_ROOT_ID = G.STREAM_ROOT_ID
AND strm.BUSINESS_UNIT = G.BUSINESS_UNIT
LEFT OUTER JOIN PS_QS_SUBGROUP S
ON hdr.BUSINESS_UNIT = S.BUSINESS_UNIT
AND hdr.SESSN_ID = S.SESSN_ID
AND S.STREAM_ID = G.STREAM_ID
LEFT OUTER JOIN PS_QS_SESSN_COMM8 CMNT
ON S.BUSINESS_UNIT = CMNT.BUSINESS_UNIT
AND S.SESSN_ID = CMNT.SESSN_ID
AND S.STREAM_ID = CMNT.STREAM_ID
AND C.SAMPLE = CMNT.SAMPLE
LEFT OUTER JOIN PS_MASTER_ITEM_TBL itm
ON itm.INV_ITEM_ID = strm.INV_ITEM_ID
LEFT OUTER JOIN PS_SET_CNTRL_REC cntrl
ON itm.SETID = cntrl.SETID
AND cntrl.RECNAME = 'MASTER_ITEM_TBL'
AND cntrl.SETCNTRLVALUE = strm.BUSINESS_UNIT
WHERE S.QS_VALUEREADING_1 = (SELECT MAX(S2.QS_VALUEREADING_1)
FROM PS_QS_SUBGROUP S2
WHERE S2.BUSINESS_UNIT = S.BUSINESS_UNIT
AND S2.SESSN_ID = S.SESSN_ID
AND S2.STREAM_ID = S.STREAM_ID)
GROUP BY hdr.BUSINESS_UNIT,
hdr.SESSN_ID,
hdr.STREAM_ROOT_ID,
hdr.SESSN_STS_CD,
hdr.SESSN_CRE_DTTM,
C.OPRID,
S.OPERATOR,
strm.QS_APP_CONTEXT,
RECV.QTY_SH_RECVD,
strm.INV_ITEM_ID,
itm.DESCR,
strm.WORK_CENTER_CODE,
strm.VENDOR_ID,
VENDOR_NAME,
strm.PRDN_AREA_CODE,
strm.COMPL_OP_SEQ,
strm.PRODUCTION_TYPE,
C.RECEIVER_ID,
C.RECV_LN_NBR,
RECV.PO_ID,
RECV.LINE_NBR,
RECV.SCHED_NBR,
C.PRODUCTION_ID,
C.SERIAL_ID,
C.INV_LOT_IDHi,
Assign the alias in a sub-query. Then you'll be able to use it wherever you want to, and how many times you want to, in a super-query.
For example:
WITH got_vendor AS
SELECT hdr.business_unit
SELECT v.name1
FROM ps_vendor v
WHERE strm.vendor_id = v.vendor_id
AND v.setid = (
SELECT setid
FROM ps_set_cntrl_rec
WHERE recname = 'VENDOR'
AND setcntrlvalue = strm.business_unit
) AS vendor_name
FROM ps_qs_sessn_hdr8 hdr
SELECT business_unit -- NOTE: no hdr.; all columns are from got_vendor now
, vendor
FROM got_vendor
GROUP BY business_unit
, vendor
;When you define an alias (such as vendor) in a query, you can use that alias in the ORDER BY clause of that same query, but that's the only place in that same query where you can use it. If you want to use the alias anywhere else (e.g., in the GROUP BY clause, as in your example, the WHERE clause, or elsewhere in the SELECT clause), then you probably want to compute it in a sub-query, as shown above.
There's probably a better way to compute vendor, but that's a separate problem.
Edited by: Frank Kulash on Jan 3, 2012 10:37 AM
Added example -
Prompting for user input in nested select statements
I recently rewrote a query to use a nested select statement instead of specifying every SELECT field on the GROUP BY line. Here's the query which works perfectly with hard-coded values of '030', '01/01/11', and '12/31/11'.
SELECT T0.[CardName] AS Customer, T0.[CardCode] as 'Cust ID', T0.[Phone1] as Phone, T0.[CntctPrsn] as 'Contact Person', T0.[Address], T0.[City], T0.[State1] as State, T0.[ZipCode] as 'Zip Code', T0.[Country], T1.[TotalSales]
FROM OCRD T0
INNER JOIN
(SELECT I.[CardCode] AS CardCode, SUM(I.[DocTotal]) AS TotalSales
FROM OINV I
WHERE left (I.[CardCode], 3) = '030' AND (I.[DocDate] >= '01/01/11' AND I.[DocDate] <= '12/31/11')
GROUP BY I.[CardCode]) T1
ON T0.[CardCode] = T1.[CardCode]
ORDER BY T0.[CardName]
When I try to prompt for the left 3 characters of the CardCode (or the dates), ie.
WHERE left (I.[CardCode], 3) = [%0] AND (I.[DocDate] >= '01/01/11' AND I.[DocDate] <= '12/31/11')
I get an error "Column 'OCRD.CardName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause".
It's like putting a user variable in the inner SELECT made it part of the outer SELECT which is exactly what I was trying to avoid by re-writing this query with the inner SELECT.
Can anyone explain what SQL Server is doing here and how to fix it?Thanks Gordon. That's how I originally wrote the query and it works fine. But I was disturbed that I had to GROUP BY every field in my SELECT statement when I really only wanted to group by CardCode. So I did some research and came up with this where the inner select still groups by only CardCode and still takes user input. I don't really understand why you need the commented SELECT statements in the SET lines, but you do. Something about using real table fields for variables.
DECLARE @startDate datetime
DECLARE @endDate datetime
DECLARE @rep varchar(10)
SET @rep /* SELECT T0.[CardCode] FROM ORDR T0 WHERE T0.[CardCode] */ = '[%0]'
SET @startDate /* SELECT T0.[DocDate] FROM OINV T0 WHERE T0.[DocDate] */ = '[%1]'
SET @endDate /* SELECT T0.[DocDate] FROM OINV T0 WHERE T0.[DocDate] */ = '[%2]'
SELECT T0.[CardName] AS Customer, T0.[CardCode] as 'Cust ID', T0.[Phone1] as Phone, T0.[CntctPrsn] as 'Contact Person', T0.[Address], T0.[City], T0.[State1] as State, T0.[ZipCode] as 'Zip Code', T0.[Country], T1.[TotalSales]
FROM OCRD T0
INNER JOIN
(SELECT I.[CardCode] AS CardCode, SUM(I.[DocTotal]) AS TotalSales
FROM OINV I
WHERE left (I.[CardCode], 3) = @rep AND (I.[DocDate] >= @startDate AND I.[DocDate] <= @endDate)
GROUP BY I.[CardCode]) T1
ON T0.[CardCode] = T1.[CardCode]
ORDER BY T0.[CardName]
FOR BROWSE -
How to utilize index in selection statement
hi
how to utilize index in selection statement and how is it reduces performance whether another alternative is there to reduce performance .
thanksHi Suresh,
For each SQL statement, the database optimizer determines the strategy for accessing data records. Access can be with database indexes (index access), or without database indexes (full table scan).The cost-based database optimizer determines the access strategy on the basis of:
*Conditions in the WHERE clause of the SQL statement
*Database indexes of the table(s) affected
*Selectivity of the table fields contained in the database indexes
*Size of the table(s) affected
*The table and index statistics supply information about the selectivity of table fields, the selectivity of combinations of table fields, and table size. Before a database access is performed, the database optimizer cannot calculate the exact cost of a database access. It uses the information described above to estimate the cost of the database access.The optimization calculation is the amount by which the data blocks to be read (logical read accesses) can be reduced. Data blocks show the level of detail in which data is written to the hard disk or read from the hard disk.
<b>Inroduction to Database Indexes</b>
When you create a database table in the ABAP Dictionary, you must specify the combination of fields that enable an entry within the table to be clearly identified. Position these fields at the top of the table field list, and define them as key fields.
After activating the table, an index is created (for Oracle, Informix, DB2) that consists of all key fields. This index is called a primary index. The primary index is unique by definition. As well as the primary index, you can define one or more secondary indexes for a table in the ABAP Dictionary, and create them on the database. Secondary indexes can be unique or non-unique. Index records and table records are organized in data blocks.
If you dispatch an SQL statement from an ABAP program to the database, the program searches for the data records requested either in the database table itself (full table scan) or by using an index (index unique scan or index range scan). If all fields requested are found in the index using an index scan, the table records do not need to be accessed.
A data block shows the level of detail in which data is written to the hard disk or read from the hard disk. Data blocks may contain multiple data records, but a single data record may be spread across several data blocks.
Data blocks can be index blocks or table blocks. The database organizes the index blocks in the form of a multi-level B* tree. There is a single index block at root level, which contains pointers to the index blocks at branch level. The branch blocks contain either some of the index fields and pointers to index blocks at leaf level, or all index fields and a pointer to the table records organized in table blocks. The index blocks at leaf level contain all index fields and pointers to the table records from the table blocks.
The pointer that identifies one or more table records has a specific name. It is called, for example, ROWID for Oracle databases. The ROWID consists of the number of the database file, the number of the table block, and the row number within the table block.
The index records are stored in the index tree and sorted according to index field. This enables accelerated access using the index. The table records in the table blocks are not sorted.
An index should not consist of too many fields. Having a few very selective fields increases the chance of reusability, and reduces the chance of the database optimizer selecting an unsuitable access path.
<b>Index Unique Scan</b>
If, for all fields in a unique index (primary index or unique secondary index), WHERE conditions are specified with '=' in the WHERE clause, the database optimizer selects the access strategy index unique scan.
For the index unique scan access strategy, the database usually needs to read a maximum of four data blocks (three index blocks and one table block) to access the table record.
<b><i>select * from VVBAK here vbeln = '00123' ......end select.</i></b>
In the SELECT statement shown above, the table VVBAK is accessed. The fields MANDT and VBELN form the primary key, and are specified with '=' in the WHERE clause. The database optimizer therefore selects the index unique scan access strategy, and only needs to read four data blocks to find the table record requested.
<b>Index Range Scan</b>
<b><i>select * from VVBAP here vbeln = '00123' ......end select.</i></b>
In the example above, not all fields in the primary index of the table VVBAP (key fields MANDT, VBELN, POSNR) are specified with '=' in the WHERE clause. The database optimizer checks a range of index records and deduces the table records from these index records. This access strategy is called an index range scan.
To execute the SQL statement, the DBMS first reads a root block (1) and a branch block (2). The branch block contains pointers to two leaf blocks (3 and 4). In order to find the index records that fulfill the criteria in the WHERE clause of the SQL statement, the DBMS searches through these leaf blocks sequentially. The index records found point to the table records within the table blocks (5 and 6).
If index records from different index blocks point to the same table block, this table block must be read more than once. In the example above, an index record from index block 3 and an index record from index block 4 point to table records in table block 5. This table block must therefore be read twice. In total, seven data blocks (four index blocks and three table blocks) are read.
The index search string is determined by the concatenation of the WHERE conditions for the fields contained in the index. To ensure that as few index blocks as possible are checked, the index search string should be specified starting from the left, without placeholders ('_' or %). Because the index is stored and sorted according to the index fields, a connected range of index records can be checked, and fewer index blocks need to be read.
All index blocks and table blocks read during an index range scan are stored in the data buffer at the top of a LRU (least recently used) list. This can lead to many other data blocks being forced out of the data buffer. Consequently, more physical read accesses become necessary when other SQL statements are executed
<b>DB Indexex :Concatenation</b>
In the concatenation access strategy, one index is reused. Therefore, various index search strings also exist. An index unique scan or an index range scan can be performed for the various index search strings. Duplicate entries in the results set are filtered out when the search results are concatenated.
<i><b>Select * from vvbap where vbeln in ('00123', '00133', '00134').
endselect.</b></i>
In the SQL statement above, a WHERE condition with an IN operation is specified over field VBELN. The fields MANDT and VBELN are shown on the left of the primary index. Various index search strings are created, and an index range scan is performed over the primary index for each index search string. Finally, the result is concatenated.
<b>Full Table Scan</b>
<b><i>select * from vvbap where matnr = '00015'.
endselect</i></b>
If the database optimizer selects the full table scan access strategy, the table is read sequentially. Index blocks do not need to be read.
For a full table scan, the read table blocks are added to the end of an LRU list. Therefore, no data blocks are forced out of the data buffer. As a result, in order to process a full table scan, comparatively little memory space is required within the data buffer.
The full table scan access strategy is very effective if a large part of a table (for example, 5% of all table records) needs to be read. In the example above, a full table scan is more efficient than access using the primary index.
<i><b>In Brief</b></i>
<i>Index unique scan:</i> The index selected is unique (primary index or unique secondary index) and fully specified. One or no table record is returned. This type of access is very effective, because a maximum of four data blocks needs to be read.
<i>Index range scan:</i> The index selected is unique or non-unique. For a non-unique index, this means that not all index fields are specified in the WHERE clause. A range of the index is read and checked. An index range scan may not be as effective as a full table scan. The table records returned can range from none to all.
<i>Full table scan:</i> The whole table is read sequentially. Each table block is read once. Since no index is used, no index blocks are read. The table records returned can range from none to all.
<i>Concatenation:</i> An index is used more than once. Various areas of the index are read and checked. To ensure that the application receives each table record only once, the search results are concatenated to eliminate duplicate entries. The table records returned can range from none to all.
Regards,
Balaji Reddy G
***Rewards if answers are helpful
Maybe you are looking for
-
I can't connect my I-Phone 6 to my car Bluetooth, any fixes yet?
I can't connect my I-Phone 6 to my car Bluetooth, any fixes yet? I just updated with the new update this morning. My I-Phone 5s had no problem connecting to car Bluetooth.
-
I want to upgrade my oracle 10g database to 11g. the utlui112.sql script shows following - WARNING: --> Database contains schemas with objects dependent on network packages. .... Refer to the Upgrade Guide for instructions to configure Network ACLs.
-
Best way to handle duplicate headings stemming from linked TOC book?
What's the best way to handle duplicate topic titles stemming from TOC books that contain links to a topic that you want to have appear in the body? The problem I've had for years now is that the TOC generates one heading, and the topic itself genera
-
One billing Doc, Two accounting documents
HI, all, I just found a billing document associated with 2 idential accounting document(different creation time, 10s minutes apart), our users has no idea how it happened, could any one help why and how to avoid this problem? our vension is ECC6 EHP4
-
HT5312 sorry! i can't reset Apple ID security question. Please help me
sorry! i can't reset Apple ID security question. Please help me