‎2010 Oct 05 3:14 PM
Hi guys,
I have Incoming data and an outgoing structure created dynamicly. See code snippets.
*&- Incoming data
CREATE DATA lt_incoming_data LIKE it_tr_str.
ASSIGN lt_incoming_data->* TO <fs_incoming_data>.
<fs_incoming_data> = it_tr_str.
*&- Outgoing data
CREATE DATA lt_outgoing_data TYPE HANDLE table_descr.
ASSIGN lt_outgoing_data->* TO <fs_outgoing_data>.
wa_outgoing_data = cl_abap_structdescr=>create( comp_tab ).
ASSIGN wa_outgoing_data TO <wa_outgoing_data>.
Now I want to append/insert data to the dynamic created internal table from the incoming dynamic table:
FIELD-SYMBOLS: <fs_in> TYPE data,
<fs_out> TYPE data.
DATA: lv_subrc TYPE sy-subrc.
LOOP AT <fs_incoming_data> ASSIGNING <wa_incoming_data>.
CLEAR wa_outgoing_data.
lv_subrc = sy-subrc.
WHILE lv_subrc = 0.
ASSIGN COMPONENT sy-index OF STRUCTURE <wa_incoming_data> TO <fs_in>.
lv_subrc = sy-subrc.
*&- Now put the <fs_in> value in the dynamic workarea of the outgoing data and append to lt_outgoing_data
----
ENDWHILE.
ENDLOOP.
Please advice what to do if possible ?/
Cheers, John
‎2010 Oct 05 3:48 PM
Same as
ASSIGN COMPONENT sy-index OF STRUCTURE <wa_incoming_data> TO <fs_in>.
assign the component of dynamic workarea of the outgoing data to a field symbol say <fs_t> then move it like
<fs_t> = <fs_in>. once all the components in workarea of the outgoing data are populated the append the work area to the itab.
Somethig similar to this code
LOOP AT <fs_incoming_data> ASSIGNING <wa_incoming_data>.
CLEAR wa_outgoing_data.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <wa_incoming_data> TO <fs_in>.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
ASSIGN COMPONENT sy-index OF STRUCTURE <wa_outgoing_data> TO <fs_t>.
CHECK sy-subrc = 0.
<fs_t> = <fs_in>.
ENDDO.
append <wa_outgoing_data> to it_outgoing.
ENDLOOP.
‎2010 Oct 05 3:39 PM
just use INSERT statement
INSERT <wa_incoming_data> INTO TABLE <fs_incoming_data>.
‎2010 Oct 05 3:48 PM
Same as
ASSIGN COMPONENT sy-index OF STRUCTURE <wa_incoming_data> TO <fs_in>.
assign the component of dynamic workarea of the outgoing data to a field symbol say <fs_t> then move it like
<fs_t> = <fs_in>. once all the components in workarea of the outgoing data are populated the append the work area to the itab.
Somethig similar to this code
LOOP AT <fs_incoming_data> ASSIGNING <wa_incoming_data>.
CLEAR wa_outgoing_data.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <wa_incoming_data> TO <fs_in>.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
ASSIGN COMPONENT sy-index OF STRUCTURE <wa_outgoing_data> TO <fs_t>.
CHECK sy-subrc = 0.
<fs_t> = <fs_in>.
ENDDO.
append <wa_outgoing_data> to it_outgoing.
ENDLOOP.
‎2010 Oct 05 4:06 PM
Hi,
What is the type of <fs_in>, is that declared with TYPE ANY?
FIELD-SYMBOLS: <fs_in> TYPE ANY.
in the LOOP and ENDLOOP, add below logic.
LOOP AT <fs_incoming_data> ASSIGNING <wa_incoming_data>.
ASSIGN COMPONENT sy-index OF STRUCTURE <wa_outgoing_data> TO <fs_in>. " Give <wa_outgoing_data>
<fs_in> = <wa_incoming_data>-(1 st field). " Give fields in the order of <wa_outgoing_data> structure which matches with incoming structure
ASSIGN COMPONENT sy-index OF STRUCTURE <wa_outgoing_data> TO <fs_in>.
<fs_in> = <wa_incoming_data>-(2nd field).
ASSIGN COMPONENT sy-index OF STRUCTURE <wa_outgoing_data> TO <fs_in>.
<fs_in> = <wa_incoming_data>-(3rd field).
....
...
...
INSERT <wa_outgoing_data> INTO TABLE <fs_outgoing_data>.
CLEAR : <fs_in>, <wa_outgoing_data>.
ENDLOOP.Regards
Bala Krishna
‎2010 Oct 05 4:23 PM
Hi John,
as you did not give any example of what you want or what is the underlying process it is hard to answer.
I would not use
ASSIGN COMPONENT sy-index OF STRUCTURE
Better use CL_ABAP_STRUCTDESCR->GET_COMPONENTS to get the fieldnames. Loop over the components table,
ASSIGN COMPONENT <component_table-name> OF STRUCTURE <wa_incoming_data> TO <in>Do this for <wa_incoming_data> and <wa_outgoing_data>, if both are assigned, move <in> to <out> and APPEND <wa_outgoing_data> to <fs_outgoing_data>.
Or simply move-corresponding
<wa_incoming_data> to <wa_outgoing_data>.
APPEND <wa_outgoing_data> to <fs_outgoing_data>.Regards,
Clemens
‎2010 Oct 06 2:12 PM
Thanks the most who have contributed. Based on the combination of your answers I was able to solve the issue.
Here it is the code snippet how it works now:
*&- Incoming data
CREATE DATA lt_incoming_data LIKE it_tr_str.
ASSIGN lt_incoming_data->* TO <fs_incoming_data>.
<fs_incoming_data> = it_tr_str.
*&- Outgoing data
CREATE DATA lt_outgoing_data TYPE HANDLE table_descr.
ASSIGN lt_outgoing_data->* TO <fs_outgoing_data>.
CREATE DATA wa_outgoing_data TYPE HANDLE struct_descr.
ASSIGN wa_outgoing_data->* TO <wa_outgoing_data>.
LOOP AT <fs_incoming_data> ASSIGNING <wa_incoming_data>.
CLEAR wa_outgoing_data.
lv_subrc = sy-subrc.
MOVE-CORRESPONDING <wa_incoming_data> TO <wa_outgoing_data>.
ASSIGN COMPONENT 'DETAIL_GUID' OF STRUCTURE <wa_outgoing_data> TO <fs_guid>.
SELECT SINGLE * FROM /rpm/item_d INTO wa_item_d
WHERE guid = <fs_guid>.
LOOP AT lt_sl_fields INTO wa_sl_fields.
CASE wa_sl_fields-ztable.
WHEN '/RPM/ITEM_D'.
ASSIGN COMPONENT wa_sl_fields-zfield OF STRUCTURE wa_item_d TO <fs_field>.
ASSIGN <fs_field> TO <fs_out>.
WHEN 'DPR_AREA_T'.
WHEN 'ZZZTPXR116USER'.
ENDCASE.
ASSIGN COMPONENT wa_sl_fields-zfield OF STRUCTURE <wa_outgoing_data> TO <fs_temp>.
<fs_temp> = <fs_out>.
ENDLOOP.
APPEND <wa_outgoing_data> TO <fs_outgoing_data>.
ENDLOOP.
*&- Append outgoing structure
CREATE DATA ex_tab TYPE HANDLE table_descr.
ASSIGN ex_tab->* TO <ex_tab>.
<ex_tab> = <fs_outgoing_data>.
CATCH cx_sy_struct_creation
cx_sy_table_creation INTO error.
MESSAGE error TYPE ' I' DISPLAY LIKE 'E'.
RETURN.
ENDTRY.