progress 4gl query for export count of records in all table available in db

user3668036

I am trying to export count of all tables in excel or text file.

if any program or any query will help me ? 

I am trying to code for export count of data available in each table.

code:

  define stream table t1.
    output stream t1 to t1.csv.

    &scope-define display-fields count(*)

    select count(*) from emp.

    export starem t1 delimiter ",".

This code create excel with empty value but display result on screen. i out in excel.

Jensd

Unsure what you want to do. Something like this if you want to count the number of tables in a database:

DEFINE VARIABLE icount AS INTEGER NO-UNDO.
FOR each _file NO-LOCK WHERE _file._owner = "PUB":

    /* Skip "hidden" virtual system tables */
    IF _file._file-name BEGINS "_" THEN NEXT.

    iCount = iCount + 1.
END.

MESSAGE iCount "tables in the database"
    VIEW-AS ALERT-BOX INFORMATION.

If you have several db's connected you need to prepend the _file-table with the database name ie database._file.

However: since you say "export to excel" perhaps what you mean is that you want to know the number of records for each table?

To count number of records in a table you can use FOR or SELECT.

SELECT COUNT(*) FROM tablename.

or

DEFINE VARIABLE iCount AS INTEGER NO-UNDO.  
FOR EACH tablename NO-LOCK TABLE-SCAN:
    iCount = iCount + 1.
END.
DISPLAY iCount.

If you don't want to code this for each table you need to combine it with a dynamic query counting all records.

DEFINE VARIABLE hQuery  AS HANDLE    NO-UNDO.
DEFINE VARIABLE hBuffer AS HANDLE    NO-UNDO.
DEFINE VARIABLE iCount  AS INTEGER   NO-UNDO.
DEFINE VARIABLE cTable  AS CHARACTER NO-UNDO.

/* Insert tablename here */
cTable = "TableName".

CREATE QUERY hQuery.
CREATE BUFFER hBuffer FOR TABLE cTable.

hQuery:SET-BUFFERS(hBuffer).

hQuery:QUERY-PREPARE(SUBSTITUTE("FOR EACH &1", cTable)).

hQuery:QUERY-OPEN.

queryLoop:
REPEAT:

    hQuery:GET-NEXT().

    IF hQUery:QUERY-OFF-END THEN LEAVE queryLoop.

    iCount = iCount + 1.
END.

DELETE OBJECT hQuery.
DELETE OBJECT hBuffer.

MESSAGE iCount "records in the table".

Combine those two and you have a solution. It might be slow however since it will count all records of all tables.

A quick and dirty way is to run "tabanalys" on the database instead if you have access to it via the prompt:

proutil DatabaseName -C tabanalys > tabanalys.txt

This can be run online and might have impact on file io etc so run it the first time on off peak hours just to make sure. Then look into that file, you will see record count, sizes etc for all tables: system-tables as well as user-tables.

Proutil ran online might not be 100% correct but most likely "good enough".

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Count all records that does not exist to other table - SQL Query

How to read a XML file and export an item using Progress 4GL

How to add a date condition to for each loop in Progress 4GL query?

Progress Database 4GL - Math calculate for export file

Count all and count the records that meet a clause in a single query

Dynamically update the count for number of records available in react-table

How to export xml file in progress 4gl?

How to list all lines in a field with Progress 4GL

Usage of LOB's in progress 4GL

Datatype in progress 4gl

In progress 4gl get field names of temp-table

Count all records in a table

Progress 4gl Matches Queries

How do I do a case/switch query with Progress 4GL 9.1D?

How to get a list of all table available in the db?

How to match a records in progress 4GL?

Can I get the count of all records in a Cosmos DB table for a large amount of records?

How to calculate yesterday records with today records using progress 4gl?

Getting XML data into Temp-Table in Progress 4GL/OpenEdge ABL

How do I count total lines and create new/Select sheet in one csv file using progress 4GL?

Count all records of table ignoring filters

How to implement NOT EXISTS in OPEN QUERY statement in PROGRESS 4GL - OpenEdge 10.2A

How to fix Dynamic Query error for progress 4gl?

SQL query for all grouped records in joined table

How add only required fields from table to dynamic temp table? - PROGRESS 4GL

how to add and display specific records from code_mstr to temp-table in progress 4gl?

how to create a temp-table for code_mstr in progress 4gl?

Unable to connect to db using -pf in openEdge progress 4gl

<Table> already exists with Record ID 0. (132) - PROGRESS 4GL