ABAP – SELECT Statement with a variable table name

I just figured out a cool trick last night, and this may be old hat to a lot of you.  I was working on the latest piece of Proximity, and I wanted to be able to re-use my code, but each place would call it’s own custom transparent table.  The structures were the same, so it was an easy change.  Well, turns out it was a pretty easy trick.  You can create a Select statement with a variable table name.  Check it out the specific details below.

DATA: L_TABNAME TYPE DD02L-TABNAME.
L_TABNAME = ‘Z_TABLE’.

        select single * from (L_TABNAME) into z_wa
where field  = field.

That’s it.  Again, a trick I could’ve used a long time ago, but finally did the research last night to implement it.  Hope you find this handy.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top