Skip to Content
author's profile photo Former Member
Former Member

Subtotal in ALV display

Hi Friends,

I have a development where i have to first do a sub total and at the end a total of all values. I have used DO_SUM for the total of all values in a column.

I have also used SUB_TOT but facing some problem.

My requirement is to display a sub-total on change of Policy Nu and the total of all at the end.

As you can see, the values of Open Amount Column is added to Calculation B columns, which should not be.

Please help me to achieve the below mentioned tasks.

1. How to remove the sub total after every row? The subtotal should only be displayed at the change of Policy Nu.

2. How to stop adding values of first column to 2nd column?

Here is the sample code.

***Open Amount(DMSHB)

CLEAR wa_fieldcatalog.

wa_fieldcatalog-col_pos = 7.

wa_fieldcatalog-fieldname = text-013.

wa_fieldcatalog-outputlen = 15.

wa_fieldcatalog-seltext_m = text-014.

wa_fieldcatalog-do_sum = 'X'.

APPEND wa_fieldcatalog TO fieldcatalog.

***Calculation Based(AMONT)

CLEAR wa_fieldcatalog.

wa_fieldcatalog-col_pos = 8.

wa_fieldcatalog-fieldname = text-015.

wa_fieldcatalog-outputlen = 13.

wa_fieldcatalog-seltext_m = text-016.

wa_fieldcatalog-do_sum = 'X'.

APPEND wa_fieldcatalog TO fieldcatalog.

***Deductibles(VRSRP)

CLEAR wa_fieldcatalog.

wa_fieldcatalog-col_pos = 9.

wa_fieldcatalog-fieldname = text-017.

wa_fieldcatalog-outputlen = 03.

wa_fieldcatalog-seltext_m = text-018.

APPEND wa_fieldcatalog TO fieldcatalog.

SORT it_final ASCENDING BY vrsnr .

CLEAR wa_sort.

wa_sort-fieldname = text-003.

wa_sort-tabname = 'IT_FINAL'.

wa_sort-up = 'X'.

wa_sort-group = '*'.

APPEND wa_sort TO it_sort.

CLEAR wa_sort.

wa_sort-fieldname = text-013.

wa_sort-tabname = 'IT_FINAL'.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO it_sort.

CLEAR wa_sort.

wa_sort-fieldname = text-015.

wa_sort-tabname = 'IT_FINAL'.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO it_sort.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = 'ZFIAR_CREINS_PREM_REPORT'

i_callback_user_command = 'USER COMMAND'

i_callback_top_of_page = 'TOP_OF_PAGE'

it_fieldcat = fieldcatalog[]

* i_default = 'X'

i_save = 'X'

* it_events = i_events

* it_event_exit = i_ex

it_sort = it_sort[]

TABLES

t_outtab = it_final[]

EXCEPTIONS

program_error = 1

OTHERS = 2.

Thanks in Advance,

Prakhar Singh Chandel

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2014 at 02:39 PM

    Thanks Everyone for response, i have solved this issue.

    I have to provide the field name for which i want the subtotal. Like i want the subtotal on change of Policy Number so i have to add sub_tot field where Policy Number is filled in it_sort.

    So the sample code would be like this.

    ***Open Amount(DMSHB)

    CLEAR wa_fieldcatalog.

    wa_fieldcatalog-col_pos = 7.

    wa_fieldcatalog-fieldname = text-013.

    wa_fieldcatalog-outputlen = 15.

    wa_fieldcatalog-seltext_m = text-014.

    wa_fieldcatalog-do_sum = 'X'.

    APPEND wa_fieldcatalog TO fieldcatalog.

    ***Calculation Based(AMONT)

    CLEAR wa_fieldcatalog.

    wa_fieldcatalog-col_pos = 8.

    wa_fieldcatalog-fieldname = text-015.

    wa_fieldcatalog-outputlen = 13.

    wa_fieldcatalog-seltext_m = text-016.

    wa_fieldcatalog-do_sum = 'X'.

    APPEND wa_fieldcatalog TO fieldcatalog.

    ***Deductibles(VRSRP)

    CLEAR wa_fieldcatalog.

    wa_fieldcatalog-col_pos = 9.

    wa_fieldcatalog-fieldname = text-017.

    wa_fieldcatalog-outputlen = 03.

    wa_fieldcatalog-seltext_m = text-018.

    APPEND wa_fieldcatalog TO fieldcatalog.

    SORT it_final ASCENDING BY vrsnr .

    CLEAR wa_sort.

    wa_sort-fieldname = text-003.

    wa_sort-tabname = 'IT_FINAL'.

    wa_sort-up = 'X'.

    wa_sort-group = '*'.

    wa_sort-sub_tot = 'X'

    APPEND wa_sort TO it_sort.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_callback_program = 'ZFIAR_CREINS_PREM_REPORT'

    i_callback_user_command = 'USER COMMAND'

    i_callback_top_of_page = 'TOP_OF_PAGE'

    it_fieldcat = fieldcatalog[]

    * i_default = 'X'

    i_save = 'X'

    * it_events = i_events

    * it_event_exit = i_ex

    it_sort = it_sort[]

    TABLES

    t_outtab = it_final[]

    EXCEPTIONS

    program_error = 1

    OTHERS = 2.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 07, 2014 at 12:54 PM

    Hi Prakhar,

    please see these code snippet, and change it according to your use,in place of col_pos

    please write the no of colomn position, for which you wants its sum, it will do exactly

    you need., first declare this T_FIELDCAT as shown below.

    DATA : T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

    DATA : WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

    FORM INSERT_FIELD USING VALUE(P_FNAME)

    VALUE(P_TNAME)

    VALUE(P_KEY)

    VALUE(P_LENGTH).

    DATA : WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

    V_COUNTER = V_COUNTER + 1.

    WA_FIELDCAT-COL_POS = V_COUNTER.

    WA_FIELDCAT-FIELDNAME = P_FNAME.

    WA_FIELDCAT-SELTEXT_M = P_TNAME.

    WA_FIELDCAT-KEY = P_KEY.

    WA_FIELDCAT-OUTPUTLEN = P_LENGTH.

    IF WA_FIELDCAT-COL_POS = 7

    OR WA_FIELDCAT-COL_POS = 13

    OR WA_FIELDCAT-COL_POS = 14

    OR WA_FIELDCAT-COL_POS = 15.

    * OR WA_FIELDCAT-COL_POS = 24.

    WA_FIELDCAT-DO_SUM = 'X'.

    ENDIF.

    APPEND WA_FIELDCAT TO T_FIELDCAT.

    ENDFORM.


    And then pass this T_FIELDCAT TO REUSE_ALV_GRID_DISPLAY as



    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    * I_INTERFACE_CHECK = ' '

    * I_BYPASSING_BUFFER = ' '

    * I_BUFFER_ACTIVE = ' '

    I_CALLBACK_PROGRAM = V_REPID

    * I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'

    I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

    * I_CALLBACK_TOP_OF_PAGE = ' '

    * I_CALLBACK_HTML_TOP_OF_PAGE = ' '

    * I_CALLBACK_HTML_END_OF_LIST = ' '

    * I_STRUCTURE_NAME =

    * I_BACKGROUND_ID = ' '

    * I_GRID_TITLE =

    * I_GRID_SETTINGS =

    IS_LAYOUT = S_LAYOUT

    IT_FIELDCAT = T_FIELDCAT[]

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 07, 2014 at 12:45 PM

    Hi,

    use control break statements inside the loop then you get sub totals as well as total as per your requirement.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.