Skip to Content
avatar image
Former Member

alv grid

hi friends,

i have created one alv grid report , i want calculate total and subtotals , total and subtotal will be calculated but total and subtotal text can't be display .

How to do this ?

please help me.

regards,

jai

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Oct 06, 2007 at 04:06 AM

    Hi Jai,

    Can you paste your code here.

    Then only Experts will analyse your code.

    Thanks.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 06, 2007 at 06:55 AM

    hi jai,

    go through this code, this will be helpfull to u. If u have further doubts, send me your code. I will modify it and send u again.

    wa_fcat-fieldname = 'TOTAL'.

    wa_fcat-tabname = 'T_ITAB'. "internal table name

    wa_fcat-col_pos = '0'. "position of that column (i.e total column)

    wa_fcat-seltext_m = 'TOTAL'. "test to display.

    APPEND wa_fcat TO it_fcat.

    wa_fcat-fieldname = 'SUBTOTAL'.

    wa_fcat-tabname = 'T_ITAB'. "internal table name

    wa_fcat-col_pos = '1'. "position of that column (i.e subtotal column)

    wa_fcat-seltext_m = 'SUBTOTAL'. "test to display.

    APPEND wa_fcat TO it_fcat.

    <b>please reward points if helpfull.</b>

    with regards,

    radhika kolluru.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 06, 2007 at 07:28 AM

    totals and sub totals are only happens on currancy fields only if you want to do totals while creating field catlog there is a parameter called do_sum make it as X.For sub totals you have to use slis_t_sortinfo_alv. in this thre is a parameter called subtot keep it as X. i am attaching some sample code for doing totals and sub totals.

    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                   = 'ZREL'
    *   I_END_OF_LIST_GRID       =
    *   I_ALV_FORM               =
                .
    ENDFORM.                    "TOP
    
    
    <b>if helpful reward some points.</b>
    

    Add comment
    10|10000 characters needed characters exceeded