Does 'For All Entries in itab' work exactly like 'Join' statement?
Hi,
I would like to know that if 'For All Entries in itab' work exactly like 'Join' statement?
If yes, then when I use 'For All Entries in itab' and a 'Join' statement seperately with the same logical conditions for both, the number of records returned by the two methods are not same. Ideally, they should both return the same number of recs.
Can somebody help?
With regards.
Hi,
for all entries will not work in the same way unless untill it should satisfy some conditions,
it has some pre-requisests...
like in the select clause or in where clause or in both the cluases, there should be entire key..
then only it will behave like the join statement..
hope i am clear.
please revert back if u have any quiries.
Regards,
Sunil Kumar Mutyala.
Similar Messages
-
Error - for all entries in itab
Hello guys !!!
I have the following select queries....
select * from vbrp into table itab.
select * from vbpa into table i_vbpa for all entries in itab
where VBELN = itab-vbeln and ( PARVW = 'Z2' or PARVW = 'Z3').
select belnr awkey from bkpf into table i_bkpf2 for all entries in itab where xblnr = itab-vbeln.
I get the following error in 3rd select query.....
When you use the addition "FOR ALL ENTRIES IN itab", the fields "XBLNR"
and "ITAB-VBELN" must have the same type and the same length.
But if i try to change the data type of the field ITAB-VBELN to - " VBELN(16) TYPE C " then i get the following error....
When you use the addition "FOR ALL ENTRIES IN itab", the fields "VBELN"
and "ITAB-VBELN" must have the same type and the same length.
How to i solve this problem ?????Hi,
This is because XBLNR is 16 char length and VBELN is of 10.
So before passing itab to 3 query;
select belnr awkey from bkpf into table i_bkpf2 for all entries in itab where xblnr = itab-vbeln.
Create an intermediate itab with structure of vbeln with length 16 and transfer all data to this itab.
Then do as;
select belnr awkey from bkpf into table i_bkpf2 for all entries in itab where xblnr = itab1-vbeln.
Since you are using only vbeln in for all entries its even enough for the intermediate itab to have only one field to hold the values of VBELN. But you should add leading zeroes( by CONVERSION_EXIT_ALPHA_INPUT) before passing it in the query.
Regards
Karthik D -
For all entries in itab.....
Hi experts..
i hv select query which looks like this...
<b>select field1 field2 into (itab-field1, itab-field2) from dbtab1
where field1 in s_field1.</b>
The problem is i hv to add another code
<b>"for all entries in itab2
where field2 = itab2-field2"</b>
to this select query..
please advice how i can do this.....
Thanks in advance..
-Pranati..Hi,
In the following piece of code,
select field1 field2 into (itab-field1, itab-field2) from dbtab1
for all entries in itab2
where field1 in s_field1
and field2 = itab2-field2.
change this to:
data: begin of itab1 occurs 0,
field1 like dbtab1-field1,
field2 like dbtab1-field2,
end of itab1.
select field1 field2 into table itab1 from dbtab1
for all entries in itab2
where field1 in s_field1
and field2 = itab2-field2.
Hope this works.
Regards
Subramanian -
"For All Entries in ITAB" -error
Hello!
I am new to this ABAP. I getting one error in Select query "For All Entries" keyword. My problem is,
Iam taking vbeln field from the table LIPS and stored in internal table it_lips. and then based on this vbeln i am taking the material document no. field mblnr from MKPF table. The Common field present in this table is vbeln in LIPS and xblnr in MKPF.
my select query is,
select xblnr mblnr
into corresponding fields of table it_mkpf
from mkpf
for all entries in it_lips
where xblnr = it_lips-vbeln
and blart = 'WL'.Hi,
Use the below logic:
TYPES: BEGIN OF ty_mkpf,
mblnr TYPE mblnr,
xblnr TYPE xblnr1,
END OF ty_mkpf.
TYPES: BEGIN OF ty_lips,
vbeln TYPE vbeln_vl,
vbeln1 TYPE xblnr1,
END OF ty_lips.
DATA: git_mkpf TYPE STANDARD TABLE OF ty_mkpf,
git_lips TYPE STANDARD TABLE OF ty_lips.
DATA: gwa_lips TYPE ty_lips.
SELECT vbeln FROM lips INTO TABLE git_lips
UP TO 5 ROWS.
LOOP AT git_lips INTO gwa_lips.
gwa_lips-vbeln1 = gwa_lips-vbeln.
MODIFY git_lips FROM gwa_lips.
ENDLOOP.
SELECT mblnr xblnr
INTO TABLE git_mkpf
FROM mkpf
FOR ALL ENTRIES IN git_lips
WHERE xblnr = git_lips-vbeln1
AND blart = 'WL'. -
The select with for all entries is not working correctly
IF NOT i_ekko_ekpo[] IS INITIAL.
SELECT ebeln
ebelp
zekkn
vgabe
bewtp
menge
bpmng
shkzg
INTO TABLE i_ekbe
FROM ekbe
FOR ALL ENTRIES IN i_ekko_ekpo
WHERE ebeln EQ i_ekko_ekpo-ebeln.
AND ebelp EQ i_ekko_ekpo-ebelp.
IF sy-subrc EQ 0.
SORT i_ekbe.
ENDIF.
ENDIF.
I have a PO with 2 line items in i_ekko_ekpo. In EKBE, I have 49 recs for this PO and this select is returning only 13 recs.
I tried by commenting EBELP and still the same result.
Thanks
Kiran
Edited by: kiran dasari on May 22, 2009 9:56 PMHi Sudhi, I added these now but still no charm
SELECT ebeln
ebelp
zekkn
vgabe
bewtp
menge
bpmng
shkzg
INTO TABLE i_ekbe
FROM ekbe
FOR ALL ENTRIES IN i_ekko_ekpo
WHERE ebeln EQ i_ekko_ekpo-ebeln
AND ebelp EQ i_ekko_ekpo-ebelp
AND zekkn GE '00'
AND vgabe IN ('1','2').
And as per your note: in the 13 entries, am having duplicate also. This is something weird for me now.
Any more clues.
Thanks
Kiran -
About for all entries in itab usage issue
hi
i will get a lot of material information first.
the next i will get inforamtion about table MARC AND MBEW.
one statement i use sap function to get MARC:
CALL FUNCTION 'MARC_ARRAY_READ'
EXPORTING
KZRFB = ' '
NEUFLAG = ' '
SPERRMODUS = ' '
STD_SPERRMODUS = ' '
EXCEPTION_ON_LOCK = ' '
IMPORTING
RETC = ret
TABLES
IPRE01 = ipre
MARC_TAB = disp
EXCEPTIONS
ENQUEUE_MODE_CHANGED = 1
LOCK_ON_MARC = 2
LOCK_SYSTEM_ERROR = 3
OTHERS = 4.
two statement if i use:
select matnr dispo ekgrp plifz
into table disp
from marc
for all entries in ipre
where werks = ipre-werks and
matnr = ipre-matnr.
which one will get better performce.
and
if ipre table have a lot of data, so in sap what about for all entries of Limit?
and will lose data to use for all entries of statements?
have function in sap to get data like 'MARC_ARRAY_READ' about MEBW.
THANK YOU!thank you!
what about for all entries of Limit?
and will lose data to use for all entries of statements?
exist function about get MEBW ARRAY?? -
For All Entries is NOT better than INNER JOIN in most cases
I quote from Siegfried Boes' excellent post here: Will writing an inner join be better or creating a view?
For all the FOR ALL ENTRIES lovers ... there is no proof for these reappearing recommendation.
There is nearly nobody who receives forum points, who recommends FOR ALL ENTRIES instead of Joins. What is the reason ???
It is easier to prove the opposite. A Join is a nested loop inside the database, a FOR ALL ENTRIES is partly outside of the database. FOR ALL ENTRIES works in blocks, joins on totals.
FOR ALL ENTRIES are not recommded on really large tables, because the chances are too high that
too many records are transferred.
People prefer FOR ALL ENTRIES, because JOINs are not so easy to understand. Joins can go wrong, but with a bit of understanding they can be fixed.
Some Joins are slow and can not be fixed, but then the FOR ALL ENTRIES would be extremely slow.
There are several kinds of views:
- projection views, i.e. only one table involved just fields reduced
- join views, several tables, joins conditions stored in dictionary
- materialized views, here the joined data are actually stored in the database. Storing and synchronisation has to be done manually.
Only the last one creates real overhead. It should be the exception.
Join Views and Joins are nearly identical. The view is better for reuse. The join is better in complicated, becuase if the access goes wrong, it can often be fixed by adding a hint. Hints can not be added to views.
Abraham Bukit points out:
If it is cluster table, (you can't use join). If it is buffered table, I would also say avoid join.
If they all are transaction table which are not buffered and are not cluster tables.
He further supports Siegfried's statement that FAE is easier to undestand than INNER JOINs.
Thomas Zloch says, regarding buffered tables:
At least think twice, maybe compare runtimes if in doubt.
So, unless someone has some EVIDENCE that FOR ALL ENTRIES is better, I don't think we want to see this discussed further.
Kind regards
MattTo give food for thought here's an example I gave in a thread:
If you have a statement like
SELECT ... FOR ALL ENTRIES IN FAE_itab WHERE f = FAE_itab-f.
SAP sends it to the database depending how the parameter rsdb/prefer_union_all is set:
rsdb/prefer_union_all = 0 =>
SELECT ... WHERE f = FAE_itab[1]-f
OR f = FAE_itab[2]-f
OR f = FAE_itab[N]-f
You have some influence of the generated statement type: Instead of OR'ed fields an IN list can be used
if you have only a single coulmn N to compare:
rsdb/prefer_in_itab_opt parameter:
SELECT ... WHERE f IN (itab[1]-f, itab[2]-f, ..., itab[N]-f)
rsdb/prefer_union_all = 1 =>
SELECT ... WHERE f = FAE_itab[1]-f
UNION ALL SELECT ... WHERE f = FAE_itab[2]-f
UNION ALL SELECT ... WHERE f = FAE_itab[N]-f
see: Note 48230 - Parameters for the SELECT ... FOR ALL ENTRIES statement
As you can see for the 2nd parameter several statements are generated and combined with a UNION ALL,
the first setting generates statements with OR's (or uses IN if possible) for the entries in FAE_itab.
I give you a little example here (my parameters are set in a way that the OR's are translated to IN lists; i traced the execution in ST05)
Select myid into table t_tabcount from mydbtable
for all entries in t_table " 484 entries
where myid = t_table-myid .
ST05 trace:
|Transaction SEU_INT|Work process no 0|Proc.type DIA|Client 200|User |
|Duration |Obj. name |Op. |Recs.|RC |Statement|
| 640|mydbtable |PREPARE| | 0|SELECT WHERE "myid" IN ( :A0 , :A1 , :A2 , :A3 , :A4 ) AND "myid" = :A5|
| 2|mydbtable |OPEN | | 0|SELECT WHERE "myid" IN ( 1 , 2 , 3 , 4 , 5 ) AND "myid" = 72 |
| 2.536|mydbtable |FETCH | 0| 1403| |
| 3|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 6 , 7 , 8 , 9 , 10 ) AND "myid" = 72 |
| 118|mydbtable |FETCH | 0| |
| 2|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 11 , 12 , 13 , 14 , 15 ) AND "myid" = 72 |
| 3|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 475 , 476 , 477 , 478 , 479 ) AND "myid" = 72 |
| 94|mydbtable |FETCH | 0| 1403| |
| 2|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 480 , 481 , 482 , 483 , 484 ) AND "myid" = 72 |
You see the IN list contained 5 entries each , wich made up about 97 statements for all 484 entries.
For every statment you have a single fetch operation wich means a separate access to the database.
If you would replace the FAE with a join you would only have one fetch to the database.
With the example above we can derive these observations:
1. From database point of view these settings kill performance when you access a big table and/or have a lot of entries or columns in your FAE_itab. Furthermore, you hide information what data you will access
at all and thus you block the database from creating a more efficient execution plan because it DOESN'T KNOW wich data you will select in the next step. I.e. it may be more efficient to scan the table in one shot instead of having many index accesses - but the database can make this decision only if it can examine ONE statement that has ALL the information of what data to retrieve.
2. A second impact is that with every statement execution you trigger the allocation of database resources
wich will contribute to the overhead described above.
Said that, FAE can never be a replacement for joining big tables (think of having a table with thousands of records in a FAE table )
Edited by: kishan P on Nov 2, 2010 2:16 PM - Format Fixed -
Like operator in for all entries
hi all,
may i know how to apply like for "for all entries"
where the first position is 9.
syntax is incorrect. hope can get help.
thanks
CONCATENATE itab-xx+0(1) '%' INTO v_kstar.
SELECT kstar txt20 INTO TABLE it_act
FROM aaa
FOR ALL ENTRIES IN itab
WHERE kstar like v_kstar AND
spras = sy-langu.in that case u have to call with in loop itself, may be there is another way also.
do v_times times
varying v_name
from dept-dept01
next dept-dept02.
concatenate p_rprctr '%' v_name into v_dep.
concatenate '%' v_name into v_dep.
select single mctxt into v_txt
from cskt
where cskt~spras = 'EN'
and cskt~kokrs = 'PEPS'
and cskt~kostl like v_dep
and cskt~datbi eq '99991231'.
concatenate v_txt '-' v_name into v_txt.
write: (47) v_txt centered no-gap ,
sy-vline no-gap .
hide v_name.
clear v_dep.
enddo.
its not a complete code , just a sample code.
Regards
Prabhu -
Select query like For all Entries
Hi,
I have a requirement like:
I need to extract data (BKTXT) from table BKPF based on some criteria, into one internal table and I need to query on REGUP table for the above data, the selection criteria on REGUP as follows:
BKTXT(Document Header Text with 25 Char) is a combination of DATE and character string.
Ex: bkpf-bktxt = 20060710-PL02 (YYYYMMDD)
it is like LAUFD + LAUFI (of table REGUP)
i.e: LAUFD (REGUP) = 07/10/2006 (MM/DD/YYYY) and LAUFI(REGUP) = PL02
here I am thinking to use a select query on REGUP using FOR ALL ENTRIES of table i_bkpf..
How can I change the date format YYYYMMDD to MM/DD/YYYY for my requirement?
(( Run-on Date (REGUP-LAUFD) = the first 8 characters in the Document Header Text (BKPF- BKTXT) in MM/DD/YYYY date format (e.g. 07/10/2006)
Run ID (REGUP-LAUFI) = the 10th character through the 15th character in the Document Header Text (BKPF- BKTXT)It is not possible to do in the way you are thinking of doing. "For all entries" requires you to have the itab table field and the database table field to have the same type and length. So something like below <u>will not work</u>.
TABLES: regup.
DATA: BEGIN OF itab OCCURS 0,
text LIKE bkpf-bktxt.
DATA: END OF itab.
DATA: BEGIN OF itab_regup OCCURS 0.
INCLUDE STRUCTURE regup.
DATA: END OF itab_regup.
SELECT * INTO TABLE itab_regup
FROM regup FOR ALL ENTRIES IN itab
WHERE laufd = itab-text+0(8).
If you run this code, you will get an error as follows:
<i>"When using the addition "FOR ALL ENTRIES IN itab", the fields "LAUFD" and "ITAB-TEXT+0(8)" must have the same type and length."</i> -
For all entries.. with agregate functions....help
Hi ppl,
I want to put this select query outside loop using for all entries but it doesnt support group by neither aggregate funstions like sum.
its not giving correct results if i use collect or sum even using control break statements .
plz help..
LOOP AT T_UNITS.
V_TABIX = SY-TABIX.
get GLPCA postings
SELECT AWTYP AWORG RACCT REFDOCNR SUM( HSL ) FROM GLPCA "1062
INTO TABLE T_GLPCA
WHERE RPRCTR = T_UNITS-UNIT
AND RACCT IN S_HKONT
AND KOKRS = V_KOKRS
AND RYEAR = P_GJAHR
AND POPER <= P_MONAT
GROUP BY AWTYP AWORG RACCT REFDOCNR. "GK_166118
SORT T_GLPCA BY AWTYP AWORG REFDOCNR. "1062
process GLPCA postings
LOOP AT T_GLPCA.
endloop.
some code
endloop.
thanks
Archana... FOR ALL ENTRIES IN itab WHERE cond
Effect
Only selects the records that meet the logical condition cond when each replacement symbol itab-f is replaced with the value of component f of the internal table itab for at least one line of the table. 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).
Example
Displaying the occupancy of flights on 28.02.2001:
TYPES: BEGIN OF ftab_type,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
END OF ftab_type.
DATA: ftab TYPE STANDARD TABLE OF ftab_type WITH
NON-UNIQUE DEFAULT KEY INITIAL SIZE 10,
free TYPE I,
wa_sflight TYPE sflight.
Suppose FTAB is filled as follows:
CARRID CONNID
LH 2415
SQ 0026
LH 0400
SELECT * FROM sflight INTO wa_sflight
FOR ALL ENTRIES IN ftab
WHERE CARRID = ftab-carrid AND
CONNID = ftab-connid AND
fldate = '20010228'.
free = wa_sflight-seatsocc - wa_sflight-seatsmax.
WRITE: / wa_sflight-carrid, wa_sflight-connid, free.
ENDSELECT.
The statement has the same effect as:
SELECT DISTINCT * FROM sflight INTO wa_sflight
WHERE ( carrid = 'LH' AND
connid = '2415' AND
fldate = '20010228' ) OR
( carrid = 'SQ' AND
connid = '0026' AND
fldate = '20010228' ) OR
( carrid = 'LH' AND
connid = '0400' AND
fldate = '20010228' ).
free = wa_sflight-seatsocc - wa_sflight-seatsmax.
WRITE: / wa_sflight-carrid, wa_sflight-connid, free.
ENDSELECT.
Notes
You can only use ... FOR ALL ENTRIES IN itab WHERE cond in a SELECT statement.
In the logical condition cond, the symbol itab-f is always a replacement symbol, and should not be confused with the component f of the header line of the internal table itab. The internal table itab does not need to have a header line.
Each component of the internal table that occurs in a replacement symbol in the WHERE condition must have exactly the same type and length as the corresponding component in the database table.
You cannot use replacement symbols in comparisons in LIKE, BETWEEN, or IN expressions.
If you use FOR ALL ENTRIES IN itab, you cannot use ORDER BY f1 ... fn in the ORDER-BY clause.
If you use FOR ALL ENTRIES IN itab, you cannot use a HAVING clause as well.
Sameer -
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. -
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. -
Hi experts,
I have a below statement in my code
"SELECT on EKPO for all entries on ITAB (which is having 4 hundread thousand recods )"
giving dump saying "MEMORY_PGFREE_FAILED" and "Error releasing memory block in paging"
i need your suggestion to avoid the memory problem
"MEMORY_PGFREE_FAILED" ?
can we go ahead with EXTRACT logic, does this solve the memory problem?
thoughts will be appriciated,
Thanks,
Shaik bhashaSee the example code :
REPORT ZSPFLI LINE-SIZE 132 LINE-COUNT 65(3)
NO STANDARD PAGE HEADING.
TABLES:SPFLI,SCARR, SFLIGHT, SBOOK.
SELECT-OPTIONS: MYCARRID FOR SPFLI-CARRID.
FIELD-GROUPS: HEADER, SPFLI_FG, SFLIGHT_FG, SBOOK_FG.
INSERT:
SPFLI-CARRID
SPFLI-CONNID
SFLIGHT-FLDATE
SBOOK-BOOKID
INTO HEADER,
SPFLI-CARRID
SPFLI-CONNID
SPFLI-CITYFROM
SPFLI-AIRPFROM
SPFLI-CITYTO
SPFLI-AIRPTO
SPFLI-DEPTIME
SCARR-CARRNAME
INTO SPFLI_FG,
SFLIGHT-FLDATE
SFLIGHT-SEATSMAX
SFLIGHT-SEATSOCC
SFLIGHT-PRICE
INTO SFLIGHT_FG,
SBOOK-BOOKID
SBOOK-CUSTOMID
SBOOK-CUSTTYPE
SBOOK-SMOKER
INTO SBOOK_FG.
SELECT * FROM SPFLI WHERE CARRID IN MYCARRID.
SELECT SINGLE * FROM SCARR WHERE CARRID = SPFLI-CARRID.
EXTRACT SPFLI_FG.
SELECT * FROM SFLIGHT
WHERE CARRID = SPFLI-CARRID AND CONNID = SPFLI-CONNID.
EXTRACT SFLIGHT_FG.
SELECT * FROM SBOOK
WHERE CARRID = SFLIGHT-CARRID AND
CONNID = SFLIGHT-CONNID AND FLDATE = SFLIGHT-FLDATE.
EXTRACT SBOOK_FG.
CLEAR SBOOK.
ENDSELECT.
CLEAR SFLIGHT.
ENDSELECT.
CLEAR SPFLI.
ENDSELECT.
SORT.
LOOP.
AT SPFLI_FG.
FORMAT COLOR COL_HEADING.
WRITE: / SCARR-CARRNAME,
SPFLI-CONNID, SPFLI-CITYFROM,
SPFLI-AIRPFROM, SPFLI-CITYTO, SPFLI-AIRPTO, SPFLI-DEPTIME.
FORMAT COLOR OFF.
ENDAT.
AT SFLIGHT_FG.
WRITE: /15 SFLIGHT-FLDATE, SFLIGHT-PRICE, SFLIGHT-SEATSMAX,
SFLIGHT-SEATSOCC.
ENDAT.
AT SBOOK_FG.
WRITE: /30 SBOOK-BOOKID, SBOOK-CUSTOMID,
SBOOK-CUSTTYPE, SBOOK-SMOKER.
ENDAT.
ENDLOOP. -
Alternative for / Problems with: "For all entries in data_package"
Hi Guys
I doing some ABAP in a Start Rotine in BW and would like to do the following:
select * from /BI0/PMATERIAL into table 0mat
for all entries in DATA_PACKAGE
where material = DATA_PACKAGE-/bic/zmaterial.
But I get the following error:
E:When using the addition "FOR ALL ENTRIES IN itab", the fields "MATERIAL" and "DATA_PACKAGE-/BIC/ZMATERIAL" must have the same type and length. and length.
ZMATERIAL:
- Length: 28
- Type: CHAR - Character String
ZMATERIAL:
- Length: 18
- Type: CHAR - Character String
According to the error message "For all entries" cannot be used in this case since the lengths are not identical, but is there an alternative way to do what I would like to do?
Thanks in advance, kind regards,
TorbenHi
one thing you can try like this define one variable in other itab of same type
then loop at the first table and assign it to new field and modify the itab
then use this field with for all entries
Regards
Shiva -
Select... for all entries in...
Hi,
Can anybody help me to sort out this issue. This select should work. I m filling an itab with distinct pernr. in temp it should give <b>all the records for which pernr should not be in itab.</b>
report ZTEST4.
data : begin of ITAB occurs 0,
PERNR like PA0001-PERNR,
ename like pa0001-ename,
end of ITAB.
data : temp like itab occurs 0 with header line.
clear : ITAB, TEMP.
refresh : ITAB,TEMP.
select distinct PERNR into table ITAB from PA0001 where PERNR le 10.
select PERNR ENAME into table TEMP from PA0001
for all entries in ITAB where pernr not in itab-pernr.
sort TEMP by PERNR.
break-point.Hi Sagar,
If i understand it well, you exclude all PERNR LE 10.
But first things first.
You cannot use the FOR ALL ENTRIES in your case (it doesn't allow the operator "NOT IN").
Your code should be:
REPORT ztest4.
TYPES: BEGIN OF ty_itab,
pernr TYPE persno,
ename TYPE emnam,
END OF ty_itab.
DATA : itab TYPE ty_itab occurs 0,
wtab TYPE ty_itab.
CLEAR: itab,
wtab.
SELECT pernr ename
INTO TABLE itab
FROM pa0001
WHERE pernr LE 10
ORDER BY pernr.
IF sy-subrc EQ 0.
DELETE ADJACENT DUPLICATES FROM itab COMPARING pernr.
ENDIF.
Regards,
Rob.
Maybe you are looking for
-
This is so frustrating, i have gone through iforgot and reset my password, re logged in and it all works fine until it wants me to update my apple ID?? I dont know what it wants me to put? Any help appreciated : )
-
Can't print a photo multiple times on a single page
I just installed iLife 8 and am trying to print one 3X5 photo multiple times on a single page. When I consulted the help menu in iPhoto, I found what I thought was the answer. When I followed the instructions, I hit a snag because I don't have the Ph
-
Whats the best way to get an averaged measuremen​ts while scanning?
I currently have a PXI 4071 DMM and a PXI 2575 Mux. I've played around with the examples of how to do scanning of channels which all works out fine. However the scanning only takes one measurement every time it steps down the scan list. What I need i
-
F4 help in dropdownlistbox and values in input fields
I need a F4 help in dropdown list box. Actually i have 2 more input fields alongwith one dropwdown list box. As per my problem if i select one value from F4 help then corresponding other values should bepopulated into input fields. For example in F4
-
When I hit return after typing, the cursor returns to the beginning of the sentence
I open a new layer. I type my text I hit return' The cursor starts typing at the beginning of the sentence, typing right over the text I just finished. It will not go to the next line. I've been using PS since 2 and I have never seen this nor do I