Skip to content

Instantly share code, notes, and snippets.

View forstie's full-sized avatar

Scott Forstie forstie

  • IBM
View GitHub Profile
@forstie
forstie / SQL alternative to the command ANZDFTPWD ACTION(*NONE).sql
Last active October 26, 2021 19:43
The request was, is there an SQL alternative to the command ANZDFTPWD ACTION(*NONE)? The answer was a resounding YES.
--
-- Subject: SQL alternatives to Analyze Default Passwords (ANZDFTPWD) ACTION(*NONE)
-- Author: Scott Forstie
-- Date : October 26, 2021
-- Features Used : This Gist uses user_info_basic, grouping, and SYSTOOLS.CHANGE_USER_PROFILE
--
-- Function - The request was, is there an SQL alternative to the command ANZDFTPWD ACTION(*NONE) ?
--
--
stop;
@forstie
forstie / virtually done.sql
Last active December 27, 2023 19:27
Does your physical data model include a virtual layer? If no, this gist is for you...
--
-- Subject: Establishing a virtual layer in the data model using SQL Views
-- Author: Scott Forstie
-- Date : Rocktober, 2021
-- Features Used : This Gist uses QSYS2.SYSFILES, QSYS2.SYSCOLUMNS2, dynamic SQL, and SQL PL
-- Prereq: IBM i 7.3 or higher, with the Db2 PTF Group level from September 9, 2021 or later
--
-- Function - The request was, I don't have a DBE.. I don't have SQL Views... how do I get started with
-- shifting users and applications away from directly consuming the physical files?
--
@forstie
forstie / Extracting the IFS filename from an absolute path name.sql
Created September 28, 2021 01:55
The request was, if you have an absolute path, how can SQL extract the filename from the path? One approach is found below.
--
-- Subject: Extracting the IFS file name from a path, using regular expression built-in functions
-- Author: Scott Forstie
-- Date : September 27, 2021
-- Features Used : This Gist uses regexp_count, regexp_instr, substr, and SQL PL
--
-- Function - The request was, if you have an absolute path, how can SQL extract the filename from the path?
-- One approach is found below.
--
--
@forstie
forstie / authority collection - split to the rescue.sql
Last active March 4, 2022 15:43
This Gist shows how SQL can be used to simplify the task of analyzing Authority Collection runtime authority data.
--
-- Subject: authority collection - split to the rescue
-- Author: Scott Forstie
-- Date : September 20, 2021
-- Features Used : This Gist uses split(), right exception join, set session authorization, and authority_collection
--
-- Function - This gist goes beyond visual recognition of the authorization gap, using SQL to compute the different AND
-- generate the Grant Object Authority (GRTOBJAUT) CL commands needed to bridge the gap.
--
-- In this example, JOEUSER wants to QUERY and UPDATE the TOYSTORE/SALES file.
@forstie
forstie / IFS_search_replace_and_create.sql
Last active July 22, 2021 16:15
I was asked how ifs_read and ifs_write could be combined to build a new IFS stream file, where certain character strings are replaced.
--
-- Subject: IFS stream file transformation
-- Author: Scott Forstie (thanks to Sue Romano for helping with this Gist)
-- Date : June 28, 2021
-- Features Used : This Gist uses ifs_read, ifs_write, regexp_replace, and the previously unknown fx designation for a unicode literal.
--
-- Function - Point is routine at an existing IFS steam file, which contains some character data that you want to globally replace.
-- The function extracts (reads) the contents, replaces the search string occurrences with the replacement string, and then
-- writes everything to the target IFS stream file.
--
@forstie
forstie / change command default.sql
Created June 4, 2021 16:22
Before an upgrade, rollswap, or just for good hygiene, its good to know which CL commands have had their command defaults changed. Here's an approach that works all the way back to IBM i 7.2.
--
-- Which CL commands have had their parameter defaults changed?
-- (On IBM i 7.3 and higher)
--
with libs (lib) as (
select objname
from table (
qsys2.OBJECT_STATISTICS('*ALLAVL', '*LIB')
)
)
@forstie
forstie / QBATCH job study.sql
Created May 30, 2021 17:10
I was asked to show how SQL could be used to analyze QBATCH subsystem job history. Super grouping to the rescue.
--
-- Subject: QBATCH Job Analysis
-- Author: Scott Forstie
-- Date : May 30, 2021
-- Note : This Gist leverages different built-in functions and grouping support to explore job history
--
-- ================================================================================================
--
-- description: 20 Jobs that ran (started and ended) the longest in QBATCH over the last 24 hours
@forstie
forstie / Employment Days.sql
Last active November 18, 2022 17:40
I was asked how SQL could compute the number of days difference between two dates columns, where one column might contain NULL. The timestamp_format and timestampdiff built-in functions get the job done, with a little help from coalesce.
create table toystore.employee_deetz (
Company_Id bigint,
Employee_Id bigint,
FirstName varchar(100) for sbcs data,
SurName varchar(100) for sbcs data,
Employed_Start_Date date,
Employed_End_Date date);
insert into toystore.employee_deetz values
(101, 10001, 'Scott', 'Forstie', '07/11/1989', NULL);
@forstie
forstie / prtprvaut.sql
Created May 14, 2021 14:02
Someone sent me an "SQL Challenge". Challenge accepted! #SQLcandoit
--
-- If you're not ready to use IFS_OBJECT_PRIVILEGES, this might help you...
-- Note: A special thanks to Sue Romano for her help with this Gist
--
-- https://www.ibm.com/docs/en/i/7.4?topic=services-ifs-object-privileges-table-function
cl:PRTPVTAUT OBJTYPE(*STMF) DIR('/') SCHSUBDIR(*YES);
--
-- create an alias over the most recent execution of PRTPRVAUT
@forstie
forstie / QAPMJOBL.sql
Created May 13, 2021 13:47
I was asked how SQL could transform Collection Services data, in this case Job Performance Data, into a more consumable form. SQL built-in functions and CASE expressions get the job done.
--
-- Collection Services data file: QAPMJOBL (JOB PERFORMANCE DATA)
--
-- Resource:
-- https://www.ibm.com/docs/en/i/7.4?topic=data-collection-services-files-qapmjobs-qapmjobl
--
--
-- Raw
--