‎2007 Nov 19 9:12 AM
Hi all,
There are three tables in SAP they are, stop, stko, mast. And i have to join them on the basis of STLNR, that's what i am not able to do, can you show me a way.
‎2007 Nov 19 9:38 AM
Hi,
TABLES : stpo, stko, mast.
SELECT-OPTIONS : s_stlnr FOR stpo-stlnr.
SELECT stpo~stlnr <field2> <field3> <field4> ..... INTO TABLE itab FROM stpo
INNER JOIN stko ON stpo~stlnr = stko~stlnr
INNER JOIN mast ON stpo~stlnr = mast~stlnr WHERE
stpo~stlnr IN s_stlnr.
‎2007 Nov 19 9:18 AM
Hi,
Use FOR ALL ENTRIES for that.
select data from stko based on stlnr then using for all entries select data from stpo and mast.
Ex.
Select data
from stko
into table it_stko
where stlnr in s_stlnr.
if not it_stko[] is initial.
select data
from stpo
into table it_stpo
for all entries in it_stko
where stlnr eq it_stko-stlnr.
endif.
if not it_stko[] is initial.
select data
from mast
into table it_mast
for all entries in it_stko
where stlnr eq it_stko-stlnr.
endif.
Reward Points.
Regards,
Prashant
‎2007 Nov 19 9:29 AM
HI
BY USEING FOR ALL ENTRIES YOU CAN JOIN THESE 3 TABLES
<b>FOR ALL ENTRIES WHERE</b>
... FOR ALL ENTRIES IN itab WHERE ... col operator itab-comp ...
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.
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.
‎2007 Nov 19 9:36 AM
Hi,
select af1 b f2 cf3 into corresponding fields of table itab from ( stop as a inner join stko as b on aSTLNR = bSTLNR inner join mast as c on aSTLNR = c~STLNR).
where,
f1 - field that you require from table stop
f2- field that you require from table stko
f3- field that you require from table mast
itab -internal table.
STLNR- field that is common in 3 tables.
‎2007 Nov 19 9:38 AM
Hi.
Try this
Select * into itab from ( ( stko as p inner join stpo as k on pstlnr = kstlnr )
inner join mast as t on pstlnr = tstlnr ) wher <condition>
Hope it will helps.
Regards
Bala.
‎2007 Nov 19 9:38 AM
Hi,
TABLES : stpo, stko, mast.
SELECT-OPTIONS : s_stlnr FOR stpo-stlnr.
SELECT stpo~stlnr <field2> <field3> <field4> ..... INTO TABLE itab FROM stpo
INNER JOIN stko ON stpo~stlnr = stko~stlnr
INNER JOIN mast ON stpo~stlnr = mast~stlnr WHERE
stpo~stlnr IN s_stlnr.