11-20-2008 6:02 AM
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.
11-20-2008 6:06 AM
Hi,
try using collect statement and then passing to IT_final
Thanks & Regards
11-20-2008 6:06 AM
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.
11-20-2008 6:08 AM
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
11-20-2008 6:09 AM
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
11-20-2008 6:13 AM
Use the below code.
sort it_table.
loop it_table.
move it_table to it_final.
collect it_final.
endloop.
11-20-2008 6:29 AM
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.