Select querry using inner join
Hi Friends,
I need to fetch data from two tables, I used inner join but I am not able to fetch the data in some fields can any one tell me what is wrong in this select querry.
SELECT but000~partner
but000~name_org1
but000~name_first
but000~name_last
but000~bpext
FROM but000 INNER JOIN dfkkop ON but000partner = dfkkopgpart
INTO table lt_but000
WHERE but000~partner IN so_part
AND dfkkop~faedn IN so_faedn.
Thanx in advance,
Parvez
hi Lutin,
SELECT but000~partner
but000~name_org1
but000~name_first
but000~name_last
but000~bpext
FROM but000 INNER JOIN dfkkop ON but000partner = dfkkopgpart <------check this condition,it has to *satisfy both table
INTO table lt_but000
WHERE but000~partner IN so_part
AND dfkkop~faedn IN so_faedn.
Regards,
siva
Message was edited by:
SivaKumar
Similar Messages
-
Issue when suming the field in Select query using inner join
Hi All,
SELECT A~OI_SHNUM
A~FORWAGENT
A~ROUTE
A~SHTYP
A~DTSHP_EACT
A~/BIC/GTCLICENS
A~/BIC/GTCADD04
A~COMP_CODE
SUM( C~GRS_WGT_DL )
C~UNIT_OF_WT
INTO TABLE I_LAYONE
FROM ( ( /BIC/ANTCD000200 AS A
INNER JOIN /BIC/AGSSD000700 AS B ON BOI_SHNUM = AOI_SHNUM )
INNER JOIN /BIC/AGSSD000600 AS C ON CDELIV_NUMB = BDELIV_NUMB ).
I need to sum the field C~GRS_WGT_DL
While compiling it show the error given below
The field "C~UNIT_OF_WT" from the SELECT list is is missing in the
GROUP BY clause. is missing in the GROUP BY clause. is missing in the
GROUP BY clause. is missing in the GROUP BY clause. is missing in the
GROUP BY clause. is "C~UNIT_OF_W
with regards,
ThambeHi,
Try the following SQL statement. Hope it helps you.
SELECT A~OI_SHNUM
A~FORWAGENT
A~ROUTE
A~SHTYP
A~DTSHP_EACT
A~/BIC/GTCLICENS
A~/BIC/GTCADD04
A~COMP_CODE
SUM( C~GRS_WGT_DL )
C~UNIT_OF_WT
INTO TABLE I_LAYONE
FROM ( ( /BIC/ANTCD000200 AS A
INNER JOIN /BIC/AGSSD000700 AS B ON BOI_SHNUM = AOI_SHNUM )
INNER JOIN /BIC/AGSSD000600 AS C ON CDELIV_NUMB = BDELIV_NUMB )
GROUP BY
A~OI_SHNUM
A~FORWAGENT
A~ROUTE
A~SHTYP
A~DTSHP_EACT
A~/BIC/GTCLICENS
A~/BIC/GTCADD04
A~COMP_CODE.
Murthy. -
How to use INNER JOIN in such case
when i program as below[CASE1]. the code is able to active.
CASE1:
==========================
DATA: WK_BUKRS LIKE T001-BUKRS,
WK_BUTXT LIKE T001-BUTXT,
WK_TABLE(4) TYPE C VALUE 'T001'.
START-OF-SELECTION.
WK_BUKRS = 'DECN'.
PERFORM GET_BUTXT USING WK_BUKRS WK_TABLE
CHANGING WK_BUTXT.
WRITE: WK_BUTXT.
FORM GET_BUTXT USING I_BUKRS LIKE T001-BUKRS
I_TABLE
CHANGING O_BUTXT LIKE T001-BUTXT.
SELECT SINGLE BUTXT
INTO O_BUTXT
FROM (I_TABLE)
WHERE BUKRS = I_BUKRS.
ENDFORM.
===========================
but when I need to INNER JOIN another table [CASE2]
CASE2:
=======================
DATA: WK_BUKRS LIKE T001-BUKRS,
WK_BUTXT LIKE T001-BUTXT,
WK_TABLE(4) TYPE C VALUE 'T001'.
START-OF-SELECTION.
WK_BUKRS = 'DECN'.
PERFORM GET_BUTXT USING WK_BUKRS WK_TABLE
CHANGING WK_BUTXT.
WRITE: WK_BUTXT.
FORM GET_BUTXT USING I_BUKRS LIKE T001-BUKRS
I_TABLE
CHANGING O_BUTXT LIKE T001-BUTXT.
SELECT SINGLE BUTXT
INTO O_BUTXT
FROM (I_TABLE) AS G INNER JOIN BKPF AS H
ON GBUKRS = HBUKRS
WHERE G~BUKRS = I_BUKRS.
ENDFORM.
=================================
Syntax error:
Wrong expression "INNER" in FROM clause. WHERE condition.
Can anybody help me to solve the problem.
My requirement is to use INNER JOIN with variable tablehi slam,
chk this sample code.
hi,
table emp
empno name
a sasi
b xxx
c yyy
table sal
empno salary
a 1000
b 2000
Inner join
select eempno ename
s~sal
into table int_table
from emp as e
inner join sal as s
on
eempno = sempno.
if you made inner join between table a and b by emp no
the selection retrives only if the condition satisfy the output will be
a sasi 1000
b xxx 2000
rgds
anver
if hlped mark points
Message was edited by: Anversha s -
I need to delete records from a table using inner join from other tables. See below for the table structure and records.
CREATE TABLE STUDENT (ROLL_NO NUMBER(10),NAME VARCHAR2(100),DEPT_NO NUMBER(10),JOIN_DATE DATE);
CREATE TABLE DEPART (DEPT_NO NUMBER(10), DEPT_NAME VARCHAR2(100));
CREATE TABLE ACTIVE_DEPT (DEPT_NO NUMBER(10), IS_ACTIVE VARCHAR2(1));
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(1,'SAM',10,SYSDATE-10);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(2,'ALEX',10,SYSDATE -10);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(3,'FRANK',20,SYSDATE -10);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(4,'WAYNE',20,SYSDATE+1);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(5,'KRUL',30,SYSDATE -10);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(6,'ALICE',40,SYSDATE -10);
INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (10,'DEPT1');
INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (20,'DEPT2');
INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (30,'DEPT3');
INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (10,'Y');
INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (20,'N');
INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (30,'Y');
DELETE FROM STUDENT WHERE (STUDENT.DEPT_NO) IN (SELECT D.dept_no FROM DEPART D,ACTIVE_DEPT AD WHERE D.DEPT_NO = AD.DEPT_NO AND AD.IS_ACTIVE = 'N');The above delete query will delete two records from the STUDENT table. Now i want to include another condition say, join_date should be a past date (join_date < trunc(sysdate)).
How to include this condition in the above delete statement. I know i can do this using a subquery but i wont prefer that option. Basically i don't have much idea about join in delete statements.
Please help.Is this you need ?
DELETE FROM student WHERE join_date < TRUNC(SYSDATE)
AND student.dept_no IN (SELECT D.dept_no
FROM depart d,active_dept ad
WHERE d.dept_no = ad.dept_no AND ad.is_active = 'N');Only one record is deleted. -> 3,'FRANK',20,SYSDATE -10
>
Balaji wrote:
Yes. But here we are getting the dept_no from the sub query, is there a better way to achieve this without sub query?
>
As far I know you need to have sub query in this case.
You can close this thread if answered. If you have any further queries please post it so that someone can help you.
Edited by: Lokanath Giri on २० मार्च, २०१२ ५:०५ अपराह्न -
Relationship between tables while using inner joins.
Hi,
I had a few clarifications on "inner joins", and as i was going through the forum, i came across two points,
1. In one of the threads it said " inner joins is applicable for tables that have a parent child relationship.
2. In another thread it said " inner join is established from master table (the table on the left) to the transcation table (the table on the right)".
I have two clarifications based on the above points.
1. Is it necessary that the tables on which im performing an inner join should have a parent-child/children relationship or is it enough that the tables just have a common field.
2. Also is it necessary that the master table should come first, (or can i use any child table from where i can fetch the records when there is a mater table in my report) as shown below.
Eg: select * <fields> from <master table> inner join <table> on <field> into <itab>.
Edited by: Narayananchandran on Dec 27, 2010 12:31 PMhave two clarifications based on the above points.
1. Is it necessary that the tables on which im performing an inner join should have a parent-child/children relationship or is it enough that the tables just have a common field.
2. Also is it necessary that the master table should come first, (or can i use any child table from where i can fetch the records when there is a mater table in my report) as shown below.
Eg: select * <fields> from <master table> inner join <table> on <field> into <itab>
1) NO
2) NO -
How to use Inner join of table as Source in Merge statement in SQL
Hi All,
I am trying to make source as multiple tables output using Join while coding there is no any syntax error but when i am executing this statement is giving following error
Following is the query
Merge Into EmpDept Target
Using (select E.Address,e.Design,e.EmailId,e.EmpId,e.Ename,e.ManagerId, e.Salary,D.DeptId,D.DeptName,D.Location from Employee E Inner join Dept D on E.DeptId=D.DeptId )As Source (Address,Design,EmailId,EmpId,EName,ManagerId,Salary,DeptId,DeptName,Location)
On Source.EmpId=Target.EmpId
when not matched then
Insert (Target.Address,Target.Design,Target.EmailId,Target.EmpId,Target.Ename,Target.ManagerId, Target.Salary,Target.DeptId,Target.DeptName,Target.Location)
values
(Address,Design,EmailId,EmpId,EName,ManagerId, Salary,DeptId,DeptName,Location)
When matched then
Update set Target.Address = Source.Address ,Target.Design = Source.Design,Target.EmailId = Source.EmailId ,Target.Ename = Source.Ename ,Target.ManagerId = Source.ManagerId , Target.Salary = Source.Salary ,Target.DeptId = Source.DeptId ,Target.DeptName = Source.DeptName ,Target.Location = Source.Location;
This is error while executing the above merge statement
The insert column list used in the MERGE statement cannot contain multi-part identifiers. Use single part identifiers instead.
Please suggest me where i am wrong..
Niraj SevalkarMERGE INTO EmpDept Target
Using (SELECT E.Address,
e.Design,
e.EmailId,
e.EmpId,
e.Ename,
e.ManagerId,
e.Salary,
D.DeptId,
D.DeptName,
D.Location
FROM Employee E
INNER JOIN Dept D
ON E.DeptId = D.DeptId) AS Source (Address, Design, EmailId, EmpId, EName, ManagerId, Salary, DeptId, DeptName, Location)
ON Source.EmpId = Target.EmpId
WHEN NOT matched THEN
INSERT (Address,
Design,
EmailId,
EmpId,
Ename,
ManagerId,
Salary,
DeptId,
DeptName,
Location)
VALUES (Address,
Design,
EmailId,
EmpId,
EName,
ManagerId,
Salary,
DeptId,
DeptName,
Location)
WHEN matched THEN
UPDATE SET Address = Source.Address,
Design = Source.Design,
EmailId = Source.EmailId,
Ename = Source.Ename,
ManagerId = Source.ManagerId,
Salary = Source.Salary,
DeptId = Source.DeptId,
DeptName = Source.DeptName,
Location = Source.Location; -
Select SUM( ) in inner join - error in code
Hi All,
The following code is using ABAP OO and I get the following error
E:The addition "FOR ALL ENTRIES" excludes all aggregate functions with
the exception of "COUNT( * )", as the single element of the SELECT
clause.
Here is the Code:
select a/bic/ZEDM_ENTP amaterial a~/bic/zedm_stid
a/bic/ZEDM_SDT a/bic/ZEDM_MINH a~/bic/ZEDM_EHD
SUM( b~/bic/ZEDM_QPLN )
c~/bic/ZDEMQTY
from /bic/azdrp_1900 as a inner join /bic/azdrp_0400 as b
on
a/bic/ZEDM_ENTP = b/bic/ZEDM_ENTP and
amaterial = bmaterial and
a/bic/zedm_stid = bplant and
a/bic/ZEDM_SDT = b/bic/zedm_pshp
inner join /bic/azrp_0800 as C
on
amaterial = cmaterial and
a/bic/zedm_stid = c/bic/zedm_stid and
a/bic/ZEDM_SDT = c/bic/ZEDM_ESDT
into table z_it_inv for all entries in
RESULT_PACKAGE where
a~/bic/ZEDM_ENTP = RESULT_PACKAGE-/bic/ZEDM_ENTP
and a~material = RESULT_PACKAGE-material
and a~/bic/ZEDM_SDT = RESULT_PACKAGE-/BIC/OIZEDM_EDT
and a~/bic/zedm_stid = RESULT_PACKAGE-/BIC/OIZEDM_TOST
group by b/bic/ZEDM_ENTP bmaterial b~plant
b~/bic/zedm_pshp
Can you please tell me how to correct this?
ThanksHi,
You can get all records first and then LOOP AT Internal table and use COLLECT statement to sum up required column.
This will be a better idea than trying to use SUM in SELECT with JOINS.
ashish -
Dear Experts,
I have writen a inner join code with MKPF and MSEG which taking too much time, while I have used index.
Indexes are:
MSEG
MATNR
WERKS
LGORT
BWART
SOBKZ
MKPF
BUDAT
MBLNR
My Select Query is :
SELECT B~MATNR
B~MAT_KDAUF
B~MAT_KDPOS
B~BWART
B~MENGE
B~MEINS
B~AUFNR
INTO TABLE IT_MSEG
FROM MKPF AS A
INNER JOIN MSEG AS B
ON AMBLNR EQ BMBLNR
AND AMJAHR EQ BMJAHR
WHERE A~BUDAT IN BUDAT
AND B~MATNR IN MATNR
AND B~WERKS IN WERKS
AND B~LGORT IN LGORT
AND B~BWART IN BWART.hi,
you can use for all entries it will work faster then joins
About it:*
FOR ALL ENTRIES WHERE
Syntax
... FOR ALL ENTRIES IN itab WHERE ... col operator itab-comp ...
Effect
If the addition FOR ALL ENTRIES is specified before the language element WHERE, then the components comp of the internal table itab can be used as operands when comparing with relational operators.
The internal table itab must have a structured line type and the component comp must be compatible with the column col.
The logical expression sql_cond of the WHERE condition can comprise various logical expressions by using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one Comparison with a column of the internal table itab, which can be specified either statistically or dynamically (Release 6.40 and higher). In a statement with a SELECTstatement with FOR ALL ENTRIES, the addition ORDER BY can only be used with the addition PRIMARY KEY.
The whole logical expression sql_cond is evaluated for each individual line of the internal table itab. The resulting set of the SELECT statement is the union of the resulting sets from the individual evaluations. Duplicate lines are automatically removed from the resulting set. If the internal table itab is empty, the whole WHERE statement is ignored and all lines in the database are put in the resulting set.
Notes
In Release 6.10 and higher, the same internal table can be specified after FOR ALL ENTRIES and after INTO.
The addition FOR ALL ENTRIES is only possible before WHERE conditions of the SELECT statement.
Example
Exporting all flight data for a specified departure city. The relevant airlines and flight numbers are first put in an internal table entry_tab, which is evaluated in the WHERE condition of the subsquent SELECT statement.
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.
hope it will help you
Rahul sharma
Edited by: RAHUL SHARMA on Sep 11, 2008 8:10 AM -
How to use BKPF and BSEG without using inner join
Hi,
can anybody plz tell me the logic about how to complete the report without inner joining bkpf and bseg.Is this report can be really be made by using only bseg,bkpf ?
*selection-criteria .
BKPF-USNAM
BKPF-CPUDT
BKPF-BUDAT
BKPF-GJAHR
BKPF-BUKRS
BKPF-BELNR
BSEG-SAKNR
BSEG-LIFNR
BSEG-KUNNR
BSEG-ZUONR
BSEG-SGTXT
Output fields required.
BKPF-BUKRS
BKPF-BELNR
BKPF-GJAHR
BKPF-MONAT
BKPF-BLART
BKPF-CPUDT
BKPF-BLDAT
BKPF-BUDAT
BKPF-USNAM
BKPF-XBLNR
BKPF-STBLG
BKPF-BKTXT
BKPF-WAERS
BKPF-KURSF
BSEG-BUZEI
BSEG-BSCHL
BSEG-KOART
BSEG-UMSKZ
BSEG-SHKZG
BSEG-MWSKZ
BSEG-PSWBT
BSEG-PSWSL
BSEG-DMBTR
BSEG-SAKNR
BSEG-HKONT
BSEG-KOSTL
BSEG-KUNNR
BSEG-VBELN
BSEG-LIFNR
BSEG-ANLN1
BSEG-ANLN2
BSEG-AUFNR
BSEG-MATNR
BSEG-MENGE
BSEG-MEINS
BSEG-ZUONR
BSEG-SGTXT
Thanks,
Rahman
Moderator Message: Please search before posting your question. Thread locked.
Edited by: Suhas Saha on Jan 31, 2012 3:07 PMQuick question - what's preventing your from using built-in functions?
I suggest mapping your Time Dim to a standard Time Dim and work with it - you'll save a lot more time. You'd even need this table if you wanted to work around Todate/AGO.
It is possible to model this functionality w/o functions, but it'll be time consuming task, similar to using Time Series Wizard in Siebel Analytics. You'll need to build aliases and views along with some complex joins (such as TIME.KEY=TIME.KEY-365), introduce a bunch of variables to control. Also, you might not get much flexibility in terms of years. For each year, you'd need an alias table. (TIME_DIM_PY). -
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 -
table
can any please modify the query
thanking in advance
BEGIN OF t_initord OCCURS 0,
vbeln LIKE vbak-vbeln, " Sales Order
posnr LIKE vbap-posnr, " Sales Order Line Item
auart LIKE vbak-auart, " Sales Order Type
bezei LIKE tvakt-bezei, " Sales Order Type Text
billdo Like vbrk-vbeln, "billing document number
matnr LIKE vbfa-matnr, " Material
maktx LIKE makt-maktx, " Material Description
bstnk LIKE vbak-bstnk, " Customer PO number
bukrs LIKE vbak-bukrs_vf, " Company Code..
vkorg LIKE vbak-vkorg, " Sales Org
vtweg LIKE vbak-vtweg, " Distribution Channel
spart LIKE vbak-spart, " Division
vkgrp LIKE vbak-vkgrp, " Sales Group
augru LIKE vbak-augru, " Order Reason
abgru LIKE vbap-abgru, " Reson for rejection
kwmeng LIKE vbap-kwmeng, " Order Line quantit
deliv LIKE likp-vbeln, " Delivery Number
delit LIKE lips-posnr, " Delivery Number
rfmng LIKE vbfa-rfmng, " Delivery Qty..
vbtyp_n LIKE vbfa-vbtyp_n, " R12 Defect 8938.
mrnkz LIKE vbkd-mrnkz, " Subsequent Invoicing
docurr LIKE vbak-waerk, " Document Currency
netwr LIKE vbap-netwr, " Line Item Amt in Doc curr
ocdate LIKE vbak-aedat, " Order change date
objnr LIKE vbap-objnr, " Object number
rad LIKE sy-datum, " Requested Arrival Date
submi LIKE ekko-submi, " Collective number
plant1 LIKE vbap-werks, " Supplying Plant
ernam LIKE vbak-ernam, " Order Created by
erdat LIKE vbak-erdat, " Order Created on
lifnr LIKE ekko-lifnr, " Vendor
soldto LIKE vbak-kunnr, " Sold-to Party
shipto LIKE vbak-kunnr, " Ship-to Party
etenr LIKE vbep-etenr, " Sales Order schedule line
bmeng LIKE vbep-bmeng, " Order Sch Line quantity
vrkme LIKE vbap-zieme, " Sales Order UOM
cad LIKE sy-datum, " Confirmed Arrival Date
ktokk LIKE lfa1-ktokk, " Vendor account group
docurramt LIKE vbap-netwr, " Document Currency Amount
locurr LIKE vbak-waerk, " Local Currency
locurramt LIKE vbap-netwr, " Local Currency Amount
werks1 LIKE vbap-werks, " Supplying Plant
werks_name1 LIKE t001w-name1, " Plant description
lifnr_name1 LIKE lfa1-name1, " Name of the Vendor
stat TYPE g_stat_typ, " Status Code
lstatus TYPE g_stext_typ, " Last Status
soappr TYPE tj30t-txt30, " Sales Order Approval
bdnum LIKE vbfa-vbeln, " Billing doc number
bdlin LIKE vbrp-posnr, " Billing Item
uecha_b LIKE vbrp-uecha, " Item of Batch split
uecha_d LIKE lips-uecha, " Item of Batch split
END OF t_initord.
This is the internal table
to get the details wrote a select query
can any one please correct the select query
SELECT t1vbeln t2posnr t1auart t4bezei
t2matnr t5maktx
t1bstnk t1bukrs_vf t1vkorg t1vtweg t1spart t1vkgrp
t1augru t2abgru t2kwmeng t8vbeln
t8posnn t8rfmng t8vbtyp_n t7mrnkz t2waerk t2netwr
t1aedat t1objnr t1vdatu t1submi t2werks t1ernam t1~erdat
t6lifnr t1kunnr t9~kunnr
INTO TABLE t_initord
FROM vbak AS t1
INNER JOIN vbap AS t2
ON t1vbeln EQ t2vbeln
LEFT OUTER JOIN tvakt AS t4
ON t1auart EQ t4auart
AND t4~spras EQ c_en
LEFT OUTER JOIN makt AS t5
ON t2matnr EQ t5matnr
AND t5~spras EQ c_en
LEFT OUTER JOIN vbpa AS t9
ON t1vbeln EQ t9vbeln
AND t9~parvw EQ c_we
LEFT OUTER JOIN ekko AS t6
ON t1submi EQ t6ebeln
LEFT OUTER JOIN vbkd AS t7
ON t1vbeln EQ t7vbeln AND
t7~posnr EQ c_initposnr
LEFT OUTER JOIN vbfa AS t8
ON t2vbeln EQ t8vbelv AND
t2posnr EQ t8posnv
WHERE t1~vbeln IN s_slord
AND t1~vkbur IN s_sloff
AND t1~vkgrp IN s_slgrp
AND t1~kunnr IN s_custag
AND t1~auart IN s_ortyp
AND t1~vkorg IN s_slorg
AND t1~vtweg IN s_disch
AND t1~spart IN s_divi
AND t1~erdat IN s_date
AND t1~bukrs_vf IN s_ccode
AND t2~ernam IN s_slcre.
i need to modify the above query to get the additional information into the above table
billing doument number
document currency
document currency amount
billed quantity
sold to country
ship to countryYou can also refer to this code... for making your code better..
SELECT MATNR
WERKS
DISMM
DISPO
BESKZ INTO TABLE I_MARC FROM MARC
WHERE WERKS IN S_WERKS AND BESKZ = 'F' AND DISMM <> 'ND'.
IF NOT I_MARC IS INITIAL.
SELECT MATNR
MAKTX INTO TABLE I_MAKT FROM MAKT
FOR ALL ENTRIES IN I_MARC
WHERE MATNR = I_MARC-MATNR.
ENDIF.
REFRESH I_MDPS.
REFRESH I_MDEZ.
REFRESH I_MT61D.
REFRESH I_MDPS2.
REFRESH I_MDEZ2.
LOOP AT I_MARC INTO WA_MARC.
CALL FUNCTION 'MD_STOCK_REQUIREMENTS_LIST_API'
EXPORTING
MATNR = WA_MARC-MATNR
WERKS = WA_MARC-WERKS
TABLES
MDEZX = I_MDEZ
EXCEPTIONS
MATERIAL_PLANT_NOT_FOUND = 1
PLANT_NOT_FOUND = 2
OTHERS = 3
LOOP AT I_MDEZ.
I_MDEZ2-MATNR = WA_MARC-MATNR.
I_MDEZ2-WERKS = WA_MARC-WERKS.
MOVE-CORRESPONDING I_MDEZ TO I_MDEZ2.
APPEND I_MDEZ2.
ENDLOOP.
CLEAR I_MDEZ.
CLEAR I_MDEZ2.
ENDLOOP.
Deleting teh records from the internal table which are
nither purchase order nor purchase requisition.
if pur_ord = 'X' and Pur_req = 'X'.
delete i_mdez2 where delkz <> 'BA' and delkz <> 'BE'.
endif.
if pur_ord = 'X' and Pur_req <> 'X'.
delete i_mdez2 where delkz <> 'BE'.
endif.
if pur_req = 'X' and pur_ord <> 'X'.
delete i_mdez2 where delkz <> 'BA'.
endif.
Populating the final internal table to be displayed.
Sort i_mdez2 by matnr werks.
SORT I_MAKT BY MATNR.
LOOP AT I_MDEZ2 WHERE LIFNR IN S_LIFNR.
wa_final-werks = i_mdez2-werks.
WA_FINAL-LIFNR = I_MDEZ2-LIFNR.
WA_FINAL-EXTRA = I_MDEZ2-EXTRA.
WA_FINAL-MNG01 = I_MDEZ2-MNG01.
WA_FINAL-AUSKT = I_MDEZ2-AUSKT.
WA_FINAL-UMDAT = I_MDEZ2-UMDAT.
WA_FINAL-WERKS = I_MDEZ2-WERKS.
WA_FINAL-MATNR = I_MDEZ2-MATNR.
wa_final-delkz = i_mdez2-delkz.
For Message to be displayed with the Purchase Order and Purchase Requisition.
PERFORM TEXT_EXCEPTION.
READ TABLE I_MAKT INTO WA_MAKT WITH KEY MATNR = WA_FINAL-MATNR BINARY SEARCH.
IF SY-SUBRC = 0.
WA_FINAL-MAKTX = WA_MAKT-MAKTX.
ENDIF.
APPEND WA_FINAL TO I_FINAL .
ENDLOOP.
IF SY-SUBRC <> 0.
MESSAGE I058.
leave program.
ENDIF.
Selecting the Purchase Organisation from the EKKO table.
if not i_final is initial.
SELECT EBELN EKORG LIFNR INTO TABLE I_EKKO FROM EKKO
FOR ALL ENTRIES IN I_FINAL
WHERE LIFNR = I_FINAL-LIFNR.
Selecting the name of the vendor from the LFA1 table.
select lifnr name1 into table i_lfa1 from lfa1
for all entries in i_final
where lifnr = i_final-lifnr.
Selecting the current date from the eban table.
select matnr lfdat into table i_eban from eban
for all entries in i_final
where matnr = i_final-matnr." and bnfpo = i_ekpo-bnfpo.
endif.
if not i_ekko is initial.
Selecting the Unit Price from EKPO for finding the Extended amount.
SELECT EBELN ebelp NETPR MATNR banfn bnfpo INTO TABLE I_EKPO FROM EKPO
FOR ALL ENTRIES IN I_EKKO
WHERE EBELN = I_EKKO-EBELN.
endif.
if not i_ekpo is initial.
Selecting the current date from the Eket table.
select ebeln ebelp eindt into table i_eket from eket
for all entries in i_ekpo
where ebeln = i_ekpo-ebeln and ebelp = i_ekpo-ebelp.
endif.
*Sorting the internal tables.
SORT I_EKKO BY LIFNR.
sort i_lfa1 by lifnr.
SORT I_EKPO BY MATNR.
sort i_eket by ebeln ebelp.
sort i_eban by matnr.
LOOP AT I_FINAL INTO WA_FINAL.
READ TABLE I_EKKO INTO WA_EKKO WITH KEY LIFNR = WA_FINAL-LIFNR.
WA_FINAL-EKORG = WA_EKKO-EKORG.
wa_final-ebeln = wa_ekko-ebeln.
read table i_lfa1 into wa_lfa1 with key lifnr = wa_final-lifnr.
wa_final-name1 = wa_lfa1-name1.
READ TABLE I_EKPO INTO WA_EKPO WITH KEY MATNR = WA_FINAL-MATNR.
wa_final-ebelp = wa_ekpo-ebelp.
WA_FINAL-NETPR = WA_EKPO-NETPR.
if wa_final-delkz = 'BA'.
read table i_eban into wa_eban with key matnr = wa_final-matnr.
wa_final-dat00 = wa_eban-lfdat.
endif.
if wa_final-delkz = 'BE'.
read table i_eket into wa_eket with key ebeln = wa_final-ebeln ebelp = wa_final-ebelp.
wa_final-dat00 = wa_eket-eindt.
endif.
WA_FINAL-EXTND_AMOUNT = WA_FINAL-MNG01 * WA_FINAL-NETPR.
MODIFY I_FINAL FROM WA_FINAL TRANSPORTING EKORG name1 dat00 EXTND_AMOUNT.
ENDLOOP.
In this I have taken many internal tables... according to the database table I am extracting from .. then I am bringing all the record in the final internal table which will be containing teh records from all the internal table that i have used..
Regards,
Jayant
<b>Please award if helpful</b> -
How to re-write this big SELECT Query with INNER JOINs?
Hi Experts
I have a performance killer SELECT query with an inner join of 3 tables u2013 VBAP, VBAK and VBEP together, which populates records to an internal table INT_COLL_ORD. Based on these records selected, in another SELECT query, records are fetched from VBUK table to the internal table INT_VBUK.
SELECT A~VBELN A~POSNR A~MATNR A~KWMENG A~KBMENG A~ERDAT A~ERZET A~PSTYV D~AUART E~ETTYP E~EDATU
INTO TABLE INT_TAB_RES
FROM VBAP AS A INNER JOIN VBAK AS D
ON D~VBELN EQ A~VBELN AND D~MANDT EQ A~MANDT
INNER JOIN VBEP AS E
ON E~VBELN EQ A~VBELN AND E~POSNR EQ A~POSNR AND E~MANDT EQ A~MANDT
WHERE A~VBELN IN s_VBELN AND
D~auart in s_auart AND
D~vkorg in s_vkorg AND
D~vbtyp eq 'C' AND
( ( matnr LIKE c_prefix_sp AND zz_msposnr NE 0 AND kbmeng EQ 0 )
OR ( matnr LIKE c_prefix_fp AND kwmeng NE A~kbmeng ) ) AND
A~ABGRU EQ SPACE AND
A~MTVFP IN R_MTVFP AND
A~PRCTR IN R_PRCT AND
E~ETENR EQ '1'.
SORT INT_COLL_ORD BY VBELN POSNR ETTYP.
DELETE ADJACENT DUPLICATES FROM INT_TAB_RES COMPARING VBELN POSNR.
CHECK NOT INT_TAB_RES [] IS INITIAL.
SELECT VBELN UVALL CMGST INTO TABLE INT_VBUK
FROM VBUK FOR ALL ENTRIES IN INT_TAB_RES
WHERE VBELN = INT_TAB_RES-VBELN AND UVALL NE 'A'.
Now, the requirement is:
I want to split this query. Like, first join VBAK and VBUK first. With this selection, go to the inner join of VBAP and VBEP (on key VBELN) to get the results. How can I re-write this Query?
Please help.
Thx n RgdsHi Nagraj
As of your suggestion, I have re-written the query as below:
* Declarations
TYPES: BEGIN OF TYP_COLL_ORD,
VBELN LIKE VBAK-VBELN,
POSNR LIKE VBUP-POSNR,
MATNR LIKE VBAP-MATNR,
KWMENG LIKE VBAP-KWMENG,
KBMENG LIKE VBAP-KBMENG,
ERDAT LIKE VBAK-ERDAT,
ERZET LIKE VBAK-ERZET,
PSTYV LIKE VBAP-PSTYV,
AUART LIKE VBAK-AUART, u201Calready exists in type
ETTYP LIKE VBEP-ETTYP,
EDATU LIKE VBEP-EDATU.
TYPES: END OF TYP_COLL_ORD.
DATA: INT_COLL_ORD TYPE TABLE OF TYP_COLL_ORD WITH HEADER LINE.
TYPES: BEGIN OF TYP_VBUK,
AUART LIKE VBAK-AUART, u201Chave added this field
VBELN LIKE VBUK-VBELN,
UVALL LIKE VBUK-UVALL,
CMGST LIKE VBUK-CMGST.
TYPES: END OF TYP_VBUK.
DATA: INT_VBUK TYPE TABLE OF TYP_VBUK WITH HEADER LINE.
*QUERY#1 u2013 for VBAK & VBUK Join
SELECT A~AUART B~VBELN B~UVALL B~CMGST
INTO TABLE INT_VBUK
FROM VBAK AS A INNER JOIN VBUK AS B
ON A~VBELN EQ B~VBELN
WHERE A~VBELN IN s_VBELN AND
A~auart in s_auart AND
A~vkorg in s_vkorg AND
A~vbtyp eq 'C' AND
B~UVALL NE 'A'.
IF NOT INT_VBUK[] IS INITIAL.
SORT INT_VBUK BY VBELN.
DELETE ADJACENT DUPLICATES FROM INT_VBUK COMPARING VBELN.
*QUERY#2 u2013 for VBAP & VBEP Join
SELECT A~VBELN A~POSNR A~MATNR A~KWMENG A~KBMENG A~ERDAT A~ERZET A~PSTYV B~ETTYP B~EDATU
INTO TABLE INT_COLL_ORD
FROM VBAP AS A INNER JOIN VBEP AS B
ON B~VBELN EQ A~VBELN AND B~POSNR EQ A~POSNR AND B~MANDT EQ A~MANDT
FOR ALL ENTRIES IN INT_VBUK
WHERE A~VBELN = INT_VBUK-VBELN AND
( ( matnr LIKE c_prefix_sp AND zz_msposnr NE 0 AND kbmeng EQ 0 )
OR ( matnr LIKE c_prefix_fp AND kwmeng NE A~kbmeng ) ) AND
A~ABGRU EQ SPACE AND
A~MTVFP IN R_MTVFP AND
A~PRCTR IN R_PRCT AND
B~ETENR EQ '1'.
ENDIF.
SORT INT_COLL_ORD BY VBELN POSNR ETTYP.
DELETE ADJACENT DUPLICATES FROM INT_COLL_ORD
COMPARING VBELN POSNR.
CHECK NOT INT_COLL_ORD[] IS INITIAL.
LOOP AT INT_COLL_ORD.
CLEAR: L_MTART,L_ATPPR,L_ETTYP.
IF L_PREVIOUS_ETTYP NE INT_COLL_ORD-ETTYP OR
L_PREVIOUS_AUART NE INT_COLL_ORD-AUART.
READ TABLE INT_OVRCTL WITH KEY AUART = INT_COLL_ORD-AUART ETTYP = INT_COLL_ORD-ETTYP.
CHECK SY-SUBRC NE 0.
Now, the issue is:
Please note that declaration for INT_COLL_ORD has a field AUART, which is used in further parts of program (see the statement just above)
But, since neither VBAP nor VBEP contains AUART field, it cannot be fetched through the QUERY#2. So this value is not populated into INT_COLL_ORD through SELECT Query.
Since this field is used in later part of program & that the internal table has no value for this field, it dumps!!
How to include this value into the INT_COLL_ORD?
Plz suggest.... -
Can we use inner joins with for all entries?
Hi,
Can we use innerjoin on two tables MARA and MAKT against the materials in
the internal table.
If so ,please let me know whether there is performance issue.Because if there is
bad performance issue or something else like thise means,my project manager
wont allow to include.
So can one let me know about this.
Thanks,
BalajiHi Arunkumar,
I think you are not clear.My question is can I use innerjoin with
for all entries.For example below is my code.
SELECT A~MATNR
B~MAKTX
A~MTART
A~MATKL
FROM MARA AS A INNER JOIN MAKT AS B
ON AMATNR = BMATNR
INTO TABLE IT_MARA_MAKT
FOR ALL ENTRIES IN IT_MATNR
WHERE A~MATNR = IT_MATNR-MATNR
AND A~EXTWG = P_EXTWG
AND A~SPART = P_SPART.
Can we use like this for all entries along with innerjoins.
Thanks,
Balaji -
Help needed in rewriting the code using inner joins
Hi all,
I need help in rewriting this code
DATA : FLD LIKE ZTABLE-ZFLD,
FLD1 LIKE ZTABLE2-ZFLD2.
select single ZFLD from zTABLE1 into FLD
where MATNR = '123' and
werks = 'ABC'.
select single ZFLD1 from zTABLE2 into FLD1
where zFLD = FLD.
iS there way that we can write this with inner joins
ThanksHi,
help me out
TABLE 1 HAS
MATNR , WERKS , FLD1.
TABLE 2 HAS
FLD1, FLD2.
I KNOW MATNR AND WERKS BASED ON THAT I HAVE TO GET FLD2
I WANT IT BE WRITTEN WITH INNEWR JOINS
WITH FOLLOWING COD E I GET AN ERROR MESSAGE SAYING
comma without preccing colon (after select?)
data : FLD1 like zTABLE1-ZFLD1.
data : FLD2 like ZTABLE2-ZFLD2.
SELECT FZFLD1 BZFLD2
INTO ( FLD1, FLD2)
FROM ZTABLE1 AS F INNER JOIN ZTABLE2 AS B
ON FZFLD1 = BFLD2
WHERE F~MATNR = '123'
AND F~WERKS = 'ABC' .
Thanks -
Hi,
I'm trying to execute some SQL queries and I just don't understand what's wrong.
I�m using Tomcat and SQL Server in order to do this, but when I�m try to execute a query with a INNER JOIN statements Tomcat raise a SQL exception... at the very first time I thought there was a problem with database connection but I realize that a simple query to a table works pretty well. then I found out some problems with JDBC:ODBC.... so I install JDBC for SQL Server 2000 and test with the same simple query and works..... so, I come to a conclusion.... INNER JOIN or JOIN statements can't be used in JDBC..... please... somebody tell I�m wrong and give me a hand...
I'm using TOMCAT 4 and JDK 1.4 SQL Server 2000
Error occurs when executeQuery() is called.... not prepareStatement().... ??????
Driver DriverRecResult = (Driver)Class.forName(driver).newInstance();
Connection ConnRecResult = DriverManager.getConnection(DSN,user,password);
PreparedStatement StatementRecResult = ConnRecResult.prepareStatement(query);
ResultSet RecResult = StatementRecResult.executeQuery(); <---- Exception raise here
So much tahnks in advance,That's exactly what I think, driver it's raising the exception, but I don't know why.... i test the same query with INNER JOIN directly from SQL Query Analyser and it's works perfectly, my problem ain't SQL, but JSP and JDBC 'cause i'm a newbie about these issues.
Common sense tell me possible problems lie in SQLServer drivers 'cause i run the same pages on JRUN through jdbc:odbc and do works well, but by now i just depend on Tomcat.....
I've installed SQL Server drivers for JDBC but i just find it doesn't work fully... could be the version of JDK i've installed? what version do i need?
( I'm running Tomcat 4 with JDK 1.4 & SQL Server 2000 W2K )
thanks for reply.
Maybe you are looking for
-
Connecting Mac to Plasma TV via VGA Cable
I just got a VGA cable to connect my MacBook Pro (2009) to my Plasma TV. When I did, my screen on my MacBook looked like it went into a ZOOM mode where everything was bigger than normal and did not fit on the screen. Is this normal or is there a way
-
Update statement taking too much time
Hi All, I defined a cursor in which there are almost 94 lakh records and i want to update few fields of a table from another table which takes data over a dblink. my cursor is cursor c_tpo is select t.loc_loc_id, t.till_no,
-
Older purchased music wont play??
my itunes plays most of the newly purchased music, but it wont play other music. i have already deathurized all computers and only authorized the one that im on now. but the older music says its still already used up all 5 slots. any thoughts???
-
Ipod nano FROZEN!!! i cant do anything.....
ok so... i was changing songs and it froze... i tried pushing the menu thing and yeah... it wont do anything... then i tried plugging it in at home, but that wont work either... on i-tunes my ipod doesnt even show up... i dont know what to do... plea
-
Is it possible to move or merge my local user account with an Active Directory account?
10.7.2 update now allows me to authenticate against AD, and I have a shiny new account on my mac. Is there any way to merge my local and AD accounts? Or link my local account to my AD account? Can I change the home directory of the AD account to po