‎2007 May 22 10:42 AM
Hello,
Can any one tell me how to create internal table dynamically same as standard table..like db name keeps on changing so i want to create internal table as standard table dyanmically
‎2007 May 22 10:45 AM
Hi
Dynamic internal table is internal table that we create on the fly with flexible column numbers.
For sample code, please look at this code tutorial. Hopefully it can help you
Check this link:
http://www.saptechnical.com/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm
Reward points if useful
Regards
Anji
‎2007 May 22 10:48 AM
Hi anand,
1.
For this purpose,
in my program,
there is an <b>INDEPENDENT FORM</b>
whose inputs are
<b>TABLE NAME / STRUCTURE NAME</b>
and from those, it consructs dynamic table.
2. Here is the program.
the dynamic table name will be
<DYNTABLE>.
3. U can use this program (FORM in this program)
to generate any kind of internal table
by specifying TABLE NAME .
4.
REPORT abc.
*----
COMPULSORY
FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.
FIELD-SYMBOLS: <dynline> TYPE ANY.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
FIELD-SYMBOLS: <fld> TYPE ANY.
DATA : fldname(50) TYPE c.
*----
parameters : iname LIKE dd02l-tabname.
*----
START-OF-SELECTION.
*----
PERFORM
PERFORM mydyntable USING lt.
BREAK-POINT.
*----
INDEPENDENT FORM
*----
FORM mydyntable USING ptabname.
*----
Create Dyn Table From FC
FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
FIELD-SYMBOLS: <fs_1>.
FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.
DATA: lt_data TYPE REF TO data.
data : lt TYPE lvc_t_fcat .
DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.
*----
CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
EXPORTING
tabname = iname
TABLES
ddfields = ddfields.
.
*----
CONSTRUCT FIELD LIST
LOOP AT ddfields.
ls-fieldname = ddfields-fieldname.
APPEND ls TO lt.
ENDLOOP.
ASSIGN lt_data TO <fs_data>.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
*----
Assign Dyn Table To Field Sumbol
ASSIGN <fs_data>->* TO <fs_1>.
ASSIGN <fs_1> TO <fs_2>.
ASSIGN <fs_1> TO <dyntable>.
ENDFORM. "MYDYNTABLE
regards,
amit m.