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

Dynamic table declaration in select statement

Former Member
0 Likes
758

I want to accept a filename from user and display its contents.

parameters:tabname(15) type c.
data wa type ZGTABLE. *I dont know how to declare a variable of table type which user enters.
select * from (TABNAME) into wa. *Dynamic declaration
write wa.
endselect.

The output is coming,but I have hardcoded 'Data wa type zgtable' ie if user enters table otherthan zgtable it gives undesired ouput.I need to declare wa type as table type which user enters.Hope you understood my question.Thanks in advance.

5 REPLIES 5
Read only

Former Member
0 Likes
672

Hi

take care that table name should be defined as:

data: tabname type dd08v-tabname Value 'MARA.

select * from (tabname) into table itab where x = y.

<b>Reward if usefull</b>

Read only

Former Member
0 Likes
672

Hi

Try this piece of code:

REPORT YDEMO .

PARAMETERS: TBLNAME(50). "DEFAULT 'SPFLI'.

DATA: TOTAL_ROWS TYPE P.

SELECT COUNT(*) FROM (TBLNAME) INTO TOTAL_ROWS.

WRITE: / TBLNAME, TOTAL_ROWS.

Thanks

Vasudha

Read only

Former Member
0 Likes
672

check this blog by Rich Heilman

<a href="/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap:///people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

regards

shiba dutta

Read only

Former Member
0 Likes
672

Hi Gopi,

Use Field symbols then. Or refer below thread

http://www.sap-img.com/ab030.htm

https://wiki.sdn.sap.com/wiki/display/Snippets/DynamicInternalTable

Regards,

Atish

Read only

Former Member
0 Likes
672

Thanks guys for your replies.I tried your ways.

Naresh:Itab is not declared.How do you declare it now?we dont the structure of the table which user is going to input.

Vasudha : Your code displays number of total rows in the given table.

Reminder:If user enters zgtable,zgtable contents should be displayed.If zgtable1 is entered,its conents should be displayed.This is how it should work.

Any more help..Please.