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: 

output in alv -- sum on the particular field

Former Member
0 Kudos

Dear Freinds,

I have developed a report using a ALV grid . The output i having the fields

as

orgunit orgdesc count name salary total salary.

1234 test1 raja 100 1200

2 rama 200 2400

-


300 3600 -> i want count 2 in this line

-


1235 test 2 1 rana 500 6000

-


500 6000 -> i want count 1 in this line

-


Can i give the Count 1 and 2 in the same row where the Totals --- 500 and 6000

and 300 and 3600 are being displayed int he above row ?

the user says he want to have the count in the down along witht he total's lline

the count is not a now a currency field i tried to sum it is not summing because it is

NUM data type.

As per the above data(sample data) we can see that Orgunit(1234) is having two employees hence the count was two . For the Orgunit(1235) we have only one employee the count was only one . Nowe my question is can i give the counts 2 in the first row and the count 1 in the second rown can give along with the total.........line ...

if so what i can do the change in the field cat.

When iam using in my field cat for getting the output as above

CLEAR ls_fieldcat.

ls_fieldcat-col_pos = 0.

ls_fieldcat-fieldname = 'ORGUNIT'.

ls_fieldcat-seltext_l = text-015. "'Orgunit'.

ls_fieldcat-key = 'X'.

ls_fieldcat-key_sel = 'X'.

  • ls_fieldcat-no_out = 'X'.

APPEND ls_fieldcat TO fp_i_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-col_pos = 1.

ls_fieldcat-fieldname = 'ORGTEXT'.

ls_fieldcat-seltext_l = text-016. "'Orgdesc'.

  • ls_fieldcat-no_out = 'X'.

APPEND ls_fieldcat TO fp_i_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-col_pos = 2.

ls_fieldcat-fieldname = 'COUNT'. ---This is data type Numc

ls_fieldcat-seltext_l = 'H.Count'.

ls_fieldcat-outputlen = 4.

ls_fieldcat-do_sum = 'X'. -


> it is not getting summed up

  • ls_fieldcat-datatype = 'NUMC'.

APPEND ls_fieldcat TO fp_i_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-col_pos = 3.

ls_fieldcat-fieldname = 'STAFFNAME'.

  • ls_fieldcat-no_out = 'X'.

ls_fieldcat-seltext_l = 'Name'.

APPEND ls_fieldcat TO fp_i_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = 'SALARY'.

ls_fieldcat-seltext_m = 'Salary'.

ls_fieldcat-col_pos = 4.

ls_fieldcat-outputlen = 17.

ls_fieldcat-do_sum = 'X'.

ls_fieldcat-datatype = 'CURR'.

APPEND ls_fieldcat TO fp_i_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = 'TOTAL'.

ls_fieldcat-seltext_m = 'Total Salary'.

ls_fieldcat-col_pos = 5.

ls_fieldcat-outputlen = 17.

ls_fieldcat-do_sum = 'X'.

ls_fieldcat-datatype = 'CURR'.

APPEND ls_fieldcat TO fp_i_fieldcat.

3 REPLIES 3

kiran_k8
Active Contributor
0 Kudos

Syamala,

ALV report has a feature of caluculating subtotals.All you have to do is once you get the output select the filed based on which you wanna caluculate the subtotals and then click on SUBTOTALS button and then select the field which needs to sbutotaled and then click on AGGREGATION button in the ALV tool bar.Both these SUBTOTALS and AGGREGRATION buttons you can find in the ALV tool bar.

K.Kiran.

Former Member
0 Kudos

Dear Kiran,

iam seding the alv output which i got can you please correct my code

where i can give .........since my basic question was the Count which iam

getting in the below is 2 (data type NUM4) how can i do sum on this 2 or subtotal??

i want the count 2 to come in the total....line only ..can you please let me know what is the parameter i have to use ........i couldnt find the

Aggregation in my tool bar...

orgunit orgdesc count name salary total salary.

12345 test raja 100

space space 2 rama 200

-


300 -> i want count 2 in this line

-


1235 test 2 1 rana 500

-


500 6000 -> i want count 1 in this line

-


Can i give the Count 1 and 2 in the same row where the Totals --- 500 and 6000

and 300 and 3600 are being displayed int he above row ?

the user says he want to have the count in the down along witht he total's lline

the count is not a now a currency field i tried to sum it is not summing because it is

NUM data type.

As per the above data(sample data) we can see that Orgunit(1234) is having two employees hence the count was two . For the Orgunit(1235) we have only one employee the count was only one . Nowe my question is can i give the counts 2 in the first row and the count 1 in the second rown can give along with the total.........line ...

if so what i can do the change in the field cat.

When iam using in my field cat for getting the output as above

CLEAR ls_fieldcat.

ls_fieldcat-col_pos = 0.

ls_fieldcat-fieldname = 'ORGUNIT'.

ls_fieldcat-seltext_l = text-015. "'Orgunit'.

ls_fieldcat-key = 'X'.

ls_fieldcat-key_sel = 'X'.

  • ls_fieldcat-no_out = 'X'.

APPEND ls_fieldcat TO fp_i_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-col_pos = 1.

ls_fieldcat-fieldname = 'ORGTEXT'.

ls_fieldcat-seltext_l = text-016. "'Orgdesc'.

  • ls_fieldcat-no_out = 'X'.

APPEND ls_fieldcat TO fp_i_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-col_pos = 2.

ls_fieldcat-fieldname = 'COUNT'. ---This is data type Numc

ls_fieldcat-seltext_l = 'H.Count'.

ls_fieldcat-outputlen = 4.

ls_fieldcat-do_sum = 'X'. -


> it is not getting summed up

  • ls_fieldcat-datatype = 'NUMC'.

APPEND ls_fieldcat TO fp_i_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-col_pos = 3.

ls_fieldcat-fieldname = 'STAFFNAME'.

  • ls_fieldcat-no_out = 'X'.

ls_fieldcat-seltext_l = 'Name'.

APPEND ls_fieldcat TO fp_i_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = 'SALARY'.

ls_fieldcat-seltext_m = 'Salary'.

ls_fieldcat-col_pos = 4.

ls_fieldcat-outputlen = 17.

ls_fieldcat-do_sum = 'X'.

ls_fieldcat-datatype = 'CURR'.

APPEND ls_fieldcat TO fp_i_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = 'TOTAL'.

ls_fieldcat-seltext_m = 'Total Salary'.

ls_fieldcat-col_pos = 5.

ls_fieldcat-outputlen = 17.

ls_fieldcat-do_sum = 'X'.

ls_fieldcat-datatype = 'CURR'.

APPEND ls_fieldcat TO fp_i_fieldcat.

Former Member
0 Kudos

Hi

Use the get_subtotal method of class cl_gui_alv_grid to calculate the sub total of the required field.

CALL METHOD .

Thanks

Vijay

PLZ reward points if helpful