Subtotal

Hi,
i need to get subtotal title in ALV report.
for eg:
N1               100
N1                200
N2                300
N2                400
N1        
SUBTOTAL                 300
N2
SUBTOTAL                700
TOTAL                        1000

hi,
try this...
*& 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'.
  APPEND wa_fcat TO temp_fcat.
  CLEAR wa_fcat.
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.
  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'.
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.
APPEND 'Total' TO itab.
  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

Similar Messages

  • Field should not display in the subtotal row in ALV report after sorting .

    we have a requirement, after sorting and subtotaling, the output in ALV is -
    vbeln        amount1  amount2  amount3
    123           11              12            13
    123           12             13             14
    123           23             25             27 
    133           11              12            13
    133           12             13             14
    133           23             25             27
    Now the customer wants the ALV outpput in this fashion -
    123           11              12            13
    123           12             13             14
                     23             25             27    --->123 (vbeln) should not come in subtotaling row
    133           11              12            13
    133           12             13             14
                      23             25             27--->133(vbeln) should not come in subtotaling row

    Hi,
    if it helps you could create a hierachy. In this way you can define the field catalog for the lines and for the subtotal columns. The only thing is that you would always show the subtotal rows.
    You have references of hierachy alvs in
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c060fcb4-2c62-2b10-d2b2-f32407a5cc6f
    ALV Hierarchy
    alv hierarchy
    In this case it also sorts
    Sorting for ALV hierarchy
    I hope it helps.
    Edited by: Oscar Pecharroman on Aug 2, 2010 1:13 PM

  • Goods receipt subtotal is showing zero instead sum of quantity..!

    Hi Guys,
    1. Goods movement subtotal showing 0 instead of the total of the quantity.
    The check throwing the following error message.
    Update control of movement type is incorrect (entry 122 X X)
    Message no. M7226
    2. Purchase order data tab not showing item details for variance items but showing the message
    "This item has not been ordered."  But the PO items are ordered and present in the PO.
    Please find the screen shots.
    Thanks
    Sam

    Hi Sam,
    Kindly  Check table T156SC entries there is a entry missing in the table.
    And if required so kindly Maintain the missing entries in table.
    If entries of movement type 101 are prefect then
    Goto Transaction  -- SE37 ,
    Function module -- MB_CONTROL_MOVETYPE_GET_SINGLE
    Kindly do Set a break point to select statement which is failing at the table above at both the systems.You should be able to crack the error.
    Hope this will help you to solve the issue.
    And if not Kindly let us know.
    Thanks & Regards
    Ritesh Kumar

  • Transfer from Subtotal in one table to another sheet.

    Hi, about a year ago i made a salary application for my production company. This works quite well, but when I supposed to report amounts for each employed to the swedish tax authorities I am still not automatic because I haven't solved how to transfer a subtotal sum to a specific cell in another sheet. I am sure that this has been discussed earlier, but in the searches I have done I can't find a similar question. So if someone has an idea where to look or knows if it is possible.
    What I would need is to have a formula like LOOKUP (I guess that is the english formula for looking up references) or similar so that I can identify a Subtotal for a specific class of rows (i.e. salaries for one person).

    Thanks for the reply. If I understand you correctly the approach is simple an genial. I am all the time using and thinking within the frame of the elegant sorting functions that you find in the tables. Very easy to use when you need a quick result, though as far as I can see impossible to bring with you. But of course just put the conditions i a Sum.if. Simple!
    Thanks.
    Leif

  • Subtotal issue when subtotaling on a calc field built using CASE function

    Okay, I hpe I can explain this well. May be possible that this is something cannot handle in Discoverer. I am using Discoverer Plus to develop a new workbook - cross project expenditure inquiry. A requirement is to not allow a worksheet user to see labor cost (since possible to figure out someone's salary) amount unless they are allowed to view labor cost. I have a function that returns a Y/N value that tells me if they can view labor cost. That works out just fine. So what I am doing is taking my database cost column (which is defined as Number(22,5) in the Oracle table. I create a new calculated column, basically like this -
    CASE WHEN expenditure type <> LABOR THEN cost WHEN view labor cost = 'Y' THEN cost ELSE NULL END.
    That calculated column is working just fine. I am seeing my desired results in that column. Okay so far.
    Next, the users want subtotals by project organization and project. So I created a new total. When I did that, my subtotal row amount is blank.
    Okay, I have seen this happen with NULLS before. Like in the gl_je_lines tables, where the accounted_Dr and accounted_Cr may be null, and have to do a NVL function to convert the null to 0 and allow me to subtotal on the column in a Discoverer workbook.
    So I tried creating a second calculation -
    NVL(Cost,0)
    So I return the cost if not null, otherwise I return 0. Second calc column results look okay.
    Now I did a subtotal on the second calculation. Oops. Wrong result. Amount is shown as 0.
    For grins, I went back to my CASE statement on my first calculation and changed the ELSE condtion from NULL to 0. When I did that, the subtotal on that column changes from a blank (Null) value to a 0 value. Well, better, but still just like my second calculation subtotal.
    Obviously the users have the option to export to Excel and subtotal in Excel.
    Does anyone know of a way to get a good subtotal in this kind of situation, where I am attempting to subtotal on a calculated field that is built on a CASE function? Or am I out of luck when it comes to Discoverer?
    John Dickey

    Okay, I did find a workaround, though I do not understand why the workaround works, but why the way I first tried to get a subtotal did not work. What I did is that I had to go to Discoverer Administrator. I picked my folder and did an Insert/Item. I created my new item building the same CASE statement that I used in my worksheet to create a new calculation. I then closed Discoverer Plus and reopened Discoverer Plus. Opened my worksheet. Edited the worksheet and brought in my new (derived) item from my folder. Then I created my subtotals for this secured cost amount. Voila. I get a number now, and the subtotal amount appears to be correct (still testing/verifying, but looks okay so far). So I deleted my subtotals on my calculated column and then deleted the calculation, to get that stuff out of the report. Sure would be nice if there was documentation in the Discoverer manuals about this.
    John Dickey

  • IPC Java routine for subtotal

    Hi All,
    I am a java developer new to SAP and IPC CRM pricing, the below subtotal routine is already implemented in ECC,we need to implement the same in CRM.
    FORM FRM_KONDI_WERT_906.
    *{   INSERT         SE1K900344                                        1
    if xkomv-kinak na 'AKLMXZ'.
        komp-ZZWI1 = xkwert.
    alternative solution if formula is used several times:
      add xkwert to komp-ZZWI1.
      endif.
    *}   INSERT
    ENDFORM.
    Please help on this.
    Regards
    Sabarinathan

    I am a java developer new to SAP and IPC CRM pricing
    Writing IPC pricing exits requires not just Java. It requires basic understanding of SD pricing and CRM / IPC pricing.
    IF
         you have
         Java knowledge AND
         SD Pricing knowledge AND
         CRM / IPC Pricing knowledge
    THEN
    DO
        IPC exit programming happily.
    ELSEIF
         you have time
         _Please_ get some basic knowledge in the above items.
    ELSE
         Engage someone who knows the stuff.
    ENDIF

  • Problem with subtotal, and the total icon is not displayed at the toolbar

    Hi all,
    I'm currentlyhaving difficulties working with the subtotal and the grandtotal. I have the code in the right place like the sort table
      CLEAR k_sort.
      ADD 1 TO k_sort-spos.
      k_sort-fieldname = pv_fieldname.
      k_sort-up        = c_x.
      k_sort-subtot    = pv_subtot.
      APPEND k_sort TO i_sort.
    and the fieldcatalog
      CLEAR k_fieldcat.
      add 1 to k_fieldcat-col_pos.
      k_fieldcat-fieldname  = pv_fieldname.
      k_fieldcat-tabname    = c_tabname.
      k_fieldcat-seltext_l  = pv_seltext.
      k_fieldcat-outputlen  = pv_outputlen.
      k_fieldcat-datatype   = pv_datatype.
      k_fieldcat-do_sum     = pv_dosum.
      APPEND k_fieldcat TO i_fieldcat.
    but it didn't seems to show both the total and subtotal. Even the icon is not displayed at the ALV toolbar. The field which I need the total is a currency field. I even try other fields (interger fields) but with no luck. I'm using REUSE_ALV. Any help is greatly appreciated.

    hi,
    In field catalog for the particular column which you want to sum make that as 'X'.
    say
    WHEN'MATNR'.
    it_fcat-do_sum = 'X'.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_callback_program     = report_id
                i_grid_title           = ws_title
    *            i_callback_top_of_page = 'TOP-OF-PAGE'
                is_layout              = wa_layout
                it_fieldcat            = i_fieldcat[]
                it_sort                = i_sortcat
                i_save                 = 'A'
                it_events              = i_events
           TABLES
                t_outtab               = i_reportdata1
           EXCEPTIONS
                program_error          = 1
                OTHERS                 = 2.
      IF sy-subrc <> 0.
    This will enable.

  • ALV Grid Control -  Modifiy data in total and subtotal lines

    Hello all,
    I´am creating a report using ALV Grid Control. This report calculates (using delivered and returned materials) for each vendor/material-combination the return quote.
    Using the totals and subtotals function for different characteristics I want to calculate the return quote for the selected characteristic. Example:
    Material delivered returned quote
    ..4711 . . . 500 . . . 5 . . . . 1 (=returned*100/delivered)
    ..4711 . . . 400 . . . 10 . . . . 2,5
    . SUM . . . 900 . . . 15 . . . . 3,5 <-- 3,5 is the sum but I want display the calculated value 1,667
    Is there a possibility to modify data in the total and subtotal lines.
    Thank you for your answer
    Best regards
    Thomas

    you said instead of 3.5 you want to show 1,667 ..
    how is it possible...
    3,5 become 1,667
    i thought you are doing any conversions...
    vijay

  • 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.

  • Subtotal in Blocked ALV

    Hi All,
    I am facing the problem in displaying the subtotal in Blocked ALV.
    My requirement is, I need to display the subtotals in 3 lines like below.
    for ex:
    subtotal:          7 <above total>
                          (5)<coming from someother field>
                           2
    from the above: 7 is total of that column.
                              5 is coming from some other field.
                              2 is substraction of above 2.
    Could anyone please help me in the above.
    Many thanks in advance.
    Regards,
    venkat.

    Hi Vaibhav,
    Thanks for your response.
    and one thing here in my above example is,  the value  5 is neither total nor subtotal. its just a different value coming from some other field.
    only the 7 is total of that column.
    and if I write that logic manually, It may not able display as the position of that column is around 500. because write statment may display upto 252nd position in the output, I guess.
    thank you very much.
    Regards,
    Venkat.
    Edited by: venkat reddy on Jan 18, 2010 8:45 PM

  • Total count to be displayed in subtotal ALV(GRID Display)

    Hello ,
    I want to display total count in subtotal.
                                 720 Mr JORGE 522,06
                                 720 Mr JORGE 566,23
                                 720 Mr JORGE 100,33
                                 720 Mr JORGE 123,33
                                 720 Mr JORGE 332,22     
    subtotal ->            720                  1644.2  Count 5
                                 888 Ms Mariam 100,00
    subtotal ->            888                    100,00 Count 1
    Is this possible?  Plz dont post same answers how to display subtotal. I am able to display subtotal , only  issue is to display  with count.
    Edited by: Vimalnair on Aug 19, 2009 9:37 AM

    Hi,
    You cannot have subtotal for particular number of rows of ALV,
    but if you want to get the total number of rows of the ALV data display
    you can describe your final internal table from which the data is
    getting displayed in ALV output and get it displayed in the header
    or footer area of the ALV output.
    For Eg:
    DATA V_LINES TYPE I.
    DESCRIBE TABLE IT_FINAL LINES V_LINES.
    DATA: it_header TYPE slis_t_listheader,
          wa_header TYPE slis_listheader.
      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          = 'PF_STATUS'
          i_callback_user_command           = 'COMM'
          i_callback_top_of_page            = 'TOP'   "This top will call the subroutine namely TOP
    FORM top.
      REFRESH it_header.
      wa_header-typ = 'S'.
      wa_header-key = text-001.
      wa_header-info = sy-repid.
      APPEND wa_header TO it_header.
      CLEAR wa_header.
      wa_header-typ = 'S'.
      wa_header-key = text-002.
      wa_header-info = sy-uname.
      APPEND wa_header TO it_header.
      CLEAR wa_header.
      wa_header-typ = 'S'.
      wa_header-key = text-003.
      wa_header-info = V_LINES.    "This will print the total number of lines in the header
      APPEND wa_header TO it_header.
      CLEAR wa_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
    Hope it helps
    Regards
    Mansi

  • Hide subtotal based on the values not the field.

    Hi,
    i am developing an ALV(FM) report to display the status of the Sale order (cleared and not cleared). my need in this is
    1. i need to show the subtotal of the cleared sales orders values only and hide the not cleared SO values.
    2. while sorting by status, i want to show the status for each rows rather than displaying on the whole.
    please provide me some hints for this.
    thanks in advance.

    Hi,
    Have you appended the fields to sort table like this:
    it_sort-fieldname = 'Item Field'.
    IT_SORT-TABNAME = 'GI_FINAL'.
    IT-SORT-SPOS = '2'.
    IT_SORT-SUBTOT = 'X'.
    IT-SORT-UP = 'X'.
    APPEND IT-SORT.
    it_sort-fieldname = "Header Field'.
    IT_SORT-TABNAME = 'GI_FINAL'.
    IT-SORT-SPOS = '1'.
    IT_SORT-SUBTOT = 'X'.
    IT-SORT-UP = 'X'.
    APPEND IT-SORT.
    HERE SPOS IS SORTING POSITION...
    LIKE IN YOUR ITAB..
    SORT ITAB BY Header-field and Item-field.
    THE PREFERENCE OF SORTING....
    Regards,
    Kumar.

  • Subtotal calculation display in ALV report

    hi,
    i had made a report n alv which is almost complete but i want to add the feature that when i click on a field when output is displayed den the subtotal of all qty fields should be shown also.
    plz provide me with useful example as i am using the concept of INTERNAL TABLES.
    plzz reply fast as it is important to me and definately rewarded.

    Hi ric,
    check out this code.
    *& Report  ZST_ALV
    REPORT  ZST_ALV.
    type-POOLs: slis.
    --ALV Related Variables--
    DATA: lt_fcat          TYPE slis_t_fieldcat_alv,
          lw_fcat          TYPE slis_fieldcat_alv,
          lv_variant       TYPE disvariant,
          lv_layout        TYPE slis_layout_alv,
          lt_sort          type slis_t_sortinfo_alv,
          lw_sort          type slis_sortinfo_alv.
    types: begin of ty_vbap,
           vbeln type vbap-vbeln,
           posnr type vbap-posnr,
           zmeng type vbap-zmeng,
           end  of ty_vbap.
    data: lt_vbap type table of ty_vbap.
    start-of-selection.
    select vbeln posnr zmeng
           from  vbap
           into  table lt_vbap.
    sort lt_vbap descending.
    clear lw_fcat.
    lw_fcat-fieldname = 'VBELN'.
    lw_fcat-seltext_l = 'Sales document'.
    append lw_fcat to lt_fcat.
    clear lw_fcat.
    lw_fcat-fieldname = 'POSNR'.
    lw_fcat-seltext_l = 'Sales document'.
    append lw_fcat to lt_fcat.
    clear lw_fcat.
    lw_fcat-fieldname = 'ZMENG'.
    lw_fcat-seltext_l = 'Sales document'.
    lw_fcat-do_sum = 'X'.
    append lw_fcat to lt_fcat.
    lw_sort-spos = 1.
    lw_sort-fieldname = 'VBELN'.
    LW_SORT-Up = 'X'.
    append lw_sort to lt_sort.
    clear lw_sort.
    lw_sort-spos = 3.
    lw_sort-fieldname = 'ZMENG'.
    LW_SORT-Up = 'X'.
    lw_sort-subtot = 'X'.
    append lw_sort to lt_sort.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
      I_CALLBACK_PROGRAM                = ' '
      I_CALLBACK_PF_STATUS_SET          = ' '
      I_CALLBACK_USER_COMMAND           = ' '
      I_CALLBACK_TOP_OF_PAGE            = ' '
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      =
      I_GRID_SETTINGS                   =
      IS_LAYOUT                         =
       IT_FIELDCAT                       = lt_fcat[]
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
       IT_SORT                           = lt_sort[]
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
      I_SAVE                            = ' '
      IS_VARIANT                        =
      IT_EVENTS                         =
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      I_HTML_HEIGHT_TOP                 = 0
      I_HTML_HEIGHT_END                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
      TABLES
        T_OUTTAB                          = lt_vbap
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    regards,
    Santosh Thorat

  • Subtotal in ALV grid for a particular type and Grand total in ALV

    Hi,
    I need to have sub total for a particular type(eg: goods, services).. and grand total at end in ALV grid..
    ALV output required as below:
    Type     VAT registration number     Country      Total Gross Amounts       Total Tax Amounts       Total Amount, ex-tax
    Goods     ATU12345678     AT                  222.42      0         222.42
    Goods     NL123456789B02     NL               3,417.00      0      3,417.00
         Goods Total                    3,639.42                -         3,639.42
    Services     ATU12345678     AT               2,342.34      0      2,342.34
    Services     NL123456789B02     NL                  223.33      0         223.33
         Services Total                    2,565.67                -         2,565.67
         Grand Total                    6,205.09                -         6,205.09
    Let me as to how to achieve the above type in ALV grid...
    Regards
    Shiva

    check this link..
    Grand Totals in ALV grid disply function module
    or do like this..
    REPORT  ZALVTESTFORSUBTOTAL.
    tables:pa0008.
    type-pools:slis.
    types:begin of ty_pa0008,
          pernr like pa0008-pernr,
          begda like pa0008-begda,
          endda like pa0008-endda,
          ansal like pa0008-ansal,
          lga01 like pa0008-lga01,
          bet01 like pa0008-bet01,
          end of ty_pa0008.
    data:it_pa0008 type standard table of ty_pa0008 with header line.
    data:it_fieldcat type SLIS_T_FIELDCAT_ALV,
         wa_fieldcat type slis_fieldcat_alv,
         it_layout type slis_layout_alv,
         WA_events TYPE slis_alv_event,
         it_events TYPE slis_t_event.
    select-options:s_pernr for pa0008-pernr.
    start-of-selection.
    perform getD_data.
    perform disp_alv.
    *&      Form  getD_data
          text
    -->  p1        text
    <--  p2        text
    form getD_data .
    select pernr
           begda
           endda
           ansal
           lga01
           bet01
           from pa0008
           into table it_pa0008
           where pernr in s_pernr.
    sort it_pa0008 by pernr begda descending.
    endform.                    " getD_data
    *&      Form  disp_alv
          text
    -->  p1        text
    <--  p2        text
    form disp_alv .
    wa_fieldcat-fieldname = 'PERNR'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Personnel no'.
    *WA_FIELDCAT-no_subtotals = 'X'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'BEGDA'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Start date'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'ENDDA'.
    wa_FIELDCAT-REPTEXT_DDIC = 'End date'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'ANSAL'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Annula salary'.
    wa_fieldcat-do_sum = 'X'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'LGA01'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Wage Type'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'BET01'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Amount for wagetype'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    DATA: sort TYPE slis_sortinfo_alv,
    it_sort TYPE slis_t_sortinfo_alv.
    sort-fieldname = 'PERNR'.
    sort-subtot = 'X'.
    SORT-UP = 'X'.
    APPEND sort TO it_sort.
    *sort-fieldname = 'BEGDA'.
    *SORT-NO_SUBTOTS = 'X'.
    *APPEND sort TO it_sort.
    IT_layout-totals_text = 'total text'.
    IT_layout-subtotals_text = 'Subtotal text'.
    *WA_EVENTS-NAME = 'SUBTOTAL TEXT'.
    *WA_EVENTS-FORM = 'SUBTOTAL TEXT'.
    *APPEND WA_EVENTS TO IT_EVENTS.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
       I_CALLBACK_PROGRAM             = sy-repid
       IS_LAYOUT                      = it_LAYOUT
       IT_FIELDCAT                    = IT_FIELDCAT
       it_sort                        = it_sort
      it_events                      = it_events
       TABLES
        t_outtab                       = it_pa0008 .
    endform.                    " disp_alv

  • Subtotal in alv report based on the particular field value

    Hi,
    As per my requirement, i need to do subtotal of quntity field based on the material number field value in alv report.
    Ex:  if material number falls 1 to 10 then i need to be calculate and display subtotal qty amount with text " total of the mat1" and if material number falls 11 to 20 then again i need to be claculate and display subtotal qty amount with text "total of the mat2". similarily i need to display the details.
    <removed_by_moderator>
    Regards
    Nagendra

    Hi,
    Ex: if material number falls 1 to 10 then i need to be calculate and display subtotal qty amount with text " total of the mat1" and if material number falls 11 to 20 then again i need to be claculate and display subtotal qty amount with text "total of the mat2". similarily i need to display the details.
    What you can do is in your output table, you will have to create an auxilary field, lets call it as material group (groupid). Now you can do a subtotal on the material group. However the logic to determine what materials belong to which group should be coded. I guess you might be having some logic for that.
    So lets say that material 1 to 10 as G1 ( group 1 ) and material 11 to 20 as G2 ( group 2 )
    The output of the internal table would be
    Groupid  matnr ...
    1  1
    1  2
    1  3.....and so on
    2  11
    2  12
    2  13....upto 20.
    Now in the fieldcatalog assign an 'X' to the 'dosum' parameter to the field Groupid
    In the sort info do the following :
    gs_sort-fieldname = 'GROUPID'.
    gs_sort-spos = 1.
    gs_sort-up = 'X'.
    gs_sort-subtot = 'X'. ***CRUCIAL STATEMENT****
    append gs_sort to gt_sort.
    Now pass all this data to the alv grid function. And you are done.
    regards,
    Advait

  • SUBTOTAL  IN  ALV   REPORT

    hello freinds,
    I am facing problem of subtotal in alv report.
    I am explaining my problem.....................
    In my report there are 8 columns...
    in first colum there is <b>'Acount Number'</b> field. I have to sort out it.and I have done it succesfully. Now in my seventh and eighth column there are fields 'PAYMENT GROSS AMOUNT' and ' IVA AMOUNT' respectively.
    Now I have to do subtotal of these two columns (7th & 8th) according to first column value i.e Acount Number.
    Please send me solution.
    Thanks in Advance........

    Hi,
    try this code ,hope usefull to u, please reward point if usefull to u.
    *& Report  ZALV_SUBTOTAL
    This program lists orders (VBAK) with sort and sub-total for        *
    'sold-to-party' (KUNNR) and 'Sales organization' (VKORG)            *
    REPORT  ZALV_SUBTOTAL.
    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
    fareedas

Maybe you are looking for