If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Cobol Host-variable For Select Count(*)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-19-07, 12:37
db2dcs db2dcs is offline
Registered User
 
Join Date: Feb 2005
Location: United States
Posts: 20
Cobol Host-variable For Select Count(*)

What is the compatible COBOL host variable structure to receive the result of a SELECT COUNT(*) ?
Is it integer type: PIC S9(9) USAGE COMP?
It seems that is the type favored by our compiler.
If so, what if the count reached 1 billion (1,000,000,000) ?

My result may one day exceed 999,999,999. If that is true, what host variable structure should I use?

thanks to anyone who can assist.

db2dcs
Reply With Quote
  #2 (permalink)  
Old 09-19-07, 13:12
jsharon1248 jsharon1248 is offline
Registered User
 
Join Date: Apr 2007
Location: Chicago
Posts: 57
COUNT(*) returns a large integer (-2147483648 to +2147483647), so the PIC S9(9) USAGE COMP is actually correct. Use COUNT_BIG which returns a decimal with length 31, PIC S9(31) COMP-3.
Reply With Quote
  #3 (permalink)  
Old 09-19-07, 19:22
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by db2dcs
What is the compatible COBOL host variable structure to receive the result of a SELECT COUNT(*) ?
Is it integer type: PIC S9(9) USAGE COMP?
It seems that is the type favored by our compiler.
If so, what if the count reached 1 billion (1,000,000,000) ?

My result may one day exceed 999,999,999. If that is true, what host variable structure should I use?

thanks to anyone who can assist.

db2dcs
The assumption is that if you use SELECT COUNT(*) and the answer is greater than 2,147,483,648 (you were off by about 1 billion), then there would be some rather serious cobwebs on your skeleton as you sit at the computer waiting for the query to return with an answer.

If you want to know how many rows there are in the table, then execute runstats and look at the CARD column on SYSCAT.TABLES (which is a BIGINT and goes up to 9,223,372,036,854,775,807). I believe that on the mainframe DB2 it is called CARDF.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390

Last edited by Marcus_A; 09-20-07 at 00:28.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On