Total - Sum of a function

Hi All,
The following is a test I performed in order to check a problem I got.
I created a simple function in Oracle which receives a number and returns it divided by 2. (NUM/2). I registered this function in Discoverer Administrator and then created a simple report with only one column: A calculated column, calling for this formula with the value of 1000. As expected, the returned value was 500. But when I tried to use Total->Sum of this column, it failed. All the other options (Average, Count...) worked, except the sum.
As I mentioned in the beginning, this is just a test for my real situation.
Any ideas how it can be solved?

Hi
Other than the neat workaround suggested by Russ, if my memory serves me right that issue was fixed in the final release for 4.1 - 4.1.48
The patch to upgrade Discoverer 4.1 Admin and Desktop is 3201601, while for Plus and Viewer the patch is 3201610. These patches will upgrade you to 4.1.48.06. If you are using E-Business Suite the patch you need is 3451636 which is the upgrade to 4.1.48.08.
All of these patches are still available for download on Metalink.
For further information on the latest patches please look on my blog here: http://learndiscoverer.blogspot.com/2006/09/releases-and-patch-numbers-september.html
I'll be updating this again very soon with the latest information for other releases but for 4.1 my posting is accurate.
Best wishes
Michael

Similar Messages

  • I want to be able to totally block the FaceTime functionality in my home network.  I would like to do this at the router level.  Does anyone know the hostname or IP address that the FaceTime application uses? Or which port it connects to?

    I want to be able to totally block the FaceTime functionality in my home network so my 4 kids aren't using the Facetime feature- It was easy for Skype just had to enter the work Skype on my Router Security list- and it denies access. I would like to do this at the router level for FaceTime? Only site I find in init.ess.apple.com - is this the startup site for Facetime?   Does anyone know a site I can block, hostname or IP address that the FaceTime application uses? Or which port it connects to?

    I would presume so, but it might be worth your while to experiment and play around with different combinations to see if you can block FaceTime while keeping Game Center open.  Good luck!

  • Total sum to be displayed in a table view control ?

    Hi,
      I am unable to display the total sum of a column in a table view control( using HTMLB ). How should one display the sum of a column ?
    THanks in advance,
    VaraPrasad

    Hi,
    it should work once you are restricting the capacity of the out put port then it should provide that much rows only otherwise its a Bug.
    Alternativily you are tellin to disaply using sorting then add a Sort operator to the output port and the display ur output port in down order.
    But first option should work just check it again.
    On which SP u r working?
    Regards,
    Govindu

  • How to Hide rows in ALV without affecting total sum at the end of table?

    Hi,
    I need some help in hiding particular rows in an ALV Grid without affecting the total sum at the end of the table. I am trying to hide the rows that have negative quantities, but I still need those values so that the user can still compute for the total sums. Can anyone help? Thanks.
    Joseph

    Hi,
    Hopw this way you can hide the rows in the GRID.
    DATA:
      ld_column      TYPE lvc_fname,
      ld_hide          TYPE abap_bool.
    FIELD-SYMBOLS:
      <ls_entry>     TYPE any,
      <ld_fld>         TYPE any.
      ld_column = 'COL_1'.  " column which you want to suppress if everything is zero
      ld_hide     = abap_true.  " = 'X';  default hide column
      LOOP at <gt_outtab> ASSIGNING <ls_entry>.
        ASSIGN COMPONENT (ld_column) OF STRUCTURE <ls_entry> TO <ld_fld>.
        IF ( <ld_fld>   > 0 ).
          ld_hide = abap_false.  " display column because at least single value > 0
          EXIT.  " leave LOOP
        ENDIF.
      ENDLOOP.
      READ TABLE gt_fcat INTO ls_fcat
                           WITH KEY fieldname = ld_column.
      IF ( syst-subrc = 0 ).
        ls_fcat-no_out = ld_hide.
        MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
      ENDIF.
    hop you will get the total with for those columns too.
    Regards,
    Madhavi

  • Different units in total sum row

    Hello Bex Experts,
    I have orders with different Units in a report. currently the total sum row show * for Mix
    How can I get the total sum for ST and KG like
    Total Sum 366 KG
    Total Sum 342 ST
    BR Matthias

    Hi Matthias,
    If you want to sum their numbers regardless of the UNITS, just use the NODIM() in formula..But if you need to add them and have 1 unit for the result, you must convert one of the them to another unit..
    Regards,
    Loed

  • Displaying a total sum value in the af:table - footer

    Hello everyone,
    I have seen various threads on how to calculate a summary column based on a af:column in an af:table. I would like the value of this column to be displayed in the af:table -> footer (right undernead the af:column)
    I'm having trouble putting together the pieces. This is the last requirement I have on this page, so hopefully I won't have to start all over.
    Here this what I have:
    I have created my page. (jspx) I did not create the page with a "backing bean". I have seen in various threads that the backing bean can be used to programmatically populate the table.
    This is what I have done so far.
    For the DataModel:
    I have created my entity object, and I have a view assigned to the object. I assigned the view to my Application Module.
    For the UserInterface:
    On the layout, I dragged the instance of the view from the page definition. I created an af:table.
    My questions/train of thought are:
    I didn't create a "backing bean" when I first created my jspx page. From the various threads that I have seen, they all reference this. Can anyone explain how I can do this when the page has already been created? I'm using jdev version 10.1.3.3
    Within the backing bean, I assume this is where I would then create a method that would do the "sum" of my column.
    To display the column:
    I would then create an af:output_text and drag it to theh table footer. The binding section
    If anyone has a prior thread that I haven't found that can point me in the right direction with what I already I would really appreciate it.
    Thanks

    Kuba,
    By creating a managed bean against the page definition, you are able to access the "iterator". The iterator is an object that is based off of hte View object (which the page is build off of)... From there, you can then loop through the rows and add them together to come up with the total sum.
    You can then reference this method in the TEST.java class since it was created as a managed bean.
    I believe I got the gist of it now... Coming from an Oracle Forms perspecitive, it is actually pretty similar. Now I understand what Managed Beans are used for. Thanks again for the great example.
    Danny

  • How to get total sum of big filtered table?

    Hello
    I'm using JDeveloper 11.1.1.3.0
    I have an af:table with big data source (100 000 rows). The table have filters.
    I want to display total count of the filtered rows and total sum by the one of column of the filtered rows in the footer of the table.
    In my backing bean I can get a Map with all filter values:
    Map<String, Object> filters = ((FilterableQueryDescriptor)table.getFilterModel()).getFilterCriteria();And, in this case, I may create the method for getting sum I need on my own.
    In this method I may create SQL Query dynamically, because I have to process all filter values with different types
    It is possible, but, maybe, there is a more easy way to do it?
    Anatolii

    Hi, sanchezis
    Code example.
    In the jsp:
                    <af:column sortProperty="Sumv" sortable="true" filterable="false" align="end" width="125px"
                               headerText="#{bindings.TransactionView1.hints.Sumv.label}" id="c16">
                      <af:outputText value="#{row.Sumv}" id="qt4">
                        <af:convertNumber maxFractionDigits="2" minFractionDigits="2"/>
                      </af:outputText>
                      <f:facet name="footer">
                          <af:panelGroupLayout id="pg41" halign="right"
                                               layout="vertical">             
                        <af:outputText value="#{backing_reptransactions.tableTransactionTotalSumV}" id="ot44">
                          <af:convertNumber maxFractionDigits="2" minFractionDigits="2"/>
                        </af:outputText>
                        </af:panelGroupLayout>
                      </f:facet>
                    </af:column>In the backing bean:
        public double getTableTransactionTotalSumV() {
            DCIteratorBinding iter =
                binding.findIteratorBinding("TransactionView1Iterator");
            TransactionViewImpl vo = (TransactionViewImpl)iter.getViewObject();
            return vo.getFilteredTotalSumV();
        }In the ViewImpl (TransactionViewImpl) class.
        public double getFilteredTotalSumV() {
            double sumV = 0d;
            DBTransaction dbTransaction = getDBTransaction();
            ResultSet rs = null;
            String query = "SELECT SUM(SumV) sumvtotal FROM (" + getQuery() + ")";
            String str1 = "WHERE ROWNUM < :Bind_RangePage_High";
            String str2 = "WHERE Z_R_N > :Bind_RangePage_Low";
            int i = query.indexOf(str1);
            if (i > 0) {
                query = query.substring(0, i) + " " + query.substring(i + str1.length());
            i = query.indexOf(str2);
            if (i > 0) {
                query = query.substring(0, i) + " " + query.substring(i + str2.length());
            PreparedStatement st = dbTransaction.createPreparedStatement(query, 0);
            try {
                Object[] params = this.getWhereClauseParams();
                int index = 0;
                for (Object avalue : params) {
                    String key = (String)((Object[])avalue)[0];
                    if ((!key.equals("Bind_RangePage_High")) &&
                        (!key.equals("Bind_RangePage_Low"))) {
                        Object value = ((Object[])avalue)[1];
                        index++;
                        if (value instanceof Integer) {
                            st.setInt(index, (Integer)value);
                        } else if (value instanceof oracle.jbo.domain.Date) {
                            st.setDate(index,
                                       ((oracle.jbo.domain.Date)value).dateValue());
                        } else if (value instanceof java.sql.Date) {
                            st.setDate(index, (Date)value);
                        } else {
                            st.setString(index, (String)value);
                rs = st.executeQuery();
                if (rs.next()) {
                    sumV = rs.getDouble("sumvtotal");
            } catch (SQLException e) {
                throw new JboException(e);
            } finally {
                if (st != null) {
                    try {
                        st.close();
                    } catch (SQLException e) {
            return sumV;
        public long getFilteredTotalCount() {
            return this.getEstimatedRowCount();
        }But, you need to know that in the TransactionView in the "General" - "Tuning" I set up next values:
    "All rows",
    "As needed",
    "Fill Last Page of Rows when Paging through Rowset",
    "Passivate State(..."
    Access Mode - "Range Paging Incremental"
    Range Size - 160
    Range Paging Cache Factor - 3
    If you have other values, then your SQL request may be different, so, you will have to rewrite it.
    I talk about
    "WHERE ROWNUM < :Bind_RangePage_High",
    "WHERE Z_R_N > :Bind_RangePage_Low",
                    if ((!key.equals("Bind_RangePage_High")) &&
                        (!key.equals("Bind_RangePage_Low")))If you have other solution, please, tell me.
    Anatolii

  • Smartform total sum

    Hi All,
    I am a newer of smartform. Now I face a problem, I want to do total sum at the bottom of main table without showed at each page. But I tried many method and it is not ok.
    Plz help me.

    Hi,
    In the node where u r printing the value , u will be printing each value in the textelement.  so Before that text elelment u create a program line.
    u take a variable and assign the variable as zero .
    in the program lines u put the code as
    variable = variable + (text-value).
    ex:-itab-menge.( uwant to make sum of menge).
    var type menge.  = 0.(This u do in global def.).
    in the program lines.
    var = var + itab-menge.
    after the loop.
    var will be sum of the all .
    Assign points if useful.

  • ABAP Dump while doing total(summing up)

    Hello Experts
    I have a report:
    This program reads Sales Order and Delivery information. When i tried to sum the Order Quantity, an ABAP Dump is coming. Can anyone help me in correcting my Code?
    Program looks like following and DUMP follows.
    Global data declaration
    TYPE-POOLS: slis.
    TABLES: vbap, vbrk, vbfa, vbak, vbrp, konv, kna1, bkpf, bsad, bkpf_bsad,
    knvv, pa0002, t005u, mvke, lips, likp, vbpa, vbep.
    DATA: BEGIN OF i_list OCCURS 0,
          vbeln LIKE vbak-vbeln,
          posnr LIKE vbap-posnr,
          etenr like vbep-etenr,
          matnr LIKE vbap-matnr,
          erdat LIKE vbap-erdat,
          mvgr1 LIKE mvke-mvgr1,
          wadat_ist LIKE likp-wadat_ist,
          days TYPE i,
          werks LIKE vbap-werks,
          lgort LIKE vbap-lgort,
          kwmeng LIKE vbap-kwmeng,"                                  CH01+
          lfimg  LIKE lips-lfimg,"                                   CH01+
          pstyv  LIKE vbap-pstyv,"                                   CH01+
          obd    LIKE lips-vbeln,"                                   CH01+
          obd_pos LIKE lips-posnr,"                                  CH01+
          soldto  LIKE vbaK-kunnr,"                                  JR+
          shipto  LIKE vbpa-kunnr,"                                  JR+
          edatu like vbep-edatu,"                                    PR+
          END OF i_list.
    DATA: i_list2 LIKE i_list OCCURS 0 WITH HEADER LINE,
          i_list3 LIKE i_list OCCURS 0 WITH HEADER LINE.
    DATA: i_list4 LIKE vbap OCCURS 0 WITH HEADER LINE.
    *ALV Output Header
    DATA: gt_list_top_of_page TYPE slis_t_listheader,
          prognm     LIKE sy-repid,
          gc_formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE',
          gt_events   TYPE slis_t_event,
          is_layout TYPE slis_layout_alv,
          is_variant LIKE disvariant,
          it_sort  TYPE slis_t_sortinfo_alv WITH HEADER LINE.
    DATA:gt_fieldcat TYPE slis_t_fieldcat_alv.
    DATA:gt_outtab LIKE i_list OCCURS 0 WITH HEADER LINE.
    DATA:   g_repid LIKE sy-repid,
            g_count LIKE sy-tabix.
    SELECTION-SCREEN BEGIN OF BLOCK block0 WITH FRAME TITLE text-t01.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(79) text-t10.
    SELECTION-SCREEN: END OF LINE.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(79) text-t11.
    SELECTION-SCREEN: END OF LINE.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(79) text-t12.
    SELECTION-SCREEN: END OF LINE.
    SELECTION-SCREEN END OF BLOCK block0.
    */ Selection and Input Parameters
    SELECTION-SCREEN BEGIN OF BLOCK blocko WITH FRAME TITLE text-001.
    SELECT-OPTIONS: s_vbeln FOR vbap-vbeln, "SO
                    s_auart FOR vbak-auart DEFAULT 'KB' OBLIGATORY,
                    s_matnr FOR vbap-matnr," obligatory,
                    s_mvgr1 FOR mvke-mvgr1,
                    s_erdat FOR vbap-erdat OBLIGATORY,
                    s_werks FOR vbap-werks,
                    s_lgort FOR vbap-lgort,
                    s_edatu FOR vbep-edatu.
    PARAMETERS:     p_vkorg LIKE vbak-vkorg DEFAULT '5010'.
    SELECTION-SCREEN SKIP 2.
    +EC1
    Addition                                                          +EC1
    +EC1
    PARAMETERS: p_vari LIKE disvariant-variant.
    +EC1
    End Addition                                                      +EC1
    +EC1
    SELECTION-SCREEN END OF BLOCK blocko.
    +EC1
    Addition                                                          +EC1
    +EC1
    DATA:   g_save(1) TYPE c,
           g_default(1) TYPE c,
            g_exit(1) TYPE c,
            gx_variant LIKE disvariant,
            g_variant LIKE disvariant.
    +EC1
    End Addition                                                      +EC1
    +EC1
    Initialization fieldcatalog
    INITIALIZATION.
    PERFORM clear_tables.
      g_repid = sy-repid.
      PERFORM fieldcat_init USING gt_fieldcat[].
    +EC1
    Addition                                                          +EC1
    +EC1
      g_save = 'A'.
      PERFORM variant_init.
    Get default variant
      gx_variant = g_variant.
      CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
           EXPORTING
                i_save     = g_save
           CHANGING
                cs_variant = gx_variant
           EXCEPTIONS
                not_found  = 2.
      IF sy-subrc = 0.
        p_vari = gx_variant-variant.
      ENDIF.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.
      PERFORM f4_for_variant.
    AT SELECTION-SCREEN.
      PERFORM auth_check.  "+ESC
      PERFORM pai_of_selection_screen.
    +EC1
    End Addition                                                      +EC1
    +EC1
    START-OF-SELECTION.
      PERFORM get_data.
      PERFORM alv.
    END-OF-SELECTION.
          FORM get_data                                                 *
    FORM get_data.
    *CH01 - Added kwmeng(order qty) to selection, excluded rejects
    *JR -added soldto and shipto code
      SELECT avbeln aposnr amatnr aerdat awerks algort
             akwmeng apstyv bkunnr cedatu
    CH01+
      INTO
    (i_list-vbeln, i_list-posnr, i_list-matnr, i_list-erdat, i_list-werks,
    i_list-lgort,
    i_list-kwmeng , i_list-pstyv, i_list-soldto,i_list-edatu)
           CH01+
      FROM vbap AS a INNER JOIN vbak AS b ON avbeln = bvbeln
                     INNER JOIN vbep AS c ON avbeln = cvbeln
      WHERE b~vkorg = p_vkorg
      AND   a~werks IN s_werks
      AND   a~lgort IN s_lgort
      AND   b~auart IN s_auart
      AND   a~vbeln IN s_vbeln
      AND   a~erdat IN s_erdat
      AND   a~abgru = ''"                                            CH01+
      AND   a~matnr IN s_matnr
      AND   c~edatu IN s_edatu.
        APPEND i_list.
      ENDSELECT.
      COMMIT WORK AND WAIT.
    SORT i_list BY VBELN POSNR EDATU.
    DELETE ADJACENT DUPLICATES FROM i_list COMPARING vbeln posnr.
      LOOP AT i_list.
        SELECT SINGLE mvgr1 INTO i_list-mvgr1 FROM mvke
        WHERE matnr = i_list-matnr.
        MODIFY i_list.
        CLEAR: i_list.
      ENDLOOP.
      COMMIT WORK AND WAIT.
      LOOP AT i_list.
        IF i_list-mvgr1 IN s_mvgr1.
          CONTINUE.
        ELSE.
          DELETE i_list.
          COMMIT WORK AND WAIT.
        ENDIF.
      ENDLOOP.
    CH01 - commented these lines out and redid logic below
    LOOP AT i_list.
       select single vbeln into lips-vbeln from lips
       where vgbel = i_list-vbeln
       and   vgpos = i_list-posnr.
       select single wadat_ist into i_list-wadat_ist from likp
       where vbeln = lips-vbeln.
       SELECT b~wadat_ist  INTO i_list-wadat_ist
       FROM lips AS a INNER JOIN
       likp AS b ON avbeln = bvbeln WHERE a~vgbel = i_list-vbeln
                                      AND   a~vgpos = i_list-posnr.
         MODIFY i_list.
         CLEAR: i_list, lips-vbeln.
       ENDSELECT.
    ENDLOOP.
    CH01 - Changed to select multiple delivery lines & del qty
    summing the total deliveries per OBD# and date
      LOOP AT i_list.
        SELECT avbeln   sum( alfimg ) b~wadat_ist
        INTO (i_list-obd , i_list-lfimg , i_list-wadat_ist)
        FROM lips AS a INNER JOIN
        likp AS b ON avbeln = bvbeln WHERE a~vgbel = i_list-vbeln
                                       AND   a~vgpos = i_list-posnr
                                       AND   a~pstyv = i_list-pstyv
          group by avbeln bwadat_ist.
          i_list2 = i_list.
          APPEND i_list2.
        ENDSELECT.
        IF sy-subrc <> 0.
          i_list2 = i_list.
          APPEND i_list2.
        ENDIF.
      ENDLOOP.
      i_list[] = i_list2[].
    *End CH01
      COMMIT WORK AND WAIT.
      LOOP AT i_list.
        IF  i_list-wadat_ist IS INITIAL.
          CONTINUE.
        ELSE.
          i_list-days = i_list-wadat_ist - i_list-erdat.
        ENDIF.
        MODIFY i_list.
        CLEAR: i_list.
        COMMIT WORK AND WAIT.
      ENDLOOP.
      COMMIT WORK AND WAIT.
      LOOP AT i_list.
        IF i_list-vbeln IS INITIAL.
          DELETE i_list.
        ENDIF.
      ENDLOOP.
      COMMIT WORK AND WAIT.
    *JR
      LOOP AT i_list.
        SELECT SINGLE KUNNR INTO i_list-shipto FROM vbpa
        WHERE vbeln = i_list-vbeln
         AND parvw = 'WE'.
        MODIFY i_list.
      ENDLOOP.
    *END JR
      gt_outtab[] = i_list[].
      COMMIT WORK AND WAIT.
    ENDFORM.
          FORM alv                                                      *
    FORM alv.
      PERFORM e03_eventtab_build USING gt_events[].             "+EC1
      PERFORM e04_comment_build  USING gt_list_top_of_page[].   "+EC1
      prognm = sy-repid.                                        "+EC1
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
          EXPORTING
               i_callback_user_command = 'USER_COMMAND'
               i_callback_program      = g_repid
               it_fieldcat             = gt_fieldcat[]
               it_events               = gt_events[]    "+ESC
               it_sort                 = it_sort[]
    +EC1
    Addition                                                          +EC1
    +EC1
               is_variant              = g_variant
               i_save                  = g_save
    +EC1
    End Addition                                                      +EC1
    +EC1
          TABLES
               t_outtab                = gt_outtab.
      COMMIT WORK AND WAIT.
    ENDFORM.
          FORM fieldcat_init                                            *
    -->  I_FIELDCAT                                                    *
    FORM fieldcat_init
          USING i_fieldcat TYPE slis_t_fieldcat_alv.
      DATA: ls_fieldcat TYPE slis_fieldcat_alv.
      DATA: pos TYPE i VALUE 1.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       =  pos.
      ls_fieldcat-fieldname     = 'VBELN'.
      ls_fieldcat-ref_tabname   = 'VBAK'.
      ls_fieldcat-key           = 'X'.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       =  pos.
      ls_fieldcat-fieldname     = 'POSNR'.
      ls_fieldcat-ref_tabname   = 'VBAP'.
      ls_fieldcat-key           = 'X'.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       =  pos.
      ls_fieldcat-fieldname     = 'MATNR'.
      ls_fieldcat-ref_tabname   = 'VBAP'.
      ls_fieldcat-key           = 'X'.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       =  pos.
      ls_fieldcat-fieldname     = 'MVGR1'.
      ls_fieldcat-ref_tabname   = 'MVKE'.
      ls_fieldcat-key           = 'X'.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       =  pos.
      ls_fieldcat-fieldname     = 'WERKS'.
      ls_fieldcat-ref_tabname   = 'VBAP'.
    ls_fieldcat-key           = 'X'.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       =  pos.
      ls_fieldcat-fieldname     = 'LGORT'.
      ls_fieldcat-ref_tabname   = 'VBAP'.
    ls_fieldcat-key           = 'X'.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       =  pos.
      ls_fieldcat-fieldname     = 'ERDAT'.
      ls_fieldcat-ref_tabname   = 'VBAP'.
    ls_fieldcat-key           = 'X'.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       =  pos.
      ls_fieldcat-fieldname     = 'WADAT_IST'.
      ls_fieldcat-ref_tabname   = 'LIKP'.
    ls_fieldcat-key           = 'X'.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       =  pos.
      ls_fieldcat-fieldname     = 'DAYS'.
      ls_fieldcat-ref_fieldname = 'DAYS'.
      ls_fieldcat-seltext_s     = '# Of Days'.
      ls_fieldcat-seltext_m     = '# Of Days'.
      ls_fieldcat-seltext_l     = '# Of Days'.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
    *Begin CH01
      pos = pos + 1.
      ls_fieldcat-col_pos       =  pos.
      ls_fieldcat-fieldname     = 'KWMENG'.
      ls_fieldcat-ref_tabname   = 'VBAP'.
      ls_fieldcat-outputlen     = 7.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       =  pos.
      ls_fieldcat-fieldname     = 'LFIMG'.
      ls_fieldcat-ref_tabname   = 'LIPS'.
      ls_fieldcat-outputlen     = 7.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       =  pos.
      ls_fieldcat-fieldname     = 'OBD'.
      ls_fieldcat-seltext_s     = 'OBD'.
      ls_fieldcat-seltext_m     = 'Outbound Del'.
      ls_fieldcat-seltext_l     = 'Outbound Delivery'.
      ls_fieldcat-outputlen     = 10.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
    ls_fieldcat-col_pos       =  pos.
    ls_fieldcat-fieldname     = 'OBD_POS'.
    ls_fieldcat-seltext_s     = 'OBD Ln'.
    ls_fieldcat-seltext_m     = 'Outbound Del Ln'.
    ls_fieldcat-seltext_l     = 'Outbound Del Line'.
    ls_fieldcat-outputlen     = 10.
    APPEND ls_fieldcat TO i_fieldcat.
    CLEAR ls_fieldcat.
    *End CH01
    *JR
      pos = pos + 1.
      ls_fieldcat-col_pos       =  pos.
      ls_fieldcat-fieldname     = 'SOLDTO'.
      ls_fieldcat-ref_tabname   = 'VBAP'.
      ls_fieldcat-seltext_m     = 'Sold To'.
      ls_fieldcat-seltext_l     = 'Sold To'.
      ls_fieldcat-outputlen     = 10.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos       =  pos.
      ls_fieldcat-fieldname     = 'SHIPTO'.
      ls_fieldcat-ref_tabname   = 'VBPA'.
      ls_fieldcat-seltext_m     = 'Ship To'.
      ls_fieldcat-seltext_l     = 'Ship To'.
      ls_fieldcat-outputlen     = 10.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
      pos = pos + 1.
      ls_fieldcat-col_pos = pos.
      ls_fieldcat-fieldname = 'ETERN'.
      ls_fieldcat-ref_tabname = 'VBEP'.
      ls_fieldcat-seltext_m     = 'Schedule line number'.
      ls_fieldcat-seltext_l     = 'Schedule line number'.
    ls_fieldcat-key = 'Schedule line number'.
      APPEND ls_fieldcat TO i_fieldcat.
      CLEAR ls_fieldcat.
    *END JR
    pos = pos + 1.
    ls_fieldcat-col_pos = pos.
    ls_fieldcat-fieldname = 'EDATU'.
    ls_fieldcat-ref_tabname = 'VBEP'.
    ls_fieldcat-seltext_m = 'Requested Delivery date'.
    ls_fieldcat-seltext_l = 'Requested Delivery date'.
    ls_fieldcat-outputlen = 20.
    APPEND ls_fieldcat TO i_fieldcat.
    CLEAR ls_fieldcat.
    *FOR ALV SORT & SUBTOTAL
      CLEAR it_sort.
      it_sort-spos = '0'.
      it_sort-fieldname = 'VBELN'.
      it_sort-tabname = 'GT_OUTTAB'.
      it_sort-up = 'X'.
    it_sort-subtot = 'X'.
      APPEND it_sort.
      CLEAR it_sort.
      it_sort-spos = '1'.
      it_sort-fieldname = 'POSNR'.
      it_sort-tabname = 'GT_OUTTAB'.
      it_sort-up = 'X'.
      it_sort-subtot = 'X'.
    it_sort-subtot = 'X'.
      APPEND it_sort.
      CLEAR it_sort.
      it_sort-spos = '2'.
      it_sort-fieldname = 'MATNR'.
      it_sort-tabname = 'GT_OUTTAB'.
      it_sort-up = 'X'.
    it_sort-subtot = 'X'.
      APPEND it_sort.
      CLEAR it_sort.
      it_sort-spos = '3'.
      it_sort-fieldname = 'MVGR1'.
      it_sort-tabname = 'GT_OUTTAB'.
      it_sort-up = 'X'.
    it_sort-subtot = 'X'.
      APPEND it_sort.
      CLEAR it_sort.
      it_sort-spos = '4'.
      it_sort-fieldname = 'ERDAT'.
      it_sort-tabname = 'GT_OUTTAB'.
      it_sort-up = 'X'.
    it_sort-subtot = 'X'.
      APPEND it_sort.
      CLEAR it_sort.
      it_sort-spos = '5'.
      it_sort-fieldname = 'WADAT_IST'.
      it_sort-tabname = 'GT_OUTTAB'.
      it_sort-down = 'X'.
    it_sort-subtot = 'X'.
      APPEND it_sort.
    CLEAR it_sort.
    it_sort-spos = '6'.
    it_sort-fieldname = 'PERNR'.
    it_sort-tabname = 'GT_OUTTAB'.
    it_sort-up = 'X'.
    it_sort-subtot = 'X'.
    APPEND it_sort.
    CLEAR it_sort.
    it_sort-spos = '7'.
    it_sort-fieldname = 'VORNA'.
    it_sort-tabname = 'GT_OUTTAB'.
    it_sort-up = 'X'.
    it_sort-subtot = 'X'.
    APPEND it_sort.
    CLEAR it_sort.
    it_sort-spos = '8'.
    it_sort-fieldname = 'NACHN'.
    it_sort-tabname = 'GT_OUTTAB'.
    it_sort-up = 'X'.
    it_sort-subtot = 'X'.
    APPEND it_sort.
    CLEAR it_sort.
    it_sort-spos = '9'.
    it_sort-fieldname = 'VKGRP'.
    it_sort-tabname = 'GT_OUTTAB'.
    it_sort-up = 'X'.
    it_sort-subtot = 'X'.
    APPEND it_sort.
    CLEAR it_sort.
    it_sort-spos = '10'.
    it_sort-fieldname = 'VBELN'.
    it_sort-tabname = 'GT_OUTTAB'.
    it_sort-up = 'X'.
    it_sort-subtot = 'X'.
    APPEND it_sort.
    CLEAR it_sort.
    it_sort-spos = '11'.
    it_sort-fieldname = 'ERDAT'.
    it_sort-tabname = 'GT_OUTTAB'.
    it_sort-up = 'X'.
    it_sort-subtot = 'X'.
    APPEND it_sort.
    CLEAR it_sort.
    it_sort-spos = '12'.
    it_sort-fieldname = 'BEZEI'.
    it_sort-tabname = 'GT_OUTTAB'.
    it_sort-up = 'X'.
    it_sort-subtot = 'X'.
    APPEND it_sort.
    clear it_sort.
    it_sort-spos = '1'.
    it_sort-fieldname = 'BELNR'.
    it_sort-tabname = 'GT_OUTTAB'.
    it_sort-up = 'X'.
    append it_sort.
    ENDFORM.
    +EC1
    Addition                                                          +EC1
    +EC1
    *&      Form  VARIANT_INIT
          text
    -->  p1        text
    <--  p2        text
    FORM variant_init.
      CLEAR g_variant.
      g_variant-report = g_repid.
    ENDFORM.                               " VARIANT_INIT
          FORM f4_for_variant                                           *
    FORM f4_for_variant.
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
           EXPORTING
                is_variant          = g_variant
                i_save              = g_save
              it_default_fieldcat =
           IMPORTING
                e_exit              = g_exit
                es_variant          = gx_variant
           EXCEPTIONS
                not_found = 2.
      IF sy-subrc = 2.
        MESSAGE ID sy-msgid TYPE 'S'      NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ELSE.
        IF g_exit = space.
          p_vari = gx_variant-variant.
        ENDIF.
      ENDIF.
    ENDFORM.
    *&      Form  PAI_OF_SELECTION_SCREEN
          text
    FORM pai_of_selection_screen.
      IF NOT p_vari IS INITIAL.
        MOVE g_variant TO gx_variant.
        MOVE p_vari TO gx_variant-variant.
        CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
             EXPORTING
                  i_save     = g_save
             CHANGING
                  cs_variant = gx_variant.
        g_variant = gx_variant.
      ELSE.
        PERFORM variant_init.
      ENDIF.
    ENDFORM.                               " PAI_OF_SELECTION_SCREEN
    +EC1
    End Addition                                                      +EC1
    +EC1
          FORM e03_eventtab_build                                       *
    -->  E03_LT_EVENTS                                                 *
    FORM e03_eventtab_build USING e03_lt_events TYPE slis_t_event.
      DATA: ls_event TYPE slis_alv_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
           EXPORTING
                i_list_type = 0
           IMPORTING
                et_events   = e03_lt_events.
      READ TABLE e03_lt_events WITH KEY name =  slis_ev_top_of_page
                               INTO ls_event.
      IF sy-subrc = 0.
        MOVE gc_formname_top_of_page TO ls_event-form.
        APPEND ls_event TO e03_lt_events.
      ENDIF.
    ENDFORM.
          FORM e04_comment_build                                        *
    -->  E04_LT_TOP_OF_PAGE                                            *
    FORM e04_comment_build USING e04_lt_top_of_page TYPE slis_t_listheader.
      DATA: ls_line TYPE slis_listheader.
    *Report Title
      CLEAR ls_line.
      ls_line-typ  = 'H'.
      ls_line-info = text-007.
      APPEND ls_line TO e04_lt_top_of_page.
    **Doc Type Desc.
    clear ls_line.
    ls_line-typ  = 'S'.
    ls_line-key = text-008.
    ls_line-info = p_matnr.
    append ls_line to e04_lt_top_of_page.
    clear ls_line.
    ls_line-typ  = 'S'.
    ls_line-key  = text-009.
    ls_line-info = p_werks.
    append ls_line to e04_lt_top_of_page.
    clear ls_line.
    ls_line-typ  = 'S'.
    ls_line-key = text-010.
    ls_line-info = p_stlan.
    append ls_line to e04_lt_top_of_page.
    clear ls_line.
    ls_line-typ  = 'S'.
    ls_line-key = text-011.
    ls_line-info = p_stlal.
    append ls_line to e04_lt_top_of_page.
    clear ls_line.
    ls_line-typ  = 'S'.
    ls_line-key = text-012.
    ls_line-info = p_stlal.
    append ls_line to e04_lt_top_of_page.
    ENDFORM.
          FORM top_of_page                                              *
    FORM top_of_page.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
           EXPORTING
                it_list_commentary = gt_list_top_of_page.
    ENDFORM.
          FORM auth_check                                               *
    FORM auth_check.
      AUTHORITY-CHECK OBJECT 'V_VBAK_VKO'
                      ID 'VKORG' FIELD p_vkorg.
      IF sy-subrc NE 0.
        MESSAGE e054 WITH p_vkorg.
      ENDIF.
    ENDFORM.                    " auth_check
    *&      Form  USER_COMMAND
    FORM user_command  USING r_ucomm LIKE sy-ucomm
                             rs_selfield TYPE slis_selfield.
      CASE r_ucomm.
        WHEN '&IC1'.
          PERFORM display_so_order USING r_ucomm
                                        rs_selfield.
      ENDCASE.
    ENDFORM.
    *&      Form  display_sales_order
          text
         -->P_R_UCOMM  text
         -->P_RS_SELFIELD  text
    FORM display_so_order USING    r_ucomm LIKE sy-ucomm
                                             rs_selfield TYPE slis_selfield.
      CASE rs_selfield-sel_tab_field.
        WHEN '1-VBELN'.
          SET PARAMETER ID 'AUN' FIELD rs_selfield-value.
          CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
        WHEN '1-MATNR'.
          SET PARAMETER ID 'MAT' FIELD rs_selfield-value.
          CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
        WHEN '1-OBD'.
          SET PARAMETER ID 'VL' FIELD rs_selfield-value.
          CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.
        WHEN OTHERS.
          MESSAGE i000(z1) WITH 'Please Click on the Valid Selection'.
          EXIT.
      ENDCASE.
    ENDFORM.                    " display_sales_order
          FORM EDit_table                                               *
    -do_sum = 'C'.     
    009350   *     save the actual grouplevel information                        
    009360         gs_grouplevels = rs_grouplevels.                              
    009370         clear g_lines.                                                
    009380                                                                       
    009390   *     get number of lines of the collect table                      
    009400         describe table rt_data lines g_lines.                         
    009410   *     if there is only one line or the field has no references so   
    009420   *     that only the first line has to be considered                                                                               
    Contents of system fields                                                                               
    SY field contents..................... SY field contents.....................                                                                               
    SY-SUBRC 4                             SY-INDEX 1                                      
    SY-TABIX 15                            SY-DBCNT 1                                      
    SY-FDPOS 1                             SY-LSIND 0                                      
    SY-PAGNO 0                             SY-LINNO 1            
    SY-COLNO 1                                                                               
    Chosen variables                                                                               
    Name.......................... Contents.1........2........3....+....4                                                                               
    %_ARCHIVE                                                                               
    4444444444444444444444444444444444444444            
                                   0000000000000000000000000000000000000000            
    ... +  40                                                                               
    4444444444444444444444444444444444444444            
                                   0000000000000000000000000000000000000000            
    ... +  80                                                                               
    4444444444444444444444444444444444444444            
                                   0000000000000000000000000000000000000000            
    ... + 120                                                                               
    44444444                                            
                                   0000000                                             
    -FIELDNAME        ETERN                                                                               
    CECDD4444444444444444444444444                       
                                  535950000000000000000000000000                       
    T_DATA                        00004082920002000000                  00             
                                  FFFFFFFFFFFFFFFFFFFF444444444444444444FF             
                                  0000408292000200000000000000000000000000             
    .. +  40                      000000   00000000#######        ########             
                                  FFFFFF444FFFFFFFF00000004444444400000000             
                                  000000000000000000000000000000000000000C             
    .. +  80                      #######              000000                          
                                  000000044444444444444FFFFFF4444444444444             
                                  000000C000000000000000000000000000000000             
    .. + 120                             00000000#                                     
                                  4444444F                                             
                                  0000000                                              
    S_DRAGDROP                                                    ####                 
                                  444444444444444444444444444444440000                 
                                  000000000000000000000000000000000000
                                   000000000000000000000000000000000000             
    SY-SUBRC                       4                                                                               
    0000                                             
                                   0004                                             
    SY-XPROG                       SAPCNVE                                          
                                   ECDCDEC444444444444444444444444444444444         
                                   2173555000000000000000000000000000000000         
    %_SPACE                                                                               
    0                                                                               
    0                                                
    SY-MSGID                       0K                                                                               
    FD444444444444444444                             
                                   02000000000000000000                             
    %_PRINT                            000                                          
                                   4444FFF444444444444444444444444444444444         
                                   0000000000000000000000000000000000000000         
    ... +  40                                                                               
    4444444444444444444444444444444444444444         
                                   0000000000000000000000000000000000000000         
    ... +  80                                0 ########                             
                                   4444444444F40000000044444444444444444444         
                                   0000000000000000000000000000000000000000         
    ... + 120                                                                               
    44444444                                         
                                   0000000                                          
    SY-MSGNO                       000                                              
                                   FFF                                              
                                   000
                                   000                                                   
    %_ITAB_MODIFY_LIST             ###########################ø##Èø########              
                                   0000000000000000000000000007007700000000              
                                   0000000000000000000000004000004000000000              
    ... +  40                      ###################################Ø#²#0              
                                   0001000100010000FFFF00000000020000083E0F              
                                   0009000900090000FFFF04000002900000000A50              
    ... +  80                      ########################################              
                                   0000000000000000000000000000000000000000              
                                   0000000000000000000000000000000000000000              
    ... + 120                      ################################                      
                                   00000000                                              
                                   0000000                                               
    SY-MSGV1                                                                               
    4444444444444444444444444444444444444444              
                                   0000000000000000000000000000000000000000              
    ... +  40                                                                               
    4444444444                                            
                                   0000000000                                            
    SY-MSGV2                                                                               
    4444444444444444444444444444444444444444              
                                   0000000000000000000000000000000000000000              
    ... +  40                                                                               
    4444444444                                            
                                   0000000000                                            
    SY-MSGV3                                                                               
    4444444444444444444444444444444444444444              
                                   0000000000000000000000000000000000000000
                                   0000000000000000000000000000000000000000          
    ... +  40                                                                               
    4444444444                                        
                                

    Hi Experts,
    I tried with  OUTPUT length, still Dump Persists, Any Ideas??
    <b>Source code extract on the dump is:</b>
    Thanks
    SP
                                                                                    008930         gs_roid-row_id = rs_row-index * -1.        
    008940       endif.                                                                               
    008950       gs_roid-sub_row_id = rs_row-rowtype+7(10).   
    008960       gs_poid-row_id = gs_roid-row_id.             
    008970       gs_poid-sub_row_id = gs_roid-sub_row_id.     
    008980       gs_poid-rowtype    = rs_row-rowtype.         
    008990       gs_poid-index      = rs_row-index.           
    009000       insert gs_poid into table rt_poid.           
    009010     endif.                                                                               
    009020     append gs_roid to rt_roid.                     
    009030                                                                               
    009040     loop at rt_fieldcat assigning <ls_fieldcat>
    where tech ne 'X' and                    
    009050                                                    
      no_out ne 'X'.                     
    009060                                                                               
    009070       if gflg_invisible = 'X'.                     
    009080         if <ls_fieldcat>-do_sum is initial.        
    009090           clear gflg_invisible.                    
    009100           continue.                                
    009110         else.                                                                               
    009120           clear g_col_counter.                     
    009130           clear gflg_invisible.                    
    009140         endif.                                                                               
    009150       endif.                                                                               
    009160                                                                               
    009170       clear gs_lvc_data.                           
    009180       clear g_style.                               
    009190                                                                               
    009200       assign component                             
    009200       assign component                             
    009210              <ls_fieldcat>-fieldname of structure
    rt_data to <g_field>.                        
    009220       if sy-subrc ne 0.                                                                               
    >         message x000(0k).                          
    009240       endif.                                                                               
    009250                                                                               
    009260       g_col_counter = g_col_counter + 1.           
    009270                                                                               
    009280       gs_lvc_data-row_pos = r_row_counter.         
    009290       gs_lvc_data-col_pos = g_col_counter.         
    009300       gs_lvc_data-row_id  = gs_roid-row_id.        
    009310       gs_lvc_data-sub_row_id = gs_roid-sub_row_id. 
    009320                                                                               
    009330   *   Endtotal and average                         
    009340       if rs_row-rowtype(1) ca 'T' and
    <ls_fieldcat>-do_sum = 'C'.                              
    009350   *     save the actual grouplevel information     
    009360         gs_grouplevels = rs_grouplevels.           
    009370         clear g_lines.                             
    009380                                                                               
    009390   *     get number of lines of the collect table   
    009400         describe table rt_data lines g_lines.      
    009410   *     if there is only one line or the field has
    no references so                            
    009420   *     that only the first line has to be
    considered

  • Running Sum without analytic function

    Hi
    I have data like below
    Create table Test (Name Varchar(30),M Int, Y Int, Val Int);
    Insert into Test Values ('A',1,2011,2);
    Insert into Test Values ('A',2,2011,2);
    Insert into Test Values ('A',3,2011,2);
    Insert into Test Values ('A',4,2011,2);
    Insert into Test Values ('A',5,2011,2);
    Insert into Test Values ('A',6,2011,2);
    Insert into Test Values ('A',7,2011,2);
    Insert into Test Values ('A',8,2011,2);
    Insert into Test Values ('A',9,2011,2);
    Insert into Test Values ('A',10,2011,2);
    Insert into Test Values ('A',11,2011,2);
    Insert into Test Values ('A',12,2011,2);
    Insert into Test Values ('A',1,2012,2);
    Insert into Test Values ('A',2,2012,2);
    Insert into Test Values ('A',3,2012,2);
    Insert into Test Values ('A',4,2012,2);
    Insert into Test Values ('A',5,2012,2);
    Insert into Test Values ('A',6,2012,2);
    Insert into Test Values ('A',7,2012,2);
    Now based on above data I need to calculate running sum for past 18 Months. Condition is I can not use analytic function or Oracle specific SQL functions (for portability).
    I tries following SQL but it dint work
    select Name,rnk, SUM(val) from (
    SELECT a.Name,a.m,a.Y,b.val, count(*) rnk
    from Test a, Test b
    where (a.Name=b.Name and (a.M <= b.M and a.Y<= b.Y))
    group by a.Name,a.Y,a.m
    order by a.Name,a.Y,a.m
    ) abc
    group By Name,rnk
    Order by Name,rnk
    Can some one give suggastion.

    Hi,
    I don't see what your query or your desired results have to do with the last 18 months. Is the task here to show for a given month (July, 2012, for example) the total of the 18 months ending in that month (February, 2011 through July, 2012 in this case) for the same name? If so:
    SELECT       c.name, c.y, c.m
    ,       SUM (p.val)     AS running_total
    FROM       test     c
    JOIN       test     p  ON     ( ((12 * c.y) + c.m)
                   - ((12 * p.y) + p.m)
                   ) BETWEEN 0 AND 17
    GROUP BY  c.name, c.y, c.m
    ORDER BY  c.name, c.y, c.m
    ;Output:
    NAME                Y          M RUNNING_TOTAL
    A                2011          1             2
    A                2011          2             4
    A                2011          3             6
    A                2011          4             8
    A                2011          5            10
    A                2011          6            12
    A                2011          7            14
    A                2011          8            16
    A                2011          9            18
    A                2011         10            20
    A                2011         11            22
    A                2011         12            24
    A                2012          1            26
    A                2012          2            28
    A                2012          3            30
    A                2012          4            32
    A                2012          5            34
    A                2012          6            36
    A                2012          7            36

  • Returning total sum plus pivoted sums in same result set

    I want to return a result set in the following format:
    YEARMONTH Total ModelA ModelB ModelC
    200101    0     0      0      0
    200102    10    5      5      0
    200103    8     2      2      4where the total is the sum of the hours for all model types grouped by yearmonth, and the individual model columns are the sum of hours per model type grouped by yearmonth. I can get the correct results using the following query with nested selects:
            select distinct yearmonth,
         sum(a.hours) as Total,
         (select sum(b.hours) from model_hours b
             where model = 'ModelA' and a.yearmonth = b.yearmonth) as ModelA,
            (select sum(b.hours) from model_hours b
             where model = 'ModelB' and a.yearmonth = b.yearmonth) as ModelB,
            (select sum(b.hours) from model_hours b
             where model = 'ModelC' and a.yearmonth = b.yearmonth) as ModelC
        from model_hours a
        group by yearmonth
        order by yearmonthI was curious to try using the pivot function in Oracle 11 to achieve the same results, and am able to get all the results EXCEPT the total hours using the following query:
        select * from (
             select yearmonth, hours, model
             from model_hours a
        pivot
             sum(hours)
             for model in ('ModelA', 'ModelB', 'ModelC')
        order by yearmonthwhich returns this result:
    YEARMONTH  ModelA ModelB ModelC
    200101     0      0      0
    200102     5      5      0
    200103     2      2      4I have not been able to figure out how to also get the sum of the hours for all models, grouped by yearmonth, into this resultset. Is it possible? And if so, would it be likely to be more efficient than the nested selects? This particular table has some 200K rows right now.

    Hi,
    923402 wrote:
    Frank, thank you so much. I added a bunch of nvl() functions and it works now. Didn't have a chance to try it with the other answer but it looks like it would be similar.
    I'm still curious as to whether doing it this way is more efficient than my original query, using nested selects.Definitely! Scalar sub-queries, like you did in your first message, will require multiple passes through the table. SELECT ... PIVOT only requires one.
    Here's another way that should be as efficient as SELECT ... PIVOT:
    SELECT       yearmonth
    ,       SUM (hours)                                   AS total
    ,       NVL (SUM (CASE WHEN model = 'ModelA' THEN hours END), 0)     AS modela
    ,       NVL (SUM (CASE WHEN model = 'ModelB' THEN hours END), 0)     AS modelb
    ,       NVL (SUM (CASE WHEN model = 'ModelC' THEN hours END), 0)     AS modelc
    FROM       model_hours
    GROUP BY  yearmonth
    ORDER BY  yearmonth
    ;The NVLs are only necessary for display; you don't need them to get the correct total.
    I don't have access to a SQL efficiency testing program; otherwise, I'd test it myself; if you don't think you can answer I'll just give it to our overworked DBA. Ask your DBA if you can use EXPLAIN PLAN.

  • SUM a COUNT function

    I need to perform a summation on the results of a COUNT but I'm not sure what's the best way to do it.
    Example:
    TableA
    CaseID (int)
    FollowupCorrespondence (int) incremented
    CustomerName (varchar)
    /**Get the total number of followups for each customer case, and display the customer's name.*/
    select sum(count(FollowupCorrespondence)), CustomerName from
    tableA
    group by caseID, CustomerName;
    This produces an error that the functions cannot be nested. How can I get the result that I'm looking for?

    This?
    SQL> with tablea as (
       select 1 caseid, 'John Doe' customername, 1 followupcorrespondence from dual union all
       select 1 caseid, 'John Doe', 2 from dual union all
       select 1 caseid, 'John Doe', 3 from dual union all
       select 1 caseid, 'John Doe', 4 from dual union all
       select 2 caseid, 'Jane Doe', 1 from dual union all
       select 2 caseid, 'Jane Doe', 2 from dual union all
       select 2 caseid, 'Jane Doe', 3 from dual)
    select caseid,
       count(*) over (partition by caseid) cnt_caseid,
       customername,
       followupcorrespondence
    from tablea
        CASEID CNT_CASEID CUSTOMER FOLLOWUPCORRESPONDENCE
             1          4 John Doe                      1
             1          4 John Doe                      2
             1          4 John Doe                      3
             1          4 John Doe                      4
             2          3 Jane Doe                      1
             2          3 Jane Doe                      2
             2          3 Jane Doe                      3

  • How to calculate the total sum value of a particular field that repeats

    Hi All,
    I have the following Req...File----Idoc Scenario
    In the Inbound xml file i will get the Sales Order details with suppose 10 line items( 10 Orders)
    Each line item represents one one SO. So totally i wil have 10 Sales Orders in this file.
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_Sales_Order xmlns:ns0="http://sap/Sales_Order">
       <Header>
          <COMP_CODE></COMP_CODE>
          <DOC_TYPE></DOC_TYPE>
           <SUPPL_VEND></SUPPL_VEND>
       </Header>
       <Item>
          <ITEM></ITEM>
          <MATERIAL></MATERIAL>
          <PLANT></PLANT>
          <QUANTITY></QUANTITY>
          <Amount></Amount> 
    </Item>
    In the above structure Item Segment will repeats as many no. of Sales Orders comes in a file.
    In a file if there are 10 Orders means the Item segment wil repeats 10 times.
    I have the Amount field in the Item Segment, each and every time that needs to be added to next Amount value that presents in the next Line Item.
    Finally i will have the Another separate field caled Grand Total, and i have to get the total summation of the 10 values of the Amount field at last.
    Can we achieve this using UDF or is there any way to do this
    REgards

    Hi,
    Do like this, actually in your case sum is taking place before the condition check for discount type
    do a little change in mapping
    DiscntType--removeContext--
                                              EqulsS-------IfWithoutElse----Amount---removecontext--then---SUM-
    Connstatnt(Value)
    --->GrandAmount
    Krishna, Check the same question asked by Rajesh in thread Calculate totals of segments that occur multiple times
    Thanks!

  • Help in Total sum query

    Hello, How I can sum(code1). Every code1 has a group and every group's total (total_per) should be 100. I want to add the comments column in the result as well. Thanks.
    create table #Cumulate (code numeric (10), code1 numeric (10), total_per numeric(10),code_desc char(20))
    insert into #Cumulate values (1,121,10,'DHJ')
    insert into #Cumulate values (2,121,90,'DHJ')
    insert into #Cumulate values (3,121,10,'DHJ')
    insert into #Cumulate values (4,122,10,'CRT')
    insert into #Cumulate values (5,122,80,'CRT')
    insert into #Cumulate values (6,122,05,'CRT')
    insert into #Cumulate values (7,122,10,'CRT')
    insert into #Cumulate values (8,123,10,'DRT')
    insert into #Cumulate values (9,123,60,'DRT')
    insert into #Cumulate values (10,123,10,'DRT')
    insert into #Cumulate values (11,123,10,'DRT')
    insert into #Cumulate values (12,123,10,'DRT')
    insert into #Cumulate values (13,124,20,'DRT')
    insert into #Cumulate values (14,124,60,'DRT')
    insert into #Cumulate values (15,124,10,'DRT')
    insert into #Cumulate values (16,124,10,'DRT')
    insert into #Cumulate values (17,124,10,'DRT')
    --Results
    Code1 total_per Commments
    121   100         Total is 100
    122   105         Total is not 100
    123   100         Total is 100
    124   110        Total is not 100

    Try the below:
    Select Code1, Sum(Total_per) total_per, 'Total is '+Case when Sum(Total_per)=100 then '' else ' not' end+'100' Comments
    From
    #Cumulate
    Group by Code1
    However, I would suggest you to do the comment session at presentation layer, which would be a good for performance.
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped.
     [Blog]

  • How to Total(Sum) of HH:MM (Varchar2) Format in the Table Region Style of OAF

    Hi All.
    I have Requirement to Calculate the Total Duration in OAF Table Style Region.
    Check In
    Check Out
    Total Hours (HH:MM)
    08:50:59
    15:29:56
    6:38
    07::02:18
    17:05:10
    10:02
    08:20:56
    16:28:33
    8:07
    Total
    24:47
    If i Could not Able to Sum of 6:38+10:02+8:07=24:47 Due to VArchar2 as Display.
    If i use Total (True) in Attribute it is through as sum 0.
    Please Help me to Calculate the Duration Sum in OAF Page.
    Regards
    Rama

    Your question is not clear..
    Provide CREATE tABLE and INSERT statements and expected output. Your DB version also.
    What is the data type of the column RUNTIME?
    And what does your calculation " avg((01:29:40+ 07:10:58)/14)" mean - what is the result of this?
    Please read FAQ: {message:id=9360002}

Maybe you are looking for

  • RE: Macbook Stuttering, Audio Distortion

    FYI As discussed in Macbook Stuttering, Audio Distortion, The solution to this problem is as follows: The fix is to blow out nearly four years of dust (in my case), using the instructions given here (for replacing a fan...) http://www.ifixit.com/Guid

  • Old CRT HD TV is overscanning

    I have a Toshiba 34HF81 16:9, Hi definition CRT TV.  Its highest resolution is 1080i. The TV still works very well, but has a problem when connected either to my cable box/PVR or  a Blu Ray player: It overscans.  I lose the outer 10% of the picture,

  • Working on check printing template,Getting Extra space in second page

    I am working on check printing template,in case of multi page output.I am getting almost 1/2 page blank space and getting disturbed output. Please provide mail id so that i will share template and xml. Thanks in advance. Mahi

  • PO print before last release

    Hi guru, i need help to allow PO print by ME9F tcode, before last release. there is an abap way for solve it? I try by customizing but it's not possible. eg i've got 4 release step and I want to print after the 3rd but before the 4th.

  • MAC installing Acrobat Pro X and Creative Suite 5.5 Design Premium pop up ?

    Hello, I have an Acrobat Pro X PKG (for MAC) from the Univeristy that should have a serial number inside the PKG. The installation works well. On the Acrobat Pro lauch I saw the main windows, for 2-3 secondes and then it goes a way.  A Creative Suite