/* List all DB2 tables with more than 1000 rows
    using the prepped package SAMPLE1 */

  arg db user password

  /* Connect the database; exit at error */
  "REXXSQL CONNECT" user "IDENTIFIED BY" password "TO" db
  if SQLCODE < 0 then exit 8

  /* Check if package SAMPLE1 exists, create it if not */
  "REXXSQL LOCATE PACKAGE SAMPLE1"  
  if SQLCODE = 100 then call Create_Package

  /* Execute the prepped statement "get_rowcount" */
  "REXXSQL EXECUTE GET_ROWCOUNT IN SAMPLE1 USING '%' 1000"
  if SQLCODE <> 0 then exit sqlcode

  /* Show results */
  do i = 1 to _NROWS
    tablename = strip(creator.i)"."strip(tname.i)
    say "Table" tablename "has" rowcount.i "rows"
  end
  "REXXSQL COMMIT"
  exit

  /* Create the package SAMPLE1 */
  Create_Package:
  "REXXSQL CREATE PACKAGE SAMPLE1"
  if SQLCODE <> 0 then /* process error */
  s = "SELECT CREATOR,TNAME,ROWCOUNT FROM SYSTEM.SYSCATALOG" ,
      "WHERE TNAME LIKE :VARCHAR AND ROWCOUNT >= :INTEGER" ,
      "ORDER BY ROWCOUNT DESC"
  "REXXSQL PREPARE GET_ROWCOUNT FROM" s
  if SQLCODE <> 0 then /* process error */
  "REXXSQL "COMMIT"
  return