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: 

add multiple column of rows

Former Member
0 Kudos

hi i have an internal table itab it has following values.

empl_Id month expence1 expence2 expence3 expence4

259 jan 00 25 25 66

259 feb 30 11 00 22

259 feb 40 00 22 45

259 feb 40 00 26 10

259 mar 00 30 72 45

259 mar 25 88 32 55

259 apr 40 00 22 45

the final value of the internal table itab2 should be.

259 jan 00 25 25 66

259 feb 110 11 48 77

259 mar 25 118 104 110

259 apr 40 00 22 45

please suggest me how to write the code

1 ACCEPTED SOLUTION

Former Member
0 Kudos

LOOP AT itab.

COLLECT itab.
itab2 = itab.
APPEND itab2.

ENDLOOP.

Pushpraj

10 REPLIES 10

Former Member
0 Kudos

hi there,

use at end of event.

search sdn with key word at end of.

regards

Edited by: BrightSide on Feb 25, 2009 1:57 PM

Edited by: BrightSide on Feb 25, 2009 1:58 PM

Former Member
0 Kudos

LOOP AT itab.

COLLECT itab.
itab2 = itab.
APPEND itab2.

ENDLOOP.

Pushpraj

Former Member
0 Kudos
loop at itab.
 collect itab into itab2.
endloop.

Former Member
0 Kudos

Hi,

loop at itab into fs.

at new month.

sum.

endat.

at end of month.

write : ...

endat.

endloop.

This resolves ur issue

Former Member
0 Kudos

Hi,

sort itab by employee_id month.

Loop at itab.

itab2-employeeid = itab-employeeid.

itab2-month = itab-month.

expense1 = expense1 + itab-expense1.

expense2 = expense2 + itab-expense2.

expense3 = expense3 + itab-expense3.

expense4 = expense4 + itab-expense4.

at end of month.

itab2-expense1 = expense1.

itab2-expense1 = expense2.

itab2-expense1 = expense3.

itab2-expense1 = expense4.

clear: expense1, expense2,expense3,expense4.

append itab2.

end at.

endloop.

Regards,

Venkatesh

0 Kudos

but this is only sample of the prob i have up expence45.

do i have to declare all expence in data diclaration.

Former Member
0 Kudos

Hi Ajay,


loop at  itab.
write:/ itab-empl_id.
at end of month.
sum.
write: 10 itab-month,
             itab-exp1,
             itab-exp2,
             itab-exp3,
             itab-exp4.
endat.
endloop.

also try this......

create itab2 of empl_id, month as character fields.


loop at itab.
itab2-emp = itab-emp.
itab2-month = itab-month.
itab2-exp1 = itab-exp.
itab2-exp2 = itab-exp.
itab2-exp3 = itab-exp.
itab2-exp4 = itab-exp.
collect itab2.
endloop.

Regards,

Mdi.Deeba

Former Member
0 Kudos

Hi

here im am assuming that your internal table is not with header line and

the work area is wa1.Create another internal table of the same line type

of the first one(ITAB1).

Now loop through the internal table itab1 .

loop at itab1 into wa1.
COLLECT wa1 INTO itab2.
 endloop.

Now your itab2 eill contains the values as follows

259 jan 00 25 25 66
259 feb 110 11 48 77
259 mar 25 118 104 110
259 apr 40 00 22 45

What this statement does is,it will inserts contents of a work area wa to the

itab2 by adding all the numeric fields with the same key.

Try this.

This defnitly will solve your problem.

Regards

Hareesh.

Former Member
0 Kudos

Hi

here im am assuming that your internal table is not with header line and

the work area is wa1.Create another internal table of the same line type

of the first one(ITAB1).

Now loop through the internal table itab1 .

loop at itab1 into wa1.
COLLECT wa1 INTO itab2.
 endloop.

Now your itab2 eill contains the values as follows

259 jan 00 25 25 66
259 feb 110 11 48 77
259 mar 25 118 104 110
259 apr 40 00 22 45

What this statement does is,it will inserts contents of a work area wa to the

itab2 by adding all the numeric fields with the same key.

Try this.

This defnitly will solve your problem.

Regards

Hareesh.

Former Member
0 Kudos

Hi Ajay,

Try following code.

sort itab by empl_id month exp1 exp2 exp3 exp4.

data: l_itab like itab,

l_exp1 like itab-exp1,

l_exp2 like itab-exp2,

l_exp3 like itab-exp3,

l_exp4 like itab-exp4.

loop at itab.

move itab to l_itab.

l_exp1 = l_exp1 + l_itab-exp1 .

l_exp2 = l_exp2 + l_itab-exp2 .

l_exp3 = l_exp3 + l_itab-exp3 .

l_exp4 = l_exp4 + l_itab-exp4 .

at end of month.

write : \1(10) l_itab-empl_id ,

13(8) l_itab-month ,

24(8) l_exp1 ,

35(8) l_exp1 ,

46(8) l_exp1 ,

57(8) l_exp1 .

****Or populate ITAB2......as per your requirement.....

clear : l_exp1,

l_exp2,

l_exp3,

l_exp4.

endat.

endloop.

Regards,

Anil