11-02-2009 6:13 PM
I am using the following code for creating dynamic internal table.....
DATA: t_details TYPE abap_compdescr_tab,
wa_details TYPE abap_compdescr,
t_ref_tab TYPE REF TO cl_abap_structdescr.
* Get the structure of the table.
t_ref_tab ?= cl_abap_typedescr=>describe_by_name( pv_tabname ).
t_details[] = t_ref_tab->components[].
LOOP AT t_details INTO wa_details.
CLEAR wa_fc.
wa_fc-fieldname = wa_details-name .
wa_fc-datatype = wa_details-type_kind.
wa_fc-inttype = wa_details-type_kind.
wa_fc-intlen = wa_details-length.
wa_fc-decimals = wa_details-decimals.
APPEND wa_fc TO it_fc.
ENDLOOP.
* Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fc
IMPORTING
ep_table = it_dynamic.
ASSIGN it_dynamic->* TO <fs_dyn>.
* Create dynamic work area and assign to FS
CREATE DATA wa_dynamic LIKE LINE OF <fs_dyn>.
ASSIGN wa_dynamic->* TO <fs_line>.
* Filling data into dynamic internal table.
SELECT * FROM (gv_tabname) INTO TABLE <fs_dyn>.
LOOP AT <fs_dyn> assigning <fs_line>.
MOVE-CORRESPONDING <fs_line> TO wa_chandisc. " --> Causing error
APPEND wa_chandisc TO gt_chandisc.
ENDLOOP.
Need some help in fixing this issue.
11-02-2009 6:22 PM
Hello Karthik,
LOOP AT <fs_dyn> assigning <fs_line>.
MOVE-CORRESPONDING <fs_line> TO wa_chandisc. " --> Causing error
APPEND wa_chandisc TO gt_chandisc.
ENDLOOP.
This is bound to give an error b'coz <fs_line> is generic & until runtime the type of <fs_line> is not determined. So MOVE-CORRESPONDING will give an error.
BR,
Suhas
11-02-2009 6:23 PM
11-02-2009 6:28 PM
>
> How can i solve this issue... can you give my any direction.
Yes, a small trick
But I want to know if you have the structures wa_chandisc & table gt_chandisc defined. And you know which field of wa_chandisc will be mapped to which field of <fs_line>.
BR,
Suhas
11-02-2009 6:37 PM
Yes, they are declared...the mapping depends on structure of <fs_line>.
Edited by: Karthik on Nov 2, 2009 1:38 PM
11-02-2009 6:32 PM
Hi!
1. Get strucutre of wa_chandisc into internal table.
2. Loop at itab.
3. You need use constraction ASSIGN COMPONENT itab-compname OF <fs_line> INTO <fsymbol1>.
Than iterativly ASSIGN COMPONENT itab-compname OF wa_chandisc INTO <fsymbol2>.
4. <fsymbol2> = <fsymbol1>.
Good luck.