Skip to Content

Unable to sum up column in ABAP

Dear all,

i am using structure LVC_S_LAYO.

Here in my toolbar some icons like show next,summation are inactive.

Also i am using LVC_T_FCAT where i have set DO_SUM = 'X'.

When i see in debugging the value X is getting passed from my it_fieldcatalog table but still

the sum of the desired column is not displayed.what must be the problem?

Why are these icons inactive in the toolbar.?What should i do to Activate them?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

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

    for doing sum based on customer no( in your case).declare one internal table of type slis_t_sortinfo_alv and one work area and there is a parameter subtot pass X to that no and spos = '1'.

    fieldname = 'KUNNR'.

    tabname = 'LT_KNA1'.(internal table)

    UP = 'X'.

    subtot = 'X'.

    your requirment is full filled.

    i am sending the sample code for this but here i am doing based on the VBELN.

    TYPE-POOLS: slis.
     
    TYPES: BEGIN OF tw_vbap,
    vbeln TYPE vbeln,
    posnr TYPE posnr,
    matnr TYPE matnr,
    ernam TYPE ernam,
    netwr TYPE netwr,
          END OF tw_vbap,
    tt_vbap TYPE STANDARD TABLE OF tw_vbap.
     
     
     
    DATA: lf_vbeln TYPE vbeln,
          lw_vbap TYPE tw_vbap,
          lt_vbap TYPE tt_vbap,
          lt_fieldcat TYPE slis_t_fieldcat_alv,
          lw_fieldcat LIKE LINE OF lt_fieldcat,
          lt_sort TYPE slis_t_sortinfo_alv,
          lw_sort LIKE LINE OF lt_sort.
    *types: tt_layo type table of SLIS_LAYOUT_ALV.
    DATA: lw_layo TYPE slis_layout_alv,
     
          lt_layo TYPE STANDARD TABLE OF  slis_layout_alv,
          lt_header TYPE slis_t_listheader,
          lw_header LIKE LINE OF lt_header.
     
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.
    SELECT-OPTIONS: so_vbeln FOR lf_vbeln.
    SELECTION-SCREEN END OF BLOCK b1.
     
    START-OF-SELECTION.
      SELECT vbeln
              posnr
              matnr
              ernam
              netwr FROM vbap INTO TABLE lt_vbap WHERE vbeln IN so_vbeln.
      IF sy-subrc EQ 0.
     
        PERFORM layout.
        PERFORM build_fieldcat.
        PERFORM sort.
        PERFORM display.
     
      ENDIF.
    *&---------------------------------------------------------------------*
    *&      Form  build_fieldcat
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM build_fieldcat .
      lw_fieldcat-col_pos = '1'.
      lw_fieldcat-fieldname = 'VBELN'.
      lw_fieldcat-tabname   = 'LT_VBAP'.
    *lw_fieldcat-checkbox(1)  = 'X'.
      lw_fieldcat-emphasize(4) = 'C111'.
      lw_fieldcat-seltext_l  = 'SALES ORDER'.
      lw_fieldcat-seltext_m  = 'SAODER'.
      lw_fieldcat-seltext_s  = 'S.O'.
      APPEND lw_fieldcat TO lt_fieldcat.
     
      lw_fieldcat-col_pos = '2'.
      lw_fieldcat-fieldname = 'POSNR'.
      lw_fieldcat-tabname   = 'LT_VBAP'.
    *lw_fieldcat-checkbox(1)  = 'X'.
      lw_fieldcat-emphasize(4) = 'C211'.
      lw_fieldcat-seltext_l  = 'ITEMNO'.
      lw_fieldcat-seltext_m  = 'ITEM'.
      lw_fieldcat-seltext_s  = 'I.N'.
      APPEND lw_fieldcat TO lt_fieldcat.
     
      lw_fieldcat-col_pos = '3'.
      lw_fieldcat-fieldname = 'MATNR'.
      lw_fieldcat-tabname   = 'LT_VBAP'.
    *lw_fieldcat-checkbox(1)  = 'X'.
      lw_fieldcat-emphasize(4) = 'C311'.
      lw_fieldcat-seltext_l  = 'MATERIALNO'.
      lw_fieldcat-seltext_m  = 'MATERIAL'.
      lw_fieldcat-seltext_s  = 'MAT'.
      APPEND lw_fieldcat TO lt_fieldcat.
     
      lw_fieldcat-col_pos = '4'.
      lw_fieldcat-fieldname = 'ERNAM'.
      lw_fieldcat-tabname   = 'LT_VBAP'.
    *lw_fieldcat-checkbox(1)  = 'X'.
      lw_fieldcat-emphasize(4) = 'C411'.
      lw_fieldcat-seltext_l  = 'PERSONCREATED'.
      lw_fieldcat-seltext_m  = 'PERCREATED'.
      lw_fieldcat-seltext_s  = 'PERCRE'.
      APPEND lw_fieldcat TO lt_fieldcat.
     
     
      lw_fieldcat-col_pos = '5'.
      lw_fieldcat-fieldname = 'NETWR'.
      lw_fieldcat-tabname   = 'LT_VBAP'.
    *lw_fieldcat-checkbox(1)  = 'X'.
      lw_fieldcat-emphasize(4) = 'C311'.
      lw_fieldcat-seltext_l  = 'TOTALVALUE'.
      lw_fieldcat-seltext_m  = 'TOTAL'.
      lw_fieldcat-seltext_s  = 'TOT'.
      lw_fieldcat-do_sum = 'X'.
      APPEND lw_fieldcat TO lt_fieldcat.
     
     
     
    ENDFORM.                    " build_fieldcat
    *&---------------------------------------------------------------------*
    *&      Form  layout
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM layout .
     
      lw_layo-colwidth_optimize = 'X'.
      lw_layo-zebra = 'X'.
      APPEND lw_layo TO  lt_layo.
    ENDFORM.                    " layout
    *&---------------------------------------------------------------------*
    *&      Form  sort
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM sort .
      LW_SORT-spos = '1'.
      LW_SORT-fieldname = 'VBELN'.
      LW_SORT-tabname = 'LT_VBAP'.
      LW_SORT-UP = 'X'.
    LW_SORT-subtot = 'X'.
     
    APPEND LW_SORT TO LT_SORT.
     
     
    *  LW_SORT-spos = '2'.
    *  LW_SORT-fieldname = 'POSNR'.
    *  LW_SORT-tabname = 'LT_VBAP'.
    *  LW_SORT-UP = 'X'.
    **  LW_SORT-subtot = 'X'.
    *
    *APPEND LW_SORT TO LT_SORT.
     
    ENDFORM.                    " sort
    *&---------------------------------------------------------------------*
    *&      Form  display
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM display .
     
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
    *   I_INTERFACE_CHECK                 = ' '
    *   I_BYPASSING_BUFFER                = ' '
    *   I_BUFFER_ACTIVE                   = ' '
         i_callback_program                = 'Z_SU_ALVOOPS1'
    *   I_CALLBACK_PF_STATUS_SET          = ' '
    *   I_CALLBACK_USER_COMMAND           = ' '
         i_callback_top_of_page            = 'TOP'
    *   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
    *   I_CALLBACK_HTML_END_OF_LIST       = ' '
    *   I_STRUCTURE_NAME                  =
    *     i_background_id                   = 'ENJOYSAP_LOGO'
    *   I_GRID_TITLE                      =
    *   I_GRID_SETTINGS                   =
    *   IS_LAYOUT                         = LT_LAYO
         it_fieldcat                       = lt_fieldcat
    *   IT_EXCLUDING                      =
    *   IT_SPECIAL_GROUPS                 =
         it_sort                           = lt_sort
    *   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
    *   I_HTML_HEIGHT_TOP                 = 0
    *   I_HTML_HEIGHT_END                 = 0
    *   IT_ALV_GRAPHICS                   =
    *   IT_HYPERLINK                      =
    *   IT_ADD_FIELDCAT                   =
    *   IT_EXCEPT_QINFO                   =
    *   IR_SALV_FULLSCREEN_ADAPTER        =
    * IMPORTING
    *   E_EXIT_CAUSED_BY_CALLER           =
    *   ES_EXIT_CAUSED_BY_USER            =
        TABLES
          t_outtab                          = lt_vbap
    * 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
    *&--------------------------------------------------------------------*
    *&      Form  TOP
    *&--------------------------------------------------------------------*
    *       text
    *---------------------------------------------------------------------*
    FORM top.
      lw_header-typ(1) = 'H'.
      lw_header-info  = 'SALESORDERITEM DATA'.
      APPEND lw_header TO lt_header.
      lw_header-typ(1) = 'S'.
      lw_header-info  = sy-datum.
      APPEND lw_header TO lt_header.
     
     
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary       = lt_header
         i_logo                   = 'SCREEN'
    *   I_END_OF_LIST_GRID       =
    *   I_ALV_FORM               =
                .
    

    if helpful reward some points.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 12:52 PM

    1) FORGET the NON OO version(s) of creating ALV grids

    2) Create an OO Grid of the data you want displayed as per any of the Many Many posts on the Forum(s). The data to be summed must be numeric;

    3) The standard toolbar will have a SUM button on it; Just select the column(s) and press the Sum button. NO CODE NEEDED.

    If you need some sort of model look at the BCALV_GRID*

    or BCALV_EDIT* demo programs in the library.

    (OO class for ALV grid cl_gui_alv_grid);

    Cheeers

    jimbo

    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.