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

SELECT statement in FROM clause - syntax help

Former Member
0 Likes
1,233

Hi,

I want to have a SELECT statement in the FROM clause. I get syntax error when doing this and since I am new to ABAP I need som help.

I want to do the following, (and if anyone has any SELECT statement from their own system which you know there is no syntax error in please post it here so I can analyze the syntax):

*I leave the INTO itab clause out, since I only want to demonstrate the functionality

  • I am trying to get.

<b>SELECT</b> tableOne~someField

<b>FROM</b> tab <b>AS</b> tableOne (<b>SELECT</b> someField

<b>FROM</b> tab

<b>WHERE</b> someFiled > 1) <b>AS</b> tableTwo

<b>WHERE</b> tableOnesomeField > tableTwosomeField

like I said, the problem is that the select statement in the parenthesis in the from clause seems to be incorrect because I get "wrong expression" when trying to compile. Is this because I cannot have a select statement in the from clause or is it because of a minor syntax error, such as I forgot a dot, or some other sign?

thanks and regards

Baran

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,018

Hi

I suppose you want to do a join, don't I?

If it's so:

SELECT tableOnesomeField tableTwosomeField

FROM tab AS tableOne A INNER JOIN tab2 AS tableTwo

on tableOnesomeField > tableTwosomeField

INTO TABLE ITAB.

WHERE tableTwo~someFiled > 1.

Where ITAB is an internal table with fields of TAB and TAB2.

Max

5 REPLIES 5
Read only

Former Member
0 Likes
1,019

Hi

I suppose you want to do a join, don't I?

If it's so:

SELECT tableOnesomeField tableTwosomeField

FROM tab AS tableOne A INNER JOIN tab2 AS tableTwo

on tableOnesomeField > tableTwosomeField

INTO TABLE ITAB.

WHERE tableTwo~someFiled > 1.

Where ITAB is an internal table with fields of TAB and TAB2.

Max

Read only

Former Member
0 Likes
1,018

Baron,

Write the staement like below.

data : begin of itab occurs 0,

some field like tableTwo-somefield,

end of itab.

SELECT someField into table itab

FROM tab

WHERE someFiled > 1.

if not itab[] is initial.

SELECT someField

into table itab2

FROM tableOne

for all entries in itab

WHERE someField > itabsomeField.

endif.

Pls. reward if useful

Read only

Former Member
0 Likes
1,018

sorry i am not enough familiar with sub queries but some error i can see which i will state here.

1> you have to use sub queries i.e. select in ( ) after where clause because here you are fulfilling a where clause by another select statement.

like this

SELECT * FROM SFLIGHT

INTO WA

WHERE SEATSOCC = ( SELECT MAX( SEATSOCC ) FROM SFLIGHT ).

2> you cannot specify field name without into clause either you have to use

select * or select f1 into tab-f1 like this...

but if you are using select * without into you have to define

tables : dbtab.

selec * from dbtab. like that.

regards

shiba dutta

Read only

Former Member
0 Likes
1,018

hi,

check this

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.

Regards,

Sruthi

Read only

Former Member
0 Likes
1,018
I guess you cannot use subqueries in FROM claus , u can only use in WHERE condition


REPORT ZTEST.

TABLES :MARA , MAKT , DD02L.

DATA : V_MATNR LIKE MARA-MATNR,
       V_MAKTX LIKE MAKT-MAKTX.



SELECT SINGLE A~MATNR
       B~MAKTX
       FROM MARA AS A INNER JOIN
            MAKT AS B
            ON A~MATNR EQ B~MATNR
            INTO (V_MATNR , V_MAKTX)
            WHERE A~MATNR EQ ( SELECT MAX( SEATSOCC ) FROM SFLIGHT ).