Skip to content

Instantly share code, notes, and snippets.

@BirgittaHauser
Created November 5, 2020 15:44
Show Gist options
  • Save BirgittaHauser/74b78ed5db37970155b5aacecb824266 to your computer and use it in GitHub Desktop.
Save BirgittaHauser/74b78ed5db37970155b5aacecb824266 to your computer and use it in GitHub Desktop.
How to search source physical file member for a specific String
It was just a question in a Forum: How to search (all) source physical file members for a specific string and list all those members
In this examples all source files beginning with "QSRC" in the "YOURSCHEMA" library are searched whether they include "String".
All Source Members that include "String" are returned
With a as (Select a.System_Table_Schema OrigSchema,
a.System_Table_Name OrigTable,
a.System_Table_Member OrigMember,
Trim(System_Table_Schema) concat '/' concat
Trim(System_Table_Name) concat '(' concat
Trim(System_Table_Member) concat ')' as OrigCLOBMbr
from Syspartitionstat a
Where System_Table_Name like 'QSRC%'
and System_Table_Schema = 'YOURSCHEMA')
Select OrigSchema, OrigTable, OrigMember
from a
Where Get_Clob_From_File(OrigClobMbr) like '%String%';
@venredit
Copy link

venredit commented Nov 8, 2020

Really useful, thankyou.

Had to issue a transaction isolation level of “read uncommitted” to enable GET_CLOB_FROM_FILE.

@BirgittaHauser
Copy link
Author

Get_CLOB_From_File returns a CLOB locator.
And when working with LOB locators commitment control is required.
If forgot it to mention because I always work under commitment control.

@thebeardedgeek
Copy link

Hi Birgitta,
Can I get an explanation of how to use this for dummies...lol

I have been spending more time learning the database structure and how to interact with it. I am very familiar with using SQL on the system. When you say Schema does that = library name? Some software refers to Schema as the RDB name.

I tried the following changes and the SQL executes but with no results:
System_Table_Name like 'SRC%'
and System_Table_Schema = 'MATTS'
Where Get_Clob_From_File(OrigClobMbr) like '%FTP%'

I was hoping this would bring back all of the source that referenced FTP in it. Am I totally off base with what I am trying to do and what you are saying this does?

Thank you.

@BirgittaHauser
Copy link
Author

Schema and library are (at least on IBM i) identical. Schema is the SQL Name and Library the IBM i name.
Where are your sources located? In Source Files that start with QSRC? If your sources you want to search are located for examples in source files starting with QRPG, you then have to replace QSRC with QRPG.

@GlennGundermann
Copy link

Hi Birgitta,

Do you have a version that doesn't rely on source files starting with 'QSRC'?
I.E. Search all tables that are type source physical files.

Thank you.

@BirgittaHauser
Copy link
Author

BirgittaHauser commented Mar 25, 2022 via email

@GlennGundermann
Copy link

Hi Birgitta,

Your code above has: Where System_Table_Name like 'QSRC%'
I am asking if instead of looking for specific table names, can you join with SYSTABLES and look for tables where file_type = 'S'.

Glenn

@gcraill
Copy link

gcraill commented Jan 26, 2023

Thanks Birgitta,

FYI - Had an issue whereby it failed to identify part of the object name due to wild card shenanigans and did not filter correctly.

image

As seen it ignored the underscore in the selection criteria.

The fix (Thanks @zkarj735) was to use this instead.

Where System_Table_Name like 'QCLSRC+_%' escape '+'

@pabloto
Copy link

pabloto commented Feb 13, 2024

Hi Birgitta,

I can't use it if my schema is inside IASP. It return me sqlstate 42704, Is there any circumvention?

(If I try on QGPL it works, and I can do a select on a table into iasp)

Thank you

@masmithrpg
Copy link

when i try to run this is ACS Run Sql Scripts, i receive sql0443 state 42927
LOB and XML locators are not allowed with COMMIT(*NONE)

@BirgittaHauser
Copy link
Author

Yes, that's true! When working with Locators (LOB or XML-Locators) you have to run under commitment control. Normally the lowest level *CHG is enough.
Locators are kind of Pointers ... and Pointers have to be freed. ... LOB-Locators or XML-Locators get freed when executing a COMMIT or ROLLBACK statement! So you must use them under commitment control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment