Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
There's frequently more than one way to code a solution. Today I was asked how to use SQL to count the number of objects within a library. There are two examples... one is very fast, but requires IBM i 7.4.
--
-- description: Count objects in a library (superfast)
-- minvrm: v7r4m0
--
with libs (ln) as (
select objname
from table (
qsys2.object_statistics('*ALLSIMPLE', 'LIB')
)
)
select ln, object_count
from libs, lateral (
select *
from table (
qsys2.library_info(system_schema_name => ln)
)
)
order by object_count desc;
--
-- description: Count objects in a library (slowish)
-- minvrm: v7r3m0
--
with libs (ln) as (
select objname
from table (
qsys2.object_statistics('*ALLSIMPLE', 'LIB')
)
)
select ln, object_count
from libs, lateral (
select count(*) as object_count
from table (
qsys2.object_statistics(ln, '*ALL', '*ALLSIMPLE')
)
)
order by object_count desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment