Skip to Content

Transfer Data from one Field Symbol to another

I have a requirement where my internal table (T1) is dynamic with fields as the columns.

My internal table where the data resides has fields as rows and has following format.

Sort Sequence Characteristic Class

1 1 Ch1 CA

1 1 Ch2 CA

2 1 Ch1 CA

2 1 Ch2 CA

3 1 Ch1 CA

3 1 Ch3 CA

I am trying to populate above internal table (T1) from another table (T2) where fields are rows. I am looping around T2 and for the first loop count, one column for T1 gets populated. For second loop count, i am updating T1 from field symbol (this field symbol now has value for first two rows. This works fine until Sort 1 and 2. For Sort 3, since Characteristic Ch2 is not there but since we are using the same field symbol as work area...it also populates value for Ch2 which is incorrect. How to fix this issue. If i clear work area field symbol, then the data that gets populated is not correct as well.

Let me know if i need to provide more details.

Thanks for your help.

Add comment
10|10000 characters needed characters exceeded

  • What do you mean with "internal table (T1) is dynamic with fields as the columns" or "table (T2) where fields are rows" ???

    Is the line type of the table statically known or is it only available at runtime? How are the tables declared?

  • This is how the data is ..

    untitled.jpg (32.9 kB)
  • The structure is also dynamic which is only known during runtime.

    * Create dynamic internal table and assign to Field Symbol
    
          CREATE DATA w_tref TYPE HANDLE im_compdesc.
    
          ASSIGN w_tref->* TO <dyn_tab>.
    
          lt_key = im_compdesc->key.
    
    *
    
    ** Create dynamic work area and assign to Field Symbol
    
          CREATE DATA w_dy_line LIKE LINE OF <dyn_tab>.
    
          ASSIGN w_dy_line->* TO <dyn_wa>.

    All the data is then populate by looping around another table with the data in form of rows and the values are populated in work area <dyn_wa> which is appended to table <dyn_tab>

  • Get RSS Feed

1 Answer

  • Best Answer
    Aug 24, 2017 at 09:29 AM

    Hello,

    You have to do it in 3 times :

    - List column names required to create T1 (loop at T2 and append COMP_TAB for distinct Characteristic)

    - Create table T1 (using COMP_TAB)

    - Fill T1 (loop at T2, assign component(T2-characteristic) of structure T1 to <IFIELD>, <IFIELD> = T2-characteristic )

    Here is an example you can copy/paste in a new local test program to undertand how it works :

    DATA :  comp_tab TYPE         cl_abap_structdescr=>component_table,
            comp     LIKE LINE OF comp_tab,
            new_str  TYPE REF TO  cl_abap_structdescr,
            new_tab  TYPE REF TO  cl_abap_tabledescr,
            tref     TYPE REF TO  data,
            lref     TYPE REF TO  data.
    
    FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
    FIELD-SYMBOLS: <iline> TYPE any.
    FIELD-SYMBOLS: <ifield> TYPE any.
    * 1 - Create the structured data you want to fill
    comp-name = 'COL1'.
    comp-type = cl_abap_elemdescr=>get_c( 10 ). " Choose the length and basic type
    APPEND comp TO comp_tab.
    comp-name = 'COL2'.
    comp-type = cl_abap_elemdescr=>get_c( 12 ).
    APPEND comp TO comp_tab.
    new_str = cl_abap_structdescr=>create( comp_tab[] ). " Create structure
    new_tab = cl_abap_tabledescr=>create( " Create a memomy space for a data table
                      p_line_type  = new_str
                      p_table_kind = cl_abap_tabledescr=>tablekind_std
                      p_unique     = abap_false ).
    CREATE DATA tref TYPE HANDLE new_tab.  " create a usable data table
    ASSIGN tref->* TO <itab>. "INTERNAL TABLE. 
    CREATE DATA lref TYPE HANDLE new_str. " create a usable data line
    ASSIGN lref->* TO <iline>. "INTERNAL LINE.
    * 2 - Fill data table
    DO 2 TIMES. " Repeat for each "XLS line"
      CLEAR <iline>.
      ASSIGN COMPONENT 'COL1' OF STRUCTURE <iline> TO <ifield>.
      <ifield> = 'VALUE1'.
      ASSIGN COMPONENT 2 OF STRUCTURE <iline> TO <ifield>.
      <ifield> = 'VALUE2'.
      APPEND <iline> TO  <itab>.
    ENDDO.
    
    * Now <itab> contents values
    BREAK-POINT.
    

    Best regards

    Bertrand

    Add comment
    10|10000 characters needed characters exceeded