Skip to Content
author's profile photo Former Member
Former Member

internal table

hi,

may i know how to move fieldc in temp internal table to main internal table fieldc and overrite the fieldc in main internal table when fielda and fieldb are the same?

notice that sometimes temp table entry may less. for example fielda 124 is only 1 entry in temp but want to update the corresponding entry in main internal table which has 2 entries.

main internal table

fielda fieldb fieldc

123 10 999

123 10 999

123 10 999

124 10 sss

124 10 sss

temp internal table

fielda fieldb fieldc

123 10 999

123 10 998

123 10 997

124 10 see

thanks

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 12, 2007 at 02:57 AM

    Hi,

    I dont find any necessity of using temporary internal table over here. You can directly compare field content of

     fielda

    and

     fieldb

    and by using <b>modify</b> keyword, we can update the main internal table. So that you can get what expecting.

    begin of itab

    fielda

    fieldb

    fieldc

    end of itab.

    data : wa like itab.

    loop at itab into wa.

    if wa-fielda = wa-fieldb.

    fieldc = 'see'.

    modify itab form wa transporting fieldc.

    endif.

    Dont forget to Reward points.

    Regards

    Sreenivasa sarma k.

    endloop.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 12, 2007 at 02:59 AM

    Try this..

    Loop at temp.

    if temp-fielda = temp-fieldb.

    read table main index sy-tabix.

    if sy-subrc = 0.

    move temp-fieldc to main-fieldc.

    modify main.

    clear main.

    endif.

    endif.

    endloop.

    Mithun

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 12, 2007 at 03:30 AM

    Hi Eliana,

    By your example your results may vary or be inaccurate. Main internal table should be your main loop, and temp is your lookup table. Your temp table should be sorted by fielda and fieldb and use binary search. Main will have a header.

    loop at main.

    ..read temp with key fielda = main-fielda and fieldb = main-fieldb binary search.

    ..if sy-subrc = 0.

    ....main-fieldc = temp-fieldc.

    ....modify main.

    ..endif.

    endloop.

    In your example, you will have a problem, because in your temp table, you have the same key (fielda, fieldb) 3 times, 123 10. So which value would you want? So I assume this was just an example error. Your temp table should look more like:

    123 10 999

    123 11 998

    123 12 996

    124 10 999

    Point: you should always use a sorted table and read with binary search, only time you might not is if you have less than 10 records. But generally, use Binary search and don't forget to sort the table or define the table as type sorted.

    Hope this helps.

    Filler

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 12, 2007 at 03:34 AM
    loop at it_main into is_main.
    read table it_temp into is_temp with key fielda = is_main-fielda
                                             fieldb = is_main-fieldb.
    if sy-subrc = 0.
      move is_temp-fieldc to is_main-fieldc.
      modify it_main from is_main transporting fieldc.
    endif.
    clear : is_main, is_temp.
    endloop.

    if you do this way your ouptu will be this.

    fielda fieldb fieldc

    123 10 999

    123 10 999

    123 10 999

    124 10 see

    124 10 see

    But i doubt this is not what you need because in main table you will have duplicate entries.

    so make clear ur requirement..before u proceed with my code.

    and use / change the code accordingly to meet your requirement.

    Regards

    Gopi

    Add a comment
    10|10000 characters needed characters exceeded

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.