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

by adding two fields and placed in field3

Former Member
0 Likes
816

this is internal table ITAB

F1 F2 F3

1 3

2 2

3 4

4 1

F1 is the field one ,F2 is the field two, both containing data like above ,

F3 is the field three it has no data

we want to add F1,F2 fields we have to store into F3 field

F! fied has row value "1" etc..

F2 fied has row value"3" etc..

1 + 3 = 4 this result will be stored into F3 field result of 4 will be first row of F3.

could u plz explain clearly with code and step by step with comments

this is internal table ITAB

F1 F2 F3

1 3

2 2

3 4

4 1

F1 is the field one ,F2 is the field two, both containing data like above ,

F3 is the field three it has no data

we want to add F1,F2 fields we have to store into F3 field

F! fied has row value "1" etc..

F2 fied has row value"3" etc..

1 + 3 = 4 this result will be stored into F3 field result of 4 will be first row of F3.

could u plz explain clearly with code and step by step with comments

5 REPLIES 5
Read only

rahulkavuri
Active Contributor
0 Likes
752

hi carry on like this

loop at itab.

itab-field3 = itab-field1 + itab-field2.

modify itab index sy-tabix.

endloop.

award points if found helpful

Read only

Former Member
0 Likes
752

if not itab[] is initial. "Check if itab contains data

loop at itab.

itab-f3 = itab-f1 + itab-f2.

modify itab transporting f3 index sy-tabix. "Modify the current row with F3 field

endloop.

Thanks,

Santosh

Read only

0 Likes
752

Hi Rajesh,

Please use the below code

Loop at ITAB.
   ITAB-F3 = ITAB-F1 +ITAB-F2.
   Modify ITAB.
Endloop.

Read only

Former Member
0 Likes
752

Hello Rajesh,

While modifying internal tables, it is always useful to use field symbols. So you can use the follwing code. The field symbol points directly to the assigned line in memory. Unlike work areas, in which the contents of the line are only available indirectly, field symbols allow you to read and change table entries directly. When we change an internal table with the MODIFY statement, we must first fill a work area with values, and then assign them to the internal table. If we work with field symbols instead, we do not have this overhead. This can improve performance if you have large or complex internal tables.

FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.

LOOP AT ITAB ASSIGNING <FS>.

<FS>-f3 = <FS>-f1 + <FS>-f2.

ENDLOOP.

Award points if found useful.

Regards

Indrajit

Read only

Former Member
0 Likes
752

data : begin of itab occurs 0,

f1(3) type C,

f2(3) type C,

f3(4) type C,

end of itab.

itab-f1 = '1'. itab-f2 = '2'. APPEND ITAB.

itab-f1 = '2'. itab-f2 = '3'. APPEND ITAB.

ITAB-F1 = '3'. ITAB-F2 = '4'. APPEND ITAB.

ITAB-F1 = '4'. ITAB-F2 = '1'. APPEND ITAB.

loop at itab.

ITAB-F3 = ITAB-F1 + ITAB-F2.

MODIFY ITAB INDEX SY-TABIX.

write : / itab-f3.

endloop.

first we have to declare the internal table with variables and then assign the values into the variables and append them into the internal table.

looping will help you to read the fields one by one.

modify itab will insert the var3 into the itab.

i guess this will help you