Open an native sql
1) what is open sql an wat is native sql an wt is the diference between these to.....
Hi Satish,
The difference is:
OPEN SQL - Open SQL consists of a set of ABAP statements that perform operations on the central database in the R/3 System. The results of the operations and any error messages are independent of the database system in use. Open SQL thus provides a uniform syntax and semantics for all of the database systems supported by SAP. ABAP programs that only use Open SQL statements will work in any R/3 System, regardless of the database system in use. Open SQL statements can only work with database tables that have been created in the ABAP Dictionary.
NATIVE SQL - Open SQL allows you to access database tables declared in the ABAP Dictionary regardless of the database platform that you R/3 System is using. Native SQL allows you to use database-specific SQL statements in an ABAP program. This means that you can use database tables that are not administered by the ABAP Dictionary, and therefore integrate data that is not part of the R/3 System.
Plz Reward if useful,
Mahi.
Similar Messages
-
Native SQL from ABAP - ORA 02396 max idle time exceeded
Hello,
I am trying to read a table outside of the R/3 environment using native SQL statements. I'm getting the data just fine. But every other time (depending on elapsed time), I get the ORA-02396 exceeded maximum idle time, connect again. Here's the SQL code I'm using and I'm obviously not getting disconnected but I'm not sure why. Any help?
Open a native SQL connection.
EXEC SQL.
connect to 'ONECD'
ENDEXEC.
Retrieve information from the BVER tables.
EXEC SQL PERFORMING read_dental.
select emp_ssn_num, emp_fname, emp_lname,
to_char(start_date, 'YYYYMMDD') as start_date,
rec_type,
to_char(eff_date, 'YYYYMMDD') as eff_date,
vendor_plan_id
into :dental
from opr$8oc.BVER_CURR_DENTAL_MASTER
ENDEXEC.
EXEC SQL PERFORMING read_medical.
select emp_ssn_num, emp_fname, emp_lname, rec_type,
to_char(start_date, 'YYYYMMDD') as start_date,
to_char(eff_date, 'YYYYMMDD') as eff_date,
network_code, pcp_number, patient_flag,
vendor_plan_id,
to_char(network_eff_date, 'YYYYMMDD') as
network_eff_date,
to_char(pha_eff_date, 'YYYYMMDD') as
pha_eff_date
into :medical
from opr$8oc.BVER_CURR_MEDICAL_MASTER
ENDEXEC.
Disconnect from the native SQL connection.
EXEC SQL.
DISCONNECT 'ONECD'
ENDEXEC.
The system log has messages like 'Work process is in reconnect status' and 'Work process has left reconnect status' after the ORA-02396 message. And I specifically do a disconnect at the end and a connect at the beginning, but it looks like it is trying to do a reconnect?
Thanks,
DianeHi Daine,
Oracle Parameter IDLE_TIME set by the administrator.
1. Since you are using Secondary database
connection, the connection must
have been made with the help of BASIS Team.
2. This secondary database ORACLE
has some settings/parameters
which have been set to say 10 minutes, 60 minutes etc.
, so what happens,
if there is NO ACTIVITY / NO SQL / NO INTERACTION
with the database ,
the connection is IDLE
and hence ORACLE then disconnects by itself.
3. Contact your basis team / oracle administarotr
team to INCREASE this setting.
(they do it for some security purpose, firewall etc)
I hope it helps.
Regards,
Amit M.
Message was edited by: Amit Mittal -
Performance: Open SQL vs. Native SQL (Oracle)
Hi everybody,
I have an interesting issue here. For a DB selection I use an Open SQL query from a table view into an internal table. It works fine, but the performance is not very well. The SELECT uses LIKE and wildcards (%) to search for customer master data (names and address fields).
Because of the bad performance I made some tests in transaction DB02 with native SQL, but exactly the same SELECT structure. It looks like this:
SELECT *
FROM zzrm_cust_s_hlp
WHERE client = 100
AND mc_name1 LIKE '<name>%'
AND mc_name2 LIKE '<name>%'
AND valid_from <= <timestamp>
AND valid_to >= <timestamp>
Ok, now I tried exactly the same SELECT statement with the same data to search for (<name> and <timestamp) with Open SQL and Native SQL. The Difference is quite suprising, the Native SQL query is about 5-10 times faster (arount 1 sec) than the Open SQL query (around 5-10 sec). Even with the LIKE keywords and the wildcards.
Any ideas what could be the problem with the Open SQL query?
And: what can I do to achive the same performance as with the Native SQL query?
Kind regards and thanks in advance for any help,
MatthiasOk, here is the the SQL explaination from the DB02 query:
SELECT STATEMENT ( Estimated Costs = 194 , Estimated #Rows = 1 )
9 COUNT STOPKEY
Filter Predicates
8 NESTED LOOPS
( Estim. Costs = 193 , Estim. #Rows = 1 )
Estim. CPU-Costs = 1,665,938 Estim. IO-Costs = 193
5 NESTED LOOPS
( Estim. Costs = 144 , Estim. #Rows = 98 )
Estim. CPU-Costs = 1,162,148 Estim. IO-Costs = 144
2 TABLE ACCESS BY INDEX ROWID BUT000
( Estim. Costs = 51 , Estim. #Rows = 93 )
Estim. CPU-Costs = 468,764 Estim. IO-Costs = 51
Filter Predicates
1 INDEX SKIP SCAN BUT000~NAM
( Estim. Costs = 6 , Estim. #Rows = 93 )
Search Columns: 1
Estim. CPU-Costs = 59,542 Estim. IO-Costs = 6
Access Predicates Filter Predicates
4 TABLE ACCESS BY INDEX ROWID BUT020
( Estim. Costs = 1 , Estim. #Rows = 1 )
Estim. CPU-Costs = 7,456 Estim. IO-Costs = 1
Filter Predicates
3 INDEX RANGE SCAN BUT020~0
( Estim. Costs = 1 , Estim. #Rows = 1 )
Search Columns: 2
Estim. CPU-Costs = 3,661 Estim. IO-Costs = 1
Access Predicates
7 TABLE ACCESS BY INDEX ROWID ADRC
( Estim. Costs = 1 , Estim. #Rows = 1 )
Estim. CPU-Costs = 5,141 Estim. IO-Costs = 1
Filter Predicates
6 INDEX UNIQUE SCAN ADRC~0
Search Columns: 4
Estim. CPU-Costs = 525 Estim. IO-Costs = 0
Access Predicates
And this is the one from the Open SQL query in ABAP:
SELECT STATEMENT ( Estimated Costs = 15,711 , Estimated #Rows = 29 )
7 NESTED LOOPS
( Estim. Costs = 15,710 , Estim. #Rows = 29 )
Estim. CPU-Costs = 3,021,708,117 Estim. IO-Costs = 15,482
4 NESTED LOOPS
( Estim. Costs = 15,411 , Estim. #Rows = 598 )
Estim. CPU-Costs = 3,018,711,707 Estim. IO-Costs = 15,183
1 TABLE ACCESS FULL BUT020
( Estim. Costs = 9,431 , Estim. #Rows = 11,951 )
Estim. CPU-Costs = 2,959,067,612 Estim. IO-Costs = 9,207
Filter Predicates
3 TABLE ACCESS BY INDEX ROWID ADRC
( Estim. Costs = 1 , Estim. #Rows = 1 )
Estim. CPU-Costs = 4,991 Estim. IO-Costs = 1
Filter Predicates
2 INDEX UNIQUE SCAN ADRC~0
Search Columns: 4
Estim. CPU-Costs = 525 Estim. IO-Costs = 0
Access Predicates
6 TABLE ACCESS BY INDEX ROWID BUT000
( Estim. Costs = 1 , Estim. #Rows = 1 )
Estim. CPU-Costs = 5,011 Estim. IO-Costs = 1
Filter Predicates
5 INDEX UNIQUE SCAN BUT000~0
Search Columns: 2
Estim. CPU-Costs = 525 Estim. IO-Costs = 0
Access Predicates
Of course I can see the difference.
But since the statements are identical, I don't understand why this difference exists
Thanks for your help!
Kind regards, Matthias -
CREATE VIEW in ABAP (Open SQL or Native SQL)
Hi all you experts!
I want to create a VIEW in ABAP. I have created Table Views using ABAP Dictionary (in transaction SE11), I don't have any problem with them.
But, what I need is to create a dynamic view, I mean, a view that can be created/replaced (or modified) at runtime. Is this possible with SAP Open SQL, I don't think so... that is why I tried to created using native SQL but it is not working.
Here is the code:
EXEC SQL.
CREATE VIEW [ZMXRFIV_GLPCA]
AS SELECT
T1.GL_SIRID,
T1.POPER,
T1.RBUKRS,
T1.RPRCTR,
T1.RACCT,
T1.HSL
FROM
GLPCA T1
INNER JOIN
SKA1 T2
ON
T1.RACCT = T2.SAKNR
WHERE
T1.RVERS = '000'
AND T1.RYEAR = '2008'
AND T1.KOKRS = 'PI01'
AND T2.KTOPL = 'PI00'
AND T2.XBILK <> 'X'.
ENDEXEC.
I have tried using quotes (") for the view name, parenthesis and even using only the name but this make no difference.
Do any of you experts have any idea?
PS: After creating the view I need to do a SELECT INTO TABLE to that view and finally delete this view and continue working with the data on the internal table.Hi ,
oh yes it is an object (well, how the database should handle it in any context if it wasn't)
i.e. for ORACLE you would have several thousands of them:
select count(*) from dba_objects where object_type ='VIEW'
If you avoid some kind of foreground processing (i.e. pull the data over the network) and handle the processing inside the database it can improve somehow performance a little (i.e. using the retieved rows of the view to stuff into a database table directly). But his may not always possible...
bye
yk -
Converting Native SQL to OPEN SQL
Any inputs on how the following Native SQL can be converted to OPEN SQL.
Especially self join of same table .
EXEC SQL PERFORMING APPEND_ITAB.
SELECT /+ ORDERED/
A.VTYPE, A.LIFNR, G.MTNO,
A.ASYTR, A.DATAB, A.DATBI,
D.MAKTX, F.NAME1, G.COMP,
C.PREF, C.COMP, E.MAKTX,
C.QNTY, C.UNIT, B.MEINS,
A.EKGRP, A.SEQNO, C.STGB,
C.DATUV, C.DATUB
INTO :WA_MODULE-VTYPE, :WA_MODULE-LIFNR, :WA_MODULE-MATNR,
:WA_MODULE-ASYTR, :WA_MODULE-DATAB, :WA_MODULE-DATBI,
:WA_MODULE-MAKTX, :WA_MODULE-NAME1, :WA_SUB-UPGVC,
:WA_SUB-PREF, :WA_SUB-COMP, :WA_SUB-MAKTX,
:WA_SUB-QNTY, :WA_SUB-UNIT, :WA_SUB-MEINS,
:WA_MODULE-EKGRP, :WA_MODULE-SEQNO, :WA_SUB-STGB,
:WA_SUB-DATAB, :WA_SUB-DATBI
FROM ZTMM_ASSY_COST1 A, ZTBM_ABXDULDT G,
ZTBM_ABXDULDT C, MARA B, MAKT D, MAKT E, LFA1 F
WHERE A.MANDT = :SY-MANDT
AND A.VTYPE BETWEEN :WA_VTYPE_F AND :WA_VTYPE_T
AND A.MCODE BETWEEN :WA_MCODE_F AND :WA_MCODE_T
AND A.LIFNR BETWEEN :WA_LIFNR_F AND :WA_LIFNR_T
AND A.EKGRP BETWEEN :WA_EKGRP_F AND :WA_EKGRP_T
AND A.DATAB <= :P_DATUM
AND A.DATBI >= :P_DATUM
AND F.MANDT = A.MANDT
AND F.LIFNR = A.LIFNR
AND G.MANDT = A.MANDT
AND G.MTNO LIKE CONCAT(CONCAT(A.VTYPE,A.MCODE),'%')
AND G.MTNO BETWEEN :WA_MATNR_F AND :WA_MATNR_T
AND G.PLNT = :C_WERKS
AND G.USAG = '2'
AND G.ALTN in ('1','01')
AND G.DATUV <= :P_DATUM
AND G.DATUB >= :P_DATUM
AND B.MANDT(+) = G.MANDT
AND B.MATNR(+) = G.MTNO
AND B.LVORM(+) = ' '
AND C.MANDT(+) = G.MANDT
AND C.MTNO(+) = G.COMP
AND C.PLNT(+) = G.PLNT
AND C.USAG(+) = '2'
AND C.ALTN(+) = '01'
AND C.DATUV(+) <= :P_DATUM
AND C.DATUB(+) >= :P_DATUM
AND D.MANDT(+) = B.MANDT
AND D.MATNR(+) = B.MATNR
AND D.SPRAS(+) = :SY-LANGU
AND E.MANDT(+) = C.MANDT
AND E.MATNR(+) = C.COMP
AND E.SPRAS(+) = :SY-LANGU
ORDER BY A.VTYPE, A.LIFNR, G.MTNO
ENDEXEC.Then why don't you post the code you have. It would be a lot easier for us to improve that rather than try do redo what you have already done.
Rob -
Hai all !
Can anybody give me the exact Difference between Open SQL & Native SQL.
Thanks in Advance,
Swapna.Hii!
Open SQL is basically SAP specific Structured Query language.Open SQL consists of a set of ABAP statements that perform operations on the central database in the R/3 System. The results of the operations and any error messages are independent of the database system in use. Open SQL thus provides a uniform syntax and semantics for all of the database systems supported by SAP. ABAP programs that only use Open SQL statements will work in any R/3 System, regardless of the database system in use. Open SQL statements can only work with database tables that have been created in the ABAP Dictionary.
Native SQL is basically a database specific language.
Open SQL allows you to access database tables declared in the ABAP Dictionary regardless of the database platform that you R/3 System is using. Native SQL allows you to use database-specific SQL statements in an ABAP program. This means that you can use database tables that are not administered by the ABAP Dictionary, and therefore integrate data that is not part of the R/3 System.
As a rule, an ABAP program containing database-specific SQL statements will not run under different database systems. If your program will be used on more than one database platform, only use Open SQL statements.
To use a Native SQL statement, you must precede it with the EXEC SQL statement, and follow it with the ENDEXEC statement as follows:
EXEC SQL [PERFORMING <form>].
<Native SQL statement>
ENDEXEC. -
Native SQL "Table does not exist in database"
Hi Developers,
I'm doing a database connection to an Oracle db and trying to read data using native SQL - I keep getting the runtime error "table does not exist in database" on the statement Fetch Next Cursor. The following is the code snippet (I've commented out the Exec SQL and Fetch Next to make sure I have a connection and I do). HR is a schema in the database and T_Donation is a table in HR.
Data: w1(3),
c1 type cursor.
start-of-selection.
if con_name is initial.
write: 'No connection specified'. "#EC NOTEXT
return.
endif.
try to open the connection and catch the errors (if any)
try.
con_ref = cl_sql_connection=>get_connection( con_name ).
catch cx_sql_exception into sqlerr_ref.
error occured
write:
'Could not open connection', con_name, '.'. "#EC NOTEXT
if sqlerr_ref->unknown_connection = 'X'.
write:
/ con_name, 'is not defined in DBCON'. "#EC NOTEXT
elseif sqlerr_ref->db_error = 'X'.
write:
/ 'sql error', sqlerr_ref->sql_code, 'occured:',
/ sqlerr_ref->sql_message. "#EC NOTEXT
else.
perform get_trace_file using dev_file.
write:
/ 'DBI error', sqlerr_ref->internal_error, 'occured.',
/ 'See trace file for further info:',
icon_read_file as icon hotspot, dev_file. "#EC NOTEXT
endif.
return.
endtry.
connection successfully opened
write:
/ 'Connection', con_name, 'successfully opened.'. "#EC NOTEXT
*- Get the data from MS-SQL Server
EXEC SQL.
open C1 for
SELECT HR.T_DONATION.DN_DONATIONYEAR
FROM HR.T_DONATION
ENDEXEC.
do.
EXEC SQL.
FETCH NEXT C1 into :w1
ENDEXEC.
if sy-subrc = 0.
perform loop_output.
else.
exit.
endif.
enddo.
EXEC SQL.
CLOSE C1
ENDEXEC.
close connection again
con_ref->close( ).
write:
/ 'Connection', con_name, 'closed'. "#EC NOTEXT
end-of-selection.
*& Form LOOP_OUTPUT
Output
form loop_output .
write: /5 w1.
endform. " LOOP_OUTPUT
Thanks for your help.
Jim
Message was edited by:
James BarnesWell my advice is to check the question in the sql tutorial, it will be quicker then getting an answere.
-
Native sql not populating correct data in ECC6.0 unicode system
Hi,
I am working in an upgrade upgrade project from 4.6c to ECC6.0.
4.6c is non-unicode system. ECC6 is Unicode system.
I am facing Native SQL problem in custom developed programe in ECC6.That means programe reading the data from oracle datbase and stored into internal table.
But data not stored as normal character format that means its stored as different character format.
I am suspecting this is due to unicode system. IF that is issue then please provide
what syntax I have to use for Native SQL statment in unicode system.
I have provided the code which we are using in programe.
data:
i_locn type table of t_locn,
v_locn like line of i_locn.
field-symbols:
<f_005t> type t_005t.
Get existing EIS_VIDEO_LOCN_CONV records
EXEC SQL.
OPEN C FOR
SELECT EIS_LOCN
FROM VIDADMIN.EIS_VIDEO_LOCN_CONV
ENDEXEC.
do.
EXEC SQL.
FETCH NEXT C
INTO :V_LOCN-EIS_LOCN
ENDEXEC.
if sy-subrc ne 0.
exit.
endif.
append v_locn to i_locn.
enddo.
EXEC SQL.
CLOSE C
ENDEXEC.
sort i_locn.
I am facing the problem in i_locn internal table. Please give me your input to solve this issue.
- Anandakumar KHi,
We have resolved this issue with BASIS team help.
We modified the data charcater set as UTF8 in Oracle data base in unicode system ECC6.0 then the programme returns the
exact character format
Regards
K.Anandakumar -
I'm new to Native SQL commands.
Can somebody tell me how to fine tune this code.
Is there anything like FOR ALL ENTRIES in these commands also. We're using Oracle database.
loop at it_cus1.
EXEC SQL PERFORMING APPEND_IT_CUS2.
SELECT SAP_MASTNR, ANK_MASTNR
INTO
:IT_CUS2-KUNNR, :IT_CUS2-DATLT
FROM NOVARTIS.TABLE_ADRESS@ANKD
WHERE ANK_MASTNR = :IT_CUS1-DATLT
ENDEXEC.
endloop.
FORM append_it_cus2 .
APPEND it_cus2.
CLEAR it_cus2.
ENDFORM.you could try cursor processing, it might be more efficient:
EXEC SQL.
OPEN C FOR
SELECT SAP_MASTNR, ANK_MASTNR
FROM NOVARTIS.TABLE_ADRESS@ANKD
WHERE ANK_MASTNR = :IT_CUS1-DATLT
ENDEXEC.
loop at it_cus1.
EXEC SQL.
FETCH NEXT C into
:IT_CUS2-KUNNR, :IT_CUS2-DATLT
ENDEXEC.
APPEND it_cus2.
CLEAR it_cus2.
ENDloop.
EXEC SQL.
CLOSE C
ENDEXEC. -
Hi all,
my open SQL query is like
select matnr matkl from mara into corresponding fields of table i_mara for all entries in i_marc
where matnr = marc-matnr.
can u plz tell me the native sql for the same query?
Thanks.
pabihi,
EXEC SQL PERFORMING form.
Native SQL Anweisung
ENDEXEC.
EXEC SQL
select matnr matkl from mara into corresponding fields of table i_mara for all entries in i_marc
where matnr = marc-matnr.
ENDEXEC.
For further ref pls refer to link...
Re: Normal SQL Query othern than Native
Native SQL -
Alternative for EXEC command(Native SQL)
Hi Friends,
While Using the EXEC command in native sql it is showing the obselete Error , Can any one help with giving the alternative for the commands for native SQl.
ImmediateIn a Native SQL statement, data is passed between the ABAP program and the database using host variables. A host variable is an ABAP variable that is identified as such in the Native SQL statement by a preceding colon (:).
Example
Displaying an extract from the table AVERI_CLNT:
DATA: F1(3), F2(3), F3(3).
F3 = ' 1 '.
EXEC SQL.
SELECT CLIENT, ARG1 INTO :F1, :F2 FROM AVERI_CLNT
WHERE ARG2 = :F3
ENDEXEC.
WRITE: / F1, F2.
To simplify the form of the INTO lists in the SELECT statement, you can, as in Open SQL, specify a single structure as the target area.
Example
Displaying an Extract from the Table AVERI_CLNT:
DATA: BEGIN OF WA,
CLIENT(3), ARG1(3), ARG2(3),
END OF WA.
DATA F3(3).
F3 = ' 1 '.
EXEC SQL.
SELECT CLIENT, ARG1 INTO :WA FROM AVERI_CLNT
WHERE ARG2 = :F3
ENDEXEC.
WRITE: / WA-CLIENT, WA-ARG1.
Native SQL supports the directly-executable commands of your underlying database system. There are other special commands that you can use after the EXEC SQL statement for cursor handling, stored procedures (procedures stored in the database), and connections to other databases.
Cursor Processing -
Problem with native SQL cursor in generic data source
Hi, All!
I am implementing generic data source based on FM.
Because of complicated SQL I canu2019t use Open SQL and RSAX_BIW_GET_DATA_SIMPLE-example u201Cas isu201D.
So, I have to use Native SQL. But Iu2019ve got a problem with a cursor. When I test my data source in RSA3, everything is Ok. But, if I start appropriate info-package, I get error u201CABAP/4 processor: DBIF_DSQL2_INVALID_CURSORu201D. It happens after selecting of 1st data package in line u201CFETCH NEXT S1 INTOu2026u201D. It seems to me that when system performs the second call of my FM the opened cursor has already been disappeared.
Did anyone do things like this and what is incorrect?
Is it real to make generic data source based on FM with using Native SQL open, fetch, closeu2026Hi Jason,
I don't think this SQL is very valuable It is just an aggregation with some custom rules. This aggregation is performing on info-provider which consists of two info-cubes. Here we have about 2 billion records in info-provider and about 30 million records in custom db-table Z_TMP (certainly, it has indexes). I have to do this operation on 21 info-providers like this and I have to do this 20 times for each info-provider (with different values of host-variable p_GROUP)
SELECT T.T1, SUM( T.T2 ), SUM( T.T3 ), SUM( T.T4 )
FROM (
SELECT F."KEY_EVENT06088" AS T1,
F."/BIC/EV_COST" + F."/BIC/EV_A_COST" AS T2,
DECODE( D.SID_EVENTTYPE, 23147, 0,
23148, 0,
23151, 0,
23153, 0,
23157, 0,
23159, 0,
24896734, 0,
695032768, 0,
695029006, 0,
695029007, 0,
695036746, 0, F."/BIC/EV_COST") +
DECODE( D.SID_EVENTTYPE, 23147, 0,
23148, 0,
23151, 0,
23153, 0,
23157, 0,
23159, 0,
24896734, 0,
695032768, 0,
695029006, 0,
695029007, 0,
695036746, 0, F."/BIC/EV_A_COST") AS T3,
DECODE( D.SID_EVENTTYPE, 23147, F."/BIC/EV_DURAT",
23148, F."/BIC/EV_DURAT",
23151, F."/BIC/EV_DURAT",
23153, F."/BIC/EV_DURAT",
23157, F."/BIC/EV_DURAT",
23159, F."/BIC/EV_DURAT",
24896734, F."/BIC/EV_DURAT",
695032768, F."/BIC/EV_DURAT",
695029006, F."/BIC/EV_DURAT",
695029007, F."/BIC/EV_DURAT",
695036746, F."/BIC/EV_DURAT", 0) AS T4
FROM "/BIC/VEVENT0608F" F,
Z_TMP G,
"/BIC/DEVENT06085" D
WHERE F."KEY_EVENT06088" = G.ID
AND F."KEY_EVENT06085" = D.DIMID
AND G.GROUP_NO = :p_GROUP
AND ( F."/BIC/EV_COST" < 0 OR F."/BIC/EV_A_COST" < 0 )
AND D.SID_EVENTTYPE <> 695030676 AND D.SID_EVENTTYPE <> 695030678
UNION
SELECT F."KEY_EVNA06088" AS T1,
F."/BIC/EV_COST" + F."/BIC/EV_A_COST" AS T2,
DECODE( D.SID_EVENTTYPE, 23147, 0,
23148, 0,
23151, 0,
23153, 0,
23157, 0,
23159, 0,
24896734, 0,
695032768, 0,
695029006, 0,
695029007, 0,
695036746, 0, F."/BIC/EV_COST") +
DECODE( D.SID_EVENTTYPE, 23147, 0,
23148, 0,
23151, 0,
23153, 0,
23157, 0,
23159, 0,
24896734, 0,
695032768, 0,
695029006, 0,
695029007, 0,
695036746, 0, F."/BIC/EV_A_COST") AS T3,
DECODE( D.SID_EVENTTYPE, 23147, F."/BIC/EV_DURAT",
23148, F."/BIC/EV_DURAT",
23151, F."/BIC/EV_DURAT",
23153, F."/BIC/EV_DURAT",
23157, F."/BIC/EV_DURAT",
23159, F."/BIC/EV_DURAT",
24896734, F."/BIC/EV_DURAT",
695032768, F."/BIC/EV_DURAT",
695029006, F."/BIC/EV_DURAT",
695029007, F."/BIC/EV_DURAT",
695036746, F."/BIC/EV_DURAT", 0) AS T4
FROM "/BIC/VEVNA0608F" F,
Z_TMP G,
"/BIC/DEVNA06085" D
WHERE F."KEY_EVNA06088" = G.ID
AND F."KEY_EVNA06085" = D.DIMID
AND G.GROUP_NO = :p_GROUP
AND ( F."/BIC/EV_COST" < 0 OR F."/BIC/EV_A_COST" < 0 )
AND D.SID_EVENTTYPE <> 695030676 AND D.SID_EVENTTYPE <> 695030678
) T
GROUP BY T.T1 -
Performance of native sql query detoriates
Dear Experts,
The performance of my native SQL query is bad. On the database the query takes less than 5 seconds to process. From my abap program I get a session timeout dump after 10 minutes. What might be the possible reason.
Warm Regards,
AbdullahI am not a DBA, but this is a wild guess.
I have a native SQL query. It was running fine all morning(transported it to production today). By afternoon the report was not giving any output.
I went to the MS SQL query analyzer and executed the query, it returned the results in less than 5 seconds. The same query when I was executing from SAP using native SQL took more than 10 minutes and gave a dump(time exceeded).
My database guy asked me to execute the following on the database. Dbcc dbreindex('tablename')
The report is running fine since then. I am still not satisfied if this is the reason the performance is back on track, but yeah the report is running fine again. There seems to be some problem with the indexes.
I am using standard classes provided by SAP to execute my query and after execution the resultset reference object is being closed, I am closing the connection.
the code is as below.
PERFORM:
connect USING con_name con_ref,
select_into_table USING con_ref,
disconnect USING con_ref.
* FORM connect
* Connects to the database specified by the logical connection name
* P_CON_NAME which is expected to be specified in table DBCON. In case
* of success the form returns in P_CON_REF a reference to a connection
* object of class CL_SQL_CONNECTION.
* --> P_CON_NAME logical connection name
* <-- P_CON_REF reference to a CL_SQL_CONNECTION object
FORM connect USING p_con_name TYPE dbcon-con_name
p_con_ref TYPE REF TO cl_sql_connection
RAISING cx_sql_exception.
* if CON_NAME is not initial then try to open the connection, otherwise
* create a connection object representing the default connection.
IF p_con_name IS INITIAL.
CREATE OBJECT p_con_ref.
ELSE.
p_con_ref = cl_sql_connection=>get_connection( p_con_name ).
ENDIF.
ENDFORM. " connect
* FORM select_into_table
* Selects some rows from the test table and fetches the result rows
* into an internal table whose row structure corresponds to the
* queries select list columns.
FORM select_into_table
USING p_con_ref TYPE REF TO cl_sql_connection
RAISING cx_sql_exception.
DATA:
l_stmt TYPE string,
l_stmt_ref TYPE REF TO cl_sql_statement,
l_dref TYPE REF TO data,
l_res_ref TYPE REF TO cl_sql_result_set,
*Data related query
l_itab TYPE TABLE OF t_pricing_report,
l_row_cnt TYPE i.
* create the query string
CONCATENATE
'select A.SEQ,A.CONDTABLE,A.CONDNAME,A.VKORG,A.VTWEG,A.MATKL,A.MATNR,B.MTEXT,A.VKGRP,A.SGRPNAME,'
'A.VKBUR,A.SOFFNAME,A.ZSALES,A.SCNTNAME,A.KUNNR,A.SCSTNAME,A.PRBATCH,A.INCO1,'
'A.INCO2,A.DATAB,A.DATBI,A.KBETR,A.KONWA,A.KOSRT,B.MTART,B.GROES,B.VOLUM,B.EXTWG,B.WRKST,'
'A.MXWRT,A.GKWRT,'
'B.PATTERN,B.RIM,B.SERIES,B.SPDINDEX,B.LDINDX,B.MGROUP,B.APPLN,B.SDWALL,B.MGRPTXT'
'FROM Z_PRICELIST A,Z_MATERIALVIEW B'
'WHERE A.MANDT = ? AND'
'B.MANDT = A.MANDT AND'
'A.MATNR = B.MATNR AND'
'A.KSCHL = ? AND'
'A.CONDTABLE LIKE ? AND'
'A.VKORG LIKE ? AND'
'A.VTWEG LIKE ? AND'
'A.MATKL >= ? AND A.MATKL <= ? AND'
'A.MATNR >= ? AND A.MATNR <= ? AND'
'A.INCO1 LIKE ? AND'
'A.INCO2 LIKE ? AND'
'A.ZSALES >= ? AND A.ZSALES <= ? AND'
'A.KUNNR >= ? AND A.KUNNR <= ? AND'
'A.PRBATCH >= ? AND A.PRBATCH <= ? AND'
'A.VKBUR >= ? AND A.VKBUR <= ? AND'
'A.VKGRP >= ? AND A.VKGRP <= ? AND'
'B.WRKST >= ? AND B.WRKST <= ? AND'
'B.MTART >= ? AND B.MTART <= ? AND'
'? BETWEEN A.DATAB AND A.DATBI AND'
'B.GROES LIKE ? AND'
'B.LDINDX LIKE ? AND'
'B.SPDINDEX LIKE ? AND'
'B.RIM LIKE ? AND'
'B.SERIES LIKE ? AND'
'B.PATTERN LIKE ? AND'
'B.MGROUP LIKE ?'
'order by A.MATNR'
INTO l_stmt SEPARATED BY space. "#EC NOTEXT
* create a statement object
l_stmt_ref = p_con_ref->create_statement( ).
* bind input variables
GET REFERENCE OF l_col1 INTO l_dref.
l_stmt_ref->set_param( l_dref ).
*binding other references here
GET REFERENCE OF l_col33 INTO l_dref.
l_stmt_ref->set_param( l_dref ).
* set the input values and execute the query
l_col1 = sy-mandt.
*..Assigning values here
l_col33 = p_mgroup.
* PERFORM trace_2 USING 'EXECUTE_QUERY' l_stmt l_col1 l_col2.
l_res_ref = l_stmt_ref->execute_query( l_stmt ).
* set output table
GET REFERENCE OF l_itab INTO l_dref.
l_res_ref->set_param_table( l_dref ).
* get the complete result set
l_row_cnt = l_res_ref->next_package( ).
* display the contents of the output table
* PERFORM trace_next_package USING l_itab.
* PERFORM trace_result USING l_row_cnt 'rows fetched'.
pricing_report[] = l_itab[].
free l_itab.
* don't forget to close the result set object in order to free
* resources on the database
l_res_ref->close( ).
ENDFORM. "select_into_table
* FORM disconnect
* Disconnect from the given connection. In case of the default
* connection this can be omitted.
FORM disconnect
USING p_con_ref TYPE REF TO cl_sql_connection
RAISING cx_sql_exception.
DATA: l_con_name TYPE dbcon-con_name.
l_con_name = p_con_ref->get_con_name( ).
CHECK l_con_name <> cl_sql_connection=>c_default_connection.
* PERFORM trace_0 USING 'CLOSE CONNECTION' l_con_name.
p_con_ref->close( ).
* PERFORM trace_result USING l_con_name 'closed'.
ENDFORM. "disconnect
* FORM handle_sql_exception
* Write appropriate error messages when a SQL exception has occured
* --> P_SQLERR_REF reference to a CX_SQL_EXCEPTION object
FORM handle_sql_exception
USING p_sqlerr_ref TYPE REF TO cx_sql_exception.
FORMAT COLOR COL_NEGATIVE.
IF p_sqlerr_ref->db_error = 'X'.
WRITE: / 'SQL error occured:', p_sqlerr_ref->sql_code,
/ p_sqlerr_ref->sql_message. "#EC NOTEXT
ELSE.
WRITE:
/ 'Error from DBI (details in dev-trace):',
p_sqlerr_ref->internal_error. "#EC NOTEXT
ENDIF.
ENDFORM. "handle_sql_exception -
Dynamic 'from' Clause in Native SQL
Hi All,
While running a select query in ORACLE, we can put the table name in '<i>from</i>' clause at the runtime-Seletion Screen Parameter .
But I am not able to do so in SAP using Native Sql. Does SAP has any restrictions regarding this?
It might be possible that ,by using Embedded SQL (C/C++ precompiler ),we may be able to achive this.
Can any body please throw light on this.
Its Urgent.
Thanks in Advance.
Regards,
GauravHi
<u>Assuming you can also use Open SQL.</u>
Macroman's suggestion is OK. in Open SQL (this is SQL of ABAP platform) but a query statement can be constituted using some dynamic clauses. Although macro coding has some restrictions it will be less time consuming using it than a dynamic query.
<u>An example SELECT statement with dynamic clauses:</u>
SELECT (fields) FROM (table_name_variable)
INTO <target_fields>
WHERE (conditions_tab) .
For more information:
<a href="http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3983358411d1829f0000e829fbfe/frameset.htm">Open SQL -Reading Data</a>
*--Serdar -
Possible for Native SQL to read Pooled Tables?
Hi Experts,
Is it possible to run native SQL against SAP's internal Pool Table, the table that stores the many "Pooled Tables" across SAP? I realize that is much preferred to access the pooled table using Open SQL via ABAP functions, but that is not an option for me. I am writing native SQL against a copy of the SAP ECC underlying tables.
If it is possible, what is the technical name of the table?
Thanks,
KevinHello Kevin,
quite a strange question. As you mentioned it before, the preffered way is to use open sql. The pooled tables are handled by the application server and so, they are not accessible by native sql.
Independently, consider about two things:
1.) The ABAP DDIC uses sometimes different sizes and field-lengths, so you should not read LSTR or LRAW fields with native sql.
2.) You have to be more patient about transaction handling and parameter setting via SQL, because your application server does not get any information about what you have done before.
Kind regards,
Hendrik
Maybe you are looking for
-
XI/PI: need to create configuration from backend service interface to file
Hi All, I need to create configuration in which i have to map my backend service interface to file document. For example i have interface CreateOrderInformation_Out which is coming from abckend and i want to store those details in a file on external/
-
Hi All, When the user clicks on an order from search results, or when create new order action invoked there are tabs created on right pane of the Internet Sales. Did anybody add new custom tabs to ISA? May be adding threedocnav.jsp(similar to twodocn
-
Illustrator CS3 and Illustrator V10 compatibility
Hi Can Illustrator v10 open Illustrator cs3 files? If so which extension types? I am mainly interested in EPS and AI file formats but will be nice to know if there are other extension types as well. Thanks Dave
-
CS-Mars... understaing
Hi, being new to the concept of correlation and deep packet inspection, i have few design related (to CS-MARS) questions. - How isthe incident analyzed? I have only 1 incident "Inactive CS-MARS reporting device".. What does this mean, and how to go t
-
Since the ios6 upgrade my iCal is not getting iCal invites. Anyone know why or how to trouble shoot?