SUM statement efficiency

Hi everyone
I need to calculate some totals in an itab and have discivered the SUM statement, which seems a very easy way to achieve this.  However, being a cynical chap I was wondering if this carries a large overhead and will be less efficient than just storing a running total in a variable i.e x = x + y.
I anybody able to shed any light...?
Thanks
Andy

SUM.
Effect
When processing an internal table in a block starting with LOOP and concluded by ENDLOOP , SUM calculates the control totals of all fields of type I , F and P (see also ABAP/4 number types ) and places them in the LOOP output area (header line of the internal table or an explicitly specified work area).
Sum statement in report is basically used in Control Break Processing.
After you fill an internal table with data, you often need to write the data out. This output will frequently contain summary information(uch as totals) at the top or bottom of the report.There might also be interim situations (such as subtotals ) within the body of report.
To do this , you can read the data into an internal table and then, within loop at , use the following statements:
1. at first / endat
2.at last / endat
3.at new / endat
4.at end of / endat
5.sum
6.on change of / endon.
The first statement of each of these pairs - except for Sum - controls when the code lies between them is executed.This type of control is called a control break.Their purpose is to ececute the code between them whenever a specific condition in the data is detected during the processing of the loop.
Using the Sum statement :
syntax :
at first/last/new/end of.
sum
endat.
where :
... represents any number of lines of code.
Sum calculates a total for the current value of the control level that contains it.
It finds all rows that have the same values within the control level field and all fields of the left of it.
It sums each numeric column to the right of the control level.
It places the totals in the corresponding fields of the work area.

Similar Messages

  • SUM STATEMENT

    HI GURU'S,
    Please can anybody explains me
    what is significance of using SUM statement inside the AT AND ENDAT statement.
    what i understood about sum is: The statement SUM calculates the component total with the numeric data type (i, p, f)
    of all rows in the current control level and assigns these to the components of the work area wa. In the control levels
    FIRST, LAST, and outside of an AT-ENDAT control structure, the system calculates the sum of numeric components
    of all rows in the internal table.
    but in below program which i did, its not doing that</b>
    TYPES: BEGIN OF companies_type,
            name(30),
            product(20),
            sales TYPE i,
            SALES1 TYPE I,
          END   OF companies_type.
    DATA: companies TYPE STANDARD TABLE OF companies_type WITH
                         NON-UNIQUE DEFAULT KEY INITIAL SIZE 20,
          wa_companies TYPE companies_type.
    wa_companies-name = 'XYZ'.
    wa_companies-product = 'SAP'.
    wa_companies-sales = '1'.
    wa_companies-sales1 = '1'.
    APPEND wa_companies TO companies.
    wa_companies-name = 'ABC'.
    wa_companies-product = 'ABAP'.
    wa_companies-sales = '4'.
    wa_companies-sales1 = '4'.
    APPEND wa_companies TO companies.
    wa_companies-name = 'PQR'.
    wa_companies-product = 'HR'.
    wa_companies-sales = '3'.
    wa_companies-sales1 = '3'.
    APPEND wa_companies TO companies.
    LOOP AT companies INTO wa_companies.
      AT NEW name.
      sum.
        NEW-PAGE.
        WRITE / wa_companies-name.
      ENDAT.
      WRITE: / wa_companies-product, wa_companies-sales,wa_companies-sales1.
      AT END OF NAME.
        SUM.
        WRITE: / wa_companies-name, wa_companies-sales,wa_companies-sales1 .
      ENDAT.
    ENDLOOP.
    Thanks
    Priya

    Hi,
      The control statements should be used inside a loop, the internal table should be sorted before using the control statements.
    loop...
    At new name.
    sum.
    endat.
    endloop....
    Sum of the numeric values will be calculated when the name changes. At new  is triggered at the begining itself.
    loop...
    At end of name.
    sum.
    endat.
    endloop....
      Sum of the numeric values will be calculated when the name changes .
    Just a simple example:
    ID no    Name    Salary.
    100       Ram     5000
    100       Ravi      6000
    200       Prajn    7000
    In this case.
    loop at itab.
      At new idno.
         sum
      write:/ itab-idno , itab-name, itab-salaty.
    Endat.
    endloop.
    O/p will be :
          100  Ram 11000
    The sum will trigger when the number idno is changing .
    Similarly AT end  also works.
    Regards,
    Vani

  • Regarding summing statement in scripts

    Hi,
    please give one small example code for SUMMING statement in SAP Scripts.
    Thanks,
    Srinivas

    Hi,
    /:SUMMING &NETPR& INTO V_TOTAL
    loop
      write form for main window
    endloop.
    For every time(loop pass) the value will be added to v_total ,this will be defined in script.
    Regards,
    Ferry Lianto

  • Is this statement efficient?

    Is this statement efficient? How to tuning it?
    UPDATE INCOMING_MSG_IDX SET STATUS = 5    -- update message status to has read
            WHERE MSG_ID = V_MSG_ID AND
                  IP_ADDRESS = V_IP_ADDRESS AND
                  DATETIME = V_DATETIME AND
                  MSG_TYPE >= LOW_MSG_TYPE AND
                  MSG_TYPE <= UP_MSG_TYPE;

    jetq wrote:
    Is this statement efficient? How to tuning it?
    UPDATE INCOMING_MSG_IDX SET STATUS = 5    -- update message status to has read
    WHERE MSG_ID = V_MSG_ID AND
    IP_ADDRESS = V_IP_ADDRESS AND
    DATETIME = V_DATETIME AND
    MSG_TYPE >= LOW_MSG_TYPE AND
    MSG_TYPE <= UP_MSG_TYPE;
    Yes, No, May be, May be Not, actually don't know! Its like asking for a car which is standing in the parking lounge that is it giving a good mileage? Post the execution plan of the query with db and os version for us to comment.
    HTH
    Aman....

  • Making select statement efficient

    Can any one suggest how to make this below statement efficient? It is taking quite a long time to run, wht could be the reasons.
    SELECT pbimbedae pbimversb pbimpbdnr pbimmatnr pbim~werks
      pbedpdatu pbedplnmg pbed~meins
      pbed~aenam
      FROM pbim
      INNER JOIN pbed ON pbedbdzei = pbimbdzei
      INTO TABLE I_IDEMAND
      WHERE pbim~werks IN wa_plantsel
      AND EXISTS ( SELECT matnr FROM mara
          WHERE matnr = pbim~matnr
          AND lvorm = '' )
      AND EXISTS ( SELECT matnr FROM marc
          WHERE marcmatnr = pbimmatnr
          AND marcwerks = pbimwerks
          AND marc~lvorm = '' )
      AND pbim~vervs = 'X'
      AND pbed~plnmg > 0 .

    Hi,
    1. First of all the sequence of fields in select query for PBIM & PBED table should be same as database table.
    2. First select the data from mara & marc the fetch data from pbim.
    This should solve ur performnace problem .
    Regards
    Kapil

  • Performing a Sum on a Conditional if statement (in Business Objects)

    Post Author: Rhonda Jackson
    CA Forum: Formula
    I have been trying to debug a sum statement that evaluates a code (for example 0001) which then maps the corresponding dollar amount to a new column.  This part is working.  Unfortunately when I try to sum the values in the new column with the mapped values that meet the criteria, I receive a syntax error at the second If statement.  Any assistance of suggestions would be appreciated.  I have tried Sum(If....) and it still provides a syntax error.  Here is a sample of the code.
    =If(&#91;Acct - Account Purpose Code&#93;="0001";&#91;Acct - Sum Loan Amount X-collateral&#93;; If(&#91;Acct - Account Purpose Code&#93;="0003";&#91;Acct - Sum Loan Amount X-collateral&#93;;If(&#91;Acct - Account Purpose Code&#93;="0008";&#91;Acct - Sum Loan Amount X-collateral&#93;;If(&#91;Acct - Account Purpose Code&#93;="0009";&#91;Acct - Sum Loan Amount X-collateral&#93;;If(&#91;Acct - Account Purpose Code&#93;="0010";&#91;Acct - Sum Loan Amount X-collateral&#93;; If(&#91;Acct - Account Purpose Code&#93;="0011";&#91;Acct - Sum Loan Amount X-collateral&#93;;If(&#91;Acct - Account Purpose Code&#93;="0012";&#91;Acct - Sum Loan Amount X-collateral&#93;;If(&#91;Acct - Account Purpose Code&#93;="0014";&#91;Acct - Sum Loan Amount X-collateral&#93;;"0"))))))))

    Post Author: branko
    CA Forum: Formula
    Where is your sum located ? Where is your mapped value  located? Here are some shooting in the dark that might light a bulb.I assume you are using Crystal 9 or above. You might want to try running total. For each code EG. 0001 you would create running total that looks like this You
    would select field you want to sum ( eg. dolar value) then you would
    click on formula icon "x-2" in evaluate section and type something like
    this. (&#91;Acct - Account Purpose Code&#93;="0001"Then put  running total in  in the footer. Create text box and type something like this "SUM OF "TEXT BOX -
    SUM OF 0001 = your running total you made (e.g.RT0001) Repeat steps 1 and 2 for rest of the codes. ALTERNATIVE**** You might want to consider this approach also.Create a group base on (&#91;Acct - Account Purpose Code&#93;) created field. You would create a formula. And then put it in the detail section. Select it and make it a group. Then you can have sums per group.

  • Selecting, reading and sum of billing quantity for last 12 months in transformation end routine

    Hi experts,
    i have requirement to write end routine to read a DSO for last 12 months sales quantity for each month and sum value pass to keyfigure
    not interested using bex variable, while data loading from source to target dso in end routine i am trying to read another DSO which is same as my
    target dso where information is stored by fiscal period, year material etc. finally there is  a keyfigure in target whih needs to be filled with sum of 12
    months sales quantity, for each record form sourc to target maximum of 12 records will be in read dso (for 12 months) my routine is like below.
    i am not expert in abap please kindly gothrough and guide me in this
    TYPES: BEGIN OF s_/BIC/AZOSLS00,
    FISCPER  type /BI0/OIFISCPER,
    FISCVARNT  type /BI0/OIFISCVARNT,
    PLANT  type /BI0/OIPLANT,
    STOR_LOC  type /BI0/OISTOR_LOC,
    /BIC/MATERIAL  type /BIC/OIMATERIAL,
    VTYPE  type /BI0/OIVTYPE,
    BILL_QTY  type /BI0/OIBILL_QTY,
    END OF s_/BIC/AZOSLS00.
    DATA: it_/BIC/AZOSLS00 TYPE TABLE OF s_/BIC/AZOSLS00,
    wa_/BIC/AZOSLS00  TYPE s_/BIC/AZOSLS00.
    SELECT
    FISCPER
    FISCVARNT
    PLANT
    STOR_LOC
    /BIC/MATERIAL
    VTYPE
    BILL_QTY
         FROM /BIC/AZOSLS00 INTO TABLE it_/BIC/AZOSLS00
           FOR ALL
          ENTRIES IN RESULT_PACKAGE
           WHERE
    below field is from value of fiscal period (which is fiscal period -999 ex:  for 001.2014 this
    value will be 002.2013 so 12 months including current period)
    FISCPER >=  RESULT_PACKAGE-/BIC/ZFISCPERF
    below is result filed fiscal period (here i dont know which keyword or statement to be used to select
    interval values this between statement giving syntax error that can not be used in where for for all entries
    between RESULT_PACKAGE-FISCPER
            AND
             FISCVARNT = RESULT_PACKAGE-FISCVARNT AND
             PLANT = RESULT_PACKAGE-PLANT AND
             STOR_LOC = RESULT_PACKAGE-STOR_LOC and
          /BIC/MATERIAL = RESULT_PACKAGE-/BIC/MATERIAL .
        SORT it_/BIC/AZOSLS00 BY FISCPER FISCVARNT PLANT STOR_LOC
        /BIC/MATERIAL .
        LOOP AT RESULT_PACKAGE ASSIGNING <result_fields>.
          READ TABLE it_/BIC/AZOSLS00 INTO wa_/BIC/AZOSLS00 WITH KEY
    below dont know what statement i need to use in read statement for interval of fiscal periods
    giving error that >= can not be used
         FISCPER >=  <result_fields>-/BIC/ZFISCPERF
    FISCPER = <result_fields>-FISCPER
             FISCVARNT = <result_fields>-FISCVARNT
             PLANT = <result_fields>-PLANT
             STOR_LOC = <result_fields>-STOR_LOC
          /BIC/MATERIAL = <result_fields>-/BIC/MATERIAL
           BINARY SEARCH.
          BREAK-POINT.
          IF sy-subrc = 0.
    below for each record there will be 12 records in read so sume of 12 records quantity i need to pass to result again dont know what to say here
    sum statement giving error
                <result_fields>-/BIC/ZLSTSLS12 =
                 sum(wa_/BIC/AZOSLS00-BILL_QTY).
              ENDIF.
        ENDLOOP.
    friends please help me in this.
    Thanks
    Chandra.

    Hiii,
    If you only want to store last  12 months data in Target ODS .
    Then Create filter in DTP and write routine in filter for calmonth or fiscal period.
    Refer the below link to create filter routine :
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/80b2db87-639b-2e10-a8b9-c1ac0a44a7a6?QuickLink=index&…
    Regards,
    Akshay

  • Summing up a Column in ALV report

    Hi All,
    I have developed an ALV Report which will display Invoices and other details.
    Now i need to display the sum of NETWR column, if user wish to select that column and click the "SUM" icon.
    As of now, if i select the NETWR column and click 'SUM" column, i am getting Runtime error.
    How to resolve this issue?
    Regards
    Pavan

    Hi Pavan,
    ALV GRID CONTROL:
    This task is performed by the SAP Control Framework.
    The R/3 System allows you to create custom controls using ABAP Objects. The application server is the Automation Client, which drives the custom controls (automation server) at the front end.
    If custom controls are to be included on the frontend, then the SAPGUI acts as a container for them.
    Custom controls can be ActiveX Controls or JavaBeans.
    The system has to use a Remote Function Call (RFC) to transfer methods for creating and using a control to the front end.
    ABAP objects are used to implement the controls in programs.
    An SAP Container can contain other controls (for example, SAP ALV Grid Control, Tree Control, SAP Picture Control, SAP Splitter Control, and so on). It administers these controls logically in one collection and provides a physical area for the display.
    Every control exists in a container. Since containers are themselves controls, they can be nested within one another. The container becomes the parent of its control. SAP containers are divided into five groups:
    SAP custom container: Displays within an area defined in Screen Painter on screens or sub screens.
    Class: CL_GUI_CUSTOM_CONTAINER
    SAP dialog box container: Displays in a modeless dialog box or as a full screen. Class:
    CL_GUI_DIALOGBOX_CONTAINER
    SAP docking container: Displays as docked, resizable sub-window with the option of displaying it as a modeless dialog box. Class: CL_GUI_DOCKING_CONTAINER
    SAP splitter container: Displays and groups several controls in one area - that is, splits the area into cells Class: CL_GUI_SPLITTER_CONTAINER
    SAP easy splitter container: Displays controls in two cells, which the user can resize using a split bar. Class: CL_GUI_EASY_SPLITTER_CONTAINER.
    In the control, you can adjust the column width by dragging, or use the 'Optimum width' function to adjust the column width to the data currently displayed. You can also change the column sequence by selecting a column and dragging it to a new position.
    Standard functions are available in the control toolbar. The details display displays the fields in the line on which the cursor is positioned in a modal dialog box.
    The sort function in the ALV Control is available for as many columns as required. You can set complex sort criteria and sort columns in either ascending or descending order.
    You can use the 'Search' function to search for a string (generic search without *) within a selected area by line or column.
    You can use the 'Sum' function to create totals for one or more numeric columns. You can then use the "Subtotals" function to set up control level lists: You can use the 'Subtotal' function to structure control level lists: select the columns (non-numeric columns only) that you want to use and the corresponding control level totals are displayed.
    For 'Print' and 'Download' the whole list is always processed, not just the sections displayed on the screen.
    You can define display variants to meet your own specific requirements. For information on saving variants, see 'Advanced Techniques'.
    The ALV grid control is a generic tool for displaying lists in screens. The control offers standard functions such as sorting by any column, adding numeric columns, and fixed lead columns .
    Data collection is performed in the program (with SELECT statements, for example) or by using a logical database. The data records are saved in an internal table and passed on to the ALV control along with a field description.
    The field description contains information about the characteristics of each column, such as the column header and output length. This information can defined either globally in the Dictionary (structure in the Dictionary) or in the field catalog in the program itself. You can also merge both techniques.
    The ALV link is a standard function of Query and QuickViewer. If multiline queries or Quick View lists have been defined, they will automatically be compressed to a single line and output in the ALV control as a long, single line list.
    Use Screen Painter to create a sub screen container for the ALV grid control. The control requires an area where it can be displayed in the screen. You have to create a container control that determines this area.
    Use the corresponding icon in the Screen Painter layout to create the container control. The size of area "MY_CONTROL_AREA" determines the subsequent size of the ALV control.
    The valid GUI status must be set at the PBO event in the flow logic of the ALV subscreen container.
    The OK_CODE processing for the cancel functions must be programmed at the PAI event.
    The reference variables for the custom container and the ALV grid control must be declared.
    To create reference variables, use ABAP statement TYPE REF TO .
    The global classes you need to do this are called cl_gui_custom_container (for the custom container control) and cl_gui_alv_grid (for the ALV grid control).
    The global classes are defined in the Class Builder. You can use the Class Builder to display information for the methods, their parameters, exceptions, and so on.
    Use ABAP statement CREATE OBJECT to create the objects for the container and the ALV control. Objects Are instances of a class.
    When an object is created (CREATE), method CONSTRUCTOR of the corresponding class is executed. The parameters of method CONSTRUCTOR determine which parameters have to be supplied with data when the object is created. In the above example, object alv_grid is given the name of the container control (g_custom_container) in exporting parameter i_parent, which links the two controls. For information on which parameters method CONSTRUCTOR possesses and which of these parameters are required, see the Class Builder.
    Objects should only be created once during the program. To ensure that this is the case, enclose the CREATE OBJECT statement(s) in an IF IS INITIAL. ... ENDIF clause. The objects must be generated before the control is displayed for the first time - that is, during the PBO event of the ALV subscreen container.
    To display the requested dataset in the ALV control, the data must be passed on to the control as an internal table, and a field description must exist indicating the order in which the columns will be output.
    In the simplest case, the field description can use a structure from the Dictionary. The Dictionary also determines the technical field attributes like type and length, as well as the semantic attributes like short and long texts. The ALV control uses this information to determine the column widths and headers. The column sequence is determined by the field sequence in the structure.
    If no suitable structure is active in the Dictionary, or you want to output internal program fields in the control, then you will have to define information like the output length and column header in the field catalog.
    In a typical program run, the dataset is read first (SELECT ....), the internal table is filled with the data to display (... INTO TABLE ...), and ABAP statement CALL SCREEN is then used to call the ALV sub screen container.
    The data transfer to the ALV control takes place during the call of method
    set_table_for_first_display from class cl_gui_alv_grid. The method call must be programmed at the PBO event of the ALV subscreen container.
    The name of the Dictionary structure that supplies the field description is specified in exporting parameter i_structure_name. The name of the internal table that contains the data records to display is specified in changing parameter it_outtab.
    The field description for the ALV control can be ta ken from an active Dictionary structure (fully automatic), by passing a field catalog (manual), or through a mixture of the two options (merge).
    The field catalog is in internal table with type lvc_t_fcat. This type is defined globally in the Dictionary.
    Each line in the field catalog table corresponds to a column in the ALV control.
    The field characteristics (= column characteristics) are defined in the field catalog. The field catalog is in internal table with type lvc_t_fcat. Each line that is explicitly described in the ALV control corresponds to a column in the field catalog table.
    The link to the data records to output that are saved in internal table is established through field name . This name must be specified in column "fieldname" in the field catalog.
    This field can be classified through a Dictionary reference (ref_table and ref_field) or by specifying an ABAP data type (inttype).
    Column headers and field names in the detail view of an ALV control line can be determined in the field catalog in coltext and seltext, respectively.
    The position of a field during output can be determined with col_pos in the field catalog.
    If you want to hide a column, fill field no_out with an "X" in the field catalog. Hidden fields can be displayed again in a user display variant.
    Icons can be displayed in the ALV control. If you want a column to be interpreted as an icon, then the icon name must be known to the program (include .) and icon = "X" must be specified for this column in the field catalog.
    The above example shows a semi-automatic field description: Part of the field description comes from the Dictionary structure (sflight), while another part is explicitly defined in the field catalog (gt_fieldcat).
    The field catalog (internal table) is filled in the program and is passed on together with the name of the Dictionary structure during the method call. The information is merged accordingly in method set_table_for_first_display.
    For a user to save display variants, parameters is_variant and i_save must be passed on during method call set_table_for_first_screen. To assign display variants uniquely to a program, at least the program name must be supplied in the transferred structure (gs_variant).
    Program names can be up to 30 characters long.
    If you only pass on the current parameters for is_variant, then existing variants can be loaded, but no new ones can be saved. If you use parameter i_save, you must pass on a variant structure with is_variant.
    I_SAVE = SPACE No variants can be saved.
    I_SAVE = 'U' The user can only save user-specific variants.
    I_SAVE = 'X' The user can only save general (shared) variants.
    I_SAVE = 'A' The user can save both user-specific and general (shared) variants.
    You can use parameter is_layout of method set_table_for_first_display, for example, to define the header in the ALV control and the detail display.
    To do this, define a query area in the program in accordance with Dictionary structure lvc_s_layo, and pass on the text to display in field -grid_title or -detailtitl.
    If you want to create print lists with zebra stripes, set field -zebra to "X". You can display a print preview for print lists by requesting standard function "Print".
    All parameters of method SET_TABLE_FOR_FIRST_DISPLAY from global class
    CL_GUI_ALV_GRID are defined in the Class Builder.
    Events are defined in global class cl_gui_alv_grid; you can use these events to implement user interaction within the program. To respond to a double -click on a table line, you must respond to event DOUBLE_CLICK.
    You receive control in the program, allowing you to implement interactive reporting - such as a full screen details list. The events for cl_gui_alv_grid are located in the Class Builder.
    To define an implement a local class in the program, you use a handler method. In this handler method, you program the functionality to trigger by a double -click in the output table.
    To activate a handler method at runtime, a class or an object from that class registers itself with an event using command SET HANDLER. The names of the IMPORTING parameters in the handler method correspond to the names of the EXPORTING parameters of the related event.
    In the above example, the local class is LCL_ILS and the handler method is ON_DBLCLICK. An object - ALV_DBLCLICK - is created and registers itself for event DOUBLE_CLICK.
    You can query parameter e_row-index to determine which output line was requested by the double -click. This parameter corresponds to the line number of the output table (internal table with the data records to output). If you need information for the selected line, you have to read it with READ TABLE itab INDEX e_row-index.
    This subsequent read in the output table generally corresponds to the HIDE area in conventional reporting. You first have to make sure that the user has double -clicked a line in the output table (similar to the valid line selection with the HIDE technique).
    A field group can contain global data objects, but not data objects that have been defined locally in a subroutine or function module.
    You can use INSERT to specify both fields and field symbols. This makes it possible to dynamically insert a data object referred to by a field symbol into a field group at runtime. Any field symbols that have not been assigned are ignored, which means no new field is inserted into the field group.
    The EXTRACT statement writes all the fields of a field group as one record to a sequential dataset (transport takes place with similarly named fields). If a HEADER field group is defined, then its fields are placed ahead of each record as sort keys. You can then sort the dataset with SORT and process it with LOOP ...ENDLOOP. In this case, no further EXTRACT is possible.
    The INSERT statement is not a declarative statement: This means field groups can also be expanded in the program flow section.
    As soon as the first dataset of a field group has been extracted with EXTRACT, that field group can no longer be expanded with INSERT. In particular, the HEADER field group cannot be expanded after the first EXTRACT (regardless of the field group).
    When the GET events are processed, the logical database automatically writes hexadecimal zeros in all the fields of a node when it returns to an upper-level node in the hierarchy. Since the HEADER normally contains sort fields for all field groups, these hexadecimal zeros in the HEADER serve as a type of hierarchy key: The more zeros there are, the further up in the control level hierarchy you go.
    &#61550;&#61472;The SORT statement sorts the extract dataset in accordance with the defined field sequence in field group HEADER. The addition BY ... sets a new sort key.
    Each must be either a field of field group HEADER or a field group that consists only of fields of the field group HEADER. You can use the additions ASCENDING and DESCENDING to determine whether the fields are sorted in ascending (default) or descending order.
    Fields containing X'00' in the logical databases are always displayed before all other values during a SORT.
    Processing of an extract dataset always takes places within a LOOP. The contents of the extract dataset field are placed in program fields with the same names.
    The group change always involves the fields of the HEADER. Single record processing for extract datasets is performed using language element AT ( = field group).
    CNT() is not a statement, but instead a field that is automatically create d and filled when is a non-numeric field from field group HEADER and is part of the sort key. At the end of the group, CNT() contains the number of different values that the field recorded in this group level.
    SUM() is not a statement, but instead a field that is automatically created and filled when is a numeric field of an extract dataset. At the end of the group, SUM() contains the control total of field .
    *** and CNT are only available at the end of the group level or at AT LAST.
    Single record processing for extract datasets AT WITH is only performed when field group is immediately followed by field group in the temporary dataset.
    Loops over an extract dataset cannot be nested. However, several contiguous loops are permitted.
    The sequence of the control level changes within the LOOP must correspond to the sort sequence.
    Totals can only be calculated within control footer processing.
    Extracts allow only appends (EXTRACT), sorting (SORT) and sequential processing (LOOP).
    Once a SORT or LOOP has occurred, the intermediate dataset is frozen and cannot be expanded with EXTRACT. Operations that insert into or delete from EXTRACT datasets are not supported.
    Extracts allow for several record types (FIELD-GROUPS) with fields that can be set dynamically (INSERT is not a declarative statement!). Internal tables have a single, statically-defined line type.
    Internal tables use the sequence of table fields according to the declaration for the hierarchy of the control leve l. The control level structure for internal tables is therefore static, and is independent of which criteria were used to sort the internal table.
    Extracts do not depend on the field sequence for control level processing: a re-sort or a completely different control level process can take place. The control level structure for extract datasets is therefore dynamic. It corresponds exactly to the sort key of the extract dataset. The sort key is the sequence of fields from the field group HEADER, and is used to sort the extract dataset.
    Extracts rely on the compiler to determine which combinations of group levels and a cumulating field the control level totals desire. The desired control level totals are determined by the processing of LOOP ... ENDLOOP blocks. Internal tables build the control level total with the SUM statement.
    This procedure leads to high resource depletion for totaling control levels in internal tables.
    Regards,
    Chandru

  • How to get sum of bugs for particular Mnth and particular Year dynamically?

    Hi All,
    I've a query related to dynamic date and year :
    select bug_id,
    category,
    count(*) Total_bugs,
    SUM(CASE when bug_date >= '10/1/2011' and bug_date <= '10/31/2011' Then 1 else 0 end) OCT_11,
    SUM(CASE when bug_date >= '9/1/2011' and bug_date<= '9/30/2011' Then 1 else 0 end) SEP_11,
    FROM AA_BUG_TBL
    GROUP BY BUG_ID,BUG_CATEGORY
    In the above query,Can we write one sum statement to get sum of bugs for a particular month and particular year dynamically?
    for ex:2 bugs between 10/1/2011 and 10/31/2011 then 2 under oct_11
    5 bugs between 09/01/11 and 09/30/2011 then 5 under sep_11
    In this case we need to calculate correct no of days for feb
    Thanks,
    Mahender.

    So...
    You need to iterate based on something like the month, quarter, year... Then query on that. I'll use a "WITH" clause to illustrate:
    with my_bugs as
        select bug_id
             , bug_date
             , case when to_char ( bug_date, 'QYYYY' ) = '12009' then 1 else 0 end y2009q1_bug
             , case when to_char ( bug_date, 'QYYYY' ) = '22009' then 1 else 0 end y2009q2_bug
             , case when to_char ( bug_date, 'QYYYY' ) = '32009' then 1 else 0 end y2009q3_bug
             , case when to_char ( bug_date, 'QYYYY' ) = '42009' then 1 else 0 end y2009q4_bug
             , case when to_char ( bug_date, 'YYYY' ) = 2009 then 1 else 0 end y2009_bug
             , case when to_char ( bug_date, 'YYYY' ) = 2010 then 1 else 0 end y2010_bug
             , case when to_char ( bug_date, 'YYYY' ) = 2011 then 1 else 0 end y2011_bug
             , case when 1 = 1 then 1 else 0 end is_bug_flag
          from bugs
      select bug_id
           , bug_date
           , sum   ( y2009q1_bug ) over () as total_bugs_2009q1
           , sum   ( y2009q2_bug ) over () as total_bugs_2009q2
           , sum   ( y2009q3_bug ) over () as total_bugs_2009q3
           , sum   ( y2009q4_bug ) over () as total_bugs_2009q4
           , sum   ( y2009_bug   ) over () as total_bugs_2009
           , count (*)             over ( partition by is_bug_flag ) as total_bugs
        from my_bugsI mocked up some data so my results will be drastically different than yours but here are the results:
        BUG_ID BUG_DATE  TOTAL_BUGS_2009Q1 TOTAL_BUGS_2009Q2 TOTAL_BUGS_2009Q3 TOTAL_BUGS_2009Q4 TOTAL_BUGS_2009 TOTAL_BUGS
          2014 10-SEP-10                 0                 0               114              1143         1257         10000
          2015 14-APR-10                 0                 0               114              1143         1257         10000
          2016 30-NOV-09                 0                 0               114              1143         1257         10000
          2017 03-JUN-11                 0                 0               114              1143         1257         10000
          2018 29-DEC-10                 0                 0               114              1143         1257         10000
          2019 12-JAN-11                 0                 0               114              1143         1257         10000
          2020 21-APR-10                 0                 0               114              1143         1257         10000
          2021 12-JAN-11                 0                 0               114              1143         1257         10000
          2022 29-NOV-10                 0                 0               114              1143         1257         10000
          2023 20-JUL-11                 0                 0               114              1143         1257         10000
          2024 04-MAR-11                 0                 0               114              1143         1257         10000

  • Help needed regarding SUM keyword in an ITAB loop

    Hello,
    I am maintaining a code as given below.
    LOOP AT itab INTO totwa.
    SUM.
    ENDLOOP.
    totwa is defined as a workarea which is needed to hold the sum totals of the fields in the itab. According to the documentation of SUM, it should calculate the sum totals and should put the totals in the workarea mentioned. But somehow its not calculating the value. Could anyone please help me in resolving this issue. Please guide me with your thoughts as to what might have gone wrong.
    Note: the itab fields are of type P.
    Thanks in advance
    Sudha Naik

    Hello Suha
    According to the ABAP documentation the SUM statement is used in a specific situation:
    <b>Syntax
    SUM. </b>
    <b>Effect </b>
    <i>The statement SUM can only be specified within a loop starting with LOOP, and is only considered within a AT-ENDAT control structure. Prerequisites for using the statement SUM include using the addition INTO in the LOOP statement, and that the specified work area wa is compatible with the row type of the internal table. In addition, SUM cannot be used when the row type of the internal table itab contains components that are tables. </i>
    <i>The statement SUM calculates the component total with the numeric data type ( i, p, f) of all rows in the current control level and assigns these to the components of the work area wa. In the control levels FIRST, LAST , and outside of an AT-ENDAT control structure, the system calculates the sum of numeric components of all rows in the internal table.</i>
    I hope the following sample report will clarify the use of <b>SUM </b>and <b>COLLECT</b>.
    *& Report  ZUS_SDN_COLLECT
    REPORT  zus_sdn_collect.
    TYPES: BEGIN OF ty_s_line.
    TYPES:   key(1)    TYPE n.
    TYPES:   value     TYPE p DECIMALS 2.
    TYPES: END OF ty_s_line.
    TYPES: ty_t_itab    TYPE STANDARD TABLE OF ty_s_line
                        WITH DEFAULT KEY.
    DATA:
      gs_line       TYPE ty_s_line,
      gt_itab       TYPE ty_t_itab,
      gt_itab_coll  TYPE ty_t_itab.
    START-OF-SELECTION.
      DO 3 TIMES.
        gs_line-key = syst-index.
        gs_line-value = syst-index * '2.3'.
        APPEND gs_line TO gt_itab.
        APPEND gs_line TO gt_itab.
      ENDDO.
      gs_line-key = 4.
      gs_line-value = '5.5'.
      APPEND gs_line TO gt_itab.
      WRITE: / 'Initial list'.
      LOOP AT gt_itab INTO gs_line.
        WRITE: / gs_line-key,
                 gs_line-value.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using SUM statement with AT END OF'.
      SORT gt_itab BY key.
      LOOP AT gt_itab INTO gs_line.
        AT END OF key.
          SUM.
          WRITE: / gs_line-key,
                   gs_line-value.
        ENDAT.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using SUM statement without control structure (1)'.
      SORT gt_itab BY key.
      LOOP AT gt_itab INTO gs_line.
        SUM.
        WRITE: / gs_line-key,
                 gs_line-value.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using SUM statement without control structure (2)'.
      SORT gt_itab BY key.
      LOOP AT gt_itab INTO gs_line.
        SUM.
        WRITE: / gs_line-key,
                 gs_line-value.
        EXIT.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using COLLECT statement'.
      REFRESH: gt_itab_coll.
      LOOP AT gt_itab INTO gs_line.
        COLLECT gs_line INTO gt_itab_coll.
      ENDLOOP.
      LOOP AT gt_itab_coll INTO gs_line.
        WRITE: / gs_line-key,
                 gs_line-value.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
      WRITE: / 'Using COLLECT statement for total sum'.
      REFRESH: gt_itab_coll.
      LOOP AT gt_itab INTO gs_line.
        gs_line-key = 0.
        COLLECT gs_line INTO gt_itab_coll.
      ENDLOOP.
      LOOP AT gt_itab_coll INTO gs_line.
        WRITE: / gs_line-key,
                 gs_line-value.
      ENDLOOP.
      WRITE: / syst-uline.
      SKIP 2.
    END-OF-SELECTION.
    Regards
      Uwe

  • Need a formula to calulate multiple cells and add the sum total to a cell in a other table

    Im a chef and my monthly inventory is a time consuming task. I get invoices from multiple suppliers on each day of the week. I enter them into a spread sheet and then need to add the sum total for all the invoices for say MONDAY. That total needs to be entered into a cell in another table  called "daily spend". Is there a formula to automatically add say all the invoices from monday and input the daily spend cell on that table. Here is an example
    I created a column B-to give each day a number(sometimes multiple invoices come from the same supplier for each day)<GREEN>..If there was a way to do this differently...Im happy to change the layout of the spreadsheet.  I want to add the total $ (column F)  for each day together(all the blue fields) and then insert the total into another cell seen in the next  table .  So in this example its F4+F16+F17=?, ? inserted into N2 of the next table
    Thanks so much

    "I ve finally has a play with the advice you gave me but I have realized that the formula you gave me is for a week....and like I mentioned in my reply to you, one table is weekly the other is monthly....is there a way to overcome this? (my answer to you explains it)"
    Hi Gavin,
    Unfortunately, the scale of your illustrations in that reply made them difficult (or impossible) to read, even on the Retina screen.
    The first formula, used to fill column B, extracts the Weekday number for each date. Since these numbers should be equivalent to the day of the month, You'll need to replace this with a formula that returns the Day value of each date:
    Old:
    B2: =WEEKDAY(A,2)
    New:
    B2: =DAY(A)
    Fill down to end of column.
    Because of the arrangeent of your Data table, you will need to repeat this formula in column H (with references to column G), etc. for each set of dates in the table.
    The SUMIF formula in column F is fine as is, except that it assumes all condition data will be in column B of Data, and all data to be summed will be in column F of Data. Since this is obviously not the case for your Data table, you will need a separate iteration of the formula for each week in the table, with the four SUMIF statements enclosed in a SUM statement:
    E2: =SUM(SUMIF(Data :: $B,A2,Data :: $F),SUMIF(Data :: $H,A2,Data :: $L),SUMIF(Data :: $N,A2,Data :: $R),SUMIF(Data :: $T,A2,Data :: $X))
    Fill down for as many rows as there are days in the month being summarized.
    Column references in the formula assume that six columns are used for each week, and that there is no gap in the table between weeks.
    Note that the formula does not distinguish between transactions on July 7 and those on June 7 or August 7. Because of this, the Data table must be limited to transactions in a single calendar month.
    Regards,
    Barry

  • Join table SUM using for all entries

    Dear All,
                Will anyone pls. tell me what is the problem in this query, it is not working.
        SELECT aufnr SUM( menge )
         INTO CORRESPONDING FIELDS OF TABLE itab_aufnr
         FROM mkpf
         INNER JOIN mseg ON msegmblnr EQ mkpfmblnr AND mkpfmjahr EQ msegmjahr
         FOR ALL ENTRIES IN itab_rework
          WHERE mseg~aufnr = itab_rework-aufnr
          GROUP BY aufnr.
    Regards,
    Moderator message: please search for available information before asking, "it's not working" is not a proper error description.
    Edited by: Thomas Zloch on Dec 6, 2010 9:41 AM

    When I have used it in loop it is taking so much time to execute.
    That depends upon the amount of data you are processing and the set of codes written inside the loop. For sum you have to use collect statement or a SUM statement inside a control break statement.

  • Trigger that sums free days

    Hi to all,
    I try to write a trigger that fires after an insert or update that drives me crazy!
    My problem is the following: I have a table HOLIDAYS where I have all my free days in a year, always the name and than the number of days, e.g. ('smith', 5). Totally I have 30 days free a year which I can plan. But when I take at least 20 days free from january to march and / or from october to december I get one more day free, so I have 31 days then. I tried to write the trigger that it sums all the free days with the updated or inserted name with the time conditions in the where clause. But nothing works.
    Can anybody help me please?
    Thanks Mandy

    But I get always ora errors:Firstly, a rant. You don't give us the error numbers, I guess that might make things too easy for us. Look, if I'd wanted to spend my time pulling teeth I'd have gone into dentistry. Help us to help you.
    Now I've got that off my chest I'm prepared to take a wild guess. It's ORA-4088, the mutating table bomb. The problem is you are querying the table you are inserting, which causes problems for transactional integrity. When Oracle sums the rows should it include the row that's currently being inserted? What if the next row inserted is also for 'SMITH' - should Oracle go back and recalculate the previous row? These are not simple questions to answer. Processing the SUM() statement leaves the database in an unpredictable statement and that's not allowed. So Oracle hurls ORA-4088 instead.
    There are solutions to this problem around. They tend to involve flag setting, packages, even jobs - all gnarly stuff. The reason it's so difficult is because the information you are trying to capture is not normal (i.e. not 3NF). It is entirely derivable:
    no_of_days free = allowance - sum(END-BEGIN).
    Ah, you say, but what about weekends, etc. Well, the inimitable Connor MacDonald has a solution for calculating Business Days on his website (find it here). I also suggest you take his advice about a table for holding public holidays.
    Now you know how to calculate the amount of holiday taken, you can include the calculation as a function in a view over the HOLIDAYS table. This (in my opinion) is a more elegant solution than pfaffing around with flags, triggers and packages.
    Cheers, APC

  • Xsl sum question

    hi all,
    I'm trying to find the sum of a specific set of nodes and my sum statement looks like this:
    <xsl:value-of select="sum(//row[*[name=$sortDefault]/month=$currentMonth]/obligation)"/>
    This will sum up all the obligation nodes of all the rows that have $sortDefault as the name of the node and their month node equal to $currentMonth, however, I need the rows to have their year node equal to $currentYear also, is there any way i can add that criteria into that statement, month and year nodes are siblings, thanks in advance.

    this is what my xml looks like:
    <row>
    <row>
    <r_object_id>0000FE3451024</r_object_id>
    <kex_agreement>service agreement</kex_agreement>
    - <kex_date date="20050407">
    <fulldate>4/7/05 4:03 PM</fulldate>
    <year>2005</year>
    <month>04</month>
    <day>07</day>
    </kex_date>
    <agreement_name>5</agreement_name>
    <obligation>300</obligation>
    </row>

  • How can i make update efficient

    Hi,
    I have one update statement updating column from value coming from cursor. And its taking time I don't wanna use cursor and update the statement.
    <CODE>
    DECLARE
    CURSOR c1 is select distinct hicn , h from provider_assign_logic;
    begin for x in c1
    loop
    UPDATE provider_assignment_logic p
    SET p.provider4 = (SELECT provider_id FROM (SELECT *
    FROM provider_assignment3 p3
    WHERE hcc = x.hcc
    AND trim(hicn) = x.hicn
    AND provider_id NOT IN (SELECT provider1
    FROM provider_assignment_logic p1
    WHERE trim(p1.hicn) = trim(x.hicn)
    AND p1.hcc = x.hcc)
    AND provider_id NOT IN (SELECT provider2
    FROM provider_assignment_logic p1
    WHERE trim(p1.hicn) = trim(x.hicn)
    AND p1.hcc = x.hcc)
    AND provider_id NOT IN (SELECT provider3
    FROM provider_assignment_logic p1
    WHERE trim(p1.hicn) = trim(x.hicn)
    AND p1.hcc = x.hcc)
    AND ROWNUM = 1
    ORDER BY claim_count,service_date DESC))
    WHERE p.hicn = x.hicn
    AND p.hcc = x.hcc;
    commit;
    end loop;
    <CODE>
    Can you please let me know how i can write update statement efficient without cursor.
    Thanks for help!
    Appreciated!
    Thanks,
    Nick
    end;

    btw it's , not <CODE> - see the FAQ for more formatting tips.
    Also there's a COMMIT inside the loop.                                                                                                                                                                                                                           

Maybe you are looking for

  • New service order type...

    hi all, i copied a new service order type from sm02 (customer service). i am creating a new service order and confirming for activity. but activity cost is not appeared on service order. what will be the reason? (when i use sm02 with the same data, t

  • Image Quality in Writer

    Does Writer display all images as JPEGs? I am trying to insert screen shots of program into a Writer document and I am getting very fuzzy, low-quality display. The images are saved as bitmaps. I have also tried PNG. Regardless of the file format, I g

  • Data pump import from 11g to 10g

    I have 2 database: first is 11.2.0.2.0 and second is 10.2.0.1.0 In 10g i created database link on 11g CREATE DATABASE LINK "TEST.LINK" CONNECT TO "monservice" IDENTIFIED BY "monservice" USING '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP

  • IMac boots to bit-mapped rows of diaganol lines across screen & then freeze

    Im not sure where to post this. Unsure if it's a start-up or a display problem - or both ... A friend of mine was trying to install boot camp on her 17" Early 2006 but the installation failed half-way through ... Now, when the machine is switched bac

  • Date format in CUCM 8.5

    can we change the time format in CUCM 8.5 to dd-mm-yy