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 table

Former Member
0 Likes
765

Hello everybody,

I had created a dynamic internal table for alv, where i need dynamic number of colums.

  • Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = ifc

IMPORTING

ep_table = dy_table.

assign dy_table->* to <dyn_table>.

  • Create dynamic work area and assign to FS

create data dy_line like line of <dyn_table>.

assign dy_line->* to <dyn_wa>.

now i need to populate <dyn_table>.

how can i populate <dyn_table>.

even i am unable to populate work area <dyn_wa>.

how can i access fields of work area, and append records to internal table with work area..

Thanks In advance

Regards

Ravi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
683

FIELD-SYMBOLS: <gf_field> TYPE ANY.

ASSIGN COMPONENT 'VSTTXT' OF STRUCTURE <gf_line> TO <gf_field>.

<gf_field> = gw_workarea-vsttxt.

INSERT <gf_line> INTO TABLE <gf_table>.

You can populate using this logic. VSTTXT is field name in workarea

5 REPLIES 5
Read only

uwe_schieferstein
Active Contributor
0 Likes
683

Hello Ravi

You can use the fieldcatalog to populate the dynamic structure. Afterwards you append the record to your dynamic itab.


  FIELD-SYMBOLS:
    <ld_fld>    TYPE any.

  LOOP AT lt_fcat INTO ls_fcat.
    ASSIGN COMPONENT ls_fcat-fieldname OF STRUCTURE <dyn_wa> TO <ld_fld>.

   <ld_fld> = ... .   " assign values to the components
  ENDLOOP.
  APPEND <dyn_wa> TO <dyn_table>.

Regards

Uwe

Read only

Former Member
0 Likes
684

FIELD-SYMBOLS: <gf_field> TYPE ANY.

ASSIGN COMPONENT 'VSTTXT' OF STRUCTURE <gf_line> TO <gf_field>.

<gf_field> = gw_workarea-vsttxt.

INSERT <gf_line> INTO TABLE <gf_table>.

You can populate using this logic. VSTTXT is field name in workarea

Read only

Former Member
0 Likes
683

Hi Ravi.

Just try this,

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = tb_fields_for_it

IMPORTING

ep_table = gp_dyn_table.

ASSIGN gp_dyn_table->* TO <gt_table>.

ASSIGN LOCAL COPY OF INITIAL LINE OF <gt_table> TO <fs_table>.

LOOP AT tb_output.

*To assign value for serial number.

ASSIGN COMPONENT 1 OF STRUCTURE <fs_table> TO <ls_field>.

<ls_field> = tb_output-sno.

UNASSIGN <ls_field>.

*To assign value for Sales Organization.

ASSIGN COMPONENT 2 OF STRUCTURE <fs_table> TO <ls_field>.

<ls_field> = tb_output-vkorg.

UNASSIGN <ls_field>.

*To assign Rate for its respective Condition type.

LOOP AT tb_konp WHERE knumh = tb_output-knumh.

READ TABLE tb_fieldcat1 WITH KEY fieldname = tb_output-kschl.

IF sy-subrc EQ 0.

lv_count = tb_fieldcat1-col_pos.

ASSIGN COMPONENT lv_count OF STRUCTURE <fs_table> TO <ls_field>.

IF tb_konp-konwa EQ '%'.

tb_konp-kbetr = tb_konp-kbetr / co_10.

<ls_field> = tb_konp-kbetr.

ELSE.

<ls_field> = tb_konp-kbetr.

ENDIF.

ENDIF.

ENDLOOP.

lv_count = lv_count + 1.

APPEND <fs_table> TO <gt_table>.

CLEAR <fs_table>.

ENDLOOP.

Hope this proves helpful to you.

Read only

Former Member
0 Likes
683

Hi,

Directly you can fetch the data into internal table usin Select Statement like Below..if you know the field names.

select field1 field2 field3.....etc

from (p_table)

into table <fs_dyntab>

up to p_max rows.

Here ....Table name is also dynamic. If that is not dynamic you can give the name of table.

if fieldnames are also dynamic... that means if you are giving fieldnames on the selection screen, then you need to do like below.

Code:

data : v_selfields type string.

concatenate p_fnam1 p_fnam2 p_fnam3 p_fnam4 p_fnam5 p_fnam6 p_fnam7 p_fnam8 p_fnam9 p_fnam10

into v_selfields

separated by space.

*Dynamic Select

if wa_where-where_tab is initial.

select (v_selfields)

from (p_table)

into table <fs_dyntab>

up to p_max rows.

Regards

Sandeep Reddy

Read only

Former Member
0 Likes
683

This message was moderated.