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
895

i have got an dynamic internal table generated and i need to pass these values..since it's dynamic the no of values can b any thing from 1 to n..i need to pass these values one by one to some fm and retrieve the value n move it in the dynamic table again in the same order!!

how to achieve the same

regards

gunjna

1 ACCEPTED SOLUTION
Read only

amit_khare
Active Contributor
0 Likes
856

Hi,

to create the table dynamically you may use following method -

<b>CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = I_FIELDCAT

IMPORTING

EP_TABLE = I_PTABLE.

ASSIGN I_PTABLE->* TO <I_TABLE>.</b>

Regards,

Amit

7 REPLIES 7
Read only

Former Member
0 Likes
856

hi,

this kind of dynamism can be achieved by using field symbols appraoch. Please check if you can use it.

Rgds,

HR

Read only

amit_khare
Active Contributor
0 Likes
857

Hi,

to create the table dynamically you may use following method -

<b>CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = I_FIELDCAT

IMPORTING

EP_TABLE = I_PTABLE.

ASSIGN I_PTABLE->* TO <I_TABLE>.</b>

Regards,

Amit

Read only

Former Member
0 Likes
856

HI,

Check this sample code.

REPORT zmaschl_create_data_dynamic .

TYPE-POOLS: slis.

DATA: it_fcat TYPE slis_t_fieldcat_alv,

is_fcat LIKE LINE OF it_fcat.

DATA: it_fieldcat TYPE lvc_t_fcat,

is_fieldcat LIKE LINE OF it_fieldcat.

DATA: new_table TYPE REF TO data.

DATA: new_line TYPE REF TO data.

FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,

<l_line> TYPE ANY,

<l_field> TYPE ANY.

  • Build fieldcat

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'SYST'

CHANGING

ct_fieldcat = it_fcat[].

LOOP AT it_fcat INTO is_fcat WHERE NOT reptext_ddic IS initial.

MOVE-CORRESPONDING is_fcat TO is_fieldcat.

is_fieldcat-fieldname = is_fcat-fieldname.

is_fieldcat-ref_field = is_fcat-fieldname.

is_fieldcat-ref_table = is_fcat-ref_tabname.

APPEND is_fieldcat TO it_fieldcat.

ENDLOOP.

  • Create a new Table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = new_table.

  • Create a new Line with the same structure of the table.

ASSIGN new_table->* TO <l_table>.

CREATE DATA new_line LIKE LINE OF <l_table>.

ASSIGN new_line->* TO <l_line>.

  • Test it...

DO 30 TIMES.

ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.

<l_field> = sy-index.

INSERT <l_line> INTO TABLE <l_table>.

ENDDO.

LOOP AT <l_table> ASSIGNING <l_line>.

ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.

WRITE <l_field>.

ENDLOOP.

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

Do reward if it helps,

Regards,

Laxmi.

Read only

Former Member
0 Likes
856

Hi I have recently done something similar, This is similar to what you need. Obviously with a couple of changes.

DO 10 TIMES.

READ TABLE <t1> ASSIGNING <line_table1> INDEX loop_count.

LOOP AT fields INTO field.

fieldname = field-fieldname.

ASSIGN COMPONENT fieldname OF STRUCTURE

<line_table1> TO <field_table1>.

ENDLOOP.

ENDDO.

Read only

0 Likes
856

after gettin the fieldname shall i pass it to FM and then return parameter to be used to create using ur statement

ASSIGN COMPONENT fieldname OF STRUCTURE

<line_table1> TO <field_table1>.

can both the dynamic internal table be same?the one we use in the starting n after passing it fm ..the return value's internal table..do i need to create catalogue in the starting?

regards

gunjan

Read only

Former Member
0 Likes
856

Hi Gunjan,

I hope u r asking about how to populate the data into the dynamically created internal table ,Please try the following method

Keep ur final data into one internal table..

After creating the dynamic internal table

create a temporary internal table using the field symbols

field-symbols: <fs> type any

<fs_line> type any.

Say ur dynamic internal table is <itab> and the data is present in internal table t_final .

assign local copy of <itab> to <fs_table>.

v_lines = 1.

loop at t_final.

at new (keyfield).

assgin v_lines of structure <fs_table> to <fs_line>.

<fs_line> = t_final-field1.

v_lines = v_lines + 1.

assgin v_lines of structure <fs_table> to <fs_line>.

<fs_line> = t_final-field1.

v_lines = v_lines + 1.

endat.

assgin v_lines of structure <fs_table> to <fs_line>.

<fs_line> = t_final-field1.

v_lines = v_lines + 1.

assgin v_lines of structure <fs_table> to <fs_line>.

<fs_line> = t_final-field1.

v_lines = v_lines + 1.

at end of (keyfield)

append <fs_table> to <itab>.

endat.

endloop.

Try using the above method(syntaxes used may not be correct)..Hope it will be useful.

Read only

0 Likes
856

hi

i have got five(may vary for each row) dynamic columns(fld1--fld5) in my dynamic internal table ...which has value 1 2 3 4 5...

i have to pass these 5 values one by one to some FM and the export parameter needs to be stored in the same dynamic internal table with diff col (fld6-fld10)..

how shall i go about them?

Regards

Gunjan