Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Field Symbol Append

Former Member
0 Likes
1,331

I have two dynamically dereferenced field symbol tables (comes from 2 different function modules). I need to append these two into a single field symbol table. Please let me  know how to do it?

Data: <Fs1> type standard table,
<fs3> type standard table,
<fs2> type standard table.

Data : lv_data1 type ref to data,
lv_data2 type ref to data .

assign lv_data1->* to <fs1> ." Comes from the first FM

assign lv_data2->* to <fs2> ." Comes from the Second FM

Now I need to combine these two into <fs3>.

Please let me know how to do this?

I have two dynamically dereferenced field symbol tables (comes from 2 different function modules). I need to append these two into a single field symbol table. Please let me  know how to do it?

Data: <Fs1> type standard table,
<fs3> type standard table,
<fs2> type standard table.

Data : lv_data1 type ref to data,
lv_data2 type ref to data .

assign lv_data1->* to <fs1> ." Comes from the first FM

assign lv_data2->* to <fs2> ." Comes from the Second FM

Now I need to combine these two into <fs3>.

Please let me know how to do this?

4 REPLIES 4
Read only

Former Member
0 Likes
1,000

Hello Selva

You have two fieldsymbols of tables, you want to joint them into a 3rd table

Because they are dynamic tables

only way is to loop and assign the data one by one

Code snippet will be:

field-symbols<output_table> type standard table

                 ,<output_line> type any

      .

*create the dynami table here!!

     assign gt_dref_table->* to <output_table>.

     assign gs_dref_line->* to <output_line>.

*Get the base components first, columns

*Get the components descriptions

   lo_structdescr ?= cl_abap_typedescr=>describe_by_data(

<output_line> ).

  lt_base_components[] = lo_structdescr->get_components( ).


loop at <output_table> assigning <output_line>.

*build the fieldnames

       loop at lt_base_components assigning <lfs_base_components>.

         concatenate  <lfs_base_components>-name '_'  <lfs_ozet>-yıl_ay

         into lv_field_name.

         assign component <lfs_base_components>-name of structure

         <lfs_ozet> to <lv_from_value>.

         check sy-subrc eq 0.

         assign component lv_field_name of structure  <output_line> to

   <lv_to_value>.

         if sy-subrc eq 0.

           <lv_to_value> = <lv_from_value>.

         endif.

       endloop.

endloop.

Read only

VXLozano
Active Contributor
0 Likes
1,000

What about to APPEND all lines of both tables to a third internal table and then ASSIGN it to a third FIELD-SYMBOL?

Read only

Former Member
0 Likes
1,000

The function module return only the data reference. So I am not sure about the structure of the output data.

Read only

Former Member
0 Likes
1,000

Hi Selva,

This is the trick of dynamic programming. Coming to your issue, let us assume TAB1 (returned by FM1) and TAB2 (returned by FM2) are the concerned tables you want to append.

Here we have to assume that there will be some common fields in both the tables otherwise there is no point in collecting the whole data.

DATA: lr_data TYPE REF TO data.
FIELD-SYMBOLS: <lt_tab1> TYPE table,
                <lt_tab2> TYPE table,
                <lt_tab3> TYPE table,
                <ls_tab1> TYPE any,
                <ls_tab2> TYPE any.

ASSIGN tab1->* TO <lt_tab1>.
CREATE DATA lr_data LIKE LINE OF <lt_tab1>.
ASSIGN lr_data->* TO <ls_tab1>.

CLEAR lr_data.

ASSIGN tab2->* TO <lt_tab2>.
CREATE DATA lr_data LIKE LINE OF <lt_tab2>.
ASSIGN lr_data->* TO <ls_tab2>.

LOOP AT <lt_tab2> ASSIGNING <ls_tab2>.
   MOVE-CORRESPONDING <ls_tab2> TO <ls_tab1>.
   APPEND <ls_tab1> TO <lt_tab1>.
ENDLOOP.

<lt_tab1> will contain both the tables data.

Please reward if found helpful. Also do revert back for further queries.

Regards,

Koushik