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

runtime tablename selection

Former Member
0 Likes
1,084

Hi experts,

On selection-screeen i defined one field. In this field i am giving table name.

Requirement: i want to use this name in select query.

e.g.

paramenter : p_tab like tabname.

select * from (p_tab).

is this possible????

if not how can i do it??

any sample code??

Thanks in advance.

Saurabh

10 REPLIES 10
Read only

Former Member
0 Likes
1,068

Hi,

it is possible.


data:var like mara-matnr.
parameters:table(30) default 'MARA'.
select single matnr from (table) into var.
write:/ var.

NOTE:be careful that the field u r giving in selection query should exist in the table name otherwise it will give u dump.

rgds,

bharat.

Read only

Former Member
0 Likes
1,068

Hi,

Yes this will work..

SELECT *

INTO wa

FROM (name) CLIENT SPECIFIED

WHERE mandt = '000'.

Read only

0 Likes
1,068

is this possible without work area??

because i want to copy data from table to table.

and there are records around 10,000,000.

i am using insert statement.

means select * from (name)

insert into (name1) values (name).

endselect.

Read only

0 Likes
1,068

Not necessary to use work area. You can get all the records into an internal table.

parameters: p_tname type tabname.

select * from p_tname into table itab.

Read only

0 Likes
1,068

hi,

it is giving dump if i use the internal table.

the dump is :With an Open SQL select, the output area is too small.

so any other solution????

Read only

Former Member
0 Likes
1,068

hi Saurabh,

i encountered the same problem few days back. I guess you can't do that. rather in case you declare that field as select-options then you can loop/read at that internal table.

Reward if it really helps.

Thanks,

VV

Read only

Former Member
0 Likes
1,068

Hi,

paramenter : p_tab like DD02L-tabname.

start-of-selection.

select * from DD02L where tabname = p_tab.

Regards

Read only

Former Member
0 Likes
1,068

Hi,

You have to declare a dynamic internal table as follows:

data: lv_table_name TYPE dd03l-tabname,

lt_dyn_table TYPE REF TO data.

FIELD-SYMBOLS: <fs_dyn_table> TYPE STANDARD TABLE,

<fs_dyn_wa>.

CREATE DATA lt_dyn_table TYPE STANDARD TABLE OF (lv_table_name).

ASSIGN lt_dyn_table->* TO <fs_dyn_table>.

  • Create dynamic work area and assign to FS

CREATE DATA lv_dy_line LIKE LINE OF <fs_dyn_table>.

ASSIGN lv_dy_line->* TO <fs_dyn_wa>.

lv_table_name = p_tab.

SELECT * FROM (lv_table_name)

INTO TABLE <fs_dyn_table>

WHERE <conditions>.

*&--- If any extra logic needed...

LOOP AT <fs_dyn_table> ASSIGNING <fs_dyn_wa>.

Endloop.

Read only

Former Member
0 Likes
1,068

Hi saurabh,

you can do it using dynamic table creation...

even i have never tried this before...but today i tried for you and i got it

Reward Point if useful...

if any doubts you can mail me to sturd2cum@gmail.com...

with subject : SAP Community Forum...

copy / paste the code written below...and run..

&----


*& Report ZSS_TEST_TP *

*& *

&----


*& *

*& *

&----


REPORT zss_test_tp.

PARAMETERS: p_tab TYPE tabname.

DATA : it_dd03l TYPE TABLE OF dd03l,

wa_dd03l TYPE dd03l.

DATA : wa_fieldcat TYPE lvc_s_fcat,

it_fldcat TYPE lvc_t_fcat.

DATA : it_tab TYPE REF TO data,

wa_line TYPE REF TO data.

----


  • FIELD-SYMBOLS *

----


FIELD-SYMBOLS: <fs_table> TYPE table,

<fs_any> TYPE ANY,

<fs_wa> TYPE ANY.

SELECT * FROM dd03l

INTO TABLE it_dd03l

WHERE tabname = p_tab

AND comptype = 'E'.

IF sy-subrc = 0.

ENDIF.

LOOP AT it_dd03l INTO wa_dd03l.

wa_fieldcat-fieldname = wa_dd03l-fieldname.

wa_fieldcat-tabname = wa_dd03l-tabname.

wa_fieldcat-domname = wa_dd03l-domname.

wa_fieldcat-datatype = wa_dd03l-datatype.

wa_fieldcat-outputlen = wa_dd03l-leng.

APPEND wa_fieldcat TO it_fldcat.

ENDLOOP.

  • Create Dynamic INTERNAL TABLE IT_TAB

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fldcat

IMPORTING

ep_table = it_tab.

  • * Assign the pointer <fs_table> to the dynamically created internal table 'IT_TAB'

ASSIGN it_tab->* TO <fs_table> .

CREATE DATA wa_line LIKE LINE OF <fs_table>.

ASSIGN wa_line->* TO <fs_wa>.

  • Select data from dynamic table...here im selecting all entries from table

SELECT * FROM (p_tab)

INTO CORRESPONDING FIELDS OF TABLE <fs_table>.

IF sy-subrc = 0.

ENDIF.

Read only

Former Member
0 Likes
1,068

hi

it is possible in sap

write the stmt like this.

parameter:

tablname(30) type c.

select *

from (tablname)

into workarea

endselect.

if u have any doubt check the saphelp