Urgent: Regarding Inner join relation b/w MSEG, MKPF, MARA and MAKT
I have written o code like below for inner join. However, The program has take much more time to give out put. Could any one please correct the below inner join statement. Its very urgent.
Thanks for your help.
SELECT mseg~mblnr
mseg~matnr
mseg~werks
mseg~charg
mseg~lifnr
mseg~bualt
mseg~erfmg
mseg~ebeln
mseg~ebelp
mkpf~budat
mara~zzshelf_life
makt~maktx
FROM mseg
INNER JOIN mkpf
ON mkpfmblnr EQ msegmblnr
INNER JOIN mara
ON msegmatnr EQ maramatnr
INNER JOIN makt
ON maramatnr EQ maktmatnr
INTO TABLE gt_mat_doc
WHERE mseg~matnr IN s_matnr
AND mseg~werks IN s_werks
AND mseg~lifnr IN s_lifnr
AND mseg~bwart EQ p_bwart
AND ( msegebeln NE ' ' AND msegebeln IN s_ebeln )
AND mkpf~budat IN s_budat
AND mara~mtart IN s_mtart
AND makt~spras EQ sy-langu.
Hi,
Do like this
Types: begin of ty_mesg_mkpf,
mblnr type mseg-mblnr,
matnr type mseg-matnr,
werks type mseg-werks,
charg type mseg-charg,
lifnr type mseg-lifnr,
bualt type mseg-bualt,
erfmg type mseg-erfmg,
ebeln type mseg-ebeln,
ebelp type mseg-ebelp,
budat type mkpf-budat,
end of ty_mseg_mkpf,
Begin og ty_mara_makt,
matnr type mara-matnr,
zzshelf_life type mara-zzshelf_life,
maktx type makt-maktx,
end of ty_mara_makt.
Data: it_mseg_mkpf type table of ty_mseg_mkpf,
wa_mseg_mkpf type ty_mseg_mkpf,
it_mara_makt type table of ty_mara_makt,
wa_mara_makt type ty_mara_makt.
SELECT m1~mblnr
m1~matnr
m1~werks
m1~charg
m1~lifnr
m1~bualt
m1~erfmg
m1~ebeln
m1~ebelp
m2~budat
FROM mseg
INTO TABLE it_mseg_mkpf
INNER JOIN mkpf
ON m1mblnr EQ m2mblnr
WHERE m1~matnr IN s_matnr
AND m1~werks IN s_werks
AND m1~lifnr IN s_lifnr
AND m1~bwart EQ p_bwart
AND ( m1ebeln NE ' ' AND m1ebeln IN s_ebeln )
AND m2~budat IN s_budat
if sy-subrc = 0.
Select m3~matnr
m3~zzshelf_life
m4~maktx from mara as m3
INNER JOIN makt as m4
ON m3matnr EQ m4matnr
INTO TABLE it_mara_makt
where m3~mtart IN s_mtart
AND m4~spras EQ sy-langu.
endif.
loop at it_mseg_mkpf into wa_mseg_mkpf.
Move necessary field values from wa_mseg_mkpf to wa_mat_doc.
Read table it_mara_makt into wa_mara_makt with key matnr = wa_mseg_mkpf-matnr.
if sy-subrc = 0.
move remaining field values to wa_mat_doc.
append wa_mat_doc to gt_mat_doc.
clear wa_mat_doc.
endif.
endloop.
Regards,
Satish
Similar Messages
-
Hi Guriji,s
I wrote one inner join query. it is working fine. but when i exceute this query it is fetching the data only 261 movement type but but i also fetch the data movement type 201. for this plz tell me the correction in this query.
select amatnr awerks abwart bbudat into table t_itab from mseg as a inner join mkpf as b
on amblnr = bmblnr
where awerks in plant and abwart = '261' or a~bwart = '201'
and btcode2 = 'mb1a' or btcode2 = 'mfbf' .
thanks.Hi Sachin
try to use like below
select amatnr awerks abwart bbudat into table t_itab from mseg as a inner join mkpf as b
on amblnr = bmblnr
where awerks in plant and ( abwart = '261' or a~bwart = '201' )
and ( btcode2 = 'mb1a' or btcode2 = 'mfbf' ).
or try to fill ranges like select-options or use like
select amatnr awerks abwart bbudat into table t_itab from mseg as a inner join mkpf as b
on amblnr = bmblnr
where awerks in plant and abwart in ('261', '201')
and btcode2 = 'mb1a' or btcode2 = 'mfbf' .
Regards
Praveen -
Regarding inner joins and calculations
Dear Experts,
I have a simple problem but i am a little confused. The problem is that i have 3 tables one is ekpo, ekes,ekbe
from ekpo i have to take matnr value and with respect to the matnr value i have to do this
Field discription is opening stock to get this value i have to do this
FOR ANY material sum of MENGE of EKES minus sum of MENGE of EKBE where VGABE=1
Where EKES. EBELN = EKBE. EBELN And EBELP
For input date range for EKBE BUDAT, EKES EINDT
could you help me out with this problemHi ,
Don't use inner join for 3 tables. Instead extract the data from 2 tables EKES and EKBE and store in a internal table. for EKPO store in another internal table. now you write the logic to calculate the desired result. By doing this way it will not cause any problems on performance. -
I am not getting how to inner join two tables(any two internal tables).
please give one example.Hi,
Check this,
data : begin of itab occurs 0,
matnr like mara-matnr,
ersda like mara-ersda,
maktx like makt-maktx,
end of itab.
SELECT Amatnr Aersda b~maktx
INTO itab
FROM mara AS A INNER JOIN makt AS b
ON Amatnr = bmatnr
ENDSELECT.
Also read this link for understanding,
http://help.sap.com/saphelp_46c/helpdata/en/cf/21ec77446011d189700000e8322d00/frameset.htm
Regards -
Hi
Can anyone explain me the error in this select query and give me the correct answer.
select 1begda 1endda 2kostl 2persg 2anvsh 3pernr into
corresponding fields of table i_emp from
( ( pa0000 as 1 innerjoin pa0001 as 2 on 1pernr = 2pernr )
join pa0003 as 3 on 3pernr = pa0002pernr )
for all entries in pa0002
where 2~pernr = pa0002-pernr.
Requirement is :
retreive data from 4 tables :PA0000,PA0001,PA0002,PA0003 based on pernr field.
From PA0000 we need begda and endda.
From PA0001 we need kostl and persg and anvsh.
From PA0002 we need to concatenate VORNA and NACHN fieldsand put this in display_name field of i_emp.How to do this in innerjoin.
From PA0003 we need pernr field.
Structure of t_emp is:
types:begin of t_emp,
start_date like pa0000-begda,
end_date like pa0000-endda,
cost_centre like pa0001-kostl,
active_status like pa0001-persg,
display_name(80) type c,
perno like pa0003-pernr,
activity_type like zpm_activity_typ-lstar,
contract_id like pa0001-anvsh,
end of t_emp.
data:i_emp type standard table of t_emp.
Please tell me the exact select query.The perfect one.
Points will definitely be given.This is really urgent.
Please help me.
Thanking you
chandrika.Make use of Logical databse PNP (mention in attributes of prgram) and copy this code below ,it will work and dont forget to award me points -
*& Report ZGILL_TEST11 *
REPORT ZGILL_TEST11 message-id rp
line-size 250
line-count 65 .
tables: pernr.
infotypes: 0000,
0001,
0002,
0003.
constants: c_1(1) type c value '1'.
Internal Table for Output
data: begin of t_output occurs 0 ,
pernr like pernr-pernr ,
name(80),
begda like p0000-begda ,
endda like p0000-endda ,
kostl like p0001-kostl,
persg like p0001-persg,
ansvh like p0001-ansvh.
data: end of t_output .
Start-of-selection.
get pernr.
clear t_output.
Read Infotype 0
rp-provide-from-last p0000 space pn-begda pn-endda.
check pnp-sw-found eq c_1.
Read Infotype 1
rp-provide-from-last p0001 space pn-begda pn-endda.
check pnp-sw-found eq c_1.
Read Infotype 2
rp-provide-from-last p0002 space pn-begda pn-endda.
check pnp-sw-found eq c_1.
rp-provide-from-last p0003 space pn-begda pn-endda.
check pnp-sw-found eq c_1.
Gather all the required information related to the emp
move: pernr-pernr to t_output-pernr,
p0000-begda to t_output-begda,
p0000-endda to t_output-endda,
p0001-kostl to t_output-kostl,
p0001-persg to t_output-persg,
p0001-ansvh to t_output-ansvh.
concatenate p0002-vorna p0002-nachn into t_output-name separated by space.
append t_output.
end-of-selection.
perform print_report. -
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 -
BELOW IS MY PROGRAM. AND I WANT TO SHOW THE WHOLE DATA OF ALL THE TABLE.SO HOW I WILL DEFINE TABLE IN DATA STATEMENT AND IN SELECT STATEMENT.
PLZ IT'S URGENT
TAHNKS..
SAM
*& Report ZTEMP_JOIN
REPORT ZTEMP_JOIN.
TABLES: MARA,MARC,MARD,MSEG, MAST.
SELECT-OPTIONS: SAM FOR MARA-MATNR.
DATA: BEGIN OF ITAB OCCURS 0,
MATNR LIKE MARA-MATNR,
ERSDA LIKE MARA-ERSDA,
ERNAM LIKE MARA-ERNAM,
MTART LIKE MARA-MTART,
WERKS LIKE MARC-WERKS,
PSTAT LIKE MARC-PSTAT,
LVORM LIKE MARC-LVORM,
LFGJA LIKE MARD-LFGJA,
MBLNR LIKE MSEG-MBLNR,
MJAHR LIKE MSEG-MJAHR,
BWART LIKE MSEG-BWART,
STLAN LIKE MAST-STLAN,
STLAL LIKE MAST-STLAL,
STLNR LIKE MAST-STLNR,
END OF ITAB.
SELECT MA~MATNR MA~ERSDA MA~ERNAM MA~MTART MC~WERKS MC~PSTAT MC~LVORM MD~LFGJA MG~MBLNR MG~MJAHR MG~BWART MT~STLAN MT~STLAL MT~STLNR
INTO TABLE ITAB FROM MARA AS MA INNER JOIN MARC AS MC ON
MA~MATNR = MC~MATNR
INNER JOIN MARD AS MD ON
MC~MATNR = MD~MATNR
INNER JOIN MSEG AS MG ON
MD~MATNR = MG~MATNR
INNER JOIN MAST AS MT ON
MG~MATNR = MT~MATNR
WHERE MA~MATNR IN SAM.
LOOP AT ITAB.
WRITE:/ ITAB-MATNR,ITAB-ERSDA,ITAB-ERNAM,ITAB-MTART,ITAB-WERKS, ITAB-PSTAT, ITAB-LVORM, ITAB-LFGJA,
ITAB-MBLNR, ITAB-MJAHR, ITAB-BWART, ITAB-STLAN, ITAB-STLAL, ITAB-STLNR.
ENDLOOP.
*START-OF-SELECTION.
WRITE: / 'line 1'.
WRITE: / 'line 2'.
WRITE: / 'line 3'.
TOP-OF-PAGE.
WRITE: / 'MM FIVE TABLES INNNER JOIN'.
ULINE.
TOP-OF-PAGE.
WRITE: /1(109) sy-uline.
WRITE: /1 '|', 2(18) 'MATNR-MATNR' COLOR 1,
20 '|', 21(8) 'ERSDA' COLOR 2,
29 '|', 30(12) 'ERNAM-ERNAM' COLOR 3,
42 '|', 43(4) 'MTART' COLOR 4,
47 '|', 48(4) 'WERKS' COLOR 5,
52 '|', 53(15) 'PSTAT-PSTAT' COLOR 6,
68 '|', 69(1) 'LVORM' COLOR 7,
70 '|', 71(4) 'LFGJA' COLOR 1,
75 '|', 76(10) 'MBLNR' COLOR 2,
86 '|', 87(4) 'MJAHR' COLOR 3,
91 '|', 92(3) 'BWART' COLOR 4,
95 '|', 96(1) 'STLAN' COLOR 5,
97 '|', 98(2) 'STLAL' COLOR 6,
100 '|', 101(8) 'STLNR' COLOR 7,
109 '|'.
WRITE: /1(109) sy-uline.Hi Sam,
Refer sample code when using Multiple INNER JOIN.
SELECT T1~PERNR
T7~ZDSILONR
T7~ZDTEAMNR
T1~AUFNR
T1~GMNGA
T2~MATNR
T2~CHARG
T4~ARBPL
T8~AUART
INTO TABLE I_ITAB1
FROM ( ( ( ( AFRU AS T1 INNER JOIN AFPO AS T2
ON T1WERKS = T2DWERK AND
T1AUFNR = T2AUFNR )
INNER JOIN S022 AS T4 ON T4AUFNR = T1AUFNR AND
T4~VORNR = C_VORNR )
INNER JOIN ZTK_ORDRSILOTEAM AS T7 ON T7ZDAUFNR = T1AUFNR )
INNER JOIN AUFK AS T8 ON T8AUFNR = T2AUFNR )
WHERE T1~WERKS IN S_PLANT AND
T1~BUDAT IN S_START AND
T1~PERNR IN S_SHIFT AND
T7~ZDTEAMNR IN S_TEAM AND
T2~MATNR IN S_ITEM AND
T1AUFNR = T8AUFNR AND
T4~ARBPL IN S_WORK AND
T8~AUART IN (C_ZCES,C_ZCRS,C_ZCEX,
C_ZCFT,C_ZCFS,C_ZCFX).
Reward points if this Helps.
Manish -
Inner join with for-all entries
Why is the below inner join-for all entries does not result in expected output ?
REPORT ZTST3 .
tables : ztst1,ztst2 .
* table ztst1 has 4 fields : mandt,ebeln,ebelp,etenr,char4. ; ztst2 has
* 3 fields : mandt,ebeln,ebelp,matnr
*Entries in ztst1
* EBELN EBELP ETERN CHAR4
* 5000000000 00010 0001 abc
* 5000000000 00010 0002 cbd
* 5000000000 00010 0003 efg
*Entries in ztst2
* EBELN EBELP matnr
* 5000000000 00010 matabc
*expected itab after inner join
* EBELN EBELP CHAR4 MAtnr
* 5000000000 00010 abc matabc
* 5000000000 00010 cbd matabc
* 5000000000 00010 efg matabc
data : begin of itab1 occurs 0,
ebeln type ebeln,
ebelp type ebelp,
end of itab1.
data : begin of itab occurs 0,
ebeln type ebeln,
ebelp type ebelp,
char4 type char4,
matnr type matnr,
end of itab.
start-of-selection.
itab1-ebeln = '5000000000'.
itab1-ebelp = '00010'.
append itab1.
select ztst1~ebeln
ztst1~ebelp
ztst1~char4
ztst2~matnr into corresponding fields of table itab
from ztst1 inner join ztst2
on ztst1~ebeln = ztst2~ebeln and
ztst1~ebeln = ztst2~ebelp
for all entries in itab1
where
ztst1~ebeln eq itab1-ebeln and
ztst1~ebelp eq itab1-ebelp .
* why does it return no entries;
break-point.For example in the bellow case
*Entries in ztst1
EBELN EBELP ETERN CHAR4
5000000000 00010 0001 abc
5000000000 00010 0002 cbd
5000000000 00010 0003 efg
5000000002 00020 0003 efg
5000000002 00020 0003 efg
*Entries in ztst2
EBELN EBELP matnr
5000000000 00010 matabc
5000000002 00020 abc
may it will return you 2 records yes, than I think you have under stand the working of u201Cfor all entriesu201D ?
And the following case I think it will work fine.
*Entries in ztst1
key EBELN EBELP ETERN CHAR4
1 5000000000 00010 0001 abc
2 5000000000 00010 0002 cbd
3 5000000000 00010 0003 efg
4 5000000002 00020 0003 efg
5 5000000002 00020 0003 efg
*Entries in ztst2
EBELN EBELP matnr
5000000000 00010 matabc
5000000002 00020 abc
select ztst1~key
ztst1~ebeln
ztst1~ebelp
ztst1~char4
ztst2~matnr into corresponding fields of table itab
from ztst1 inner join ztst2
on ztst1~ebeln = ztst2~ebeln and
ztst1~ebelp = ztst2~ebelp
for all entries in itab1
where
ztst1~ebeln eq itab1-ebeln and
ztst1~ebelp eq itab1-ebelp .
Sorry, I donu2019t have system with me right now and I am sending you with out testing but I am sure that it is working the same way.
Please Reply if any problem
Kind Regards,
Faisal -
Difference between inner join and outer join
1.Difference between inner join and outer join
2.wht is the difference in using hide and get crusor value in interactive.
3. Using join is better or views in writting program . Which is better.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 |
|--||||||||--|
Regards
Prabhu -
Inner Join for Dynamic Select statement
Hi All,
Can some one please help me in rewriting the below select statement where i have to remove the existing table1 by putting a dynamic table name which has the same table structure.
select a~zfield1
a~zfield2
from ztab1 as a
inner join ztab2 as b
on b~ztab1-zfield3 = a~ztab2-zfield3
where a~zfield4 = 'A'.
I am looking something as below. But encountering an error when using the below statement
select a~zfield1
a~zfield2
from (v_ztab1) as a
inner join ztab2 as b
on b~ztab1-zfield3 = a~ztab2-zfield3
where a~zfield4 = 'A'.
No Separate selects please. Please help me in rewriting the same select statement itself.
Regards,
PSKhi,
What error you are getting ?
Also INTO is missing from the statement.
SELECT pcarrid pconnid ffldate bbookid
INTO TABLE itab
FROM ( spfli AS p
INNER JOIN sflight AS f ON pcarrid = fcarrid AND
pconnid = fconnid )
WHERE p~cityfrom = 'FRANKFURT' AND
p~cityto = 'NEW YORK' .
thanks -
Time Out by select on DD04L inner join DD04T
Hello,
I just installed ERP 2005. After the import of a language package (SMLT, IT, FR, ES) I get some problem.
If I logon with EN or IT (and I think with any language other than DE) many transaction get a Time Out error in the function module DDIF_FIELDINFO_GET by the following selection:
* get texts of primary language (inner join here !)
SELECT DD04L~ROLLNAME DD04L~DOMNAME DD04L~HEADLEN
DD04L~SCRLEN1 DD04L~SCRLEN2 DD04L~SCRLEN3
DD04T~DDLANGUAGE DD04T~DDTEXT DD04T~REPTEXT
DD04T~SCRTEXT_S DD04T~SCRTEXT_M DD04T~SCRTEXT_L
INTO TABLE Rolltexts
FROM DD04L inner JOIN DD04T
ON DD04T~ROLLNAME = DD04L~ROLLNAME AND
DD04T~AS4LOCAL = 'A' AND
DD04T~DDLANGUAGE = langu_loc
FOR ALL ENTRIES IN missing
WHERE DD04L~ROLLNAME = missing-ROLLNAME
AND DD04L~AS4LOCAL = 'A'.
That is, the ERP is using sequential read instead of direct read.
Any idea is welcomed.
Thanks & regards,
TommasoHello,
Thanks for your replies.
I checked OSS and I found nothing.
ST05 gives me this SQL command: (more than 500 sec!)
SELECT T_00 . "ROLLNAME" , T_00 . "DOMNAME" , T_00 . "HEADLEN" , T_00 . "SCRLEN1" , T_00 . "SCRLEN2" , T_00 . "SCRLEN3" , T_01 . "DDLANGUAGE" , T_01 . "DDTEXT" , T_01 . "REPTEXT" , T_01 . "SCRTEXT_S" , T_01 . "SCRTEXT_M" , T_01 . "SCRTEXT_L" FROM "DD04L"
T_00 INNER JOIN "DD04T" T_01 ON T_01 . "ROLLNAME" = T_00 . "ROLLNAME" AND T_01 . "AS4LOCAL" = 'A' AND T_01 . "DDLANGUAGE" = 'I' WHERE T_00 . "ROLLNAME" = 'VAL_TEXT' AND T_00 . "AS4LOCAL" = 'A'
I executed it in SQL Studio and I got also a big execution time.
But if I try
SELECT "ROLLNAME" , "DOMNAME" , "HEADLEN" , "SCRLEN1" , "SCRLEN2" , "SCRLEN3" FROM "DD04L" WHERE T_00 . "ROLLNAME" = 'VAL_TEXT' AND T_00 . "AS4LOCAL" = 'A'
I get the result in 1 ms.
Is there something wrong in the inner join?
What does it mean the operation "REOPEN"?
How can I see from ST05 if an index has been used?
Thanks & Regards,
Tommaso -
hi all,
i have to extract data from 3 different tables.
is a single inner join better option or separate select statements ?
thanksHi,
If there are common key fields in the three tables, then inner join is a better option else its better to use for all entries to fetch the data.
If you want an example to join 3 tables, you can find it at this path in SAP
ABAPDOCU(Transaction)>ABAP Database Access>Open SQL>Read data>Inner Join.
you can find the following code*
DATA: BEGIN OF wa,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
fldate TYPE sflight-fldate,
bookid TYPE sbook-bookid,
END OF wa,
itab LIKE SORTED TABLE OF wa
WITH UNIQUE KEY carrid connid fldate bookid.
SELECT pcarrid pconnid ffldate bbookid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( spfli AS p
INNER JOIN sflight AS f ON pcarrid = fcarrid AND
pconnid = fconnid )
INNER JOIN sbook AS b ON bcarrid = fcarrid AND
bconnid = fconnid AND
bfldate = ffldate )
WHERE p~cityfrom = 'FRANKFURT' AND
p~cityto = 'NEW YORK' AND
fseatsmax > fseatsocc.
LOOP AT itab INTO wa.
AT NEW fldate.
WRITE: / wa-carrid, wa-connid, wa-fldate.
ENDAT.
WRITE / wa-bookid.
ENDLOOP.
Reward if helpfull
Regards,
Adithya M -
Hi,
select sum( a~dmbtr )
into o_debit
from bsik as A inner join FAGLFLEXA as B
on abukrs = bRBUKRS
and agjahr = bRYEAR
and abelnr = bdocnr
where a~bukrs = x_bukrs
and a~lifnr = p_lifnr
and a~shkzg = 'S'
and a~budat in s_budat
and a~hkont gt '0000000000'
and a~hkont le '9999999999'
and b~prctr = p_prctr.
Above query is not giving result in o_debit though data is available in both the table. Please guide me, if I have written something wrong.Hi, Raj.
Test the following Sample It is working fine for me hope will work for you too, I did some little change.
TYPES: BEGIN OF ty_test,
dmbtr LIKE bsik-dmbtr,
END OF ty_test.
DATA: it_test TYPE STANDARD TABLE OF ty_test WITH HEADER LINE.
SELECT SUM( a~dmbtr ) as dmbtr
INTO CORRESPONDING FIELDS OF TABLE it_test
FROM bsik AS a INNER JOIN faglflexa AS b ON ( a~bukrs = b~rbukrs AND a~gjahr = b~ryear AND a~belnr = b~docnr )
WHERE a~bukrs = x_bukrs
AND a~lifnr = p_lifnr
AND a~shkzg = 'S'
AND a~budat IN s_budat
AND a~hkont GT '0000000000'
AND a~hkont LE '9999999999'
AND b~prctr = p_prctr.
Please Reply if still any Issue,
Best Regards,
Faisal -
Hi All,
I am using this inner Join Statement
SELECT *
FROM vbap AS a INNER JOIN vbak AS b
ON avbeln = bvbeln
AND amandt = bmandt
WHERE a~vbeln IN lr_vbeln AND
a~posnr IN lr_posnr AND
a~aedat IN lr_aedat AND
( b~vbtyp EQ 'A' OR
b~vbtyp EQ 'B' OR
b~vbtyp EQ 'G' ).
But when i see the Output, One of the field ERDAT is geeting picked up from VBAK table instead of VBAP table.
Any pointers on how can we select the ERDAT from VBAP using this inner Join.
I dont want to use 2 select stetements.
Regards,
MayankIn Inner join, it is always advisable to put the header table as First table and secondly, it should be advisable to fetch only the requried fields. I believe that you might not required all the fields of VBAP table.
Select A~Vbeln
A~vbtyp
B~posnr
B~erdat
into table I_VBAP
from vbak as A innner Join VBAP as B
on a~vbeln = b~vbeln
where a~vbeln IN lr_vbeln AND
b~posnr IN lr_posnr AND
b~aedat IN lr_aedat AND
( a~vbtyp EQ 'A' OR
a~vbtyp EQ 'B' OR
a~vbtyp EQ 'G' ). -
Dynamic BD table name with inner join.
Hi experts,
I'm trying to do something like this:
if syst-datum(4) > s_budat-high(4) or
syst-datum4(2) > s_budat-high4(2).
tabname = 'MBEWH'.
else.
tabname = 'MBEW'.
endif.
select m1matnr m1mtart m3~bwkey
from ( mara as m1
inner join marc as m2
on m1matnr = m2matnr
inner join (tabname) as m3
on m1matnr = m3matnr and
m2werks = m3bwkey )
where m1~matnr in s_matnr and
m1~lvorm in s_lvorm and
m1~mstae in s_mstae and
m2~werks in s_werks.
endselect.
I get the following error: Incorrect expression "1000 %_#T953" in WHERE condition.
Should I forget the inner join with one dynamic table or is it possible to do?
Thanks in advance, best regards,
André CostaHi experts,
I'm trying to do something like this:
if syst-datum(4) > s_budat-high(4) or
syst-datum4(2) > s_budat-high4(2).
tabname = 'MBEWH'.
else.
tabname = 'MBEW'.
endif.
select m1matnr m1mtart m3~bwkey
from ( mara as m1
inner join marc as m2
on m1matnr = m2matnr
inner join (tabname) as m3
on m1matnr = m3matnr and
m2werks = m3bwkey )
where m1~matnr in s_matnr and
m1~lvorm in s_lvorm and
m1~mstae in s_mstae and
m2~werks in s_werks.
endselect.
I get the following error: Incorrect expression "1000 %_#T953" in WHERE condition.
Should I forget the inner join with one dynamic table or is it possible to do?
Thanks in advance, best regards,
André Costa
Maybe you are looking for
-
ME21N-Deliver completed check box in delivey tab to be given user authorzn
In ME21N User A creates the Po for a Quantity 100 Nos & then he makes a MIGO for the qty 60 Nos:He comes back to ME22N in *DELIVERY TAB where in there will be a check box as DELIVERY COMPLETED :He will ensure to tick the same & save. So Other User B
-
With itunes 11.1.3.8, where is the sync button?
With iTunes 11.1.3.8, where is the option to sync my Playlist with my iPhone?
-
Clearing stock in transit (MB5T)
I am unable to clear the stock in transit. We do not necessarily need to receive these small quantities, it would be acceptable to write the stock off to clear this report and remove this stock that does not really exist. I have tried using the Tra
-
Hey guys, This is the problem. My father just got an iPhone 5. He has a Macbook Pro 2009 with OS X 10.5.8. The iPhone is not compatible with this version since the iTunes is an older version as well. At our local Apple store in my home country, they
-
Is there any IDoc like this?
Hi, Can anybody tell me whether the following IDoc exist? AIDMATMAS.MATMAS01 basic type is MATMAS01 Message type is AIDMATMAS