What is the use of for all entries in select statement
what is the use of for all entries in select statement
hi,
FOR ALL ENTRIES is an effective way of doing away with using JOIN on two tables.
You can check the below code -
SELECT BUKRS BELNR GJAHR AUGDT
FROM BSEG
INTO TABLE I_BSEG
WHERE BUKRS = ....
SELECT BUKRS BELNR BLART BLDAT
FROM BKPF
INTO TABLE I_BKPF
FOR ALL ENTRIES IN I_BSEG
WHERE BUKRS = I_BSEG-BUKRS
AND BELNR = I_BSEG-BELNR
AND BLDAT IN SO_BLDAT.
*******************************8
look another example
what is the use of FOR ALL ENTRIES
1. INNER JOIN
DBTAB1 <----
> DBTAB2
It is used to JOIN two DATABASE tables
having some COMMON fields.
2. Whereas
For All Entries,
DBTAB1 <----
> ITAB1
is not at all related to two DATABASE tables.
It is related to INTERNAL table.
3. If we want to fetch data
from some DBTABLE1
but we want to fetch
for only some records
which are contained in some internal table,
then we use for alll entries.
1. simple example of for all entries.
2. NOTE THAT
In for all entries,
it is NOT necessary to use TWO DBTABLES.
(as against JOIN)
3. use this program (just copy paste)
it will fetch data
from T001
FOR ONLY TWO COMPANIES (as mentioned in itab)
4
REPORT abc.
DATA : BEGIN OF itab OCCURS 0,
bukrs LIKE t001-bukrs,
END OF itab.
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
itab-bukrs = '1000'.
APPEND itab.
itab-bukrs = '1100'.
APPEND itab.
SELECT * FROM t001
INTO TABLE t001
FOR ALL ENTRIES IN itab
WHERE bukrs = itab-bukrs.
LOOP AT t001.
WRITE :/ t001-bukrs.
ENDLOOP.
Hope this helps!
Regards,
Anver
<i>if hlped pls mark points</i>
Similar Messages
-
What is the usage of for all entries ?
What is the Usage of read table after using for all entries ?
In the following example what exactly it is doing ?
Usage of 'for all entries' in Select Statement
FORM data_retrieval.
DATA: ld_color(1) TYPE c.
DATA: BEGIN OF T_VBAP OCCURS 0,
VBELN LIKE VBAP-VBELN,
MATNR LIKE VBAP-MATNR,
POSNR LIKE VBAP-POSNR,
END OF T_VBAP.
DATA: BEGIN OF T_VBFA OCCURS 0,
VBELV LIKE VBFA-VBELV,
VBELN LIKE VBFA-VBELN,
VBTYP_N LIKE VBFA-VBTYP_N,
END OF T_VBFA.
DATA: BEGIN OF T_VBAK OCCURS 0,
VBELN LIKE VBAK-VBELN,
IHREZ LIKE VBAK-IHREZ,
END OF T_VBAK.
DATA: BEGIN OF T_KNA1 OCCURS 0,
KUNNR LIKE KNA1-KUNNR,
NAME1 LIKE KNA1-NAME1,
END OF T_KNA1.
DATA: BEGIN OF T_MAKT OCCURS 0,
MATNR LIKE MAKT-MATNR,
MAKTX LIKE MAKT-MAKTX,
END OF T_MAKT.
SELECT likpvbeln likplifex likpbldat likpwadat likpwadat_ist likpkodat likp~lfart
likpkunnr likpvstel lipsposnv lipslfimg lipsvrkme lipslgmng lips~meins
lipswerks lipslgort lipscharg lipsvbelv lipsposnr lipsmatnr
lipsvbeln LIPSVGBEL LIPSVGPOS vbupkosta vbupwbsta vbupposnr vbup~vbeln
VBAKIHREZ VBAKVBELN VBAP~VBELN
INTO CORRESPONDING FIELDS OF TABLE it_itab
FROM ( likp
INNER JOIN lips
ON lipsvbeln = likpvbeln
INNER JOIN vbup
ON vbupposnr = lipsposnr
and VBUPVBELN = LIPSVBELN )
left outer join VBAK
on VBAKVBELN = LIPSVGBEL
inner join VBAP
on VBAPVBELN = VBAKVBELN )
WHERE likp~vbeln IN so_vbeln
AND likp~lifex IN so_lifex
AND likp~lfart IN so_lfart
AND likp~kunnr IN so_kunnr
AND likp~vstel IN so_vstel
AND likp~bldat IN so_bldat
AND likp~wadat_ist IN so_wadat
AND vbup~kosta IN so_kosta
AND vbup~wbsta IN so_wbsta
AND LIPS~LFIMG NE 0.
SELECT VBELN IHREZ INTO TABLE T_VBAK
FROM VBAK
FOR ALL ENTRIES IN IT_ITAB
WHERE VBELN = IT_ITAB-VGBEL.
APPEND T_VBAK.
ENDSELECT.
SELECT VBELN MATNR POSNR INTO TABLE T_VBAP
FROM VBAP
FOR ALL ENTRIES IN IT_ITAB
WHERE VBELN = IT_ITAB-VGBEL AND
MATNR = IT_ITAB-MATNR AND
POSNR = IT_ITAB-VGPOS.
APPEND T_VBAP.
ENDSELECT.
SELECT VBELV VBELN VBTYP_N INTO TABLE T_VBFA
FROM VBFA
FOR ALL ENTRIES IN IT_ITAB
WHERE VBELV = IT_ITAB-VBELN AND
VBTYP_N = 'M' .
SELECT KUNNR NAME1 INTO TABLE T_KNA1
FROM KNA1
FOR ALL ENTRIES IN IT_ITAB
WHERE KUNNR = IT_ITAB-KUNNR.
APPEND T_KNA1.
ENDSELECT.
SELECT MATNR MAKTX INTO TABLE T_MAKT
FROM MAKT
FOR ALL ENTRIES IN IT_ITAB
WHERE MATNR = IT_ITAB-MATNR.
APPEND T_MAKT.
ENDSELECT.
*Populate field with color attributes
LOOP AT it_itab INTO wa_ITAB.
Populate color variable with colour properties
Char 1 = C (This is a color property)
Char 2 = 3 (Color codes: 1 - 7)
Char 3 = Intensified on/off ( 1 or 0 )
Char 4 = Inverse display on/off ( 1 or 0 )
i.e. wa_ekko-line_color = 'C410'
REFRESH color.
colourize 'VBELN' 0. " .
WA_ITAB-farbe = color[].
ld_color = ld_color + 1.
Only 7 colours so need to reset color value
IF ld_color = 3. "8
ld_color = 1.
ENDIF.
CONCATENATE 'C' ld_color '10' INTO wa_ITAB-line_color.
WA_ITAB-NAME1 = ''.
WA_ITAB-MAKTX = ''.
WA_ITAB-IHREZ = ''.
WA_ITAB-VBELV = ''.
READ TABLE T_KNA1 WITH KEY KUNNR = WA_ITAB-KUNNR.
IF SY-SUBRC = 0.
WA_ITAB-NAME1 = T_KNA1-NAME1.
ENDIF.
READ TABLE T_MAKT WITH KEY MATNR = WA_ITAB-MATNR.
IF SY-SUBRC = 0.
WA_ITAB-MAKTX = T_MAKT-MAKTX.
ENDIF.
READ TABLE T_VBAK WITH KEY VBELN = WA_ITAB-VGBEL.
IF SY-SUBRC = 0.
WA_ITAB-IHREZ = T_VBAK-IHREZ.
ENDIF.
READ TABLE T_VBFA WITH KEY VBELV = WA_ITAB-VBELN.
IF SY-SUBRC = 0.
WA_ITAB-VBELVA = T_VBFA-VBELN.
ENDIF.
READ TABLE T_VBAP WITH KEY VBELN = WA_ITAB-VGBEL
POSNR = WA_ITAB-VGPOS
MATNR = WA_ITAB-MATNR.
IF SY-SUBRC = 0.
WA_ITAB-IHREZ = T_VBAK-IHREZ.
ENDIF.
wa_ekko-line_color = 'C410'.
MODIFY it_itab FROM wa_itab.
ENDLOOP.
ENDFORM. " data_retrievalhi Jyotirmoy,
The explanation below can give u an idea of wat is going in ur code..
Use of FOR ALL Entries
Outer join can be created using this addition to the where clause in a select statement. It speeds up the performance tremendously, but the cons of using this variation are listed below
Duplicates are automatically removed from the resulting data set. Hence care should be taken that the unique key of the detail line items should be given in the select statement.
If the table on which the For All Entries IN clause is based is empty, all rows are selected into the destination table. Hence it is advisable to check before-hand that the first table is not empty.
If the table on which the For All Entries IN clause is based is very large, the performance will go down instead of improving. Hence attempt should be made to keep the table size to a moderate level.
Not Recommended
Loop at int_cntry.
Select single * from zfligh into int_fligh
where cntry = int_cntry-cntry.
Append int_fligh.
Endloop.
Recommended
Select * from zfligh appending table int_fligh
For all entries in int_cntry
Where cntry = int_cntry-cntry.
Thankyou,
Regards. -
Hi guru's what is the diff between for all entries & joins
hi guru's what is the diff between for all entries & joins
Hi Vasu,
Joins are used to fetch data fast from Database tables:
Tables are joined with the proper key fields to fetch the data properly.
If there are no proper key fields between tables don't use Joins;
Important thing is that don't USE JOINS FOR CLUSTER tableslike BSEG and KONV.
Only use for Transparenmt tables.
You can also use joins for the database VIews to fetch the data.
JOINS
... FROM tabref1 [INNER] JOIN tabref2 ON cond
Effect
The data is to be selected from transparent database tables and/or views determined by tabref1 and tabref2. tabref1 and tabref2 each have the same form as in variant 1 or are themselves Join expressions. The keyword INNER does not have to be specified. The database tables or views determined by tabref1 and tabref2 must be recognized by the ABAP Dictionary.
In a relational data structure, it is quite normal for data that belongs together to be split up across several tables to help the process of standardization (see relational databases). To regroup this information into a database query, you can link tables using the join command. This formulates conditions for the columns in the tables involved. The inner join contains all combinations of lines from the database table determined by tabref1 with lines from the table determined by tabref2, whose values together meet the logical condition (join condition) specified using ON>cond.
Inner join between table 1 and table 2, where column D in both tables in the join condition is set the same:
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
|--||||||||--|
Example
Output a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
DATA: DATE LIKE SFLIGHT-FLDATE,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID.
SELECT FCARRID FCONNID F~FLDATE
INTO (CARRID, CONNID, DATE)
FROM SFLIGHT AS F INNER JOIN SPFLI AS P
ON FCARRID = PCARRID AND
FCONNID = PCONNID
WHERE P~CITYFROM = 'FRANKFURT'
AND P~CITYTO = 'NEW YORK'
AND F~FLDATE BETWEEN '20010910' AND '20010920'
AND FSEATSOCC < FSEATSMAX.
WRITE: / DATE, CARRID, CONNID.
ENDSELECT.
If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or a table alias.
Note
In order to determine the result of a SELECT command where the FROM clause contains a join, the database system first creates a temporary table containing the lines that meet the ON condition. The WHERE condition is then applied to the temporary table. It does not matter in an inner join whether the condition is in the ON or WHEREclause. The following example returns the same solution as the previous one.
Example
Output of a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
DATA: DATE LIKE SFLIGHT-FLDATE,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID.
SELECT FCARRID FCONNID F~FLDATE
INTO (CARRID, CONNID, DATE)
FROM SFLIGHT AS F INNER JOIN SPFLI AS P
ON FCARRID = PCARRID
WHERE FCONNID = PCONNID
AND P~CITYFROM = 'FRANKFURT'
AND P~CITYTO = 'NEW YORK'
AND F~FLDATE BETWEEN '20010910' AND '20010920'
AND FSEATSOCC < FSEATSMAX.
WRITE: / DATE, CARRID, CONNID.
ENDSELECT.
Note
Since not all of the database systems supported by SAP use the standard syntax for ON conditions, the syntax has been restricted. It only allows those joins that produce the same results on all of the supported database systems:
Only a table or view may appear to the right of the JOIN operator, not another join expression.
Only AND is possible in the ON condition as a logical operator.
Each comparison in the ON condition must contain a field from the right-hand table.
If an outer join occurs in the FROM clause, all the ON conditions must contain at least one "real" JOIN condition (a condition that contains a field from tabref1 amd a field from tabref2.
Note
In some cases, '*' may be specified in the SELECT clause, and an internal table or work area is entered into the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the FROM clause, according to the structure of each table work area. There can then be gaps between table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, not simply by counting the total number of fields. For an example, see below:
Variant 3
... FROM tabref1 LEFT [OUTER] JOIN tabref2 ON cond
Effect
Selects the data from the transparent database tables and/or views specified in tabref1 and tabref2. tabref1 und tabref2 both have either the same form as in variant 1 or are themselves join expressions. The keyword OUTER can be omitted. The database tables or views specified in tabref1 and tabref2 must be recognized by the ABAP-Dictionary.
In order to determine the result of a SELECT command where the FROM clause contains a left outer join, the database system creates a temporary table containing the lines that meet the ON condition. The remaining fields from the left-hand table (tabref1) are then added to this table, and their corresponding fields from the right-hand table are filled with ZERO values. The system then applies the WHERE condition to the table.
Left outer join between table 1 and table 2 where column D in both tables set the join condition:
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
|--||||||||--|
Example
Output a list of all custimers with their bookings for October 15th, 2001:
DATA: CUSTOMER TYPE SCUSTOM,
BOOKING TYPE SBOOK.
SELECT SCUSTOMNAME SCUSTOMPOSTCODE SCUSTOM~CITY
SBOOKFLDATE SBOOKCARRID SBOOKCONNID SBOOKBOOKID
INTO (CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID)
FROM SCUSTOM LEFT OUTER JOIN SBOOK
ON SCUSTOMID = SBOOKCUSTOMID AND
SBOOK~FLDATE = '20011015'
ORDER BY SCUSTOMNAME SBOOKFLDATE.
WRITE: / CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID.
ENDSELECT.
If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or using an alias.
Note
For the resulting set of a SELECT command with a left outer join in the FROM clause, it is generally of crucial importance whether a logical condition is in the ON or WHERE condition. Since not all of the database systems supported by SAP themselves support the standard syntax and semantics of the left outer join, the syntax has been restricted to those cases that return the same solution in all database systems:
Only a table or view may come after the JOIN operator, not another join statement.
The only logical operator allowed in the ON condition is AND.
Each comparison in the ON condition must contain a field from the right-hand table.
Comparisons in the WHERE condition must not contain a field from the right-hand table.
The ON condition must contain at least one "real" JOIN condition (a condition in which a field from tabref1 as well as from tabref2 occurs).
Note
In some cases, '*' may be specivied as the field list in the SELECT clause, and an internal table or work area is entered in the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the llen in der FROM clause, according to the structure of each table work area. There can be gaps between the table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, as in the following example (not simply by counting the total number of fields).
Example
Example of a JOIN with more than two tables: Select all flights from Frankfurt to New York between September 10th and 20th, 2001 where there are available places, and display the name of the airline.
DATA: BEGIN OF WA,
FLIGHT TYPE SFLIGHT,
PFLI TYPE SPFLI,
CARR TYPE SCARR,
END OF WA.
SELECT * INTO WA
FROM ( SFLIGHT AS F INNER JOIN SPFLI AS P
ON FCARRID = PCARRID AND
FCONNID = PCONNID )
INNER JOIN SCARR AS C
ON FCARRID = CCARRID
WHERE P~CITYFROM = 'FRANKFURT'
AND P~CITYTO = 'NEW YORK'
AND F~FLDATE BETWEEN '20010910' AND '20010920'
AND FSEATSOCC < FSEATSMAX.
WRITE: / WA-CARR-CARRNAME, WA-FLIGHT-FLDATE, WA-FLIGHT-CARRID,
WA-FLIGHT-CONNID.
ENDSELECT.
And for all entries,
this will help u.
use of FOR ALL ENTRIES:
1. INNER JOIN
DBTAB1 <----
> DBTAB2
It is used to JOIN two DATABASE tables
having some COMMON fields.
2. Whereas
For All Entries,
DBTAB1 <----
> ITAB1
is not at all related to two DATABASE tables.
It is related to INTERNAL table.
3. If we want to fetch data
from some DBTABLE1
but we want to fetch
for only some records
which are contained in some internal table,
then we use for alll entries.
1. simple example of for all entries.
2. NOTE THAT
In for all entries,
it is NOT necessary to use TWO DBTABLES.
(as against JOIN)
3. use this program (just copy paste)
it will fetch data
from T001
FOR ONLY TWO COMPANIES (as mentioned in itab)
4
REPORT abc.
DATA : BEGIN OF itab OCCURS 0,
bukrs LIKE t001-bukrs,
END OF itab.
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
itab-bukrs = '1000'.
APPEND itab.
itab-bukrs = '1100'.
APPEND itab.
SELECT * FROM t001
INTO TABLE t001
FOR ALL ENTRIES IN itab
WHERE bukrs = itab-bukrs.
LOOP AT t001.
WRITE :/ t001-bukrs.
ENDLOOP.
cheers,
Hema. -
What is the use of FOR ALL ?
What is the use of FOR ALL ?. Need clear explanation with examples
http://www.oracle.com/pls/db112/portal.portal_db?selected=5&frame=#sql_and_pl_sql_languages
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/tuning.htm#i48876
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/tuning.htm#i54218
Straight SQL operations are faster, but if you can't write those for some reason bulk operations are not quite as slow as PL/SQL loops. -
'FOR ALL ENTRIES' in SELECT statements
Hi,
I got a doubt in working of the 'FOR ALL ENTRIES' option in the SELECT statement. Here is my scenarion.
Table A - Document Header Level (Key: Doc Number)
Internal Table B - Document Item level (Keys: Doc num and Doc Item).
So, for each record in Table A, table B will have multiple records.
In this situation, how the below SELECT will work.
SELECT <field names> INTO <some internal table>
FROM A
FOR ALL ENTRIES in B
WHERE doc_num = B-doc_num.
Will the above SELECT result in duplicate records or not?
(I tested it and found that it doesn't! I was lil surprised and wanted to confirm that)
Thanks & Regards,
SreeHi,
For all entries option basically sorts out the entries in the internal tbale based on the where condition and thus it only picks the unique entries based on the list.
so indeed your table A is a header one so it will give you only single value. if you go by the reverse way where in look for B for all entries in A it will give you multiple values as table B has multiple values for each value in A.
Regards,
Jagath -
Duplicate entries missing using for all entries in select query.
Hi Gurus,
Is there any way to avoid missing duplicate entries in an internal table if you use for all entries in select statement?
Note : i am selecting two tables using non key fields and i have to aggregate the data. I want only 2 data fields and one amount field in my final internal table. I can add all the primary key fields into my internal table and collect my required fields in another table, but I just want to know is there any other way to avoid missing duplicate entries without adding all the key fields?
Regards,
RaghavendraHi,
Just check what are the other possible fields in the table which may be having
duplicate entries and make use of them in the selection accordingly.
You may not miss any entries unless there is any restriction on them.
You can better judge that in debugging mode while selecting data from that table. -
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 -
Use of for all entries in abap
Please tell me how to use "for all entries" in linking two
tables for retrieve informations by using corresponding fields in both the tables.plz send the codings.REPORT YVCHIERSEQ .
TYPE-POOLS:SLIS.
DATA:T_VBAK TYPE STANDARD TABLE OF VBAK INITIAL SIZE 0,
T_VBAP TYPE STANDARD TABLE OF VBAP INITIAL SIZE 0,
W_VBAK TYPE VBAK,
W_VBAP TYPE VBAP,
G_VBELN TYPE VBAK-VBELN,
W_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
W_KEYINFO TYPE SLIS_KEYINFO_ALV.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS:S_VBELN FOR G_VBELN.
SELECTION-SCREEN END OF BLOCK B1.
INITIALIZATION.
CLEAR:W_VBAK,
W_VBAP.
REFRESH:T_VBAK,
T_VBAP.
START-OF-SELECTION.
PERFORM SUB_GET_VBAK.
PERFORM SUB_GET_VBAP.
PERFORM SUB_DISP_OUTPUT.
FORM SUB_GET_VBAK.
SELECT * FROM VBAK INTO TABLE T_VBAK WHERE VBELN IN S_VBELN.
ENDFORM.
FORM SUB_GET_VBAP.
SELECT * FROM VBAP INTO TABLE T_VBAP FOR ALL ENTRIES IN T_VBAK WHERE
VBELN = T_VBAK-VBELN.
ENDFORM.
FORM SUB_DISP_OUTPUT.
W_FIELDCAT-COL_POS = 1.
W_FIELDCAT-FIELDNAME = 'VBELN'.
W_FIELDCAT-SELTEXT_M = 'SALESORDER'.
W_FIELDCAT-TABNAME = 'VBAK'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 2.
W_FIELDCAT-FIELDNAME = 'ERNAM'.
W_FIELDCAT-SELTEXT_M = 'NAME'.
W_FIELDCAT-TABNAME = 'VBAK'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 3.
W_FIELDCAT-FIELDNAME = 'VBTYP'.
W_FIELDCAT-SELTEXT_M = 'SD CATEGORY'.
W_FIELDCAT-TABNAME = 'VBAK'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 4.
W_FIELDCAT-FIELDNAME = 'KUNNR'.
W_FIELDCAT-SELTEXT_M = 'SOLD TO PARTY'.
W_FIELDCAT-TABNAME = 'VBAK'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 5.
W_FIELDCAT-FIELDNAME = 'NETWR'.
W_FIELDCAT-SELTEXT_M = 'NET VALUE'.
W_FIELDCAT-TABNAME = 'VBAK'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 1.
W_FIELDCAT-FIELDNAME = 'POSNR'.
W_FIELDCAT-SELTEXT_M = 'SALES ITEM'.
W_FIELDCAT-TABNAME = 'VBAP'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 2.
W_FIELDCAT-FIELDNAME = 'MATNR'.
W_FIELDCAT-SELTEXT_M = 'MATERIAL NO'.
W_FIELDCAT-TABNAME = 'VBAP'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 3.
W_FIELDCAT-FIELDNAME = 'MATKL'.
W_FIELDCAT-SELTEXT_M = 'MAT GROUP'.
W_FIELDCAT-TABNAME = 'VBAP'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_FIELDCAT-COL_POS = 4.
W_FIELDCAT-FIELDNAME = 'NETWR'.
W_FIELDCAT-SELTEXT_M = 'NET VALUE'.
W_FIELDCAT-TABNAME = 'VBAP'.
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.
W_KEYINFO-HEADER01 = 'VBELN'.
W_KEYINFO-ITEM01 = 'VBELN'.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_CALLBACK_PROGRAM = SY-CPROG
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
IS_LAYOUT =
IT_FIELDCAT = T_FIELDCAT
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
i_tabname_header = 'VBAK'
i_tabname_item = 'VBAP'
I_STRUCTURE_NAME_HEADER =
I_STRUCTURE_NAME_ITEM =
is_keyinfo = W_KEYINFO
IS_PRINT =
IS_REPREP_ID =
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
tables
t_outtab_header = T_VBAK
t_outtab_item = T_VBAP
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. -
HOW TO PRINT THE MATTER IN FOR ALL ENTRIES
HI HOW T PRINT THE FOR ALL ENTRIES MATTER
Hi Naresh,
You can only use FOR ALL ENTRIES IN ...WHERE ...in a SELECT statement.
SELECT ... FOR ALL ENTRIES IN itab WHERE cond returns the union of the solution sets of all SELECT statements that would result if you wrote a separate statement for each line of the internal table replacing the symbol itab-f with the corresponding value of component f in the WHERE condition.Duplicates are discarded from the result set. If the internal table itab does not contain any entries, the system treats the statement as though there were no WHERE cond condition, and selects all records (in the current client).
For example:
SELECT * FROM sflight INTO wa_sflight
FOR ALL ENTRIES IN ftab
WHERE CARRID = ftab-carrid AND
CONNID = ftab-connid AND
fldate = '20010228'.
This condition, return all entries of the sflight.
When using FOR ALL ENTRIES the number of matching records is restricted to the number of records in the internal table. If the number of records in the database tables is too large then join would cause overheads in performance. Additionally a JOIN bypasses the table buffering.
Thanks,
Reward If Helpful. -
For all entries in read statement
hi
is there any command equivalent to for all entries in read statementHi,
You have to use Loop at...and move the values from the it_vbrp to the final internal table..
Example
LOOP AT IT_OUTPUT.
MOVE-CORRESPONDING IT_OUTPUT TO IT_FINAL.
LOOP AT IT_VBRP WHERE AUBEL = IT_OUTPUT-VBELN
AND AUPOS = IT_OUTPUT-POSNR.
MOVE-CORRESPONDING IT_VBRP TO IT_FINAL.
APPEND IT_FINAL.
ENDLOOP.
IF SY-SUBRC <> 0.
APPEND IT_FINAL.
ENDIF.
ENDLOOP.
Thanks,
Naren -
For all entries in select query
Hi Guys,
I am fetching the BUKRS GJAHR BELNR and BUZEI from BSEG table, using for all entires of BSEG data, i am getting the data from BSID table.
But in BSID table, i have duplicate records, those records i am not able to get.
Could you please suggest me, is any wrong in my code. Please sugest is any other way to get the data.
SELECT bukrs
belnr
gjahr
buzei
xref1 INTO TABLE it_bseg
FROM bseg
WHERE bukrs = p_bukrs
AND gjahr IN s_gjahr
AND xref1 IN s_xref1.
SORT it_bseg BY bukrs gjahr belnr buzei.
SELECT bukrs
kunnr
zuonr
gjahr
belnr
budat
bldat
xblnr
blart
dmbtr
shkzg INTO TABLE it_bsid
FROM bsid
FOR ALL ENTRIES IN it_bseg
WHERE bukrs = it_bseg-bukrs
AND belnr = it_bseg-belnr
AND gjahr = it_bseg-gjahr
AND buzei = it_bseg-buzei
AND blart IN r_blart.
Thanks
Gourisankar.Hi Sankar,
if there are duplicates entries select statement will omit those records. try to include fields in the select statement which makes the selected record different from other atleast by one field.
cheers!! -
Usage of FOR ALL ENTRIES in SELECT query
Hi All,
While writing SELECT query using FOR ALL ENTRIES, in the WHERE condition can we use IN operator on a range table?
Will this work out.
Thanks,
Anil KumarHI,
Yes you can use the in operator.
SELECT *
FROM MARC
INTO TAB:E i_mARC
FOR ALL ENTRIES IN I_MARA
WHERE MATNR EQ I_MARA_MATNR
AND WERKS IN S_WERKS. -
Want to Avoid Loop for all entries with select query !!
Hi Guru's !
This is my following code . I want to avoid loop to improve the performance of program.
data: lt_cuhd type HASHED TABLE OF /sapsll/cuhd WITH UNIQUE key guid_cuhd,
ls_cuhd type /sapsll/cuhd.
data: lt_comments type STANDARD TABLE OF zss_comments,
ls_comments type zss_comments.
data: lv_objkey type string.
select * from /sapsll/cuhd into table lt_cuhd.
loop at lt_cuhd into ls_cuhd.
CONCATENATE ls_cuhd-corder '%' into lv_objkey. " Example 'Mum%'
select * from zss_comments into table lt_comments
where objkey like lv_objkey
AND guid_cuhd = ls_cuhd-guid_cuhd
AND event_id <> ''.
endloop.
I want
New code should be...using all entries no loop required.
*select * from zss_comments into table lt_comments
where objkey like lv_objkey
AND guid_cuhd = ls_cuhd-guid_cuhd
AND event_id <> ''.*why dont you add the object key also to lt_cuhd and once you fetch the data to lt_cuhd loop it and add the '%'
when looping use field symbols so that you dont have to use modify.
then use for all entries using lt_cuhd
i don't you can find a better way to add the % mark apart from looping but by this way only one select query will be done for
zss_comments
Thanks
Nafran -
Problem with for all entries in select querry
hi,
Hi,
I am using select queery like this
SELECT version COUNT( * )
from ztbi_default_va4
INTO CORRESPONDING FIELDS OF TABLE lit_new
FOR ALL ENTRIES IN lit_new1
WHERE network = lit_new1-network GROUP BY version.
this is not working showing error as:
The addition "FOR ALL ENTRIES" excludes all aggregate functions with
the exception of "COUNT( * )" as the single element of the SELECT clause.
I am using only count(*) ,not using othes like max,min etc,,,,,,,,,
please suggest any missing in syntax,,,,attach relavant code using count(*) with for all entreis
any help appriciated,,,,,
Thanks in advance,,,,Hi,
Try this -
TYPES: begin of t_data,
version TYPE version,
count type i,
end of t_data.
DATA: i_data TYPE STANDARD TABLE OF t_data,
wa_data TYPE t_data.
DATA: l_version TYPE version,
l_count TYPE i.
SELECT version COUNT( * )
from ztbi_default_va4
INTO CORRESPONDING FIELDS OF TABLE lit_new
FOR ALL ENTRIES IN lit_new1
WHERE network = lit_new1-network.
SORT lit_new.
LOOP AT lit_new INTO lwa_new.
IF lwa_new EQ l_version.
l_count = l_count + 1.
ELSE.
wa_data-version = l_version.
wa_data-count = l_count + 1.
APPEND wa_data TO i_data.
CLEAR: wa_data.
CLEAR: l_count.
ENDIF.
l_version = lwa_new-version.
CLEAR: lwa_new.
I hope this will do.
Make any necessary changes.
Regards,
Harsh Bansal -
What is the correct Procedure for all of this?
I'm on a Mac with latest Mavericks OS and Latest Aperture 3.5.1
I moved around a lot of Projects and added to them and deleted some.
I want to replace my Photo internal hard drive with a new one
I want to replace my external hared drive that has my Vault on it that is now too small with a 1TB hard drive.
I haven't done anything with the library like restoring it and done nothing with the Vault since my current external hard drive is now too small. One big mistake I made was I have a folder with folders in it on my desktop 37 GB of images That I added to Aperture If I now drag that folder and all it's internal folders to my Photography internal hard drive will the link to them be broken?
I would also like to rename my Vault and Library since they have old dates in there name.
Thank YouOne big mistake I made was I have a folder with folders in it on my desktop 37 GB of images That I added to Aperture If I now drag that folder and all it's internal folders to my Photography internal hard drive will the link to them be broken?
Have imported that folder to Aperture as referenced images? Then don't move the images in this folder using the Finder, but let Aperture relocate the original image files in this folder to your new drive. Select all referenced images in Aperture in the browser and use the command "File > Relocate Originals" and select a destination folder on your new drive.
See this manual page: Working with Referenced Images
To move the library itself, just drag it to the new drive and then double click the copy to open it in Aperture.
As to the vault - it is essentially an aperture library, but it might be easier to let Aperture create a new vault on a replacement drive, then to copy the vault over.
-- Léonie
Maybe you are looking for
-
I have an example below using a simple gui that has print function in it. The aim of the program is when the user clicks on the print button that they can call p the print and print waht ever is in the text area. I'm not sure if i'm in the right foru
-
TCP active open: Failed gethostbyname() ?
Cannot send mail to outside,but my dns is ok. 18-Jun-2005 08:43:56.87 tcp_local Q 1 [email protected] rfc822;[email protected] [email protected] TCP active open: Failed gethostbyname() on mta.21cn.com, resolver errno = 2 # nslookup -type=mx 21cn.com
-
Changing of Item category in bom after being set at once
how can i changethe item category of item in bom while it has been ones used
-
I am trying to edit phots from Aperture in Photoshop. When the photo is back in Aperture as a psd file it does not apprear. Message of unsupported format appears. Does anyone have a list of supported formats? psd, tif, pdf all seem to be unsupport
-
Connecting to a non-oracle database (jdbc) from a java stored procedure
Does anyone know to configure the database to allow a connection to a non-oracle database from a Java Stored procedured, using JDBC? Thank you in advance, Chris