03-31-2008 1:47 PM
Hi all,
I want to accept a table name, and declare an internal table which is of type of that accepted table.
03-31-2008 1:49 PM
03-31-2008 1:50 PM
Dont forget it should be a field symbol or it is not possible.
Example field symbols test type any.
Then u can assign it to any thing.
03-31-2008 1:57 PM
field symbol should be assigned to an internal table here, how do i declare that internal table whose type is unknown
03-31-2008 2:02 PM
field symbol should be assigned to an internal table here, how do i declare that internal table whose type can not determined statically? the user will enter the type
03-31-2008 2:11 PM
You can do that using the method of class
cl_alv_table_create method is create_dynamic_table
REPORT Z_TEST_09.
PARAMETERS : p_table(10) TYPE C.
DATA:
i_newtable TYPE REF TO data. " To create dyn.Itab
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.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
i_style_table = 'SPFLI'
IMPORTING
ep_table = i_newtable.
ASSIGN i_newtable->* TO <t_itab>.
SELECT *
FROM (w_tabname) UP TO 20 ROWS
INTO TABLE <t_itab>.
CREATE OBJECT w_grid
EXPORTING i_parent = cl_gui_container=>screen0.
CALL METHOD w_grid->set_table_for_first_display
EXPORTING
i_structure_name = w_tabname
CHANGING
it_outtab = <t_itab>.
03-31-2008 2:37 PM
03-31-2008 1:49 PM
HI
Use field symbols
field-symbols: <fs1>
you can assign any type to field symbol at run time
Regards
Aditya
03-31-2008 1:55 PM
you can use the below syntax.
field-symbols: <fs> type any.
data: var(9).
var = 'IT_VBAP[]'.
assign (var) to <fs>.
There are many ways to do this. Above is one such.
03-31-2008 2:01 PM
You can also do this...
data: tab type ref to data.
DATA: it_vabp TYPE STANDARD TABLE OF vbap WITH HEADER LINE.
select * from vbap into table it_vabp .
GET REFERENCE OF it_vabp[] INTO tab.
03-31-2008 1:56 PM
Hi
You can use
Field-symbols: <fs_tab> type any table.
This filed symbol then can accept any table dynamically.
you can process this dynamically filled table by statement
Loop at <fs_tab> into <wa_tab>.
loop at <wa_tab> assigning componets of <wa_tab> to <field>
endloop.
endloop.
This way you process any table dynamically.
Reward points if helpful
Regards,
Rahul
03-31-2008 2:05 PM
03-31-2008 2:07 PM
Hi,
Do use the code. I think it will give you some picture.
&----
*& Report ZDYNTEST *
*& *
&----
*& *
*& *
&----
report zdyntest.
type-pools : slis.
tables : marc,t001w.
data : begin of itab occurs 0,
matnr like marc-matnr,
end of itab.
data : fieldstab type lvc_t_fcat,
stab type lvc_s_fcat,
t_fieldcat type slis_t_fieldcat_alv,
s_fieldcat type slis_fieldcat_alv,
new_line type ref to data,
new_table type ref to data,
index(3) type c,
str(70),
text(6),
cnt(1),
text1(16),
repid like sy-repid.
field-symbols : <fs> type standard table,
<wa> type any.
select-options : s_werks for marc-werks no intervals,
s_matnr for marc-matnr no intervals.
initialization.
repid = sy-repid.
start-of-selection.
select * from marc
into corresponding fields of table itab
where matnr in s_matnr
and werks in s_werks.
sort itab by matnr.
delete adjacent duplicates from itab comparing matnr.
stab-fieldname = 'MATNR'.
stab-datatype = 'CHAR'.
stab-intlen = '18'.
append stab to fieldstab.
clear cnt.
loop at s_werks.
clear text.
cnt = cnt + 1.
concatenate 'EISLO' cnt into text.
stab-fieldname = text.
stab-datatype = 'CHAR'.
stab-intlen = '16'.
append stab to fieldstab.
clear s_werks.
endloop.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = fieldstab
importing
ep_table = new_table.
assign new_table->* to <fs>.
create data new_line like line of <fs>.
assign new_line->* to <wa>.
perform move_data.
clear s_fieldcat.
s_fieldcat-fieldname = 'MATNR'.
s_fieldcat-tabname = itab.
s_fieldcat-seltext_m = 'Part Number'.
s_fieldcat-no_zero = 'X'.
s_fieldcat-ddictxt = 'M'.
append s_fieldcat to t_fieldcat.
clear cnt.
loop at s_werks.
clear t001w.
cnt = cnt + 1.
select single * from t001w where werks = s_werks-low and spras = sy-langu.
clear text.
concatenate 'EISLO' cnt into text.
s_fieldcat-fieldname = text.
s_fieldcat-seltext_m = t001w-name2.
S_FIELDCAT-NO_ZERO = 'X'.
s_fieldcat-ddictxt = 'M'.
append s_fieldcat to t_fieldcat.
clear s_werks.
endloop.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = t_fieldcat[]
tables
t_outtab = <fs>.
&----
*& Form MOVE_DATA
&----
text
----
form move_data.
loop at itab.
clear str.
concatenate itab-matnr ' ' into str separated by space.
loop at s_werks.
clear marc.
select single * from marc where matnr = itab-matnr and werks = s_werks-low.
if sy-subrc eq 0.
clear text1.
text1 = marc-eislo.
concatenate str text1 into str separated by space.
else.
concatenate str '0' into str separated by space.
endif.
endloop.
<wa> = str.
append <wa> to <fs>.
clear itab.
endloop.
endform. "MOVE_DATA
Regards,
Sankar.