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 within the case statement...

Former Member
0 Likes
1,095

Is it possible to declare a select within a case statement?

I got an error.. I declared the CASE under my WHEN statement...

Please advise... Thanks!

regards,

Mark

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,046

Hi,

check this sample code..

TABLES: MARA,

MVKE.

CASE sy-subrc.

WHEN 0.

SELECT SINGLE * FROM MARA where MATNR = 'TEST'.

WHEN 1.

SELECT SINGLE * FROM MVKE WHERE MATNR = 'TEST'.

ENDCASE.

Also please post your code..

Thanks

Naren

8 REPLIES 8
Read only

Former Member
0 Likes
1,046

Hi Mark,

Here is a sample

case decision_field.

when something.

select * etc......

when something_else.

when others.

endcase.

thanks.

Jamie

Read only

0 Likes
1,046

Thanks Jamie,,,

But thats the code I used when I encounter an error ...

Seem not to work..

Read only

0 Likes
1,046

if you use select * ... use ENDSELECT incase not importing to internal table...

other wise it will work perfectly.

Read only

Former Member
0 Likes
1,047

Hi,

check this sample code..

TABLES: MARA,

MVKE.

CASE sy-subrc.

WHEN 0.

SELECT SINGLE * FROM MARA where MATNR = 'TEST'.

WHEN 1.

SELECT SINGLE * FROM MVKE WHERE MATNR = 'TEST'.

ENDCASE.

Also please post your code..

Thanks

Naren

Read only

Former Member
0 Likes
1,046

Hi Mark,

can u paste the code where u get error?

Also tell us what is the error u get?

Read only

Former Member
0 Likes
1,046

are you using endselect with select statement without into any internal table

just add error in this thread for more clear picture

Read only

Former Member
0 Likes
1,046

hi mark,

if u use select statement fetching the data into an internal table then u won't have this problem

select * from trans_table into table itab where cond.

eg:

case 'X'.

when 0.

select statement.

when 1.

select statement.

when others .

select statement.

end case.

hope this helps u.

regards,

sohi

Read only

Former Member
0 Likes
1,046

Hi Mark,

Why did you get error it is perfectly work.

Try this code.

Data t_table type table of spfli with header line.

data w_temp type c value 'X'.

Case w_temp.

when 'X'.

Select * from spfli into table t_table.

endcase.

Plz Reward if useful,

Mahi.