Application Development 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: 

abap query

Former Member
0 Kudos

how can i join a table by using abap query?

10 REPLIES 10

Former Member
0 Kudos

Priya-

SELECT lfa1lifnr lfa1stcd1

bsakxblnr bsakaugbl bsak~auggj

FROM lfa1

INNER JOIN bsak ON lfa1lifnr = bsaklifnr

INTO TABLE i_lfa1

WHERE lfa1~lifnr = actualvendorid

AND bsak~xblnr = ap03_invoicenumber .

I hope this will help you out...

Thanks,

Venky

aris_hidalgo
Contributor
0 Kudos

Hi,

The above example is right. I'll give you another example:

SELECT apsphi brefbn b~lifnr

FROM prps AS a INNER JOIN cooi AS b

ON aobjnr = bobjnr

INTO CORRESPONDING FIELDS OF it_hdr

WHERE a~psphi IN so_psphi

AND a~pbukr = pa_bukrs

AND a~erdat LE v_budat

AND b~refbn IN so_ebeln

AND b~lifnr IN so_lifnr

AND b~matnr IN so_matnr

AND b~rfart = 'P'.

Regards!

Former Member
0 Kudos

table should be having pri-foer key relation ship , the only u can join table in SQVI or any Joins , u cannt use Cluster table in ABAP Quey .

Former Member
0 Kudos

Hi Priya,

You can join tables using JOIN statement in ABAP.

But you can not join on cluster tabels.Be sure that your join tables are not of cluster tables.<b>To Join two tables you need to have a foreign key relation ship between tables.</b> There are two kinds of joins.

<b>1)Inner Join:</b> The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition.

<b>2)Outer Join:</b> The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition.

A maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM.

The ABAP statement for joinin tables is as follows.

PARAMETERS p_cityfr TYPE spfli-cityfrom.

DATA: BEGIN OF wa,

carrid TYPE scarr-carrid,

carrname TYPE scarr-carrname,

connid TYPE spfli-connid,

END OF wa,

itab LIKE SORTED TABLE OF wa

WITH NON-UNIQUE KEY carrid.

<b>SELECT scarrid scarrname p~connid

INTO CORRESPONDING FIELDS OF TABLE itab

FROM scarr AS s

INNER JOIN spfli AS p ON scarrid = pcarrid

AND p~cityfrom = p_cityfr.</b>

LOOP AT itab INTO wa.

IF wa-connid = '0000'.

WRITE: / wa-carrid, wa-carrname.

ENDIF.

ENDLOOP.

Thanks,

Vinay

Note: plz reward points to helpful answers

Former Member
0 Kudos

Hi,

select single a~smtp_addr from adr6 as a inner join

kna1 as k

on kadrnr = aaddrnumber

into i_clientinfo-Email

where k~KUNNR = i_clientinfo-clientid.

Regards,

abhishek

Former Member
0 Kudos

hi priya.

try out this.

parameters: p_matno like mkpf-mblnr.

data: begin of wt_mseg occurs 10,

zeile like mseg-zeile,

matnr like mseg-matnr,

maktx like makt-maktx,

menge like mseg-menge,

meins like mseg-meins,

end of wt_mseg.

select msegzeile msegmatnr

maktmaktx msegmenge

mseg~meins

into (wt_mseg-zeile,

wt_mseg-matnr,

wt_mseg-maktx,

wt_mseg-menge,

wt_mseg-meins)

from mseg inner join makt

on msegmatnr = maktmatnr

where mblnr = p_matno.

append wt_mseg.

endselect.

Former Member
0 Kudos

howhat r the steps in table controls in user exits

Manohar2u
Active Contributor
0 Kudos

Refer to this for abap query. In info sets you can do join between tables.

<a href="http://www.sappoint.com/abap/ab4query.pdf">ABAP Query</a>

Regds

Manohar

Former Member
0 Kudos

Hi,

u can go through the following two examples :

Inner Join:

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.

Outer join :

SELECT scarrid scarrname p~connid

INTO CORRESPONDING FIELDS OF TABLE itab

FROM scarr AS s

LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid AND

p~cityfrom = 'FRANKFURT'.

Former Member
0 Kudos

Hi,

You can join the TABLES in the Functional Area (Info Set in 5.0 ver.) Directly. You have the 'Insert Table' Option in the Tool Bar.

Regards

BaLaji