Database hints in select statement
Hi all,
i need to apply the databaser hints for my select statement where i am using for all entries clause .But the issue is that i am getting the dump when i am tring with the same .
If i use the hint without all entries clause ,it runs fine.
The query where i need to apply the hint is :
SELECT * FROM bsim "n443935
INTO CORRESPONDING FIELDS OF TABLE g_t_bsim_lean "n443935
FOR ALL ENTRIES IN t_bwkey WHERE bwkey = t_bwkey-bwkey
AND matnr IN matnr
AND bwtar IN bwtar
AND budat >= datum-low.
and the DB hint is:
Addition of database hints for DB6 as per OSS message 649621
%_HINTS
DB6 'USE_OPTLEVEL 7' " Insert CR-1000000473 Tr-D11K934315
DB6 '&SUBSTITUTE VALUES&'.
Let me know whats the issue for the dump in for all entries in clause.
Did you check if [https://service.sap.com/sap/support/notes/1520152|https://service.sap.com/sap/support/notes/1520152] applies?
Similar Messages
-
Hi,
Can anybody explain me why HITS keyword is used with SELECT statement, whats the use of if, How to find the HINTS for a particular table.
SELECT recn, recnroot, ippers
INTO CORRESPONDING FIELDS OF TABLE <ITAB1>
FROM CCIHT_IP
FOR ALL ENTRIES IN <ITAB2>
WHERE ippers = <ITAB2>-ippers
AND valfr LE sy-datum
AND valto GE sy-datum
AND iptype = 'INJ'
%_hints db2 '&max_blocking_factor 500&&max_in_blocking_factor 500&u2019.
-RajivHi,
Complex database statements or large numbers of secondary indexes that can be very
similar make it difficult for the database optimizer and the R/3 database interface to process
most efficiently. In some database systems, you can expressly influence decisions made by
database optimizer by what are known as hints.
Ex- %_HINTS ORACLE '&SUBSTITUTE VALUES&'.
Search with HINTS in SELECT STATEMENT you will get so many ans -
Error by using database procedure in select statement
hi ,
I have built a database procedure having one parameter with in out varchar type. that return value with some addition.
i am using it with some column in select statement only for display purpuses but i am facing error by doing that in select statement. that procedure is working well with bind variable but not with select statement.
plz help me how i can use a procedure in select statement. or can i do it or not.plz help me how i can use a procedure in select statement. or can i do it or not.A workaround could be to create a wrapper function for your procedure. One that only passes the input parameters and returns the output parameter.
The simply call this function in your select which internally calls the procedure. -
How to insert ORACLE HINT into select statement....
Hi team,
Can you please suggest me how to add an Oracle hint to point the Program to BSAD~1.
Index BSAD1 has all three fields MANDT, BUKRS, AUGDT which are there in the where clause. But as per the execution plan index BSAD0 is being used which is the primary one.
Also the stats for this table are are current.
Thanks in Advance.
Puneet.Hi punnet, look at this example:
SELECT MAX( kkop~augbd )
INTO it_gen_docs-augbd
FROM ( fkkvkp AS vkp INNER JOIN dfkkop AS kkop
ON vkpvkont = kkopvkont ) INNER JOIN dfkkko AS kkko
ON kkopaugbl = kkkoopbel
WHERE vkp~exvko = ti_cuentas-exvko
AND kkop~bukrs = p_bukrs
AND kkop~blart IN r_blart
AND kkop~augst = '9'
AND kkko~blart IN r_blartd
%_HINTS ORACLE 'INDEX("DFKKOP" "DFKKOP~Z07")'.
DFKKOP is the table name and DFKKOP~Z07 is the index.
I hope this helps you. -
Number of records are different in database table and select statement
Hi All,
i need to fetch data from table BSID for the customer 0010000145
if i am writing the code like -
SELECT bukrs kunnr umskz shkzg dmbtr zfbdt zbd1t kkber
FROM bsid
INTO TABLE it_bsid
FOR ALL ENTRIES IN it_kna1
WHERE kunnr = it_kna1-kunnr
and bukrs = pa_bukrs.
no. of records are 130 in the internal table it_bsid
and actual records are 200
but when i am hardcoding the customer no.
i am getting the exact records
SELECT bukrs kunnr umskz shkzg dmbtr zfbdt zbd1t kkber
FROM bsid
INTO TABLE it_bsid
FOR ALL ENTRIES IN it_kna1
WHERE bukrs = pa_bukrs
AND kunnr = '0010000145'.
records in internal table = records in the database = 200.
how it is possible.
why the first code is not giving the correct no. of records.
please reply asap.
thanks in advance,
madhuMadhu,
You need to use the conversion routine...before u pass KUNNUR.
CONVERSION_EXIT_ALPHA_RANGE_I
CONVERSION_EXIT_ALPHA_RANGE_O
Hope this helps..
Chandra. -
* table name in the select statements
Hi,
I have come across a select Statement as below.
Select * into *nast from nast where <conditions>.. End select.
what does this *nast represents and when is it used. why do we need to call a Table with *<Table Name>
Kind Regards,
Ushahi,
select statement will always points to a database table so we have to give database table name and it gets data from that table. for storing that data we have to use internal tables must have same structure of database table.
so select statement has the following form as........
select * from [dbtable] into table [internal table]
endselect.
in sap select will act as a loop so that we hav to use end sleect. select has different varities in sap. for some types no need of end select.
for ex:
select single *
select * ..................... into table [internal table name].....
if helpful reward some points.
with regards,
suresh. -
Problems with Hints in abap code to use an index in a Select statement
Hi,
I want to use an especific index in a select statement but I can´t get it. I use de next statement:
SELECT ltaklgnum ltaktanum ltakvbeln ltaptapos ltapnltyp ltappvqui
FROM ltak AS ltak INNER JOIN ltap AS ltap
ON ltaktanum = ltaptanum
AND ltaklgnum = ltaplgnum
INTO TABLE l_t_tanum_silo
WHERE ltap~lgnum EQ ip_lgnum
AND ltap~pquit EQ ' '
AND ltak~lgnum EQ ip_lgnum
AND ltak~kquit EQ ' '
AND ltak~queue EQ ip_queue
%_HINTS DB2 ''.
We have DB2 for Linux Unix and Windows 9.5 as DB system.
How can I fix this?
Thanks a lot.
RegardsThe DB2 for Linux Unix and Windows is coded DB6 for SAP and not DB2
Look at the following OSS notes
- [Note 129385 - Database hints in Open SQL|https://service.sap.com/sap/support/notes/129385]
- [Note 150037 - Database hints in Open SQL for DB6 (DB2 for LUW)|https://service.sap.com/sap/support/notes/150037]
- [Note 1270314 - DB6: DB2 9.5 Perf. degrad. for queries with INLIST clause|https://service.sap.com/sap/support/notes/1270314]
- [Note 868888 - DB6: Optimization Guidelines|https://service.sap.com/sap/support/notes/868888]
You should use a
SELECT ltak~lgnum ltak~tanum ltak~vbeln ltap~tapos ltap~nltyp ltap~pvqui
FROM ltak AS ltak INNER JOIN ltap AS ltap
ON ltak~tanum = ltap~tanum
AND ltak~lgnum = ltap~lgnum
INTO TABLE l_t_tanum_silo
WHERE ltap~lgnum EQ ip_lgnum
AND ltap~pquit EQ ' '
AND ltak~lgnum EQ ip_lgnum
AND ltak~kquit EQ ' '
AND ltak~queue EQ ip_queue
%_HINTS DB6 '<IXSCAN TABLE=''LTAP'' INDEX=''"LTAP~M"'' />'.
In note 868888 there is a sample for a join.
SELECT A~TABSPACE
FROM TADB6 AS A
JOIN IADB6 AS B ON A~TABART = B~TABART
%_HINTS DB6 '<NLJOIN><IXSCAN TABLE=''IADB6'' />'
DB6 '<IXSCAN TABLE=''TADB6'' /></NLJOIN>'.
Regards -
Regarding Logical database and select statement..
Hi
Experts.
i would like to know the diff b/w logical data base & select statement while using report.
wt is the use of logical databases in R/3. is there any advantage used in the reports.
Thanks & Regards..
Spandana.Dear Spandana,
Go through the below description of LDB. I hope you wil get a fair amount of idea.
SAP comes loaded with all the extras. Among the extras that are most helpful to IT managers are all the access routines needed to pull any business object that managers can think of out of SAP databases. However, SAP has not thought of everything where your particular applications are concerned. SAP organizes its standard database tables to service business units based on conventional business applications. Itu2019s likely your business requires something new, perhaps even something exotic. In that case, you will need to create a new database, using information from different places. Basically, you need a logical database. You need to create a virtual business data object repository consisting of a new kind of record or table that suits your purposes. In addition, the repository should be composed of information that is actually stored in a number of different locations, none of them necessarily logically associated with one another. Letu2019s take a closer look at creating logical databases.
A case for a logical database
Suppose my company manufactures widgets of the most obscure variety, and they are components of other widgets. I sell my widgets as raw material for the more sophisticated widgets built by others, but in some cases I actually partner with other manufacturers in creating yet another class of widget. Now, in my world, I consequently have customers who are also partners. I sell to them and I partner with them in manufacturing and distribution. Also, I need an application that uses both of these dual-use relationships.
Essentially, I have a customer database and a partner database. Neither contains records that are structured to contain the identifying particulars of the other. Thus, I need a hybrid database that gives me tables detailing these hybrid relationships. What can I do? I can go the long way around and write a new database, pulling information from both and creating new objects with a customized program that I write by hand. However, this process is cumbersome and contains maintenance issues. On the other hand, I can use SAPu2019s logical database facility, create my logical database in a couple of minutes, and have no maintenance issues at all.
Logical database structures
There are three defining entities in an SAP logical database. You must be clear on all three in order to create and use one.
u2022 Table structure: Your logical database includes data from specified tables in SAP. There is a hierarchy among these tables defined by their foreign keys (all known to SAP), and you are going to define a customized relationship between select tables. This structure is unique and must be defined and saved.
u2022 Data selection: You may not want or need every item in the referenced tables that contributes to your customized database. There is a selection screen that permits you to pick and choose.
u2022 Database access programming: Once youu2019ve defined your logical database, SAP will generate the access subroutines needed to pull the data in the way you want it pulled.
Creating your own logical database
ABAP/4 (Advanced Business Application Programming language, version 4) is the language created by SAP for implementation and customization of its R/3 system. ABAP/4 comes loaded with many predefined logical databases that can construct and table just about any conventional business objects you might need in any canned SAP application. However, you can also create your own logical databases to construct any custom objects you care to define, as your application requires in ABAP/4. Hereu2019s a step-by-step guide:
1. Call up transaction SLDB (or transaction SE36). The path you want is Tools | ABAP Workbench | Development | Programming Environment | Logical Databases. This screen is called Logical Database Builder.
2. Enter an appropriate name in the logical database name field. You have three options on this screen: Create, Display, and Change. Choose Create.
3. Youu2019ll be prompted for a short text description of your new logical database. Enter one. Youu2019ll then be prompted to specify a development class.
4. Now comes the fun part! You must specify a root node, or a parent table, as the basis of your logical database structure. You can now place subsequent tables under the root table as needed to assemble the data object you want. You can access this tree from this point forward, to add additional tables, by selecting that root node and following the path Edit | Node | Create. Once youu2019ve saved the structure you define in this step, the system will generate the programming necessary to access your logical database. The best part is you donu2019t have to write a single line of code.
Watch out!
The use of very large tables will degrade the performance of a logical database, so be aware of that trade-off. Remember that some tables in SAP are very complex, so they will be problematic in any user-defined logical database.
Declaring a logical database
Hereu2019s another surprising feature of logical databases: You do not assign them in your ABAP/4 Code. Instead, the system requires that you specify logical databases as attributes. So when you are creating a report, have your logical database identifier (the name you gave it) on hand when you are defining its attributes on the Program Attributes screen. The Attributes section of the screen (the lower half) will include a Logical database field, where you can declare your logical database.
Logical databases for increasing efficiency
Why else would you want to create a logical database? Consider that the logical databases already available to you begin with a root node and proceed downward from there. If the data object you wish to construct consists of items that are all below the root node, you can use an existing logical database program to extract the data, then trim away what you donu2019t want using SELECT statementsu2014or you can increase the speed of the logical database program considerably by redefining the logical database for your object and starting with a table down in the chain. Either way, youu2019ll eliminate a great deal of overhead.
Regards
Arindam -
Using Variables in a select statement through a Database Adapter
I was wondering how I reference a variable in a select statement through a Database Adapter.
Ex.
1. I have a global variable that stores an employee number
2. I want to select an SSN # from a table based on an employee #
variable.
select ssn from emp where ssn = :input_variable - ????
- how do i reference the variable - I am getting a 'missing IN or OUT parameter error?
Any advice is much appreciated.
~ThanksI'm just wondering if anyone knows a work around so that I might be able to store a Table's FIELD name in a variable or an array[] so that I can do a query based on the decision of a loop without having to code 10 IF/ELSE statements.For instance, although the above code will not work, this code, although quite lengthy, does:
If DataGrid1.SelStartCol = 0 Then
Adodc1.RecordSource = "Select * from tblReservation order by RES__PUR_DT"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 1 Then
Adodc1.RecordSource = "Select * from tblReservation order by VENDOR"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 2 Then
Adodc1.RecordSource = "Select * from tblReservation order by VEN_LOC"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 3 Then
Adodc1.RecordSource = "Select * from tblReservation order by RES_TYPE"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 4 Then
Adodc1.RecordSource = "Select * from tblReservation order by RES_FROM_DT"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 5 Then
Adodc1.RecordSource = "Select * from tblReservation order by RES_TO_DT"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 6 Then
Adodc1.RecordSource = "Select * from tblReservation order by MISC_ADJ"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 7 Then
Adodc1.RecordSource = "Select * from tblReservation order by STATE_TAX"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 8 Then
Adodc1.RecordSource = "Select * from tblReservation order by LOC_CHARGE"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 9 Then
Adodc1.RecordSource = "Select * from tblReservation order by RES_ID"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 10 Then
Adodc1.RecordSource = "Select * from tblReservation order by RES_OP"
Adodc1.Refresh
End If
Do you see where i'm going with this?
I simple want to use a variable in the "select * from <Table> Order by <Field>" -
Hi,
Is it possible to use column aliases in the select statement for a database adapter to return an xml element name which is different to the column in the queried table?
I have tried using
SELECT EMPLOYEE_ID, FIRST_NAME AS MYNAME, LAST_NAME, SALARY, DEPARTMENT_ID, PHONE_NUMBER, EMAIL, HIRE_DATE FROM HR.EMPLOYEES WHERE (DEPARTMENT_ID = #DEPT_ID)
but I get the following XML fragment returned
<Employees>
<employeeId>100</employeeId>
<firstName xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<lastName>King</lastName>
<salary>24000</salary>
Any pointers appreciated.
Joel.That is really interesting.
When I use the "custom sql" option in the DB adapter wizard, it used the aliases just fine in the return schema.
Marc -
Hint in Update or Select Statement in an inline query ??
Hi ,
I had an update statement that will get the data from the inline select statement,now where can i can keep the hint ,either in update statement or in Select statement...
Please let me know if my sample script is wrong or any better way to approach...Please assume that Salary table had millions of employee's salary records.
update emp
set salary = salary + (select /*+ full(a) parallel(a,4) */ salary from Salary
where experience > 5 and empno = 55 )
where empno = 85Thanks
RedeYou would put the hint in the select statement as you have it, but it won't work until you alias your table name to "a" since that is how you are referencing it in the hint:
update emp
set salary = salary + (select /*+ full(a) parallel(a,4) */ salary from Salary a
where experience > 5 and empno = 55 )
where empno = 85
NOTE I added the "a" right after the Salary table name AND you can only do parallel updates on partitioned table, but the select will run in parallel to at least get the data for you quickly.
To answer your other question about syntax, it is incorrect and there are a lot of ways to write it but a straight forward way would be to use the merge statement
merge into emp e
using (select /*+ full(s) parallel(s,4) */ s.salary from salary s where s.experience > 5) s
on (e.empno = s.empno)
when matched then update
set salary = s.salary; -
Using Hint in Update or Select Statement...
Hi ,
I had an update statement that will get the data from the inline select statement,now where can i can keep the hint ,either in update statement or in Select statement...
Please let me know if my sample script is wrong or any better way to approach...Please assume that Salary table had millions of employee's salary records.
update emp
set salary = salary + (select /*+ full(a) parallel(a,4) */ salary from Salary
where experience > 5 and empno = 55 )
where empno = 85Thanks
RedeThe better approach would be to determine why you need a hint in the first place. If you're using a hint, that implies that the optimizer is choosing the incorrect plan when left to its own devices. That, in turn, implies that the statistics on your objects, the statistics on your system, your optimizer parameters, your session's optimizer settings or some other variable is incorrect. You're generally better off fixing the root problem than hinting every query.
In this specific case, the parallel hint is invalid because there is no table aliased A. The full hint is invalid for similar reasons. Plus, with the query you provided, if A was intended to be the SALARY table, it seems exceptionally unlikely that you really want to do a full scan on the salary table to look for what had better be a single row (otherwise your query would throw a "too many rows returned" exception).
Justin -
How to compile the hint to force selection statement to use index
Hello expert,
will you please tell me how to compile the hint to force selection statement to use index?
Many Thanks,Not sure what you mean by compile, but hint is enclosed in /*+ hint */. Index hint is INDEX(table_name,index_name). For example:
SQL> explain plan for
2 select * from emp
3 /
Explained.
SQL> @?\rdbms\admin\utlxpls
PLAN_TABLE_OUTPUT
Plan hash value: 3956160932
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 14 | 546 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| EMP | 14 | 546 | 3 (0)| 00:00:01 |
8 rows selected.
SQL> explain plan for
2 select /*+ index(emp,pk_emp) */ *
3 from emp
4 /
Explained.
SQL> @?\rdbms\admin\utlxpls
PLAN_TABLE_OUTPUT
Plan hash value: 4170700152
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 14 | 546 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 14 | 546 | 2 (0)| 00:00:01 |
| 2 | INDEX FULL SCAN | PK_EMP | 14 | | 1 (0)| 00:00:01 |
9 rows selected.
SQL> Hint in the above example is forcing optimizer to use index which resul;ts in a bad execution plan. Most of the time optimizer does not need hints and chooses an optimal plan. In most cases sub-optimal plan is result of stale or incomplete statistics.
SY. -
Select statement in Logical Database
hi,
i need to select particular fields(not select * )
from bsis table in my Logical database. how can i write code for this?
for eg,
In Ordinary report , we can write (select belnnr into
itab_bsis-belnr) like this.
but in Logical Database how can i write the code ?
Neptune.MHi,
I am new to ABAP.Currently I'm practicing logical database. I am facing a similar problem like what Neptune is having.
I have created a logical database 'Z03_SAMPLEDB5' using tables KNA1, KNB1,KNB4,KNB5 and KNKK.
I have defined the Database program and selections.Now I would like to use this logical database in one of my programs.
Please find the code of the program in which I'm using this logical datbase :
REPORT Z03_SAMPLELDB5.
tables : kna1.
data: begin of t occurs 0,
kunnr like kna1-kunnr,
land1 like kna1-land1,
bukrs like knb1-bukrs,
end of t.
start-of-selection.
get kna1.
clear t.
move-corresponding kna1 to t.
append t.
end-of-selection.
write: /20 'Customer No.', 40 'Country code', 55 'Company Code'.
ULINE.
loop at t.
write: /20 t-kunnr, 40 t-land1, 55 t-bukrs.
endloop.
In the output screen I could get data for only 'Customer No' and 'Country code' .'Company Code' is blank.
Please let me know what I need to do to get data for 'Company Code' as well.
Thanks,
Prasuna -
I have written a select statement as part of cursor in a
Database Trigger, the following statement works fine in Oracle
8i ver 8.1.5.0 but the same statement returns error PLS-00103
(Parser related error) in Oracle 8i version 8.1.7.0!!!!!!
The error shown is
PLS-00103Encountered the symbol")" when expecting one of the
following:
from
The Sql statement in a Database Trigger is as follows
select opn_stk,iss_qty,rec_qty,ROWID
from mnth_bal
where to_date(lpad(to_char(month),2,'0')||to_char
(year),'mmyyyy') >= SYSDATE AND
REV_NO = :NEW.REV_NO AND
ITEM_STOCK_ITEM_CD = :NEW.ITEM_CD and
unit_cd = :NEW.unit_cd and
store_cd = :new.store_cd
order by to_date(lpad(to_char(month),2,'0')
||to_char(year),'mmyyyy') ;
Can any one please tell me whats the problem ? In 8.1.5.0 the
same statement in the trigger runs absolutely fine &
compiles.Because of this problem the trigger is not compiling in
8.1.7.0
Would be grateful for any solutions givenRelating line numbers in compile errors to source code.
Oracle does not count blank lines in line numbers. Commenting
with "--" blank lines or deleting blank lines will make the line
counter more accurate.
Oracle counts comments delimited with /*...*/ as one line, no
matter how many lines are in the source code. Using only "--"
will make the line counter more accurate.
Oracle does not count lines before the PL/SQL block DECLARE when
compiling triggers. (CREATE ... TRIGGER....FOR EACH...WHEN(...))
parts of the syntax are not counted. The line in the source
code with the DECLARE of the trigger's PL/SQL block will be line
1.
Hint: Avoid uncertainty. Use "SHO ERR TRIGGER <trigger_name>"
when looking at compile problems.
Good Luck....
Maybe you are looking for
-
Everything correct, but the images are not there
Ok, with the podcast I do, All Things Gaming throught www.upstatefighting.com, I went throught and added the album art for the cast in the feed that we use. I checked in the store, and the image shows up. But when I resubscribe to the podcast, the
-
Error in defining a property & property-alias for a correlation for a BPEL
hallo, would anybdy be kind enough to tell me where i've done somthing wrong? im using netbeans 6.1 for SOA application development. there are two receive activities in a BPEL, recieve1 and recieve2. on the latter i have defined a correlation whose i
-
With holding tax should deduct on down payment
hi gurus, Pls help me out regarding this issue, while iam paying down payment to vendors, i will cut the TDS and i will pay it to him, while raising an invoice the TDS should automatically adjust the invoice amount. pls send me the configura
-
Ora- 12535 (Oracle 9i, Solaris 9) Client WinXP
Hi Guys, I keep on getting this error when trying to connect to the database using Enterprise Manager. Pls assist. Thank you.
-
I should probably know this. Or maybe I'm doing something wrong. I try to navigate through an image in Camera Raw to check for dust spots by using the PageUp and PageDown keys. Also use the Home key to go to the upper left corner to start the process