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_member190178
Participant
0 Likes
1,655

Hi Experts,

I have Table Name on the selection screen. Inside program I would like to create the Internal table based on the users input example if user gives MARA then internally Internal should be declared of MARA type.

How can we achieve this ? Please reply.

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
604

Hello

I advise against using method cl_alv_table_create=>create_dynamic_table. Instead I recommend to use either RTTI or data objects (if available in your SAP release) to create these runtime objects.


DATA: ldo_data   TYPE REF TO data,
          ld_tabnam TYPE tabname.

FIELD-SYMBOLS:
  <lt_itab>    TYPE TABLE.


ld_tabnam = 'MARA'.
CREATE DATA ldo_data TYPE STANDARD TABLE OF ( ld_tabnam ).
ASSIGN ldo_data->* TO <lt_itab>.

SELECT * FROM (ld_tabnam) INTO TABLE <lt_itab>.

Regards

Uwe

4 REPLIES 4
Read only

Former Member
0 Likes
604

Hi,

I hope the below link will help you.

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

Thanks & Regards,

Khushboo.

Read only

Former Member
0 Likes
604

Here are several examples how you can process the dynamic table afterwords.

now you have a line of the internal table

FIELD-SYMBOLS: <fs_dyn_table> LIKE LINE OF dyn_table.

this can be used for any field

FIELD-SYMBOLS: <fs_component> TYPE ANY.

example read

READ TABLE dyn_table ASSIGNING <fs_dyn_table>

INDEX 1.

example loop

LOOP AT dyn_table ASSIGNING <fs_dyn_table>.

place your coding here

ENDLOOP.

once you have a line you can display its elements

DO.

ASSIGN COMPONENT sy-index OF

STRUCTURE <fs_dyn_table> TO <fs_component>.

IF sy-subrc 0. EXIT. ENDIF.

WRITE / <fs_component>.

ENDDO.

if you want to display by name

ASSIGN COMPONENT 'COMPONENT_NAME' OF STRUCTURE <fs_dyn_table>

TO <fs_component>.

IF sy-subrc EQ 0.

WRITE: / 'Specific component ' , <fs_component>.

ENDIF.

Read only

uwe_schieferstein
Active Contributor
0 Likes
605

Hello

I advise against using method cl_alv_table_create=>create_dynamic_table. Instead I recommend to use either RTTI or data objects (if available in your SAP release) to create these runtime objects.


DATA: ldo_data   TYPE REF TO data,
          ld_tabnam TYPE tabname.

FIELD-SYMBOLS:
  <lt_itab>    TYPE TABLE.


ld_tabnam = 'MARA'.
CREATE DATA ldo_data TYPE STANDARD TABLE OF ( ld_tabnam ).
ASSIGN ldo_data->* TO <lt_itab>.

SELECT * FROM (ld_tabnam) INTO TABLE <lt_itab>.

Regards

Uwe

Read only

Former Member
0 Likes
604

Hi Soniya,

There are many threads regarding dynamic internal table, please search SCN before you post a question.

for dynamic internal table refer to the link below:

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

With luck,

Pritam.