Select Join problem
Hi Experts,
I need your help on this. I really don't know what's wrong with my select statment. Please let me know what went wrong. I'm not sure if select join statement allows parameters for select-options. Below is my select statement. Thanks.
SELECT tbtcojobname tbtcplistident
INTO CORRESPONDING FIELDS OF TABLE itab
FROM tbtco JOIN TBTCP ON ( tbtcojobcount = tbtcpjobcount )
WHERE tbtco~status = 'F'
AND tbtco~jobname IN P_SEARCH
AND tbtco~enddate IN p_date
AND tbtcp~listident IN p_spool.
IF sy-subrc = 0.
APPEND itab.
CLEAR itab.
ENDIF.
Anna
Just to give you an idea: Here's what I did.
SELECT-OPTIONS: p_search FOR TBTCO-jobname,
p_date FOR TBTCO-enddate,
p_spool FOR TBTCP-listident.
DATA: BEGIN OF itab OCCURS 0,
sp_name TYPE tbtco-jobname,
br_code(1),
dumon(7),
sp_numb TYPE TSP01-rqident,
ofc(12),
END OF itab.
SELECT tbtcojobname tbtcplistident
INTO CORRESPONDING FIELDS OF TABLE itab
FROM tbtco JOIN TBTCP ON ( tbtcojobcount = tbtcpjobcount )
WHERE tbtco~status = 'F'
AND tbtco~jobname IN P_SEARCH
AND tbtco~enddate IN p_date
AND tbtcp~listident IN p_spool.
IF sy-subrc = 0.
APPEND itab.
CLEAR itab.
ENDIF.
Similar Messages
-
Joined problem labels Labels to color everyone in the line archives mp3 and selection in dots as it exists now can be anyone who wants to do what HELPS of how thoroughly enjoyable.
Sp188585 wrote:
Joined problem labels Labels to color everyone in the line archives mp3 and selection in dots as it exists now can be anyone who wants to do what HELPS of how thoroughly enjoyable.
Sorry, you will have to outline your issues more clearly.
Thanks
Pete -
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 -
Experts,
Do we have any automated tool that will detect joins in the layers ???
secondly in case we start with manually joining the tables will there be any join problems like we have in BO?
Third In case of manual joins in physical layer can have to make joins that suit our requirement or we have to follow the database structure. and join all columns that could be joined in the structure
thanks in advance
Edited by: ZSAMEE on May 2, 2011 11:55 AM
Edited by: ZSAMEE on May 2, 2011 12:11 PMAs far as I know there are no tools out there that would automatically join the tables in BMM layer. You have to join the fact and dimensions to design star/snow flake schema's manually.
Thanks,
-Amith. -
[iPhone] Custom UITableViewController and selecting cell problem.
Hello,
I'm creating a custom table view controller by declaring a UIViewController and adopting the UITableViewDataSource and UITableViewDelegate protocol.
With my current implementation, if I select a cell to transition to another view and then navigate back to the tableview, the cell will remain selected.
There must be some delegate method I am not implementing.
If I update the header file of my table view controller by removing the adopted protocols and subclassing the UITableViewController, I dont have this "selection sticking" problem.
Any ideas as to what I am doing wrong?
Thanks!You're not doing anything wrong, except by omission. If you choose to implement a table view controller as a UIViewController rather than a UITableViewController, you are responsible for controlling selection/deselection of the cells on returning back to the table view from some child view. In the common case where something going on in the child controller affects what cell should be selected/deselected on returning back to the parent table view, this is exactly what you want, because the UITableViewController doesn't always get it right, to sometimes comical effect.
How you would set this up is highly context-dependent.
Doug -
hey guys,
i've used a select query to get details from KNA1, KNVV, ADRC, KNVP, pa0002. tables by joining. but i'm getting only about 170 records. there are more than 3000 records in the database. for each tables. here is my select query
SELECT KNA1KUNNR KNA1NAME1 KNA1NAME2 ADRCSTR_SUPPL1 ADRCSTR_SUPPL2 ADRCSTR_SUPPL3 ADRCCITY1 KNVVVWERK KNVPPERNR PA0002VORNA PA0002NACHN KNVVVKBUR KNVVKDGRP KNA1STCD1 KNA1~STCEG
INTO CORRESPONDING FIELDS OF TABLE IT_FINAL FROM KNA1
INNER JOIN KNVV ON KNA1KUNNR = KNVVKUNNR
INNER JOIN ADRC ON KNA1ADRNR = ADRCADDRNUMBER
INNER JOIN KNVP ON KNA1KUNNR = KNVPKUNNR
INNER JOIN PA0002 ON KNVPPERNR = PA0002PERNR
WHERE KNA1KUNNR IN S_KUNNR AND KNVVVWERK in P_VWERK AND PA0002PERNR IN S_PERNR AND KNVVVKBUR IN S_VKBUR AND KNVV~KDGRP IN S_KDGRP.
can anyone tell me the problem in the above query.
thanks.Hi
you are using tables KNA1, KNVV, ADRC, KNVP, pa0002.
Create internal table for each table mentioned above with all the primary keys and find the links between them
then select data in one table and select data from another table into your internal table for all the entries exists in firs internal table.
go for below links.
http://www.sapdev.co.uk/abap/commands/select_forallentries.htm
http://wiki.sdn.sap.com/wiki/display/ABAP/FORALLENTRIES-Home+page
http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP_ITAB.htm
Thanks
lalit -
Select distinct problem with muliple join tables, help needed
Hi,
I have two main tables. Each has its of sub joined tables.
guest_id_for_reservation connects two major tables. This has
to be that way
because my guest may change the room status from single to
double (and the
similar exceptional requests).
guests reservation
guest_id_for_reservation
countrytable hoteltable
delegationtable roomtype
I form a query. I want to select distinct those results. But
it does not
work.
If I do not include any table related to reservation table
and its sub
joined tables (disregarding guest_id_for_reservation), it
works.
Is there a specific syntax for select distinct of this type
or any
workaround.?
Thank you
HakanHi I'm still battling with this - have connected the AX to my Imac via ethernet and it shows up fine in Airport Utility. Status light is green and it says its set up to connect to my existing wireless network using wireless connection. Security in Network Preferences is the same for both: WPA2 Personal.
So I don't think there's a problem with the AX, and my current wireless network (BT Home Hub) is working fine.
And when I restore factory settings Airport Utility can see the AX before updating settings so the wireless side of AX must work too.
I'm figuring it must be something about the settings that mean AU can't see it anymore. But I can't work out what, since security is the same.
Any ideas would be great! -
Problem of using formula in select join statement
I would like to use following statement but I can not.(do you have an example of an statement where this wuld work):
SELECT
lipsprodh sum(lipslfimg * lipsumvkz / lipsumvkn) sum(lipsvolum) lipsvtweg likp~wadat_ist
INTO CORRESPONDING
FIELDS OF TABLE itab FROM
lips
JOIN likp
ON lipsvbeln = likpvbeln
WHERE lips~vkorg = '0200'.Hi ,
types: BEGIN OF s_itab ,
prodh LIKE lips-prodh,
lfimg LIKE lips-lfimg,
umvkz LIKE lips-umvkz,
umvkn LIKE lips-umvkn,
volum LIKE lips-volum,
vtweg LIKE lips-vtweg,
wadat_ist LIKE likp-wadat_ist,
END OF s_itab.
DATA : temp type p decimal 2 ,
temp1 type p decimal 2 ,
temp2 type p decimal 2 ,
itab type table of s_itab ,
wt_tab type s_itab .
SELECT lips~prodh
lips~lfimg
lips~umvkz
lips~umvkn
lips~volum
lips~vtweg
likp~wadat_ist
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( lips INNER JOIN likp ON lipsvbeln = likpvbeln )
WHERE lips~vkorg = '0200'.
loop at itab inro wt_tab .
temp = ( wt_tab-lfimg * wt_tab-umvkz ) / lips~umvkn .
temp1 = temp1 + temp .
temp2 = temp2 + wt_tab .
endloop.
Hope it helped you .
Message was edited by:
Lakshminarayanan rohini -
Outer Join problems - "ORA-30563 outer join operator (+) not allowed in select-list"
Products: Discoverer 4.1.33.0.2
(Admin and User/Plus)
8i EE 8.1.7 (Discoverer server)
8i EE 8.1.5 ('source data' server)
Background assumptions: (1) If a column from an "outer-joined" table is compared to a constant, the outer join operator must be applied to that column in order for the outer join to work. (2) A 'Condition' specified in Discoverer User/Plus manifests as a comparison to a constant.
I created a join in Admin between two folders, selected 'outer join on detail' option. In User/Plus, created worksheet containing columns from the joined folders. When no Conditions are NOT specified, results seem ok. However, when Condition IS added, worksheet encounters "ORA-30563 outer join operator (+) not allowed in select-list" and returns blank sheet.
To workaround, created Custom folder with outer join in place. Didn't work either with Conditions specified. No error, but I think that because Discoverer did not 'outer join' the Condition column, the outer join was ignored.
Any insights, ideas, or workarounds are much appreciated.
-JimIf you build a query that uses an outer join then any items from the potentially deficient side of the join will have (+) appended to them everywhere in the sql. Up until 8.1.7 this was OK in the select list as it was just treated as noise and ignored - However this now fails with ORA-30563:
outer join operator (+) not allowed in select-list...
In 4.1.33.1.6 you get the error 'ORA-30563 outer join operator(+) not allowed in select list'.
In 4.1.36.1.10 the query runs OK.. Your work around I would guess would be to create a custom folder as you suggested. -
I am trying to write a query to return data from 4 different tables and it is doubling my summed values. I can get the separate queries to work, but not combined and I need them combined so that I can get a balance due and limit the records to only those that had a total billed (fees) less than $200.
Query #1 Gets the total of the fees due for each appeal type and invoice:
Note: There is always at least one fee attached to an invoice.
SELECT APT.APTY_DESCR "APPEAL TYPE",
INV.INVC_ID_SEQ INVOICE,
SUM( ALL FEE.AMT_DUE) "TOTAL BILLED AMOUNT"
FROM WRD_APPEALS AP,
WRD_INVOICES INV,
WRD_FEES_DUE FEE,
WRD_APPEAL_TYPES APT
WHERE AP.APST_CD = 'PEND'
AND AP.INVC_ID_SEQ = INV.INVC_ID_SEQ
AND AP.INVC_ID_SEQ = FEE.INVC_ID_SEQ
AND AP.APTY_CD = APT.APTY_CD
GROUP BY APT.APTY_DESCR, INV.INVC_ID_SEQ
ORDER BY APT.APTY_DESCR, INV.INVC_ID_SEQ
4 BILLING CATEGORY INCORRECT 4147 1200
5 BILLING CATEGORY INCORRECT 4203 1100
6 BILLING CATEGORY INCORRECT 4216 72600
7 BILLING CATEGORY INCORRECT 4826 1000
8 BILLING CATEGORY INCORRECT 4951 2060
Query #2 Gets the total amount paid for each appeal type and invoice:
Note: An invoice may or may not have a payment, thus the outer join.
SELECT APT.APTY_DESCR "APPEAL TYPE",
INV.INVC_ID_SEQ INVOICE,
SUM(ALL PMT.PAID_AMT) "AMOUNT PAID"
FROM WRD_APPEALS AP,
WRD_INVOICES INV,
WRD_APPEAL_TYPES APT,
WRD_PAYMENTS PMT
WHERE AP.APST_CD = 'PEND'
AND AP.INVC_ID_SEQ = INV.INVC_ID_SEQ
AND AP.APTY_CD = APT.APTY_CD
AND INV.INVC_ID_SEQ = PMT.INVC_ID_SEQ(+)
GROUP BY APT.APTY_DESCR, INV.INVC_ID_SEQ
ORDER BY APT.APTY_DESCR, INV.INVC_ID_SEQ
4 BILLING CATEGORY INCORRECT 4147 200
5 BILLING CATEGORY INCORRECT 4203 0
6 BILLING CATEGORY INCORRECT 4216 72600
7 BILLING CATEGORY INCORRECT 4826
8 BILLING CATEGORY INCORRECT 4951
Combined Query - Gets all of the above as well as the balance due. Note the doubled values for some records.
SELECT APT.APTY_DESCR "APPEAL TYPE",
INV.INVC_ID_SEQ INVOICE,
SUM( ALL FEE.AMT_DUE) "TOTAL BILLED AMOUNT",
SUM(ALL PMT.PAID_AMT) "AMOUNT PAID",
(SUM(ALL FEE.AMT_DUE) -
NVL2(SUM(ALL PMT.PAID_AMT), SUM(ALL PMT.PAID_AMT), 0)) "BALANCE DUE"
FROM WRD_APPEALS AP,
WRD_INVOICES INV,
WRD_FEES_DUE FEE,
WRD_APPEAL_TYPES APT,
WRD_PAYMENTS PMT
WHERE AP.APST_CD = 'PEND'
AND AP.INVC_ID_SEQ = INV.INVC_ID_SEQ
AND INV.INVC_ID_SEQ = PMT.INVC_ID_SEQ(+)
AND INV.INVC_ID_SEQ = FEE.INVC_ID_SEQ
AND AP.APTY_CD = APT.APTY_CD
GROUP BY APT.APTY_DESCR, INV.INVC_ID_SEQ
ORDER BY APT.APTY_DESCR, INV.INVC_ID_SEQ,
4 BILLING CATEGORY INCORRECT 4147 1200 400 800
5 BILLING CATEGORY INCORRECT 4203 2200 0 2200
6 BILLING CATEGORY INCORRECT 4216 72600 435600 -363000
7 BILLING CATEGORY INCORRECT 4826 1000 1000
8 BILLING CATEGORY INCORRECT 4951 2060 2060
HELP PLEASE!
Thank you.When you have multiple child rows, the parent row gets returned once for each child row found. Therefore, if you have summed the invoice, it gets summed again for each payment. Perhaps this little example will help you understand the problem.
Note that I used a sub query here to obtain the desired results. Analytic functions can do the same I believe, but I am still learning them :-)
D> DROP TABLE DMILL.invoice;
Table dropped.
D>
D> DROP TABLE DMILL.payments;
Table dropped.
D>
D> CREATE TABLE invoice AS
SELECT 1 id, 10 amount FROM DUAL UNION ALL
SELECT 2 id, 10 FROM DUAL UNION ALL
SELECT 2 id, 10 FROM DUAL UNION ALL
SELECT 3 id, 10 FROM DUAL;
Table created.
D>
D> CREATE TABLE payments AS
SELECT 1 inv_id, 5 amount FROM DUAL UNION ALL
SELECT 1 inv_id, 5 amount FROM DUAL UNION ALL
SELECT 2 inv_id, 5 amount FROM DUAL UNION ALL
SELECT 2 inv_id, 5 amount FROM DUAL UNION ALL
SELECT 2 inv_id, 5 amount FROM DUAL;
Table created.
D>
D> select * from invoice;
ID AMOUNT
1 10
2 10
2 10
3 10
D>
D> select * from payments;
INV_ID AMOUNT
1 5
1 5
2 5
2 5
2 5
D>
D> select id
,sum (amount)
from invoice
group by id;
ID SUM(AMOUNT)
1 10
2 20
3 10
D>
D> select inv_id
,sum(amount)
from payments
group by inv_id;
INV_ID SUM(AMOUNT)
1 10
2 15
D>
D> select inv.id
,inv.amount
,pay.amount
from invoice inv
,payments pay
where pay.inv_id = inv.id;
ID AMOUNT AMOUNT
1 10 5
1 10 5
2 10 5
2 10 5
2 10 5
2 10 5
2 10 5
2 10 5
8 rows selected.
D>
D> select inv.id
,sum(inv.amount)
,sum(pay.amount)
from invoice inv
,payments pay
where pay.inv_id = inv.id
group by inv.id;
ID SUM(INV.AMOUNT) SUM(PAY.AMOUNT)
1 20 10
2 60 30
D>
D> select inv.id
,sum(inv.amount)
,(SELECT sum(pay.amount)
FROM payments pay
WHERE pay.inv_id = inv.id)
from invoice inv
group by inv.id;
ID SUM(INV.AMOUNT) (SELECTSUM(PAY.AMOUNT)FROMPAYMENTSPAYWHEREPAY.INV_ID=INV.ID)
1 10 10
2 20 15
3 10Let me know if you need further explanation. -
This report will take delivery document number and delivery date from user and fetches details from delivery table and fetches
corresponding sales order details and billing details and displays sales order details with ALV list.
<< Please only post the relevant portions of your code >>
i just want to know that is this way of fetching the data into internal table okay ?are there any better ways of fetching the data into the internal table ? why is it looping in work area of lips, why not in likp?
(plz dont use field-symbols or oo abap or macros) I WANT TO USE PLAIN AND SIMPLE ABAP STATEMENTS LIKE ABOVE..
By using "vbeln type lips-vbeln" are we refering to the field or data element? plz suggest.
P.S. [my approach was to inner join likp and lips into itab(my internal table).
select data from kna1, vbak,vbap,vbrp into respective internal tables like it_kna1,it_vbak etc.
then using individual loops into the tables, i would use read table to insert data into itab(my final internal table) plz suggest which method wud be more efficient? ]
Edited by: Rob Burbank on Jun 8, 2009 11:54 AMok i am posting the select queries once again.
i want to know why are we looping in t_lips and why not t_likp? bcoz tlikp is the header table, if we loop thru it and then read the rest tables then what will be the problem? plz clarify with examples._
[my idea was to loop at t_likp then read t_lips.append the lips data into t_order(main internal table).then do read table on t_kna1,t_vbap etc indexing t_order. so plz suggest whether my approach was write or wrong?if wrong why?plz site any other ways of doing this query.
types: begin of ty_vbap,
vbeln type vbap-vbeln,
posnr type vbap-posnr, .....
does the declaration statement in types refer to tables or data elements? what is the difference if we declare it like:
types: begin of ty_vbap,
vbeln type vbeln,
posnr type posnr, .....
select-options:
s_deldoc FOR likp-vbeln, " Delivery
s_dldate FOR likp-lfdat. " Delivery Date
Get delivery document number,delivery date,customer number from
delivery header table
SELECT vbeln " Delivery
lfdat " Delivery Date
kunnr " Customer Number 1
FROM likp
INTO TABLE t_likp
WHERE vbeln IN s_deldoc
AND lfdat IN s_dldate.
IF sy-subrc EQ 0.
Get Customer name for customer numbers from Customer master table
SELECT kunnr " Customer Number 1
name1 " Name 1
FROM kna1
INTO TABLE t_kna1
FOR ALL ENTRIES IN t_likp
WHERE kunnr EQ t_likp-kunnr.
IF sy-subrc EQ 0.
Get delivery item number,sales document number,sales item number,
delivery quantity from delivery item table
SELECT vbeln " Delivery
posnr " Delivery Item
vgbel " Document number of
" reference document
vgpos " Item number of reference item
lfimg " Actual quantity delivered
vrkme " Sales unit
FROM lips
INTO TABLE t_lips
FOR ALL ENTRIES IN t_likp
WHERE vbeln EQ t_likp-vbeln.
IF sy-subrc EQ 0.
Get sales document number,item number,material,material description,
ordered quantity from sales item table
SELECT vbeln " Sales Document
posnr " Sales Document Item
matnr " Material Number
arktx " Short text for sales order
" item
kwmeng " Cumulative Order Quantity
vrkme " Sales unit
FROM vbap
INTO TABLE t_vbap
FOR ALL ENTRIES IN t_lips
WHERE vbeln EQ t_lips-vgbel
AND posnr EQ t_lips-vgpos.
IF sy-subrc EQ 0.
Get sales document number ,created date,purchase order number from
sales header table
SELECT vbeln " Sales Document
erdat " Date on Which Record Was" Created
aufnr " Order Number
FROM vbak
INTO TABLE t_vbak
FOR ALL ENTRIES IN t_lips
WHERE vbeln EQ t_lips-vgbel.
IF sy-subrc EQ 0.* Get billing document number,billing item,reference delivery document
number,delivery item number,billing item from billing item table
SELECT vbeln " Billing Document
posnr " Billing item
vgbel " Document number of the
" reference document
vgpos " Item number of the" reference" item
fklmg " Billing quantity in" stockkeeping unit
vrkme " Sales unit
FROM vbrp
INTO TABLE t_vbrp
FOR ALL ENTRIES IN t_lips
WHERE vgbel EQ t_lips-vbeln
AND vgpos EQ t_lips-posnr.
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ELSE.
Display message if records are not found for entered values
MESSAGE S000.
EXIT.
ENDIF. " IF SY-SUBRC EQ 0
Looping Delivery item internal table to assign values to order
internal table
LOOP AT t_lips INTO fs_lips.
Get delivery date and customer number for delivery document number
from delivery header internal table
READ TABLE t_likp WITH KEY vbeln = fs_lips-vbeln
INTO fs_likp.
Get customer name for customer number from customer master internal
table
IF sy-subrc EQ 0.
READ TABLE t_kna1 WITH KEY kunnr = fs_likp-kunnr
INTO fs_kna1.
Get sales document number,item number,ordered quantity for delivery
document number,item number from sales item internal table
IF sy-subrc EQ 0.
READ TABLE t_vbap WITH KEY vbeln = fs_lips-vgbel
posnr = fs_lips-vgpos INTO fs_vbap.
Get goods issue date and purchase order number for sales document
number from sales header internal table
IF sy-subrc EQ 0.
READ TABLE t_vbak WITH KEY vbeln = fs_vbap-vbeln INTO fs_vbak.
IF sy-subrc EQ 0.
Get billing document number,billing item,billing quantity for delivery
document number,delivery item number from billing item internal table
READ TABLE t_vbrp WITH KEY vgbel = fs_lips-vbeln
vgpos = fs_lips-posnr INTO fs_vbrp.
Assign sales,delivery,billing fields into respective fields of sales
order internal table
IF sy-subrc EQ 0.
fs_order-vbeln = fs_vbap-vbeln.
fs_order-posnr = fs_vbap-posnr.
fs_order-erdat = fs_vbak-erdat.
fs_order-kunnr = fs_likp-kunnr.
fs_order-name1 = fs_kna1-name1.
fs_order-aufnr = fs_vbak-aufnr.
fs_order-matnr = fs_vbap-matnr.
fs_order-arktx = fs_vbap-arktx.
fs_order-kwmeng = fs_vbap-kwmeng.
fs_order-vrkme = fs_vbap-vrkme.
fs_order-vbeln1 = fs_lips-vbeln.
fs_order-posnr1 = fs_lips-posnr.
fs_order-lfimg = fs_lips-lfimg.
fs_order-vrkme1 = fs_lips-vrkme.
fs_order-vbeln2 = fs_vbrp-vbeln.
fs_order-posnr2 = fs_vbrp-posnr.
fs_order-fklmg = fs_vbrp-fklmg.
fs_order-vrkme2 = fs_vbrp-vrkme.
APPEND fs_order TO t_order.
CLEAR fs_order.
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDLOOP. " LOOP AT T_LIPS INTO FS_LIPS -
Left outer join problem -- need feedback
using crystal 2008
haveing prolbems with a left outerjoin to get a blank field(null) to show up.
basically i have some po line have have long descriptions or text fields that i want to include with the report. Below is my sql statement. I have written a formula with a join between 2 fields to get the report to work- this does but- it leave the polines off that do not have a long description. I have tried left outer joins but seem to be having problems. The long description field where the data is actually at is under my po.line table, although serveral area have long description fields -
*one note i had to add a duplicate table to the field to get some items in my header to work properly - not sure if this is effecting the report or not.
OK- when I set up the link to a LO join enforce from = to
and dont add the ldtext.field to the report the left outjoin works(but no long description)and all my line items show up.
1. when I keep the same join and add either just the ld.text field to the report it comes back with a error saying invalid table
2. when i use my formula that joins the ld.text and po.line and place it in the report with the same left outerjoin i get the same failure.
3. when i dont reference the ldtext(field) at all in the report it works fine w/ the lo join
4. when i Dont use a left outer join and use my formula(see below)
if not isnull(({LONGDESCRIPTION.LDTEXT }))
then {POLINE.DESCRIPTION}+{LONGDESCRIPTION.LDTEXT}
else {POLINE.DESCRIPTION}
and link from poline.ld
to ld.ldtext - my formula works and populates the po.line and the ld.text together - except that any po.line with no description will not show up. Like its not there.
Not sure what to do?
here is my current sql statement with the longdescription field in the select statement
here is the error statement i am getting:
Failed to retrieve data from the database:
Details:42000[intersolv][odb sql base driver][sql base] 00906 itn invalid table name[database vendor code:906]
sql statement:
SELECT "PO"."PONUM", "PO"."STATUS", "PO"."VENDOR",
"COMPANIES"."NAME", "COMPANIES"."ADDRESS1",
"COMPANIES"."ADDRESS2", "COMPANIES"."ADDRESS3",
"COMPANIES"."ADDRESS4", "COMPANIES"."PHONE",
"COMPANIES"."FAX", "COMPANIES_1"."NAME",
"COMPANIES_1"."ADDRESS1", "COMPANIES_1"."ADDRESS2",
"COMPANIES_1"."ADDRESS3", "COMPANIES_1"."ADDRESS4",
"COMPANIES_1"."CONTACT", "COMPANIES_1"."PHONE",
"COMPANIES_1"."FAX", "PO"."PURCHASEAGENT",
"PO"."ORDERDATE",
"PO"."REQUIREDDATE", "PO"."PAYMENTTERMS",
"PO"."SHIPVIA", "PO"."FREIGHTTERMS", "PO"."FOB",
"POLINE"."DESCRIPTION", "POLINE"."ITEMNUM",
"POLINE"."ORDERQTY", "POLINE"."UNITCOST",
"POLINE"."LOADEDCOST", "POLINE"."POLINENUM",
"PO"."SHIPTOATTN", "LONGDESCRIPTION"."LDTEXT"
FROM ("MAXIMO"."PO" "PO" LEFT OUTER JOIN
"MAXIMO"."LONGDESCRIPTION" "LONGDESCRIPTION" ON "PO"."LDKEY"="LONGDESCRIPTION"."LDKEY"),
"MAXIMO"."POLINE" "POLINE",
"MAXIMO"."COMPANIES" "COMPANIES_1",
"MAXIMO"."COMPANIES" "COMPANIES"
WHERE ("PO"."PONUM"="POLINE"."PONUM") AND ("PO"."VENDOR"="COMPANIES_1"."COMPANY") AND ("PO"."SHIPTO"="COMPANIES"."COMPANY") AND "PO"."PONUM"='3386-053'If you took the time to read this thanks.... turns out... and I just want to pull my hair out over this. My connection had a old odbc driver so somehow it would not allow a left outer join....go figure - weeks of agony over that..... thanks ....have to say love this forum.
-
Hi,
In my report List of Block Customer's, INNER JOIN is not working..
Code:----
SELECT DISTINCT M1KUNNR M1KTOKD M1NAME1 M1CASSD M1AUFSD M1LIFSD M1~FAKSD INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM KNA1 AS M1 INNER JOIN KNVV AS M2 ON M1KUNNR = M2KUNNR
WHERE M1~KTOKD IN ('0001' , 'KTOKD')
AND M1~CASSD EQ 'X'
OR M1~AUFSD NE ''
OR M1~LIFSD NE ''
OR M1~FAKSD NE ''
OR (M2~AUFSD NE ''
OR M2~LIFSD NE ''
OR M2~FAKSD NE ''
OR M2~CASSD EQ 'X'.
Here, condition on 0001 is not matching..
Plz tell me, what is the problem in it..
Thanks
Edited by: Prince Kumar on Oct 20, 2008 9:37 AMhi,
please use " FOR ALL ENTRIES " as it is better performance wise also rather then inner joins
and for syntax refer this code:
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.
thanks and regards
RAHUL -
Correlated sub-query/outer join problem
Hi,
I have a problem similar to this one (Outer join with correlated subquery but I'm struggling to find a solution for mine!
The following query works OK unless there is no entry in room_prices, so I need to outer join somehow to that table otherwise it doesn't return any rows.
The main difference between the query in the other thread and mine is that mine has an extra table (bookings b) in the sub-query, which is complicating things a bit.
select b.book_from,
b.book_to,
b.flat_rate,
nvl(c.discount,0),
p.hourly,
p.half_day,
p.daily,
p.discountable,
p.surcharge,
l.evening_start,
nvl(b.full_day,'N')
from booking.bookings b,
booking.customer c,
booking.room_prices p,
booking.rooms r,
booking.location l
where b.id = 9272
and c.id = b.customer
and b.room = p.room
and b.room = r.id
and r.loc = l.id
and p.from_date =
select max(p2.from_date)
from booking.room_prices p2
where p2.room = p.room
and p2.from_date < b.book_from
Could anyone suggest a way to re-write the query so that it is outer joined to room_prices?
Thanks,
HazelThanks for both of your responses.
Unfortunately your suggestion didn't work Dmytro - still no rows are returned.
Here are some table creation scripts and test data to insert:
CREATE TABLE BOOKINGS
ID NUMBER NOT NULL,
ROOM NUMBER NOT NULL,
CUSTOMER NUMBER NOT NULL,
BOOK_FROM DATE NOT NULL,
BOOK_TO DATE NOT NULL,
CONFIG VARCHAR2(24) NOT NULL,
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
DELEGATES NUMBER,
NARRATIVE VARCHAR2(256),
CONTACT_DETAILS VARCHAR2(400),
CONFIRMED VARCHAR2(1),
CANC_REASON NUMBER,
FULL_DAY VARCHAR2(1),
FLAT_RATE NUMBER,
STANDBY NUMBER,
TOTAL_STANDBY_TIME DATE,
PRE_STANDBY_TIME DATE,
PRE_STANDBY NUMBER,
GL_CODE VARCHAR2(20)
CREATE TABLE CUSTOMER
ID NUMBER NOT NULL,
CUSTOMER VARCHAR2(160) NOT NULL,
CONTACT_ADDRESS VARCHAR2(240),
CONTACT_TELEPHONE VARCHAR2(20),
CONTACT_EMAIL VARCHAR2(160),
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
DISCOUNT NUMBER(5,2),
CUST_TYPE VARCHAR2(1),
CONTACT_FAX VARCHAR2(20),
DEBTOR_NO VARCHAR2(20),
BC_CONTACT VARCHAR2(64)
CREATE TABLE ROOMS
ID NUMBER NOT NULL,
LOC NUMBER NOT NULL,
NAME VARCHAR2(160) NOT NULL,
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
ACTIVE VARCHAR2(1),
ROOM_DESC VARCHAR2(2000)
CREATE TABLE LOCATION
ID NUMBER NOT NULL,
NAME VARCHAR2(240) NOT NULL,
ADDRESS VARCHAR2(240),
PCODE VARCHAR2(8),
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
CONF_RDF VARCHAR2(10),
CLOSING VARCHAR2(5),
EVENING_START VARCHAR2(5)
CREATE TABLE ROOM_PRICES
ROOM NUMBER NOT NULL,
FROM_DATE DATE NOT NULL,
HOURLY NUMBER(6,2),
HALF_DAY NUMBER(6,2),
DAILY NUMBER(6,2),
DISCOUNTABLE VARCHAR2(1),
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
SURCHARGE NUMBER(6,2)
Insert into bookings
(ID, ROOM, CUSTOMER, BOOK_FROM, BOOK_TO, CONFIG, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, DELEGATES, NARRATIVE, CONTACT_DETAILS, CONFIRMED, FLAT_RATE, PRE_STANDBY_TIME, PRE_STANDBY)
Values
(9272, 7466, 4946, TO_DATE('10/25/2005 10:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/25/2005 13:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Default', TO_DATE('10/27/2005 15:35:02', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', TO_DATE('10/27/2005 15:36:26', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 1, 'another meeting', 'Hazel', 'Y', 40, TO_DATE('10/25/2005 09:30:00', 'MM/DD/YYYY HH24:MI:SS'), 1800);
Insert into customer
(ID, CUSTOMER, CONTACT_ADDRESS, CONTACT_TELEPHONE, CREATED_DATE, CREATED_BY, CUST_TYPE, BC_CONTACT)
Values
(4946, 'Association of Teachers', 'Address', '0191 8887777', TO_DATE('09/22/2003 08:05:47', 'MM/DD/YYYY HH24:MI:SS'), 'Dataload', 'B', 'Miss Jones');
Insert into rooms
(ID, LOC, NAME, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, ACTIVE)
Values
(7466, 308, ' Counselling Room 1', TO_DATE('04/11/2005 10:55:33', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/22/2005 14:43:50', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 'Y');
Insert into location
(ID, NAME, ADDRESS, PCODE, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, CONF_RDF, CLOSING, EVENING_START)
Values
(308, 'Business Centre', 'Address', 'NE30 1NT', TO_DATE('03/19/2003 13:07:35', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/09/2005 11:17:09', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', 'BKCF_2', '22:30', '18:00');
Thanks,
Hazel -
Outer join problem (ORA-01799)
We have a database design roughly as follows:
- A STAFF table (columns don't matter here).
- Resources have a cost per hour that varies over time, so we have a STAFF_COST table with an effective date and a cost per hour
- A PROJECT table (columns don't matter here).
- Projects can have staff assigned, so we have a PROJECT_STAFF table which has foreign keys to the PROJECT and STAFF table.
- Project staff have a cost per hour, which can vary over time, and be different to the (default) staff costs. So we have a PROJECT_STAFF_COST table which uses the PROJECT_STAFF foreign key, with an effective date and a cost per hour
- Staff work on tasks so we have a TIMESHEET_TASK and TIMESHEET_DAY tables which define a project worked on, task within the project (optional as time can be 'entered against the project', who is recording the time, the hours worked and the day the hours were worked.
So when timesheet information is entered we have three scenario's that we need to cover.
1) The resource is a member of the project and the hours were worked on a day for which we have a project staff cost. That is, the project staff cost table has one or more rows for the staff member assigned to the given project with an effective date before the date the hours were entered against.
2) The resource is a member of the project but the hours were worked on a day for which we do not have a project staff cost. That is, the project staff cost table has one or more entries for the staff member assigned to the given project, but all the effective dates are after the date the hours were entered against.
3) The resource is not a member of the project. That is, the project staff cost table does not have any rows for the staff member. Time was entered 'against the project'.
We need to work out the actual cost of the project. So we need to retrieve every day's timesheet entry, returning the hours assigned and the cost per hour relevant for that day. I have the following query:
select tsh.staff_id, s.full_name, tsd.entry_date, tsd.hours as ProjectHours,
psCOST_INFO.cost_per_hour as ProjectCost
from timesheet_day tsd
inner join timesheet_task tst on tst.timesheet_task_id = tsd.timesheet_task_id
inner join timesheet_header tsh on tst.timesheet_header_id = tsh.timesheet_header_id
inner join staff s on s.staff_id = tsh.staff_id
left join (Select ps.project_id, ps.staff_id, psc.project_staff_id, psc.effective_date, psc.cost_per_hour
from project_staff ps
inner join project_staff_cost psc on ps.project_staff_id = psc.project_staff_id) as psCOST_INFO
on psCOST_INFO.staff_id = tsh.staff_id and psCOST_INFO.project_id = tst.project_id
and psCOST_INFO.effective_date = (select max(ps2.effective_date) from project_staff_cost ps2
where ps2.project_staff_id = psCOST_INFO.project_staff_id
and ps2.effective_date <= tsd.entry_date)
where tst.project_id = 55825
Using the left join covers scenario's 2 and 3 above because I will get null in the cost columns and can then take appropriate action. If I were to use an inner join, then hours in timesheets from scenario's 2 and 3 would be excluded, which is not what we want.
The subselect using the MAX aggregate function is required to get the cost per hour most relevant for the timesheet day. That is, if there are several effective dates for the project staff member before the date in question, we want the most recent one. We can't just use the MAX one, however in case there is an effective date after the particular timesheet date. Sheesh...
This query works fine in SQL Server. It it not allowed in Oracle and returns an ORA-01799 column may not be outer joined to a subquery.
I'm not going to bother to ask why not. I just need a way to do what I want. I've spent days trying to move the code around but I either end up with an inner join (which returns fewer rows than I want) or it just plain don't work.
Can someone help me rework this query to achieve the result I want?
Thanks, AndrewThanks for your reply, Laurent. In my experience trying to cut important corners in explaining a problem only serves to make it more difficult to solve. That pretty much was the smallest reproducable query that demonstrates the complexity of the problem I have. I'm not just trying to get which publishers live in the 'CA' state here...
From what I have just read about rank() it serves the same purpose as max() on a given column, and getting the maximum or top ranked one just doesn't cut it. As I said in my original post that provided all the relevant (and no spurious) information on the problem, it is possible that there are effective dates AFTER the date we are interested in and they have to be excluded.
I have to get the project staff cost row with the latest date that is before the timesheet date. That means I have to reference data in the outer query. Oracle seems to have a problem with that when used in an outer join.
We are currently going down the track of 3 UNION'd statement to cover the 3 scenario's. A single query would be more efficient so if anyone can provide guidance I would appreciate it.
Thanks, Andrew
Maybe you are looking for
-
Hello all, I am facing problem in restarting the java webconsole service. After disabling the java webconsole through "*smcwebserver stop*" command, I am unable to start the java webconsole. root@imola2> smcwebserver start Starting Sun Java(TM) Web C
-
How to create an internal table with fields from different sources
Hi. I need to create an internal table where some of the fields are from a database table, and the other fields are user specified. How do i do that? Example: DB table ZTAB with fields ZTAB-FIELD1, ZTAB-FIELD2. I want to create an internal table ITAB
-
Hi What is NWDI ? I need some documentation on NWDI... and how to install those components on NWDS ? Please Help Me Best Regards Ravi Shankar B
-
Does anyone know where I can find details on firing sequence of each type of triggers on Item, Block and Form levels? Can I set the Debugger to trace the actual sequence of firing of triggers at run-time? Message was edited by: wyfwong
-
How do I stop extra instances of Firefox program being opened by another page when it loads?
How do I stop extra instances of Firefox program being opened by another page when it loads? When I log on to a favorite site it loads OK. The site has a number of pages. When I move to the second or third page, a second instance of Firefox automatic