2013 Jan 29 6:18 PM
Hi experts,
What is the more convenient abap syntax to code this requirement?
What I want to do is to transfer the sold of the last year concerning an account to the current year if the key is similar of course
Example:
Account | Field A | Field B | Year | Amount |
AAAA | TEST | ABC | 2012 | 100 |
AAAA | XXX | ABC | 2012 | 150 |
AAAA | TEST | ABC | 2012 | 300 |
AAAA | TEST | ABC | 2013 | 200 |
As you can see, line 1 and 3 of my example have the same key (in green)
So what I want to do is to calculate the summation of field Amount and report it in the next year which gives:
Summation:
Account | Field A | Field B | Year | Amount |
AAAA | TEST | ABC | 2012 | 100 |
AAAA | TEST | ABC | 2012 | 300 |
AAAA | TEST | ABC | 2012 | 400 |
Report on next year:
Account | Field A | Field B | Year | Amount |
AAAA | TEST | ABC | 2013 | 200 |
AAAA | TEST | ABC | 2012 | 400 |
AAAA | TEST | ABC | 2013 | 600 |
If not clear I can develop more.
Thanks for your help.
Amine
Message was edited by: Kesavadas Thekkillath
Hi experts,
What is the more convenient abap syntax to code this requirement?
What I want to do is to transfer the sold of the last year concerning an account to the current year if the key is similar of course
Example:
Account | Field A | Field B | Year | Amount |
AAAA | TEST | ABC | 2012 | 100 |
AAAA | XXX | ABC | 2012 | 150 |
AAAA | TEST | ABC | 2012 | 300 |
AAAA | TEST | ABC | 2013 | 200 |
As you can see, line 1 and 3 of my example have the same key (in green)
So what I want to do is to calculate the summation of field Amount and report it in the next year which gives:
Summation:
Account | Field A | Field B | Year | Amount |
AAAA | TEST | ABC | 2012 | 100 |
AAAA | TEST | ABC | 2012 | 300 |
AAAA | TEST | ABC | 2012 | 400 |
Report on next year:
Account | Field A | Field B | Year | Amount |
AAAA | TEST | ABC | 2013 | 200 |
AAAA | TEST | ABC | 2012 | 400 |
AAAA | TEST | ABC | 2013 | 600 |
If not clear I can develop more.
Thanks for your help.
Amine
Message was edited by: Kesavadas Thekkillath
2013 Jan 29 6:37 PM
Hi Amine,
After you get all the data in internal table, you can sort the internal table on the key fields.
SORT itab STABLE ASCENDING BY Account FieldA FieldB Year.
Then you can loop on itab and sum up the values at end of Year.
LOOP AT itab INTO wa.
w_total = w_total + wa-amount.
AT END OF year.
wa_output-account = wa-account.
wa_output-fielda = wa-fielda.
wa_output-fieldb = wa-fieldb.
wa_output-year = wa-year.
wa_output-amount = w_total.
APPEND wa_output TI i_output.
CLEAR : wa, wa_output,w_total.
ENDAT.
ENDLOOP.
2013 Jan 29 6:38 PM
Hi,
I am not clear with the statement "report it in the next year ". But if you just want to sum the amount for the same key fields you can use COLLECT statement on your internal table.
thanks.
2013 Jan 29 6:43 PM
Hi Ashwatha,
Using COLLECT is a good option but i presume collect statement sums up the contents of all the numeric fields and GJAHR i.e year is a numeric field. Please correct me if i am wrong
2013 Jan 29 6:57 PM
Yes gjahr is a numeric field but it is also a key field. For collect to work all the fields except fields belonging to table key must be of numeric type. Please refer to collect statement in this site.
http://help.sap.com/saphelp_nw04/Helpdata/EN/fc/eb36d5358411d1829f0000e829fbfe/content.htm
2013 Jan 29 7:01 PM
Hi Aswatha,
Thanx for the clarification
Maybe i wasn't able to remember the syntax properly
2013 Jan 29 7:16 PM
you are welcome.......... have you got the soln or you are trying with collect?
2013 Jan 30 4:27 AM
Hi Aswatha,
I am not the owner of the thread. I am just trying to help(as you are)
2013 Jan 30 4:33 AM
Hi Aniket,
Sorry i didn't check the name in full thread as i typed this in communications.
thanks.
2013 Jan 30 9:16 AM
Hi,
Thanks to both of you for your helpfull answers.
I am not sure if i can use collect statement, because the key will be different for the next year-->the year changes.
Could you clarify to me how to use it?
Thanks.
Amine
2013 Jan 30 9:27 AM
Can you please explain little more on your requirement as it is little confusing? you are adding amount for 2012 and in SUMMATION table its fine. Now what you are doing in the next year table?
2013 Jan 30 9:36 AM
What i would like to do is for some accounts.
Calculate the sum of the previous year and add it to the same account for the current year.
It's in accounting like balance carried forward
E.G:
2012 the total was 10.
2013 the total is 30.
I want the total of 2013 : 30 + 10 = 40
Thanks.
Amine