Skip to Content
avatar image
Former Member

add fields from tab2 to tab1

hallow

i have two internal tables with same type fields and i wont to add fields of table 2

to table 1 what is the best way to do that?

<b>i reward</b>

ex.

itab1

a1 a2 a3 a4 a5

1 2 3 4 5

itab 2

b1 b2 b3 b4 b5

6 7 8 9 10

i wont in itab 1

<b>a1 a2 a3 a4 a5

7 9 11 13 15 <---a1+b1 in field a1 in itab 1</b>

Regards

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

8 Answers

  • Best Answer
    avatar image
    Former Member
    Aug 20, 2007 at 07:56 AM

    loop at itab1.

    read table itab2 index sy-tabix.

    itab1-a1 = itab1-a1 + itab2-b1.

    itab1-a2 = itab1-a2 + itab2-b2.

    itab1-a3 = itab1-a3 + itab2-b3.

    itab1-a4 = itab1-a4 + itab2-b4.

    itab1-a5 = itab1-a5 + itab2-b5.

    modify itab1.

    endloop.

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 20, 2007 at 07:54 AM

    Antonio,

    loop at the first internal table

    read the second internal table with common fields

    itab1-a1 = itab1-a1 + itab2-b1.

    ...

    ...

    modify itab1.

    endloop.

    clear itab1

    clear itab2.

    K.Kiran.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 20, 2007 at 07:56 AM

    hi

    use ADD-CORRESPONDING statement

    if helpful, reward

    Sathish. R

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 20, 2007 at 08:15 AM

    HI,

    do like this.

    DESCRIBE TABLE itab1 lines sy-tfill.

    do sy-tfill times.

    READ TABLE itab1 index 1 into wa1.

    READ TABLE itab2 index sy-index into wa2.

    DELETE itab1 index 1.

    wa1-a1 = wa1-a1 + wa2-b1.

    wa1-a2 = wa1-a2 + wa2-b2.

    wa1-a3 = wa1-a3 + wa2-b3.

    wa1-a4 = wa1-a4 + wa2-b4.

    wa1-a5 = wa1-a5 + wa2-b5.

    APPEND wa1 to itab1.

    enddo.

    rgds,

    bharat.

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 20, 2007 at 07:55 AM

    Hi,

    Use like this

    DATA: itab1_wa LIKE LINE OF itab1.
    DATA: itab2_wa LIKE LINE OF itab2.
    LOOP AT itab2 into itab2_wa.
    itab1_wa = itab2_wa. "Since the types are same length will be same so you can do this
    COLLECT itab1_wa INTO itab1.
    ENDLOOP.
    

    Regards,

    Sesh

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 20, 2007 at 07:56 AM

    Hi

    loop at itab1.

    index = sy-tabix.

    loop at itab2 index index.

    itab3-c1 = itab1-a1 + itab2-b1.

    .

    .

    .

    .

    endloop.

    append itab3.

    clear itab2,itab1.

    endloop.

    reward points to all helpful answers

    kiran.M

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 20, 2007 at 07:57 AM

    This should work:

    LOOP AT itab1 INTO wa1.
       READ TABLE itab2 INDEX sy-tabix INTO wa2.
       wa1 = wa2.
       COLLECT wa1 INTO itab1.
    ENDLOOP.
    

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 20, 2007 at 08:10 AM

    Hi..

    <b>Try this ...</b> This can be better bcoz we are using the FIELD SYMBOLS so it will calucate the Sum for all the fields irrespective of how many are there.

    Note: ADD-CORRESPONDING can be used only if the Fieldnames are same.

    Field-symbols: <FS1> LIKE LINE OF ITAB1.

    Field-symbols: <FS2> LIKE LINE OF ITAB1.

    Field-symbols: <FS_FIELD1> TYPE ANY.

    Field-symbols: <FS_FIELD2> TYPE ANY.

    LOOP AT ITAB1 ASSIGNING <FS1>.

    V_TABIX = SY-TABIX.

    READ TABLE ITAB2 assigning <FS2> INDEX V_TABIX.

    DO .

    ASSIGN-COMPONENT SY-INDEX OF <FS2> TO <FS_FIELD2>.

    IF SY-SUBRC NE 0.

    EXIT.

    ENDIF.

    ASSIGN-COMPONENT SY-INDEX OF <FS1> TO <FS_FIELD1>.

    IF SY-SUBRC NE 0.

    EXIT.

    ENDIF.

    ADD <FS_FIELD2> <TO <FS_FIELD1>.

    ENDDO.

    ENDLOOP.

    <b>Reward if Helpful</b>

    Add comment
    10|10000 characters needed characters exceeded