Number of records in a database table
Hi,
Is there a way to find the no of records for database tables ? I have over 1000 tables and need to find the tables without any records. I have found an FM for this requirment but it isnt of much use as i dont have developer access to the system.
Thanks & Regards,
Esha Raj
Hi esha,
This is one way. Just copy paste to get a feel.
On the screen, in select-options, enter a few tables, and it will output the table name and the record count.
report abc.
data : mycount type i.
tables : DD02L.
select-options : tabname for dd02l-tabname no intervals.
loop at tabname.
select count(*)
into mycount
from (tabname-low).
write :/ tabname-low , mycount.
endloop.
regards,
amit m.
Similar Messages
-
Count Number of Records in Oracle Database Table
Please help me to see if I "set" and "return" the number of records in my database table correctly (I am using the Oracle 9i):
public int getNumberOfRecipientBeans() throws AssertionException, DatabaseException
Connection conn = null;
PreparedStatement stmt = null;
String query = "SELECT count(*) FROM ContactEntry WHERE ContactTypeID = 6";
ResultSet rs = null;
try
conn = DBConnection.getDBConnection();
stmt = conn.prepareStatement( query );
rs = stmt.executeQuery();
// do I have to set anything here?
if ( !rs.next() )
throw new AssertionException("Assertion in servuce.getNumberOfRecipients");
// Am I returning the counts here?
return rs.getInt( 1 );
catch( SQLException sqle )
sqle.printStackTrace();
throw new DatabaseException( "Error executing SQL in service.getNumberOfRecipients." );
finally
if ( conn != null )
try
stmt.close();
stmt = null;
conn.close();
catch( Exception Ex )
System.out.println( "Problem occurs while closing " + Ex );
conn = null;public class MyE extends Exception {
public MyE() {
super(); // this line is not necessary. An empty method would suffice
public MyE(String msg) {
super(msg);
// Check the API for Exception or Throwable--I may have the args backward
public MyE(String msg, Throwable cause) {
super(msg, cause);
public MyE(Throwable cause) {
super(cause);
// Replace the log_warn() calls with appropriate logging calls for your context
public class Closer {
public static final void close(ResultSet closeMe) {
if (closeMe != null) {
try {
closeMe.close();
catch (Throwable th) { log_.warn("Closing " + closeMe + ": ", th); }
public static final void close(Statement closeMe) {
if (closeMe != null) {
try {
closeMe.close();
catch (Throwable th) { log_.warn("Closing " + closeMe + ": ", th); }
public static final void close(Connection closeMe) {
if (closeMe != null) {
try {
closeMe.close();
catch (Throwable th) { log_.warn("Closing " + closeMe + ": ", th); }
public static final void close(ResultSet rs, Statement stmt, Connection con) {
close(rs);
close(stmt);
close(con);
} -
How to count and display the number of records in a database table
My webpage has a list of items and their details, every item has a button
Read / Make comments that loads the item in its own page displaying
a comments form and previous comments.
This is all working fine.
I would like to add to each item information stating how many comments have
been made about that item.
Allowing the user to see before hand if it is worth while clicking on the
Read / Make comments button.
Ideally each item will have a different number of comments.
The problem I have is outputing the number of comments associated with each item.
My comments table is called guest my items table is called titles.
I'm sure mysql statement is correct -
The table guest currently has 7 comments,
Item 1 has 3 comments
Item 2 has 2 comments
Item 3 has 1 comment
Item 4 has 1 comment
When I test the query in dreamweaver
$Recordset1 = "SELECT COUNT(guest.software_id) as COUNT, titles.id FROM titles LEFT JOIN guest ON titles.id = guest.software_id GROUP BY guest.software_id";
the outoput is a list showing 2, 3, 1, 1
My problem is, getting the totals into my repeat region.
I tried the following line
<td align="left" valign="top" bgcolor="#e5f8cb">Current comments:<?php echo $row_Recordset1['COUNT']; ?></td>
resulting in all comments so far displaying 0
I have highlighted in bold the parts that I am having difficulty with.
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
return $theValue;
$colname_rsTitles = "-1";
if (isset($_GET['id'])) {
$colname_rsTitles = $_GET['id'];
mysql_select_db($database_abe, $abe);
$query_rsTitles = sprintf("SELECT title, company, `description`, resources, location, url, image, keyword, copies FROM titles WHERE id = %s ORDER BY id ASC", GetSQLValueString($colname_rsTitles, "int"));
$rsTitles = mysql_query($query_rsTitles, $abe) or die(mysql_error());
$row_rsTitles = mysql_fetch_assoc($rsTitles);
$totalRows_rsTitles = "-1";
if (isset($_GET['id'])) {
$totalRows_rsTitles = $_GET['id'];
$colname_rsTitles = "-1";
mysql_select_db($database_abe, $abe);
$query_rsTitles = sprintf("SELECT title, company, `description`, resources, location, url, image, keyword, copies FROM titles WHERE id = %s ORDER BY id ASC", GetSQLValueString($colname_rsTitles, "int"));
$rsTitles = mysql_query($query_rsTitles, $abe) or die(mysql_error());
$row_rsTitles = mysql_fetch_assoc($rsTitles);
$totalRows_rsTitles = mysql_num_rows($rsTitles);
mysql_select_db($database_abe, $abe);
$query_rs_comments = "SELECT * FROM guest";
$rs_comments = mysql_query($query_rs_comments, $abe) or die(mysql_error());
$row_rs_comments = mysql_fetch_assoc($rs_comments);
$totalRows_rs_comments = mysql_num_rows($rs_comments);
mysql_select_db($database_abe, $abe);
$query_rs_users = "SELECT * FROM users";
$rs_users = mysql_query($query_rs_users, $abe) or die(mysql_error());
$row_rs_users = mysql_fetch_assoc($rs_users);
$totalRows_rs_users = mysql_num_rows($rs_users);
mysql_select_db($database_abe, $abe);
$query_Recordset1 = "SELECT COUNT(guest.software_id) as COUNT, titles.id FROM titles LEFT JOIN guest ON titles.id = guest.software_id GROUP BY guest.software_id";
$Recordset1 = mysql_query($query_Recordset1, $abe) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_select_db($database_abe, $abe);
if(!isset($_POST['softwareLevel'])){
if (!isset($_GET['class_id'])) {
//show all software titles
$query_rsTitles = "SELECT id, title, company, `description`, resources, location, url, image, keyword, copies FROM titles ORDER BY id ASC";
}else{
//show software titles filtered by Literacy of Numeracy (using URL GET variable)
$query_rsTitles = "SELECT id, title, company, `description`, resources, location, url, image, keyword, copies FROM titles WHERE titles.class_id = ". GetSQLValueString($_GET['class_id'], "int") ." ORDER BY id ASC";
}else{
//show software titles filtered by Level (using Form POST variable)
$query_rsTitles = "SELECT id, title, company, `description`, resources, location, url, image, keyword, copies FROM titles WHERE titles.level_id = ". GetSQLValueString($_POST['softwareLevel'], "int") ." ORDER BY id ASC";
$rsTitles = mysql_query($query_rsTitles, $abe) or die(mysql_error());
$row_rsTitles = mysql_fetch_assoc($rsTitles);
$totalRows_rsTitles = mysql_num_rows($rsTitles);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php $pagetitle="ABE Software Locator"?>
<html xmlns="http://www.w3.org/1999/xhtml" >
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $pagetitle ?></title>
<link rel="stylesheet" href="../../includes/styles.css" type="text/css" media="screen" />
<style type="text/css">
body {
background-color: #FFF;
</style>
</head>
<body>
<?php include("../../includes/header.php"); ?>
<div><table width="70%" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td width="29%" height="50" align="center"><a href="software_detail.php">Back to Locator</a></td>
<td width="50%" align="center"><a href="../../index.php">Welcome Page</a></td>
<td width="21%" align="center"><a href="../../logout.php">Log Out</a></td>
</tr>
<tr>
<td colspan="3" align="center"><strong> There Are <span class="totalrecordsnumber"><?php echo $totalRows_rsTitles ?></span> Software Titles Listed</strong></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<?php do { ?>
<table width="820" border="0" align="center" cellpadding="3" cellspacing="2">
<tr>
<td width="206" height="200" rowspan="3" align="center" bgcolor="#FFFFFF"><img src="images/<?php echo $row_rsTitles['image']; ?>" alt="<?php echo $row_rsTitles['title']; ?>" /></td>
<td colspan="3" align="center" bgcolor="#086b50"><h2><?php echo $row_rsTitles['title']; ?></h2></td>
</tr>
<tr>
<td colspan="3" align="center" bgcolor="#f6b824"><strong>Made by:</strong> <?php echo $row_rsTitles['company']; ?></td>
</tr>
<tr>
<td colspan="3" align="left" valign="top" bgcolor="#e5f8cb"><p class="ptaglineheight"><strong>Description: </strong><?php echo $row_rsTitles['description']; ?></p></td>
</tr>
<tr>
<td colspan="2" align="left" valign="top" bgcolor="#e5f8cb"><span class="tabletext"><strong>Keywords</strong></span><strong>: </strong><?php echo $row_rsTitles['keyword']; ?></td>
<td colspan="2" align="left" valign="top" bgcolor="#e5f8cb"><strong>Resources:</strong> <?php echo $row_rsTitles['resources']; ?></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" bgcolor="#e5f8cb"><strong>Web Address:</strong> <a href="<?php echo $row_rsTitles['url']; ?>" target="_blank"><?php echo $row_rsTitles['url']; ?></a></td>
</tr>
<tr>
<td colspan="3" align="left" valign="top" bgcolor="#e5f8cb"><strong>Is installed on:</strong> <?php echo $row_rsTitles['location']; ?></td>
<td width="195" align="left" valign="top" bgcolor="#e5f8cb"><strong>Copies available:</strong><?php echo $row_rsTitles['copies']; ?></td>
</tr>
<tr>
<td colspan="3" align="left" valign="top" bgcolor="#e5f8cb"><a href="fulltitle.php?software_id=<?php echo $row_rsTitles['id']; ?>&id=<?php echo $row_rsTitles['id']; ?>">Read / Make Comments About This Software</a></td>
<td align="left" valign="top" bgcolor="#e5f8cb">Current comments:<?php echo $row_Recordset1['COUNT']; ?></td>
</tr>
</table>
<br />
<?php } while ($row_rsTitles = mysql_fetch_assoc($rsTitles)); ?>
</div>
<?php include("../../includes/footer.php"); ?>
</body>
</html>
<?php
mysql_free_result($rsTitles);
mysql_free_result($rs_comments);
mysql_free_result($rs_users);
mysql_free_result($Recordset1);I changed the mysql as you suggested GROUP BY titles.id
and added a while loop to iterate over the data
mysql_select_db($database_abe, $abe);
$query_Recordset1 = "SELECT COUNT(guest.software_id) as COUNT, titles.id FROM titles LEFT JOIN guest ON titles.id = guest.software_id GROUP BY titles.id";
$Recordset1 = mysql_query($query_Recordset1, $abe) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$row_Recordset1 = mysql_query($query_Recordset1) or die(mysql_error());
<td>Current comments:<?php
if($row_Recordset1)
while($row = mysql_fetch_array($row_Recordset1))
echo $row['COUNT'];
} ?></td>
The first item now displays the following,
comments:2311000000000000000000000000000
all others
comments:
the number matched the database table exactly, 30 records 4 of which have 2, 3, 1, 1 comments.
It looks as if the problem is trying to get the repeat region to pick up on it! -
To count the records in the database table...
I want to count the number of records in the database table (infotypes PA0000)
is it possible to count ?
Any function module is there?
Thanks in advance..Hi dhavamani ponnusamy,
SELECT COUNT(*) FROM <DB TABLE NAME> WHERE <CONDITION>.
or
SY-DBCNT Will have total no of records satisfying the given criteria in where clause.
See below sample..
Data: itab like mara occurs 0 with header line.
Select * from mara into table mara.
write:/ sy-dbcnt.
Hope it will solve your problem...
Reward points if useful..
Thanks & Regards
ilesh 24x7 -
I am creating biztalk application to store the data into sql server.
and my client says this line what i am not understood .
"Only one round trip to database from BizTalk per message irrespective of number of records in message per table."
Any one can help me to understand this line.!
Thanks,One more option is -
Create a stored procedure to perform batch insert, you can insert into any number of tables you want.
--sample SP code...just added the steps you need to know to extract XML and perform insert
CREATE PROCEDURE <SPName>
@YourXML XML
AS
BEGIN
EXEC sp_xml_preparedocument @idoc OUTPUT, @youXML
SET @j = 1
WHILE @j <= @recordCount
BEGIN
SET @xpath = '//ns1:RootNode/Record[' + CAST(@j AS VARCHAR(11)) + ']'
;WITH XMLNAMESPACES('record namespace' as ns0, 'rootnode namespace' as ns1)
INSERT INTO YourTable
(field1, field2....field20)
SELECT
field1, field2....field20
FROM OPENXML(@idoc, @xpath, 2)
WITH(field1 varchar(2), field2 varchar(20)........field20 varchar(100))
SET @j = @j + 1
END
END
On BizTalk side its quite simple...generate schema for your stored procedure...and in your map transform your XML to StoredProcedure schema using CDATA.
Hope it helps!! -
Sortdump when checking number of records of an SAP table
When trying to check number of records in an SAP table from SE16, that ends with shortdump as below.
SQL error in the database when accessing a table.
Database error text........: "601 Could not continue scan with NOLOCK due to
data movement."
Internal call code.........: "RSQL/COUN//BIC/B0000116000 "
Thank you in advance for quick response.Hi,
please follow note 142731 and do a complete database check. This error is often caused by database corruptions.
Best regards
Clas -
How to get number of records in all user tables in one select
Please advise how to retrieve the number of records in all user tables in one select. I would likt to extract the data to excel file.
Many thanks,
AndrewYou could always analyze the tables:
declare
begin
for X in (select owner, table_name from all_tables
minus
select owner, table_name from all_external_tables) LOOP
dbms_stats.Gather_Table_Stats(X.Owner, X.Table_Name) ;
end loop;
end;
/Then: Select Owner, Table_Name, Num_Rows from All_Tables ; -
Inserting multiple records in to database table using webdynpro abap
Hi all,
I have created a username inputfield,a button and a table
with one coloumn.
If i enter names in the input field then the values should be
displayed in that table.
Even i have got the answer i am not able to insert
the values in to database(ztable) table.
i.e. only one value(1st) was inserted the second value was
not inserted ....
so kindly send me the coding to insert multiple records
into the database table......
by,
ranjithhi Ranjith,
If you want to insert multiple records from the webdynpro view table to database table then try the following code.
DATA lo_nd_tablenode TYPE REF TO if_wd_context_node.
DATA lo_el_tablenode TYPE REF TO if_wd_context_element.
DATA ls_tablenode TYPE wd_this->element_tablenode.
DATA it_tablenode LIKE STANDARD TABLE OF ls_tablenode.
navigate from <CONTEXT> to <tablenode> via lead selection
lo_nd_tablenode = wd_context->get_child_node( name = wd_this->wdctx_tablenode ).
get element via lead selection
lo_el_tablenode = lo_nd_tablenode->get_element( ).
get all declared attributes
lo_nd_tablenode->get_static_attributes_table(
IMPORTING
table = it_tablenode ).
MODIFY databasetablename FROM TABLE it_tablenode.
here it_tablenode is the internal table which holds the value from webdynpro view..
Regards,
Shamila. -
Spilt the number of records in a internal table
Hi all,
I have a requirement where i must spilt the number of records in my internal table itab .Say if i have 2000 records , i must spilt it taking the first 990 records and doing some posting using Bapi and again take the next 990 records and do the posting .Can some one help me out.
Good answers will be rewarded with points.Hi,
You can use these instructions using two internal tables, but please be aware to not forget any line.
REFRESH my_table2.
APPEND LINES OF my_table FROM 1 TO 990 TO my_table2.
CALL FUNCTION 'BAPI'....
(with my_table2)
REFRESH my_table2.
APPEND LINES OF my_table FROM 991 TO my_table2.
CALL FUNCTION 'BAPI'....
(with my_table2)
Regards,
Mathieu -
Count number of records in a internal table
hi
i want to count number of records in internal table
pls let me know how to count the number of records in a internal table.
regards
Arorahi
one way is
data field type i.
Decribe table itab lines field.
write: / field.
displays the no of records in tha internal table
or if u want to write logic.
data:
w_count type i.
loop at itab.
w_count = w_count + 1.
endloop.
write: / w_count.
displays the no of records.
reward points if useful. -
Locking multiple records in a database table at a time
Hi Experts,
I have a requirement to lock multiple records in the database table for writing. I have created lock object in SE11. But with this we have only 2 possibilities either lock entire table or lock a single record at a time.
My requirement is, i have table with key field PROJECTID. I want more than one project to be locked, but not the complete table. I dont have any other field in the table to compare.
Thanks in advance..
Regards,
AsrarHi ,
Try with FOR UPDATE in the SELECT sentence.
SELECT FOR UPDATE *
INTO Internal_Table
FROM Table
WHERE Conditions.
UPDATE "Table_name" FROM TABLE Internal_Table.
COMMIT WORK.
This sentence blocks only the records that satisfy of the WHERE conditions (not the entire table) and unlocks after commit work.
Hope this information is help to you.
Regards,
José -
Number of records in a standard table
Hi,
How to find number of records, without fetching them into a internal table?
is there any command for that?
I want to know the number of records of a standard table in a report.
ThanksHi,
If you want to know the number of records in your internal table after select statement.
You can use the below statement.
data : wa_lines like sy-tfill.
DESCRIBE TABLE itab LINES WS_LINES.
In wa_lines you will have the number of records.
If you want to know the number of records from standard itself.
You can use below :
select count(*) from table into variable
endselect.
Thanks,
Sriram Ponna. -
To count number of records in an internal table for a condition
Hello All,
I want to count number of records in an internal table for a condition.
For e.g. -- I have one internal table IT which having fields F1, F2, F3, F4, F5.
Now, I want number of records in itnternal table IT where F1 = 'ABC'.
Is it possible to do..?? If yes, then how.??
Thanks in advance...!!
Regards,
Poonam.Hi,
If you mean an internal table, there are a few ways to do this.
1 One would be to loop over the table with a WHERE clause and increment a counter.
data: lv_counter type i.
clear lv_counter.
loop at itab where fld1 = 'ABC'.
lv_counter = lv_counter + 1.
endloop.
lv_counter now has the number of rows per the condiction.
2 Well, you may want to try this as well, and compare to the LOOP way. Not sure what kind of overhead you may get doing this way. Here ITAB is our main internal table, and ITAB_TMP is a copy of it. Again I think there may be some overhead in doing the copy. Next, delete out all records which are the reverse of your condition. Then whatever is left is the rows that you want to count. Then simply do a LINES operator on the internal table, passing the number of lines to LV_COUNT.
data: itab type table of ttab.
data: itab_tmp type table of ttab.
itab_tmp[] = itab[].
delete table itab_tmp where fld1 'ABC'.
lv_count = lines( itab_tmp ).
Thanks & Regards,
ShreeMohan -
How to set default number of records shown in report table?
How can I set the default number of records shown in a table report?
This is how report attributes page should look like and there is the number of rows where you enter whatever you need:
http://i44.tinypic.com/es95bn.gif
Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.opal-consulting.de/training
http://apex.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
Selecting the last record from a database table
In my ABAP Program, I have to use a select statement to retrieve the last record from the database table with the same key. In other words, the Program will get more than one hit on the database table for the selected keys and I need to retrieve values from only the last record and not the first. I know I can use an internal table to sort the records first and then retrieve the right value. But to make things easier, is there a SELECT statement keyword than I can use to do this in one single step? Thanks!
hi,
tables:mara.
data: begin of it_mara occurs 0,
matnr like mara-matnr,
meins like mara-meins,
mtart like mara-mtart,
end of it_mara.
select-options:s_matnr for mara-matnr.
select matnr
meins
mtart
from mara
into table it_mara
where matnr in s_matnr.
if not it_mara[] is initial.
sort it_mara by matnr descending.
read table it_mara index 1.
endif.
then you get the last record of the select statement.
reward points if useful,
venkat.
Maybe you are looking for
-
How do I email (or share) pdf files I have stored on my Galaxy Note II?
I have been using Galaxy Note 2 and used to be able to send pdf files using Adobe Reader to myself and to others. I believe there used to be a "share option" at the top which allowed me to do this. After updating Adobe Reader, this option disappeared
-
My officejet 4500 wireless keeps shutting down when i turn it on
when I turn on my officejet 4500 wireless it starts to warm up and then shuts down. This question was solved. View Solution.
-
Has no sound and the screen is dim
Can anyone help? It was working fine and then the sound was kind of scratchy and now it has NO sound and the screen isn't as bright as it was before Thanks....
-
ICR Process 003 - FBICR3 - Display original FI document
Hello, I am doing several test run of ICR Process 003 and I have found that, without any reason, sometimes functionality "display original FI document2 does not work when pushing the "button". Am I doing something wrong? Is there any functional reaso
-
Bridge forgets the last folder I had open when I restart the computer and PS4/Bridge. What gives? thanks Marv.