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

Dynamically create columns in internal table and populate it

Former Member
0 Likes
729

Hi fellow abapers

I need to create an internal table (dynamically) as following

begin of itab,

material

material description

operation1

machine1

operation2

machine2

..

..

operation<n>

machine<n>

end of itab.

in this,no. of occurancesof the fields - OPERATION & MACHINE will vary depending on the material (some may have 5 , some have 10 ).

how to create the internal table, populate the values in it and display in alv.

plz help, its urgent.

rewards sure.

Regards

Prabumanoharan

1 ACCEPTED SOLUTION
Read only

former_member491305
Active Contributor
0 Likes
641

Hi Prabhu,

Here it is..

step1.Build an field catelog which should consist of all the fields which u want in internal table.

step2.Call the method

step3.Create work area..

Sample Code:

data: t_fieldcat TYPE lvc_t_fcat,

wa_fieldcat TYPE lvc_s_fcat.

wa_fieldcat-tabname = 'EKKO'.

wa_fieldcat-fieldname = 'EBELN'.

wa_fieldcat-datatype = 'CHAR'.

wa_fieldcat-intlen = '10'.

APPEND wa_fieldcat TO t_fieldcat.

CLEAR : wa_fieldcat.

wa_fieldcat-tabname = 'EKPO'.

wa_fieldcat-fieldname = 'MATNR'.

wa_fieldcat-datatype = 'CHAR'.

wa_fieldcat-intlen = '18'.

APPEND wa_fieldcat TO t_fieldcat.

CLEAR : wa_fieldcat.

*-----Building Dynamic internal table.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = t_fieldcat

IMPORTING

ep_table = dy_table.

ASSIGN dy_table->* TO <t_paymord>.

*-----Creating work area for dynamic internal table

CREATE DATA: dy_line LIKE LINE OF <t_paymord>.

ASSIGN: dy_line->* TO <w_paymord> .

LOOP AT <t_paymord> INTO <w_paymord>.

Endloop.

Regards,

Vigneswaran S

Hi fellow abapers

I need to create an internal table (dynamically) as following

begin of itab,

material

material description

operation1

machine1

operation2

machine2

..

..

operation<n>

machine<n>

end of itab.

in this,no. of occurancesof the fields - OPERATION & MACHINE will vary depending on the material (some may have 5 , some have 10 ).

how to create the internal table, populate the values in it and display in alv.

plz help, its urgent.

rewards sure.

Regards

Prabumanoharan

3 REPLIES 3
Read only

Former Member
0 Likes
641

hi,

chk the sample code here:

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/dynamic%2binternal%2btable

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

Read only

former_member491305
Active Contributor
0 Likes
642

Hi Prabhu,

Here it is..

step1.Build an field catelog which should consist of all the fields which u want in internal table.

step2.Call the method

step3.Create work area..

Sample Code:

data: t_fieldcat TYPE lvc_t_fcat,

wa_fieldcat TYPE lvc_s_fcat.

wa_fieldcat-tabname = 'EKKO'.

wa_fieldcat-fieldname = 'EBELN'.

wa_fieldcat-datatype = 'CHAR'.

wa_fieldcat-intlen = '10'.

APPEND wa_fieldcat TO t_fieldcat.

CLEAR : wa_fieldcat.

wa_fieldcat-tabname = 'EKPO'.

wa_fieldcat-fieldname = 'MATNR'.

wa_fieldcat-datatype = 'CHAR'.

wa_fieldcat-intlen = '18'.

APPEND wa_fieldcat TO t_fieldcat.

CLEAR : wa_fieldcat.

*-----Building Dynamic internal table.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = t_fieldcat

IMPORTING

ep_table = dy_table.

ASSIGN dy_table->* TO <t_paymord>.

*-----Creating work area for dynamic internal table

CREATE DATA: dy_line LIKE LINE OF <t_paymord>.

ASSIGN: dy_line->* TO <w_paymord> .

LOOP AT <t_paymord> INTO <w_paymord>.

Endloop.

Regards,

Vigneswaran S

Read only

Former Member
0 Likes
641

closing the thread