Skip to Content

Moving data from table1 to table 2.

Hello Friends,

I need to move data from table lt_source ( TYPE well defined) to table lt_target. I know the type of lt_target also but the table type of table lt_target gets defined only at runtime.

Also as both tables have some common fields and MOVE-CORRESPONDING cannot be used. Nonetheless the main issue is assigning any value from lt_source to lt_target.

Regards,

Aayush

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Oct 01, 2009 at 10:15 AM

    Hi

    U need to use the field-symbols, u should store the name of the field it_source in a internal table and use it for the mapping:

    LOOP AT IT_SOURCE.
       LOOP AT IT_FIELD.
          ASSIGN COMPONENT IT_FIELD-NAME OF STRUCTURE IT_SOURCE TO <FS_SOURCE>.
          ASSIGN COMPONENT IT_FIELD-NAME OF STRUCTURE IT_TARGET TO <FS_TARGET>.
          IF SY-SUBRC = 0.
             <FS_TARGET> = <FS_SOURCE>.
         ENDIF.
       ENDLOOP.
       APPEND IT_TARGET.
    ENDLOOP.

    Max

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Try to use a code like this:

      DATA: LT_CAMPAIGNS TYPE ZTESTCAMPAIGN_TAB,
            LS_CAMPAIGNS TYPE ZTESTCAMPAIGN.
      
      DATA: DFIES_TAB TYPE TABLE OF DFIES,
            DFIES_WA  TYPE  DFIES.
      
      DATA DYN_WA TYPE REF TO DATA.
      FIELD-SYMBOLS <WA> TYPE ANY.
      
      FIELD-SYMBOLS: <FS_TARGET> TYPE ANY,
                     <FS_SOURCE> TYPE ANY.
      
      * Create the workarea
      CREATE DATA DYN_WA LIKE LINE OF CT_DB_DATA.
      ASSIGN DYN_WA->* TO <WA>.
      
      CALL FUNCTION 'DDIF_FIELDINFO_GET'
        EXPORTING
          TABNAME   = 'ZTESTCAMPAIGN'
        TABLES
          DFIES_TAB = DFIES_TAB.
      
      LOOP AT LT_CAMPAIGNS INTO LS_CAMPAIGNS.
        CLEAR <WA>.
        LOOP AT DFIES_TAB INTO DFIES_WA.
          ASSIGN COMPONENT DFIES_WA-FIELDNAME OF STRUCTURE LS_CAMPAIGNS TO <FS_SOURCE>.
          ASSIGN COMPONENT DFIES_WA-FIELDNAME OF STRUCTURE <WA>         TO <FS_TARGET>.
          IF SY-SUBRC = 0.
            <FS_TARGET> = <FS_SOURCE>.
          ENDIF.
        ENDLOOP.
        CHACK NOT <WA> IS INITIAL.
        APPEND <WA> TO CT_DB_DATA.
      ENDLOOP.

      Max

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.