‎2005 Jul 18 12:41 PM
Hi guys,
is it possible to select multiple dtab`s?
I thought about something like this:
" Select var1.dtab1, var2.dtab2 from dtab1, dtab2 where var3.dtab1 = var4.dtab2 ..."
Sorry for that Question but i'm a newbie in ABAP.
Thanks for reply's
Marcus
‎2005 Jul 18 12:48 PM
Yes it is possible using JOINS.
See this example
DATA: CUSTOMER TYPE SCUSTOM,
BOOKING TYPE SBOOK.
SELECT SCUSTOMNAME SCUSTOMPOSTCODE SCUSTOM~CITY
SBOOKFLDATE SBOOKCARRID SBOOKCONNID SBOOKBOOKID
INTO (CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID)
FROM SCUSTOM LEFT OUTER JOIN SBOOK
ON SCUSTOMID = SBOOKCUSTOMID AND
SBOOK~FLDATE = '20011015'
ORDER BY SCUSTOMNAME SBOOKFLDATE.
WRITE: / CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID.
ENDSELECT.
‎2005 Jul 18 12:46 PM
yes, this is called <b>JOINS</b>
here is a sample code from ABAP key word documentation.
for more on this topic read the ABAP key word documentation for <b>JOIN</b>
PARAMETERS: p_cityfr TYPE spfli-cityfrom,
p_cityto TYPE spfli-cityto.
DATA: BEGIN OF wa,
fldate TYPE sflight-fldate,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa.
DATA itab LIKE SORTED TABLE OF wa
WITH UNIQUE KEY fldate carrname connid.
SELECT c~carrname p~connid f~fldate
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( scarr AS c
INNER JOIN spfli AS p ON p~carrid = c~carrid
AND p~cityfrom = p_cityfr
AND p~cityto = p_cityto )
INNER JOIN sflight AS f ON f~carrid = p~carrid
AND f~connid = p~connid ).
LOOP AT itab INTO wa.
WRITE: / wa-fldate, wa-carrname, wa-connid.
ENDLOOP.
Regards
Raja
‎2005 Jul 18 12:49 PM
Hello Raja,
I know the ABAP key word documentation,
and JOINS are not really new for me, but i thought there will be another solution for that problem.
In other program languages like PHP, it is possible to do:
Select var1.dtab1 from dtab1,dtab2 where .......
So it isn´t possible in ABAP?
regards
Marcus
‎2005 Jul 18 12:53 PM
there is no other way using OPEN SQL.
I dont know whether NATIVE SQL (which you can use in an ABAP program) supports this kind of selects.
Regards
Raja
‎2007 Nov 15 2:42 AM
hi,
In a join, is there an easy way to select all fields of one of the table?
E.g.
SELECT <b>a~*</b> INTO some_itab
FROM ( table_1 AS a
INNER JOIN table_2 AS b ON ....).
With a*, I want to select all fields of a into some_itab. Of course, a* was reported not illegal grammar. Just want to know: is that possible to avoid use afield1, afield2, ... to fetch all fields of a in the join ABAP open SQL?
Thanks and kind regards,
Said
‎2005 Jul 18 12:47 PM
Hi Marcus,
u can achieve the same using Joins:
check this sample query:
select cdhdrusername cdposvalue_old cdpos~value_new
into table i_output
from ( cdhdr INNER JOIN cdpos
<b>* on cdhdrobjectid = cdposobjectid )</b>
where cdhdr~objectclas = lc_class
and cdhdr~objectid like lv_objid
and cdhdr~change_ind = lv_status
and cdposobjectid = cdhdrobjectid
and cdpostabkey = cdhdrobjectid
and cdposchangenr = cdhdrchangenr.
But the two tables should be having a field in common. Now try it out this way as per your requirement.
hope this helps you.
Regards,
Anjali.
‎2005 Jul 18 12:48 PM
Yes it is possible using JOINS.
See this example
DATA: CUSTOMER TYPE SCUSTOM,
BOOKING TYPE SBOOK.
SELECT SCUSTOMNAME SCUSTOMPOSTCODE SCUSTOM~CITY
SBOOKFLDATE SBOOKCARRID SBOOKCONNID SBOOKBOOKID
INTO (CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID)
FROM SCUSTOM LEFT OUTER JOIN SBOOK
ON SCUSTOMID = SBOOKCUSTOMID AND
SBOOK~FLDATE = '20011015'
ORDER BY SCUSTOMNAME SBOOKFLDATE.
WRITE: / CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID.
ENDSELECT.
‎2005 Jul 18 12:57 PM
Hi,
This can be done by using Inner join in select query u can do a f1 check in select query,
eg.
SELECT c~ekgrp
a~matnr
b~maktx
c~werks
c~minbe
INTO CORRESPONDING FIELDS OF TABLE i_output
<b>FROM mara AS a INNER JOIN makt AS b
ON amatnr = bmatnr</b>
<b>INNER JOIN marc AS c</b>
ON <b>amatnr = cmatnr</b>
<b>inner join MSKU as d</b>* on <b>amatnr = dmatnr</b>* WHERE a~matnr IN s_matnr
AND a~mtart IN s_mtart
AND c~werks IN s_werks
AND c~ekgrp IN s_ekgrp
AND c~lgfsb IN s_lgfsb
and d~KUNNR in s_kunnr
and d~sobkz = c_w
and d~kulab > 0.
In this case it is for four tables.
Similarly u can check the sample code in the documentation.
If ur problem got solved kindly reward points and close the thread.
‎2007 Nov 15 2:49 AM
HI
Yes its possible to select data from multiple tables using JOINS..
as above examples..
But we should try to keep no DATAbase tables minimum as good Practise..
Try to yse READ and FOR ALL Entries for multiple tables .
Praveen
‎2007 Nov 15 4:25 AM
thanks, praveen.
I think maybe I didn't express clear.
What is wanted is:
there two table a, b; they will be joined; while only all the fields of a need to be in the result. How to do this in ABAP SQL with something like table_1.* in standard SQL?
B.T.W.
Could you kindly explain the READ and FOR ALL in detail?
Regards,
Said