Count total rows?

Hello,
In some function of my program, I need to count total number of rows but, I don't need to fetch results. Only the number of rows.
Is there any way to count the total number of result rows without fetch?
In OCI ver.7, it was very simple.
Just Call ofen() (OCIStmtFetch() in ver.8) without defining, but it's impossible that fetch without defining in Ver.8
Is there any idea to solve this situation?
I can defining and fetching just like normal process, but customer can send any SQL statement so, it can include LOBs.. and so on.
It's very waste source codes and memory for just counting rows.
Thank you

One possibility is to execute a different statement
(i.e. select count(*) from foo;) to get the number of
rows directly. This would probably be the most efficient
way to get the row count (since no row data is shipped
with this statement).
Unfortunately, I was unable to fetch rows w/o defining
in OCI either (I got an ORA-24374), so I am not sure how
you can get around this.
Incidentallly, when fetching LOBs, I don't think that
the entire lob is fetched, only the LOB locator. In this
case, there is very little over head associated with the
data transfer.
Also, I believe that ofen() was doing roundtrips in the
past, and my impression was that the latency of the
roundtrip to the server (and not the associated latency
of transferring the data) was the bottleneck here. Hence,
there may not be as much of a performance penalty as
expected for doing the extra client define with OCI
v8. So you still might be able to use your old ofen logic
(after replacing with OCIStmtExecute/OCIDefine) and not
see a very high performance hit.
Hope that helps out somewh

Similar Messages

  • Count total rows in database?

    Hello all,
    Is there a way to query the database for the total number of rows.... without using ANALYZE STATISTICS? (That would cause the db to sometimes use COST instead of RULE based optimization, slowing it down significantly.)
    I know I could could brute force a total row count with something like:
    spool get_total_rows.sql
    SELECT 'SELECT COUNT(*) FROM '||owner||'.'||table_name||';'
    FROM ALL_TABLES;
    spool off
    ...then run get_total_rows and manually add all the counts.
    But it just seems like there must be a cleaner way to do it.
    Thanks much,
    Natasha

    ok. here you have that information:
    ALL_TABLES
    ALL_TABLES describes all relational tables accessible to the current user. To gather statistics for this view, use the SQL ANALYZE statement.
    Related Views
    DBA_TABLES describes all relational tables in the database.
    USER_TABLES describes all relational tables owned by the current user. This view does not display the OWNER column.
    Note:
    Columns marked with an asterisk are populated only if you collect statistics on the table with the ANALYZE statement or the DBMS_STATS package.
    Column Datatype NULL Description
    OWNER
    VARCHAR2(30)
    Owner of the table
    TABLE_NAME
    VARCHAR2(30)
    Name of the table
    TABLESPACE_NAME
    VARCHAR2(30)
    Name of the tablespace containing the table; NULL for partitioned, temporary and index-organized tables
    CLUSTER_NAME
    VARCHAR2(30)
    Name of the cluster, if any, to which the table belongs
    IOT_NAME
    VARCHAR2(30)
    Name of the index-organized table, if any, to which the overflow entry belongs. If IOT_TYPE column is not null, this column contains the base table name.
    PCT_FREE
    NUMBER
    Minimum percentage of free space in a block; NULL for partitioned tables
    PCT_USED
    NUMBER
    Minimum percentage of used space in a block; NULL for partitioned tables
    INI_TRANS
    NUMBER
    Initial number of transactions; NULL for partitioned tables
    MAX_TRANS
    NUMBER
    Maximum number of transactions; NULL for partitioned tables
    INITIAL_EXTENT
    NUMBER
    Size of the initial extent in bytes; NULL for partitioned tables
    NEXT_EXTENT
    NUMBER
    Size of the secondary extension bytes; NULL for partitioned tables
    MIN_EXTENTS
    NUMBER
    Minimum number of extents allowed in the segment; NULL for partitioned tables
    MAX_EXTENTS
    NUMBER
    Maximum number of extents allowed in the segment; NULL for partitioned tables
    PCT_INCREASE
    NUMBER
    Percentage increase in extent size; NULL for partitioned tables
    FREELISTS
    NUMBER
    Number of process freelists allocated to this segment; NULL for partitioned tables
    FREELIST_GROUPS
    NUMBER
    Number of freelist groups allocated to this segment; NULL for partitioned tables
    LOGGING
    VARCHAR2(3)
    Logging attribute; NULL for partitioned tables
    BACKED_UP
    VARCHAR2(1)
    Has table been backed up since last change
    NUM_ROWS*
    NUMBER
    Number of rows in the table
    BLOCKS*
    NUMBER
    Number of used data blocks in the table
    EMPTY_BLOCKS*
    NUMBER
    Number of empty (never used) data blocks in the table
    AVG_SPACE*
    NUMBER
    Average amount of free space, in bytes, in a data block allocated to the table
    CHAIN_CNT*
    NUMBER
    Number of rows in the table that are chained from one data block to another, or which have migrated to a new block, requiring a link to preserve the old ROWID
    AVG_ROW_LEN*
    NUMBER
    Average length of a row in the table in bytes
    AVG_SPACE_FREELIST
    _BLOCKS
    NUMBER
    The average freespace of all blocks on a freelist
    NUM_FREELIST_BLOCKS
    NUMBER
    The number of blocks on the freelist
    DEGREE
    VARCHAR2(10)
    The number of threads per instance for scanning the table
    INSTANCES
    VARCHAR2(10)
    The number of instances across which the table is to be scanned
    CACHE
    VARCHAR2(5)
    Whether the cluster is to be cached in the buffer cache (CACHE | NOCACHE)
    TABLE_LOCK
    VARCHAR2(8)
    Whether table locking is enabled or disabled
    SAMPLE_SIZE
    NUMBER
    Sample size used in analyzing this table
    LAST_ANALYZED
    DATE
    Date on which this table was most recently analyzed
    PARTITIONED
    VARCHAR2(3)
    Indicates whether this table is partitioned. Set to YES if it is partitioned.
    IOT_TYPE
    VARCHAR2(12)
    If this is an index-organized table, then IOT_TYPE is IOT, IOT_OVERFLOW, or IOT_MAPPING. If this is not an index-organized table, then IOT_TYPE is NULL.
    TEMPORARY
    VARCHAR2(1)
    Can the current session only see data that it place in this object itself?
    SECONDARY
    VARCHAR2(1)
    Whether the trigger is a secondary object created by the ODCIIndexCreate method of the Oracle9i Data Cartridge (Y |N)
    NESTED
    VARCHAR2(3)
    Is the table a nested table?
    BUFFER_POOL
    VARCHAR2(7)
    The default buffer pool for the object. NULL for partitioned tables
    ROW_MOVEMENT
    VARCHAR2(8)
    Whether partitioned row movement is enabled or disabled
    GLOBAL_STATS
    VARCHAR2(3)
    For partitioned tables, indicates whether statistics were collected for the table as a whole (YES) or were estimated from statistics on underlying partitions and subpartitions (NO)
    USER_STATS
    VARCHAR2(3)
    Were the statistics entered directly by the user?
    DURATION
    VARCHAR2(15)
    Indicates the duration of a temporary table:
    SYS$SESSION: the rows are preserved for the duration of the session
    SYS$TRANSACTION: the rows are deleted after COMMIT
    Null for a permanent table
    SKIP_CORRUPT
    VARCHAR2(8)
    Whether Oracle ignores blocks marked corrupt during table and index scans (ENABLED) or raises an error (DISABLED). To enable this feature, run the DBMS_REPAIR.SKIP_CORRUPT_BLOCKS procedure.
    MONITORING
    VARCHAR2(3)
    Whether the table has the MONITORING attribute set
    Try with ALL_TABLES and post if the results were zero too
    Joel P�rez

  • Count total rows in vo.

    Dear All,
    I have a af:showDetailItem in which i have a af:table. I want to show the total number of records in the header of af:showDetailItem.
    example:
    Employees  (count=10)
    So any one have any idea of how to solve this problem.?
    Regards,
    Santosh.
    Component              Version
    ================================================
    ADF Business Components         11.1.1.59.23
    Java(TM) Platform         1.6.0_21
    Oracle IDE              11.1.1.4.37.59.23
    Versioning Support         11.1.1.4.37.59.23

    You can use estimatedRowCount on tree binding.
    Sample:
    <af:showDetailItem text="Employees (count = #{bindings.<Tree_Binding>.estimatedRowCount})" ...>
         <af:table value="#{bindings.<Tree_Binding>.collectionModel}" ...>
         </af:table>
    </af:showDetailItem>Sireesha

  • Count total number of rows present in the schema

    Count total number of rows present in the schema including table, sequence, view
    Desirable Output
    table          Sequence     Views
    1000          20          1000

    You mean You need to count the No of Tables, View and Sequence Present in the Schema ??
    Hi Some thing like this,
    SELECT a.view_cnt AS "View Count", b.tab_cnt AS "Table Count",
           c.seq_cnt AS "Sequence Count"
      FROM (SELECT COUNT (*) view_cnt
              FROM USER_VIEWS) a,
           (SELECT COUNT (*) tab_cnt
              FROM USER_TABLES) b,
           (SELECT COUNT (*) seq_cnt
              FROM USER_SEQUENCES) cWhich give you,
    View Count      Table Count      Sequence Count
           153              878                   32Thanks,
    Shankar
    Edited by: Shankar Viji on Aug 28, 2012 3:03 AM

  • Present a total count of rows

    I'd like to present a total count of rows in the bottom of a report.
    how would you recommand me to do it???
    the point is that it must be presented in each report so i thought to add some HTML code to "After Rows" section in the report template. but i need a variable (or some substitution string) which will contain the total count. but how do i define a substitution string?

    as i mentioned i need to present a total count in the buttom of each report in my application. therefore I think it's reasonable to add a code in the report template, which present some variable which count all rows in a report.
    #TOTAL_ROWS# doesn't work if i place it on the template html code, though it works fine if i place it in the report region definition:
    <br><b>Total Number of Results:</b> #TOTAL_ROWS#.</br>
    why can't i use #TOTAL_ROWS# as a template variable? and how can i do that?

  • The best way to do paging and get total rows count given a sql statement

    Hi,
    Just got a quick question.... what is the best way to do paging as well as the total rows count given by a sql statement.
    e.g. "select * from emp"
    1. I need to know the total row count for this statement.
    2. I also need to do a 10 rows per page....
    Is there a way to do it in a SINGLE statement for best performance?
    Thanks experts.

    Sounds more like a "formatting" problem...
    If Sql*plus is your reporting tool, check out the guide:
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a90842/toc.htm

  • Total row count - where from is that value?

    Hi,
    I need the value of total row count that is displayed at the button of portal report. I need this value to use in my java script.
    Is that value somewhere in database? Maybe any variable or hidden form element on the page?
    Where from does the portal know when to show only the previous button and when both next and previous? It must by calucated somehow.
    Thanks in advance.
    best regards
    Krzysztof Jungowski
    null

    Thanks. Just to make clear:
    Probelm:
    I need to display links to pages with part of results at the bottom of page - just like in discussion group: Pages: [1] [2] [3] ....
    Solution:
    I know that there is a hidden form on every report rendered by portal. In that form there are several elements like:
    pagenumer, minrow and maxrows. Updating these elements I can jump to every page with results.
    Total row count problem:
    The problem is that I don't know the number of pages. If I had a total row count value I would calculate the number of pages and create links only to existing pages.
    best regards
    Krzysztof Jungowski

  • 3.0.9.8.5 - Total Row Count in reports

    "Total Row Count" seems to be broken after applying patch 3.0.9.8.5.
    After applying the patch, we viewed an existing report which returned (let's say) 25 rows (and I've got max rows per page set to 5):
    The first page correctly says: "Total Row Count in Report- 25" and "Row(s) 1 - 5 "
    But then clicking the 'next' button, the following page incorrectly says: "Total Row Count in Report- 10" and "Row(s) 6 - 10 "
    So, the total row count is getting screwed up. Clicking "previous" in the example above, the total row count goes down to '5'.
    Another 3.0.9.8.5 patch problem appears to be 5 extra <br>'s within the report customize page top level of buttons and the criteria form. Looks ugly.

    Thanks for the reply.
    Is there nothing I can do to fix this problem before the next 3.0.9 patch comes out? We've have perhaps another few months to go before we make the move to portal release 2.
    This one issue with patch 3.0.9.8.5 is mostly definitely a show-stopper for us...we cannot live with customers seeing errors as basic as "total rows" returned in queries....we will have to roll back to our previous patch level 3.0.9.8.3. By doing this, we will continue to get bad customer feedback because of the awful performance introduced by that patch (Internet Explorer HTTP 1.0 vs 1.1 / keepalives / SSL issue). That's not to mention that we won't see the benefits of the content-area export/import bug fixes in this latest pathset.
    So, if there is ANYTHING we can do to fix this one problem, we (and our customers) would greatly appreciate hearing about it.
    thanks,
    -john

  • Answers: total row count

    Ist it possible to print the total row count on the first or each page?
    Regards,
    Stefan

    I am relatively new to Answers. How do use row level count function?

  • Add a row after Total row in ALV report

    Hi Experts,
    I have a report is displayed by  ALV format(not use function module to display it but use Class cl_gui_custom_container),I want to add a row after the total row. for example,
    Customer   amount1    amount2    amount3 
    10000         1,234        1,000         2,000
    10001         4,000        2,000         1,000
    10002         1,300        1,000         3,000
    11000         1,200        4,000         3,000
         Total:     7,734        8,000         9,000
    Ratio%        31.27       32.34          36.39
    the row of 'Total' is calculated by fieldcat-do_sum = 'X' But after the Total row we need a Ratio row to display the ratio. Yes we can calculate the total amout and ratio and then append it into the output itab, but we don't like this solution.We want to keep the total function in the ALV report.Any experts can poit me a direction. Thanks in advance.
    Joe

    Djoe,
    First you need to handle the user command,in order to capture the button action. For this you need to implment a class, i  am attaching sample codes here
    In top include write the following code
    CLASS lcl_event_handler DEFINITION .
      PUBLIC SECTION .
        METHODS:
         handle_toolbar  FOR EVENT toolbar                   " To add new functional buttons to the ALV toolbar
                         OF        cl_gui_alv_grid
                         IMPORTING e_object,
         handle_user_command FOR EVENT user_command          " To implement user commands
                            OF cl_gui_alv_grid
                            IMPORTING e_ucomm .
      PRIVATE SECTION.
    ENDCLASS.                                               " Lcl_event_handler DEFINITION
    Now   <b>Class implementation</b>
    CLASS lcl_event_handler IMPLEMENTATION .
      METHOD handle_toolbar.                                " Handle Toolbar
        PERFORM f9500_handle_toolbar USING e_object.
    ENDMETHOD .                                            " Handle_toolbar
      METHOD handle_user_command .                          " Handle User Command
        PERFORM f9600_handle_user_command USING e_ucomm .
      ENDMETHOD.
    ENDCLASS .                                              " lcl_event_handler IMPLEMENTATION
    FORM f9600_handle_user_command USING p_e_ucomm TYPE sy-ucomm.
      CONSTANTS:c_newl(4) TYPE c
                          VALUE 'NEWL',               " New line
                c_copy(4) TYPE c
                          VALUE 'COPY',               " Copy
                c_corr(4) TYPE c
                          VALUE 'CORR'.               " Correction
      CASE p_e_ucomm .
        WHEN c_newl.
    Create a new line
          PERFORM f9610_insert_new_line.
    ENDFORM.                                          " f9600_handle_user_command
    FORM f9610_insert_new_line .
    *Data Declarations
      DATA: lt_rows     TYPE lvc_t_row,                 " Itab for row property
            ls_rows     TYPE lvc_s_row,                 " Work area for row
            lv_cntid    TYPE i.                         " Counter
      DATA: gv_index TYPE sy-index.
      CLEAR gs_last.
      CALL METHOD gr_alvgrid->get_selected_rows
        IMPORTING
          et_index_rows = lt_rows.
      READ TABLE lt_rows INTO ls_rows INDEX 1.
      IF sy-subrc EQ 0.
        gv_index = ls_rows-index + 1.
      ELSE.
        gv_index = 1.
      ENDIF.
      DESCRIBE TABLE gt_last LINES lv_cntid.
      lv_cntid = lv_cntid + 1.
      gs_last-cntid = lv_cntid.
      INSERT gs_last INTO gt_last INDEX gv_index.
      LOOP AT gt_last INTO gs_last FROM gv_index TO gv_index.
    Make the new line editable
        PERFORM f9611_style.
      ENDLOOP.
      CALL METHOD gr_alvgrid->refresh_table_display
        EXCEPTIONS
          finished = 1
          OTHERS   = 2.
    ENDFORM.                    " f9610_insert_new_line
    You can ask questions doubts if any!
    regards
    Antony Thomas

  • Count of rows in ALv report

    Hi!
    I would like to get the count of rows in my ALV report . How to get the count of the rows ? Can anyone guide me in getting it dome please.
    Thanks

    Hi Gaddemmedi!
    I am attaching the report as you had asked for. I have added the things you asked me to do and now I am getting the count on the top of the page. The problem is that though it shows me the count of the lines from the LAV report on top but when I try to filter the records in the report that count first of all dosent change and remain the same as the initial number of record though after filtering records reduce and over that the count lines keep on increasing I mean the count is shown in repeated lines afet lines. Kindly help please.
    Thanks
    *& Report  ZSD_BILLING_HDR_TEXT_sum                                       *
    *&         billing doc. and associated header text report              *
    *&                            CHANGE LOG                               *
    *& jpoon 2007.08.03                  Change request: DEVK905095        *
    *& Move request: SD_1451_01          Requestor: Mona Fox               *
    *& FP14134 - original code.                                            *
    REPORT  zsd_billing_hdr_text_sum MESSAGE-ID zsd NO STANDARD PAGE HEADING.
    * For ALV usage
    TYPE-POOLS: slis.
    DATA: gs_layout   TYPE slis_layout_alv,
          tp_print    TYPE slis_print_alv,
          gt_sort     TYPE slis_t_sortinfo_alv,
          gt_events   TYPE slis_t_event,
          t_fieldcat  TYPE slis_t_fieldcat_alv WITH HEADER LINE,
          repid       TYPE syrepid,               " ABAP Program.
          gt_list_top_of_page TYPE slis_t_listheader,     " Top of page text.
          alv_variant   TYPE disvariant," Customize Disp. Variant
          w_event type slis_alv_event.
    DATA: w_field    TYPE slis_fieldcat_alv.
    TABLES: vbrk, vbrp, vbpa.
    DATA  SLIS_EV_AFTER_OUTPUT.
    data: gs_list_top_of_page type slis_listheader.
    *data: gt_list_top_of_page type slis_t_listheader.
    * Definition of selection screen                                       *
    *   By plant, storage location, sold-to customers, material and        *
    *   posting date of the sales orders                                   *
    SELECTION-SCREEN BEGIN OF BLOCK one WITH FRAME TITLE text-001.
    SELECT-OPTIONS: s_vbeln  FOR  vbrk-vbeln,      " billing doc.
                    s_kunnr  FOR  vbpa-kunnr,      " bill-to customer number.
                    s_werks  FOR  vbrp-werks,      " line item plant.
                    s_fkdat  FOR  vbrk-fkdat,      " billing date.
                    s_fkart  FOR  vbrk-fkart,      " billing type.
                    s_vkorg  FOR  vbrk-vkorg.      " sales org.
    PARAMETERS:     p_hold   AS CHECKBOX.
    SELECTION-SCREEN END OF BLOCK one.
    * ALV display layout
    SELECTION-SCREEN BEGIN OF BLOCK layout WITH FRAME TITLE text-003.
    PARAMETERS: pa_vari TYPE slis_vari DEFAULT ' '. " Display variant.
    SELECTION-SCREEN END OF BLOCK layout.
    * Data Definitions                                                     *
    * Storing Extracted Info.
    TYPES: BEGIN OF t_extract,
             vbeln        TYPE vbeln_vf,   " Sales order number.
             posnr        TYPE posnr,      " line item
             fkart        TYPE fkart,      " billing type.
             vtext        TYPE BEZEI20,    " billing type description.
             fkdat        TYPE fkdat,      " billing date.
             werks        TYPE werks_d,    " line item plant.
             werks_name1  TYPE name1,      " plant description.
             kunnr        TYPE kunnr,      " bill-to customer.
             kunnr_name1  TYPE name1_gp,   " bill-to description.
             netwr        TYPE netwr,      " net value,invoice total $
             zzflag       TYPE boolean,    " hold indicator
             zzreason     TYPE char30,     " header text2 (reason)
             zzuser       TYPE ernam,      " last changed by
             zz_changed_date TYPE dats,    " last changed date
             zz_changed_time TYPE tims,    " last changed time
            END OF t_extract.
    DATA: it_extract  TYPE TABLE OF t_extract WITH HEADER LINE,
          it_extract2 TYPE TABLE OF t_extract WITH HEADER LINE.
    DATA: it_text TYPE TABLE OF tline WITH HEADER LINE.
    DATA: wa_thead type thead.
    DATA: w_tdname type TDOBNAME.
    DATA: L_COUNT TYPE I.
    * initialization
    INITIALIZATION.
      gs_layout-colwidth_optimize = 'X'.
      tp_print-no_print_listinfos = 'X'.
      tp_print-no_coverpage = 'X'.
      PERFORM set_fieldcat.
      PERFORM alv_eventtab_build USING:
    **    Event name     Form to execute     Event internal table
       'TOP_OF_PAGE'  'TOP_OF_PAGE'       gt_events[].
    * Dropdown list for all created ALV layouts, global or user-specific
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_vari.
      PERFORM alv_variant_f4 CHANGING pa_vari.
    * Main BODY of processing logic
    START-OF-SELECTION.
      IF s_vbeln IS INITIAL
      AND s_kunnr IS INITIAL
      AND s_werks IS INITIAL
      AND s_fkdat IS INITIAL
      AND s_fkart IS INITIAL
      AND s_vkorg IS INITIAL.
         MESSAGE i000 WITH text-037 ' ' ' ' ' '.
      ELSE.
        PERFORM extract_data.
      ENDIF.
    END-OF-SELECTION.
      IF it_extract2[] IS INITIAL.
        MESSAGE i000 WITH text-002 ' ' ' ' ' '.
      ELSE.
    * Build headings for report.
    *    PERFORM build_top_of_page  USING gt_list_top_of_page[].
    * describe table it_extract2 lines l_count.
    *write :/ 'TOTAL NO OF ENTRIES', SY-VLINE, 32 L_COUNT.
          PERFORM call_alv.
    *write :/ 'TOTAL NO OF ENTRIES', SY-VLINE, 32 L_COUNT.
      ENDIF.
    *&      Form  EXTRACT_KEY_DATA
    * Retreive the data for the report.
    FORM extract_data.
      CLEAR: it_extract.  REFRESH: it_extract.
    * read and select billing documents
      IF p_hold IS INITIAL.
        SELECT vbrk~vbeln vbrk~fkart vbrk~fkdat vbrk~netwr
               vbrk~zzflag vbrk~zzreason vbrk~zzuser
               vbrk~zz_changed_date vbrk~zz_changed_time
               vbrp~posnr vbrp~werks
          INTO CORRESPONDING FIELDS OF TABLE it_extract
          FROM vbrk INNER JOIN vbrp ON
               vbrk~vbeln = vbrp~vbeln
         WHERE vbrk~vbeln IN s_vbeln
           AND vbrk~fkart IN s_fkart
           AND vbrk~fkdat IN s_fkdat
           AND vbrk~vkorg IN s_vkorg
           AND vbrk~fksto NE 'X'
           AND vbrp~werks IN s_werks.
      ELSE.
    * read 'held' documents only as per selection
        SELECT vbrk~vbeln vbrk~fkart vbrk~fkdat vbrk~netwr
               vbrk~zzflag vbrk~zzreason vbrk~zzuser
               vbrk~zz_changed_date vbrk~zz_changed_time
               vbrp~posnr vbrp~werks
          INTO CORRESPONDING FIELDS OF TABLE it_extract
          FROM vbrk INNER JOIN vbrp ON
               vbrk~vbeln = vbrp~vbeln
         WHERE vbrk~vbeln IN s_vbeln
           AND vbrk~fkart IN s_fkart
           AND vbrk~fkdat IN s_fkdat
           AND vbrk~vkorg IN s_vkorg
           AND vbrk~fksto NE 'X'
           AND vbrk~zzflag = 'X'
           AND vbrp~werks IN s_werks.
      ENDIF.
      IF sy-subrc <> 0.
        MESSAGE i000 WITH text-002 ' ' ' ' ' '.
      ENDIF.
      CHECK sy-subrc = 0.
    * only need first line item for this report.
      SORT it_extract BY vbeln posnr.
      DELETE ADJACENT DUPLICATES FROM it_extract COMPARING vbeln.
      LOOP AT it_extract.
    * Retrieve and select by sales order bill-to on header level
    * as well as lookup bill-to customer name/description
        SELECT SINGLE kunnr FROM vbpa INTO it_extract-kunnr
         WHERE vbeln = it_extract-vbeln
           AND posnr = '000000'
           AND parvw = 'RE'.
        IF it_extract-kunnr IN s_kunnr.
          it_extract-kunnr_name1 = zcl_kna1=>get_name1( it_extract-kunnr ).
        ELSE.
          DELETE it_extract.
          CONTINUE.
        ENDIF.
    * lookup billing type description
        SELECT SINGLE vtext FROM tvfkt
          INTO it_extract-vtext
         WHERE spras = sy-langu
           AND fkart = it_extract-fkart.
        IF sy-subrc <> 0.
          clear it_extract-vtext.
        ENDIF.
    * lookup plant description
        SELECT SINGLE name1 FROM t001w
          INTO it_extract-werks_name1
         WHERE werks = it_extract-werks.
        IF sy-subrc <> 0.
          clear it_extract-werks_name1.
        ENDIF.
        MOVE-CORRESPONDING it_extract TO it_extract2.
        APPEND it_extract2.
       ENDLOOP.
    describe table it_extract2 lines l_count.
    ENDFORM.                    " EXTRACT_DATA
    *&      Form  SET_FIELDCAT
    * Create the field catalogue.
    FORM set_fieldcat .
    *CLEAR W_EVENT.
    *W_EVENT-FORM = SLIS_EV_AFTER_OUTPUT.
    *W_EVENT-NAME = SLIS_EV_AFTER_LINE_OUTPUT.
    *APPEND W_EVENT TO GT_EVENTS.
      CLEAR w_field.
      CLEAR t_fieldcat.  REFRESH t_fieldcat.
      w_field-col_pos = 1.
      w_field-fieldname = 'ZZFLAG'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Hold Printing'(005).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 2.
      w_field-fieldname = 'ZZREASON'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Reason'(036).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 3 .
      w_field-fieldname = 'VBELN'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Billing Doc'(028).
      w_field-emphasize = 'X'.
      w_field-hotspot   = 'X'.
      APPEND w_field TO t_fieldcat.
      CLEAR w_field.
      w_field-col_pos = 4 .
      w_field-fieldname = 'VTEXT'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Type Description'(030).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 5 .
      w_field-fieldname = 'FKDAT'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Billing Date'(031).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 6 .
      w_field-fieldname = 'WERKS'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Plant'(012).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 7 .
      w_field-fieldname = 'WERKS_NAME1'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Plant Description'(032).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 8.
      w_field-fieldname = 'KUNNR'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Bill-to Customer'(033).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 9 .
      w_field-fieldname = 'KUNNR_NAME1'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Bill-to Description'(034).
      w_field-emphasize = 'X'.
      w_field-hotspot   = 'X'.
      APPEND w_field TO t_fieldcat.
      CLEAR w_field.
      w_field-col_pos = 10 .
      w_field-fieldname = 'NETWR'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Invoice Amount'(035).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 11 .
      w_field-fieldname = 'ZZUSER'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Changed By'.
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 12 .
      w_field-fieldname = 'ZZ_CHANGED_DATE'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Last Changed Date'(006).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 13 .
      w_field-fieldname = 'ZZ_CHANGED_TIME'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Last Changed Time'(007).
      APPEND w_field TO t_fieldcat.
    *  W_event-NAME = slis_ev_end_of_list.
    *  W_event-FORM = 'END_OF_LIST'.
    *  APPEND W_event  TO GT_EVENTS.
    *  CLEAR W_event .
    *  w_field-col_pos = 14 .
    *  w_field-fieldname = 'COUNT'.
    *  w_field-tabname = 'IT_EXTRACT2'.
    *  w_field-seltext_l = 'COUNT'.
    *  APPEND w_field TO t_fieldcat.
    ENDFORM.                    " SET_FIELDCAT
    *&      Form  CALL_ALV
    * Call the ALV Grid function.
    FORM call_alv .
      SORT it_extract BY vbeln.
    * repid is necessary since the ALV F.M. does not work properly with
    * sy-repid.
      repid = sy-repid.
      alv_variant-variant  = pa_vari.
      alv_variant-report   = sy-repid.
      alv_variant-username = sy-uname.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program      = repid
          i_callback_user_command = 'USER_COMMAND'
          is_layout               = gs_layout
          it_fieldcat             = t_fieldcat[]
          it_sort                 = gt_sort[]
          i_default               = 'X'
          i_save                  = 'A'
          is_variant              = alv_variant
          it_events               = gt_events[]
          is_print                = tp_print
        TABLES
          t_outtab                = it_extract2
        EXCEPTIONS
          program_error           = 1
          OTHERS                  = 2.
    write :/ 'TOTAL NO OF ENTRIES', SY-VLINE, 32 L_COUNT.
      IF sy-subrc NE 0.
        MESSAGE w000 WITH text-004 ' ' ' ' ' '.
      ENDIF.
    ENDFORM.                    " CALL_ALV
    *&      Form  alv_eventtab_build
    *     Pass list of events to be triggered by the ALV function module
    FORM alv_eventtab_build USING  u_name  TYPE slis_alv_event-name
                                   u_form  TYPE slis_alv_event-form
                                   alv_lt_events  TYPE slis_t_event.
      DATA: ls_event TYPE slis_alv_event.   " structure for event handling
      ls_event-name = u_name.
      ls_event-form = u_form.
      APPEND ls_event TO alv_lt_events.
    ENDFORM.                    " alv_eventtab_build
    *       FORM TOP_OF_PAGE                                              *
    FORM top_of_page.
    *gs_list_top_of_page-type = 'H'.
    GS_LIST_TOP_OF_PAGE-INFO = L_COUNT.
    APPEND GS_LIST_TOP_OF_PAGE TO GT_LIST_TOP_OF_PAGE.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          i_logo             = 'NEWALTA_LOGO'
          it_list_commentary = gt_list_top_of_page.
    ENDFORM.                    " TOP_OF_PAGE
    *&      Form  user_command
    * Process the user command.
    *      -->R_UCOMM      User command
    *      -->RS_SELFIELD  Field selected
    FORM user_command USING r_ucomm     LIKE sy-ucomm
                            rs_selfield TYPE slis_selfield.
      DATA: ltp_vbeln TYPE vbeln.  " Sales document number.
      CASE  r_ucomm.
        WHEN '&IC1'.
          IF ( rs_selfield-fieldname = 'VBELN'
            OR rs_selfield-fieldname = 'BILL_VBELN' )
           AND rs_selfield-value IS NOT INITIAL.        " Display sales document.
            ltp_vbeln = rs_selfield-value.
            zcl_sales_doc=>display( ltp_vbeln ).
          ENDIF.
      ENDCASE.
    ENDFORM.                    "user_command
    *&      Form  alv_v-ariant_f4
    * Get the display variant.
    *      <--CTP_VARI  Variant name
    FORM alv_variant_f4 CHANGING ctp_vari TYPE slis_vari.
      alv_variant-report   = sy-repid.             " Report ID
      alv_variant-username = sy-uname.             " User ID
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
        EXPORTING
          is_variant = alv_variant
          i_save     = 'A'
        IMPORTING
          es_variant = alv_variant
        EXCEPTIONS
          OTHERS     = 1.
      IF sy-subrc = 0.
        ctp_vari = alv_variant-variant.
      ENDIF.
    ENDFORM.                    " alv_variant_f4

  • Count MySQL rows based off Value in Dynamic Table

    Greetings all. I have 2 MySQL tables; 1 that contains the names of my classes.(Class A, Class, B, etc.) and 1 table that contains the names of students in each Class (for example Class A: John Doe; Class A: Susie Smith.; Class B: Jane Doe). In the 2nd table the Class name is in its own column and the student's name is in a 2nd column.
    I currently have a dynamic repeating table that lists the names of all of the classes from the 1st table. What I'm trying to do is add a second column to this repeating dynamic table that lists the number of students in each class. For example; Row 1 of the dynamic table would say "Class A | 5; Class B | 3; Class C | 7, etc.). The dynamic table works perfectly to list the class names. For the life of me I can't figure out how to perform a count for each class to insert in the repeating table. I will be adding more Classes which as why I'm trying to set up the counting query dynamically. So far I have only been able to figure out how to count the total rows in the 2nd table, or count the rows with a specified class name. Any advice or guidance on how to count the number of rows in the 2nd MySQL table based off the class name in the repeating table is much appreciated. Thank you for any and all help. Have a great day.

    Select count(*), Class from MyTable
    Group by Class
    Time to learn about SQL:
    http://www.w3schools.com/sql/sql_intro.asp

  • Paging and count of rows

    Hi,
    I have a procedure doing paging and returning the count of rows:
    As you see I used 2 select, one for paging and one for getting total row counts.
    Is there a way to get rid of "SELECT count(*) into PO_TOTAL FROM TABLE1;"?
    CREATE OR REPLACE PACKAGE BODY MYPACKAGE AS
    TYPE T_CURSOR IS REF CURSOR;
    PROCEDURE SP_PAGING
    PI_STARTID IN NUMBER,
    PI_ENDID IN NUMBER,
    PO_TOTAL OUT NUMBER,
    CUR_OUT OUT T_CURSOR
    IS
    BEGIN
    OPEN CUR_OUT FOR
    SELECT *
    FROM (SELECT row_.*, ROWNUM rownum_
    FROM (
    SELECT column1, column2, column3 FROM TABLE1
    ) row_
    WHERE ROWNUM <= PI_ENDID)
    WHERE rownum_ >= PI_STARTID;
    SELECT count(*) into PO_TOTAL FROM TABLE1;
    END SP_PAGING;
    END MYPACKAGE;

    Yes, I can reproduce that:
    SQL> create table emp1 as select * from emp
      2  /
    Table created.
    SQL> exec dbms_stats.gather_table_stats('SCOTT','EMP1');
    PL/SQL procedure successfully completed.
    SQL> EXPLAIN PLAN FOR
      2  SELECT  ename,
      3          job,
      4          sal,
      5          cnt
      6    FROM  (
      7           SELECT  ename,
      8                   job,
      9                   sal,
    10                   count(*) over() cnt,
    11                   row_number() over(order by 1) rn
    12             FROM  emp1
    13          )
    14    WHERE rn BETWEEN 4 AND 9;
    Explained.
    SQL> @?\rdbms\admin\utlxpls
    PLAN_TABLE_OUTPUT
    Plan hash value: 1444408506
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |      |    14 |   728 |     4  (25)| 00:00:01 |
    |*  1 |  VIEW               |      |    14 |   728 |     4  (25)| 00:00:01 |
    |   2 |   WINDOW BUFFER     |      |    14 |   252 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP1 |    14 |   252 |     3   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       1 - filter("RN">=4 AND "RN"<=9)
    15 rows selected.
    SQL> EXPLAIN PLAN FOR
      2  SELECT *
      3  FROM (SELECT row_.*, ROWNUM rownum_
      4  FROM (
      5  SELECT ename,job,sal, count(*) over() FROM emp1
      6  ) row_
      7  WHERE ROWNUM <= 9)
      8  WHERE rownum_ >= 4;
    Explained.
    SQL> @?\rdbms\admin\utlxpls
    PLAN_TABLE_OUTPUT
    Plan hash value: 519025698
    | Id  | Operation             | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |      |     9 |   468 |     2   (0)| 00:00:01 |
    |*  1 |  VIEW                 |      |     9 |   468 |     2   (0)| 00:00:01 |
    |*  2 |   COUNT STOPKEY       |      |       |       |            |          |
    |   3 |    VIEW               |      |     9 |   351 |     2   (0)| 00:00:01 |
    |   4 |     WINDOW BUFFER     |      |     9 |   162 |     2   (0)| 00:00:01 |
    |   5 |      TABLE ACCESS FULL| EMP1 |     9 |   162 |     2   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       1 - filter("ROWNUM_">=4)
       2 - filter(ROWNUM<=9)
    18 rows selected.
    SQL> However, you interpreted it incorrectly. Your query will still fetch all rows in TABLE1. Optimizer is smart enough to stop creating window buffer after 9 rows and that is what you see 9 in explain plan, while my query builds 14 row window buffer and then filters. So your query will be a bit faster.
    SY.
    Edited by: Solomon Yakobson on Jan 25, 2009 2:51 PM

  • Getting the count of rows present in the oracle table

    Hi all,
    i want to get the total number of rows present in the sql table to the appmodule.
    After applying the some view criteria to the view object. if it try with getallrowsinrange it was giving count of rows present in the viewobject but i want total number of rows present in the sql table.
    How can i get that
    I am using jdev 11.1.1.5
    Thanks in advance

    I threw something together, quick and dirty, feel free to optimize.
    Assuming that you want the table count, I put the code into a EntityDefImpl subclass since this is what represents a table in the middle-tier.
    public class EmpDefImpl
          extends EntityDefImpl {
       * This is the default constructor (do not remove).
      public EmpDefImpl( ) {}
      //~ Methods ****************************************************************************
      public long getTableRowCount( DBTransaction transaction ) {
        String query = getQuery( );
        String countQuery = String.format( "SELECT COUNT(*) FROM (%s)", query );
        long count = 0;
        ViewObject vo = transaction.createViewObjectFromQueryStmt( countQuery );
        try {
          vo.executeQuery( );
          Row row = vo.first( );
          Number number = (Number)row.getAttribute( 0 );
          count = number.longValue( );
        } finally {
          vo.remove( );
        return count;
    }Depending on your type map, you might not get a oracle.jbo.domain.Number, but something else, so the cast might need correction.
    Usage example:
    public class EmpEditViewImpl extends ViewObjectImpl {
      public EmpEditViewImpl() {
      protected void executeQueryForCollection( Object object, Object[] object2, int i ) {
        super.executeQueryForCollection( object, object2, i );
        EmpDefImpl def = ( EmpDefImpl )getEntityDef( 0 );
        long tableRowCount = def.getTableRowCount( getDBTransaction() ) );
        // Do something with it
    }As you can see, the code is pretty generic. You might also be able to put this into an ADF extension base class.
    Sascha
    Edited by: Sascha Herrmann on Jun 7, 2012 2:39 PM

  • How to get last Record ior Total rows in For Loop Cursor ?

    Hi Friends
    I would like to know , the last record in for loop cursor, i have the code in following format
    cursor c1 is
    select * from emp;
    begin
    for r1 in c1 loop
    v_total_rec := ? ( i would like to know total rows in the cursor , say for example if cursor has 10 rows, i want10 into this variable )
    v_count := v_count +1;
    dbms_output.put_line(r1.emp_name);
    end loop;
    end;
    Hope i am clear
    Any suggestions?
    Thanks
    Ravi

    Even though cursor loops are generally a Bad Idea ^tm^ as Dan says, here's an example of how you can get the information you wanted within the query itself...
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    cursor c1 is
      3      select emp.*
      4            ,count(*) over (order by empno) as cnt
      5            ,count(*) over () as total_cnt
      6      from emp
      7      order by empno;
      8  begin
      9    for r1 in c1 loop
    10      dbms_output.put_line(r1.ename||' - row: '||r1.cnt||' of '||r1.total_cnt);
    11    end loop;
    12* end;
    SQL> /
    SMITH - row: 1 of 14
    ALLEN - row: 2 of 14
    WARD - row: 3 of 14
    JONES - row: 4 of 14
    MARTIN - row: 5 of 14
    BLAKE - row: 6 of 14
    CLARK - row: 7 of 14
    SCOTT - row: 8 of 14
    KING - row: 9 of 14
    TURNER - row: 10 of 14
    ADAMS - row: 11 of 14
    JAMES - row: 12 of 14
    FORD - row: 13 of 14
    MILLER - row: 14 of 14
    PL/SQL procedure successfully completed.
    SQL>

Maybe you are looking for

  • IMac on Mountain Lion restarting "because of a problem" every 5 minutes for the last 4 days.

    My iMac has been restarting "because of a problem" every 5 minutes for the last 4 days. This started only since I updated Mountain Lion OS last Thursday (i didnt update TO mountain lion, i already had it and updated to a version that came up in the m

  • How do I get the spinning wheel to stop?

    I updated to Mavericks several weeks ago and haven't had a bit of trouble. Yesterday, I tried doing a screen grab of a pic and it started spinning and wouldn't stop even after I shut it down. When it restarted, the ball is still there and spinning.

  • Document printing - differrent layout

    Hi, We have developed in PLD an Invoice and a Quotation. 1. Invoice - in PLD Document Properties, the Format is A5. 2. Quotation - in PLD Document Properties, the Format is A4. In SAP screen, File--> Page Set up, the page is A4. When we print the Inv

  • Calling a URL using JavaScript even handler

    When I'm trying to call another URL using JavaScript, it doesn't work. I did following things, 1).Created a Button 2).In javascript event handler, I'm calling Javascript function doSearch() 3). I wrote this function in Header Text Section of the Form

  • Error deploying application

    My application works fine in a 10.1.3.0 OC4J container: I can simply restart that container and my .ear file will unpack and 'just work'. Now i am trying to deploy the same application to a clean install of 10.1.3.1.0 OC4J container using admin.jar.