Maximo Open Forum

 View Only

 Query to list inventory items based on several conditions.

  • Maximo User Groups
Nathan Frail's profile image
Nathan Frail posted 01-23-2025 16:57

Hey all, 

So, I pieced together this query a while back with the help of some co-workers and Maximo forums, but I knew it wasn't going to stand the test of time and was going to omit some records that we ultimately want to capture. For the time it was written, it did what we needed it to do.

Fast-forward to today, I'm trying to revisit this and capture a list of specific items from Inventory that have not been:

"Issued to an Asset, Transferred from another Store, or Received into inventory in over 365 days. Balance is not zero, cost is not zero.

My current query below is admittedly very "clunky", but it was the best I could do with my knowledge of SQL.

Here are the conditions I currently have (and want to add). I'm sure there is a more efficient way to write this as I just cobbled it together as I learned.

  1. Record is not Obsolete (Not sure this is even necessary as Obsolete records don't have a positive quantity. Redundant?)
  2. Last issue date > 365 (or lastIssuedate is null) - Some records have no issue history so the field is blank, which is why I had to include the MATRECTRANS table in mine. 
  3. Receipt Date > 365 (or no receipt history) & (I'd like to include all types of receipt transactions including RECEIPT & SHIPRECEIPT but not INVOICE)
  4. Current Balance !=0
  5. Avgcost !=0
(status in (
    select value from synonymdomain
    where domainid ='ITEMSTATUS' 
    and maxvalue not in ('OBSOLETE')
)
and exists (
    select 1 from invbalances
    where invbalances.itemnum = inventory.itemnum
    and invbalances.location = inventory.location
    and invbalances.siteid = inventory.siteid 
    and invbalances.itemsetid = inventory.itemsetid 
    and invbalances.curbal != 0
    and lastissuedate < current date - 12 month)

and exists (
    select 1 from invcost
    where itemnum = inventory.itemnum
    and location = inventory.location
    and avgcost !=0)
)

and not exists (
    select 1 from matrectrans
    where itemnum = inventory.itemnum
    and tostoreloc = inventory.location
    and fromsiteid = inventory.siteid 
    and itemsetid = inventory.itemsetid 
    and issuetype in ( 
        select value from synonymdomain
        where domainid = 'ISSUETYPE'
        and maxvalue = 'SHIPRECEIPT')
)
and not exists(
                select 1 from matrectrans
        where itemnum = inventory.itemnum
        and tostoreloc = inventory.location
        and fromsiteid = inventory.siteid
        and itemsetid = inventory.itemsetid
        and transdate > current date - 12 month
)
and not exists (
    select 1 from matusetrans
    where itemnum = inventory.itemnum
    and storeloc = inventory.location
    and siteid = inventory.siteid  
    and issuetype in ( 
        select value from synonymdomain
        where domainid = 'ISSUETYPE'
        and maxvalue = 'ISSUE')
)
and not exists(
                select 1 from matusetrans
        where itemnum = inventory.itemnum
        and storeloc = inventory.location
        and siteid = inventory.siteid
        and transdate > current date - 12 month

)

Craig Kokay's profile image
Craig Kokay

Hi Nathan,

So, let's break this down.  Per item in a storeroom that are not:

  1. Not obsolete
    1. You have that query
  2. Current balance is not zero
    1. You have that query
  3. Unit cost is not zero
    1. You have that query
  4. Not issued in the last 12 months (to an asset)
    1. You have that query, however, you have split out the issue and the date.  No need to split.
    2. You forgot to isolate it only to issued to an asset
  5. Not transferred into the last 12 months (assumption is the transferred-in portion of the transaction)
    1. You have missed the TRANSFER type.  Not the MATRECTRANS.TOSTORELOC determines the "in" location. Combine with the shipment receipt
    2. No need to split out the date
  6. Received into the store (i.e. purchased) in the last 12 month
    1. You have missed the RECEIPT type.  Not the MATRECTRANS.TOSTORELOC determines the "in" location. Combine with the shipment receipt and transfer
    2. No need to split out the date