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

Former Member
0 Likes
617

Hi Guys,

I have a requirement where in I need to create an internal table after user inputting.

I have a parameter where the user enters the Table Name.I need to create dynamic internal table for the table entered by the user.How can I do it??

Please let me the possible shortest code.

regards

Jags

6 REPLIES 6
Read only

Former Member
0 Likes
591

hi

chk this link

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

it has sample sode to create dynamic internal table.

PLZ reward if helpful.

Read only

0 Likes
591

refer my demo code,just copy and paste it -

REPORT ZGILL_FS line-size 250

line-count 65 .

************Creating Dynamic internal table************

parameter p_table type tabname.

field-symbols <tab> type table.

field-symbols <tab1> type any.

types: begin of itab,

t_name type tabname,

t_ref type ref to data,

end of itab.

data itab1 type table of itab with non-unique key t_name.

perform fetch_data using p_table.

perform print_table using p_table.

&----


*& Form fetch_data

&----


  • text

----


  • -->P_P_TABLE text

----


FORM fetch_data USING P_TABLE1 type tabname.

data itab2 type itab.

itab2-t_name = p_table1.

create data itab2-t_ref type table of (itab2-t_name) .

assign itab2-t_ref->* to <tab>.

append itab2 to itab1.

select * from (p_table1) up to 25 rows into corresponding fields of table <tab>.

ENDFORM. " fetch_data

&----


*& Form print_table

&----


  • text

----


  • -->P_P_TABLE text

----


FORM print_table USING P_TABLE1 type tabname.

DATA t_ref1 TYPE REF TO data.

DATA itab2 TYPE itab.

FIELD-SYMBOLS <field> TYPE ANY.

READ TABLE itab1 INTO itab2 WITH KEY t_name = p_table1.

ASSIGN itab2-t_ref->* TO <tab>.

CREATE DATA t_ref1 LIKE LINE OF <tab>.

ASSIGN t_ref1->* TO <tab1>.

DO.

*READ TABLE <tab> ASSIGNING <tab1> INDEX 1.

READ TABLE <tab> ASSIGNING <tab1> INDEX SY-INDEX.

*WRITE:/ p_table1.

NEW-LINE.

IF sy-subrc <> 0.

EXIT.

ENDIF.

DO.

ASSIGN COMPONENT sy-index OF STRUCTURE <tab1> TO <field>.

IF sy-subrc <> 0.

EXIT.

ENDIF.

WRITE: <field>,' '.

ENDDO.

ENDDO.

ENDFORM. " print_table

Read only

Former Member
0 Likes
591

Hi

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*********

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.

Regards

Shiva

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.

Read only

Former Member
0 Likes
591

Hi,

If the User enter MARA table in the Selection_screen field.

create the Internal table like ....

data: itab like (Selection-screen field) occurs 0 with header line.

other wise.

field-symbols: <fs> type any

assign (selection=-screen filed) to <fs>.

so create internaltable with the type FS

Regards

Sudheer.

Read only

Former Member
0 Likes
591

Check this code:

DATA:

dref TYPE REF TO data,

linetype TYPE REF TO cl_abap_structdescr,

tabletype TYPE REF TO cl_abap_tabledescr.

FIELD-SYMBOLS:

<newtab> TYPE STANDARD TABLE.

PARAMETRS: p_table TYPE ddobjname OBLIGATORY.

START-OF-SELECTION.

linetype ?= cl_abap_typedescr=>describe_by_name( p_table ).

tabletype = cl_abap_tabledescr=>create(

p_line_type = linetype

p_table_kind = cl_abap_tabledescr=>tablekind_std ).

CREATE DATA dref TYPE HANDLE tabletype.

ASSIGN dref->* TO <newtab>.

Read only

0 Likes
591

Hi All!

Thanks for your information. I would be very thankful if you are able to solve this problem too.

Q: I have an itab with one filed(say 'fld1'). I want to create an itab with the values of the fields.

Eg: 'itab-fld1' has 'abc' & 'xyz' like 2 values, then I want to create an internal table(say itab2) with these values as fields. i.e., my 'itab2' should have the field names

'abc' & 'xyz'.

My special thanks to <b>'TOMASZ KOZERSKI'</b>. would you give an immediate reply.

best regards

JagS