Regarding Subtotal Text Printing in ALV

Dear all,
I want to print some text in subtotaling.But i am not getting it..I am doing like below.
My FORM SUBTOTAL_TEXT  does not get hit al all.
Plz let me know where I am going wrong
*&      Form  GET_EVENTS
      text
-->  p1        text
<--  p2        text
FORM GET_EVENTS .
  CONSTANTS : C_FORNAME_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       = IT_EVENT
    EXCEPTIONS
      list_type_wrong = 0
      OTHERS          = 0.
Subtotal
  READ TABLE IT_EVENT INTO L_S_EVENT WITH KEY NAME = SLIS_EV_SUBTOTAL_TEXT.
  IF sy-subrc = 0.
    MOVE C_FORNAME_SUBTOTAL_TEXT TO L_S_EVENT-FORM.
    MODIFY IT_EVENT FROM L_S_EVENT INDEX SY-TABIX..
  ENDIF.
ENDFORM.                    " GET_EVENTS
*&      Form  DATA_DISPLAY
      Text-ALV Grid Display through FM REUSE_ALV_GRID_DISPLAY
FORM DATA_DISPLAY .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
   I_INTERFACE_CHECK                 = ' '
   I_BYPASSING_BUFFER                = ' '
   I_BUFFER_ACTIVE                   = ' '
     I_CALLBACK_PROGRAM                = 'ZCOMPLIANCE_WEEK'
   I_CALLBACK_PF_STATUS_SET          = ' '
     I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
     I_CALLBACK_TOP_OF_PAGE            = '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                         = I_LAYOUT
     IT_FIELDCAT                       = 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
   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                          = IT_DISPLAY.
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.                    " DATA_DISPLAY
*&      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
    P_SUBTOT_TEXT-DISPLAY_TEXT_FOR_SUBTOTAL
    = 'Material level total'(009).
ENDFORM.                    "SUBTOTAL_TEXT

just check this sample code observe the comments
REPORT ZTEST_ALV_TEXT .
type-pools : slis.
types : begin of itab_t,
ebeln like ekpo-ebeln,
lifnr like ekko-lifnr,
ekorg like ekko-ekorg,
ekgrp like ekko-ekgrp,
werks like ekpo-werks,
ebelp like ekpo-ebelp,
matnr like ekpo-matnr,
menge like ekpo-menge,
netpr like ekpo-netpr,
d, "Dummy field to fire the Subtotal text event
end of itab_t.
data: itab type table of itab_t.
data: tab type itab_t.
data : itab1 like eket occurs 0 with header line.
data: t_fcat type slis_t_fieldcat_alv,
it_sort type slis_t_sortinfo_alv,
t_events type slis_t_event,
listhead type slis_t_listheader,
ls_layout type slis_layout_alv.
start-of-selection.
select a~ebeln
a~lifnr
a~ekorg
a~ekgrp
b~werks
b~ebelp
b~matnr
b~menge
b~netpr
up to 100 rows
into corresponding fields of table itab
from ekko as a inner join ekpo as b
on a~ebeln = b~ebeln.
end-of-selection.
perform fill_fcat using t_fcat.
perform fill_event using t_events.
perform fill_layout.
perform display.
form fill_fcat using p_t_fcat type slis_t_fieldcat_alv.
data : lfcat type slis_fieldcat_alv,
colpos type i value '0'.
data : ls_sort type slis_sortinfo_alv.
colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'EBELN'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'EBELN'.
lfcat-ref_tabname = 'EKKO'.
lfcat-hotspot = 'X'.
append lfcat to p_t_fcat.
clear lfcat.
colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'LIFNR'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'LIFNR'.
lfcat-ref_tabname = 'EKKO'.
append lfcat to p_t_fcat.
clear lfcat.
colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'EKORG'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'EKORG'.
lfcat-ref_tabname = 'EKKO'.
append lfcat to p_t_fcat.
clear lfcat.
colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'EKGRP'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'EKGRP'.
lfcat-ref_tabname = 'EKKO'.
append lfcat to p_t_fcat.
clear lfcat.
colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'WERKS'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'WERKS'.
lfcat-ref_tabname = 'EKPO'.
append lfcat to p_t_fcat.
clear lfcat.
colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'EBELP'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'EBELP'.
lfcat-ref_tabname = 'EKPO'.
append lfcat to p_t_fcat.
clear lfcat.
colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'MATNR'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'MATNR'.
lfcat-ref_tabname = 'EKPO'.
append lfcat to p_t_fcat.
clear lfcat.
colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'MENGE'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'MENGE'.
lfcat-ref_tabname = 'EKPO'.
lfcat-do_sum = 'X'.
append lfcat to p_t_fcat.
clear lfcat.
colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'NETPR'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'NETPR'.
lfcat-ref_tabname = 'EKPO'.
lfcat-do_sum = 'X'.
append lfcat to p_t_fcat.
clear lfcat.
colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'D'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'EBELN'.
lfcat-ref_tabname = 'EKKO'.
lfcat-no_out = 'X'.
append lfcat to p_t_fcat.
clear lfcat.
ls_sort-spos = 1.
ls_sort-fieldname = 'EBELN'.
ls_sort-tabname = 'ITAB'.
ls_sort-up = 'X'.
ls_sort-group = 'UL'.
append ls_sort to it_sort.
clear ls_sort.
ls_sort-spos = 2.
ls_sort-fieldname = 'D'.
ls_sort-tabname = 'ITAB'.
ls_sort-up = 'X'.
ls_sort-group = 'UL'.
ls_sort-subtot = 'X'.
append ls_sort to it_sort.
endform. " fill_fcat
form fill_event using p_t_events type slis_t_event.
data : ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = p_t_events
EXCEPTIONS
LIST_TYPE_WRONG = 1
OTHERS = 2
if sy-subrc ne 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
read table p_t_events with key name = slis_ev_top_of_page
into ls_event.
if sy-subrc = 0.
move 'TOP_OF_PAGE' to ls_event-form.
append ls_event to p_t_events.
endif.
read table p_t_events with key name = SLIS_EV_SUBTOTAL_TEXT
into ls_event.
if sy-subrc = 0.
move 'SUBTOTAL' to ls_event-form.
append ls_event to p_t_events.
endif.
endform. " FILL_EVENT
FORM SUBTOTAL USING I_LISTHEAD STRUCTURE tab
I_SUBTOTAL TYPE SLIS_SUBTOT_TEXT.
*criteria type slis_fieldname,
keyword like dd03p-reptext,
criteria_text(255) type c,
max_len like dd03p-outputlen,
display_text_for_subtotal(255) type c,
if I_SUBTOTAL-criteria = 'D'.
I_SUBTOTAL-display_text_for_subtotal = 'Sub total'.
endif.
ENDFORM.
form top_of_page.
data : s_listhead type slis_listheader.
clear s_listhead.
s_listhead-typ = 'H'.
s_listhead-info = 'SIMPLE REPORT'.
append s_listhead to listhead.
s_listhead-typ = 'S'.
s_listhead-key = 'EBELN'.
s_listhead-info = 'ALV'.
append s_listhead to listhead.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = listhead
i_logo = 'ENJOYSAP_LOGO'
I_END_OF_LIST_GRID =
endform. "TOP_OF_PAGE
form fill_layout .
ls_layout-zebra = 'X'.
ls_layout-detail_popup = 'X'.
ls_layout-key_hotspot = 'X'.
ls_layout-window_titlebar = 'Test Title'.
ls_layout-totals_text = 'GRAND TOTAL'.
ls_layout-subtotals_text = 'SUB'.
endform. " fill_layout
form display .
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = sy-repid
it_sort = it_sort[]
it_events = t_events
tables
t_outtab = itab
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
if sy-subrc ne 0.
MESSAGE ID SY-MSGI D TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " display

Similar Messages

  • Subtotal text print in alv grid report

    HI all,
    I am  trying to print the text for the column e.g. "SUBTOTAL TEXT" when i click on event button on the tool bar.
    total is getting generated but text is not printing i am giving the code what i had written please tel me what changes should be done in this code .
    ***********Code
    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  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 = 'KWMENG'.
        p_subtot_text-display_text_for_subtotal    = 'Total '(009).
      ENDIF.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
       I_CALLBACK_PROGRAM                = it_repid
       I_CALLBACK_TOP_OF_PAGE            = 'TOP-OF-PAGE'                         "#EC *
       IS_LAYOUT                         = it_lay
       IT_FIELDCAT                       = it_fldct[]
       IT_EVENTS                         = i_event
      TABLES
        t_outtab                          = it_outtb
    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.                                                              "Alv_Display
    Thank you,
    Supriya.

    in order to get the subtotals and subtotal texts you need to have sort option. without sort option it is not possible to trigger this event.
    first populate the sort table then it will tirgger. check this thread for sample code
    Re: SubTotal Text in ALV?

  • Regarding subtotal text in Alv

    Hi,
         Can you please let me know how to achieve subtotal text for classical ALV reports.
    Regards,
    MNR.

    Hi,
    pl check this link
    http://wiki.sdn.sap.com/wiki/display/Snippets/DisplaysubtotaltextinALV+report
    Regards,
    Booma

  • Subtotal Text in OOPS ALV

    Hello All,
                      Can any one let me know how to display the subtotal text in OOPS ALV report .
    How can v user event SUBTOTAL_TEXT in this.
    Thanks in advanced.
    -Anmol.

    Hi Anmol,
    Do as below :-
    1) Declare event table i_event TYPE slis_t_event
    2) Declare a subrouting like *PERFORM get_event.
    2) In the subroutine, Declare a variable of type l_s_event TYPE slis_alv_event  & a constant as  CONSTANTS :     
         c_formname_subtotal_text TYPE slis_formname VALUE 'SUBTOTAL_TEXT'.
    3) call function 'REUSE_ALV_EVENTS_GET.
    4) Then Read the table I_event as below :-
    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.
    5) Declare a subroutine as Perform subtot_text
        In the subroutine subtot_text write code as below :-
    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.
    Regards
    Abhii

  • Subtotal Text in Dynamic ALV

    I have faced the problem with Subtotal Text in Dynamic ALV.
    I don't know why it is not get into "FORM subtotal_text " .
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
         i_callback_program             = sy-repid
       IS_LAYOUT                        = gw_layout
         it_fieldcat                    = gi_fieldcat[]
         it_sort                        = gi_sort[]
         it_events                      = gi_events
        TABLES
          t_outtab                       = <gi_dyntable>
       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.
    and
    *&      Form  subtotal_text
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM subtotal_text USING  p_total type ref to data
                             p_subtottxt_info TYPE slis_subtot_text.
      break-point.
    ENDFORM.                    " alv_subtotal
    Thanks in advance

    I put the form name to gi_events
    *&      Form  event_build
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM event_build .
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type = 0
        IMPORTING
          et_events   = gi_events.
      READ TABLE gi_events WITH KEY name = 'SUBTOTAL_TEXT' INTO gw_events.
      IF sy-subrc = 0.
        MOVE 'SUBTOTAL_TEXT' TO gw_events-form.
        MODIFY gi_events FROM gw_events INDEX sy-tabix.
      ENDIF.
    ENDFORM.                    " event_build

  • Regarding subtotal text and total text

    Hi All,
    can any body provide example program for ALV total text and subtotal text both using REUSE_ALV_GRID_DISPALY.  and
    using OOPS.
    @@@MODERATOR::    Please dont lock my threads.I have been searching since 2 days for this example and i tried with the provided examples .but they are not worked out ::
    FOr your information :
    Some of the links i searched in SDN: 
    http://wiki.sdn.sap.com/wiki/display/ABAP/ALVDisplayTotalTextOrSubtotalText
    Re: SubTotal Text in ALV?
    http://wiki.sdn.sap.com/wiki/display/ABAP/ALVStandardSumTotalOr+Subtotal

    Hi Naveen,
    If you are looking for specific Subtotal text in ALV Grid, then i think it is not possible.
    You can use SORT table to get sub-totals based on the columns that you display.
    Generally the record existing on the column based on which you sort the table, appears as the sub-total text automatically.....
    You can try giving Subtotal text in the LAYOUT as well and pass the layout to the ALV function module.
    Best Regards,
    Ram.

  • Sub total text in OOPs ALV

    Hi Experts,
    I need to get the subtotal text in the ALV, for which i need to handle the event sub_total text
    I see that it is not gettting trigerred.
    thanks

    Hi,
    Use the subtotal_text event of the ALV.
    Refer to this link for examples..
    [ALV Display Subtotal Text Using OO |https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/displaysubtotaltextinALV+grid]

  • How to get Subtotal text in ALV using OOPS

    hi,
    Can any one pls help me out getting  <b>subtotals text</b> in ALV using OOPS concepts....Pls provide me if any of u have  sample code for that......
    my code:
    data:gr_grid_d0100 type ref to cl_gui_alv_grid.
    data : gr_events_d0100   type ref to lcl_events_d0100.
    classes**********
    class lcl_events_d0100 definition.
      public section.
        methods:
    subtotal_text for event subtotal_text
                        of cl_gui_alv_grid
                        importing es_subtottxt_info
                        ep_subtot_line
                        e_event_data.
    endclass.
    class lcl_events_d0100 implementation.
    method subtotal_text.
        perform d0100_event_subtotal_text using       es_subtottxt_info
    ep_subtot_line
    e_event_data.
      endmethod.                    "subtotal_text
    endclass.
    data : gr_event_handler type ref to lcl_events_d0100.
    SET HANDLER gr_event_handler->subtotal_text FOR wcl_alv_grid_request
    FORM d0100_event_subtotal_text USING
          es_subtottxt_info TYPE LVC_S_STXT
          ep_subtot_line TYPE REF TO data
          e_event_data TYPE REF TO cl_alv_event_data.
      DATA: l_text TYPE string.
      l_text = es_subtottxt_info.
      FIELD-SYMBOLS: <fs> TYPE ANY.
      ASSIGN e_event_data->m_data->* TO <fs>.
                            <fs> = text-007.

    hi vijay
    check this code
    if you want to use field symbols.
    data: total type ref to data,
    subtotal1 type ref to data.
    field-symbols <total> like gt_sflight.
    field-symbols <subtotal1> like gt_sflight.
    call method grid1->get_subtotals
    importing
    ep_collect00 = total
    ep_collect01 = subtotal1.
    assign total->* to <total>.
    assign subtotal1->* to <subtotal1>.
    or u can use
    U have to do the subtotal column wise.In the field catalog specify the following in addition to the corresponding field name(i.e. Column)
    DATA ls_fcat TYPE lvc_s_fcat.
    ls_fcat-do_sum = 'X'.
    Hope this helps u out.
    Thanks & Regards,
    naveen

  • How can we change the Subtotal text in alv  , urgent.

    hi,
    i want to maintain the text at subtotal level in an ALV.here i am using standard alv.not abap oops. i tried with the event subtotal_text but the form was not triggering in the progam.please provide some sample code.

    Hi,
    See This code .
    Reward if its usefull.
    Regards,
    Durgaprasad.
    *& Report  ZALV1
    REPORT  ZALV1.
    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

  • SUBTOTAL TEXT IN ALV GRID

    HI ALL,
    could any one  send me how to display the subtotal Text  in ALV grid output with code sample.
    with thanks.
    kannan

    hi,
    means u want to print some text instead of star ( coming in subtotal) ?
    If so than try like,
    *& Report  ZALV_LIST
    REPORT  zalv_list.
    TABLES : mseg.
    TYPE-POOLS : slis.
    DATA : BEGIN OF itab OCCURS 0,
            mblnr LIKE mseg-mblnr,
            matnr LIKE mseg-matnr,
            werks LIKE mseg-werks,
            menge LIKE mseg-menge,
            line_color(4) TYPE c,
           END OF itab.
    DATA : BEGIN OF itab1 OCCURS 0,
            mblnr LIKE mseg-mblnr,
            matnr LIKE mseg-matnr,
            werks LIKE mseg-werks,
            menge LIKE mseg-menge,
            line_color(4) TYPE c,
           END OF itab1.
    DATA : t_fcat TYPE slis_t_fieldcat_alv,
           t_eve TYPE slis_t_event,
           t_subtot TYPE slis_t_sortinfo_alv,
           subtot LIKE LINE OF t_subtot,
           wa_fcat LIKE LINE OF t_fcat,
           gd_layout    TYPE slis_layout_alv.
    DATA : gt_menge LIKE mseg-menge,
           st_menge LIKE mseg-menge.
    SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS : doc FOR mseg-mblnr.
    SELECTION-SCREEN : END OF BLOCK blk1.
    INITIALIZATION.
      PERFORM build_cat USING t_fcat.
      PERFORM build_eve.
      PERFORM build_layout.
    START-OF-SELECTION.
      PERFORM get_data.
      PERFORM display.
    *&      Form  build_cat
          text
         -->TEMP_FCAT  text
    FORM build_cat USING temp_fcat TYPE slis_t_fieldcat_alv.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MBLNR'.
      wa_fcat-seltext_m = 'Material Doc.'.
      APPEND wa_fcat TO temp_fcat.
      CLEAR wa_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MATNR'.
      wa_fcat-seltext_m = 'Material'.
      APPEND wa_fcat TO temp_fcat.
      CLEAR wa_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'WERKS'.
      wa_fcat-seltext_m = 'Plant'.
      APPEND wa_fcat TO temp_fcat.
      CLEAR wa_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MENGE'.
      wa_fcat-seltext_m = 'Quantity'.
    wa_fcat-do_sum = 'Y'.
      APPEND wa_fcat TO temp_fcat.
      CLEAR wa_fcat.
    subtot-spos = 1.
    subtot-fieldname = 'MBLNR'.
    subtot-tabname = 'ITAB'.
    subtot-up = 'X'.
    subtot-group = 'X'.
    subtot-subtot = 'X'.
    subtot-expa = 'X'.
    APPEND subtot TO t_subtot.
    ENDFORM.                    "build_cat
    *&      Form  build_eve
          text
    FORM build_eve.
      DATA : wa_eve TYPE slis_alv_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type     = 0
        IMPORTING
          et_events       = t_eve
        EXCEPTIONS
          list_type_wrong = 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.
      READ TABLE t_eve WITH KEY name =  slis_ev_top_of_page
                             INTO wa_eve.
      IF sy-subrc = 0.
        MOVE 'TOP_OF_PAGE' TO wa_eve-form.
        APPEND wa_eve TO t_eve.
      ENDIF.
    ENDFORM.                    "build_eve
    *&      Form  build_layout
          text
    FORM build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-info_fieldname =      'LINE_COLOR'.
      gd_layout-subtotals_text = 'Sub Total'.
    ENDFORM.                    " BUILD_LAYOUT
    *&      Form  get_data
          text
    FORM get_data.
      SELECT mblnr matnr werks menge FROM mseg INTO CORRESPONDING FIELDS OF TABLE itab
      WHERE mblnr IN doc.
      SORT itab BY mblnr.
      LOOP AT itab.
        AT NEW mblnr.
          LOOP AT itab WHERE mblnr = itab-mblnr.
            st_menge = st_menge + itab-menge.
            itab1-mblnr = itab-mblnr.
            itab1-matnr = itab-matnr.
            itab1-werks = itab-werks.
            itab1-menge = itab-menge.
            APPEND itab1.
          ENDLOOP.
          itab1-mblnr = 'Sub_Total'.
          itab1-matnr = ''.
          itab1-werks = ''.
          itab1-menge = st_menge.
          itab1-line_color = 'C710'.
          APPEND itab1.
          itab1-line_color = ''.
          CLEAR st_menge.
        ENDAT.
      ENDLOOP.
      LOOP AT itab.
        gt_menge = gt_menge + itab-menge.
      ENDLOOP.
      itab1-mblnr = 'Total'.
      itab1-matnr = ''.
      itab1-werks = ''.
      itab1-menge = gt_menge.
      itab1-line_color = 'C310'.
      APPEND itab1.
    ENDFORM.                    "get_data
    *&      Form  display
          text
    FORM display.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
         i_callback_program             = 'ZALV_LIST'
         is_layout                      = gd_layout
         it_fieldcat                    = t_fcat
        it_sort                        = t_subtot
         it_events                      = t_eve
        TABLES
          t_outtab                       = itab1
    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_of_page
          text
    FORM top_of_page.
      WRITE:/ 'Data'.
    ENDFORM.                    "top_of_page
    reward if useful....
    Edited by: Dhwani shah on Dec 20, 2007 1:20 PM

  • Subtotal Text in ALV

    Hi all,
    I wanted to display subtotal and total text in the output.
    I searched in SDN and specified subtotal_text in Layout.
    But still i am not getting the subtotal Text in  output.
    Here is my code.....
    Please help me , where i did wrong?
    REPORT  YTEST_ALV.
    Tables VBAK.
    Type-pools: slis.
    INITIALIZATION.
    Types: Begin of TY_VBAK,
             vbeln type vbak-vbeln,
             ERDAT TYPE VBAK-ERDAT,
             ERNAM TYPE VBAK-ERNAM,
             NETWR TYPE VBAK-NETWR,
             WAERK TYPE VBAK-WAERK,
             VKORG TYPE VBAK-VKORG,
           End Of TY_VBAK.
    DATA: IT_VBAK TYPE STANDARD TABLE OF TY_VBAK,
          IT_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
          WA_FLDCAT LIKE LINE OF IT_FLDCAT,
          GD_LAYOUT TYPE STANDARD TABLE OF SLIS_LAYOUT_ALV WITH HEADER LINE,
    *TO DISPLAY THE LIST BY SORTING A PARTICULAR COLUMN
          it_sortcat   type slis_sortinfo_alv occurs 1,
          wa_sort like line of it_sortcat.
    START-OF-SELECTION.
    SELECT-OPTIONS : S_VBELN FOR VBAK-VBELN.
    PERFORM DATA_RETRIEVAL.
    PERFORM BUILD_FLDCAT.
    PERFORM BLD_LAYOUT.
    PERFORM BUILD_SORTCAT.
    PERFORM DISPLAY_LIST.
    PERFORM TOP_OF_PAGE.
    *&      Form  DATA_RETRIEVAL
          text
    -->  p1        text
    <--  p2        text
    form DATA_RETRIEVAL .
    SELECT vbeln
           ERDAT
           ERNAM
           NETWR
           WAERK
           VKORG
           FROM VBAK INTO TABLE IT_VBAK WHERE VBELN IN S_VBELN.
    endform.                    " DATA_RETRIEVAL
    *&      Form  BUILD_FLDCAT
          text
    -->  p1        text
    <--  p2        text
    form BUILD_FLDCAT .
    WA_FLDCAT-FIELDNAME = 'VBELN'.
    WA_FLDCAT-SELTEXT_L = 'Sales Order No'.
    *WA_FLDCAT-EMPHASIZE = 'C013'.
    WA_FLDCAT-COL_POS = 0.
    APPEND WA_FLDCAT TO IT_FLDCAT.
    WA_FLDCAT-FIELDNAME = 'ERDAT'.
    WA_FLDCAT-SELTEXT_L = 'Date'.
    WA_FLDCAT-COL_POS = 1.
    APPEND WA_FLDCAT TO IT_FLDCAT.
    WA_FLDCAT-FIELDNAME = 'ERNAM'.
    WA_FLDCAT-SELTEXT_L = 'UserName'.
    WA_FLDCAT-COL_POS = 2.
    APPEND WA_FLDCAT TO IT_FLDCAT.
    WA_FLDCAT-FIELDNAME = 'NETWR'.
    WA_FLDCAT-SELTEXT_L = 'Amount'.
    WA_FLDCAT-COL_POS = 3.
    WA_FLDCAT-DO_SUM = 'X'.
    APPEND WA_FLDCAT TO IT_FLDCAT.
    WA_FLDCAT-FIELDNAME = 'WAERK'.
    WA_FLDCAT-SELTEXT_L = 'Currency'.
    WA_FLDCAT-COL_POS = 4.
    APPEND WA_FLDCAT TO IT_FLDCAT.
    WA_FLDCAT-FIELDNAME = 'VKORG'.
    WA_FLDCAT-SELTEXT_L = 'Sales Organisation'.
    WA_FLDCAT-COL_POS = 5.
    APPEND WA_FLDCAT TO IT_FLDCAT.
    endform.                    " BUILD_FLDCAT
    FORM BLD_LAYOUT.
    GD_LAYOUT-NO_INPUT = 'X'.
    GD_LAYOUT-TOTALS_TEXT = 'Total'.
    GD_LAYOUT-subtotals_text = 'SubTotal'.
    APPEND GD_LAYOUT.
    ENDFORM.
    *&      Form  DISPLAY_LIST
          text
    -->  p1        text
    <--  p2        text
    form DISPLAY_LIST .
    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            = '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                         = GD_LAYOUT
       IT_FIELDCAT                        = IT_FLDCAT
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
       IT_SORT                           = it_sortcat
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
       I_SAVE                            = 'X'
      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                          = IT_VBAK.
    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_LIST
    *&      Form  TOP_OF_PAGE
          text
    -->  p1        text
    <--  p2        text
    form TOP_OF_PAGE .
    DATA: IT_HEADER TYPE SLIS_T_LISTHEADER,
          WA_HEADER TYPE SLIS_LISTHEADER.
          WA_HEADER-TYP = 'H'.
          WA_HEADER-INFO = 'WELCOME HEADER'.
          APPEND WA_HEADER TO IT_HEADER.
          WA_HEADER-TYP = 'S'.
          WA_HEADER-KEY = 'REPORT'.
          WA_HEADER-INFO = SY-REPID.
          APPEND WA_HEADER TO IT_HEADER.
          WA_HEADER-TYP = 'S'.
          WA_HEADER-KEY = 'DATE'.
          CONCATENATE SY-DATUM6(2) '/'  SY-DATUM4(2) '/' SY-DATUM+0(4)       inTO WA_HEADER-INFO.
         WA_HEADER-INFO = SY-DATUM.
          APPEND WA_HEADER TO IT_HEADER.
          CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
            EXPORTING
              it_list_commentary       = IT_HEADER.
            I_LOGO                   =
            I_END_OF_LIST_GRID       =
            I_ALV_FORM               =
    endform.                    " TOP_OF_PAGE
    *TO DISPLAY THE LIST BY SORTING A PARTICULAR COLUMN
    *&      Form  BUILD_SORTCAT
          text
    -->  p1        text
    <--  p2        text
    form BUILD_SORTCAT .
      wa_sort-spos      = 1.
      wa_sort-fieldname = 'ERDAT'.
      wa_sort-SUBTOT    = 'X'. "subtotals any totals column by this field
      APPEND wa_sort TO it_sortcat.
    endform.                    " BUILD_SORTCAT

    Hi Elan,
    *& Report  Z_ALV_SUBTOTAL
    REPORT z_alv_subtotal.
    *& 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:
    * Internal table to store EKPO 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_text
    If found helpfull do reward.
    Regards.
    Eshwar.

  • Query on ALV List Subtotal texts

    Hi,
    I am using the FM REUSE_ALV_LIST_DISPLAY and my internal table would have data categorized by for ex. two company codes 1000 and 2000.
    My requirement is for the subtotal text to display something like this during the subtotals-
    Total: 1000 <Company code text for 1000>
    instead of the existing
    <w_fieldcat-seltext_> 1000.
    I have tried changing the field seltext_l in the  fieldcat for the first field 'BUKRS', which is working. But i need the changed value of the company code (i.e. like "Total: 2000 <company code text for 2000>" at the next summation level, which i am unable to get as the fieldcat modifications do not reflect in between the ALV list.
    I have also tried changing layout-subtotals_text, but of no use.
    Any pointers/help would be useful.
    Thanks in advance,
    Daksh.

    You need activate the event for SUBTOTAL TEXT and handle the text in there. There is a sample program in BCALV which does the same, take a look at that.
    Regards,
    Ravi
    Note : Please mark all the helpful answers

  • Reg: Subtotal text in alv grid.

    Hi All,
    I need to display the subtotal text in ALV.
    If:
    data: i_layout type slis_layout_alv.
    Then, we can used
    i_layout-subtotal_text = ‘my subtotal text’.
    But my declaration is :
    Data: ls_layout   type lvc_s_layo.
    This dosnt have subtotaltext.
    I have tried the method:
    method subtotal_text.
        perform event_subtotal_text using es_subtottxt_info
                                          ep_subtot_line
                                          e_event_data.
    and also used the handle.
    as per the coding in : BCALV_TEST_GRID_EVENTS
    Still its not working.
    Waiting for your valuable inputs.
    Thanks & Regards,
    Anjali

    Hi Anjali,
    Try this sample code.
    REPORT z_demo_alv_sort.
    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
    Hope this helps,
    Thanks,
    Priya.

  • Subtotal Text not displaying in ALV

    Hi All,
    Text Sub total is not displayed in my ALV output. Below is my code snippet.
    Edited by: Manas@SAP on Jul 22, 2010 3:08 PM

    Hi,
    Through this way it is difficult to understand....try to make it more readable form.
    Nevertheless,please visit the links:
    1. http://wiki.sdn.sap.com/wiki/display/Snippets/DisplaysubtotaltextinALV+grid
    2. http://help.sap.com/saphelp_bw/helpdata/en/ee/c8e056d52611d2b468006094192fe3/content.htm
    3. Passing the Total/Subtotal Text in ALV
    These links gives you the idea about the subtotal_text.
    May this info helps you.
    Regards.
    DS

  • Subtotal text in the 3rd column of the alv list

    Hi Guru,
    Can anyone know or have some codes on how to implement a subtotal text in the 3rd column of the ALV list. Im using FM REUSE_ALV_HIERSEQ_LIST_DISPLAY to display the report.
    Please give some advise or help.
    Thanks and rewards is given.

    Hi my friend,
    Insted Using FM REUSE_ALV_HIERSEQ_LIST_DISPLAY
    better use REUSE_ALV_GRID_DISPLAY.
    in that 
            it_sort            = i_sort[]
      constants :     c_x       type char1 value 'X'.
        l_rec_fieldcat_wa-do_sum    = c_x.
      endif.

Maybe you are looking for

  • Acrobat XI Invalid Serial Number After Failed Install

    Hello,    We currently have Adobe Acrobat XI on an enterprise license. I went to install this on 3 of our Windows 7 tablets. Prior to my attempt, I removed Adobe Reader XI which is what I always do. After that I started the installer on the machine a

  • Oracle 10g AS - change of address in IE addressbar

    Hello, Users of my Application has to put following address in the addressbar of IE: http://some.ip.address:8889/forms90/f90servlet but I want to configure it in a way that they simply have put my domain name e.g. http://myApplication/ or http://myDo

  • DVD won't play in Macbook

    Hi, I have a dvd I purchased from my yoga instructor (so produced professionally (but not that professionally). When I insert the disc into my mac, it whirrs and I get the following error: There was an initialization error There was an error reading

  • Inconsistent placement of anchored text frame in data merge document

    Just writing up this bug so that anyone else who encounters it can find out what's going on with less head-scratching. It seems that InDesign's data merge feature gets confused when there are anchored objects in a text frame that's anchored inside an

  • BAPI parameters

    Hi all, It is told that we have to create a structure in order to pass input values to a BAPI, whether it is via import paramter or tables parameter. When i tried to declare a import parameter with TYPE declaration also BAPI was generated and worked