Dear All,
I wanted to know, how can I write a Simple ABAP Program, where I have to fetch data from more than 2 tables. I know joining 2 tables but want should I do if I have to fetch data from 3 or more tables.
Any example would be really great.
Thanking you.
Regards
Venkat.
Hi,
Check this example for more than 3 tables...
DATA: BEGIN OF ITAB OCCURS 0,
MATNR TYPE MATNR,
WERKS TYPE WERKS_D,
VKORG TYPE VKORG,
VTWEG TYPE VTWEG,
BWKEY TYPE BWKEY,
END OF ITAB.
PARAMETERS: P_MATNR TYPE MATNR.
SELECT AMATNR BWERKS C~VKORG
CVTWEG DBWKEY
INTO TABLE ITAB
FROM MARA AS A
INNER JOIN MARC AS B
ON AMATNR = BMATNR
INNER JOIN MVKE AS C
ON AMATNR = CMATNR
INNER JOIN MBEW AS D
ON AMATNR = DMATNR
WHERE A~MATNR = P_MATNR.
CHECK SY-SUBRC = 0.
Thanks,
Naren
Hi,
Check this example...
DATA: BEGIN OF ITAB OCCURS 0,
MATNR TYPE MATNR,
WERKS TYPE WERKS_D,
VKORG TYPE VKORG,
VTWEG TYPE VTWEG,
END OF ITAB.
PARAMETERS: P_MATNR TYPE MATNR.
SELECT AMATNR BWERKS C~VKORG
C~VTWEG
INTO TABLE ITAB
FROM MARA AS A INNER JOIN MARC AS B
ON AMATNR = BMATNR
INNER JOIN MVKE AS C
ON AMATNR = CMATNR
WHERE A~MATNR = P_MATNR.
CHECK SY-SUBRC = 0.
Thanks,
Naren
Hi venkat,
This is one select query which I worte it today so sending you.
Here I am fetching data from more than 3 tables.
<b>SELECT STSTLNR STIDNRK STPOSNR STMENGE ST~MEINS
MK~MAKTX
AK~AUFNR
INTO CORRESPONDING FIELDS OF TABLE IT_STPO
FROM STPO AS ST INNER JOIN MAKT AS MK
ON STIDNRK = MKMATNR
INNER JOIN AFKO AS AK
ON STSTLNR = AKSTLNR
FOR ALL ENTRIES IN IT_AFRU
WHERE ST~STLNR = IT_AFRU-STLNR AND
AK~AUFNR = IT_AFRU-AUFNR AND
SPRAS = 'E'.</b>
Let me know if you have any queries.
Vinod.
SELECT MSEGMATNR MSEGWERKS MSEGMBLNR MSEGZEILE MSEG~EBELN
MSEGEBELP MSEGMENGE MSEGBWART MSEGEBELN MSEG~ERFME
MSEGKOSTL MSEGLGORT MSEGMJAHR MSEGSHKZG EKKO~EKGRP
EKKOLIFNR EKPOMATKL MKPFBUDAT MKPFUSNAM
FROM ( MSEG
INNER JOIN EKKO
ON MSEGEBELN = EKKOEBELN
INNER JOIN EKPO
ON MSEGEBELN = EKPOEBELN
AND MSEGEBELP = EKPOEBELP
INNER JOIN MKPF
ON MSEGMBLNR = MKPFMBLNR
AND MSEGMJAHR = MKPFMJAHR )
APPENDING CORRESPONDING FIELDS OF TABLE IT_YMM_ST_TNUOT_MLY
WHERE MSEG~MBLNR IN SL_MBLNR
AND MSEG~MATNR IN SL_MATNR
AND MSEG~WERKS IN SL_WERKS
AND MSEG~LGORT IN SL_LGORT
AND MSEG~LIFNR IN SL_LIFNR
AND MSEG~KOSTL IN SL_KOSTL
AND EKKO~EKGRP IN SL_EKGRP
AND EKPO~MATKL IN SL_MATKL
AND MKPF~BUDAT IN SL_BUDAT .
Hi Venkat,
U can join multiple tables no prob but performance will be a major issue ...so joining upto 2 tables is ok but for more than 2 u may experience problem. Retrieve all the records by joining two tables in one internal table then using that table as a driver table try to select rest of the records from other tables .
If it sounds good pl reward.
Cheers.
Hi,
You can join multiple tables no prob but performance will be a major issue ...so joining upto 3 tables is ok but for more than 3 you may experience problem. Retrieve all the records by joining three tables in one internal table then using that internal table in the command Select for all entries try to get the records from other table.
Regadrs,
Govindarajan Umadevi.
Add a comment