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 internal table lines

Former Member
0 Kudos

Hi,

I have this situation:

itab1: bukrs hkont kosar gjahr monat actual plan

........ bukrs hkont kosar gjahr 01 actual plan

........ bukrs hkont kosar gjahr 02 actual plan

........ bukrs hkont kosar gjahr 03 actual plan

itab2: bukrs kosar mactual mplan ytdactual ytdplan

Say monat = 3, I need to get mactual, mplan, ytdactual, ytdplan from itab1.

mactual, mplan would be the record where monat = 03.

ytdactual, ytdplan would be the sum of mactual, mplan for monat 01 to 03.

How do i do this? Sample code will be really helpful.

Thanks.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi MJay,

If I got it right this time, u have a parameter and give the month there...

hope this is what u need..

PARAMETER monat(2) type c.

data: tmp like itab1-plan,

tmp2 like itab1-actual.

loop at itab1 INTO wa_itab1.

tmp = tmp + wa_itab1-actual.

tmp2 = tmp2 + wa_itab1-plan.

if wa_itab1-monat = monat.

wa_itab2-bukrs = wa_itab1-bukrs.

wa_itab2-mactual = wa_itab1-actual.

wa_itab2-mplan = wa_itab1-plan.

wa_itab2-ytdactual = tmp.

wa_itab2-ytdplan = tmp2.

COLLECT wa_itab2 into itab2.

endif.

CHECK wa_itab1-monat = monat.

endloop.

reward if helpful...

Regards,

Alin

3 REPLIES 3

Former Member
0 Kudos

Hi, if i get u right this is what u want:

DATA: wa_itab1 like LINE OF itab1,

wa_itab2 like LINE OF itab2,

tmp like itab1-plan,

tmp2 like itab1-actual.

loop at itab1 INTO wa_itab1.

wa_itab2-bukrs = wa_itab1-bukrs.

.

.

.

wa_itab2-mactual = wa_itab1-actual.

wa_itab2-mplan = wa_itab1-plan.

tmp = tmp + wa_itab2-mactual.

wa_itab2-ytdactual = tmp.

tmp2 = tmp2 + wa_itab2-mplan.

wa_itab2-ytdplan = tmp2.

COLLECT wa_itab2 into itab2.

endloop.

Reward if helpful.

Regards,

Alin.

0 Kudos

Alin,

I think I should have been a little more clearer.

The monat field can have values from 01 to 12 and hence 12 records in the internal table.

When my monat selection is say monat = '06', I need to get the mactual mplan for monat = 06

and then sum up all the mactual mplan from 01 to 06.

Thanks,

MJ

Former Member
0 Kudos

Hi MJay,

If I got it right this time, u have a parameter and give the month there...

hope this is what u need..

PARAMETER monat(2) type c.

data: tmp like itab1-plan,

tmp2 like itab1-actual.

loop at itab1 INTO wa_itab1.

tmp = tmp + wa_itab1-actual.

tmp2 = tmp2 + wa_itab1-plan.

if wa_itab1-monat = monat.

wa_itab2-bukrs = wa_itab1-bukrs.

wa_itab2-mactual = wa_itab1-actual.

wa_itab2-mplan = wa_itab1-plan.

wa_itab2-ytdactual = tmp.

wa_itab2-ytdplan = tmp2.

COLLECT wa_itab2 into itab2.

endif.

CHECK wa_itab1-monat = monat.

endloop.

reward if helpful...

Regards,

Alin