Application Development 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: 

regarding adding field values of an internal table

Former Member
0 Kudos

Hi all,

Hi all,

I have a FIELD ERFMG in table MSEG.

I m getting 4 records for this field.I need to add all these 4 records.

and pass it to final table i.e IT_FINAL.

CAN ANYONE SUGGEST ME HOW TO GO FOR IT.

Thanks & Regards.

6 REPLIES 6

Former Member
0 Kudos

Hi,

try using collect statement and then passing to IT_final

Thanks & Regards

GauthamV
Active Contributor
0 Kudos

hi,

define a new variable and add the value of erfmg in the loop and pass

that value to your final table.

data : var type mseg-erfmg.

var = var + itab-erfmg.

former_member1245113
Active Contributor
0 Kudos

Hi Rajesh,

if you want to add the values of erfmg

then use collect keyword.

or

loop at itab.

at new mblnr.

sum.

endat.

here the sum will contain the sum of all the 4 records.

then pass it to the itab and then modify the table.

endloop.

now sort the itab by erfmg descending

before you send it to the final table

read table itab index 1.

index 1 will contain the sum of all the 4 records.

ignore the below from here onwards

_____________________________

if your requirement is like this

select erfmg from dbtable into itab where some condition.

and you are getting 4 records.

now you need to pass it to the fianla itab.

loop itab.

move-corresponding itab to ifinal.

append ifinal.

endloop.

if you want the value from more then 1 interanal table into ifinal.

then

loop at ITEM_ITAB.

here if you can get the 4 records based on the ITEM_TABLE values

use READ statement.

if you can get only one record based on the ITEM_TABLE values

loop at itab where fname = ITEM_ITAB-FNAME.

here you will get all the 4 records

now append them to the final table.

ENDLOOP.

ENDLOOP.

hope this will serve your purpose.

Thanks and regards

Ramchander Rao.K

Edited by: ramchander krishnamraju on Nov 20, 2008 7:10 AM

former_member1245113
Active Contributor
0 Kudos

Hi Rajesh,

if your requirement is like this

select erfmg from dbtable into itab where some condition.

and you are getting 4 records.

now you need to pass it to the fianla itab.

loop itab.

move-corresponding itab to ifinal.

append ifinal.

endloop.

if you want the value from more then 1 interanal table into ifinal.

then

loop at ITEM_ITAB.

here if you can get the 4 records based on the ITEM_TABLE values

use READ statement.

if you can get only one record based on the ITEM_TABLE values

loop at itab where fname = ITEM_ITAB-FNAME.

here you will get all the 4 records

now append them to the final table.

ENDLOOP.

ENDLOOP.

hope this will serve your purpose.

Thanks and regards

Ramchander Rao.K

Former Member
0 Kudos

Use the below code.

sort it_table.

loop it_table.

move it_table to it_final.

collect it_final.

endloop.

Former Member
0 Kudos

Firstly you create 2 internal tables.

In first internal table get all 4 values => by using select query.

loop at first internal table into work_area.

collect into second internal table.

endloop.