Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2005
    Location
    United States
    Posts
    22

    Unanswered: 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

  2. #2
    Join Date
    Apr 2007
    Location
    Chicago
    Posts
    68
    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.

  3. #3
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    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.
    Last edited by Marcus_A; 09-20-07 at 01:28.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •