Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Passing a variable to select statement

Hi there,

I have a selection screen on which you can choose which table do you want to display.

I store the name of the selected table in a variable tab_name.

I want to use something like that:

data: tab_name(40).

.

.

.

select * from tab_name

into gt_master.

endselect.

But it did not allowed because tab_name is not a database table.

Is it possible to pass the table name in a select statement using a variable?

Tags:
Former Member
Former Member replied

Hello

Yes it is posible you can use a dynamic select...

Try this:

DATA tabname(10).

DATA: BEGIN OF wa,

id TYPE scustom-id,

name TYPE scustom-name,

END OF wa.

tabname = 'SCUSTOM'.

SELECT id name INTO CORRESPONDING FIELDS OF wa FROM (tabname).

WRITE: / wa-id, wa-name.

ENDSELECT.

or

CONSTANTS: flight_tab_name(30) VALUE 'SPFLI'.

DATA: from_clause TYPE STRING.

DATA: BEGIN OF wa,

name(20) TYPE C,

connid TYPE spfli-connid,

END OF wa.

CONCATENATE flight_tab_name ' AS t1'

' JOIN scarr AS t2 ON t1carrid = t2carrid'

INTO from_clause.

SELECT t1connid t2carrname AS name

FROM (from_clause)

INTO CORRESPONDING FIELDS OF wa.

WRITE: / wa-name, wa-connid.

ENDSELECT

Hope this helps

Gabriel

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question