SELECT QUERIES IN ABAP.....
Can you give some idea about writing efficient select queries in ABAP?
Hi kishan,
i can give you some hint from one document, please reward point.
The hit list is the set of rows determined by the WHERE clause. In other words, it is the set of table rows that the database system must take into account to respond to the query. Dont confuse the hit list with the solution set, which is the set of rows (not necessarily from the table the query deals with) the database system returns to the program. Notice that in many cases the querys hit list and the solution set are different.
What is the reason behind this rule? A smaller hit list saves disk I/Os by the database system and often reduces network load. Both of these factors have a strong influence on your programs runtime performance.
How can you use ABAP to limit a hit list? First, use a WHERE clause whenever possible. Second, always try to describe the full search condition (not just part of it) within a single WHERE clause. ABAP provides a variety of arithmetical and logical operators to do this. Compared with your application program, the database server is usually the better place to evaluate search conditions.
Let me give you an example: Run a query against the flight table to produce a list of all flight dates for Lufthansa flight 0300 in 1998. Air carrier and air connection are known and can easily be used within the WHERE clause of the SELECT statement. The relevant year is also given, but at first glance it is difficult to build an appropriate search condition. Faced with this situation, you could be tempted to use the ABAP CHECK statement.
CHECK evaluates the subsequent logical expression. If it is true, the processing continues with the next statement. CHECK with a negative outcome terminates the current SELECT-ENDSELECT loop to start with the next row of the solution set, if there is one. Considering that fldateis a type D(YYYYMMDD) column of the sflighttable, a correct fragment of an ABAP program could look like this:
SELECT fldate
FROM sflight INTO xdate
WHERE carrid = 'LH'
AND connid = '0300'.
CHECK xdate = '1998'.
WRITE: / xdate.
ENDSELECT.
With ABAP in general, CHECK does the job of pattern matching in character variables. But in the WHERE clause of a SELECT statement, pattern matching also can be done easily by applying the LIKE operator. Within the search pattern, two characters have a particular meaning: _ stands for any one character and % stands for any character string. With this in mind, a better solution would be:
SELECT fldate
FROM sflight INTO xdate
WHERE carrid ='LH'
AND connid ='0300'
AND fldate LIKE '1998%'.
WRITE: / xdate.
ENDSELECT.
Similar Messages
-
Regarding parallel queries in ABAP same as in oracle 10g
Hi,
Is there any way we can write parallel queries in ABAP, in the same way we do in oracle 10g.Kindly see below;
alter table emp parallel (degree 4);
select degree from user_tables where table_name = 'EMP';
select count(*) from emp;
alter table emp noparallel;
SELECT /*+ PARALLEL(emp,4) / COUNT()
FROM emp;
The idea here is to distribute the load of select query in multiple CPUs for load balancing & performance improvement.
Kindly advise.
Thanks:
GauravHi,
> Is there any way we can write parallel queries in ABAP, in the same way we do in oracle 10g.
sure. Since it is just a hint...
SELECT *
FROM t100 INTO TABLE it100
%_HINTS ORACLE 'PARALLEL(T100,4)'.
will give you such an execution plan for example:
SELECT STATEMENT ( Estimated Costs = 651 , Estimated #Rows = 924.308 )
4 PX COORDINATOR
3 PX SEND QC (RANDOM) :TQ10000
( Estim. Costs = 651 , Estim. #Rows = 924.308 )
Estim. CPU-Costs = 33.377.789 Estim. IO-Costs = 646
2 PX BLOCK ITERATOR
( Estim. Costs = 651 , Estim. #Rows = 924.308 )
Estim. CPU-Costs = 33.377.789 Estim. IO-Costs = 646
1 TABLE ACCESS FULL T100
( Estim. Costs = 651 , Estim. #Rows = 924.308 )
Estim. CPU-Costs = 33.377.789 Estim. IO-Costs = 646
PX = Parallel eXecution...
But be sure that you know what you do with the parallel execution option... it is not scalable.... .
Kind regards,
Hermann -
Tracing queries from abap to a custom database via dblink
I' m connecting to a database by dblink (name magiap).
I would like to know if somewhere I can trace all the queries from abap to oracle in this specific session , to dbs ='MAGIAP'.
For istance, i would like that the query "SELECT "DESPARTY1"
into :v_DESPARTY1
FROM "T040PARTY"
WHERE "CODPARTY" = '305142941' will be stored some where (in a file??).
I would like that parameters - w_CODPARTY- will be substituted and stored in the trace file with the value (305142941), as shown in the previous
Here is the piece of code ..(a very short example of course)..
DATA : dbs LIKE dbcon-con_name,
v_CODPARTY(15),
v_DESPARTY1(60).
data : w_CODPARTY(15) value '305142941'.
dbs = 'MAGIAP'.
TRY.
EXEC SQL.
CONNECT TO :dbs
ENDEXEC.
IF sy-subrc <> 0.
EXEC SQL.
CONNECT TO :dbs
ENDEXEC.
ENDIF.
IF sy-subrc <> 0.
* RAISE err_conn_aea.
ENDIF.
EXEC SQL.
set connection :dbs
ENDEXEC.
EXEC SQL .
SELECT "DESPARTY1"
into :v_DESPARTY1
FROM "T040PARTY"
WHERE "CODPARTY" = :w_CODPARTY
ENDEXEC.
IF sy-subrc NE 0.
* rc = 4.
ENDIF.
EXEC SQL.
DISCONNECT :dbs
ENDEXEC.
ENDTRY.Hi Silvana,
The SQL statements have been stored in the SQL Cursor Cache, on the database and they will be available until they have been invalidated. You can access the statements at the 'MAGIAP' side and see the last executed queries in the cache.
You can access bind variables by query on the V$SQL_BIND_CAPTURE table, also.
On the other hand, you can activate the trace by the statement, below;
ALTER SYSTEM SET sql_trace = true SCOPE=MEMORY;
Then, the sql statements will be available in the usertrace file. Please note that you should execute and investigate all the statements that I noted above, at the remote side. Plus, as far as I know that it is not able to distinguish the records by the "dblink name". You should check all the statements and try to figure out what queries have been executed remotely.
Best regards,
Orkun Gedik -
Trace queries from abap to a custom oracle database via dblink
I' m
connecting to a database by dblink (name magiap).
I
would like to know if somewhere I can trace all the queries from abap to oracle
in this specific session , to dbs ='MAGIAP'.
For istance, i would like that the query
"SELECT "DESPARTY1"
into :v_DESPARTY1
FROM "T040PARTY"
WHERE "CODPARTY" = '305142941' will
be stored some where (in a file??).
I would like that parameters - w_CODPARTY- will be substituted and stored in the trace
file with the value (305142941), as shown in the previous
Here
is the piece of code ..(a very short example of course)..
DATA : dbs LIKE dbcon-con_name,
v_CODPARTY(15),
v_DESPARTY1(60).
data : w_CODPARTY(15) value '305142941'.
dbs = 'MAGIAP'.
TRY.
EXEC SQL.
CONNECT TO :dbs
ENDEXEC.
IF sy-subrc <> 0.
EXEC SQL.
CONNECT TO :dbs
ENDEXEC.
ENDIF.
IF sy-subrc <> 0.
* RAISE err_conn_aea.
ENDIF.
EXEC SQL.
set connection :dbs
ENDEXEC.
EXEC SQL .
SELECT "DESPARTY1"
into :v_DESPARTY1
FROM "T040PARTY"
WHERE "CODPARTY" =
:w_CODPARTY
ENDEXEC.
IF sy-subrc NE 0.
* rc = 4.
ENDIF.
EXEC SQL.
DISCONNECT :dbs
ENDEXEC.
ENDTRY.Hi Silvana,
The SQL statements have been stored in the SQL Cursor Cache, on the database and they will be available until they have been invalidated. You can access the statements at the 'MAGIAP' side and see the last executed queries in the cache.
You can access bind variables by query on the V$SQL_BIND_CAPTURE table, also.
On the other hand, you can activate the trace by the statement, below;
ALTER SYSTEM SET sql_trace = true SCOPE=MEMORY;
Then, the sql statements will be available in the usertrace file. Please note that you should execute and investigate all the statements that I noted above, at the remote side. Plus, as far as I know that it is not able to distinguish the records by the "dblink name". You should check all the statements and try to figure out what queries have been executed remotely.
Best regards,
Orkun Gedik -
Re : select-options in abap-objects program
Dear friends,
I want to give select-options in abap-objects program. How to give that.
Thanking You
with regards,
ManiIn the transaction SE24, enter your class name, click modify.
in the tab named "Types" you have to declare two types. By example, if you want to receive one select-options that in your program that uses this class is declared like:
" P_SAKNR FOR SKAT-SAKNR".
you've got to declare two types in the class:
a- TYPES: begin of E_S_SAKNR,
sign(1),
option(2),
low(10),
high(10),
end of E_S_SAKNR.
b - TYPES E_T_SAKNR type standard table of E_S_SAKNR.
so, in the class method that you want to receive P_SAKNR as importing parameter. You got to do this:
method TEST importing ET_SAKNR type E_T_SAKNR.
now, in the implementation of this method you should be able to use ET_SAKNR as the same way as you usually use a parameter or a select-option. You could use it in a select with the operator IN by example.. -
Re : select-options in abap objects
Dear friends,
I want to give select-options in abap-objects program. How to give that.
Thanking You
with regards,
ManiHI Mani,
It's common mix ABAP Procedural with ABAP Objects in the same program.
You should use the same way used in ABAP procedural program as Marco Cerdelli sad.
But inside ABAP OBJECTS classes you can't use is these statement type.
Don't forget to close this thread and all yours previous when your question be answered ! In case of doubt read the [rules of engagement|https://forums.sdn.sap.com/].
Best Regards.
Marcelo Ramos -
Hi Guys,
I need a small help from you. I want to know how to populate the value from select-option to abap object. Please help me, it is very importantcheck this code
REPORT ZSELOPT_TO_CLASS .
TABLES: VBRK.
SELECT-OPTIONS: S_VBELN FOR VBRK-VBELN.
DATA: IT_VBELN TYPE RSELOPTION.
DATA: X_VBELN TYPE RSDSSELOPT.
CLASS C1 DEFINITION.
PUBLIC SECTION.
DATA: IT_VBRP TYPE VBRP_TAB,
X_VBRP LIKE LINE OF IT_VBRP.
METHODS: GET_DATA IMPORTING S_VBELN TYPE RSELOPTION.
METHODS: DISP_DATA.
ENDCLASS.
CLASS C1 IMPLEMENTATION.
METHOD GET_DATA.
*SELECT * FROM VBRP*
INTO TABLE IT_VBRP
WHERE VBELN IN S_VBELN.
ENDMETHOD.
METHOD DISP_DATA.
LOOP AT IT_VBRP INTO X_VBRP.
WRITE:/ X_VBRP-VBELN,
X_VBRP-POSNR.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA OBJ TYPE REF TO ZCL_SELOPT.
CREATE OBJECT OBJ.
LOOP AT S_VBELN.
MOVE S_VBELN-LOW TO X_VBELN-LOW.
MOVE S_VBELN-HIGH TO X_VBELN-HIGH.
MOVE S_VBELN-SIGN TO X_VBELN-SIGN.
MOVE S_VBELN-OPTION TO X_VBELN-OPTION.
APPEND X_VBELN TO IT_VBELN.
ENDLOOP.
CALL METHOD OBJ->GET_DATA
EXPORTING
S_VBELN = IT_VBELN.
CALL METHOD OBJ->DISP_DATA.
Edited by: moazam hai on May 17, 2008 6:17 AM
Edited by: moazam hai on May 17, 2008 6:19 AM -
I am using mutiple select queries to fetch data from Project Server 2010 DB(its sharepoint DB) and these queries fetch data in Excel BI report by establishing connection with DB using instance name and all. I have enhance all these select queries and data
is being fetched in secs. but when more than one copy of same Excel BI report is refreshed using 'Refresh All' option, then these select queries cause blockage on DB.
Please let me know mitigation for this blockage issue.
Should I use begin transaction and commit transaction statements/ shared lock statements.
please replyHi,
run same query at the same time? -
Executing Multiple Select Queries in a Single attempt
HI,
I executed two select queries in a single statement execute. It is executing without any error. Hence there must be two resultset objects within that single statement.
What the problem is that I m able to fetch the first resultset and its data, But I execute stmt.getMoreResults() to move to the next resultset, it returns false, which means there is no more results. I want to know what is the problem ?? (Record exist in the database for both queries)
And How can I rertieve both the resultsets. ??
Plz help me asap.
For ur convenience I m posting the Java code also which I m trying.
sql.delete(0, sql.length());
sql.append("select FIRST_NAME , MIDDLE_NAME , LAST_NAME from USER_MASTER where USER_ID=4;");
sql.append("select producttransaction_id, product_type from product_transaction where transaction_id=102 order by product_type desc");
Statement stmt = con.createStatement();
stmt.execute(sql.toString());
int resultsetcount =1;
ArrayList arrlist = new ArrayList();
rs = stmt.getResultSet();
if(rs !=null)
if(rs.next())
.........// logic here working properly
//Now when I move to next resultset using the below statement
//it returns false indicating that there r no more results.
// Why this is so ?????
boolean moreresultsets = stmt.getMoreResults();
System.out.println("MoreResultsets::"+moreresultsets);
if(moreresultsets)
rs = stmt.getResultSet();
if(rs!=null)
while(rs.next())
//...Logic.......
rs.close();
ThanksI've never seen this used the way you are using it. In my experience the only way to do this would be to execute a single SQL statement that returns multiple result sets - you are trying to append two SQL statements.
You could define an in-line procedure wrapping your two select statements, or you could define a stored procedure to do the same thing. Then (either way) use CallableStatement to execute the call to the procedure. -
How to set default value in select option for ABAP query
Hi experts,
What is the way to set up default values for select-options in ABAP query.
e.g.
I have one field 'Year' in my ABAP query selection screen.
I want value of current year to be appeared here whenever user execute report
Thanks in Advance
-HarkamalHi Harkamal,
execute your Query via SQ01. On Selection-Screen
goto save Variant. Mark your field
as selection variable an press Button election variable.
Take variable from TVARV and use it.
Than save the Variant.
Look at TVARV if the 'Year' is updated to the actualYear!
regards, Dieter -
How to write text name of parameters / select options in ABAP list??
Hi gurus, i must read the text name of parameterd / select options in ABAP program and write it in a list of the same program for log.......how can i do it??
Thanks in advance!
Best regards!
Ferdinando
Message was edited by:
Ferdinando SellittoHello Ferdinandino
Useful function modules are:
RS_PRINT_SELECTIONS
RS_LIST_SELECTION_TABLE (Generates list according to values in selection table(RSPARAMS))
RS_REFRESH_FROM_SELECTOPTIONS (Current contents of selection screen)
Function module RS_REFRESH_FROM_SELECTOPTIONS can provide the input for function module RS_LIST_SELECTION_TABLE.
Regards
Uwe -
Multiple selection lists in abap report
I need to populate a multiple selection list and then read the selection in an ABAP report. A parameter with list box is not solving my purpose.
Please give any suggestion on this.Hi
If you can't use the SELECT-OPTION statament, there's no standard solution.
U can only try to create a table control with only one colunm and every hit of the table control is a single hit for the selection.
To insert a table control in a selection-screen u need to use the statament:
SELECTION-SCREEN BEGIN OF TABBED (see the help)
In order to create a TAB where u can load a subscreen where u can insert a table control.
The u need to transfer the hit from table control to a range.
Max -
Multiple select queries for JDBC sender
I am working on JDBc to IDOC scenario.
I need to process two select queries in PI where output of 1st query becomes the input of second.
Now i need to map the output of second to IDOC through XSL mapping also i need to use BPM to process(without using the stored procedure) the scenario.
In my JDBC communication channel i have option for only one select query and second query should fetch the data through BPM.
In BPM i have used the following sequence mentioned below:
Start --> Receive step ( receives all the header lines) --> Transformation (to split the header messages to single message) --> Block Start( To processEachRecord) --> Send Syn (to map the request message i,e. output of first query with Response i,e. structure of the second query) --> Send Asyn (to send the output of second query to XSLT mapping) -->Block End --> stop
Output of XSLT mapping is the input for IDOC
Now i need to understand how to process the second query?>> I need to process two select queries in PI where output of 1st query becomes the input of second
Use SQL Nested Queries.
Example:
SELECT Model FROM Product WHERE ManufacturerID IN (SELECT ManufacturerID FROM Manufacturer
WHERE Manufacturer = 'Dell')
Here first table is Manufacturer .. we do select query in manufacturer to return data and pass it to the first table Product.
>> Now i need to understand how to process the second query?
You dont need at all. In your sender jdbc channel, write sql statement nested query and you will get only output of the second table. you map the second table output to the idoc.
Note: Dont know why do you need BPM for this case..
Jdbc sender adapter help links
http://help.sap.com/saphelp_srm40/helpdata/en/7e/5df96381ec72468a00815dd80f8b63/content.htm
Check this thread for update statement in jdbc cc
Re: sender jdbc adapter -
I know that the JDBC sender adapter can handle joins, but can it handle more sophisticated SELECT queries such as subselects, group by, rownum, etc. In other words, are there any limitations in the SELECT query?
Thanks in advance.Hi Bevan,
The only limitation with XI30-JDBC Sender Adapter is with Oracle Stored Procedure/Functions, as Oracle SP Query returns a cursor, and not a resultset.
Thanks
Prasad -
Hi All,
I have a program to be performance tuned. There are select queries on VBAP and BSEG which are taking time.
The where condition includes maximum primary keys. But when I checked the data its fetching is very large.
I have performance tuned another code and replaced the selects with FMs but now for VBAP and BSEG I am not
getting suitable FMs . Also some which I got are taking more time then the selects.
Kindly suggest something.
Thanks
Moderator message - Please see Please Read before Posting in the Performance and Tuning Forum before posting - post locked
Edited by: Rob Burbank on Mar 18, 2010 3:07 PMHi,
If you are giving All the fields of the table in the Second Query and trying to use CORRESPONDING FIELDS then second query will take more time, since here FILED names will be compared which is an extra operation if you use * instead it will just to BYTE copy which is faster.
If you are giving only some fields of the table in the Second query then second query takes less time than First query.
This is beacuse the amount of data that is transferred from Database server to Application server will be less in the second case if all fields of the table are not mentioned.
Regards,
Sesh
Maybe you are looking for
-
I can send you a screen shot if that would be helpful. I have noticed that the emails sent out of S1 always default to the end of the message so we need to scroll up to edit what we've written. Most of the time I need to edit the text near the top of
-
Printing Turkish Characters in SAP Script Form
Hi I want to print a Form where I need to Print Turkish characters from Database. Its Print Preview is coming absolutely right but there is some problem while printing. I shows # symbol in places of Turkish Characters. I have checked the printer and
-
Browsing by genre / artist view
Hi! Just upgraded to iTunes v7.0. In v6.0 I could search by genre, artist etc in the top, now I just have all my songs in the library. Is there a way to get this back? Many thanks!
-
I need help to reload my purchases to my new mac!
I need help to reload my purchases to my new mac! My other mac harddisk died withou warning. When I log on to itunes store with my apple ID>purchased (new) i only get the lists for apps and books. Not music. Anybody know a different way to redownload
-
Updating to 1.0.2 kills 2 ipods. Is it just me?
New MacBook & new 3G nano, all working fine. I succumbed to Apple's pestering & after updating iTunes to 7.5 I updated to 1.0.2 on the nano. All went well, but after the ipod shut down it wouldn't restart. In fact, it wouldn't do anything other than