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 internal table declaration

Former Member
0 Likes
9,072

Hi ,

I am writing a report to display table contents in report output, all are Z- Tables and small tables. Selection screen input is Table name.

In the program how can i declare a internal table dynamically and also how can i assign the values to internal table in select statement ?

SELECT * FROM (P_TABLE) INTO ?????
          WHERE (OPTIONS).

Thanks,

Fract

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,632

Hello,

Actually this kind of req has been discussed many times in the forum.

You can check this post for details: [|].

BR,

Suhas

5 REPLIES 5
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,633

Hello,

Actually this kind of req has been discussed many times in the forum.

You can check this post for details: [|].

BR,

Suhas

Read only

Former Member
0 Likes
2,632

Hi,

Please check the link.

Read only

Former Member
0 Likes
2,632

Hi,

Try this...

parameters : p_table(10) type c.

data: w_tabname type w_tabname,

w_dref type ref to data,

w_grid type ref to cl_gui_alv_grid.

field-symbols: <t_itab> type any table.

w_tabname = p_table.

create data w_dref type table of (w_tabname).

assign w_dref->* to <t_itab>.

select *

from (w_tabname) up to 20 rows

into table <t_itab>.

(code}

Regards

Arbind

Read only

Former Member
0 Likes
2,632

Please search in SCN

Sample code snippet:

REPORT ZDYNA . 

DATA: d_ref TYPE REF TO data, 
d_ref2 TYPE REF TO data , 
i_alv_cat TYPE TABLE OF lvc_s_fcat, 
ls_alv_cat LIKE LINE OF i_alv_cat. 


TYPES tabname LIKE dcobjdef-name . 
parameter: p_tablen type tabname. 

data: begin of itab occurs 0. 
INCLUDE STRUCTURE dntab. 
data: end of itab. 


FIELD-SYMBOLS : <F_FS> TYPE table, 
<F_FS1> TYPE TABLE, 
<F_FS2> TYPE ANY, 
<F_FS3> TYPE TABLE. 

REFRESH itab. 
CALL FUNCTION 'NAMETAB_GET' 
EXPORTING 
langu = sy-langu 
tabname = p_tablen 
TABLES 
nametab = itab 

EXCEPTIONS 
no_texts_found = 1. 
LOOP AT itab . 
ls_alv_cat-fieldname = itab-fieldname. 
ls_alv_cat-ref_table = p_tablen. 
ls_alv_cat-ref_field = itab-fieldname. 
APPEND ls_alv_cat TO i_alv_cat. 
ENDLOOP. 
* internal table build 
CALL METHOD cl_alv_table_create=>create_dynamic_table 
EXPORTING it_fieldcatalog = i_alv_cat 
IMPORTING ep_table = d_ref . 
ASSIGN d_ref->* TO <F_FS>. 

SELECT * FROM (p_tablen) INTO CORRESPONDING FIELDS OF TABLE <F_FS>. 


LOOP AT <F_FS> ASSIGNING <F_FS2>. 
*your code goes here. 
ENDLOOP.

Manas M.

Edited by: Kumar Manas Mishra on Jan 28, 2010 8:11 AM

Read only

Former Member
0 Likes
2,632

Hi

check this link.

[http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.html]

Regards

Anshul