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

Joins With 3 table

ABAPER_P
Participant
0 Likes
3,246

Hi all

I have 3 tables BKPF , BSID , BSAD.

BELNR document number will be present in either BSID (open doc ) or BSAD (cleared doc) .

Driving table here is BKPF. document number will be always present in BKPF table.

Now I need join condition if document number is present in any one of the table either BSID or BSAD I shoud get records in internal table . I have created inner join of all these 3 tables but its not woking

Hi all

I have 3 tables BKPF , BSID , BSAD.

BELNR document number will be present in either BSID (open doc ) or BSAD (cleared doc) .

Driving table here is BKPF. document number will be always present in BKPF table.

Now I need join condition if document number is present in any one of the table either BSID or BSAD I shoud get records in internal table . I have created inner join of all these 3 tables but its not woking

7 REPLIES 7
Read only

Former Member
0 Likes
2,608

Hi ABAPER P,

Try below Code.

SELECT a~bukrs
a~belnr
a~gjahr
FROM bkpf AS a
JOIN bsid AS b ON b~belnr = a~belnr
LEFT OUTER JOIN bsad AS c ON c~belnr = a~belnr
INTO TABLE it_tab
WHERE a~bukrs = '1200'
AND a~belnr IN p_belnr
AND a~gjahr = '2018'.

Thanks,

Surji

Read only

2,608

And if document exists in BSAD and not in BSID the above select will fail...

Read only

nick_giannakis
Explorer
0 Likes
2,608

On what "SAP_ABA" component you are working?

Read only

nick_giannakis
Explorer
2,608

Trying to go with surji.murugesan's answer a little bit further,

SELECT a~bukrs,
       a~belnr,
       a~gjahr
       FROM bkpf AS a
       INNER JOIN bsid AS b ON b~belnr = a~belnr
                           AND b~gjahr = a~gjahr
WHERE a~bukrs = '1200'
  AND a~belnr = @p_belnr
  AND a~gjahr = '2018'

UNION
SELECT a~bukrs,
       a~belnr,
       a~gjahr
       FROM bkpf AS a
       INNER JOIN bsad AS b ON b~belnr = a~belnr
                           AND b~gjahr = a~gjahr
WHERE a~bukrs = '1200'
  AND a~belnr = @p_belnr
  AND a~gjahr = '2018'

  INTO TABLE @it_tab.

Maybe for someone will not be the ideal solution, but will do the trick.

Read only

Nawanandana
Active Contributor
0 Likes
2,608

Hi,

you can use FM to fetch the data from those table

Regards,

Nawa

Read only

SimoneMilesi
Active Contributor
0 Likes
2,608

You already pointed out the issue

Now I need join condition if document number is present in any one of the table either BSID or BSAD I shoud get records in internal table . I have created inner join of all these 3 tables but its not woking

Since a record will be in BSAD ---OR--- BSID, if you use INNER JOIN, you'll never get anything, because the record would not be present in both of them

Read only

juan_suros
Contributor
0 Likes
2,608

Why not join BKPF to BSEG?

The helper tables BSID and BSAD each hold a subset of the data in BSEG. BSEG holds all of the accounting document segments both closed and not closed.