cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem with SELECT statements

Former Member
0 Likes
1,886

Hello,

I am working with 4 tables - lfa1, lfb1, bsik and bsak.

Initially i have to get 'LIFNR' from 'lfa1' based on some condition for 'BUKRS' in 'lfb1'.

Now, i should use these 'LIFNRs' and look up payments in 'bsik' and 'bsak'. I am stuck in the middle of writing the select statements. My code:

SELECT DISTINCT a~lifnr INTO itab-lifnr

FROM lfa1 AS a INNER JOIN lfb1 AS b ON alifnr = blifnr

WHERE b~bukrs BETWEEN '100' AND '200'.

SELECT DISTINCT clifnr cdmbtr INTO CORRESPONDING FIELDS OF TABLE itab2

FROM bsik AS c INNER JOIN bsak AS d ON clifnr = dlifnr

WHERE cbukrs = dbukrs AND

c~lifnr = itab-lifnr.

itab has field 'lifnr' and itab2 has fields 'lifnr' & 'dmbtr'. After executing these select statements, i am not getting expected output from the second select statement. Can someone tell me where am i going wrong.

Thanks.

View Entire Topic
Former Member
0 Likes

Try this:

select alifnr cshkzg c~dmbtr

from ( ( lfa1 as a inner join lfb1 as b on alifnr = blifnr ) inner join bsak as c on clifnr = blifnr )

into table itab

where b~bukrs between '100' and '200'.

The shkzg is the debit/credit indicator.

Another thing, i dont see the reason why you have to use the lfa1 table at all. If vendor numbers are all you are after then all you need is to get them from lfb1 and use it to get line items from bsak.

Former Member
0 Likes

Feroz & Srinivas,

I will try your options and let you know.

Thanks for your help.

Message was edited by: Sachin Guptha