‎2008 Mar 27 1:07 PM
Hello.
Last time someone helped me to read data out of a dynamic table as follows:
The field symbol <it> gets first gets the structure of the table. After that it also gets the contents.
Field <temp> contains one line of data from the table.
Field <wa> contains one specific field from the data.
FIELD-SYMBOLS: <it> TYPE STANDARD TABLE,
<temp>,
<wa> TYPE ANY.
DATA: infty_tab_pointer TYPE REF TO data.
CREATE DATA infty_tab_pointer TYPE STANDARD TABLE OF (tabname).
ASSIGN infty_tab_pointer->* TO <it>.
SELECT * FROM (tabname) INTO CORRESPONDING FIELDS OF TABLE <it>
LOOP AT <it> ASSIGNING <temp>.
ASSIGN COMPONENT datafields-field_name OF STRUCTURE
<temp> TO <wa>.
ENDLOOP.
Now I would like to do it reversed:
I also have the table structure in the field-symbol <it>. But now I would like to add data to the table <it> field by field. I really have no idea where to start.
Anyone?
‎2008 Mar 27 1:25 PM
hi Bert,
the solution is almost the same like "last time", except we go the opposite direction:
you have dynamic structure <temp>.
you have to handle each field one by one:
ASSIGN COMPONENT datafields-field_name OF STRUCTURE
<temp> TO <wa>.
assign value now:
<wa> = ...
when you are ready with each file than you can append the dynamic structure to the dynamic internal table:
APPEND <temp> TO <it>.
you have to repeat the process of course, if you want more lines in the internal table
hope this helps
ec
‎2008 Mar 27 1:20 PM
REPORT z_dynamic.
TYPE-POOLS : abap.
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_wa>,
<dyn_field>.
DATA: dy_table TYPE REF TO data,
dy_line TYPE REF TO data,
xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_table(30) TYPE c DEFAULT 'T001'.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
PERFORM get_structure.
PERFORM create_dynamic_itab.
PERFORM get_data.
PERFORM write_out.
&----
*& Form get_structure
&----
text
----
FORM get_structure.
DATA : idetails TYPE abap_compdescr_tab,
xdetails TYPE abap_compdescr.
DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails[] = ref_table_des->components[].
LOOP AT idetails INTO xdetails.
CLEAR xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
APPEND xfc TO ifc.
ENDLOOP.
ENDFORM. "get_structure
&----
*& Form create_dynamic_itab
&----
text
----
FORM create_dynamic_itab.
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>.
ENDFORM. "create_dynamic_itab
&----
*& Form get_data
&----
text
----
FORM get_data.
Select Data from table.
SELECT * INTO TABLE <dyn_table>
FROM (p_table).
ENDFORM. "get_data
&----
*& Form write_out
&----
text
----
FORM write_out.
Write out data from table.
LOOP AT <dyn_table> INTO <dyn_wa>.
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE <dyn_wa> TO <dyn_field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF sy-index = 1.
WRITE:/ <dyn_field>.
ELSE.
WRITE: <dyn_field>.
ENDIF.
ENDDO.
ENDLOOP.
ENDFORM. "write_out
‎2008 Mar 27 1:39 PM
THX, hope it works..
Tested ==> WORKS! Thanx man!
Greets
Edited by: Bert Neels on Mar 27, 2008 3:02 PM
‎2008 Mar 27 1:25 PM
hi Bert,
the solution is almost the same like "last time", except we go the opposite direction:
you have dynamic structure <temp>.
you have to handle each field one by one:
ASSIGN COMPONENT datafields-field_name OF STRUCTURE
<temp> TO <wa>.
assign value now:
<wa> = ...
when you are ready with each file than you can append the dynamic structure to the dynamic internal table:
APPEND <temp> TO <it>.
you have to repeat the process of course, if you want more lines in the internal table
hope this helps
ec