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

How i select from (conditional table)?

0 Likes
832

Hi,

i want to select from different tables without to do two select. I want to choose  which table i do the select with a condition before.

I try something like this but it didn't work.

DATA   lv_table   TYPE char10.

IF .........

lv_table  =  'sel_table1'.

else.

lv_table  = 'sel_table2'.

ENDIF.

SELECT * FROM (lv_table) INTO TABLE wa_table

    WHERE .......... IN ..........

I dont know if the brackets are the right way to do it.

any help are accepted.

Thanks

Dio

1 ACCEPTED SOLUTION
Read only

yogendra_bhaskar
Contributor
0 Likes
752

Hi Dio ,

TRY this , it will work

DATA   lv_table   TYPE char10.

DATA : X_HEADER LIKE  VIMDESC.

IF .........

lv_table  =  'sel_table1'.

else.

lv_table  = 'sel_table2'.

ENDIF.

 
x_header-texttab = lv_table.

SELECT * FROM (x_header-texttab) INTO TABLE wa_table

     WHERE .......... IN ..........

Regards ,

Yogendra Bhaskar


5 REPLIES 5
Read only

yogendra_bhaskar
Contributor
0 Likes
753

Hi Dio ,

TRY this , it will work

DATA   lv_table   TYPE char10.

DATA : X_HEADER LIKE  VIMDESC.

IF .........

lv_table  =  'sel_table1'.

else.

lv_table  = 'sel_table2'.

ENDIF.

 
x_header-texttab = lv_table.

SELECT * FROM (x_header-texttab) INTO TABLE wa_table

     WHERE .......... IN ..........

Regards ,

Yogendra Bhaskar


Read only

Former Member
0 Likes
752

Hi Dio,

The bracket is the right way to do this. Try with:

DATA   lv_table   TYPE string.

Cheers!

Read only

former_member195270
Active Participant
0 Likes
752

If you want to select from two table in single select then you have to do Inner Join.

Read only

0 Likes
752

Thanks to every one but nothing of this works on me.

I dont think that i can avoid two select.

Read only

Sijin_Chandran
Active Contributor
0 Likes
752

Hi Dio ,

What was the problem with your technique ?

This technique is dynamic selection.

You need to define according internal tables.

And write selection statements in conditions.

You need to write two select statements but only one ( depending on condition ) will be executed.