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

How to create Dynamic Internal table

Former Member
0 Likes
482

Hi Friends,

My requirement is i have one internal table having 50 fields example like this DATA: BEGIN OF wa_data,

field1(50) TYPE c, field2(50) TYPE c, field3(50) TYPE c,

field4(50) TYPE c, field5(50) TYPE c, field6(50) TYPE c,

field7(50) TYPE c, field8(50) TYPE c, field9(50) TYPE c,

field10(50) TYPE c, field11(50) TYPE c, field12(50) TYPE c,

field13(50) TYPE c, field14(50) TYPE c, field15(50) TYPE c,

field16(50) TYPE c, field17(50) TYPE c, field18(50) TYPE c,

field19(50) TYPE c, field20(50) TYPE c, field21(50) TYPE c,

field22(50) TYPE c, field23(50) TYPE c, field24(50) TYPE c,

field25(50) TYPE c, field26(50) TYPE c, field27(50) TYPE c,

field28(50) TYPE c, field29(50) TYPE c, field30(50) TYPE c,

field31(50) TYPE c, field32(50) TYPE c, field33(50) TYPE c,

field34(50) TYPE c, field35(50) TYPE c, field36(50) TYPE c,

field37(50) TYPE c, field38(50) TYPE c, field39(50) TYPE c,

field40(50) TYPE c, field41(50) TYPE c, field42(50) TYPE c,

field43(50) TYPE c, field44(50) TYPE c, field45(50) TYPE c,

field46(50) TYPE c, field47(50) TYPE c, field48(50) TYPE c,

field49(50) TYPE c, field50(50) TYPE c,

END OF wa_data,

instead of this i have to create dynamic internal tbale.Please answer this query.

Regards,

srini

3 REPLIES 3
Read only

andreas_mann3
Active Contributor
0 Likes
416

Hi,

1) Try this log:

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

2) For temporary program generation, you can use

GENERATE SUBROUTINE POOL <itab> NAME <prog> [<options>].

Andreas

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
416

Hi,

Check this link.

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

Kindly reward points by clicking the star on the left of reply,if it is useful.

Here is the sample code.

type-pools: slis.

field-symbols: <dyn_table> type standard table,

data: alv_fldcat type slis_t_fieldcat_alv,

it_fldcat type lvc_t_fcat.

<dyn_wa>.

selection-screen begin of block b1 with frame title text-001.

parameters: p_check type c.

selection-screen end of block b1.

start-of-selection.

perform build_dyn_itab.

perform build_report.

loop at <dyn_table> into <dyn_wa>.

write:/ <dyn_wa>.

endloop.

Build_dyn_itab************************************************************************

form build_dyn_itab.

data: index(3) type c.

data: new_table type ref to data,

new_line type ref to data,

wa_it_fldcat type lvc_s_fcat.

clear wa_it_fldcat.

wa_it_fldcat-fieldname = 'AUFNR'.

wa_it_fldcat-datatype = 'CHAR'.

wa_it_fldcat-intlen = 12.

append wa_it_fldcat to it_fldcat .

clear wa_it_fldcat.

wa_it_fldcat-fieldname = 'POSNR'.

wa_it_fldcat-datatype = 'CHAR'.

wa_it_fldcat-intlen = 6.

append wa_it_fldcat to it_fldcat .

  • Create fields

clear index.

do 2 times.

index = sy-index.

clear wa_it_fldcat.

concatenate 'Field' index into

wa_it_fldcat-fieldname .

condense wa_it_fldcat-fieldname no-gaps.

wa_it_fldcat-datatype = 'CHAR'.

wa_it_fldcat-intlen = 5.

append wa_it_fldcat to it_fldcat .

enddo.

  • 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>.

endform.

Form build_report*********************************************************************

form build_report.

data: fieldname(20) type c.

data: fieldvalue(5) type c.

data: index(3) type c.

field-symbols: <fs1>.

assign component 'AUFNR' of structure <dyn_wa> to <fs1>.

<fs1> = '123456789'.

assign component 'POSNR' of structure <dyn_wa> to <fs1>.

<fs1> = '000001'.

do 2 times.

index = sy-index.

  • Set up fieldname

concatenate 'FIELD' index into fieldname .

condense fieldname no-gaps.

  • Set up fieldvalue

concatenate 'FLD' index into fieldvalue.

condense fieldvalue no-gaps.

assign component fieldname of structure <dyn_wa> to <fs1>.

<fs1> = fieldvalue.

enddo.

  • Append to the dynamic internal table

append <dyn_wa> to <dyn_table>.

endform.

Read only

Former Member
0 Likes
416

hi,

Mebbe this is the coding u require.... this creates a dynamic internal table

type-pools : abap.

data: wa_vbak type vbak .(for u its ur structure)

data : it_details type abap_compdescr_tab,

wa_comp type abap_compdescr.

data : ref_descr type ref to cl_abap_structdescr.

ref_descr ?= cl_abap_typedescr=>describe_by_data( wa_vbak ).

it_details[] = ref_descr->components[].

Lemme knwo u solved it by giving points.

With regards,

praveen.