Application Development 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: 

How to fill internal table dynamically

Former Member
0 Kudos

Hi All,

how to fill internal table dynamically.

for example:

begin of itab occurs 0,

empid like pa0000-pernr,

empname like pa0001-ename,

grade(5),

end of itab.

now i want to append dynamically field itab-grade along with rest fields.

is this possible?? if yes kindly let me know how to do that.

Regards,

Kiran I

1 ACCEPTED SOLUTION

rahulkavuri
Active Contributor
0 Kudos

hi kiran refer this thread

Check this one too

<b>This one is on how to modify int table</b>

Message was edited by: Rahul Kavuri

4 REPLIES 4

rahulkavuri
Active Contributor
0 Kudos

hi kiran refer this thread

Check this one too

<b>This one is on how to modify int table</b>

Message was edited by: Rahul Kavuri

Former Member
0 Kudos

Hi kiran,

To fill and create and internal table dynamically you can use this code.

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.

is_fieldcat-fieldname = 'FIELD1'.

is_fieldcat-ref_field = 'MATNR'.

is_fieldcat-ref_table = 'MARA'.

APPEND is_fieldcat TO it_fieldcat.

is_fieldcat-fieldname = 'FIELD2'.

is_fieldcat-ref_field = 'SPRPS'.

is_fieldcat-ref_table = 'PA0001'.

APPEND is_fieldcat TO it_fieldcat.

is_fieldcat-fieldname = 'FIELD3'.

is_fieldcat-ref_field = 'BEGDA'.

is_fieldcat-ref_table = 'PA0002'.

APPEND is_fieldcat TO it_fieldcat.

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

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

<l_field> = '12345'.

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

<l_field> = 'X'.

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

<l_field> = '20030101'.

INSERT <l_line> INTO TABLE <l_table>.

ENDDO.

LOOP AT <l_table> ASSIGNING <l_line>.

  • ASSIGN COMPONENT 'field1' OF STRUCTURE <l_line> TO <l_field>.

WRITE / <l_line>.

ENDLOOP.

regards,

Aashish Garg

Former Member
0 Kudos

Hii

data index type i.

loop at it_ztable into wl_ztable.

index = sy-tabix + 9.

read line index field value wl_ztable-ch into w_ch.

modify it_ztable from wl_ztable.

endloop.

instead of sy-tabix u can also sy-index .

also look inot this link..this will answer your question.

<b>

regards

Naresh

Former Member
0 Kudos

hi kiran,

check this thread

HOPE THIS HELPS,

PRIYA.