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

Internal table

Former Member
0 Likes
695

I have an internal table with four fields..Using query i filled the internal table with 5 records..like

field1 field2 field3 field4

12 14 12

32 43 43

7 4 5

4 55 4

8 85 91

But field4 is not filled..I want to take tht value from other table based on the field1 value as a key value for both the tables..So how can update tht particular one field..

So tht all the records will have four fields filled

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
674

Hi Mahesh,

You can't achieve this using SELECT.

You need to get data in some other internal table and then use LOOP ..READ to move the data and MODIFY to modify the record in internal table.

Regards,

Atish

8 REPLIES 8
Read only

Former Member
0 Likes
675

Hi Mahesh,

You can't achieve this using SELECT.

You need to get data in some other internal table and then use LOOP ..READ to move the data and MODIFY to modify the record in internal table.

Regards,

Atish

Read only

0 Likes
674

can u plz give a sample code

Read only

0 Likes
674

loop at itab.

select field4 from <table name> into itab-field4 where table_name-field1 = itab-field1.

modify itab transporting field4.

endloop.

plz reward points if ids helps

Read only

0 Likes
674

Check this sample code and do it accordingly

SELECT field1 field2 field3
       FROM table1
       INTO TABLE it_tab1.

SELECT field1 field4 field5
       FROM table2
       INTO TABLE it_tab2.

SORT it_tab1 BY field1.
SORT it_tab2 BY field1.

LOOP AT it_tab2.
  READ TABLE it_tab1 WITH KEY field1 = it_tab2-field1.
  IF sy-subrc = 0.
    MOVE it_tab1-field1 TO it_final.
    MOVE it_tab1-field2 TO it_final.
    MOVE it_tab1-field3 TO it_final.
    MOVE it_tab2-field4 TO it_final.
    MOVE it_tab2-field5 TO it_final.
    APPEND it_final.
  ENDIF.
  CLEAR : it_tab1, it_tab1, it_final.
ENDLOOP.

Regards

Gopi

Read only

0 Likes
674

Hi Mahesh,

SELECT f2 f3 f4

INTO itab

FOR ALL ENTRIES iN itab1

WHERE f2 = itab1-f2

and f3 = itab1-f3.

LOOP AT itab1.

READ TABLE itab WITH KEY f2 = itab1-f2

f3 = itab1-f3.

MOVE itab-f4 to itab1-f3.

MODIFY itab1.

ENDLOOP.

Just do slight corrections

Regards,

Atish

Read only

Former Member
0 Likes
674

Assume itab has field1, field2, field3, field4

ihead has field3, field4, field5

we want to moved data from ihead-field4 to itab-field4 based on common value Field3

sort ihead by field3.
loop at itab.
read table ihead with key field3 = itab-field3 binary search.
itab-field4 = ihead-field4.
modify itab.
endloop.

Read only

Former Member
0 Likes
674

HI,

do like this.

loop at itab.

select single <field4> into itab-field4 from <table> where field1 = itab-field1.

modify itab.

endloop.

rgds,

bharat.

Read only

former_member386202
Active Contributor
0 Likes
674

Hi,

Loop on internal table. then read second internal table using read table with key

and binary search. checke sy-subrc , if it is zero then pass that value to field4 and

modify the internal table with index.

Regards,

Prashant