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: 

Self join using ABAP Query

Former Member
0 Kudos

Hello all,

How to create a self join using ABAP Query?

Say, I have this table EKBE with belnr (materials doc num) and lfbnr (reference material doc num). I have to pick the PO's from EKBE whose belnr doesnt have any lfbnr.

Regards

Madhumathi A

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Use the below select -

select *

from ekbe as a

into table itab

where not exists ( select * from ekbe

where ifbnr eq a~belnr ).

Hope it works..

Reward points if found useful...!

Cheers

Abhishek

7 REPLIES 7

Former Member
0 Kudos

Hi

in select option mention the condition that lfbnr = 0 and belnr <> 0.

this will fecth only the required

thanks

Shiva

0 Kudos

Hi ,

My requirement is that,

I have to pick the PO's with movement type 103, which does not have a corresponding 104 document (which are not rejected) using ABAP query.

So, in this case I think a different logic should be used altogether.

Regards

Madhumathi A

Former Member
0 Kudos

hi madhu,

tables : ekbe.

data itab like standard table of ekbe with header line.

select * from ekbe into table itab where belnr >< 0 and lfbnr = ' '.

loop at itab.

write 😕 itab-belnr,itab-lfbnr.

endloop.

check this code this works to select the orders whose belnr doesnt have any lfbnr

reward points if useful.

Former Member
0 Kudos

Hi,

Use the below select -

select *

from ekbe as a

into table itab

where not exists ( select * from ekbe

where ifbnr eq a~belnr ).

Hope it works..

Reward points if found useful...!

Cheers

Abhishek

Former Member
0 Kudos

Hi

Try out this code.

select-options:

s_belnr for ekbe-belnr.

data : begin of it_ekbe occurs 0,

ebeln like ekbe-ebeln,

belnr like ekbe-belnr,

end of it_ekbe.

select distinct aebeln abelnr

into corresponding fields of table it_ekbe

from ekbe as a inner join ekbe as b

on abelnr <> blfbnr

where a~belnr in s_belnr and

b~belnr in s_belnr.

HOPE THIS WILL HELP YOU.

Regs

Nimesh.

0 Kudos

Hi

Thanks all of u. I have got the solution..

Regards

Madhumathi A

0 Kudos

It would be helpful for me, if you post your solution that you found for your problem.