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

How can we sum for the field on alv grid

Dear Freinds,

I am having the field count .....in the ouput (iam using alv grid) .......which dispalys the id's which are identical .

i have scneario similar to the below in my ALV Output

ID count total

4000 3 100

100

-


200 Can i get count 3 also along with 200 in alv?

-


i am using the code as follows for count can any one please let me know.

my earlier question which i put was confusing.........so i am givin the qustion again

clear ls_fieldcat.

ls_fieldcat-col_pos = 1.

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 = 2.

ls_fieldcat-fieldname = 'COUNT'.

ls_fieldcat-seltext_l = 'H.Count'.

ls_fieldcat-outputlen = 4.

ls_fieldcat-do_sum = 'X'.

  • ls_fieldcat-datatype = 'NUMC'.

append ls_fieldcat to fp_i_fieldcat.

clear ls_fieldcat.

ls_fieldcat-fieldname = 'TOTAL'.

ls_fieldcat-seltext_m = 'total'.

ls_fieldcat-col_pos = 3.

ls_fieldcat-outputlen = 17.

ls_fieldcat-do_sum = 'X'.

ls_fieldcat-datatype = 'CURR'.

append ls_fieldcat to fp_i_fieldcat.

Please let me know how can do if so what is the parameter i have to change for COUNT

regards

syamal

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 06:14 AM

    it is possable.it can handl manually.

    add last record count value append it into field catalog.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 06:15 AM

    Hi

    If you don't want to do the SUM for the COUNT field in ALv comment the line

    • ls_fieldcat-do_sum = 'X'.

    then the field will not be Summedup

    Regards

    Anji

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Dear Anji Reddy ,

      i wan to do sum, but it is not giving me that is my question...

      inspite of me giving do_sum it is not taking ...........my thinking may be

      iam using the data type a NUM4 ........it is not taking ....

      if dont use NUM4 i cannot count in my logic and display on the screen.

      regards

      syamala

  • Posted on Nov 20, 2007 at 06:20 AM

    Syamala,

    DATA:itsort TYPE slis_t_sortinfo_alv WITH HEADER LINE.

    DATA :itsort1 TYPE slis_sortinfo_alv.

    DATA:itlayout TYPE slis_layout_alv.

    itlayout-no_subtotals = ' '.

    CLEAR itsort.

    itsort1-spos = 10."column position

    itsort1-fieldname = 'LIFNR'."field name

    itsort1-tabname = 'ITFINAL'."internal table

    itsort1-up = 'X'.

    itsort1-subtot = 'X'.

    APPEND itsort1 TO itsort.

    Based on LIFNR it will caluculate the subtotals.

    K.Kiran.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 06:21 AM

    hi,

    the following threads may give answer for your question

    How to sort the required fields in ALV, and calculate the subtotals

    How to do subtotal in CL_GUI_ALV_GRID Class?

    regards,

    pavan

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 06:23 AM

    HI

    we can do manully for this

    by using do_sum we can slove tht one.

    try this one

    ls_fieldcat-do_sum = 'X'.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Dear Santhosh,

      you can see in my code ...

      clear ls_fieldcat.

      ls_fieldcat-col_pos = 2.

      ls_fieldcat-fieldname = 'COUNT'.

      ls_fieldcat-seltext_l = 'H.Count'.

      ls_fieldcat-outputlen = 4.

      ls_fieldcat-do_sum = 'X'. -


      i have already used it since it is Numc it is not taking

      • ls_fieldcat-datatype = 'NUMC'.

      append ls_fieldcat to fp_i_fieldcat.

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 06:24 AM

    Hi

    u can do it in the field catlog.

    eg:

    fieldcatalog-fieldname = 'NETPR'.

    fieldcatalog-seltext_m = 'Net Price'.

    fieldcatalog-col_pos = 7.

    fieldcatalog-outputlen = 15.

    fieldcatalog-do_sum = 'X' "Display column total

    fieldcatalog-datatype = 'CURR'.

    append fieldcatalog to fieldcatalog.

    clear fieldcatalog.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 02:58 PM

    • no_sumchoice

    value set: SPACE, 'X' 'X' = fields which are to be summed, passed by the calling program (FIELDCAT-DO_SUM = 'X'). The user should not be able to change this value interactively.

    • no_totalline

    value set: SPACE, 'X' 'X' = no total record is to be output. Subtotals can still be calculated and output. The fields in the subtotals are flagged DO_SUM = 'X' in the field list.

    • no_subchoice

    value set: SPACE, 'X' 'X' = value whose change triggers subtotals, provided by the calling program. The user should not be able to change this value interactively.

    See also the documentation of the IMPORTING parameter IT_SORT.

    • no_subtotals

    value set: SPACE, 'X' 'X' = no subtotals.

    • totals_only

    value set: SPACE, 'X' 'X' = only total records are output.

    an interactive breakdown of simple and hierarchical-sequential lists is possible. prerequisite: the IMPORTING parameter IT_SORT contains the sort criteria and subtotal flags.

    See also the documentation of the IMPORTING parameter IT_SORT.

    • totals_text

    value set: SPACE, string(max.60) ' ' = the first column in the total record contains an appropriate number of ''s to indicate the total by default. If the first column is wide enough, the string 'Total' is output after the asterisks. 'string' = the string passed is output after the total indicated by '', if the column is wide enough.

    • subtotals_text

    value set: SPACE, string(max.60) ' ' = in the first column of subtotal records, the subtotal is indicated by an appropriate number of '*' by default. If the first column is not a subtotal criterion, the string 'Total' is output after the asterisks, if the column is wide enough.

    'string' = the string passed is output after the subtotal indicated by '*', if the column is wide enough and the first column is not a subtotal criterion.

    If it is a subtotal criterion, its value is repeated after the total, if the column is wide enough.

    • numc_sum

    value set: SPACE, 'X' ' ' = by default NUMC fields cannot be totalled

    'X' = NUMC fields can be totalled. If this flag is set, the total can be controlled via the FIELDCAT-NO_SUM parameter per NUMC column.

    THIS MIGHT BE HELPFUL .

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Fill the fieldcatalog for the field 'COUNT' in the subroutine <b>st_layout_build</b> as

      shown below.

      clear ls_fieldcat.
      ls_fieldcat-col_pos = 2.
      ls_fieldcat-fieldname = 'COUNT'.
      ls_fieldcat-seltext_l = 'H.Count'.
      ls_fieldcat-outputlen = 4.
      ls_fieldcat-do_sum = 'X'.
      ls_fieldcat-datatype = 'INT4'.
      append ls_fieldcat to fp_i_fieldcat.

  • author's profile photo Former Member
    Former Member
    Posted on Nov 21, 2007 at 06:13 AM

    Hi Shamala Kiran.

    My name is also kiran.I have a develop a code for u.Actually i cant understand your code.But i know ur problem .Plz check that code.In that code i develop a subtotals and grandttotal.Plz observe the FORM "FIELD CATALOG" in that observe the NETWR FIELD and observe the FORM SORTCATALOG then ur problem will be solved.

    Copy the the below code and execute that code and the result.

    If u r Satisfied with the answer plz give the REWARD POINTS.

    CODE:

    ----


    • Type Pools

    ----


    TYPE-POOLS:slis.

    ----


    • Tables

    ----


    TABLES: vbak,vbap.

    ----


    • Global Variable

    ----


    data: w_var type i.

    ----


    • Global Data

    ----


    DATA:it_fieldcat TYPE slis_t_fieldcat_alv,

    wa_fieldcat TYPE slis_fieldcat_alv,

    it_sortcat TYPE slis_t_sortinfo_alv,

    wa_sortcat LIKE LINE OF it_sortcat.

    ----


    • Internal Table

    ----


    data: BEGIN OF it_salesorder OCCURS 0,

    vbeln LIKE vbak-vbeln, " Sales Document Number

    posnr like vbap-posnr, " Sales Doc Item

    netwr like vbap-netwr, " Net Value

    END OF it_salesorder.

    ----


    • SELECT OPTIONS

    ----


    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

    SELECT-OPTIONS: s_vbeln FOR vbak-vbeln. " Sales Document Number.

    SELECTION-SCREEN END OF BLOCK b1.

    ----


    • Initialization

    ----


    INITIALIZATION.

    PERFORM initialization.

    &----


    *& Form initialization

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form initialization .

    s_vbeln-sign = 'I'.

    s_vbeln-option = 'BT'.

    s_vbeln-low = '4969'.

    s_vbeln-high = '5000'.

    APPEND s_vbeln.

    endform. " initialization

    ----


    • Start Of Selection

    ----


    START-OF-SELECTION.

    PERFORM field_catalog. "For Structure Creation

    PERFORM fetch_data. "Get the Data From DB Table

    PERFORM sorting USING it_sortcat.

    ----


    • End Of Selection

    ----


    END-OF-SELECTION.

    perform display_data.

    &----


    *& Form field_catalog

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form field_catalog .

    wa_fieldcat-col_pos = w_var. " Column Position Variable

    wa_fieldcat-tabname = 'IT_SALESORDER'. " Internal Table Name

    wa_fieldcat-fieldname = 'VBELN'. " Field Name

    wa_fieldcat-key = 'X'. " Blue Color

    wa_fieldcat-ref_tabname = 'VBAK'. " Table Name

    wa_fieldcat-ref_fieldname = 'VBELN'. " Field Name

    wa_fieldcat-seltext_m = 'Sales Doc No'. " Display Text In Screen

    APPEND wa_fieldcat TO it_fieldcat.

    CLEAR wa_fieldcat.

    ADD 1 TO w_var.

    wa_fieldcat-col_pos = w_var. " Column Position Variable

    wa_fieldcat-tabname = 'IT_SALESORDER'. " Internal Table Name

    wa_fieldcat-fieldname = 'POSNR'. " Field Name

    wa_fieldcat-ref_tabname = 'VBAP'. " Table Name

    wa_fieldcat-ref_fieldname = 'POSNR'. " Field Name

    wa_fieldcat-seltext_m = 'Sales Doc Item'. " Display Text In Screen

    APPEND wa_fieldcat TO it_fieldcat.

    CLEAR wa_fieldcat.

    ADD 1 TO w_var.

    wa_fieldcat-col_pos = w_var. " Column Position Variable

    wa_fieldcat-tabname = 'IT_SALESORDER'. " Internal Table Name

    wa_fieldcat-fieldname = 'NETWR'. " Field Name

    wa_fieldcat-ref_tabname = 'VBAP'. " Table Name

    wa_fieldcat-ref_fieldname = 'NETWR'. " Field Name

    wa_fieldcat-do_sum = 'X'. " Sum

    wa_fieldcat-seltext_m = 'Net Value'. " Display Text In Screen

    APPEND wa_fieldcat TO it_fieldcat.

    CLEAR wa_fieldcat.

    ADD 1 TO w_var.

    endform. " field_catalog

    &----


    *& Form sorting

    &----


    • text

    ----


    • -->P_IT_SORTCAT text

    ----


    form sorting using p_it_sortcat TYPE slis_t_sortinfo_alv.

    wa_sortcat-fieldname = 'VBELN'.

    wa_sortcat-up ='X'.

    wa_sortcat-subtot = 'X'.

    APPEND wa_sortcat TO p_it_sortcat.

    endform. " sorting

    &----


    *& Form display_data

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form display_data .

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    • I_INTERFACE_CHECK = ' '

    • I_BYPASSING_BUFFER = ' '

    • I_BUFFER_ACTIVE = ' '

    I_CALLBACK_PROGRAM = SY-REPID

    • I_CALLBACK_PF_STATUS_SET = ' '

    • I_CALLBACK_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 =

    IT_FIELDCAT = it_fieldcat

    • IT_EXCLUDING =

    • IT_SPECIAL_GROUPS =

    IT_SORT = it_sortcat

    • IT_FILTER =

    • IS_SEL_HIDE =

    • I_DEFAULT = 'X'

    • I_SAVE = ' '

    • IS_VARIANT =

    • IT_EVENTS =

    • IT_EVENT_EXIT =

    • IS_PRINT =

    • IS_REPREP_ID =

    • I_SCREEN_START_COLUMN = 0

    • I_SCREEN_START_LINE = 0

    • I_SCREEN_END_COLUMN = 0

    • I_SCREEN_END_LINE = 0

    • IT_ALV_GRAPHICS =

    • IT_HYPERLINK =

    • IT_ADD_FIELDCAT =

    • IT_EXCEPT_QINFO =

    • I_HTML_HEIGHT_TOP =

    • I_HTML_HEIGHT_END =

    • IMPORTING

    • E_EXIT_CAUSED_BY_CALLER =

    • ES_EXIT_CAUSED_BY_USER =

    TABLES

    t_outtab = it_salesorder

    EXCEPTIONS

    PROGRAM_ERROR = 1

    OTHERS = 2

    .

    IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    endform. " display_data

    &----


    *& Form fetch_data

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form fetch_data .

    select a~vbeln

    posnr

    b~netwr

    from vbak as a

    inner join vbap as b on avbeln = bvbeln

    into table it_salesorder

    where a~vbeln in s_vbeln.

    endform. " fetch_data

    -


    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.