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

Join a subquery in ABAP

Former Member
0 Likes
2,743

Hello,

I need to join a subquery in ABAP but do not know how to do this. Maybe someone can help me.

Example:

select mmatnr sal*

INTO CORRESPONDING FIELDS OF TABLE xxx

from mara as m

join (

SELECT SUM( ewmeng ) AS best SUM( ebmeng ) AS assi a~matnr AS matnr

FROM vbep AS e

INNER JOIN vbap AS a

ON avbeln = evbeln AND aposnr = eposnr

GROUP BY a~matnr

) as sal

on mmatnr = salmatnr.

This is just a simplified example. I know, I could join all three tables here.

In the bigger example, the results should look like this

material # best assi XXXX

111 10 5 abcde

111 10 5 cdefg

112 5 5 ahftw

112 5 5 jagre

...

Thanks for any help!

1 ACCEPTED SOLUTION
Read only

andreas_mann3
Active Contributor
0 Likes
884

hi ,

have a look here:

A.

Hello,

I need to join a subquery in ABAP but do not know how to do this. Maybe someone can help me.

Example:

select mmatnr sal*

INTO CORRESPONDING FIELDS OF TABLE xxx

from mara as m

join (

SELECT SUM( ewmeng ) AS best SUM( ebmeng ) AS assi a~matnr AS matnr

FROM vbep AS e

INNER JOIN vbap AS a

ON avbeln = evbeln AND aposnr = eposnr

GROUP BY a~matnr

) as sal

on mmatnr = salmatnr.

This is just a simplified example. I know, I could join all three tables here.

In the bigger example, the results should look like this

material # best assi XXXX

111 10 5 abcde

111 10 5 cdefg

112 5 5 ahftw

112 5 5 jagre

...

Thanks for any help!

4 REPLIES 4
Read only

andreas_mann3
Active Contributor
0 Likes
885

hi ,

have a look here:

A.

Read only

Former Member
0 Likes
884

Hello MB

As I can check from your query you wish to list the material number and sal table contents as your output but I would just to use your sub query as the result since does have the material number...do you have any other information required from material master ?

Regards

Anurag

Read only

0 Likes
884

Hello,

thanks for your reply. I know, I could get the material number from this query. This is just an example. The SQL that I want tu build uses 5 tables. I have to join 4 of them with a grouped expression like in my example.

So I would like to use a subquery, group and sum up some fields in there and join it to the other 4 tables.

Best regards,

MB

Read only

SMGOHIL
Participant
0 Likes
884

In which ABAP version sub query is allowed as I am getting select is invalid here(due to grammer)