ABAP Joins or Separate select statements?
Hi,
I am working on a simulation of an implementation project as part of my in-house training programme. I am a rookie to ABAP and am now doing a print program that requires master data selection from tables ANLZ, LFA1, MSEG and CSKT, and also related line items from ANLA.
As a former Java/.NET programmer I used to play with database joins. Now since ABAP joins are much simpler to use, I take the best advantage of them. For instance, in this particular program, I fetched related data from ANLZ, ANLA, LFA1 and CSKT into one internal table using a single select statement with ABAP joins.
Now I happen to hear (in bits and pieces) that one should limit the use of nested joins to a certain extend. Instead, for the above program, I was advised to use 4 internal tables and to select data separately using FOR ALL ENTRIES. But in this case, we need to use 4 select statements, which means 4 database operations in place of just one.
From ABAP documentation, I read that we can link upto 24 tables in a single select statement using ABAP joins.
Can anyone clarify more about this? Which is high on performance?
Using a single select statement using joins
or
Using multiple selects -- FOR ALL ENTRIES?
Thanks and regards,
Arun
Hi Arun,
you keep reading in these forums that FOR ALL ENTRIES is more performant, but this is simply not true.
In your example, joining four tables for one DB operation is better than storing a lot of redundant data in internal tables just to perform four separate DB operations using FOR ALL ENTRIES.
Make sure you join the tables correctly, i.e. link dependent tables giving their full primary key.
FOR ALL ENTRIES can be used where effective join statements are not possible, e.g. when cluster tables are involved (like BSEG).
Cheers
Thomas
Edit: check this out too: Inner Join or For All Entries
Similar Messages
-
Can i join these sql select statement in one
Hi All,
Can i join this two select statement in to one select statement.
select username from dba_users where username like 'SAP%%%'; # to the Schemaid of the below /BMC/YGO_CPROD.
select YOP_PRD_NM, YOP_VERS from <schemaid>."/BMC/YGO_CPROD"; # To know a version from the table.
I am using this in a script can any help to join the above select statements into one.
Schemaid should be passed to this select YOP_PRD_NM, YOP_VERS from <schemaid>."/BMC/YGO_CPROD"; and i need to get output!
Thanks a lotAre you asking about using the output of one query as the input to the WHERE clause of another?
If so look at the demos here: http://www.psoug.org/reference/conditions.html
PS: There is zero value in the construct 'SAP%%%'
What is it you are trying to do?
One "%" wildcard is sufficient. -
Inner Join for Dynamic Select statement
Hi All,
Can some one please help me in rewriting the below select statement where i have to remove the existing table1 by putting a dynamic table name which has the same table structure.
select a~zfield1
a~zfield2
from ztab1 as a
inner join ztab2 as b
on b~ztab1-zfield3 = a~ztab2-zfield3
where a~zfield4 = 'A'.
I am looking something as below. But encountering an error when using the below statement
select a~zfield1
a~zfield2
from (v_ztab1) as a
inner join ztab2 as b
on b~ztab1-zfield3 = a~ztab2-zfield3
where a~zfield4 = 'A'.
No Separate selects please. Please help me in rewriting the same select statement itself.
Regards,
PSKhi,
What error you are getting ?
Also INTO is missing from the statement.
SELECT pcarrid pconnid ffldate bbookid
INTO TABLE itab
FROM ( spfli AS p
INNER JOIN sflight AS f ON pcarrid = fcarrid AND
pconnid = fconnid )
WHERE p~cityfrom = 'FRANKFURT' AND
p~cityto = 'NEW YORK' .
thanks -
ABAP SQL: Multiplication in Select-Statement
Hi everybody,
in native SQL it should be possible to use a statement like:
SELECT preisstueck, (anzahl*preisstueck) as gesamtpreis FROM kaufteile
in ABAP I tried:
SELECT profile
(SUM( val2300 ) AS val2300 ) + ( SUM( val2315 ) AS val2315 ) + ( SUM( val2330 ) AS val2330 ) + (SUM( val2345 ) AS val2345 )
But I get an Error: Unknown row: (
Could anybody pls help?
Thanks
Regards
MarioI would never recommend using native SQL. Please try to use OpenSQL so that other abapers can easily understand the code (in future). Suppose in future the customer decides to migrate from Oracle to DB2 or HANA then the sql has to be changed too.
but if you still insist in using it here is a sample code. Please note that it works only for transparent tables.
REPORT demo_native_sql.
DATA: BEGIN OF wa,
connid TYPE spfli-connid,
cityfrom TYPE spfli-cityfrom,
cityto TYPE spfli-cityto,
END OF wa.
DATA c1 TYPE spfli-carrid VALUE 'LH'.
EXEC SQL PERFORMING loop_output.
SELECT connid, cityfrom, cityto
INTO :wa
FROM spfli
WHERE carrid = :c1
ENDEXEC.
FORM loop_output.
WRITE: / wa-connid, wa-cityfrom, wa-cityto.
ENDFORM.
Please note:
Native SQL statements bypass the R/3 database interface. There is no table logging, and no synchronization with the database buffer on the application server. For this reason, you should, wherever possible, use Open SQL to change database tables declared in the ABAP Dictionary. In particular, tables declared in the ABAP Dictionary that contain long columns with the types LCHR or LRAW should only be addressed using Open SQL, since the columns contain extra, database-specific length information for the column. Native SQL does not take this information into account, and may therefore produce incorrect results. Furthermore, Native SQL does not support automatic client handling. Instead, you must treat client fields like any other.
See native SQL syntax for
Oracle:Native SQL for Oracle (SAP Library - ABAP Programming (BC-ABA))
Informix: Native SQL for Informix (SAP Library - ABAP Programming (BC-ABA))
DB2: Native SQL for DB2 Common Server (SAP Library - ABAP Programming (BC-ABA)) -
Select distinct and 2 inner joins in same select statement
can anyone guide me how to write the below query for higher performance. can I use for all entires or shall i split this,
please let me know your opinions.
SELECT DISTINCT werks matnr b~stlal idnrk postp d~aennr
sortf potx1 c~lkenz b~stlty stlst
INTO TABLE ltab_one
FROM mast AS a INNER JOIN stko AS b
ON a~stlnr = b~stlnr
AND a~stlal = b~stlal
INNER JOIN stas AS c
ON b~stlnr = c~stlnr
AND b~stlal = c~stlal
AND b~stlty = c~stlty
INNER JOIN stpo AS d
ON c~stlnr = d~stlnr
AND c~stlkn = d~stlkn
AND c~stlty = d~stlty
WHERE a~werks IN s_werks
AND ( ( d~andat IN s_datum
OR d~aedat IN s_datum
OR a~andat IN s_datum
OR a~aedat IN s_datum
OR b~andat IN s_datum
OR b~aedat IN s_datum
OR c~andat IN s_datum
OR c~aedat IN s_datum
) AND d~datuv >= lv_effdt )
AND a~stlan = '1'
AND matnr IN s_matnr.WHERE a~werks IN s_werks
AND ( ( d~andat IN s_datum
OR d~aedat IN s_datum
OR a~andat IN s_datum
OR a~aedat IN s_datum
OR b~andat IN s_datum
OR b~aedat IN s_datum
OR c~andat IN s_datum
OR c~aedat IN s_datum
) AND d~datuv >= lv_effdt )
AND a~stlan = '1'
AND matnr IN s_matnr.
This part determines your performance, not the DISTINCT and not the joins.
What is in s_werks, s-datum, s_matnr typically? I guess there are better and worse conditions. -
How to join 2 separate SQL Statements into 1 command
Hi Everyone,
I'm pretty new to PL/SQL.. thanks for your help. I'm hoping the answer to this is pretty straight forward.
I have a report (crystal) that has 1 subreport. The results from the report are exported to excel. I'd like to take this report and include it in another report, however since I've already went 1 sub report down, looks like I need to figure out a way to get this 1 report combined into a SQL Command.
Is there an easy way to combine the main report and subreport here into 1 SQL Command?
Main Report SQL Select
SELECT DISTINCT "ST_WORKORDER_REF"."st_wo_number", "ST_WORKORDER_REF"."gs_guid", "ST_STATION"."st_workorder_ref_guid", "ST_STATION"."gs_guid", "ST_ATTACHED_ASSEMBLIES"."gs_network_feature_guid", "GS_ASSEMBLY_REF"."gs_guid", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid", "GS_ASSEMBLY_DEFAULTS"."gs_assembly_ref_guid", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_quantity", "GS_ASSEMBLY_REF"."gs_assembly_description", "GS_ASSEMBLY_REF"."gs_display_feature_name", "ST_ATTACHED_ASSEMBLIES"."gs_network_feature_name", "ST_ATTACHED_ASSEMBLIES"."st_assembly_action_code", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_date_created", "ST_ATTACHED_ASSEMBLIES"."gs_display_feature_name"
FROM ((("gs54025_master"."dbo"."ST_WORKORDER_REF" "ST_WORKORDER_REF" LEFT OUTER JOIN "gsXXXXX"."dbo"."ST_STATION" "ST_STATION" ON "ST_WORKORDER_REF"."gs_guid"="ST_STATION"."st_workorder_ref_guid") LEFT OUTER JOIN "gs54gsXXXXX"."dbo"."ST_ATTACHED_ASSEMBLIES" "ST_ATTACHED_ASSEMBLIES" ON "ST_STATION"."gs_guid"="ST_ATTACHED_ASSEMBLIES"."gs_network_feature_guid") LEFT OUTER JOIN "gsXXXXX"."dbo"."GS_ASSEMBLY_REF" "GS_ASSEMBLY_REF" ON "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid"="GS_ASSEMBLY_REF"."gs_guid") LEFT OUTER JOIN "gsXXXXX"."dbo"."GS_ASSEMBLY_DEFAULTS" "GS_ASSEMBLY_DEFAULTS" ON "GS_ASSEMBLY_REF"."gs_guid"="GS_ASSEMBLY_DEFAULTS"."gs_assembly_ref_guid"
WHERE "ST_WORKORDER_REF"."st_wo_number"=N'90295' AND "ST_ATTACHED_ASSEMBLIES"."st_assembly_action_code"=N'C'
ORDER BY "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid"I want to append the results from the subreport:
Sub Report SQL Select
SELECT DISTINCT "ST_WORKORDER_REF"."st_wo_number", "ST_WORKORDER_REF"."gs_guid", "ST_ATTACHED_ASSEMBLIES"."gs_network_feature_guid", "GS_ASSEMBLY_REF"."gs_guid", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid", "GS_ASSEMBLY_DEFAULTS"."gs_assembly_ref_guid", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_quantity", "GS_ASSEMBLY_REF"."gs_assembly_description", "GS_ASSEMBLY_REF"."gs_display_feature_name", "ST_ATTACHED_ASSEMBLIES"."gs_network_feature_name", "ST_ATTACHED_ASSEMBLIES"."st_assembly_action_code", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_date_created", "ST_ATTACHED_ASSEMBLIES"."gs_display_feature_name", "ST_SPAN"."st_workorder_ref_guid"
FROM ((("gsXXXXX"."dbo"."ST_WORKORDER_REF" "ST_WORKORDER_REF" INNER JOIN "gsXXXXX"."dbo"."ST_SPAN" "ST_SPAN" ON "ST_WORKORDER_REF"."gs_guid"="ST_SPAN"."st_workorder_ref_guid") INNER JOIN "gsXXXXX"."dbo"."ST_ATTACHED_ASSEMBLIES" "ST_ATTACHED_ASSEMBLIES" ON "ST_SPAN"."gs_guid"="ST_ATTACHED_ASSEMBLIES"."gs_network_feature_guid") LEFT OUTER JOIN "gs54025_master"."dbo"."GS_ASSEMBLY_REF" "GS_ASSEMBLY_REF" ON "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid"="GS_ASSEMBLY_REF"."gs_guid") LEFT OUTER JOIN "gsXXXXX"."dbo"."GS_ASSEMBLY_DEFAULTS" "GS_ASSEMBLY_DEFAULTS" ON "GS_ASSEMBLY_REF"."gs_guid"="GS_ASSEMBLY_DEFAULTS"."gs_assembly_ref_guid"
WHERE "ST_WORKORDER_REF"."st_wo_number"=N'90295' AND "ST_ATTACHED_ASSEMBLIES"."st_assembly_action_code"=N'C'
ORDER BY "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid"Thanks,
BTW, I realize the SQL in both are very similar. GS_station and GS_Span both starting points... why I needed the subreport.
JohnNot being a Crystal Reports developer, it's not obvious to me what "subreport" means in this context.
What would it mean to you to combine the main report and the subreport? Do you just want to add the rows that the subreport returns to the end of the results returned by the report? If so, is the structure of the two report sets identical (do they select the same number of columns with the same data types)? Or do you want to join the data from the report query to the data from the subreport query? If so, what key(s) relate the rows in one to the rows in the other? Or do you want to do something else?
It would be exceptionally helpful if you could post the DDL to create your tables (simplified versions if possible), the DML to insert some reasonable sample data, and an explanation of the output you're trying to get from the combined query.
Justin -
Default join in select statements
Hi guyz,
If I am using just Join in my select statement. What does it do by default
1. innter join
2. outer join
eg:
select vbeln posnr into table itab from vbak <b>join</b> vbap on vbakvbeln = vbapvbeln.
Thanks.Mgs,
By Default innerjoin.
See the diff.
Hi karan check also the "left outer join" statement.
It might help you if you need 1-N relation
// left outer Join
Table 1 Table 2
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
3
e2
f2
g2
h2
a3
b3
c3
2
4
e3
f3
g3
h3
a4
b4
c4
3
|--|||--|
Left Outer Join
|--||||||||--|
| A | B | C | D | D | E | F | G | H |
|--||||||||--|
| a1 | b1 | c1 | 1 | 1 | e1 | f1 | g1 | h1 |
| a2 | b2 | c2 | 1 | 1 | e1 | f1 | g1 | h1 |
| a3 | b3 | c3 | 2 |NULL|NULL|NULL|NULL|NULL|
| a4 | b4 | c4 | 3 | 3 | e2 | f2 | g2 | h2 |
|--||||||||--|
// Inner Join
Table 1 Table 2
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
3
e2
f2
g2
h2
a3
b3
c3
2
4
e3
f3
g3
h3
a4
b4
c4
3
Inner Join
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
1
e1
f1
g1
h1
a4
b4
c4
3
3
e2
f2
g2
h2
Pls. mark if useful -
Select statement Table Join sequence (Performance)
Hi,
I have 3 tables Header (Hdr), Item (Itm) and Schedule Line (Sdl) table. The number of entries is max in Sdl table (Eg: Hdr = 1000; Item = 20000 and Sdl = 200000 records). I need to join these 3 tables in my SELECT statement to fetch the required records.
Case A:
Header AS HDR
JOIN Item AS ITM
ON HDRORDID = ITMORDID
AND HDRVRSIOID = ITMVRSIOID
JOIN ScheduleLine AS SDL
ON ITMITMID = SDLITMID
Case B:
ScheduleLine AS SDL
JOIN Item AS ITM
ON ITMITMID = SDLITMID
JOIN Header AS HDR
ON HDRORDID = ITMORDID
AND HDRVRSIOID = ITMVRSIOID
Questions:
1) The performance of the Select query is really bad with Case A and very good (really fast) with Case B. Will the number of records in the tables used determine the sequence of join in the Select statement ?
2) If yes, is this independent of database used ? That is, will the behaviour be the same in all databases (Eg: Oracle, DB2, SQL Server, etc) ?
Appreciate your help.
Thanks,
KarthikI believe that the performance discrepancy between the two versions is caused by you not specifying the joins correctly (i.e. not qualifying the header and item at schedule level as I mentioned previously).
CAse A.
Header AS HDR
JOIN Item AS ITM
ON HDRORDID = ITMORDID
AND HDRVRSIOID = ITMVRSIOID
JOIN ScheduleLine AS SDL
ON ITMITMID = SDLITMID
reads all 1000 hDRs, joins all 20000 items correctly to these BUT then joins schedule lines only by item id so there will be a very large number of matches. i.e. any item with itemid 10 will match to EVERY SDL with itemid 10. as there are 20000 items and 200000 schedule lines this will be massive!
Case B:
ScheduleLine AS SDL
JOIN Item AS ITM
ON ITMITMID = SDLITMID
JOIN Header AS HDR
ON HDRORDID = ITMORDID
AND HDRVRSIOID = ITMVRSIOID
This will not have the same amount of DB traffic as the SDL is now the driving force. It will still match more than you intend but will only be reading the items redundantly trather than the more voluminous schedules.
Basically, your sql is wrong and should qualify the matches right down to schedule line level as per my earlier post. When you have changed the sql, try the two alternatives again and see if there is any performance differences. I suspect that there will not be, but it will be interesting to find out for sure. -
How to use SELECT statement to extract KNA1-NAME1 and KNB1-ZSABE
In building table I_KNA1 in form f_extract_data, an additional select statement is needed to select and append datafrom (KNA1 and KNB1) to existing I_KNA1
In form f_extract_data table i_kna1 is populated with data from zd_kna101.(where ZD_KNA101 is a view of KNA1, KNB1 and KNBK. It's a joint of these three tables.) This will take care of all customers with KNBK-BANKL and KNBK-BANLN populated. But this does not include new customers created in SAP CRM (no KNBK records). Therefore a separate SELECT statement is needed to extract KNA1-NAME1 and KNB1-ZSABE for customers created in SAP CRM(the customers who do do not have BANKL and BANKN). These selected records are then need to be appended to I_KNA1. It's possible that new selection statement might extract records that are already in existing I_KNA1 table. IF this is the case, right after the append, sort I_KNA1 and remove duplicate records.
form f_extract_data.
select kunnr " Customer Number
name1 " Name
zsabe " Business Unit
bankl " Legacy Bank Key
bankn " Legacy Bank Account
from zd_kna101 " View of KNA1, KNB1, and KNBK
into table i_kna1
for all entries in i_doc_by_ref
where kunnr = i_doc_by_ref-kunnr
and zsabe in s_zsabe.
if sy-subrc <> 0.
message a116 with 'customer'. " Customer Table is empty. HALT!!!
else.
sort i_kna1 by kunnr.
endif.
will I have to use the join statement(for KNA1-NAME1 and KNB1-ZSABE using the key as KUNNR) here or give two seperate select statements for extracting data from KNA1 and KNB1 using the key as KUNNR.
THANKS FOR THE HELP.I would suggest using the join on KUNNR. Maybe something like this.
data: begin of itab occurs 0,
kunnr type kna1-kunnr,
name1 type kna1-name1,
ZSABE type knb1-ZSABE,
end of itab.
select kna1~kunnr kna1~name1 knb1~zsabe
into table itab
from kna1
inner join knb1
on kna1~kunnr = knb1~kunnr
where ........
Regards,
Rich Heilman -
How to use a table name in the select statement using a variable?
Hi Everybody,
I got a internal table which has a field or a variable that gets me some tables names. Now I need to retrieve the data from all these tables in that field dynamically at runtime. So could you suggest me a way out to use the select query which uses this variable as a table ?
Regards,
Mallik.Hi all,
Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?
for ex : select * from (tab_name) where....?
Can we do inner join on such select statements? If so how?
Thanks & Regards,
Mallik. -
Joins And For all Enteries in Select Statement
Could you please tell me when there is a high amount of data which is being handled in the table, does the use of INNER JOINS and FOR ALL ENTERIES in SELECT Statement decreases the system performance? ?
Can you also let me know where can i get some tips regarding do's and dont's for ABAP Programming, I want to increase my system performance.
Currently the programs which are being used are taking a lot of time for execution...
Its very URGENT!Hai Jyotsna
Go through the following Tips for improving Performence
For all entries
The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.
The plus
Large amount of data
Mixing processing and reading of data
Fast internal reprocessing of data
Fast
The Minus
Difficult to program/understand
Memory could be critical (use FREE or PACKAGE size)
Some steps that might make FOR ALL ENTRIES more efficient:
Removing duplicates from the driver table
Sorting the driver table
If possible, convert the data in the driver table to ranges so a BETWEEN statement is used instead of and OR statement:
FOR ALL ENTRIES IN i_tab
WHERE mykey >= i_tab-low and
mykey <= i_tab-high.
Nested selects
The plus:
Small amount of data
Mixing processing and reading of data
Easy to code - and understand
The minus:
Large amount of data
when mixed processing isnt needed
Performance killer no. 1
Select using JOINS
The plus
Very large amount of data
Similar to Nested selects - when the accesses are planned by the programmer
In some cases the fastest
Not so memory critical
The minus
Very difficult to program/understand
Mixing processing and reading of data not possible
Use the selection criteria
SELECT * FROM SBOOK.
CHECK: SBOOK-CARRID = 'LH' AND
SBOOK-CONNID = '0400'.
ENDSELECT.
SELECT * FROM SBOOK
WHERE CARRID = 'LH' AND
CONNID = '0400'.
ENDSELECT.
Use the aggregated functions
C4A = '000'.
SELECT * FROM T100
WHERE SPRSL = 'D' AND
ARBGB = '00'.
CHECK: T100-MSGNR > C4A.
C4A = T100-MSGNR.
ENDSELECT.
SELECT MAX( MSGNR ) FROM T100 INTO C4A
WHERE SPRSL = 'D' AND
ARBGB = '00'.
Select with view
SELECT * FROM DD01L
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
SELECT SINGLE * FROM DD01T
WHERE DOMNAME = DD01L-DOMNAME
AND AS4LOCAL = 'A'
AND AS4VERS = DD01L-AS4VERS
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.
SELECT * FROM DD01V
WHERE DOMNAME LIKE 'CHAR%'
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.
Select with index support
SELECT * FROM T100
WHERE ARBGB = '00'
AND MSGNR = '999'.
ENDSELECT.
SELECT * FROM T002.
SELECT * FROM T100
WHERE SPRSL = T002-SPRAS
AND ARBGB = '00'
AND MSGNR = '999'.
ENDSELECT.
ENDSELECT.
Select Into table
REFRESH X006.
SELECT * FROM T006 INTO X006.
APPEND X006.
ENDSELECT
SELECT * FROM T006 INTO TABLE X006.
Select with selection list
SELECT * FROM DD01L
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
ENDSELECT
SELECT DOMNAME FROM DD01L
INTO DD01L-DOMNAME
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
ENDSELECT
Key access to multiple lines
LOOP AT TAB.
CHECK TAB-K = KVAL.
ENDLOOP.
LOOP AT TAB WHERE K = KVAL.
ENDLOOP.
Copying internal tables
REFRESH TAB_DEST.
LOOP AT TAB_SRC INTO TAB_DEST.
APPEND TAB_DEST.
ENDLOOP.
TAB_DEST[] = TAB_SRC[].
Modifying a set of lines
LOOP AT TAB.
IF TAB-FLAG IS INITIAL.
TAB-FLAG = 'X'.
ENDIF.
MODIFY TAB.
ENDLOOP.
TAB-FLAG = 'X'.
MODIFY TAB TRANSPORTING FLAG
WHERE FLAG IS INITIAL.
Deleting a sequence of lines
DO 101 TIMES.
DELETE TAB_DEST INDEX 450.
ENDDO.
DELETE TAB_DEST FROM 450 TO 550.
Linear search vs. binary
READ TABLE TAB WITH KEY K = 'X'.
READ TABLE TAB WITH KEY K = 'X' BINARY SEARCH.
Comparison of internal tables
DESCRIBE TABLE: TAB1 LINES L1,
TAB2 LINES L2.
IF L1 <> L2.
TAB_DIFFERENT = 'X'.
ELSE.
TAB_DIFFERENT = SPACE.
LOOP
AT TAB1.
READ TABLE TAB2 INDEX SY-TABIX.
IF TAB1 <> TAB2.
TAB_DIFFERENT = 'X'. EXIT.
ENDIF.
ENDLOOP.
ENDIF.
IF TAB_DIFFERENT = SPACE.
ENDIF.
IF TAB1[] = TAB2[].
ENDIF.
Modify selected components
LOOP AT TAB.
TAB-DATE = SY-DATUM.
MODIFY TAB.
ENDLOOP.
WA-DATE = SY-DATUM.
LOOP AT TAB.
MODIFY TAB FROM WA TRANSPORTING DATE.
ENDLOOP.
Appending two internal tables
LOOP AT TAB_SRC.
APPEND TAB_SRC TO TAB_DEST.
ENDLOOP
APPEND LINES OF TAB_SRC TO TAB_DEST.
Deleting a set of lines
LOOP AT TAB_DEST WHERE K = KVAL.
DELETE TAB_DEST.
ENDLOOP
DELETE TAB_DEST WHERE K = KVAL.
Tools available in SAP to pin-point a performance problem
· The runtime analysis (SE30)
· SQL Trace (ST05)
· Tips and Tricks tool
· The performance database
Optimizing the load of the database
Using table buffering
Using buffered tables improves the performance considerably. Note that in some cases a statement can not be used with a buffered table, so when using these statements the buffer will be bypassed. These statements are:
Select DISTINCT
ORDER BY / GROUP BY / HAVING clause
Any WHERE clause that contains a sub query or IS NULL expression
JOIN s
A SELECT... FOR UPDATE
If you wan t to explicitly bypass the buffer, use the BYPASS BUFFER addition to the SELECT clause.
Use the ABAP SORT Clause Instead of ORDER BY
The ORDER BY clause is executed on the database server while the ABAP SORT statement is executed on the application server. The database server will usually be the bottleneck, so sometimes it is better to move the sort from the database server to the application server.
If you are not sorting by the primary key ( E.g. using the ORDER BY PRIMARY key statement) but are sorting by another key, it could be better to use the ABAP SORT statement to sort the data in an internal table. Note however that for very large result sets it might not be a feasible solution and you would want to let the database server sort it.
Avoid the SELECT DISTINCT Statement
As with the ORDER BY clause it could be better to avoid using SELECT DISTINCT, if some of the fields are not part of an index. Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, to delete duplicate rows.
Thanks & regards
Sreenivasulu P -
Can we use is null in our select statement in ABAP program
hi,
I want to use 'is nul' or 'not null' in select statement of my ABAP program for any field. I have written below query but I am getting sy-subrc = 4 and getting no data. Can anyone resolve this.Hi,
I think you've posted your question on the wrong forum. This is the SAP Business One development forum which is not part of ERP and doesn't include any ABAP or Netweaver programming.
For a list of forums please see here:
http://forums.sdn.sap.com/index.jspa
Kind Regards,
Owen -
How to use 'is null' in select statement of ABAP program
hi,
I want to use 'is nul' or 'not null' in select statement of my ABAP program for any field. I have written below query but I am getting sy-subrc = 4 and getting no data.
SELECT * FROM mara INTO TABLE it_mara
WHERE volum IS NULL .
Can anyone resolve this.Hi PKB,
Check the below thread for NULL and Space value in ABAP . It will help you
NULL and Space value in ABAP
Regards,
Pawan -
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 -
ABAP select statements takes too long
Hi,
I have a select statement as shown below.
SELECT * FROM BSEG INTO TABLE ITAB_BSEG
WHERE BUKRS = CO_CODE
AND BELNR IN W_DOCNO
AND GJAHR = THISYEAR
AND AUGBL NE SPACE.
This select statement runs fine in all of R/3 systems except for 1. The problem that is shown with this particular system is that the query takes very long ( up to an hour for if W_DOCNO consists of 5 entries). Sometimes, before the query can complete, an ABAP runtime error is encountered as shown below:
<b>Database error text........: "ORA-01555: snapshot too old: rollback segment
number 7 with name "PRS_5" too small?"
Internal call code.........: "[RSQL/FTCH/BSEG ]"
Please check the entries in the system log (Transaction SM21). </b>
Please help me on this issue. However, do not give me suggestions about selecting from a smaller table (bsik, bsak) as my situation does not permit it.
I will reward points.dont use select * ....
instead u declare ur itab with the required fields and then in select refer to the fields in the select .
data : begin of itab,
f1
f2
f3
f4
end of itab.
select f1 f2 f3 f4 ..
into table itab
from bseg where ...
. this improves the performance .
select * is not advised .
regards,
vijay
Maybe you are looking for
-
Sorry a serious error has occured PE3
I can't get past this message when I either open a new project or a previous one. I have installed the update 3.02 as listed in the PE3 quick tips. The full message continues......that requires PE to shut down. We will attempt to save the current pro
-
My ipad is showing 'Cannot connect to iTunes'
My ipad shows a message 'Cannot connect to iTunes' nd will nit allow me to download apps or app updates. My internet connection is fine.
-
Beginner question: session in JSP
Hello, I'm new in JSP. I'm trying to use session variable in JSP file as shown below and get error "cannot resolve symbol" at session line <% String name = request.getParameter( "username" ); session.setAttribute( "theName", name ); %> <HTML> <BODY>
-
Question about Premiere Elements
I am considering purchasing Premiere Elements but I need to know if one can use it to add effects to an animated gif file. For example, in Photoshop Elements one can add certain effects to a gif image, such as giving it certain textures or filters. C
-
My battery icon does not always show in panel (multiple DEs)
I've been meaning to ask this for a while. I kind of asked in passing not really looking too hard for an answer. And from what I heard others aren't having this issue, but then again I didn't ask very in depth. On my laptop if I plug in my power cabl