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

Help me!

Former Member
0 Likes
1,125

Hi,

Can someone give me the coding for my requirement,

I've got to sum a field were in i have different sales offices with different amount.I've tried up with collect and with at new and at end of statements but seems to be getting a different results but cant get what i want.

this is my coding

SELECT settle_guid

settle_date

settle_perio

vkorg

vkbur

vkgrp

pernr

parvw

val_type

val_base

settle_type

amount FROM zcms_com_settle INTO TABLE t_zcms_com_settle

WHERE settle_perio IN s_perio

AND vkbur IN s_vkbur

AND pernr IN s_pernr.

SORT t_zcms_com_settle BY vkbur settle_type.

APPEND LINES OF t_zcms_com_settle TO t_temp_zcms_com_settle.

DELETE t_temp_zcms_com_settle WHERE NOT settle_type = 'REV'.

LOOP AT t_temp_zcms_com_settle.

AT NEW vkbur.

t_temp_zcms_com_settle-amount = 0.

ENDAT.

AT END OF vkbur.

SUM.

ENDAT.

t_output_summary-vkbur = t_temp_zcms_com_settle-vkbur.

t_output_summary-total_revenue = t_temp_zcms_com_settle-amount.

APPEND t_output_summary.

ENDLOOP.

i have a table with this fields

vkbur personel_no vkgrp amount

5000 121333 0033 1

5000 23456 0023 1

6000 23456 0033 1

6000 3456 0023 1

and my output tables fields are and the result shud be

vkbur amout

5000 2

6000 2

this is the requirement but it seems to be troubling me with lots of fields in my table and its not getting summed up.

Can any one give me the coding so that i can get the output as above or is there any coding which sums up and exits after every new sales office so that i can append it individually and then contiunes the loops for different sales office sum it and append it into the output field to get the requirement.Please somebody help me out of this.Points would be surely rewarded.........

Thanks in advance

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,100

Hi!

Try out this way.



SORT t_temp_zcms_com_settle.   "<<< sort your internal table
LOOP AT t_temp_zcms_com_settle.
  AT NEW vkbur.
    t_temp_zcms_com_settle-amount = 0.
  ENDAT.
  AT END OF vkbur.
    SUM.
* move the collecting between the AT...ENDAT
    t_output_summary-vkbur = t_temp_zcms_com_settle-vkbur.
    t_output_summary-total_revenue = t_temp_zcms_com_settle-amount.
    APPEND t_output_summary.
  ENDAT.
ENDLOOP.

Regards

Tamá

8 REPLIES 8
Read only

Former Member
0 Likes
1,101

Hi!

Try out this way.



SORT t_temp_zcms_com_settle.   "<<< sort your internal table
LOOP AT t_temp_zcms_com_settle.
  AT NEW vkbur.
    t_temp_zcms_com_settle-amount = 0.
  ENDAT.
  AT END OF vkbur.
    SUM.
* move the collecting between the AT...ENDAT
    t_output_summary-vkbur = t_temp_zcms_com_settle-vkbur.
    t_output_summary-total_revenue = t_temp_zcms_com_settle-amount.
    APPEND t_output_summary.
  ENDAT.
ENDLOOP.

Regards

Tamá

Read only

0 Likes
1,100

Thx u soooo much Tamas it was really nice of u i made a mistake of not taking the vkbur as the first field and misplaced the endat statement its really working fine.......Thanks soooooo much

Read only

alex_m
Active Contributor
0 Likes
1,100

LOOP AT t_temp_zcms_com_settle.

AT END OF vkbur.

SUM.

t_output_summary-vkbur = t_temp_zcms_com_settle-vkbur.

t_output_summary-total_revenue = t_temp_zcms_com_settle-amount.

APPEND t_output_summary.

ENDAT.

ENDLOOP.

Read only

Former Member
0 Likes
1,100

Hi Younus,

Your code will work fine if you make VKBUR as the first field of the internal table t_zcms_com_settle and sort table by VKBUR.

At new commands gets triggered if any one of the previous field values get changed. In this case as you have settle_guid settle_date settle_perio vkorg before the sales office field VKBUR hence if any one of the values for these (settle_guid settle_date settle_perio vkorg) it will do the total. Due to this you are getting the wrong results and both At new and At end of will work properly.

Please do the change and let me know the result.

Reward if helpful.

Regards,

Shahu

Read only

0 Likes
1,100

Thax dude this was the cheeky mistake i've done and was going through hell.Thanx soooooooooooooo much dude i've alloted points for that.....hope u guy will keep helping me like the same way in future.........

Read only

former_member187255
Active Contributor
0 Likes
1,100

Change the structure of the Internal table <b>t_zcms_com_settle</b>

<b>VKBUR</b> should be the first field in the internal table.....

Read only

former_member378318
Contributor
0 Likes
1,100

Try this

TYPES: BEGIN OF t_output_summary,

vkbur TYPE zcms_com_settle-vkbur,

total_revenue TYPE zcms_com_settle-amount,

END OF t_output_summary.

DATA: t_output_summary TYPE STANDARD TABLE OF t_output_summary

WITH HEADER LINE.

SELECT settle_guid

settle_date

settle_perio

vkorg

vkbur

vkgrp

pernr

parvw

val_type

val_base

settle_type

amount FROM zcms_com_settle INTO TABLE t_zcms_com_settle

WHERE settle_perio IN s_perio

AND vkbur IN s_vkbur

AND pernr IN s_pernr.

LOOP AT t_zcms_com_settle.

t_output_summary-vkbur = t_zcms_com_settle-vkbur.

t_output_summary-total_revenue = t_zcms_com_settle-amount.

COLLECT t_output_summary.

ENDLOOP.

Read only

Former Member
0 Likes
1,100

Make VKBUR as the first field of internal table t_zcms_com_settle.

sort table internal table by VKBUR.

if solved close the thread awarding points as such so that it will be useful that the thread is closed and no one else will open the same...