arg db user password
/* Connect the database; exit at error */
r = REXXSQL("CONNECT" user "IDENTIFIED BY" password "TO"
db)
if SQLCODE < 0 then exit 8
/* Check if package SAMPLE1 exists, create it if not */
if 0 <> REXXSQL("LOCATE PACKAGE SAMPLE1") then call Create_Package
/* Execute the prepped statement "get_rowcount" */
r = 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
r = REXXSQL("COMMIT")
exit
/* Create the package SAMPLE1 */
Create_Package:
r = 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"
r = REXXSQL("PREPARE GET_ROWCOUNT FROM" s)
if SQLCODE <> 0 then /* process error */
r = REXXSQL("COMMIT")
return