Sub totaling in the ALV report

Hi,
My requirement is to display the data in a ALV format. The ALV need to display the sub total. For example if the ALV display the comapny code, the number of the line of the company code need to displayed.
1000
1000
1000
Sub total 3
2000
2000
2000
2000
sub total 4
I made the changes to display the ALV. Please help mein obtaining the sub total..
Regards
Suresh

HI,
Below example may clear ur requirement.
REPORT YMS_ALVSUBTOTAL.
*REPORT z_alv_sub_totals .
TYPE-POOLS: slis.
DATA: BEGIN OF it_output OCCURS 0,
var1(8) TYPE n,
var2(10),
var3 TYPE I,
END OF it_output.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
t_fieldcat TYPE slis_fieldcat_alv,
it_sort TYPE slis_t_sortinfo_alv,
t_sort TYPE slis_sortinfo_alv,
v_repid LIKE sy-repid.
INITIALIZATION.
v_repid = sy-repid.
START-OF-SELECTION.
PERFORM get_data.
PERFORM sort_fields.
PERFORM fill_fieldcat.
PERFORM list_display.
*& Form GET_DATA
text
--> p1 text
<-- p2 text
FORM get_data.
it_output-var1 = 1000.
it_output-var2 = 'anupama'.
it_output-var3 = '10000'.
APPEND it_output.
CLEAR it_output.
it_output-var1 = 1000.
it_output-var2 = 'siddhu'.
it_output-var3 = '20000'.
APPEND it_output.
CLEAR it_output.
it_output-var1 = 1000.
it_output-var2 = 'chinni'.
it_output-var3 = '100000'.
APPEND it_output.
CLEAR it_output.
it_output-var1 = 2000.
it_output-var2 = 'chicchu'.
it_output-var3 = '10000'.
APPEND it_output.
CLEAR it_output.
it_output-var1 = 2000.
it_output-var2 = 'candy'.
it_output-var3 = '10000'.
APPEND it_output.
CLEAR it_output.
it_output-var1 = 1000.
it_output-var2 = 'anupama'.
it_output-var3 = '10000'.
APPEND it_output.
CLEAR it_output.
it_output-var1 = 4000.
it_output-var2 = 'anupama'.
it_output-var3 = '10000'.
APPEND it_output.
CLEAR it_output.
ENDFORM. " GET_DATA
*& Form fill_fieldcat
text
--> p1 text
<-- p2 text
FORM fill_fieldcat.
PERFORM fill_fields USING: 'IT_OUTPUT' 'VAR1' 'Variable 1' ' ',
'IT_OUTPUT' 'VAR2' 'Variable 2' ' ',
'IT_OUTPUT' 'VAR3' 'Variable 3' 'X'.
ENDFORM. " fill_fieldcat
*& Form fill_fields
text
-->P_0146 text
-->P_0147 text
-->P_0148 text
-->P_0149 text
FORM fill_fields USING value(tabname) TYPE slis_tabname
value(fieldname) TYPE slis_fieldname
value(seltext_m) LIKE dd03p-scrtext_m
value(do_sum) TYPE c.
t_fieldcat-tabname = tabname.
t_fieldcat-fieldname = fieldname.
t_fieldcat-seltext_m = seltext_m.
IF do_sum = 'X'.
t_fieldcat-datatype = 'CURR'.
ENDIF.
t_fieldcat-do_sum = do_sum.
APPEND t_fieldcat TO it_fieldcat.
CLEAR t_fieldcat.
ENDFORM. " fill_fields
*& Form list_display
text
--> p1 text
<-- p2 text
FORM list_display.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = v_repid
it_fieldcat = it_fieldcat
it_sort = it_sort[]
TABLES
t_outtab = it_output
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. " list_display
*& Form sort_fields
text
--> p1 text
<-- p2 text
FORM sort_fields.
t_sort-fieldname = 'VAR1'.
t_sort-tabname = 'IT_OUTPUT'.
t_sort-spos = 1.
t_sort-up = 'X'.
t_sort-subtot = 'X'.
APPEND t_sort TO it_sort.
CLEAR t_sort.
t_sort-fieldname = 'VAR3'.
t_sort-tabname = 'IT_OUTPUT'.
t_sort-spos = 2.
t_sort-up = 'X'.
APPEND t_sort TO it_sort.
CLEAR t_sort.
ENDFORM. " sort_fields
Thanks,
Shankar

Similar Messages

  • Short dump when I do total or sub total in the ALV report

    Hi,
    When I do total or sub-total on the currency field in the ALV report, it'll give a short dump like
    " The current application program detected a situation which really
    should not occur. Therefore, a termination with a short dump was
    triggered on purpose by the key word MESSAGE (type X)".
       Short text of error message:
       Technical information about the message:
       Message classe...... "0K"
       Number.............. 000
       Variable 1.......... " "
       Variable 2.......... " "
       Variable 3.......... " "
       Variable 4.......... " "
       Variable 3.......... " "
       Variable 4.......... " "
    Trigger Location of Runtime Error
        Program                                 SAPLSLVC
        Include                                 LSLVCF36
        Row                                     2,726
        Module type                             (FORM)
        Module Name                             FILL_DATA_TABLE
    sometime when I do the page down on the ALV report, the same short dump is coming.
    Can anyone help me out.
    Thanks
    Selva

    Hi,
    I'm getting this short dump in the standard program.
    I'm getting ALV report display perfectly. the problem is, when I do total or subtotal on the currency fields.
    2704
    2705 ************************************
    2706 * Column per Fieldcat Entry
    2707 ************************************
    2708         ls_lvc_data-value = space.
    2709         clear ls_lvc_data-style.
    2710         loop at it_fcat_local assigning <ls_fcat>
    2711                 where tech ne 'X' and no_out ne 'X'.
    2712           if l_invisible eq 'X'.
    2713             clear l_invisible.
    2714             if <ls_fcat>-do_sum is initial.
    2715               continue.
    2716             else.
    2717               clear ls_lvc_data-col_pos.
    2718             endif.
    2719           endif.
    2720
    2721           add 1 to ls_lvc_data-col_pos.
    2722
    2723           assign component <ls_fcat>-fieldname
    2724                            of structure <ls_data> to <l_field_value>.
    2725           if sy-subrc ne 0.
    >>>>>             message x000(0k).
    2727           endif.
    2728
    in this standard program, I'm getting the dump. the line is mentioned above in the code.

  • Urgent: regarding sub total button in alv report

    hi,
    i had made dis report and it is is fine till now,but now i want add the sub total field in it ,by making double click on the field sub-total should be displayed in it.
    here is d code as i had tried the sub - total but when i execute it is giving some diferrent result.
    *& Report  ZTET2
    REPORT  ZTET2.
    TABLES: ISEG,MARA.
    TYPE-POOLS : SLIS.
    DATA : DATE1(15) TYPE C,
    DATE2(15) TYPE C,
    TITLE(65) TYPE C,
    DT(25) TYPE C.
    DATA : ITEVENT TYPE SLIS_T_EVENT.
    DATA: lv_sort TYPE slis_sortinfo_alv,
          t_sort type slis_t_sortinfo_alv.
    DATA : repid LIKE sy-repid.
    INTERNAL TABLE FOR INVENTORY STOCK *****************
    DATA: BEGIN OF ITS1 OCCURS 0,
          MATNR LIKE ISEG-MATNR,
          ITEMID(6) TYPE C,
          MEINS LIKE ISEG-MEINS,
          MENGE LIKE ISEG-MENGE,
          WRTZL LIKE ISEG-WRTZL,
          BUCHM LIKE ISEG-BUCHM,
          WRTBM LIKE ISEG-WRTBM,
          WERKS LIKE ISEG-WERKS,
          BUDAT LIKE ISEG-BUDAT,
          ZLDAT LIKE ISEG-ZLDAT,
          MTART LIKE MARA-MTART,
          ITEMDESC LIKE MAKT-MAKTX,
          DIFFQTY LIKE ISEG-BUCHM,
          DIFFVALUE LIKE ISEG-WRTBM,
          GRUND LIKE ISEG-GRUND,
          GRTXT LIKE T157E-GRTXT,
          BWART LIKE T157E-BWART,
          REAS TYPE C LENGTH 15,
          END OF ITS1.
    data: t_heading type slis_t_listheader.
    SELECTION-SCREEN BEGIN OF BLOCK PAR1 WITH FRAME TITLE TEXT-001.
    *SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
    *********PARAMETERS*********
    PARAMETERS : PLANT LIKE ISEG-WERKS OBLIGATORY.
    *********SELECTION SCREEN OPTIONS*********
    SELECT-OPTIONS : R_DATE FOR ISEG-BUDAT OBLIGATORY NO-EXTENSION,
                     M_TYPE  FOR MARA-MTART,
                     IT_M FOR MARA-MATNR.
    *********DEFINING VARIABLES*********
    SELECTION-SCREEN END OF BLOCK par1.
    CONCATENATE R_DATE-LOW6(2) '.' R_DATE-LOW4(2) '.' R_DATE-LOW+0(4) INTO DATE1.
    CONCATENATE R_DATE-HIGH6(2) '.' R_DATE-HIGH4(2) '.' R_DATE-HIGH+0(4) INTO DATE2.
    TOP-OF-PAGE.
      PERFORM PG_HEADER.
       START-OF-SELECTION.
      SELECT AMATNR AMEINS AMENGE AWRTZL ABUCHM AWRTBM AWERKS ABUDAT AZLDAT BMTART AGRUND CBWART
       FROM ISEG AS A INNER JOIN MARA AS B ON BMATNR = AMATNR
       INNER JOIN MSEG AS C ON AMBLNR = CMBLNR
       INTO CORRESPONDING FIELDS OF TABLE ITS1 WHERE BMATNR = AMATNR  AND BMEINS = AMEINS AND AWERKS = PLANT AND ABUDAT IN R_DATE AND BMTART IN M_TYPE AND BMATNR IN IT_M.
    LOOP AT ITS1.
         ITS1-ITEMID = ITS1-MATNR+12(6).
         ITS1-DIFFQTY = ITS1-MENGE - ITS1-BUCHM.
         ITS1-DIFFVALUE = ITS1-WRTZL - ITS1-WRTBM.
         SELECT SINGLE MAKTX FROM MAKT INTO ITS1-ITEMDESC WHERE MATNR = ITS1-MATNR.
         SELECT SINGLE GRTXT INTO ITS1-GRTXT FROM T157E WHERE GRUND = ITS1-GRUND AND SPRAS = 'E' AND BWART = ITS1-BWART.
         MODIFY ITS1.
    ENDLOOP.
    PERFORM PRN_SMSTOCK_ALV.
    WRITING DATA FROM D TABLES**********
    FORM PG_HEADER.
    WRITE : 'PHYSICAL INVENTORY AUDIT REPORT             PLANT : ', PLANT.
    ENDFORM.
    *&      Form  PRN_SMSTOCK_ALV
          text
    -->  p1        text
    <--  p2        text
    form PRN_SMSTOCK_ALV .
    data: w_title   type lvc_title,
          w_repid   type syrepid,
          w_comm    type slis_formname,
          w_status  type slis_formname,
          x_layout  type slis_layout_alv,
          t_event   type slis_t_event,
          t_fieldcat type slis_t_fieldcat_alv,
          t_subtot TYPE slis_t_sortinfo_alv,
          subtot LIKE LINE OF t_subtot.
    refresh t_fieldcat.
    refresh t_event.
    refresh t_sort.
    clear x_layout.
    clear w_title.
      perform set_fieldcat2 using:
    1  'MTART'     'MTART'     'MARA'  '15'  space 'MATERIAL TYPE'        space  space  space space space space space space SPACE t_fieldcat 'L' 'L',
    2  'ITEMID'    'ITEMID'    'MARA'  '7'   space 'ITEM ID'              space  space  space space space space space space SPACE t_fieldcat 'R' 'C',
    3  'ITEMDESC'  'MAKTX'     'MAKT'  '25'  space 'MATERIAL DESCRIPTION' space  space  space space space space space space SPACE t_fieldcat 'L' 'C',
    4  'MEINS'     'MEINS'     'MARA'  '5'   space 'UOM'                  space  space  space space space space space space SPACE t_fieldcat 'C' 'C',
    5  'MENGE'     'MENGE'     'ISEG'  '13'  space 'ORG.INV.QTY'          space  space  space space space space space space SPACE t_fieldcat 'R' 'C',
    6  'WRTZL'     'WRTZL'     'ISEG'  '13'  space 'ORG.INV.VALUE'        space  space  space space space space space space SPACE t_fieldcat 'R' 'C',
    7  'BUCHM'     'BUCHM'     'ISEG'  '13'  space 'PHY.INV.QTY'          space  space  space space space space space space SPACE t_fieldcat 'R' 'C',
    8  'WRTBM'     'WRTBM'     'ISEG'  '13'  space 'PHY.INV.VALUE'        space  space  space space space space space space SPACE t_fieldcat 'R' 'C',
    9  'DIFFQTY'   'MENGE'     'ISEG'  '13'  space 'DIFF.INV.QTY'         space  space  space space space space space space SPACE t_fieldcat 'R' 'C',
    10 'DIFFVALUE' 'WRTZL'     'ISEG'  '13'  space 'DIFF.INV.VALUE'       space  space  space space space space space space SPACE t_fieldcat SPACE 'P',
    11 'BUDAT'     'BUDAT'     'ISEG'  '18'  space 'CORRECTED DATE'       space  space  space space space space space space SPACE t_fieldcat  'C' 'C',
    12 'GRTXT'     'GRTXT'     'ISEG'  '18'  space 'REASON'               space  space  space space space space space space SPACE t_fieldcat  'L' 'L',
    13 'REAS'      'REAS'      'ISEG'  '18'  space 'AUTH.BY'              space  space  space space space space space space SPACE t_fieldcat  'C' 'C'.
    x_layout-zebra = 'X'.
    perform set_top_page_heading using t_heading t_event.
    perform set_events using t_event.
    perform get_subtotals.
      w_status = ''.
      w_repid = sy-repid.
    w_comm   = 'USER_COMMAND'.
      call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          i_callback_program       = w_repid
          it_fieldcat              = t_fieldcat
          i_Callback_top_of_page   = 'Top-of-page'
          is_layout                = x_layout
          it_sort                  = t_sort
          i_callback_pf_status_set = w_status
          i_callback_user_command  = w_comm
          i_save                   = 'X'
          it_events                = t_event
          i_grid_title             = w_title
          tables
          t_outtab                 = ITS1
          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.
    FORM set_fieldcat2 USING
          p_colpos p_fieldname p_ref_fieldname p_ref_tabname
          p_outputlen p_noout
          p_seltext_m p_seltext_l p_seltext_s p_reptext_ddic p_ddictxt
          p_hotspot p_showasicon p_checkbox p_edit
          p_dosum
        p_subtot
          t_fieldcat TYPE slis_t_fieldcat_alv
          P_JUST
          P_FTYPE.
      DATA: wa_fieldcat TYPE slis_fieldcat_alv.
      CLEAR wa_fieldcat.
    General settings
      wa_fieldcat-fieldname = p_fieldname.
      wa_fieldcat-col_pos = p_colpos.
      wa_fieldcat-no_out = p_noout.
      wa_fieldcat-hotspot = p_hotspot.
      wa_fieldcat-checkbox = p_checkbox.
      wa_fieldcat-icon = p_showasicon.
      wa_fieldcat-do_sum = p_dosum.
    wa_fieldcat-t_subtot = p_subtot.
    Set output length.
      IF NOT p_outputlen IS INITIAL.
        wa_fieldcat-outputlen = p_outputlen.
      ENDIF.
    Set text headers.
    IF NOT p_seltext_m IS INITIAL.
        wa_fieldcat-seltext_m = p_seltext_m.
    ENDIF.
    IF NOT p_seltext_l IS INITIAL.
        wa_fieldcat-seltext_l = p_seltext_l.
    ENDIF.
    IF NOT p_seltext_s IS INITIAL.
        wa_fieldcat-seltext_s = p_seltext_s.
    ENDIF.
      IF NOT p_reptext_ddic IS INITIAL.
        wa_fieldcat-reptext_ddic = p_reptext_ddic.
      ENDIF.
    IF NOT p_ddictxt IS INITIAL.
        wa_fieldcat-ddictxt = p_ddictxt.
    ENDIF.
      IF NOT P_JUST IS INITIAL.
        WA_FIELDCAT-JUST = P_JUST.
      ENDIF.
      IF NOT p_edit IS INITIAL.
        wa_fieldcat-Input     = 'X'.
        wa_fieldcat-edit     = 'X'.
        wa_fieldcat-do_sum = 'x'.
       wa_fieldcat-p_subtot = 'x'.
      ENDIF.
    APPEND wa_fieldcat TO t_fieldcat.
    ENDFORM.                   "set_fieldcat2
    ======================== Subroutines called by ALV ================
    *&      Form  top_of_page
          Called on top_of_page ALV event.
          Prints the heading.
    form top_of_page.
      call function 'REUSE_ALV_COMMENTARY_WRITE'
         exporting
              it_list_commentary = t_heading.
    ENDFORM.
    form set_top_page_heading using t_heading type slis_t_listheader
                                    t_events  type slis_t_event.
    data: x_heading type slis_listheader,
          x_event   type line of slis_t_event.
    Report title
      clear t_heading[].
      clear x_heading.
      x_heading-typ = 'H'.
      x_heading-info = 'PHYSICAL INVENTORY AUDIT REPORT'.
      append x_heading to t_heading.
    Plant Name
    clear x_heading.
      x_heading-typ = 'S'.
      x_heading-key = 'PLANT        : '.
      x_heading-info = PLANT.
      append x_heading to t_heading.
    IF DATE2 = '00.00.0000'.
      CONCATENATE DATE1 'to' DATE1 INTO DT SEPARATED BY SPACE.
    ELSE.
      CONCATENATE DATE1 'to' DATE2 INTO DT SEPARATED BY SPACE.
    ENDIF.
    X_heading-TYP = 'S'.
    X_heading-key = 'PERIOD         :'.
    X_heading-INFO = DT.
    APPEND x_heading TO t_heading.
    Control Date
      clear x_heading.
      x_heading-typ = 'S'.
      x_heading-key = 'CONTROL NO. :'.
      x_heading-info = ' ASDFADDFAAS  DATE : 11.04.2007'.
      append x_heading to t_heading.
    Control date
    clear x_heading.
    x_heading-typ = 'S'.
    x_heading-key = 'CONTROL DATE : '.
    x_heading-info = ''.
    append x_heading to t_heading.
    Time of execution
    clear x_heading.
    x_heading-typ = 'S'.
    x_heading-key = 'DATE : '.
    write sy-DATUM to x_heading-info.
    append x_heading to t_heading.
    Top of page event
      x_event-name = slis_ev_top_of_page.
      x_event-form = 'TOP_OF_PAGE'.
      append x_event to t_events.
    endform.
    FORM get_subtotals.
    CLEAR lv_sort.
    lv_sort-fieldname = 'MENGE'.
    lv_sort-up = 'X'.
    lv_sort-subtot = 'X'.
    APPEND lv_sort TO t_sort.
    clear lv_sort.
    *lv_sort-fieldname = 'MENGE'.
    *lv_sort-tabname = 'ITS1'.
    *lv_sort-subtot = 'X'.
    *APPEND lv_sort TO t_sort.
    lv_sort-fieldname = 'WRTZL'.
    lv_sort-tabname = 'ITS1'.
    lv_sort-subtot = 'X'.
    APPEND lv_sort TO t_sort.
    clear lv_sort.
    lv_sort-fieldname = 'BUCHM'.
    lv_sort-tabname = 'ITS1'.
    lv_sort-subtot = 'X'.
    APPEND lv_sort TO t_sort.
    clear lv_sort.
    lv_sort-fieldname = 'WRTBM'.
    lv_sort-tabname = 'ITS1'.
    lv_sort-subtot = 'X'.
    APPEND lv_sort TO t_sort.
    clear lv_sort.
    lv_sort-fieldname = 'DIFFQTY'.
    lv_sort-tabname = 'ITS1'.
    lv_sort-subtot = 'X'.
    APPEND lv_sort TO t_sort.
    clear lv_sort.
    lv_sort-fieldname = 'DIFFVALUE'.
    lv_sort-tabname = 'ITS1'.
    lv_sort-subtot = 'X'.
    APPEND lv_sort TO t_sort.
    clear lv_sort.
    ENDFORM.
    form set_events using t_events type slis_t_event.
    data: x_event   type line of slis_t_event.
    endform.
    PLZ HELP ME and definately get rewarded.

    hi,
    how did u declared ur internal table?
    Declare a dummy field in your internal table to trigger subtotal text event.
    TYPES: BEGIN OF ty_ekpo,
              lifnr TYPE ekko-lifnr,    "vendor number
              ebeln TYPE ekko-ebeln,    "purchase document number
              ebelp TYPE ekpo-ebelp,    "Item Number of Purchasing Document
              matnr TYPE ekpo-matnr,    "Material Number
              bukrs TYPE ekpo-bukrs,    "Company Code
              werks TYPE ekpo-werks,    "Plant
              d,                        "Dummy field to fire the Subtotal text event
          END OF ty_ekpo.
    Prepare field catalog for that dummyfield also and set attributes like below
    wa_fcat-col_pos = 7.
      wa_fcat-fieldname = 'D'.
      wa_fcat-tabname = 'IT_EKPO'.
      wa_fcat-ref_fieldname = 'NETPR'.
      wa_fcat-ref_tabname = 'EKPO'.
      wa_fcat-no_out = 'X'.
      APPEND wa_fcat TO it_fcat.
    Fill sortinfo table as follows
    wa_sort-spos = 1.
      wa_sort-fieldname = 'LIFNR'.
      wa_sort-tabname = 'IT_EKPO'.
      wa_sort-up = 'X'.
      wa_sort-group = 'UL'.
      APPEND wa_sort TO it_sort.
      CLEAR wa_sort.
      wa_sort-spos = 2.
      wa_sort-fieldname = 'D'.
      wa_sort-tabname = 'IT_EKPO'.
      wa_sort-up = 'X'.
      wa_sort-group = 'UL'.
      wa_sort-subtot = 'X'.
      APPEND wa_sort TO it_sort.
    fill the event table
    wa_event-name = 'SUBTOTAL_TEXT'.  "--> this event is used to trigger subtotal text
      wa_event-form = 'SUBTOTAL'.
      APPEND wa_event TO it_event.
    *&      Form  subtotal
    FORM subtotal USING i_listhead STRUCTURE wa_ekpo  i_subtotal TYPE slis_subtot_text.
      READ TABLE it_sort INTO wa_sort WITH KEY fieldname = 'D'.
      IF sy-subrc = 0.
        IF i_subtotal-criteria = 'D'.
          i_subtotal-display_text_for_subtotal = 'Sub total'.
        ENDIF.
      ENDIF.
    ENDFORM.                    "subtotal
    Thanks & REgards

  • Sub total text in ALV report

    Hi,
    I need to do subtotalling in my program using ALV. I am getting the subtotal value in ALV list display , but not getting the text for subtotalling.
    matnr               werks                       stock
    154                  1001                         1589
    158                  1001                         1651
    Subtotal for plant 1001                               3240
    155                  1002                         465
    Subtotal for plant 1002                       465

    hi,
    how did u declared ur internal table?
    Declare a dummy field in your internal table to trigger subtotal text event.
    TYPES: BEGIN OF ty_ekpo,
              lifnr TYPE ekko-lifnr,    "vendor number
              ebeln TYPE ekko-ebeln,    "purchase document number
              ebelp TYPE ekpo-ebelp,    "Item Number of Purchasing Document
              matnr TYPE ekpo-matnr,    "Material Number
              bukrs TYPE ekpo-bukrs,    "Company Code
              werks TYPE ekpo-werks,    "Plant
              d,                        "Dummy field to fire the Subtotal text event
          END OF ty_ekpo.
    Prepare field catalog for that dummyfield also and set attributes like below
    wa_fcat-col_pos = 7.
      wa_fcat-fieldname = 'D'.
      wa_fcat-tabname = 'IT_EKPO'.
      wa_fcat-ref_fieldname = 'NETPR'.
      wa_fcat-ref_tabname = 'EKPO'.
      wa_fcat-no_out = 'X'.
      APPEND wa_fcat TO it_fcat.
    Fill sortinfo table as follows
    wa_sort-spos = 1.
      wa_sort-fieldname = 'LIFNR'.
      wa_sort-tabname = 'IT_EKPO'.
      wa_sort-up = 'X'.
      wa_sort-group = 'UL'.
      APPEND wa_sort TO it_sort.
      CLEAR wa_sort.
      wa_sort-spos = 2.
      wa_sort-fieldname = 'D'.
      wa_sort-tabname = 'IT_EKPO'.
      wa_sort-up = 'X'.
      wa_sort-group = 'UL'.
      wa_sort-subtot = 'X'.
      APPEND wa_sort TO it_sort.
    fill the event table
    wa_event-name = 'SUBTOTAL_TEXT'.  "--> this event is used to trigger subtotal text
      wa_event-form = 'SUBTOTAL'.
      APPEND wa_event TO it_event.
    *&      Form  subtotal
    FORM subtotal USING i_listhead STRUCTURE wa_ekpo  i_subtotal TYPE slis_subtot_text.
      READ TABLE it_sort INTO wa_sort WITH KEY fieldname = 'D'.
      IF sy-subrc = 0.
        IF i_subtotal-criteria = 'D'.
          i_subtotal-display_text_for_subtotal = 'Sub total'.
        ENDIF.
      ENDIF.
    ENDFORM.                    "subtotal
    Thanks & REgards

  • Can we display only sub totals on the alv grid output

    hi,
    can we display only the subtotals calculated on the grid display.it should display all the data it shpuld display only the subtotals of it.
    if yes can any one please give me the code for
    will be awarded with points.

    Hi Raju
    You can do that
    When you are doing fieldcatalog,comment ws_fieldcat-do_sum = 'x'.
    if you comment that it wont display totals.
    use sort
    i_sort type slis_alv...
    clear ws_sort.
    ws_sort1-spos = '1'<position of field>
    ws_sort-fieldname  = 'matnr'.
    ws_sort-up = 'x'.
    append ws_sort to i_sort.
    pass this i_sort to FM

  • How to calculate totals in Blocked ALV Report

    Hi All,
    Can any body tell how to calculate totals & sub totals in
    Blocked ALV Report[Blocked List].
    Thanks in advance
    Thanks & Regards,
    Rayeezuddin.

    read this it might help
    Sums                                                       
    15. No_sumchoice(1) TYPE c : This parameter allows the choice for summing up
    Only by fieldcatalog.
    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.
    16. No_totalline(1) TYPE c : Removes the option of having totals after sub-totals.
    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.
    17. No_subchoice(1) TYPE c : Does not allow the user to interactively change the field chosen for subtotals.
    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.
    18. No_subtotals(1) TYPE c : No subtotals possible          
    Value set: SPACE, 'X'
    'X' = no subtotals.
    19. Numc_sum(1)  TYPE c : Totals only possible for NUMC-Fields.
    20. No_unit_splitting TYPE c: No separate total lines by inh.units   
    21.totals_before_items TYPE c: Display totals before the items   
    22. Totals_only(1) TYPE c :  Show only totals      
    Value set: SPACE, 'X'
    'X' = only total records are output.
    23. Totals_text(60) TYPE c : Text for 1st col. in totals   
    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.
    24. Subtotals_text(60) TYPE c : Texts for subtotals
    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.
    ELSE TELL ME I WILL PASTE COMPLETE HELP
    regards

  • Hide grand total field on ALV report, But keep the sub total fields

    Dear Experts,
    1) How to hide grand total field on ALV report, But keep the sub total fields.
    2) How to populate rate per ton & calculate total price according to the qty in delivering document.

    Dear Experts,
    1) How to hide grand total field on ALV report, But keep the sub total fields.
    2) How to populate rate per ton & calculate total price according to the qty in delivering document.

  • How to find out the total, subtotal in alv report

    hi dears,
    how to find out the total, subtotal in alv report?
    pls tell me logic ,
    i will be waiting for eply
    regards
    eswar

    Hi,
    <b>ALV Grid List with sub-totals</b>
    REPORT z_demo_alv_sort.
    * This program lists orders (VBAK) with sort and sub-total for        *
    * 'sold-to-party' (KUNNR) and 'Sales organization' (VKORG)            *
    TABLES : vbak.
    TYPE-POOLS: slis.                      " ALV Global types
    SELECT-OPTIONS :
      s_vkorg FOR vbak-vkorg,              " Sales organization
      s_kunnr FOR vbak-kunnr,              " Sold-to party
      s_vbeln FOR vbak-vbeln.              " Sales document
    SELECTION-SCREEN :
      SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.
    PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    DATA:
      BEGIN OF gt_vbak OCCURS 0,
        vkorg LIKE vbak-vkorg,             " Sales organization
        kunnr LIKE vbak-kunnr,             " Sold-to party
        vbeln LIKE vbak-vbeln,             " Sales document
        netwr LIKE vbak-netwr,             " Net Value of the Sales Order
        waerk LIKE vbak-waerk,             " Document currency
      END OF gt_vbak.
    INITIALIZATION.
      v_1 = 'Maximum of records to read'.
    START-OF-SELECTION.
      PERFORM f_read_data.
      PERFORM f_display_data.
    *      Form  f_read_data
    FORM f_read_data.
      SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak
               FROM vbak
                 UP TO p_max ROWS
              WHERE kunnr IN s_kunnr
                AND vbeln IN s_vbeln
                AND vkorg IN s_vkorg.
    ENDFORM.                               " F_READ_DATA
    *      Form  f_display_data
    FORM f_display_data.
      DEFINE m_fieldcat.
        add 1 to ls_fieldcat-col_pos.
        ls_fieldcat-fieldname   = &1.
        ls_fieldcat-ref_tabname = 'VBAK'.
        ls_fieldcat-do_sum      = &2.
        ls_fieldcat-cfieldname  = &3.
        append ls_fieldcat to lt_fieldcat.
      END-OF-DEFINITION.
      DEFINE m_sort.
        add 1 to ls_sort-spos.
        ls_sort-fieldname = &1.
        ls_sort-up        = 'X'.
        ls_sort-subtot    = &2.
        append ls_sort to lt_sort.
      END-OF-DEFINITION.
      DATA:
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv,
        lt_sort     TYPE slis_t_sortinfo_alv,
        ls_sort     TYPE slis_sortinfo_alv,
        ls_layout   TYPE slis_layout_alv.
      m_fieldcat 'VKORG' ''  ''.
      m_fieldcat 'KUNNR' ''  ''.
      m_fieldcat 'VBELN' ''  ''.
      m_fieldcat 'NETWR' 'X' 'WAERK'.
      m_fieldcat 'WAERK' ''  ''.
      m_sort 'VKORG' 'X'.                  " Sort by vkorg and subtotal
      m_sort 'KUNNR' 'X'.                  " Sort by kunnr and subtotal
      m_sort 'VBELN' ''.                   " Sort by vbeln
      ls_layout-cell_merge = 'X'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                is_layout   = ls_layout
                it_fieldcat = lt_fieldcat
                it_sort     = lt_sort
           TABLES
                t_outtab    = gt_vbak.
    ENDFORM.                               " F_DISPLAY_DATA
    ***************** END OF PROGRAM Z_DEMO_ALV_SORT **********************
    Regards
    Sudheer

  • How to do the ALV report output in groups and caluculate the tOTALS(URGENT

    Hi
    In my ALV report output .I have to group the output based on the DAYS field
    0-10 days in one group
    10-30 days in one group
    above 30 days one group
    There is also a field by name "AMOUNT" in my output.
    I have to calculate SUBTOTALs at the end of every group and at the end of the report i should caluculate GRAND TOTAL.
    Please remember that i should not use any any BLOCKED ALVs and for Totals i should not use the SYMBOLS provided in the application toolbar of the report
    Thanks in Advance

    Please don't repost your questions...
    Check out my answer in your other post.
    How to make the ALV report in groups  and caluculate the TOTALS
    Regards,
    Naimesh Patel

  • The filtering , sorting , totaling action on ALV report is lost

    Hi ,
    I have an Interactive ALV report which i sort it , filter it and total it before I enter into my Z customised screen, from my Z cusomised screen when I come back to the ALV report, the report is no more sorted, no more filtered and no more totaled.
    Please help me on this its a bit urgent.

    *& Report  ZALV_SUM
    REPORT  ZNNR_ALV_SUM.
    TABLES:     ekko.
    type-pools: slis.                                 "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_vbap,
      vbeln TYPE vbap-vbeln,
      matnr TYPE vbap-matnr,
      netwr TYPE vbap-netwr,
      waerk TYPE vbap-waerk,
    END OF t_vbap.
    DATA: it_vbap TYPE STANDARD TABLE OF t_vbap INITIAL SIZE 0,
          wa_vbap TYPE t_vbap.
    *ALV data declarations
    data: fieldcatalog type slis_t_fieldcat_alv with header line,
          gd_tab_group type slis_t_sp_group_alv,
          gd_layout    type slis_layout_alv,
          gd_repid     like sy-repid.
    *Start-of-selection.
    START-OF-SELECTION.
    perform data_retrieval.
    perform build_fieldcatalog.
    perform build_layout.
    perform display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
          Build Fieldcatalog for ALV Report
    form build_fieldcatalog.
      fieldcatalog-fieldname   = 'VBELN'.
      fieldcatalog-seltext_m   = 'Sales Order'.
      fieldcatalog-col_pos     = 0.
      fieldcatalog-outputlen   = 10.
      fieldcatalog-emphasize   = 'X'.
      fieldcatalog-key         = 'X'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-seltext_m   = 'Material Number'.
      fieldcatalog-col_pos     = 4.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'NETWR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-do_sum      = 'X'.        "Display column total
      fieldcatalog-cfieldname     = 'WAERK'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'WAERK'.
      fieldcatalog-seltext_m   = 'Price Curr'.
      fieldcatalog-col_pos     = 8.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    endform.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
          Build layout for ALV grid report
    form build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-totals_text       = 'Totals'(201).
    gd_layout-totals_only        = 'X'.
    gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
                                            "click(press f2)
    gd_layout-zebra             = 'X'.
    gd_layout-group_change_edit = 'X'.
    gd_layout-header_text       = 'helllllo'.
    endform.                    " BUILD_LAYOUT
    *&      Form  DISPLAY_ALV_REPORT
          Display report using ALV grid
    form display_alv_report.
      gd_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = gd_repid
               i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
               i_callback_user_command = 'USER_COMMAND'
               i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
               it_special_groups       = gd_tabgroup
               IT_EVENTS                = GT_XEVENTS
                i_save                  = 'X'
               is_variant              = z_template
           tables
                t_outtab                = it_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_ALV_REPORT
    *&      Form  DATA_RETRIEVAL
          Retrieve data form EKPO table and populate itab it_ekko
    form data_retrieval.
    select vbeln matnr netwr waerk
    up to 50 rows
      from vbap
      into table it_vbap.
    endform.                    " DATA_RETRIEVAL

  • How to get the total pages in ALV report?

    Hi guys,
    Since I used page breaks can somebody please help me on how to get the total pages in ALV report?sincerely please...thanks guys.

    automatic display total page.
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907
    r

  • Regarding totals  and sub totals text in alv

    Hi all,
    i am displaying Totals and subtotals ......but i want to display the text before the the Totals and Subtotals.
    Please help me in regarding this..
    Thanks in advance,
    S.Gangi reddy.

    hi,
    check this report.
    *& Report  ZGM_ALV_SUBTOTAL_TEXT                                       *
    *& Author :
    *& Date :
    *& Description :
    *& Modification History
    REPORT  ZGM_ALV_SUBTOTAL_TEXT                   .
    *& Table declaration
    TABLES: ekko.
    *& Type pool declaration
    TYPE-POOLS: slis. " Type pool for ALV
    *& Selection screen
    SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.
    *& Type declaration
    Type declaration for internal table to store EKPO data
    TYPES: BEGIN OF x_data,
           ebeln  TYPE char30,  " Document no.
           ebelp  TYPE ebelp,   " Item no
           matnr  TYPE matnr,   " Material no
           matnr1 TYPE matnr,   " Material no
           werks  TYPE werks_d, " Plant
           werks1 TYPE werks_d, " Plant
           ntgew  TYPE entge,   " Net weight
           gewe   TYPE egewe,   " Unit of weight                          
           END OF x_data.
    *& Internal table declaration
    DATA:
      i_ekpo TYPE STANDARD TABLE OF x_data INITIAL SIZE 0,
    Internal table for storing field catalog information
      i_fieldcat TYPE slis_t_fieldcat_alv,
    Internal table for Top of Page info. in ALV Display
      i_alv_top_of_page TYPE slis_t_listheader,
    Internal table for ALV Display events
      i_events TYPE slis_t_event,
    Internal table for storing ALV sort information
      i_sort TYPE  slis_t_sortinfo_alv,
      i_event TYPE slis_t_event.
    *& Work area declaration
    DATA:
      wa_ekko TYPE x_data,
      wa_layout     TYPE slis_layout_alv,
      wa_events         TYPE slis_alv_event,
      wa_sort TYPE slis_sortinfo_alv.
    *& Constant declaration
    CONSTANTS:
       c_header   TYPE char1
                  VALUE 'H',                    "Header in ALV
       c_item     TYPE char1
                  VALUE 'S'.
    *& Start-of-selection event
    START-OF-SELECTION.
    Select data from ekpo
      SELECT ebeln " Doc no
             ebelp " Item
             matnr " Material
             matnr " Material
             werks " Plant
             werks " Plant
             ntgew " Quantity
             gewei " Unit
             FROM ekpo
             INTO TABLE i_ekpo
             WHERE ebeln IN s_ebeln
             AND ntgew NE '0.00'.  IF sy-subrc = 0.
        SORT i_ekpo BY ebeln ebelp matnr .
      ENDIF.
    To build the Page header
      PERFORM sub_build_header. "* To prepare field catalog
      PERFORM sub_field_catalog. "* Perform to populate the layout structure
      PERFORM sub_populate_layout."* Perform to populate the sort table.
      PERFORM sub_populate_sort."* Perform to populate ALV event
      PERFORM sub_get_event.
      END-OF-SELECTION.
    * Perform to display ALV report
      PERFORM sub_alv_report_display.
    *&      Form  sub_build_header
          To build the header
          No Parameter
    FORM sub_build_header .
    Local data declaration
      DATA: l_system     TYPE char10 ,          "System id
            l_r_line     TYPE slis_listheader,  "Hold list header
            l_date       TYPE char10,           "Date
            l_time       TYPE char10,           "Time
            l_success_records TYPE i,           "No of success records
            l_title(300) TYPE c.                " Title
    Title  Display
      l_r_line-typ = c_header.               " header
      l_title = 'Test report'(001).
      l_r_line-info = l_title.
      APPEND l_r_line TO i_alv_top_of_page.
      CLEAR l_r_line.
    * Run date Display
      CLEAR l_date.
      l_r_line-typ  = c_item.                " Item
      WRITE: sy-datum  TO l_date MM/DD/YYYY.
      l_r_line-key = 'Run Date :'(002).
      l_r_line-info = l_date.
      APPEND l_r_line TO i_alv_top_of_page.
      CLEAR: l_r_line,
             l_date.ENDFORM.                    " sub_build_header
    *&      Form  sub_field_catalog
          Build Field Catalog
          No Parameter
    FORM sub_field_catalog .
    Build Field Catalog
      PERFORM sub_fill_alv_field_catalog USING:     '01' '01' 'EBELN'
      'I_EKPO' 'L'
         'Doc No'(003) ' ' ' ' ' ' ' ',     '01' '02' 'EBELP' 'I_EKPO' 'L'
         'Item No'(004) 'X' 'X' ' ' ' ',     '01' '03' 'MATNR' 'I_EKPO' 'L'
         'Material No'(005) 'X' 'X' ' ' ' ',     '01' '03' 'MATNR1' 'I_EKPO'
         'L'
         'Material No'(005) ' ' ' ' ' ' ' ',
         '01' '04' 'WERKS' 'I_EKPO' 'L'
         'Plant'(006) 'X' 'X' ' ' ' ',     '01' '04' 'WERKS1' 'I_EKPO' 'L'
         'Plant'(006) ' ' ' ' ' ' ' ',     '01' '05' 'NTGEW' 'I_EKPO' 'R'
         'Net Weight'(007) ' ' ' ' 'GEWE' 'I_EKPO'.ENDFORM.
    " sub_field_catalog*&----
    *&     Form  sub_fill_alv_field_catalog
    *&     For building Field Catalog
    *&     p_rowpos   Row position
    *&     p_colpos   Col position
    *&     p_fldnam   Fldname
    *&     p_tabnam   Tabname
    *&     p_justif   Justification
    *&     p_seltext  Seltext
    *&     p_out      no out
    *&     p_tech     Technical field
    *&     p_qfield   Quantity field
    *&     p_qtab     Quantity table
    FORM sub_fill_alv_field_catalog  USING  p_rowpos    TYPE sycurow
                                            p_colpos    TYPE sycucol
                                            p_fldnam    TYPE fieldname
                                            p_tabnam    TYPE tabname
                                            p_justif    TYPE char1
                                            p_seltext   TYPE dd03p-scrtext_l
                                            p_out       TYPE char1
                                            p_tech      TYPE char1
                                            p_qfield    TYPE slis_fieldname
                                            p_qtab      TYPE slis_tabname.
                                           Local declaration for field
                                           catalog
      DATA: wa_lfl_fcat    TYPE  slis_fieldcat_alv.
      wa_lfl_fcat-row_pos        =  p_rowpos.     "Row
      wa_lfl_fcat-col_pos        =  p_colpos.     "Column
      wa_lfl_fcat-fieldname      =  p_fldnam.     "Field Name
      wa_lfl_fcat-tabname        =  p_tabnam.     "Internal Table Name
      wa_lfl_fcat-just           =  p_justif.     "Screen Justified
      wa_lfl_fcat-seltext_l      =  p_seltext.    "Field Text
      wa_lfl_fcat-no_out         =  p_out.        "No output
      wa_lfl_fcat-tech           =  p_tech.       "Technical field
      wa_lfl_fcat-qfieldname     =  p_qfield.     "Quantity unit
      wa_lfl_fcat-qtabname       =  p_qtab .
      "Quantity table
      IF p_fldnam = 'NTGEW'.
        wa_lfl_fcat-do_sum  = 'X'.
      ENDIF.
      APPEND wa_lfl_fcat TO i_fieldcat.
      CLEAR wa_lfl_fcat.
    ENDFORM.
    " sub_fill_alv_field_catalog*&----
    *&      Form  sub_populate_layout
          Populate ALV layout
          No Parameter
    FORM sub_populate_layout .  CLEAR wa_layout.
      wa_layout-colwidth_optimize = 'X'.
    " Optimization of Col width
    ENDFORM. " sub_populate_layout*&----
    *&      Form  sub_populate_sort
          Populate ALV sort table
          No Parameter
    FORM sub_populate_sort .
    Sort on material
      wa_sort-spos = '01' .
      wa_sort-fieldname = 'MATNR'.
      wa_sort-tabname = 'I_EKPO'.
      wa_sort-up = 'X'.
      wa_sort-subtot = 'X'.
      APPEND wa_sort TO i_sort .
      CLEAR wa_sort.
    Sort on plant
      wa_sort-spos = '02'.
      wa_sort-fieldname = 'WERKS'.
      wa_sort-tabname = 'I_EKPO'.
      wa_sort-up = 'X'.
      wa_sort-subtot = 'X'.
      APPEND wa_sort TO i_sort .
      CLEAR wa_sort.
    ENDFORM.
    " sub_populate_sort*&----
    *&      Form  sub_get_event
          Get ALV grid event and pass the form name to subtotal_text
          event
          No Parameter
    FORM sub_get_event .
      CONSTANTS : c_formname_subtotal_text TYPE slis_formname VALUE
    'SUBTOTAL_TEXT'.  DATA: l_s_event TYPE slis_alv_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type     = 4
        IMPORTING
          et_events       = i_event
        EXCEPTIONS
          list_type_wrong = 0
          OTHERS          = 0.
    Subtotal
      READ TABLE i_event  INTO l_s_event
                        WITH KEY name = slis_ev_subtotal_text.
      IF sy-subrc = 0.
        MOVE c_formname_subtotal_text TO l_s_event-form.
        MODIFY i_event FROM l_s_event INDEX sy-tabix.
      ENDIF.ENDFORM.
    " sub_get_event*&----
    *&      Form  sub_alv_report_display
          For ALV Report Display
          No Parameter
    FORM sub_alv_report_display .
      DATA: l_repid TYPE syrepid .
      l_repid = sy-repid .
    This function module for displaying the ALV
    report
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program       = l_repid
          i_callback_top_of_page   = 'SUB_ALV_TOP_OF_PAGE'
          is_layout                = wa_layout
          it_fieldcat              = i_fieldcat
          it_sort = i_sort
          it_events                = i_event
          i_default                = 'X'
          i_save                   = 'A'
        TABLES
          t_outtab                 = i_ekpo
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
      IF sy-subrc <> 0.
       MESSAGE i000 WITH 'Error in ALV report display'(055).
      ENDIF.
      ENDFORM.
    " sub_alv_report_display*&----
          FORM sub_alv_top_of_page
          Call ALV top of page
          No parameter
    FORM sub_alv_top_of_page.                                   "#EC CALLED*
    *To write header for the ALV
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = i_alv_top_of_page.
    ENDFORM.
    "alv_top_of_page*&----
    *&      Form  subtotal_text
          Build subtotal text
          P_total  Total
          p_subtot_text Subtotal text info
    FORM subtotal_text CHANGING
                   p_total TYPE any
                   p_subtot_text TYPE slis_subtot_text.
    Material level sub total
      IF p_subtot_text-criteria = 'MATNR'.
        p_subtot_text-display_text_for_subtotal
        = 'Material level total'(009).
      ENDIF.
    Plant level sub total
      IF p_subtot_text-criteria = 'WERKS'.
        p_subtot_text-display_text_for_subtotal = 'Plant level total'(010).
      ENDIF.
    ENDFORM.                    "subtotal_textSelection screen:
    \[removed by moderator\]
    Edited by: Jan Stallkamp on Sep 3, 2008 6:17 PM

  • How to print sub total text in ALV

    Hi All,
       I have a prblem in printing sub total text in ALV. I am passing the text for sub total in ALV layout to the field SUBTOTALS_TEXT. Even then the text is not displayed where as this is working for TOTAL with the field TOTALS_TEXT.
       Could any one provide me the solution please?
    Thanks & Regards,
    S.Lakshmi

    Hi Lakshmi,
    Please refer to the following code :
    report zalv10.
    type-pools: slis.
    data: g_repid like sy-repid,
    gs_print type slis_print_alv,
    gt_list_top_of_page type slis_t_listheader,
    gt_events type slis_t_event,
    gt_sort type slis_t_sortinfo_alv,
    gs_layout type slis_layout_alv,
    gt_fieldcat type slis_t_fieldcat_alv,
    fieldcat_ln like line of gt_fieldcat,
    col_pos type i.
    data: begin of itab,
    field1(5) type c,
    field2(5) type c,
    field3(5) type p decimals 2,
    end of itab.
    data: begin of itab1 occurs 0.
    include structure itab.
    data: end of itab1.
    data: begin of itab_fieldcat occurs 0.
    include structure itab.
    data: end of itab_fieldcat.
    Print Parameters
    parameters:
    p_print as checkbox default ' ', "PRINT IMMEDIATE
    p_nosinf as checkbox default 'X', "NO SELECTION INFO
    p_nocove as checkbox default ' ', "NO COVER PAGE
    p_nonewp as checkbox default ' ', "NO NEW PAGE
    p_nolinf as checkbox default 'X', "NO PRINT LIST INFO
    p_reserv type i. "NO OF FOOTER LINE
    initialization.
    g_repid = sy-repid.
    perform print_build using gs_print. "Print PARAMETERS
    start-of-selection.
    TEST DATA
    move 'TEST1' to itab1-field1.
    move 'TEST1' to itab1-field2.
    move '10.00' to itab1-field3.
    append itab1.
    move 'TEST2' to itab1-field1.
    move 'TEST2' to itab1-field2.
    move '20.00' to itab1-field3.
    append itab1.
    do 50 times.
    append itab1.
    enddo.
    end-of-selection.
    perform build.
    perform eventtab_build changing gt_events.
    perform comment_build changing gt_list_top_of_page.
    perform call_alv.
    form build.
    DATA FIELD CATALOG
    Explain Field Description to ALV
    data: fieldcat_in type slis_fieldcat_alv.
    clear fieldcat_in.
    fieldcat_ln-fieldname = 'FIELD1'.
    fieldcat_ln-tabname = 'ITAB1'.
    *FIELDCAT_LN-NO_OUT = 'X'. "FIELD NOT DISPLAY, CHOOSE FROM LAYOUT
    fieldcat_ln-key = ' '. "SUBTOTAL KEY
    fieldcat_ln-no_out = ' '.
    fieldcat_ln-seltext_l = 'HEAD1'.
    append fieldcat_ln to gt_fieldcat.
    clear fieldcat_in.
    fieldcat_ln-fieldname = 'FIELD2'.
    fieldcat_ln-tabname = 'ITAB1'.
    fieldcat_ln-no_out = 'X'.
    fieldcat_ln-seltext_l = 'HEAD2'.
    append fieldcat_ln to gt_fieldcat.
    clear fieldcat_in.
    fieldcat_ln-fieldname = 'FIELD3'.
    fieldcat_ln-tabname = 'ITAB1'.
    fieldcat_ln-ref_fieldname = 'MENGE'. "<- REF FIELD IN THE DICTIONNARY
    fieldcat_ln-ref_tabname = 'MSEG'. "<- REF TABLE IN THE DICTIONNARY
    fieldcat_ln-no_out = ' '.
    fieldcat_ln-do_sum = 'X'. "SUM UPON DISPLAY
    append fieldcat_ln to gt_fieldcat.
    DATA SORTING AND SUBTOTAL
    data: gs_sort type slis_sortinfo_alv.
    clear gs_sort.
    gs_sort-fieldname = 'FIELD1'.
    gs_sort-spos = 1.
    gs_sort-up = 'X'.
    gs_sort-subtot = 'X'. ***CRUCIAL STATEMENT****
    append gs_sort to gt_sort.
    clear gs_sort.
    gs_sort-fieldname = 'FIELD2'.
    gs_sort-spos = 2.
    gs_sort-up = 'X'.
    *GS_SORT-SUBTOT = 'X'. **THIS SHOULD NOT BE UNCOMENTED*
    append gs_sort to gt_sort.
    endform.
    form call_alv.
    ABAP List Viewer
    call function 'REUSE_ALV_LIST_DISPLAY'
    exporting
    I_INTERFACE_CHECK = ' '
    I_BYPASSING_BUFFER =
    I_BUFFER_ACTIVE = ' '
    i_callback_program = g_repid
    I_CALLBACK_PF_STATUS_SET = ' '
    I_CALLBACK_USER_COMMAND = ' '
    i_structure_name = 'ITAB1'
    is_layout = gs_layout
    it_fieldcat = gt_fieldcat[]
    IT_EXCLUDING =
    IT_SPECIAL_GROUPS =
    it_sort = gt_sort[]
    IT_FILTER =
    IS_SEL_HIDE =
    I_DEFAULT = 'X'
    I_SAVE = ' '
    IS_VARIANT =
    it_events = gt_events[]
    IT_EVENT_EXIT =
    is_print = gs_print
    IS_REPREP_ID =
    I_SCREEN_START_COLUMN = 0
    I_SCREEN_START_LINE = 0
    I_SCREEN_END_COLUMN = 0
    I_SCREEN_END_LINE = 0
    IMPORTING
    E_EXIT_CAUSED_BY_CALLER =
    ES_EXIT_CAUSED_BY_USER =
    tables
    t_outtab = itab1
    exceptions
    program_error = 1
    others = 2.
    endform.
    HEADER FORM
    form eventtab_build changing lt_events type slis_t_event.
    constants:
    gc_formname_top_of_page type slis_formname value 'TOP_OF_PAGE'.
    *GC_FORMNAME_END_OF_PAGE TYPE SLIS_FORMNAME VALUE 'END_OF_PAGE'.
    data: ls_event type slis_alv_event.
    call function 'REUSE_ALV_EVENTS_GET'
    exporting
    i_list_type = 0
    importing
    et_events = lt_events.
    read table lt_events with key name = slis_ev_top_of_page
    into ls_event.
    if sy-subrc = 0.
    move gc_formname_top_of_page to ls_event-form.
    append ls_event to lt_events.
    endif.
    define END_OF_PAGE event
    READ TABLE LT_EVENTS WITH KEY NAME = SLIS_EV_END_OF_PAGE
    INTO LS_EVENT.
    IF SY-SUBRC = 0.
    MOVE GC_FORMNAME_END_OF_PAGE TO LS_EVENT-FORM.
    APPEND LS_EVENT TO LT_EVENTS.
    ENDIF.
    endform.
    form comment_build changing gt_top_of_page type slis_t_listheader.
    data: gs_line type slis_listheader.
    clear gs_line.
    gs_line-typ = 'H'.
    gs_line-info = 'HEADER 1'.
    append gs_line to gt_top_of_page.
    clear gs_line.
    gs_line-typ = 'S'.
    gs_line-key = 'STATUS 1'.
    gs_line-info = 'INFO 1'.
    append gs_line to gt_top_of_page.
    gs_line-key = 'STATUS 2'.
    gs_line-info = 'INFO 2'.
    append gs_line to gt_top_of_page.
    CLEAR GS_LINE.
    GS_LINE-TYP = 'A'.
    GS_LINE-INFO = 'ACTION'.
    APPEND GS_LINE TO GT_TOP_OF_PAGE.
    endform.
    form top_of_page.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = gt_list_top_of_page.
    write: sy-datum, 'Page No', sy-pagno left-justified.
    endform.
    form end_of_page.
    write at (sy-linsz) sy-pagno centered.
    endform.
    PRINT SETTINGS
    form print_build using ls_print type slis_print_alv.
    ls_print-print = p_print. "PRINT IMMEDIATE
    ls_print-no_print_selinfos = p_nosinf. "NO SELECTION INFO
    ls_print-no_coverpage = p_nocove. "NO COVER PAGE
    ls_print-no_new_page = p_nonewp.
    ls_print-no_print_listinfos = p_nolinf. "NO PRINT LIST INFO
    ls_print-reserve_lines = p_reserv.
    endform.
    <b>Please reward points if helpful.</b>
    Regards,
    Amit Mishra

  • Short dump while doing subtotal in the ALV report

    Hi All,
    I am getting run time error while doing the sub total and total in the ALV .
    error is "MESSAGE_TYPE_X" and
    discription is  "The current application program detected a situation which really
    should not occur. Therefore, a termination with a short dump was
    triggered on purpose by the key word MESSAGE (type X)."
    Can anyone help me regarding this.
    My alv field catog is like below
      DATA: ls_fieldcat TYPE slis_fieldcat_alv,
            ls_sort     TYPE SLIS_SORTINFO_ALV.
      CLEAR:ls_fieldcat,
            ls_sort.
      REFRESH ot_fieldcat.
      ls_fieldcat-FIELDNAME   = 'LEASE_NUMBER'.
      ls_fieldcat-SELTEXT_M   = 'Lease Number'(001).
      ls_fieldcat-COL_POS     = 0.
      ls_fieldcat-OUTPUTLEN   = 10.
      ls_fieldcat-DO_SUM      = 'X'.
      ls_fieldcat-KEY         = 'X'.
      APPEND ls_fieldcat TO ot_fieldcat.
      CLEAR  ls_fieldcat.
      ls_fieldcat-FIELDNAME   = 'LEASE_TYPE'.
      ls_fieldcat-SELTEXT_M   = 'Lease Type'(002).
      ls_fieldcat-COL_POS     = 1.
      ls_fieldcat-OUTPUTLEN   = 5.
      APPEND ls_fieldcat TO ot_fieldcat.
      CLEAR  ls_fieldcat.
      ls_fieldcat-FIELDNAME   = 'LEGACY_NUM'.
      ls_fieldcat-SELTEXT_M   = 'Legacy Contract No'(003).
      ls_fieldcat-COL_POS     = 2.
      ls_fieldcat-OUTPUTLEN   = 10.
      APPEND ls_fieldcat TO ot_fieldcat.
      CLEAR  ls_fieldcat.
      ls_fieldcat-FIELDNAME   = 'CUSTOMER'.
      ls_fieldcat-SELTEXT_M   = 'Customer'(004).
      ls_fieldcat-COL_POS     = 3.
      APPEND ls_fieldcat TO ot_fieldcat.
      CLEAR  ls_fieldcat.
      ls_fieldcat-FIELDNAME   = 'STATUS'.
      ls_fieldcat-SELTEXT_M   = 'Status'(017).
      ls_fieldcat-COL_POS     = 16.
      ls_fieldcat-OUTPUTLEN   = 10.
      APPEND ls_fieldcat TO ot_fieldcat.
      CLEAR  ls_fieldcat.
      ls_fieldcat-FIELDNAME   = 'GATEIN_DT'.
      ls_fieldcat-SELTEXT_M   = 'Gate In Date'(018).
      ls_fieldcat-COL_POS     = 17.
      ls_fieldcat-OUTPUTLEN   = 10.
      APPEND ls_fieldcat TO ot_fieldcat.
      CLEAR  ls_fieldcat.
      ls_fieldcat-FIELDNAME   = 'SVALUE'.
      ls_fieldcat-COL_POS     = 18.
      ls_fieldcat-DO_SUM      = 'X'.
      ls_fieldcat-OUTPUTLEN   = 12.
      APPEND ls_fieldcat TO ot_fieldcat.
      CLEAR  ls_fieldcat.
    DATA SORTING AND SUBTOTAL
      CLEAR ls_sort.
      ls_sort-FIELDNAME = 'LEASE_NUMBER'.
      ls_sort-SPOS      = 0.
      ls_sort-UP        = 'X'.
      ls_sort-SUBTOT    = 'X'.
      APPEND ls_sort TO GT_SORT.
    If i coment the code relate dto 'SVALUE' i am getting output without sub total and total.
    if i uncomment the same then I am getting short dump.

    Hi,
    Try this coding,
    TYPE-POOLS: SLIS.                      " ALV GLOBAL TYPES
    *      FORM  F_READ_DATA
    FORM F_READ_DATA.
      SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_VBAK
               FROM VBAK
                 UP TO P_MAX ROWS
              WHERE KUNNR IN S_KUNNR
                AND VBELN IN S_VBELN
                AND VKORG IN S_VKORG.
    ENDFORM.                               " F_READ_DATA
    *      FORM  F_DISPLAY_DATA
    FORM F_DISPLAY_DATA.
      DEFINE M_FIELDCAT.
        ADD 1 TO LS_FIELDCAT-COL_POS.
        LS_FIELDCAT-FIELDNAME   = &1.
        LS_FIELDCAT-REF_TABNAME = 'VBAK'.
        LS_FIELDCAT-DO_SUM      = &2.
        LS_FIELDCAT-CFIELDNAME  = &3.
        APPEND LS_FIELDCAT TO LT_FIELDCAT.
      END-OF-DEFINITION.
      DEFINE M_SORT.
        ADD 1 TO LS_SORT-SPOS.
        LS_SORT-FIELDNAME = &1.
        LS_SORT-UP        = 'X'.
        LS_SORT-SUBTOT    = &2.
        APPEND LS_SORT TO LT_SORT.
      END-OF-DEFINITION.
      DATA:
        LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
        LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
        LT_SORT     TYPE SLIS_T_SORTINFO_ALV,
        LS_SORT     TYPE SLIS_SORTINFO_ALV,
        LS_LAYOUT   TYPE SLIS_LAYOUT_ALV.
      M_FIELDCAT 'VKORG' ''  ''.
      M_FIELDCAT 'KUNNR' ''  ''.
      M_FIELDCAT 'VBELN' ''  ''.
      M_FIELDCAT 'NETWR' 'X' 'WAERK'.
      M_FIELDCAT 'WAERK' ''  ''.
      M_SORT 'VKORG' 'X'.                  " SORT BY VKORG AND SUBTOTAL
      M_SORT 'KUNNR' 'X'.                  " SORT BY KUNNR AND SUBTOTAL
      M_SORT 'VBELN' ''.                   " SORT BY VBELN
      LS_LAYOUT-CELL_MERGE = 'X'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                IS_LAYOUT   = LS_LAYOUT
                IT_FIELDCAT = LT_FIELDCAT
                IT_SORT     = LT_SORT
           TABLES
                T_OUTTAB    = GT_VBAK.
    ENDFORM.                               " F_DISPLAY_DATA
    Regards,
    Nikhil.

  • Add a row after Total row in ALV report

    Hi Experts,
    I have a report is displayed by  ALV format(not use function module to display it but use Class cl_gui_custom_container),I want to add a row after the total row. for example,
    Customer   amount1    amount2    amount3 
    10000         1,234        1,000         2,000
    10001         4,000        2,000         1,000
    10002         1,300        1,000         3,000
    11000         1,200        4,000         3,000
         Total:     7,734        8,000         9,000
    Ratio%        31.27       32.34          36.39
    the row of 'Total' is calculated by fieldcat-do_sum = 'X' But after the Total row we need a Ratio row to display the ratio. Yes we can calculate the total amout and ratio and then append it into the output itab, but we don't like this solution.We want to keep the total function in the ALV report.Any experts can poit me a direction. Thanks in advance.
    Joe

    Djoe,
    First you need to handle the user command,in order to capture the button action. For this you need to implment a class, i  am attaching sample codes here
    In top include write the following code
    CLASS lcl_event_handler DEFINITION .
      PUBLIC SECTION .
        METHODS:
         handle_toolbar  FOR EVENT toolbar                   " To add new functional buttons to the ALV toolbar
                         OF        cl_gui_alv_grid
                         IMPORTING e_object,
         handle_user_command FOR EVENT user_command          " To implement user commands
                            OF cl_gui_alv_grid
                            IMPORTING e_ucomm .
      PRIVATE SECTION.
    ENDCLASS.                                               " Lcl_event_handler DEFINITION
    Now   <b>Class implementation</b>
    CLASS lcl_event_handler IMPLEMENTATION .
      METHOD handle_toolbar.                                " Handle Toolbar
        PERFORM f9500_handle_toolbar USING e_object.
    ENDMETHOD .                                            " Handle_toolbar
      METHOD handle_user_command .                          " Handle User Command
        PERFORM f9600_handle_user_command USING e_ucomm .
      ENDMETHOD.
    ENDCLASS .                                              " lcl_event_handler IMPLEMENTATION
    FORM f9600_handle_user_command USING p_e_ucomm TYPE sy-ucomm.
      CONSTANTS:c_newl(4) TYPE c
                          VALUE 'NEWL',               " New line
                c_copy(4) TYPE c
                          VALUE 'COPY',               " Copy
                c_corr(4) TYPE c
                          VALUE 'CORR'.               " Correction
      CASE p_e_ucomm .
        WHEN c_newl.
    Create a new line
          PERFORM f9610_insert_new_line.
    ENDFORM.                                          " f9600_handle_user_command
    FORM f9610_insert_new_line .
    *Data Declarations
      DATA: lt_rows     TYPE lvc_t_row,                 " Itab for row property
            ls_rows     TYPE lvc_s_row,                 " Work area for row
            lv_cntid    TYPE i.                         " Counter
      DATA: gv_index TYPE sy-index.
      CLEAR gs_last.
      CALL METHOD gr_alvgrid->get_selected_rows
        IMPORTING
          et_index_rows = lt_rows.
      READ TABLE lt_rows INTO ls_rows INDEX 1.
      IF sy-subrc EQ 0.
        gv_index = ls_rows-index + 1.
      ELSE.
        gv_index = 1.
      ENDIF.
      DESCRIBE TABLE gt_last LINES lv_cntid.
      lv_cntid = lv_cntid + 1.
      gs_last-cntid = lv_cntid.
      INSERT gs_last INTO gt_last INDEX gv_index.
      LOOP AT gt_last INTO gs_last FROM gv_index TO gv_index.
    Make the new line editable
        PERFORM f9611_style.
      ENDLOOP.
      CALL METHOD gr_alvgrid->refresh_table_display
        EXCEPTIONS
          finished = 1
          OTHERS   = 2.
    ENDFORM.                    " f9610_insert_new_line
    You can ask questions doubts if any!
    regards
    Antony Thomas

Maybe you are looking for

  • Nº de caracteres para item em NF de exportação entrada.

    Após a aplicação do SP12 NFs migradas via Softway "trancam" na entrada pois os caracteres configurados para os itens são enviados com 2 dígitos e o SAP esta convertendo para 1 dígitos e não reconhece o campo com os 2 dígitos. Alguém passou por este p

  • Cant turn video out on ?

    hi seem to be having a problem ,i cant seem to be able to turn video out on .silly thing.

  • I downloaded iTunes 10.5

    I have downloaded and uninstalled iTunes 10.5 about three or four times.  I have also checked to see if I had the program on my computer afterwards; it is there.  I've ran set-up so that it goes through all the crap that it needs to to install itself

  • Processing Refund checks from One time vendor

    Hi Gurus I have an issue related to refund checks from vendors with whom we have very few transactions. My question is that if I have refund check from a vendor but do not have any subsequent payment to be made, how should I enter this check in the s

  • Automatic clearing of cancelled billing document against original billing

    Hi, I have no payment received against the billing created earlier. I get the below error when i create a cancel document (vf11) - " The system cannot clear billing documents and cancellation documents because, for example individual item updating is