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

modify

Former Member
0 Likes
994

Hi,

I want to insert one field of one itab into another itab.

Itab1 has two fields n itab2 has 10 fields.I do not know any key field.

But I want insert the field from itab1 to itab2 inside the loop of itab2.

Can any one suggest some idea on this.

9 REPLIES 9
Read only

Former Member
0 Likes
972

Hi

What do you really means?

U need to insert a field or a value of a field?

If it's so:

LOOP AT ITAB2.
  READ TABLE ITAB1 WITH KEY FIELD1 = <......>
                                                  FIELD2 = <......>.
  IF SY-SUBRC = 0.
     ITAB2-FIELDN = ITAB-<FIELD>.
     MODIFY ITAB2.
  ENDIF.
ENDLOOP.

Max

Read only

Former Member
0 Likes
972

u need to know the relation for reading the itab1 value based in itab2 fields..

if u have the the relation u can read the itab1 inside the itab2 and modify itab2 table based in sy-tabix.

Read only

Former Member
0 Likes
972

Hi,

There must be the key field which is common in both internal tables.You sort both int. tables by the key field.

ITAB1 has 10 fields and ITAB2 has 2 fields.

Loop at itab1.

myindex = sy-tabix.

read itab2 with key key = <itab1-key>.

if sy-subrc = 0.

move itab2-key to itab1-key.

modify itab2 index myindex transporting key.

clear:itab1,itab2.

endloop.

Read only

Former Member
0 Likes
972

Hi ,

suppose itab1 is the internal table with two fields and itab2 is the internal table with 10 fields.

wtab1 and wtab2 are the corresponding work areas.

if you want to put the values of itab1 to itab2 follow this chunk of sample code.

loop at itab1 into wtab1.

move corresponding fields of wtab1 to wtab2.

append wtab2 to itab2.

clear :wtab1,wtab2.

endloop.

I hope this will solve ur problem.

Read only

Former Member
0 Likes
972

hi,

The below code works provided the field should exist in both the internal tables ..


loop at itab1.
  move corresponding itab1 to itab2.
  if not itab2-field is initial. 
    append itab2. 
    clear itab2.
 endif.
endloop. 

Regards,

Santosh

Read only

Former Member
0 Likes
972

Hi use as following to modify itab2.

data index type sy-tabix.

IF NOT itab2[] IS INITIAL.

LOOP AT itab2.

LOOP AT itab1 WHERE field = itab2-field.

index = sy-tabix.

itab2-fields = itab1-fields.

MODIFY itab2 INDEX index.

CLEAR index.

ENDLOOP.

ENDLOOP.

ENDIF.

Reward if found helpful

regards,

Dhan

Read only

Former Member
0 Likes
972

Hi,

Does itab2 contain field of itab1 which you want to move?

Consider this,itab1 has name1,city and pin fields.itab2 has name1.name2,name3,street,city and district.In itab2 city is blank.If youwant to move city from itab1 to itab2 ,folow this,



loop at itab1.
itab2-city = itab1-city.
modify itab2 transporting city.
endloop.

Note : here itab2 has to have the field of city.

If you have any doubt let me know.

Reward if useful.

Warm Regards,

Mohandoss P.

Read only

Former Member
0 Likes
972

Hi,

First of all i want to say one thing that combining 2 internal table without any common key fields is meaning less. any way if that is ur requirment do it as follow:

1. u can modify it with the help of index. In this process it 'll update the record based on the index that it retrives from the table.

2.u said u hav 2 fields in 1st itab...so do 1 thing first choose any one field that u feel u can keep it as common key for both and include the first itab with that common field and create a structure first modify that itab using the index and then it 'll be easy for u to update the second one.

Thanks,

Arunprasad.P

Read only

Former Member
0 Likes
972

can be closed