Regarding Inner join query
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
Similar Messages
-
Inner Join. How to improve the performance of inner join query
Inner Join. How to improve the performance of inner join query.
Query is :
select f1~ablbelnr
f1~gernr
f1~equnr
f1~zwnummer
f1~adat
f1~atim
f1~v_zwstand
f1~n_zwstand
f1~aktiv
f1~adatsoll
f1~pruefzahl
f1~ablstat
f1~pruefpkt
f1~popcode
f1~erdat
f1~istablart
f2~anlage
f2~ablesgr
f2~abrdats
f2~ableinh
from eabl as f1
inner join eablg as f2
on f1ablbelnr = f2ablbelnr
into corresponding fields of table it_list
where f1~ablstat in s_mrstat
%_HINTS ORACLE 'USE_NL (T_00 T_01) index(T_01 "EABLG~0")'.
I wanted to modify the query, since its taking lot of time to load the data.
Please suggest : -
Treat this is very urgent.Hi Shyamal,
In your program , you are using "into corresponding fields of ".
Try not to use this addition in your select query.
Instead, just use "into table it_list".
As an example,
Just give a normal query using "into corresponding fields of" in a program. Now go to se30 ( Runtime analysis), and give the program name and execute it .
Now if you click on Analyze button , you can see, the analysis given for the query.The one given in "Red" line informs you that you need to find for alternate methods.
On the other hand, if you are using "into table itab", it will give you an entirely different analysis.
So try not to give "into corresponding fields" in your query.
Regards,
SP. -
Help with Inner Join query in SQL
Hope someone can help with this, as this is quite an involved project for me, and I'm just about there with it.
My table structure is :
table_packages
packageID
package
packageDetails
etc
table_destinations
destinationID
destination
destinationDetails
etc
table_packagedestinations
packageID
destinationID
..so nothing that complicated.
So the idea is that I can have a package details page which shows the details of the package, along any destinations linked to that package via the packagedestinations table.
So this is the last part really - to get the page to display the destinations, but I'm missing something along the way....
This is the PHP from the header, including my INNER JOIN query....
PHP Code:
<?php
$ParampackageID_WADApackages = "-1";
if (isset($_GET['packageID'])) {
$ParampackageID_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
$ParamSessionpackageID_WADApackages = "-1";
if (isset($_SESSION['WADA_Insert_packages'])) {
$ParamSessionpackageID_WADApackages = (get_magic_quotes_gpc()) ? $_SESSION['WADA_Insert_packages'] : addslashes($_SESSION['WADA_Insert_packages']);
$ParampackageID2_WADApackages = "-1";
if (isset($_GET['packageID'])) {
$ParampackageID2_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
mysql_select_db($database_connPackages, $connPackages);
$query_WADApackages = sprintf("SELECT packageID, package, costperpax, duration, baselocation, category, dateadded, agerange, hotel, educational_tours, field_trips, corporate_outings, plant_visits, budget_package, rollingtours, teambuilding, description, offer FROM packages WHERE packageID = %s OR ( -1= %s AND packageID= %s)", GetSQLValueString($ParampackageID_WADApackages, "int"),GetSQLValueString($ParampackageID2_WADApackages, "int"),GetSQLValueString($ParamSessionpackageID_WADApackages, "int"));
$WADApackages = mysql_query($query_WADApackages, $connPackages) or die(mysql_error());
$row_WADApackages = mysql_fetch_assoc($WADApackages);
$totalRows_WADApackages = mysql_num_rows($WADApackages);
$colname_educationalDestinations = "1";
if (isset($_GET['PackageID'])) {
$colname_educationalDestinations = (get_magic_quotes_gpc()) ? packageID : addslashes(packageID);
mysql_select_db($database_connPackages, $connPackages);
$query_educationalDestinations = sprintf("SELECT * FROM destinations INNER JOIN (packages INNER JOIN packagedestinations ON packages.packageID = packagedestinations.packageID) ON destinations.destinationID = packagedestinations.destinationID WHERE packages.packageID = %s ORDER BY destination ASC", GetSQLValueString($colname_educationalDestinations, "int"));
$educationalDestinations = mysql_query($query_educationalDestinations, $connPackages) or die(mysql_error());
$row_educationalDestinations = mysql_fetch_assoc($educationalDestinations);
$totalRows_educationalDestinations = mysql_num_rows($educationalDestinations);
?>
And where I'm trying to display the destinations themselves, I have :
<table>
<tr>
<td>Destinations :</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_educationalDestinations['destination']; ?></td>
</tr>
<?php } while ($row_educationalDestinations = mysql_fetch_assoc($educationalDestinations)); ?>
</table>
If anyone could have a quick look and help me out that would be much appreciated - not sure if its my SQL at the top, or the PHP in the page, but either way it would be good to get it working.
Thanks.First off, you need to get the database tables so that there is a relationship between them.
In fact, if there is a one to one relationship, then it may be better to store all of your information in one table such as
table_packages
packageID
package
packageDetails
destination
destinationDetails
etc
If there is a one to many relationship, then the following would be true
packages
packageID
package
packageDetails
etc
destinations
destinationID
packageID
destination
destinationDetails
etc
The above assumes that there are many destinations to one package with the relationship coloured orange.
Once you have the above correct you can apply your query as follows
SELECT *
FROM packages
INNER JOIN destinations
ON packages.packageID = destinations.packageID
WHERE packages.packageID = %s
ORDER BY destination ASC
The above query will show all packages with relevant destinations -
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 -
Hi ABAPers,
I was trying to develop a report for which query is something like this.
*& Report ZT_SERIAL
REPORT ZT_SERIAL.
TABLES : SER01,SER03,OBJK,LIKP,LIPS. " LIKP - SD invoice header table, LIPS - SD invoice details table
TYPE-POOLS: SLIS.
DATA: AFIELD TYPE SLIS_FIELDCAT_ALV.
DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
MANDATORY WHILE DECLARING ALV ***
DATA: L_FIELDCAT TYPE SLIS_FIELDCAT_ALV..
DATA: V_EVENTS TYPE SLIS_T_EVENT.
DATA: LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: P_FIELDTAB TYPE SLIS_T_FIELDCAT_ALV.
DATA: I_TITLE_SL_NO_TRACK TYPE LVC_TITLE VALUE 'SERIAL NO TRACKER'.
DATA : BEGIN OF ITAB OCCURS 0,
OBKNR LIKE OBJK-OBKNR, "OBJECT LIST
OBZAE LIKE OBJK-OBZAE, "OBJECT COUNTER
KUNDE LIKE SER01-KUNDE, "CUSTOMER NO
MATNR LIKE OBJK-MATNR, "PART NO
SERNR LIKE OBJK-SERNR, "SERIAL NO
MBLNR LIKE SER03-MBLNR, "GRN/MATERIAL DOC NO
LIEF_NR LIKE SER01-LIEF_NR,"OUTBOUND DELV NO
DATUM LIKE SER01-DATUM, "OUTBOUND DELV DATE
TASER LIKE OBJK-TASER, "HEADER TABLE
ANZSN LIKE SER01-ANZSN, "NO OF SERIAL NOS
VGBEL LIKE LIPS-VGBEL, "SALES ORDER NO
END OF ITAB.
SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_KUNDE FOR SER01-KUNDE,
S_VGBEL FOR LIPS-VGBEL,
S_MATNR FOR OBJK-MATNR,
S_SERNR FOR OBJK-SERNR,
S_MBLNR FOR SER03-MBLNR,
S_LIFNR FOR SER01-LIEF_NR,
S_DATUM FOR SER01-DATUM.
SELECTION-SCREEN : END OF BLOCK B1.
PERFORM TRACKING.
PERFORM FLDCAT.
PERFORM BUILD_LAYOUT.
***CALL FUNCTION TO DISPLAY IN ALV FORMAT*******
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_GRID_TITLE = I_TITLE_SL_NO_TRACK
IS_LAYOUT = LAYOUT
IT_FIELDCAT = P_FIELDTAB[]
I_SAVE = 'A'
IT_EVENTS = V_EVENTS
TABLES
T_OUTTAB = ITAB.
***END OF CALL FUNCTION
FORM TRACKING.
SELECT OBJKOBKNR OBJKOBZAE OBJKMATNR OBJKSERNR OBJK~TASER
SER01KUNDE SER01LIEF_NR SER01DATUM SER01ANZSN
SER03~MBLNR
LIPS~VGBEL
INTO TABLE ITAB FROM OBJK
INNER JOIN SER01 ON OBJKOBKNR = SER01OBKNR
INNER JOIN SER03 ON OBJKOBKNR = SER03OBKNR
INNER JOIN LIPS ON SER01LIEF_NR = LIPSVBELN
WHERE
OBJKTASER = 'SER01' OR OBJKTASER = 'SER03'.
OBJK~MATNR IN S_MATNR AND
OBJK~SERNR IN S_SERNR AND
SER01~KUNDE IN S_KUNDE AND
SER01~LIEF_NR IN S_LIFNR AND
SER01~DATUM IN S_DATUM AND
SER03~MBLNR IN S_MBLNR AND
LIPS~VGBEL IN S_VGBEL.
ENDFORM.
*& Form fldcat
text
FORM FLDCAT.
PERFORM FLDCAT1 USING 'KUNDE' 'Customer No'.
PERFORM FLDCAT1 USING 'VGBEL' 'Sales Order No'.
PERFORM FLDCAT1 USING 'MATNR' 'Tejas Part No'.
PERFORM FLDCAT1 USING 'SERNR' 'Serial No'.
PERFORM FLDCAT1 USING 'MBLNR' 'Material Doc No'.
PERFORM FLDCAT1 USING 'LIEF_NR' 'Outbound Delv No'.
PERFORM FLDCAT1 USING 'DATUM' 'Outbound Delv Date'.
ENDFORM. "fldcat
*& Form fldcat1
text
-->FNAM text
-->FTEXT text
FORM FLDCAT1 USING FNAM FTEXT.
DATA: L_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
L_FIELDCAT-FIELDNAME = FNAM.
L_FIELDCAT-SELTEXT_M = FTEXT.
IF FNAM EQ 'MATNR'."OR fnam EQ 'PKUNAG'.
L_FIELDCAT-KEY = 'X'.
ENDIF.
LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
APPEND L_FIELDCAT TO P_FIELDTAB.
CLEAR fldcat1.
ENDFORM. "fldcat1
*& Form build_layout
text
FORM BUILD_LAYOUT .
LAYOUT-NO_INPUT = 'X'.
LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
LAYOUT-ZEBRA = 'X'.
LAYOUT-TOTALS_TEXT = 'Totals'(256).
layout-coltab_fieldname = 'CELL_COLOUR'.
*clear layout.
ENDFORM.
But when I run this query,the program gets terminated.Can you please help me in rectifying the query and generate the output?
Thanks in advance
BhavinHi
I have corrected the code please copy and past it and then try.
Report ZT_SERIAL.
TABLES : SER01,SER03,OBJK,LIKP,LIPS.
" LIKP - SD invoice header table, LIPS - SD invoice details table
TYPE-POOLS: SLIS.
DATA: AFIELD TYPE SLIS_FIELDCAT_ALV.
DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
+ MANDATORY WHILE DECLARING ALV ***
DATA: L_FIELDCAT TYPE SLIS_FIELDCAT_ALV..
DATA: V_EVENTS TYPE SLIS_T_EVENT.
DATA: LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: P_FIELDTAB TYPE SLIS_T_FIELDCAT_ALV.
DATA: I_TITLE_SL_NO_TRACK TYPE LVC_TITLE VALUE 'SERIAL NO TRACKER'.
DATA : BEGIN OF ITAB OCCURS 0,
OBKNR LIKE OBJK-OBKNR, "OBJECT LIST
OBZAE LIKE OBJK-OBZAE, "OBJECT COUNTER
KUNDE LIKE SER01-KUNDE, "CUSTOMER NO
MATNR LIKE OBJK-MATNR, "PART NO
SERNR LIKE OBJK-SERNR, "SERIAL NO
MBLNR LIKE SER03-MBLNR, "GRN/MATERIAL DOC NO
LIEF_NR LIKE SER01-LIEF_NR,"OUTBOUND DELV NO
DATUM LIKE SER01-DATUM, "OUTBOUND DELV DATE
TASER LIKE OBJK-TASER, "HEADER TABLE
ANZSN LIKE SER01-ANZSN, "NO OF SERIAL NOS
VGBEL LIKE LIPS-VGBEL, "SALES ORDER NO
END OF ITAB.
SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_KUNDE FOR SER01-KUNDE,
S_VGBEL FOR LIPS-VGBEL,
S_MATNR FOR OBJK-MATNR,
S_SERNR FOR OBJK-SERNR,
S_MBLNR FOR SER03-MBLNR,
S_LIFNR FOR SER01-LIEF_NR,
S_DATUM FOR SER01-DATUM.
SELECTION-SCREEN : END OF BLOCK B1.
PERFORM TRACKING.
PERFORM FLDCAT.
PERFORM BUILD_LAYOUT.
***CALL FUNCTION TO DISPLAY IN ALV FORMAT*******
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_GRID_TITLE = I_TITLE_SL_NO_TRACK
IS_LAYOUT = LAYOUT
IT_FIELDCAT = P_FIELDTAB[]
I_SAVE = 'A'
IT_EVENTS = V_EVENTS
TABLES
T_OUTTAB = ITAB.
***END OF CALL FUNCTION
FORM TRACKING.
*SELECT OBJK~OBKNR
OBJK~OBZAE
OBJK~MATNR
OBJK~SERNR
OBJK~TASER
SER01~KUNDE
SER01~LIEF_NR
SER01~DATUM
SER01~ANZSN
SER03~MBLNR
LIPS~VGBEL
INTO TABLE ITAB FROM OBJK
INNER JOIN SER01 ON OBJKOBKNR = SER01OBKNR
INNER JOIN SER03 ON OBJKOBKNR = SER03OBKNR
INNER JOIN LIPS ON SER01LIEF_NR = LIPSVBELN
WHERE
*( OBJKTASER = 'SER01' OR OBJKTASER = 'SER03' ) and
*OBJK-MATNR IN S_MATNR AND
*OBJK~SERNR IN S_SERNR AND
*SER01~KUNDE IN S_KUNDE AND
*SER01~LIEF_NR IN S_LIFNR AND
*SER01~DATUM IN S_DATUM AND
*SER03~MBLNR IN S_MBLNR AND
*LIPS~VGBEL IN S_VGBEL.
SELECT a~OBKNR "OBJK
a~OBZAE
a~MATNR
a~SERNR
a~TASER
b~KUNDE "SER01
b~LIEF_NR
b~DATUM
b~ANZSN
c~MBLNR "SER03
D~VGBEL "LIPS
INTO TABLE ITAB FROM ( OBJK as a
INNER JOIN SER01 as b ON aOBKNR = bOBKNR
INNER JOIN SER03 as c ON aOBKNR = cOBKNR
INNER JOIN LIPS as d ON bLIEF_NR = dVBELN )
WHERE
( aTASER = 'SER01' OR aTASER = 'SER03' ) and
a~MATNR IN S_MATNR AND
a~SERNR IN S_SERNR AND
b~KUNDE IN S_KUNDE AND
b~LIEF_NR IN S_LIFNR AND
b~DATUM IN S_DATUM AND
c~MBLNR IN S_MBLNR AND
d~VGBEL IN S_VGBEL.
ENDFORM.
*& Form fldcat
* text
FORM FLDCAT.
PERFORM FLDCAT1 USING 'KUNDE' 'Customer No'.
PERFORM FLDCAT1 USING 'VGBEL' 'Sales Order No'.
PERFORM FLDCAT1 USING 'MATNR' 'Tejas Part No'.
PERFORM FLDCAT1 USING 'SERNR' 'Serial No'.
PERFORM FLDCAT1 USING 'MBLNR' 'Material Doc No'.
PERFORM FLDCAT1 USING 'LIEF_NR' 'Outbound Delv No'.
PERFORM FLDCAT1 USING 'DATUM' 'Outbound Delv Date'.
ENDFORM. "fldcat
*& Form fldcat1
text
-->FNAM text
-->FTEXT text
FORM FLDCAT1 USING FNAM FTEXT.
DATA: L_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
L_FIELDCAT-FIELDNAME = FNAM.
L_FIELDCAT-SELTEXT_M = FTEXT.
IF FNAM EQ 'MATNR'."OR fnam EQ 'PKUNAG'.
L_FIELDCAT-KEY = 'X'.
ENDIF.
LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
APPEND L_FIELDCAT TO P_FIELDTAB.
* CLEAR fldcat1.
ENDFORM. "fldcat1
*& Form build_layout
* text
FORM BUILD_LAYOUT .
LAYOUT-NO_INPUT = 'X'.
LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
LAYOUT-ZEBRA = 'X'.
LAYOUT-TOTALS_TEXT = 'Totals'(256).
* layout-coltab_fieldname = 'CELL_COLOUR'.
*clear layout.
ENDFORM.
Regards,
Venkat -
Hi all,
I want to query a inner join via some tools in sap GUI. till now, i could not query a inner join between two tables via SE11. can someone tell are there some other ways to achieve this?
any response will be awarded!
thanks and regards,
samsonhi samson,
Proper use of Inner Join
When multiple SAP tables are logically joined, it is always advisable to use inner join to read the data from them. This certainly reduces the load on the network.
Let us take an example of 2 tables, zairln and zflight. The table zairln has the field airln, which is the airline code and the field lnnam, which is the name of the airline. The table zflight has the field airln, the airline code and other fields which hold the details of the flights that an airline operates.
Since these 2 tables a re logically joined by the airln field, it is advisable to use the inner join.
Select aairln alnnam bfligh bcntry into table int_airdet
example 2:--
Inner join: If you have common fields between 2 or more tables, its betterto use Inner join.
Check the below example:
VBAK & VBAP table has common fields, hence we can use inner join.
SELECT akunnr avbeln anetwr abnddt a~knumv
avkbur aerdat avdatu aaugru
aktext bmatnr barktx bkwmeng b~kzwi6
bvolum bposnr b~kdmat
INTO CORRESPONDING FIELDS OF TABLE g_t_quot
FROM vbak AS a INNER JOIN vbap AS b
ON avbeln = bvbeln
WHERE a~vbeln IN so_vbeln
AND a~trvog ='2'
AND a~vkorg IN so_vkorg
AND a~vtweg IN so_vtweg
AND a~vkbur IN so_vkbur
AND a~audat IN so_audat
AND a~kunnr IN so_kunag.
FOR ALL ENTRIES:
If you get some data into one internal table and if you want to fetch data from other table based on it, use FOR ALL ENTRIES.
g_t_quot is an internal table.
SELECT spras augru bezei FROM tvaut INTO TABLE g_t_tvaut
FOR ALL ENTRIES IN g_t_quot
WHERE augru = g_t_quot-augru AND spras = sy-langu.
From zairln as a inner join zflight as b on aairln = bairln.
In order to restrict the data as per the selection criteria, a where clause can be added to the above inner join. -
hey guys,
I have below inputs for the screen
ZWADAT_IST -Actual goods movement date
ZKUNNR- shipto party
ZVGBEL-
ZVBELN-
ZPOSNR-
ZBUNKATU-
Depends on the input, i have to retrieve necessary fields from various related tables and display in screen .
ZSDTB_LOT is the add on table where we can access few fields as below. Now i want to write QUERY using join to fetch the fields from different tables like LIKP,LIPS,ZSDTB_LOT,ADRC according to the inputs
and display in table control.
I am not good in writing SELECT JOIN statement to retrieve fields in effecient way. could somebody help me
giving equavalent code for this...
<b>
Select
LIKP-WADAT_IST,
LIKP-VSTEL(shipping point)
LIKP-KUNNR
LIKP-LFART(delievery type)
LIPS-VKBUR
LIPS-MATNR
LIPS-VGBEL
ZSDTB_LOT-VBELN
ZSDTB_LOT-BUNKATSU
ZSDTB_LOT-POSNR
ZSDTB_LOT-LOTB
ZSDTB_LOT-LGMNG
ADRC-NAME1
FROM ZSDTB_LOT,LIKP,LIPS,ADRC
WHERE WADAT_IST IN ZWADAT_IST AND
KUNNR IN ZKUNNR AND
VGBEL IN ZVGBEL AND
VBELN IN ZVBELN AND
POSNR IN ZPOSNR AND
BUNKATU IN ZBUNKATU.</b>
ambichan.I will try to avoid a big join on so many tables. Instead I will do something like this.
DATA: BEGIN OF deliveries OCCURS 0,
vbeln LIKE likp-vbeln,
lfart LIKE likp-lfart,
wadat_1st LIKE likp-wadat_1st,
vstel LIKE likp-vstel,
kunnr LIKE likp-kunnr,
posnr LIKE lips-posnr,
matnr LIKE lips-matnr,
vkbur LIKE lips-vkbur,
vgbel LIKE lips-vgbel.
DATA: END OF deliveries.
DATA: BEGIN OF ztab_entries OCCURS 0,
vbeln LIKE zsdtb_lot-vbeln,
posnr LIKE zsdtb_lot-posnr,
lotb LIKE zsdtb_lot-lotb,
lgmng LIKE zsdtb_lot-lgmng,
bunkatsu LIKE zsdtb_lot-bunkatsu.
DATA: END OF ztab_entries.
SELECT likp~vbeln likp~lfart likp~wadat_1st
likp~vstel likp~kunnr lips~posnr
lips~matnr lips~vkbur lips~vgbel
FROM likp as likp INNER JOIN lips as lips
ON likp~vbeln = lips~vbeln
INTO TABLE deliveries
WHERE lips~vbeln IN zvbeln
AND lips~posnr IN zposnr.
IF NOT deliveries[] IS INITIAL.
DELETE deliveries WHERE NOT
( wadat_1st IN zwadat_1st AND
kunnr IN zkunnr AND
vgbel IN zvgbel ).
ENDIF.
SELECT vbeln posnr lotb
lgmng bunkatsu
FROM zsdtb_lot FOR ALL ENTRIES IN deliveries
INTO TABLE ztab_entries
WHERE vbeln = deliveries-vbeln
AND posnr = deliveries-posnr.
IF NOT ztab_entries[] IS INITIAL.
DELETE ztab_entries WHERE NOT bunkatu IN zbunkatu.
ENDIF.
*-- Once we have these two internal tables then we can
* prepare the final table by looping through them
SORT deliveries BY vbeln posnr.
SORT ztab_entries BY vbeln posnr.
LOOP AT deliveries.
CLEAR ztab_entries.
READ TABLE ztab_entries WITH KEY vbeln = deliveries-vbeln
posnr = deliveries-vbeln
BIANRY SEARCH.
SELECT SINGLE name1 INTO final_tab-name1
FROM KNA1
WHERE kunnr = deliveries-kunnr.
MOVE-CORRESPONDING: deliveries TO final_tab,
ztab_entries TO final_tab.
APPEND final_tab.
CLEAR final_tab.
ENDLOOP.
This way you will be selecting records from the database with the index of the primary key and then you can manipulate the selected entries as you wish.
Hope this helps,
Srinivas -
I have this query, however... I need the 'category' variable
to be 'LIKE' but the way I have it set up it doent work. Anyone
have an idea of how I might fix this.
<CFQUERY name="getworkshops" datasource="source">
SELECT m.category, m.proj_key, m.project, r.proj_key, r.url,
r.category, r.end_date, r.title, e.event_date, e.event_date_end,
e.category, e.proj_key
FROM (main m INNER JOIN resource r ON m.category LIKE
r.category)INNER JOIN event_cal e ON m.category LIKE e.category
WHERE m.category like '%workshop%' AND m.proj_key=r.proj_key
AND m.proj_key = e.proj_key
ORDER BY m.proj_key
</CFQUERY>You could move your join statements to your where clause:
SELECT m.category, m.proj_key, m.project, r.proj_key, r.url,
r.category, r.end_date, r.title, e.event_date, e.event_date_end,
e.category, e.proj_key
FROM main m, resource r, event_cal e
WHERE m.category LIKE '%'+r.category+'%'
AND m.category LIKE '%" + e.category + '%'
AND m.category like '%workshop%' AND m.proj_key=r.proj_key
AND m.proj_key = e.proj_key
ORDER BY m.proj_key
I had to guess on how you wanted to match m.category against
resource and event_cal, but you get the idea. -
Alias for field in inner join query
In my Oracle 9i Schema, I have two tables:TableOne
pocOne pocTwo
2 3
2 4
1 2
TableTwo
TableTwoId Name
1 Jones
2 Smith
3 Edwards
4 CamdenMy SQL that works to fetch all records with Smith works great:select Name from TableTwo
Inner Join TableOne
on TableTwo.TableTwoId in (TableOne.pocOne, TableOne.pocTwo)
where Name = 'Smith' Now I need to create an alias for the Name field. Here is my attempt:select myAliasName from TableTwo
Inner Join TableOne
on TableTwo.TableTwoId in (TableOne.pocOne, TableOne.pocTwo), (select Name as myAliasName from TableTwo)
where myAliasName = 'Smith' This attempt pulls up all the records instead of just Smith records. Please advise how I can create an alias for the Name field in my above query?Are you just looking for
select Name AS AliasName
from TableTwo Inner Join TableOne
on TableTwo.TableTwoId in (TableOne.pocOne, TableOne.pocTwo)
where Name = 'Smith' Justin -
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 -
Inner join query not working properly
Hi everyone,
It does not gives any error, but it is not fetching any values...but when i dont include fourth table CSKT AND THE FIELD LTEXT it is fetching the values.
SELECT SINGLE
T1~PERNR
T1~BEGDA
T1~ENAME
T1~PLANS
T1~KOSTL
T2~STRAS
T2~PSTLZ
T2~ORT01
T3~PLSTX
T4~LTEXT
INTO FS_TAB
FROM PA0001 AS T1
INNER JOIN PA0006 AS T2 ON T1PERNR eq T2PERNR
INNER JOIN T528T AS T3 ON T1PLANS EQ T3PLANS
INNER JOIN CSKT AS T4 ON T1KOSTL EQ T4KOSTL
WHERE T1~PERNR eq p_pernr.Change like this
SELECT SINGLE
T1~PERNR
T1~BEGDA
T1~ENAME
T1~PLANS
T1~KOSTL
T2~STRAS
T2~PSTLZ
T2~ORT01
T3~PLSTX
T4~LTEXT
INTO FS_TAB
FROM PA0001 AS T1
INNER JOIN PA0006 AS T2 ON T1~PERNR eq T2~PERNR
INNER JOIN T528T AS T3 ON T1~PLANS EQ T3~PLANS
LEFT OUTER JOIN CSKT AS T4 ON T1~KOSTL EQ T4~KOSTL
WHERE T1~PERNR eq p_pernr.
OR
SELECT SINGLE
T1~PERNR
T1~BEGDA
T1~ENAME
T1~PLANS
T1~KOSTL
T2~STRAS
T2~PSTLZ
T2~ORT01
T3~PLSTX
T4~LTEXT
INTO FS_TAB
FROM PA0001 AS T1
LEFT OUTER JOIN PA0006 AS T2 ON T1~PERNR eq T2~PERNR
LEFT OUTER JOIN T528T AS T3 ON T1~PLANS EQ T3~PLANS
LEFT OUTER JOIN CSKT AS T4 ON T1~KOSTL EQ T4~KOSTL
WHERE T1~PERNR eq p_pernr.
as long as the table is not used in where condition, u can use left outter join. -
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. -
hello all,
Below is a inner join query
SELECT aebeln aebelp apackno bzekkn b~ps_psp_pnr
FROM ( ( ekpo AS a INNER JOIN ekkn AS b
ON aebeln = bebeln
AND aebelp = bebelp )
INNER JOIN prps AS c
ON bps_psp_pnr = cpspnr )
INTO TABLE t_wbspo
WHERE a~ebeln IN s_ebeln
AND c~psphi IN s_psphi
AND stufe = c_task.
I want to modify this select and put one more join on ekkn-aufnr
and aufk-afunr .
Now for this i write the below code
SELECT aebeln aebelp apackno bzekkn bps_psp_pnr baufnr
FROM ( ( ( ekpo AS a INNER JOIN ekkn AS b
ON aebeln = bebeln
AND aebelp = bebelp )
INNER JOIN prps AS c
ON bps_psp_pnr = cpspnr )
INNER JOIN aufk AS d
ON baufnr = daufnr )
INTO TABLE t_wbspo
WHERE a~ebeln IN s_ebeln
AND c~psphi IN s_psphi
AND d~aufnr IN s_aufnr
AND stufe = c_task.
By the above way does it puts a join on ekkn-aufnr and aufk-aufnr ?
Is the above way the right way to do it ?
Please confirm
regardsHello Bhanu,
Do you face any performance issue? Query looks good now, further you can refer to following threads to know more on JOIN-
Re: Inner join
http://help.sap.com/saphelp_nw04/helpdata/en/cf/21ec77446011d189700000e8322d00/frameset.htm
Thank You,
Nishikant Kumbhar.
Maybe you are looking for
-
Report for Depot Excise Invoice
Hi Friends, We need to find out the commercial invoice number for an existing Depot excise invoice directly without having to go into delivery and look into the document flow. Do we have any standard report where we can see both the Depot excise invo
-
My iPad keeps telling me that I am up to date with iOS 5.1.1. What do I need to do to download and install iOS 6?
-
Error while using UTP_MAIL package in oracle 10g
Hi, I am using the UTP_MAIL package to send a mail from oracle 10g. I hane connected to the database as sysdba,but while setting the SMTP_SERVER_OUTPUT parameter i get the following error. SQL> ALTER SYSTEM SET smtp_out_server='blrkecmbx02.ad.abc.com
-
So I've been trying to organize my music lately, and have it all on my Seagate external hard drive. I was trying to move a large chunk of folders with music in them to a different folder, and when I dragged it over, it tried to start moving them when
-
Pacman -Syu update, System not booting due to systemd
I have just done a full update on pacman, and now my system is not booting due to this message systemd[1]: /usr/lib/systemd/system-generators/systemd-gpt-auto-generator exited with status 127 Does anyone know what is causing this, and what a status c