Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

INNER JOIN

Former Member
0 Likes
1,050

guys!!! how can we join two fields each of three tables using INNER JOIN command?

like 2 fields each of MARA MARC MARD INTO one table using INNER JOIN command...

Regards,

ajit.

10 REPLIES 10
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
984

This can be done simply like this.




data: begin of itab occurs 0,
      matnr type mara-matnr,
      mtart type mara-mtart,
      werks type marc-werks,
      dispo type marc-dispo,
      lgort type mard-lgort,
      labst type mard-labst,
      end of itab.


select mara~matnr mara~mtart marc~werks marc~dispo
       mard~lgort mard~labst
              into table itab
                      from mara
                          inner join marc
                             on mara~matnr = marc~matnr
                          inner join mard
                             on marc~matnr = mard~matnr
                            and marc~werks = mard~werks
                                  up to 10 rows.

Regards,

Rich Heilman

PS.

Put yourself on the SDN world map (http://sdn.idizaai.be/sdn_world/sdn_world.html) and earn 25 points.

Spread the wor(l)d!

Read only

Former Member
0 Likes
984
SELECT a~matnr b~werks c~lgort
  into table itab from mara as a inner join marc as b inner join mard as c
    on a~matnr = b~matnr
    on b~matnr = c~matnr.
Read only

Former Member
0 Likes
984

SELECT MARA~FIELD MARC~FIELD MARD~FIELD
INTO CORRESPONDING FIELDS OF TABLE
FROM MARA
 INNER JOIN MARC
 ON MARA~MATNR = MARC~MATNR
  AND MARA~XXX = MARC~XXX
 INNER JOIN ON MARD
 ON MARA~MATNR = MARD~MATNR
  AND MARA~YYY = MARD~YYY

Regards,

Ravi

Note : Please mark all the helpful answers

Read only

Former Member
0 Likes
984

SORRY TO SAY!!! but none of your statements worked guyz!!!

Read only

0 Likes
984

Hi Ziden,

Go through the below sample code,

DATA: BEGIN OF wa,

carrid TYPE spfli-carrid,

connid TYPE spfli-connid,

fldate TYPE sflight-fldate,

bookid TYPE sbook-bookid,

END OF wa,

itab LIKE SORTED TABLE OF wa

WITH UNIQUE KEY carrid connid fldate bookid.

SELECT pcarrid pconnid ffldate bbookid

INTO CORRESPONDING FIELDS OF TABLE itab

FROM ( ( spfli AS p

INNER JOIN sflight AS f ON pcarrid = fcarrid AND

pconnid = fconnid )

INNER JOIN sbook AS b ON bcarrid = fcarrid AND

bconnid = fconnid AND

bfldate = ffldate )

WHERE p~cityfrom = 'FRANKFURT' AND

p~cityto = 'NEW YORK' AND

fseatsmax > fseatsocc.

LOOP AT itab INTO wa.

AT NEW fldate.

WRITE: / wa-carrid, wa-connid, wa-fldate.

ENDAT.

WRITE / wa-bookid.

ENDLOOP.

Reward points for helpful answers.

Regards,

Azaz Ali.

Read only

0 Likes
984

doesnot worked means what error u r getting.

all the stements above mentioned are correct.

what error u r facing and if u want some thing more, try to explain more clearly.

SELECT AMATNR AMTART BWERKS BLVORM CLGORT CLABST

FROM MARA AS A INNER JOIN MARC AS B ON AMATNR = BMATNR

INNER JOIN MARD AS C ON CWERKS = DWERKS INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE <CONDITION>.

Read only

Former Member
0 Likes
984

hello rich!!!

Rn't u using aliaz names in your statement??

If using , can we use table name itself as aliaz names???

n moreover!!! dont we need to write

<table name> AS <aliaz name> in d statement

it wud be thankful if u clear all my doubts as u've written d statement.

and cud u plz use CORRESPONDING FIELDS OF in ya statement n write d stmt again...??

Regards,

ajit.

Read only

0 Likes
984

ALIAS STATEMENTS are not compulsory and also into corresponding fields is also not compulsory, if u retrive the fields in order.

what ever RICH written is excatly right. there would be no syntax error in that if u retrieve fields in order.

Read only

Former Member
0 Likes
984

Rich Code is perfect....

Read only

Former Member
0 Likes
984

select matnr into itab from

mara as a inner join marc as c

on aMATNR = cMATnr

innerjoin MARD as d

on aMATNR = dMATNR