Application Development and Automation 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: 
Read only

Abap Syntax for a requirment

Former Member
0 Likes
1,451

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

Moderator Message:The SCN is not a forum for ordering free technical consulting. It is a collaborative community where people voluntarily help you to understand things better in the SAP world. Please try to avoid the impression of requirement dumping. I recommend to read the useful Blog "Asking Good Questions in the SCN Discussion Spaces will help you get Good Answers"  and next and first learn the principles of this before asking any more question. Thank you for taking time to understand community help.

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

Moderator Message:The SCN is not a forum for ordering free technical consulting. It is a collaborative community where people voluntarily help you to understand things better in the SAP world. Please try to avoid the impression of requirement dumping. I recommend to read the useful Blog "Asking Good Questions in the SCN Discussion Spaces will help you get Good Answers"  and next and first learn the principles of this before asking any more question. Thank you for taking time to understand community help.

Message was edited by: Kesavadas Thekkillath

11 REPLIES 11
Read only

former_member491621
Contributor
0 Likes
1,416

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.

Read only

Former Member
0 Likes
1,416

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.

Read only

0 Likes
1,416

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

Read only

0 Likes
1,416

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

Read only

0 Likes
1,416

Hi Aswatha,

Thanx for the clarification

Maybe i wasn't able to remember the syntax properly

Read only

0 Likes
1,416

you are welcome.......... have you got the soln or you are trying with collect?

Read only

0 Likes
1,416

Hi Aswatha,

I am not the owner of the thread. I am just trying to help(as you are)

Read only

0 Likes
1,416

Hi Aniket,

Sorry i didn't check the name in full thread as i typed this in communications.

thanks.

Read only

0 Likes
1,416

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

Read only

0 Likes
1,416

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?

Read only

0 Likes
1,416

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