Skip to content

Instantly share code, notes, and snippets.

@forstie
Created January 29, 2021 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forstie/d0eadb72f52d153cbe8ce9746d053d67 to your computer and use it in GitHub Desktop.
Save forstie/d0eadb72f52d153cbe8ce9746d053d67 to your computer and use it in GitHub Desktop.
I was asked how object_statistics could be used with *LIBL and *USRLIBL to produce accurate and ordered results. Gist look at this...
--
-- Use NAMING(*SYS) - system naming mode to leverage the power of the library list
--
cl: crtlib lib1;
cl: crtlib lib3;
cl: crtlib lib2;
cl:CRTDUPOBJ OBJ(QSQPTABL) FROMLIB(QSYS2) OBJTYPE(*FILE) TOLIB(LIB1) DATA(*YES);
cl:CRTDUPOBJ OBJ(QSQPTABL) FROMLIB(QSYS2) OBJTYPE(*FILE) TOLIB(LIB2) DATA(*YES);
cl:CRTDUPOBJ OBJ(QSQPTABL) FROMLIB(QSYS2) OBJTYPE(*FILE) TOLIB(LIB3) DATA(*YES);
cl: addlible lib1;
cl: addlible lib3;
cl: addlible lib2;
-- Review the library list for this thread
select *
from QSYS2.LIBRARY_LIST_INFO;
stop;
--
-- Now, use OBJECT_STATISTICS to find an object, based upon the library list order
--
select SYSTEM_SCHEMA_NAME as library_name, objname, objcreated, objsize
from table (
object_statistics(object_schema => '*LIBL', object_name => 'QSQPTABL', OBJTYPELIST => '*FILE')
) a
inner join QSYS2.LIBRARY_LIST_INFO b
on a.objlib = b.system_schema_name
order by b.ordinal_position asc;
stop;
--
-- Alternative coding
--
select SYSTEM_SCHEMA_NAME as library_name, objname, objcreated, objsize
from table (
object_statistics(object_schema => '*LIBL', object_name => 'QSQPTABL', OBJTYPELIST => '*FILE')
) a, lateral (
select *
from QSYS2.LIBRARY_LIST_INFO
where a.objlib = system_schema_name
) b
order by b.ordinal_position asc;
stop;
--
-- Switch from *LIBL to *USRLIBL
--
select SYSTEM_SCHEMA_NAME as library_name, objname, objcreated, objsize
from table (
object_statistics(object_schema => '*USRLIBL', object_name => 'QSQPTABL', OBJTYPELIST => '*FILE')
) a
inner join QSYS2.LIBRARY_LIST_INFO b
on a.objlib = b.system_schema_name
order by b.ordinal_position asc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment