11-10-2007 12:45 PM
hi experts...
suppose i have i_tab with component werks, matnr, mtart.
in i_tab, i have retrieved 2 entries of matnr from one werks.
i have to transfer the entries from i_tab into dynamic table <dyn_tab>.
how will i transfer each entry?
i have created and assigned work area for the dynamic table output:
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
please help me with this. thanks!
march
11-10-2007 1:00 PM
Do it like this:
METHOD fill_dynamic_tab.
DATA: l_descr_ref TYPE REF TO cl_abap_structdescr,
l_str TYPE string,
l_tabix TYPE sytabix.
FIELD-SYMBOLS: <li_table> TYPE ANY,
<comp_wa> TYPE abap_compdescr,
<fzmach> TYPE zscmachine. "This is your i_tab work area
* Create dynamic work area and assign to FS
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO: <dyn_wa>, <li_table>.
l_descr_ref ?= cl_abap_typedescr=>describe_by_data( <dyn_wa> ).
check ( l_descr_ref IS BOUND ).
* Main logic
LOOP AT lt_zmach ASSIGNING <fzmach>. "This is your i_tab
MOVE-CORRESPONDING <fzmach> TO: <li_table>, <dyn_wa>.
READ TABLE l_descr_ref->components ASSIGNING <comp_wa>
WITH KEY name = 'WERKS'.
l_tabix = sy-tabix.
IF sy-subrc = 0.
ASSIGN COMPONENT l_tabix OF STRUCTURE <li_table> TO <dyn_field>.
<dyn_field> = <fzmach>-werks.
ENDIF.
READ TABLE l_descr_ref->components ASSIGNING <comp_wa>
WITH KEY name = 'MATNR'.
l_tabix = sy-tabix.
IF sy-subrc = 0.
ASSIGN COMPONENT l_tabix OF STRUCTURE <li_table> TO <dyn_field>.
<dyn_field> = <fzmach>-matnr.
* keep doing as above for all other fields you require
APPEND <li_table> INTO <dyn_table>.
CLEAR: <li_table>, <dyn_wa>.
ENDLOOP.
SORT <dyn_table>.
ENDMETHOD. "fill_dynamic_tab
I'm not in front of a system, so you might get syntax errors, correct them as you go.
<b>Don't forget to reward points if this has helped you!</b>
Cheers,
Sougata.
11-10-2007 1:00 PM
Do it like this:
METHOD fill_dynamic_tab.
DATA: l_descr_ref TYPE REF TO cl_abap_structdescr,
l_str TYPE string,
l_tabix TYPE sytabix.
FIELD-SYMBOLS: <li_table> TYPE ANY,
<comp_wa> TYPE abap_compdescr,
<fzmach> TYPE zscmachine. "This is your i_tab work area
* Create dynamic work area and assign to FS
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO: <dyn_wa>, <li_table>.
l_descr_ref ?= cl_abap_typedescr=>describe_by_data( <dyn_wa> ).
check ( l_descr_ref IS BOUND ).
* Main logic
LOOP AT lt_zmach ASSIGNING <fzmach>. "This is your i_tab
MOVE-CORRESPONDING <fzmach> TO: <li_table>, <dyn_wa>.
READ TABLE l_descr_ref->components ASSIGNING <comp_wa>
WITH KEY name = 'WERKS'.
l_tabix = sy-tabix.
IF sy-subrc = 0.
ASSIGN COMPONENT l_tabix OF STRUCTURE <li_table> TO <dyn_field>.
<dyn_field> = <fzmach>-werks.
ENDIF.
READ TABLE l_descr_ref->components ASSIGNING <comp_wa>
WITH KEY name = 'MATNR'.
l_tabix = sy-tabix.
IF sy-subrc = 0.
ASSIGN COMPONENT l_tabix OF STRUCTURE <li_table> TO <dyn_field>.
<dyn_field> = <fzmach>-matnr.
* keep doing as above for all other fields you require
APPEND <li_table> INTO <dyn_table>.
CLEAR: <li_table>, <dyn_wa>.
ENDLOOP.
SORT <dyn_table>.
ENDMETHOD. "fill_dynamic_tab
I'm not in front of a system, so you might get syntax errors, correct them as you go.
<b>Don't forget to reward points if this has helped you!</b>
Cheers,
Sougata.
11-10-2007 1:15 PM
Hi Sougata,
Thank you for the code.
I have a question. The program does not recognize TYPE zscmachine.
What do you mean by this?
Thanks!
march
11-10-2007 1:19 PM
No!! The ZSCMACHINE is the type I used in my program because my internal table is TYPE that table I created in the dictionary.
For you, it depends on the definition of your internal table. It should be the same TYPE as your internal table which you are looping in to fill your dynamic table.
Sougata.
<b>Don't forget to reward points on the left hand side of the page.</b>
Message was edited by:
Sougata Chatterjee
11-10-2007 1:20 PM