2

I am writing a BSP and based on user-input I need to select data from different DB tables. These tables are in different packages. Is it possible to specify the table I want to use, based on its path, like this:

data: path1 type string value 'package1/DbTableName',
      path2 type string value 'package2/OtherDbTableName',
      table_to_use type string.

if some condition
table_to_use = path1.    
elseif some condition
table_to_use = path2.    
endif.

select *
from table_to_use

     ...

endselect

I am new to ABAP & Open SQL and am aware this could be an easy/silly question :) Any help at all would be very much appreciated!

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
B. Bowles
  • 764
  • 4
  • 9
  • 21

1 Answers1

5

You can define the name of the table to use in a variable, and then use the variable in the FROM close of your request :

data tableName type tabname.  
if <some condition>.   
   tableName='PA0001'.   
else.   
   tableName='PA0002'.   
endif.   
select * from (tableName) where ...

there are a few limitation to this method, as the stable can not contains fields of type RAWSTRING, STRING or SSTRING.

as for the fact that the table are in different package, i don't think it matters.

Regards,

Esti
  • 3,677
  • 8
  • 35
  • 57
PATRY Guillaume
  • 4,287
  • 1
  • 32
  • 41
  • 1
    Yep, package assignment usually makes no difference. If the package check is switch on in the system (it is usually not) - it is possible that it may matter depending on how the packages were set up and which objects are made available by the package. – Esti Jan 16 '12 at 21:23
  • @Esti : thanks for the info on package check. I have never seen it used, and didn't even know it existed. – PATRY Guillaume Jan 16 '12 at 22:21