‎2009 Jan 05 12:22 PM
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
‎2009 Jan 05 12:53 PM
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
‎2009 Jan 05 12:42 PM
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
‎2009 Jan 05 12:53 PM
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
‎2009 Jan 05 12:55 PM
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.
‎2009 Jan 05 1:07 PM
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
‎2015 Dec 16 1:06 PM