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

Define internal table where structure is defined at runtime

Former Member
0 Likes
1,304

Hi,

I want to define an internal table where the structure (which is a table name) in after syntax "INCLUDE STRUCTURE" is defined at runtime. How do I do this, I get the syntax error "The included type has no structure":

I want to do:

DATA: BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE i_table_name.

DATA: END OF itab.

where i_table_name is a imported string which refers to the database table in question.

regards

Baran

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
692

Hi Baran,

Just click on the below link.

Here you can see the complete details of HOW TO CREATE DYANMIC INTERNAL TABLE( Defining structure at runtime ). It is Crystal Clear.

" http://www.saptechnical.com/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm "

<b>Hope you can understand it easily.

Reward if helpful.</b>

Regards,

V.Raghavender.

3 REPLIES 3
Read only

Former Member
0 Likes
692

Hi baran,

1. Just give the Table name on selection screen, and it will consruct dynamic internal table.

2. just copy paste.

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 : tabname LIKE dd02l-tabname DEFAULT 'T001' OBLIGATORY.

*----


START-OF-SELECTION.

*----


PERFORM

PERFORM mydyntable USING lt.

PERFORM GET_DATA.

PERFORM SHOW_DATA.

BREAK-POINT.

*----


  • FORM

*----


FORM GET_DATA.

SELECT * FROM (TABNAME)

INTO TABLE <DYNTABLE>.

ENDFORM. "GET_DATA

*----


  • FORM

*----


FORM SHOW_DATA.

loop at <dyntable> ASSIGNING <dynline>.

sy-subrc = 0.

write 😕 .

WHILE SY-SUBRC = 0.

ASSIGN COMPONENT SY-INDEX OF STRUCTURE <DYNLINE> TO <FLD>.

WRITE : <FLD>.

ENDWHILE.

endloop.

ENDFORM. "SHOW_DATA

*----


  • 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 = tabname

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.

Read only

Former Member
0 Likes
692

You can use

field-symbols: <dyn_table> type standard table,

and than

  • Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = it_fldcat

importing

ep_table = new_table.

assign new_table->* to <dyn_table>.

  • Create dynamic work area and assign to FS

create data new_line like line of <dyn_table>.

assign new_line->* to <dyn_wa>.

Hope this answers your question.

Assign reward points if it helps.

-Gaurang

Read only

Former Member
0 Likes
693

Hi Baran,

Just click on the below link.

Here you can see the complete details of HOW TO CREATE DYANMIC INTERNAL TABLE( Defining structure at runtime ). It is Crystal Clear.

" http://www.saptechnical.com/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm "

<b>Hope you can understand it easily.

Reward if helpful.</b>

Regards,

V.Raghavender.