Sub-totals and Totals calculations....?

How to Calculate the Sub-totals and Grand totals in ABAP Programs.

Hi Bhaskar,
In my opinion this can be acheived in two ways:
1. Using ALV GRID DISPLAY
2. Using AT NEW  , ON CHANGE OF  , etc events.
1. In the ALV field catalogue u create entries for all the fileds to b
displayed in the output list.
Here, we need to put DO_SUM = 'X' .
eg
  ****************fieldcatalog*********************
data:anytab type slis_t_fieldcat_alv with header line.
**************pgm name**********************
data:anypgnm type sy-repid.
**************events*************************
anytab-fieldname   = 'MATNR'.
  anytab-seltext_m   = 'Material Number'.
  anytab-col_pos     = 0.
  anytab-outputlen   = 20.
  anytab-emphasize   = 'X'.
  anytab-do_sum = 'X' .                  <----
here it is.
  append anytab to anytab .
  clear  anytab .
Now wen u call the fm REUSE_ALV_GRID_DISPLAY , plz pass anytab ie fieldcatalog  and  the tabel with records to  b displayed .
this would  sum the fields at the end.
2.  Alternately ....for SUb-totals ;
   Sort itab in an ascending manner.
Data : wa_itab    like line of itab,
          wa_subtotal type i.
" fieldname1 in itab is the key field
" fieldname2 is the value field
LOOP at itab into wa_itab .
  wa_subtotal = wa-subtotal  + itab-<fieldname2>.
  AT END OF <fieldname1> .
      " your programming logic for subtotal
       Write :/ wa_itab-fieldname1 , wa_subtotal.
       Clear  wa_subtotal.
   ENDAT.
   " write :/  ....if u need to write any lofgic values ....
ENDLOOP .
Note : plz sc if a field in itab that is left of fieldname1 changes
          the AT END OF event is triggered.
         Therefoe , see that  pur key fields towards left in itab.
FYI : u can try ON CHANGE OF....ENDON....
                      AT NEW .....ENDAT
                       AT LAST....ENDAT
                       AT FIRST ......ENDAT  events for ur own understanding
i hope this helps u.
Regards
panakj

Similar Messages

  • Interactive Report Sub-total and total

    Hi friends,
    I have an employee interactive report with group by job name and also showing the salary sub-total for each and every job(group by).
    I have an requirement like to highlight the sub-total for each and every job with a background color so that the user can identify the sub-total with the color, and also whether it is possible to display an overall total @ last in the report with a label named "Total Salary" in which it calculates the overall salary is also to be highlightened with the background color.
    Also is it possible to display a text "Sub-total" besides each and every salary sub-total  of job(group by). Currently if we display a sum for the salary then im getting the total's but with out a text named total.
    Since i can see the highlighted feature in interactive report but im not sure how to apply it for the sub-total and total column.
    I have reproduced the example in apex.oracle.com
    http://apex.oracle.com/pls/apex/f?p=4550:1:0:::::
    In the application 9494 named "test" in page1.
    Thanks in advance.
    Brgds,
    Mini

    Hi, Mini,
    style=background-color:red;
    But that Total region color dint change.The code for style should be in "Form HTML Element Attributes". However, this changes the background color only for the Total value not for the whole row.
    If you want to change for the whole row, you need to change the template that is selected for the region.
    I changed the region template in your application to "Borderless Region" and made the changes to the "Borderless Region" template, it now shows the background color for Total Value.
    <table class="t20Region t20Borderless #REGION_CSS_CLASSES#" id="#REGION_STATIC_ID#" border="0" cellpadding="0" cellspacing="0" summary="" #REGION_ATTRIBUTES#>
    <thead><tr><th class="t20RegionHeader" id="#REGION_STATIC_ID#_header">#TITLE#</th></tr></thead>
    <tbody id="#REGION_STATIC_ID#_body">
    <tr><td class="t20ButtonHolder">#CLOSE##PREVIOUS##NEXT##DELETE##EDIT##CHANGE##CREATE##CREATE2##EXPAND##COPY##HELP#</td></tr>
    <tr><td class="t20RegionBody" style="background-color:orange">#BODY#</td></tr>
    </tbody>
    </table>The below does the trick. :)
    <tr><td class="t20RegionBody" style="background-color:orange">#BODY#</td></tr>Note: I made the changes to "Borderless Template", but you can copy the template to your own and apply this change.
    Regards,
    Natarajan

  • Sub-total and Total for a column having checkboxes in WD ABAP ALV

    Hello Experts,
    I have used ALV in We bdynpro ABAP to display my output. There are 2 columns that are checkboxes in Output. I want a sub-total and total for those two columns. I know tht total and sub-total functionality is available only for numeric fields .
    Is there any other indirect way by which i can achieve the same ?

    Hi Ragini,
    Please refer this thread: [alv total and subtotal|How to display graphs;.
    I hope it helps.
    Regards
    Arjun

  • Sub totals and Totals

    I am developing a query using SQVI.
    How do I insert subtotals and totals for certain fields at the end of the query report.
    Thanks
    Sandeep

    hI SANDEEP  .....
    if you  go with  layou mode   then    there will be   3  pops  like   delete  ,  TOOL BAR  , SORT FIELDS ....etc ..
    there is  TOOL BAR   with the following  options   ...
    Background
    Heading
    Normal
    <b>Subtotals</b>
    Key Columns
    Positive
    Negative
    Control Levels
    Background (intensified
    Header (intensified)
    Normal (intensified)
    Sum totals (intensified
    Keys (intensified)
    Positive (intensified)
    Negative (intensified)
    Control lev.(intensifie
    so  that  by selecting the  fields   .....  liek sub total   acrros the  Fiscal  year  can be done  ....  Document wise   sub total  ..... vendor wise   , customer wise  ... like  based  on the fields   selection for sub total  and   total can  be  done ...
    Girish

  • Caculating page wise sub totals and totals

    Friends,
    I am working on an ADOBE form,  where i need to calculate subtotals and grand totals for the invoice lines displayed.
    I achieved the functionality in the smartforms by defining a different window under the main window(this contains line amounts). For the new window where the subtotal is expected to print i triggerred the event 'Before the end of main window' to print the totals before the lines flow to the next page by auto page break in the main window.
    I tried in the forms putting different content area(other than the main content area where table lines are printed) for the subtotals in the layout designer and manipulated using all the pagination options avialable in the table properties, but in vain. 
    What exatly is the equivalent for the event 'Before the end of main window' as that of smart forms.
    Any inputs on this?
    regards
    Nalinikanth.

    Hi Nalinikanth,
    assumed you have a table created with subforms like
    MyTable
    - Header
      (text elements)
    - Data
      (repeating subform with line elements)
    you can create a line with subtotal as following:
    1. Define a new line below "MyTable" for the subtotals with name e.g. "Subtotals" and insert elements (similar to the ones in "Data").
    2. In subform "Data": palette Object -> Pagination -> Overflow Trailer: "Subtotals"
    3. In Hierarchy palette, right-click on "Subtotals" -> Insert Script Object
    4. name this script object "tableCalcs" and insert following code
    *   Table Calculation Functions
    *     To invoke these functions:
    *   syntax:     scriptObjectSOM.obj.functionName(sFieldName, [startPage], [endPage]);
    *   example:     tableCalcs.Sum("Field1", 2, 3);
    *   notes:           
    *                    -The SOM expression of the Script Object may vary upon its position in the Hierarchy.
    *                    -The start and end page arguments are 0-based numbers or a reference to an XFA object.
    DO NOT MODIFY THE CODE BEYOND THIS POINT - 705.20051114114126.253659.250577 - tableCalcs.xfo
    var obj = new CalcObject();
    function CalcObject()
         this.Sum = _doSum;
         this.Average = _doAverage;
         this.Count = _doCount;
    *     Calculate the sum of all fields with the same name.
    *      NUMBER Sum(STRING sFieldName, [NUMBER pageNum])
    *      NUMBER Sum(STRING sFieldName, [OBJECT xfaObject])
    *      NUMBER Sum(STRING sFieldName, [NUMBER startPage], [NUMBER endPage])
    *      NUMBER Sum(STRING sFieldName, [OBJECT xfaObject], [OBJECT xfaObject])
    *     param1:     STRING; Name of field to calculate sum of
    *     param2:     NUMBER; Start page for calculation
    *     param2:     OBJECT; XFA object on the page calculation will start on
    *     param3:     NUMBER; End page for calculation
    *     param3:     OBJECT; XFA object on the page calculation will end on
    *     return: NUMBER; Sum of all fields
    function _doSum(fieldName)
         var fieldSum = null;
         var startPage = 0;
         var endPage = 0;
         var lengthOfDecimal = 0;
         if (arguments.length == 2) {
              startPage = _GetPageNum(arguments[1]);
              endPage = startPage;
         } else if (arguments.length == 3){
              startPage = _GetPageNum(arguments[1]);
              endPage = _GetPageNum(arguments[2]);
         } else {
              startPage = 0;
              endPage = xfa.layout.pageCount() - 1;
         if ((startPage < 0) || (endPage < 0) || (startPage > endPage))
              throw new PageNumberException(startPage, endPage);
         var curPage = startPage;
         while (curPage <= endPage) {
              // Get the field containers on the current page
              var oFields = xfa.layout.pageContent(curPage, "field");
              var fieldCount = oFields.length;
              // Continue if fields were found on the page
              if (fieldCount > 0) {
                   var i = 0;
                   for (i=0; i < fieldCount; i++) {
                        if (oFields.item(i).name == fieldName) {
                             //only count non-empty/numeric fields
                             var fieldVal = _GetFieldVal(oFields.item(i));
                             if (fieldVal != null) {                         
                                  fieldSum += fieldVal;
                             if (_GetLengthOfField(oFields.item(i)) > lengthOfDecimal) {
                                  lengthOfDecimal = _GetLengthOfField(oFields.item(i));
              curPage++;
         if (fieldSum == null)
              throw new FieldNotFoundException(fieldName);
         if(lengthOfDecimal > 0) {
              return fieldSum.toFixed(lengthOfDecimal);
         return fieldSum;
    *     Calculate the average of all fields with the same name.
    *      NUMBER Average(STRING sFieldName, [NUMBER pageNum])
    *      NUMBER Average(STRING sFieldName, [OBJECT xfaObject])
    *      NUMBER Average(STRING sFieldName, [NUMBER startPage], [NUMBER endPage])
    *      NUMBER Average(STRING sFieldName, [OBJECT xfaObject], [OBJECT xfaObject])
    *     param1:     STRING; Name of field to calculate average of
    *     param2:     NUMBER; Start page for calculation
    *     param2:     OBJECT; XFA object on the page calculation will start on
    *     param3:     NUMBER; End page for calculation
    *     param3:     OBJECT; XFA object on the page calculation will end on
    *     return: NUMBER; Average of all fields
    function _doAverage(fieldName)
         var fieldCount = null;
         var fieldSum = null;
         var startPage = 0;
         var endPage = 0;
         var lengthOfDecimal = 0;
         if (arguments.length == 2) {
              startPage = _GetPageNum(arguments[1]);
              endPage = startPage;
         } else if (arguments.length == 3){
              startPage = _GetPageNum(arguments[1]);
              endPage = _GetPageNum(arguments[2]);
         } else {
              startPage = 0;
              endPage = xfa.layout.pageCount() - 1;
         if ((startPage < 0) || (endPage < 0) || (startPage > endPage))
              throw new PageNumberException(startPage, endPage);
         var curPage = startPage;
         while (curPage <= endPage) {
              // Get the field containers on the current page
              var oFields = xfa.layout.pageContent(curPage, "field");
              var allFields = oFields.length;
              // Continue if fields were found on the page
              if (allFields > 0) {
                   var i = 0;
                   for (i=0; i < allFields; i++) {
                        if (oFields.item(i).name == fieldName) {
                             //only count non-empty/numeric fields
                             var fieldVal = _GetFieldVal(oFields.item(i));
                             if (fieldVal != null) {
                                  fieldCount ++;
                                  fieldSum += fieldVal;
                             if (_GetLengthOfField(oFields.item(i)) > lengthOfDecimal) {
                                  lengthOfDecimal = _GetLengthOfField(oFields.item(i));
              curPage++;
         if (fieldCount == null)
              throw new FieldNotFoundException(fieldName);
         if (fieldCount != null && fieldSum != null && fieldCount > 0) {
              var average = fieldSum / fieldCount;
              if(lengthOfDecimal > 0) {
                   return average.toFixed(lengthOfDecimal);
              return average;
         else {
              return null;
    *     Calculate the number of fields with the same name.
    *      NUMBER Count(STRING sFieldName, [NUMBER pageNum])
    *      NUMBER Count(STRING sFieldName, [OBJECT xfaObject])
    *      NUMBER Count(STRING sFieldName, [NUMBER startPage], [NUMBER endPage])
    *      NUMBER Count(STRING sFieldName, [OBJECT xfaObject], [OBJECT xfaObject])
    *     param1:     STRING; Name of field to calculate number of
    *     param2:     NUMBER; Start page for calculation
    *     param2:     OBJECT; XFA object on the page calculation will start on
    *     param3:     NUMBER; End page for calculation
    *     param3:     OBJECT; XFA object on the page calculation will end on
    *     return: NUMBER; Number of fields found
    function _doCount(fieldName)
         var fieldCount = null;
         var startPage = 0;
         var endPage = 0;
         if (arguments.length == 2) {
              startPage = _GetPageNum(arguments[1]);
              endPage = startPage;
         } else if (arguments.length == 3){
              startPage = _GetPageNum(arguments[1]);
              endPage = _GetPageNum(arguments[2]);
         } else {
              startPage = 0;
              endPage = xfa.layout.pageCount() - 1;
         if ((startPage < 0) || (endPage < 0) || (startPage > endPage))
              throw new PageNumberException(startPage, endPage);
         var curPage = startPage;
         while (curPage <= endPage) {
              // Get the field containers on the current page
              var oFields = xfa.layout.pageContent(curPage, "field");
              var allFields = oFields.length;
              // Continue if fields were found on the page
              if (allFields > 0) {
                   var i = 0;
                   for (i=0; i < allFields; i++) {
                        if (oFields.item(i).name == fieldName) {
                             //only count non-empty/numeric fields
                             var fieldVal = _GetFieldVal(oFields.item(i));
                             if (fieldVal != null) {
                                  fieldCount ++;
              curPage++;
         if (fieldCount == null)
              throw new FieldNotFoundException(fieldName);
         return fieldCount;
    function _GetFieldVal(obj)
         var fieldVal = obj.rawValue;
         if (typeof fieldVal != "number") {                         
              if (typeof fieldVal == "string" && fieldVal.length > 0) {
                   fieldVal = parseFloat(fieldVal);
                   if (isNaN(fieldVal))
                        fieldVal = null;
              } else {
                   fieldVal = null;
         return fieldVal;
    function _GetPageNum(val)
         var pageNum = -1;
         if (typeof val == "number") {                         
              pageNum = val;
         else if (typeof val == "object") {
              if (val != null) {               
                   pageNum = xfa.layout.page(val) - 1
         return pageNum;
    function _GetLengthOfField(obj)
         var fieldVal = obj.rawValue;
         if (fieldVal != null) {
              if (typeof fieldVal == "number") {
               fieldVal = new String(fieldVal);
              var index = fieldVal.indexOf(".");
              if (index > -1) {
                   return fieldVal.length - index - 1;
         return 0;
    function getExceptionString() { return this.message; }
    function FieldNotFoundException(fieldName)
         this.message = "Calculation failed: No non-empty fields found called '" + fieldName + "'.";
         this.name = "FieldNotFoundException";
         this.toString = getExceptionString;
    function PageNumberException(startPage, endPage)
         this.message = "Calculation failed: Incorrect page references (start page = " + startPage + ", end page = " + endPage + ").";
         this.name = "PageNumberException";
         this.toString = getExceptionString;
    // END OF DO NOT MODIFY     
    5. In the subtotal fields, add script for event "calculate":
    this.rawValue = this.parent.variables.tableCalcs.obj.Sum("AMOUNT", 0, this);
    where "AMOUNT" is the name of the referenced field.
    HTH & best regards,
    Carlo

  • Grand total and total in all page

    page 1
    colum1 | cloum2
    4 | 55
    1 | 6
    in Footer page1
    5 | 61
    page 2
    colum1 | cloum2
    2 | 3
    1 | 6
    in Footer page2
    3 | 9
    --------- i want
    in Footer page2
    8 | 70
    plez help me
    Message was edited by: azmi
    user490620

    What do you want exactly?
    Your subject says other thing then your actual question.
    Any how it snot difficult.
    Put summery Columns calculating the SUM of both fields (reset at report)
    & Set there property "print object on" to "last page".
    Hope it 'll work.
    Capri...

  • Totals and Sub-Totals in ALV GRID

    Could anyone advice, how to display sub-totals and totals in ALV Grid(using FM).
    Ex:           value1    value2
                      100        50
                      200        50
        subtotal   300      100
        total                    400
    Thanks in advance...

    Refer below demo code and see perform Sort_list..
    it wil serve ur purpose.
    REPORT  ZGILL_ALV    message-id rp                           .
    type-pools slis.
    tables: zgill_main,zgill_details.
    data z_fieldcat type slis_t_fieldcat_alv.
    data begin of itab occurs 0.
    DATA ICON TYPE ICON-ID.
         include structure zgill_main.
    data salary like zgill_details-salary.
    data end of itab.
    *data itab1 like table of itab with header line.
    data : WA_SORT TYPE SLIS_SORTINFO_ALV,
           IT_SORT TYPE SLIS_T_SORTINFO_ALV,
           WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
           IT_FIELDTAB TYPE SLIS_T_FIELDCAT_ALV,
           WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
    PARAMETERS: p_list  radiobutton group A1,
                P_GRID  RADIOBUTTON GROUP A1.
    SELECT-OPTIONS: S_PERNR FOR ZGILL_MAIN-PERNR.
    start-of-selection.
    perform fill_itab.
    perform sort_list.
    **************Start of scenario without container******************************************
    *********Method 1***********
    perform fill_fieldcat.  " Manuallly Preparing Fiedl Catalog
    *********Method 2***********
    *perform fill_fieldcat1 changing z_fieldcat.   "Preparing field catalog with merge function
    perform display_alv.
    *****************end of scenario without container*****************************************
    *&      Form  fill_itab
          text
    -->  p1        text
    <--  p2        text
    form fill_itab .
    *select * from zgill_main up to 20 rows INTO CORRESPONDING FIELDS OF TABLE itab.
    *ITAB1[] = ITAB[].
    select apernr aname aorg adob b~salary INTO CORRESPONDING FIELDS OF TABLE itab
           from zgill_main as a join zgill_details as b on apernr = bpernr
           WHERE A~PERNR IN S_PERNR.
    LOOP AT ITAB.
    IF ITAB-PERNR < 1111.
    ITAB-ICON = '@08@'.
    ELSEIF ITAB-PERNR > 1111 AND ITAB-PERNR < 11111111.
    ITAB-ICON = '@09@'.
    ELSEIF ITAB-PERNR GE 11111111.
    ITAB-ICON = '@0A@'.
    ENDIF.
    MODIFY ITAB INDEX SY-TABIX.
    ENDLOOP.
    endform.                    " fill_itab
    *&      Form  display_alv
          text
    -->  p1        text
    <--  p2        text
    form display_alv .
    data repid like sy-repid.
    REPID = SY-REPID.
    WA_LAYOUT-ZEBRA = 'X'.
    WA_LAYOUT-WINDOW_TITLEBAR = 'GRID DISPLAY'.
    WA_LAYOUT-SUBTOTALS_TEXT = 'SUBTOTAL'.
    WA_LAYOUT-TOTALS_TEXT = 'TOTAL'.
    IF P_GRID = 'X'.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
       I_CALLBACK_PROGRAM                = repid
       IT_FIELDCAT                       = IT_FIELDTAB
       IT_SORT                           = IT_SORT
       IS_LAYOUT                         = WA_LAYOUT
    TABLES
        t_outtab                          = itab[]
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2.
    IF sy-subrc <> 0.
       message e016 with 'Error in Display'.
    ENDIF.
    ELSEIF P_LIST = 'X'.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
       I_CALLBACK_PROGRAM                = repid
       IT_FIELDCAT                       = IT_FIELDTAB
       IT_SORT                           = IT_SORT
       IS_LAYOUT                         = WA_LAYOUT
    TABLES
        t_outtab                          = itab[]
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2.
    IF sy-subrc <> 0.
       message e016 with 'Error in Display'.
    ENDIF.
    ENDIF.
    endform.                    " display_alv
    *&      Form  fill_fieldcat1
          text
    -->  p1        text
    <--  p2        text
    form fill_fieldcat1  changing d_fcat type slis_t_fieldcat_alv.
    data repid like sy-repid.
    data d_fcat1 type slis_t_fieldcat_alv with header line.
    REPID = SY-REPID.
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
       I_PROGRAM_NAME               = repid
       I_INTERNAL_TABNAME           = 'ITAB'
       I_STRUCTURE_NAME             = 'ZGILL_MAIN'
      I_CLIENT_NEVER_DISPLAY       = 'X'
      I_INCLNAME                   =
      I_BYPASSING_BUFFER           =
      I_BUFFER_ACTIVE              =
    CHANGING
        ct_fieldcat                  = d_fcat[]
    EXCEPTIONS
       INCONSISTENT_INTERFACE       = 1
       PROGRAM_ERROR                = 2
       OTHERS                       = 3.
    IF sy-subrc <> 0.
       message e016 with 'Error in preparing fiedl catalog'.
    ENDIF.
    loop at d_fcat into d_fcat1.
    case d_fcat1-fieldname.
    when 'NAME'.
    d_fcat1-reptext_ddic = 'Emp Name'.
    MODIFY D_FCAT FROM D_FCAT1.
    WHEN 'PERNR'.
    d_fcat1-reptext_ddic = 'Emp Num'.
    MODIFY D_FCAT FROM D_FCAT1.
    WHEN 'ORG'.
    d_fcat1-reptext_ddic = 'Org Unit'.
    MODIFY D_FCAT FROM D_FCAT1.
    endcase.
    clear d_fcat1.
    endloop.
    endform.                    " fill_fieldcat1
    *&      Form  sort_list
          text
    -->  p1        text
    <--  p2        text
    form sort_list .
    CLEAR WA_SORT.
    WA_SORT-FIELDNAME = 'DOB'.
    WA_SORT-SPOS = '1'.
    WA_SORT-UP = 'X'.
    WA_SORT-SUBTOT = 'X'.
    APPEND WA_SORT TO IT_SORT.
    CLEAR WA_SORT.
    WA_SORT-FIELDNAME = 'NAME'.
    WA_SORT-SPOS = '1'.
    WA_SORT-UP = 'X'.
    APPEND WA_SORT TO IT_SORT.
    CLEAR WA_SORT.
    endform.                    " sort_list
    *&      Form  fill_fieldcat
          text
    -->  p1        text
    <--  p2        text
    form fill_fieldcat .
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-TABNAME = 'ITAB'.
    WA_FIELDCAT-FIELDNAME = 'ICON'.
    WA_FIELDCAT-SELTEXT_L = 'TRAFFIC'.
    WA_FIELDCAT-ICON = 'X'.
    WA_FIELDCAT-ddictxt = 'l'.
    WA_FIELDCAT-COL_POS = 1.
    WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO IT_FIELDTAB.
    CLEAR WA_FIELDCAT .
    WA_FIELDCAT-TABNAME = 'ITAB'.
    WA_FIELDCAT-FIELDNAME = 'PERNR'.
    WA_FIELDCAT-SELTEXT_L = 'EMP NUMBER'.
    WA_FIELDCAT-ddictxt = 'l'.
    WA_FIELDCAT-COL_POS = 2.
    WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO IT_FIELDTAB.
    CLEAR WA_FIELDCAT .
    when 'maktx'.
    WA_FIELDCAT-TABNAME = 'ITAB'.
    WA_FIELDCAT-FIELDNAME = 'NAME'.
    WA_FIELDCAT-SELTEXT_L = 'EMP NAME'.
    WA_FIELDCAT-ddictxt = 'l'.
    WA_FIELDCAT-COL_POS = 3.
    WA_FIELDCAT-OUTPUTLEN = 15.
    APPEND WA_FIELDCAT TO IT_FIELDTAB.
    CLEAR WA_FIELDCAT .
    WA_FIELDCAT-TABNAME = 'ITAB'.
    WA_FIELDCAT-FIELDNAME = 'ORG'.
    WA_FIELDCAT-SELTEXT_L = 'ORG UNIT'.
    WA_FIELDCAT-COL_POS = 4.
    WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO IT_FIELDTAB.
    CLEAR WA_FIELDCAT .
    WA_FIELDCAT-TABNAME = 'ITAB'.
    WA_FIELDCAT-FIELDNAME = 'DOB'.
    WA_FIELDCAT-SELTEXT_L = 'BIRTH DATE'.
    WA_FIELDCAT-COL_POS = 5.
    WA_FIELDCAT-OUTPUTLEN = 12.
    APPEND WA_FIELDCAT TO IT_FIELDTAB.
    CLEAR WA_FIELDCAT .
    WA_FIELDCAT-TABNAME = 'ITAB'.
    WA_FIELDCAT-FIELDNAME = 'SALARY'.
    WA_FIELDCAT-SELTEXT_L = 'SALARY'.
    WA_FIELDCAT-COL_POS = 6.
    WA_FIELDCAT-OUTPUTLEN = 25.
    WA_FIELDCAT-do_sum = 'X'.
    APPEND WA_FIELDCAT TO IT_FIELDTAB.
    endform.                    " fill_fieldcat

  • Calculate totals and sub totals

    hi everybody
    can u plz suggest me how to write code for getting sub totals and totals
    regards
    hridhaya

    Hello hridhayanjili
    SAP provides us with the ABAP statement <b>COLLECT</b> to summarize totals.
    I will give you an example from which you should be able to develop you own solution.
    Let's assume we have an itab containing materials. The itab has the following line structure: MANDT, MATNR, QUANTITY. To calculate subtotals we require a second itab that is identical to the first one.
    Now here is the coding:
    data:
      gt_itab          TYPE STANDARD TABLE OF <structure>,
      gt_itab_collect  TYPE STANDARD TABLE OF <structure>,
      gt_itab_total    TYPE STANDARD TABLE OF <structure>.
      gs_entry         TYPE <structure>.
    * NOTE: <structure> stands for a named DDIC structure or
    * a type definition, not a field symbol.
    * gt_itab contains our materials
      LOOP AT gt_itab INTO gs_entry.
        COLLECT gs_entry INTO gt_itab_collect.
      ENDLOOP.
    * NOTE: Assuming we had 10 entries in gt_itab of
    * 3 different materials we end up with 3 entries in
    * gt_itab_collect that contain the quantities summarized.
    * To calculate the total one could LOOP over
    * gt_itab_collect and summarize the values. Another way
    * is shown here:
      CLEAR: gs_entry-matnr.
      MODIFY gt_itab FROM gs_entry
        TRANSPORTING matnr
        WHERE ( matnr IS NOT INITIAL ).
    * We clear the material no.
      LOOP AT gt_itab INTO gs_entry.
        COLLECT gs_entry INTO gt_itab_total.
      ENDLOOP. 
    * NOTE: because we have the same value for CLIENT and
    * MATNR in every line we will end up with a single line
    * in gt_itab_total.
    Please read the documentation of the COLLECT statement carefully because the structure of your itab (i.e. the order of the fields, especially those that will be summarized) is important.
    Regards
       Uwe

  • Page break,sub total and grand total  in adobe forms

    hi,
    In adobe forms, i am displaying purchase order details in table format. internal table contains 150 records but it displaying
    only 50 records in single page. how i have to call a new page,how i have to create a page preak and i want to display only
    5 records for a page with carry forward,page total and total net value.

    Hi Sivaprasath,
    For the table content to flow onto the next pages please make sure that the outermost subform is NOT with the content property "Positioned".
    For having only 5 records per page, you can design a deep structure with fields:
    Table 1 (The table which will hold 5 records per page)
    Page total
    total net value
    Have the table type of it defined in the form.
    Put the logic for filling the table in such a way that each row of this nested table has 5 records and pagetotal and total net value.
    then put it inside a subform and check the checkbox for "rpeat subformt for each data item".
    Another way is to use Conditional breaks in Pagination tab.
    Thanks and regards,
    Priyanka

  • Weekly Group Total and associated YTD total

    Hello,
    I need to show current week group total and total year to date of the same group.  My columns are Model, Department, Issue.  Currently, the report is grouped on Model, Department and Issue with a filter for date.  Can this be done?   Thank you

    Create a formula field, say {@Current Week Amount} as (basic syntax):
    if datepart("ww", {datefield}) = datepart("ww", CurrentDate) then
      formula = {amount}
    else
      formula = 0
    end if
    You can then sum() this, or place it in a detail line, or whatever.  It will only have a (non-zero) value when the date field is in the current week.
    HTH,
    Carl

  • Query generator used to make general total and row total

    Dear experts/gurus,
    I have a problem how to create general total and total field in row by using query generator. In inventory in warehouse report of SBO 2004A SP 00 PL 41, there are total row of price x quantity / warehouse (if selection criteria is warehouse) and general total. I have made query report that quite similar with inventory in warehouse report using query generator and put selection criteria and item but I still can't find out the solution. is it possible using query generator to do that or if I use query analyzer, what is the code that I have to put ? is it compute sum(qty x price) by itemcode or there is stil another ? i appreciate your answer. TIA
    Rgds,

    Hi Jimmy,
    Here's one approach to solve your problem:
    = = = = = = =
    select oitm.itemcode, oitm.itemname, whs.whscode, whs.quantity
    from oitm inner join
    (select itemcode, sum(onhand) as quantity, whscode from oitw group by itemcode, whscode) whs
    on oitm.itemcode=whs.itemcode
    = = = = = = =
    ...the main query refers to the subquery as it was another table. The subquery calculates quantity per warehouse from the oitw table.
    Of course you could create a view in SQL Server instead of a subquery. That would make the query inside B1 query generator more simple and would also make it faster to execute.
    Henry

  • Alv - sub  totals and avg

    Hi gurus,
    I have a problem, please help me out.
    Iam doing an report program with alv display. In that iam calculating the AVG for the workcenter wise for the field TAT.
    please observe my below o/p in general ALv  format.
    work center-- TAT- Tat(Yes/no)
    qm0010------ 1 --  yes
    qm0010-------2 --  yes
    qm0010------ 4 -- yes
    qm0010------ 7 -- No (because >5)
    Subtotal(qm0010)--3  (avg caluculated)
    qm0020--  4 --- yes
    qm0020-7-- No (because >5)
    qm0020--10 - No (because >5)
    qm002010- No (because >5)
    Subtotal(qm0020)-- 7 (avg caluculated).
    this is the rough o/p iam getting . this is acheived by programming the Field catalog for TAT field i.e... do_sum  = 'C'.
    then giving the sort table to REUSE_ALV_GRID_DISPLAY.
    Now my problem is:
    I want the avg to be calcuted by the business formula which is:
    avg  =  sum of(TAT within 5 days) / total no of the entries .
    Ex:
    work center-- TAT- Tat(Yes/no)
    qm0010------ 1 --  yes
    qm0010-------2 --  yes
    qm0010------ 4 -- yes
    qm0010------ 7 -- No (because >5)
    Subtotal(qm0010)---*7/4=2 (avg caluculated for tat<5)*
    qm0020--  4 --- yes
    qm0020-7-- No (because >5)
    qm0020--10 - No (because >5)
    qm002010- No (because >5)
    Subtotal(qm0020)--4/4=1 (avg caluculated for tat<5).
    How can i acheive the above, since in field catalog and alv, i think we cannot pass any conditions(like for TAT which is less than 5). So is there any other way to acheive the above.
    Please understand the problem and give me(please directly dont suggest any programs , since iam not a expert to understand)..
    Please explain me in detail.  Points will be duly rewarded.
    Thanks in advance........Chaitu
    Edited by: chaitanya on May 30, 2008 12:33 PM
    Edited by: chaitanya on May 30, 2008 12:38 PM
    Edited by: chaitanya on May 30, 2008 12:39 PM

    Hi Chaitanya,
       You can display in your report with totals and sub-totals using alv, but not average. That functionality has not provided by sap. Do one thing add one more extra column Average in your output, do the calculation for average and pass the value in the coding itself. Then last display your report with Average field.
    Rgds,
    Bujji

  • This is regarding totals and sub totals in sap-scripts

    Hi to all...............
    1...How to print totals and subtotals in sap-scripts? where we have to code the logic.what sort of logic is needed to print the same?
    regards,
    swaminath.

    Hi
    HI,
    To calculate totals and sub totals in sap scripts you have to use subroutines.
    Say if you have to add the unit price (KOMVD-KBERT) then in the main window whereever tat value is picked write this routine
    /: DEFINE &TOT_PRICE&
    /: PERFORM F_GET_PRICE IN PROGRAM <subroutine prog name> /:USING &KOMVD-KBERT& /:CHANGING &TOT_PRICE& /:ENDPERFORM
    Then write the variable where ever you want it to be printed (mostly it will be in footer window)
    Then create subroutine pool program and you have to write the code.
    FORM F_GET_PRICE tables int_cond structure itcsy
    outt_cond structure itcsy. data : value type kbert.
    statics value1 type kbert.
    Read int_cond table index 1.
    value = int_cond-value.
    value1 = value1 + value.
    Read outt_cond table index 1.
    outt_cond-value = value1.
    Modify outt_cond index 1.
    ENDFORM.
    To know more, have a look at this thread ..
    Re: SAP Script: Display Total calculated  on page 2 in page 1
    <b>Reward if usefull</b>

  • Calculating Percent totals and Averages in SSRS

    Below is a report created using SSRS. I want to be able to calculate the percentage(%) total to add up to 100 % in the Total column. For some reason my averages are not working as you can see from the table. The idea is to calculate the averages of opportunities
    as well as Sold. But from my calculation, things are not adding up as I supposed. This report is not grouped by parent. How do I make this to work as it should? Thank you.
    (NB: Please zoom in to view the image)
    Zionlite

    Hi,
    According  to the description, I doubt you may manually add Total and Averages columns. Did you manually add Local and International or they were in a column group?
    You can use the following expression for the Opportunity Cost(averages) column in the total row:
    =Sum(Fields!opportunitycost.Value)/2
    How did you calculate the percentage column? If it is Sold value divided by Opportunity Cost value, use:
    =Sum(Fields!sold.Value)/Sum(Fields!opportunitycost.Value)
    Also try to define the scope in the expression and see if it make difference.
    If there is no progress, please capture the screenshot of your design tab.(Click on the report and capture the image of your report structure)
    Also, tell us the expression of the text box which in problem.
    Thanks.
    Tracy Cai
    TechNet Community Support

  • How to create a sub total and grand total using my query.

    How can I create a sub total for each section and grand total for using my query like this.  your help is appreciated. I am working with 9g
    WITH  BidItemsInformation  AS
    ( SELECT DISTINCT q.iplineno "Line Number", q.section "Section Number",
             i.item "Item Number",
             initcap(i.idescr) "Description" ,
             i.iunits "Unit",
             q.qty "Quantity" ,q.price  "Engineers Unit Price",
           (q.price * q.qty) "Engineers Estimate"
         FROM letprop l,
            proposal p,
            propitem q,
            bidlet b,
            bidtabs c,
            itemlist i,
            vendor v,
            bidders d 
         WHERE(l.letting = b.letting
                And b.letting = c.letting
                And p.cspecyr = i.ispecyr)
                AND q.prpitem = i.item
                AND p.contid = l.lcontid
                AND q.contid = p.contid
                AND c.vendor = l.avendor
                AND l.CALL = c.CALL
                AND q.lineflag = c.lineflag
                AND q.iplineno = c.iplineno
                AND l.letting = d.letting 
                AND c.letting = l.letting
                AND c.CALL = d.CALL
                AND v.vendor = d.vendor
                --  AND AND l.letstat = 'A'
                AND c.lineflag = 'L'
                AND  l.letting ='&letting'
                AND l.CALL = '&call'
    ), BiddersInformation  AS
    -- This is where you make your changes for vendor name and vendor number Do not touch the above code
    -- It is always the same for any call number and letting date
    ( SELECT IPLINENO "BLine Number",
            MAX(CASE WHEN VENDOR='K020'  THEN bidprice ELSE NULL END) "K020:: Unit Price",
            MAX(CASE WHEN VENDOR='K020'  THEN bidprice ELSE NULL END) K,
            MAX(CASE WHEN VENDOR='H438'  THEN bidprice ELSE NULL END) "H438:: Unit Price",
            MAX(CASE WHEN VENDOR='H438'  THEN bidprice ELSE NULL END) H,
            MAX(CASE WHEN VENDOR='U010'  THEN bidprice ELSE NULL END) "U010:: Unit Price",
            MAX(CASE WHEN VENDOR='U010'  THEN bidprice ELSE NULL END) U,
            MAX(CASE WHEN VENDOR='G110'  THEN bidprice ELSE NULL END) "G110:: Unit Price",
            MAX(CASE WHEN VENDOR='G110'  THEN bidprice ELSE NULL END) G,
            MAX(CASE WHEN VENDOR='H530'  THEN bidprice ELSE NULL END) "H530:: Unit Price",
            MAX(CASE WHEN VENDOR='H530'  THEN bidprice ELSE NULL END) H1
        FROM  BIDTABS
        WHERE LETTING='&letting'
              AND CALL='&call'
              AND BIDPRICE <> 0
        GROUP BY IPLINENO
    SELECT BidItemsInformation."Line Number",
           BidItemsInformation."Section Number",
           BidItemsInformation."Item Number",
           BidItemsInformation."Description",
           BidItemsInformation."Unit",
           BidItemsInformation."Quantity",
           BidItemsInformation."Engineers Unit Price",
           BidItemsInformation."Engineers Estimate",
           BiddersInformation."K020:: Unit Price",
            (BidItemsInformation."Quantity" * K) "KGM CONTRACTORS INC",
           BiddersInformation."H438:: Unit Price",       
            (BidItemsInformation."Quantity" * H) "HOFFMAN CONSTRUCTION COMPAN",
           BiddersInformation."U010:: Unit Price",       
            (BidItemsInformation."Quantity" * U) "ULLAND BROTHERS INC",
           BiddersInformation."G110:: Unit Price",      
            (BidItemsInformation."Quantity" * G) "GLADEN CONSTRUCTION INC",
           BiddersInformation."H530:: Unit Price",      
            (BidItemsInformation."Quantity" * H1) "HOOVER CONSTRUCTION CO"
    FROM   BidItemsInformation,BiddersInformation
    WHERE  BidItemsInformation."Line Number" = BiddersInformation."BLine Number";
    Line Number     Section Number     Item Number     Description     Unit     Quantity     Engineers Unit Price     Engineers Estimate     K020:: Unit Price     
    0010     0001     2011601/00003     Construction Surveying     LS       1     143,000     143,000     75,000     75,000     67,080     67,080
    0013     0001     2013601/00010     Survey Equipment     LS       1     25,000     25,000     25,000     25,000     30,000     30,000
    0020     0001     2015601/00030     Blast Monitor/Survey     LS       1     50,000     50,000     30,000     30,000     35,000     35,000
    0030     0001     2021501/00010     Mobilization     LS       1     382,250     382,250     809,000     809,000     704,000     704,000
    0040     0001     2021602/00010     Well Survey     EACH     60     500     30,000     2,150     129,000     1,600     96,000
    0050     0001     2031501/00040     Field Office Type D     EACH     1     6,367     6,367     4,000     4,000     25,000     25,000
    sub total:
    1610     0002     2401501/01143     Structural Concrete (1a43)     C Y      46     350     16,100     408     18,768     400     18,400
    1620     0002     2401501/01362     Structural Concrete (1c62)     C Y      68     200     13,600     204     13,872     200     13,600
    1630     0002     2401501/03643     Structural Concrete (3y43)     C Y      60     600     36,000     592     35,520     580     34,800
    1640     0002     2401512/03633     Bridge Slab Concrete (3y33)     S F      1,876     24     45,024     28     51,778     27     50,652
    1650     0002     2401521/00030     Structure Excavation Class R     C Y      17     125     2,125     1,000     17,000     500     8,500
    1660     0002     2401541/00010     Reinforcement Bars     LB       2,490     2     3,735     1     3,312     1     3,237
    1670     0002     2401541/00011     Reinforcement Bars (Epoxy Coated)     LB       12,380     2     18,570     1     17,703     1     17,332
    1680     0002     2401601/00010     Structure Excavation     LS       1     2,500     2,500     2,000     2,000     5,000     5,000
    1690     0002     2402583/00020     Ornamental Metal Railing Type Special     L F      284     150     42,600     194     55,096     190     53,960
    sub total
    1820     0003     2401513/00346     Type Curb Railing Concrete (3y46)     L F      135     25     3,375     16     2,093     15     2,025
    1830     0003     2401513/07447     Type Mod P-4 (Tl-4) Railing Conc (3y46)     L F      302     85     25,670     72     21,593     70     21,140
    1840     0003     2401541/00010     Reinforcement Bars     LB       14,780     1     18,475     1     13,598     1     13,302
    1850     0003     2401541/00011     Reinforcement Bars (Epoxy Coated)     LB       76,720     1     103,572     1     85,926     1     84,392
    1860     0003     2401601/00010     Structure Excavation     LS       1     10,000     10,000     116,000     116,000     115,000     115,000
    1870     0003     2402583/00020     Ornamental Metal Railing Type Special     L F      132     150     19,800     184     24,288     180     23,760
    sub total
    total

    You can accomplish that using decode with the grouping function. It returns 1 when that column passed as argument was grouped (or is in some total) and 0 otherwise.
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> with t as
      2  (select 'New York' city, 'US' country, 1 num from dual
      3  union all select 'Los Angeles' city, 'US' country, 2 num from dual
      4  union all select 'London' city, 'GB' country, 2 num from dual
      5  union all select 'London' city, 'GB' country, 2 num from dual
      6  union all select 'London' city, 'GB' country, 7 num from dual)
      7  select decode(grouping(country), 0, country, 'GRAND TOTAL') country,
      8         decode(grouping(city), 0, city, decode(grouping(country), 0, 'SUBTOTAL')) city,
      9         sum(num) num_total
    10   from t
    11  group by rollup(country, city)
    12  /
    COUNTRY     CITY         NUM_TOTAL
    GB          London              11
    GB          SUBTOTAL            11
    US          New York             1
    US          Los Angeles          2
    US          SUBTOTAL             3
    GRAND TOTAL                     14
    6 linhas selecionadas.
    SQL>

Maybe you are looking for

  • Trying to install 10.3 from current 10.2.8 on G3

    We have a G3 which was used in school (daughter teaches 5-6 yr-olds). We want to continue using it for the less exotic functions, but working at its best capability. Mac has 400Mhz Bus 100Mhz, Cache 512, Model says iMac (version =2.2) SDRAM 256 and 6

  • What is an upgrade distribution system?

    In Apple discussion document 2465 [  https://discussions.apple.com/docs/DOC-2465  ] I found this question and answer: Q: Are there any pitfalls to watch out for? A: With all upgrades, backing up your data at least twice has been a given.  Hardware ca

  • Auto Login Doesn't Work After Re-Install

    Visited bad link within Facebook! Thereafter, forced to re-install Firefox -- from scratch!! Saved a few of the profile files like bookmarks, passwords, but no extension stuff. Re-installed FireFox after deleting ALL tracks I could find in Program Fi

  • Imovie 9.0.8 Crashes immediately after launch

    Running Imovie 9.0.8  on OS 10.7.5 with 8GB RAM and 1TD Hdd. Recently has started crashing immediately after launch. Have tried a couple of possible work arounds but the 3ivxVideoCodec and the plist options don't seem to be available. Anyone got any

  • AP invoice distributions not displaying

    hey we have a situaion where invoice distribution form is supposed to show 3 invoice distributions lines ,but there is only 1 distribution line is displaying in the form. However invoice header shows the total amount of the distributions lines. Check