‎2008 Jul 28 1:58 PM
Hi Expart,
How can I declare Internal Table dynamically by using the table name as input parameter in the selection screen.
like...
data i_table type standard table of (p1) . (dynamically taken by the input parameter).
Please Advice.
‎2008 Jul 28 2:00 PM
hi,
Check the link for step by step guidence of creation of internal table dynamicaly.
http://www.sapfans.com/forums/viewtopic.php?p=107594
regards,
anirban
‎2008 Jul 28 2:02 PM
Hi,
Please find the sample program to create dynamic internal table
type-pools : abap.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
selection-screen begin of block b1 with frame.
parameters: p_table(30) type c default 'T001'.
selection-screen end of block b1.
start-of-selection.
perform get_structure.
perform create_dynamic_itab. **********Creates a dyanamic internal table**********
perform get_data.
perform write_out.
form get_structure.
data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
* Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails[] = ref_table_des->components[].
loop at idetails into xdetails.
clear xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
append xfc to ifc.
endloop.
endform.
form create_dynamic_itab.
* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = ifc
importing
ep_table = dy_table.
assign dy_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
create data dy_line like line of <dyn_table>.
assign dy_line->* to <dyn_wa>.
endform.
form get_data.
* Select Data from table.
select * into table <dyn_table>
from (p_table).
endform.
Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index
of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
regards
Saravanan
‎2008 Jul 28 2:06 PM
@ Saravanan
Dont copy paste the code, From some one else post. If it is your post you can copy it. Try to Refer the Link.
‎2008 Jul 28 2:03 PM
‎2008 Jul 28 2:03 PM
Hi,
check out this link it may help you a lot with easy understanding step by step.
http://saptechnical.com/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm
‎2008 Jul 28 2:03 PM
Hi Avik,
Check these links for examples of dynamic creation of internal table:
http://www.sap-img.com/ab030.htm
http://sample-code-abap.blogspot.com/2008/07/sap-abap-dynamic-internal-table-and.html
Hope this helps you.
Regards,
Chandra Sekhar
‎2008 Jul 28 2:05 PM
One such example.
REPORT zdynamic.
FIELD-SYMBOLS: <l_table> TYPE table,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
DATA: is_lvc_cat TYPE lvc_s_fcat,
it_lvc_cat TYPE lvc_t_fcat.
DATA: new_table TYPE REF TO data,
new_line TYPE REF TO data.
START-OF-SELECTION.
is_lvc_cat-fieldname = 'KUNNR'.
APPEND is_lvc_cat TO it_lvc_cat.
is_lvc_cat-fieldname = 'NAME1'.
APPEND is_lvc_cat TO it_lvc_cat.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_lvc_cat
IMPORTING
ep_table = new_table.
*Create a new Line with the same structure of the table.
ASSIGN new_table->* TO <l_table>.
CREATE DATA new_line LIKE LINE OF <l_table>.
ASSIGN new_line->* TO <l_line>.
DO 2 TIMES.
ASSIGN COMPONENT 'KUNNR' OF STRUCTURE <l_line> TO <l_field>.
<l_field> = sy-index.
ASSIGN COMPONENT 'NAME1' OF STRUCTURE <l_line> TO <l_field>.
<l_field> = 'A'.
INSERT <l_line> INTO TABLE <l_table>.
ENDDO.
LOOP AT <l_table> INTO <l_line>.
WRITE:/ <l_line>.
ENDLOOP.
READ TABLE <l_table> INTO <l_line> INDEX 2.
<l_line>+10(2) = 'B'.
MODIFY <l_table> FROM <l_line> INDEX 2.
LOOP AT <l_table> INTO <l_line>.
WRITE:/ <l_line>.
ENDLOOP.Regards
Vijay Babu Dudla
‎2008 Jul 28 2:05 PM
‎2008 Jul 28 2:11 PM
Hi Avik.
I would like to suggest a few references,
[SDN Weblog - Standard Reference for Dynamic Internal Tables and Structures by Rich Heilman - ABAP|https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2071] [original link is broken] [original link is broken] [original link is broken];
[SDN - Reference for Creating Dynamic Internal Tables|/thread/418716 [original link is broken];
[SDN Wiki - Code Snippets - Standard Reference for Dynamic Internal Table|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/dynamic%2binternal%2btable]
Hope that's usefull.
Good Luck & Regards.
Harsh Dave