Replacement for inner join.
I have the following SELECT stmt with inner join which is taking more time to execute......Kindly help me how to improve performance
SELECT AWERKS AMATNR AMBLNR AMJAHR AMENGE ABWART A~SHKZG
AAUFNR BBUDAT
INTO CORRESPONDING FIELDS OF TABLE TRANSTAB
FROM MSEG AS A INNER JOIN MKPF AS B ON AMBLNR = BMBLNR AND
AMJAHR = BMJAHR
WHERE A~BUKRS = BUKRS AND
A~WERKS IN R_WERKS AND
A~MATNR IN S_MATNR AND
B~BUDAT >= YFDATE AND
B~BUDAT <= P_DATUM AND
A~BWART IN (101,102,601,602,641,642).
YOUR HELP IS HIGHLY APPRECIATED....
Goldie - IN may or may not take more time. It depends on selectivity. If the IN is wide open, then the database will not be able to use and index effectively and may have to use a full index scan. I encourage you to run this:
REPORT ztest_indexed_selects.
PARAMETERS: p_bukrs LIKE bkpf-bukrs,
p_blart LIKE bkpf-blart,
p_budat LIKE bkpf-budat,
p_gjahr LIKE bkpf-gjahr.
DATA: bkpf TYPE bkpf.
DATA: bkpf_int TYPE TABLE OF bkpf .
DATA: cc LIKE bkpf-bukrs,
doc LIKE bkpf-belnr,
start TYPE i,
end TYPE i,
dif TYPE i.
START-OF-SELECTION.
* Hardcoded values
* Preliminary select.
REFRESH bkpf_int.
SELECT *
FROM bkpf
INTO TABLE bkpf_int
WHERE bukrs EQ p_bukrs
AND gjahr EQ p_gjahr
AND bstat IN (' ', 'A', 'B', 'D', 'M', 'S', 'V', 'W', 'Z')
AND blart = p_blart
AND budat = p_budat.
DO 5 TIMES.
REFRESH bkpf_int.
GET RUN TIME FIELD start.
SELECT *
FROM bkpf
INTO TABLE bkpf_int
WHERE bukrs EQ p_bukrs
AND gjahr EQ p_gjahr
AND blart = p_blart
AND budat = p_budat.
GET RUN TIME FIELD end.
dif = end - start.
WRITE: /001 'Time for SELECT without BSTAT', ':', dif,
'microseconds'.
REFRESH bkpf_int.
GET RUN TIME FIELD start.
SELECT *
FROM bkpf
INTO TABLE bkpf_int
WHERE bukrs EQ p_bukrs
AND gjahr EQ p_gjahr
AND bstat IN (' ', 'A', 'B', 'D', 'M', 'S', 'V', 'W', 'Z')
AND blart = p_blart
AND budat = p_budat.
GET RUN TIME FIELD end.
dif = end - start.
WRITE: /001 'Time for SELECT with BSTAT', ':', dif,
'microseconds'.
ENDDO.
Rob
Similar Messages
-
Replacing a inner join with for all entries
Hi Team,
In a already developed program I am replacing a inner join with select query follow up with for-all-entris and passing the data to final internal table but in both the case the result should be same then only my replacement will be correct. But my no records in both cases differs. This happening because when i am selecting data from first data base table is 32 lines. then I am doing fo-all-entries moving all the duplicate entries then the no records are four. but in final internal table i am looping the first internal table. So in final internal table the no of records are 32. But in inner join query the records are 16.So please let me know how resolve this issue?
Thanks and REgards
DeepaHi Thomas,
Thanks for ur suggestion.
The solved that in below.
In select query I did not change anything The way I had written the code was correct.
I think many of us know how to write that how to make the performance better in that way.
I made the change when I transfered the to final internal table.
The original Inner join code:
select a~field1 a~field2 a~field3 b~field2 b~field3 b~field4
from dbtab1 as a inner join dbtab2 as b
on a~field1 = b~field1 into it_final where
a~field1 in s_field1. [Field1 in both the table are key field]
Before code:
Sort itab1 by key-fields.
sort itab2 by keyfields.
loop at itab1 into wa1.
move: wa1-field1 to wa_final-field1,
wa1-field2 to wa_final-field2,
wa1-field3 to wa_final-field3.
read table itab2 into wa2 witk key field1 = wa1-field1 binary search.
if sy-subrc = 0.
move : wa2-field2 to wa_final-field4,
wa2-field3 to wa_final-field5,
wa2-field4 to wa_final-field6.
append wa_final to it_final.
endif.
Clear : wa1, wa2, wa_final.
endloop.
In this case if the one key fieild value is not present there in second internal table but its there in first internal table still it will read that row with 2nd internal values having zeroes. Normally what does not happen in inner join case if the key field value will same in both the case ,then that will fetch only those rows.
Changed Code
loop at itab1 into wa1.
read table itab2 into wa2 witk key field1 = wa1-field1 binary search.
if sy-subrc = 0.
move: wa1-field1 to wa_final-field1,
wa1-field2 to wa_final-field2,
wa1-field3 to wa_final-field3.
move : wa2-field2 to wa_final-field4,
wa2-field3 to wa_final-field5,
wa2-field4 to wa_final-field6.
append wa_final to it_final.
endif.
Clear : wa1, wa2, wa_final.
endloop.
In this case the values will read to final internal table if both key field matches.
With Regards
Deepa -
Need help with program for Inner join
Hello Experts,
I need to create a list from table sbook containing booking number (sbook-bookid), customer number (sbook-customid), customer name (scustom-name) , customer class (sbook-class) and ticket price (sflight-price). I am new to ABAP and am very confused I tried reading up some examples and came up with the attached program
Attached is my program for inner join
Kindly Help
Thanks SuHi Su K
You May use key fields , Foreign keys for joining , Here
SELECT SBOOK~BOOKID SBOOK~CUSTOMID SBOOK~CLASS
SCUSTOM~ID SCUSTOM~NAME FROM SFILGHT
INNER JOIN SBOOK ON SBOOK~CARRID EQ SFILGHT~CARRID
SBOOK~CONNID EQ SFILGHT~CONNID
SBOOK~FLDATE EQ SFILGHT~FLDATE
INNER JOIN SCUSTOM ON SCUSTOM~ID = SBOOK~ID -
Alternate for inner join to improve performance
Hi all,
I have used an inner join query to fetch data from five different tables into an internal table with where clause conditions.
The execution time is almost 5-6 min for this particular query(I have more data in all five DB tables- more than 10 million records in every table).
Is there any alternate for inner join to improve performance.?
TIA.
Regards,
KarthikHi All,
Thanks for all your interest.
SELECT a~object_id a~description a~descr_language
a~guid AS object_guid a~process_type
a~changed_at
a~created_at AS created_timestamp
a~zzorderadm_h0207 AS cpid
a~zzorderadm_h0208 AS submitter
a~zzorderadm_h0303 AS cust_ref
a~zzorderadm_h1001 AS summary
a~zzorderadm_h1005 AS summary_uc
a~zzclose_date AS clsd_date
d~stat AS status
f~priority
FROM crmd_orderadm_h AS a INNER JOIN crmd_link AS b ON a~guid = b~guid_hi
INNER JOIN crmd_partner AS c ON b~guid_set = c~guid
INNER JOIN crm_jest AS d ON objnr = a~guid
INNER JOIN crmd_activity_h AS f ON f~guid = a~guid
INTO CORRESPONDING FIELDS OF TABLE et_service_request_list
WHERE process_type IN lt_processtyperange
AND a~created_at IN lt_daterange
AND partner_no IN lr_partner_no
AND stat IN lt_statusrange
AND object_id IN lt_requestnumberrange
AND zzorderadm_h0207 IN r_cpid
AND zzorderadm_h0208 IN r_submitter
AND zzorderadm_h0303 IN r_cust_ref
AND zzorderadm_h1005 IN r_trans_desc
AND d~inact = ' '
AND b~objtype_hi = '05'
AND b~objtype_set = '07'.
f~priority
FROM crmd_orderadm_h AS a INNER JOIN crmd_link AS b ON a~guid = b~guid_hi
INNER JOIN crmd_partner AS c ON b~guid_set = c~guid
INNER JOIN crm_jest AS d ON objnr = a~guid
INNER JOIN crmd_activity_h AS f ON f~guid = a~guid
INTO CORRESPONDING FIELDS OF TABLE et_service_request_list
WHERE process_type IN lt_processtyperange
AND a~created_at IN lt_daterange
AND partner_no IN lr_partner_no
AND stat IN lt_statusrange
AND object_id IN lt_requestnumberrange
AND zzorderadm_h0207 IN r_cpid
AND zzorderadm_h0208 IN r_submitter
AND zzorderadm_h0303 IN r_cust_ref
AND zzorderadm_h1005 IN r_trans_desc
AND d~inact = ' '
AND b~objtype_hi = '05'
AND b~objtype_set = '07'. -
Iam not getting output for inner join where condition
the condition i have give
TYPES:BEGIN OF TY_TAB,
WERKS TYPE WERKS_D,
LGORT TYPE LGORT_D,
LGOBE TYPE LGOBE,
NAME1 TYPE NAME1,
END OF TY_TAB.
DATA WA_TAB TYPE TY_TAB.
DATA IT_TAB TYPE TABLE OF TY_TAB.
SELECT T001L~WERKS
T001L~LGORT
T001L~LGOBE
T001W~NAME1
INTO TABLE IT_TAB FROM T001L INNER JOIN T001W ON T001LWERKS = T001WWERKS
WHERE T001L~WERKS = 'amjt' and
T001L~WERKS = 'bimi' and
T001L~WERKS = 'biml'.
LOOP AT IT_TAB INTO WA_TAB.
WRITE: / WA_TAB-WERKS,WA_TAB-LGORT,WA_TAB-LGOBE,WA_TAB-NAME1.
ENDLOOP.
iam not getting output for thisWell, re-read carefully your code
WHERE T001L~WERKS = 'amjt' and
T001L~WERKS = 'bimi' and
T001L~WERKS = 'biml'
- WERKS cannot be simultaneously equal to three different values, replace AND with OR ([Boolean algebra|http://en.wikipedia.org/wiki/Boolean_algebra])
- WERKS domain does not allow lowercase, so use uppercase ([Creating Domains|http://help.sap.com/saphelp_nw04s/helpdata/en/cf/21edf2446011d189700000e8322d00/frameset.htm])
Regards,
Raymond -
What is syntax for inner join of Select statement with Secondary Index
Hi Genies,
Here i have created the Secondary index for table COEP and also used for select query but there is no improvement in runtime . taking same time for select query without index as well as with index. my code is
SELECT * INTO CORRESPONDING FIELDS OF TABLE ITAB_COEP FROM COEP AS A
INNER JOIN COBK AS B ON ( A~BELNR = B~BELNR AND A~KOKRS = B~KOKRS AND A~GJAHR = B~GJAHR )
WHERE A~OBJNR = OBJNR
AND A~GJAHR = CURRY
AND B~GJAHR = CURRY
AND A~RBEST = ''
AND A~BEKNZ = 'S'
AND B~BELNR NE WA_COBK-BELNR
AND B~AWREF_REV = ''
AND B~AWORG_REV = ''
AND B~KOKRS = WA_COIOB-KOKRS
AND B~BLDAT BETWEEN START_DATE AND END_DATE
AND B~BLART IN ('SA','KA','KR','AB') %_HINTS ORACLE 'INDEX("COEP" "COEP~ZBU")'.
index name is ZBU.
please any one let me know is there any syntax mistakes? but while checking and during the runtime it does'nt shows any error.
Regards,
Thangam.PHi Genies,
Here i have created the Secondary index for table COEP and also used for select query but there is no improvement in runtime . taking same time for select query without index as well as with index. my code is
SELECT * INTO CORRESPONDING FIELDS OF TABLE ITAB_COEP FROM COEP AS A
INNER JOIN COBK AS B ON ( A~BELNR = B~BELNR AND A~KOKRS = B~KOKRS AND A~GJAHR = B~GJAHR )
WHERE A~OBJNR = OBJNR
AND A~GJAHR = CURRY
AND B~GJAHR = CURRY
AND A~RBEST = ''
AND A~BEKNZ = 'S'
AND B~BELNR NE WA_COBK-BELNR
AND B~AWREF_REV = ''
AND B~AWORG_REV = ''
AND B~KOKRS = WA_COIOB-KOKRS
AND B~BLDAT BETWEEN START_DATE AND END_DATE
AND B~BLART IN ('SA','KA','KR','AB') %_HINTS ORACLE 'INDEX("COEP" "COEP~ZBU")'.
index name is ZBU.
please any one let me know is there any syntax mistakes? but while checking and during the runtime it does'nt shows any error.
Regards,
Thangam.P -
Time taking for inner joins in select
Hi all,
I am using inner join on 3 tables ( PLKO,PLPO,PLAS) for the materials,
it is taking database time 20% and abap time 78 % and when i am using FM CARO_ROUTING_READ
database time 48% and abap 52%.
i am in confusion which is th ebest method to use inner join or FM.
when i am checking in the server for plant in the selection screen , it is running lot of time
This is first time i am working on the performance issue.
Can you please anbody help me how to solve this issue.
Regards,
MadhaviPercentages don't mean much, how does the overall runtime compare? Is there a problem at all?
Since you already used SE30, go a step further and study the hit list sorted by net time descending, only look at the top few items.
Also read this:
Please Read before Posting in the Performance and Tuning Forum
Thomas -
Hi all,
Im extracting different fields from material master data into different internal tables. I need to have all the data in these internal table in one final internal table, I don't want to use inner join to get the data into the final internal table. Can you suggest any alternative for this?
Thanks.hi check this..this is the alternative for the joins..
REPORT ZZZZ000000.
tables:mara,marc,mard,makt.
data:begin of it_mara occurs 0,
matnr like mara-matnr,
mtart like mara-mtart,
meins like mara-meins,
end of it_mara.
data:begin of it_marc occurs 0,
matnr like marc-matnr,
pstat like marc-pstat,
werks like marc-werks,
end of it_marc.
data:begin of it_mard occurs 0,
werks like mard-werks,
lgort like mard-lgort,
labst like mard-labst,
end of it_mard.
data:begin of it_final occurs 0,
matnr like mara-matnr,
mtart like mara-mtart,
meins like mara-meins,
pstat like marc-pstat,
werks like marc-werks,
lgort like mard-lgort,
labst like mard-labst,
maktx like makt-maktx,
end of it_final.
select-options:s_matnr for mara-matnr.
select matnr
mtart
meins
from mara
into table it_mara
where matnr in s_matnr.
if not it_mara[] is initial.
select matnr
pstat
werks
from marc
into table it_marc
for all entries in it_mara
where matnr = it_mara-matnr.
if not it_marc[] is initial.
select werks
lgort
labst
from mard
into table it_mard
for all entries in it_marc
where werks = it_marc-werks.
endif.
endif.
loop at it_mara.
it_final-matnr = it_mara-matnr.
it_final-mtart = it_mara-mtart.
it_final-meins = it_mara-meins.
read table it_marc with key matnr = it_mara-matnr.
it_final-werks = it_marc-werks.
it_final-pstat = it_marc-pstat.
read table it_mard with key werks = it_marc-werks.
it_final-lgort = it_mard-lgort.
it_final-labst = it_mard-labst.
if sy-subrc = 0.
select maktx from makt into it_final-maktx where matnr = it_final-matnr.
endselect.
endif.
append it_final.
endloop.
loop at it_final.
write:/ it_final-matnr under 'material',
it_final-mtart under 'material type',
it_final-meins under 'unit of measure',
it_final-werks under 'plant' ,
it_final-pstat under 'status',
it_final-lgort under 'storage loc',
it_final-labst under 'stock',
it_final-maktx.
endloop.
regards,
venkat -
Hi all,
give me the query with innerjoin
Based on the input values of Material number (MARC-MATNR) from selection screen check and get the Special Procurement type details from MARC-SOBSL and Material description details from MAKT-MAKTX.
basha....
Moderator message - instead of asking, you should try to write the code yourself and get back to the forum if you have a specific question.
Edited by: Rob Burbank on Apr 19, 2009 4:46 PMHi,
Please Test the following Sample Code it is according to your requirement hope will solve out your problem,
TABLES: marc.
SELECt-OPTIONS somatnr for marc-matnr.
TYPES: BEGIN OF ty_matnr,
matnr LIKE marc-matnr,
sobsl LIKE marc-sobsl,
maktx LIKE makt-maktx,
END OF ty_matnr.
DATA: it_matnr TYPE STANDARD TABLE OF ty_matnr WITH HEADER LINE.
SELECT marc~matnr marc~sobsl makt~maktx
into CORRESPONDING FIELDS OF TABLE it_matnr
from marc INNER JOIN makt on ( marc~matnr eq makt~matnr )
WHERE marc~matnr in somatnr.
Best Regards,
Faisal -
Hi,
please check this code and suggest me of an alternative for this performance wise.
SELECT b~partner
APPENDING CORRESPONDING FIELDS OF
TABLE t_db_pos_match
FROM adrc AS a
JOIN but020 AS b
ON aaddrnumber = baddrnumber
JOIN but000 AS c
ON bpartner = cpartner
WHERE c~partner NE t_bp_obj-act-ekun-partner
AND c~mc_name1 = t_bp_obj-act-ekun-name_last
AND a~city1 = wa-city1
AND a~post_code1 = wa-post_code1
AND a~po_box = wa-po_box
AND a~street = wa-street
AND a~house_num1 = wa-house_num1
AND a~house_num2 = wa-house_num2
AND a~region = wa-region
AND a~addr_group = 'BP'.
awaiting your reply.
Binay.HI
*PARAMETERS P_CITY TYPE SPFLI-CITYFROM.
**TYPES: BEGIN OF ENTRY_TAB_TYPE,
CARRID TYPE SPFLI-CARRID,
CONNID TYPE SPFLI-CONNID,
END OF ENTRY_TAB_TYPE.
**DATA: ENTRY_TAB TYPE TABLE OF ENTRY_TAB_TYPE,
SFLIGHT_TAB TYPE SORTED TABLE OF SFLIGHT
WITH UNIQUE KEY CARRID CONNID FLDATE.
**SELECT CARRID CONNID
FROM SPFLI
INTO CORRESPONDING FIELDS OF TABLE ENTRY_TAB
WHERE CITYFROM = P_CITY.
**SELECT CARRID CONNID FLDATE
FROM SFLIGHT
INTO CORRESPONDING FIELDS OF TABLE SFLIGHT_TAB
FOR ALL ENTRIES IN ENTRY_TAB
WHERE CARRID = ENTRY_TAB-CARRID AND
CONNID = ENTRY_TAB-CONNID.
TRY LIKE THIS
REWARD IF USEFULL -
Can anyone give me an example of for all entries in case of inner join
Hi abapers,
I am trying to replace an inner join with for all entries.
So kindly give me a demo code so that i can understand the use and apply it.
And plz tell me in which case it is better to use for all entries and in which case to use inner join so that better performance will occur.
With Regards
AnsumanHello Ansuman,
For example:
DATA:
BEGIN OF fs_eket,
ebeln LIKE ekko-ebeln, " Purchasing Document Number
ebelp LIKE ekpo-ebelp, " Item Number of Purchasing Doc
END OF fs_eket. " fs_eket
DATA:
t_eket LIKE " Purchase table
STANDARD TABLE
OF fs_eket.
Using joins:
select ebeln ebelp
into corresponding fields of table t_eket
from ekko join ekpo
on ekkoebeln eq ekpoebeln
where ebeln in s_sbeln.
The select statement can be replaced by
SELECT ebeln
FROM ekko
INTO CORRESPONDING FIELDS OF TABLE t_eket
WHERE ebeln IN s_ebeln.
IF sy-subrc EQ 0.
sort t_eket by ebeln.
SELECT ebeln
ebelp
FROM ekpo
INTO CORRESPONDING FIELDS OF TABLE t_eket
FOR ALL ENTRIES IN t_eket
WHERE ebeln EQ t_eket-ebeln.
The duplicate entries are removed by using FOR ALL ENTRIES. Or else by using the join, you have teh sort the table by key fields and then delete adjacent duplicates.
Hope it helps you
Regards
Indu -
Inner join query used with 7 Database tables
HI All,
In a report they used the Inner join Query with 6 Data base table..now there is a performance issue with at query.
its taking so much of time to trigger that query. Please help how to avoid that performance issue for that.
In that 2 database tables containing lakhs of records..
According to my knowledge it can be avoided by using secondary indexs for those 2 database tables..
and by replacing the Inner join Query with FOR ALL ENTRIES statement.
i want how to use the logic by using FORALL ENTRIES statement for this..
So, please give you proper suggestion to avoid this issue..
Thanking you.
Moderator message: Please Read before Posting in the Performance and Tuning Forum
Edited by: Thomas Zloch on Oct 16, 2011 10:27 PMHi,
And what do you mean with "they used"? If "SAP used" then yo will need to ask a SAP for note
FOR ALL ENTRIES is quite good described in help. Please search forum also.
Without query it won't be possible to tell how it can be optimized, however you can try to use SE30/SAT and ST05. Maybe it will help you.
BR
Marcin Cholewczuk -
i wanna add inner joins in my report,plz give me d link of websites which provide suitable example.. if u r having example of it den do tell me...
its really urgent...HI
SELECT - join
... [(] {dbtab_left [AS tabalias_left]} | join
{[INNER] JOIN}|{LEFT [OUTER] JOIN}
{dbtab_right [AS tabalias_right] ON join_cond} [)] ... .
The join syntax represents a recursively nestable join expression. A join expression consists of a left-hand and a right- hand side, which are joined either by means of [INNER] JOIN or LEFT [OUTER] JOIN. Depending on the type of join, a join expression can be either an inner (INNER) or an outer (LEFT OUTER) join. Every join expression can be enclosed in round brackets. If a join expression is used, the SELECT command circumvents SAP buffering.
On the left-hand side, either a single database table, a view dbtab_left, or a join expression join can be specified. On the right-hand side, a single database table or a view dbtab_right as well as join conditions join_cond can be specified after ON. In this way, a maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM.
AS can be used to specify an alternative table name tabalias for each of the specified database table names or for every view. A database table or a view can occur multiple times within a join expression and, in this case, have various alternative names.
The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:
At least one comparison must be specified after ON.
Individual comparisons may be joined using AND only.
All comparisons must contain a column in the database table or the view dbtab_right on the right-hand side as an operand.
The following additions not be used: NOT, LIKE, IN.
No sub-queries may be used.
For outer joins, only equality comparisons (=, EQ) are possible.
If an outer join occurs after FROM, the join condition of every join expression must contain at least one comparison between columns on the left-hand and the right-hand side.
In outer joins, all comparisons that contain columns as operands in the database table or the view dbtab_right on the right-hand side must be specified in the corresponding join condition. In the WHERE condition of the same SELECT command, these columns are not allowed as operands.
Resulting set for inner join
The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line on the right-hand side. The content of the column on the left-hand side may be duplicated in this case. If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.
Resulting set for outer join
The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition. The columns on the right-hand side that do not fulfil the join_cond condition are filled with null values.
If the same column name occurs in several database tables in a join expression, they have to be identified in all remaining additions of the SELECT statement by using the column selector ~.
Example
Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table.
PARAMETERS: p_cityfr TYPE spfli-cityfrom,
p_cityto TYPE spfli-cityto.
DATA: BEGIN OF wa,
fldate TYPE sflight-fldate,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa.
DATA itab LIKE SORTED TABLE OF wa
WITH UNIQUE KEY fldate carrname connid.
SELECT ccarrname pconnid f~fldate
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( scarr AS c
INNER JOIN spfli AS p ON pcarrid = ccarrid
AND p~cityfrom = p_cityfr
AND p~cityto = p_cityto )
INNER JOIN sflight AS f ON fcarrid = pcarrid
AND fconnid = pconnid ).
LOOP AT itab INTO wa.
WRITE: / wa-fldate, wa-carrname, wa-connid.
ENDLOOP.
Example
Join the columns carrid, carrname and connid of the database tables scarr and spfli using an outer join. The column connid is set to the null value for all flights that do not fly from p_cityfr. This null value is then converted to the appropriate initial value when it is transferred to the assigned data object. The LOOP returns all airlines that do not fly from p_cityfr.
PARAMETERS p_cityfr TYPE spfli-cityfrom.
DATA: BEGIN OF wa,
carrid TYPE scarr-carrid,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa,
itab LIKE SORTED TABLE OF wa
WITH NON-UNIQUE KEY carrid.
SELECT scarrid scarrname p~connid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM scarr AS s
LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid
AND p~cityfrom = p_cityfr.
LOOP AT itab INTO wa.
IF wa-connid = '0000'.
WRITE: / wa-carrid, wa-carrname.
ENDIF.
ENDLOOP.
REWARD if usefull -
hello sir,
plz tell me the syntax of inner join for three tables.Syntax
... [(] {dbtab_left [AS tabalias_left]} | join
{[INNER] JOIN}|{LEFT [OUTER] JOIN}
{dbtab_right [AS tabalias_right] ON join_cond} [)] ... .
Effect
The join syntax represents a recursively nestable join expression. A join expression consists of a left-hand and a right- hand side, which are joined either by means of [INNER] JOIN or LEFT [OUTER] JOIN . Depending on the type of join, a join expression can be either an inner ( INNER) or an outer (LEFT OUTER) join. Every join expression can be enclosed in round brackets. If a join expression is used, the SELECT command circumvents SAP buffering.
On the left-hand side, either a single database table, a view dbtab_left, or a join expression join can be specified. On the right-hand side, a single database table or a view dbtab_right as well as join conditions join_cond can be specified after ON. In this way, a maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM.
AS can be used to specify an alternative table name tabalias for each of the specified database table names or for every view. A database table or a view can occur multiple times within a join expression and, in this case, have various alternative names.
The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:
At least one comparison must be specified after ON.
Individual comparisons may be joined using AND only.
All comparisons must contain a column in the database table or the view dbtab_right on the right-hand side as an operand.
The following language elements may not be used: BETWEEN, LIKE, IN.
No sub-queries may be used.
For outer joins, only equality comparisons (=, EQ) are possible.
If an outer join occurs after FROM, the join condition of every join expression must contain at least one comparison between columns on the left-hand and the right-hand side.
In outer joins, all comparisons that contain columns as operands in the database table or the view dbtab_right on the right-hand side must be specified in the corresponding join condition. In the WHERE condition of the same SELECT command, these columns are not allowed as operands.
Resulting set for inner join
The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line on the right-hand side. The content of the column on the left-hand side may be duplicated in this case. If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.
Resulting set for outer join
The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition. The columns on the right-hand side that do not fulfil the join_cond condition are filled with null values.
Example
Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table.
PARAMETERS: p_cityfr TYPE spfli-cityfrom,
p_cityto TYPE spfli-cityto.
DATA: BEGIN OF wa,
fldate TYPE sflight-fldate,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa.
DATA itab LIKE SORTED TABLE OF wa
WITH UNIQUE KEY fldate carrname connid.
SELECT ccarrname pconnid f~fldate
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( scarr AS c
INNER JOIN spfli AS p ON pcarrid = ccarrid
AND p~cityfrom = p_cityfr
AND p~cityto = p_cityto )
INNER JOIN sflight AS f ON fcarrid = pcarrid
AND fconnid = pconnid ).
LOOP AT itab INTO wa.
WRITE: / wa-fldate, wa-carrname, wa-connid.
ENDLOOP.
Example
Join the columns carrid, carrname and connid of the database tables scarr and spfli using an outer join. The column connid is set to the null value for all flights that do not fly from p_cityfr. This null value is then converted to the appropriate initial value when it is transferred to the assigned data object. The LOOP returns all airlines that do not fly from p_cityfr.
PARAMETERS p_cityfr TYPE spfli-cityfrom.
DATA: BEGIN OF wa,
carrid TYPE scarr-carrid,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa,
itab LIKE SORTED TABLE OF wa
WITH NON-UNIQUE KEY carrid.
SELECT scarrid scarrname p~connid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM scarr AS s
LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid
AND p~cityfrom = p_cityfr.
LOOP AT itab INTO wa.
IF wa-connid = '0000'.
WRITE: / wa-carrid, wa-carrname.
ENDIF.
ENDLOOP.
we r using 2 type of joins in abap they are
1) inner join.
this will join 2 tables using an common fiend and return the result with field values wich are common in both the tables
itab1 itab2
a b c a d
1 2 3 1 5
2 3 4 3 6
after innerjoining itab1 n itab2 on field a we wil get the o/p as
a b c d
1 2 3 5
only common field is taken..
2)left outer join
here it wil work in opossite way it will give values whic are not common
itab1 itab2
a b c a d
1 2 3 1 5
2 3 4 3 6
after left outer joining itab1 n itab2 on field a we wil get the o/p as
a b c d
2 3 4
only fields which are not common is taken from the left table..other field(d here) wil be empty
I think it will help u.
Reward Points if helpful.
Check for ALVROBOT.COM also it is also helpful. -
Hi,
Is there a way to configure BI Server 11g to generate ANSI join sytax ("INNER JOIN" clause) for Oracle, as it does when using OUTER JOINs?
Thank you.OBIEE will not generate ANSI syntax for Inner Joins and as you said it only generates for Outer joins. Hope this clears your doubt.
Maybe you are looking for
-
Iphotos there but not really???
I have photos in my library that are there. And like usual when you open iphoto, they are along the top. But I cannot open them (if you want to edit or just see them larger). It just shows this swirling icon. Any ideas....your knowledge is appreciate
-
Modbus Slave Demon - Executable cannot find VI.
I have included in my application Modbus Ethernet Example Slave, which I've altered a bit ( only the inside of While Loop ). Everything is working fine until I've come to using an executable built from my project. When I start it I got: Error 7 occur
-
Error while configuring saprouter
Hi, I m getting error while configuring saprouter. When i run the command get_pse -v -r certreq -p local.pse"DN name".I get the following error. get_pse: Malformed distinguished name "pqprojsrv CN=pqprojsrv, OU=0000756782, O U=SAProuter, O=SAP, C=DE
-
I tried to run ubuntu from a disk to try it out (no install). Now I cant boot into OSX anymore, even when i hold down the option key, Windows 7 automatically starts. How do i get back into OSX?
-
Windows vista - IE 7 - problem with adobe flash player
last week I bought a notebook with MS vista home premium, after some hours of enthusiasm I had problems with adobe flash player. Accessing to some sites I receiveed the requested to install flash player, I did it and even if the installation seemed e