Skip to Content
0
Sep 15, 2017 at 05:39 PM

Inventory Aging Query - Need help with query not showing correct aging

114 Views

Hello SAP Gurus,

I need my query to include inventory transfers when determining aging. I have some items that are only showing 0-30 days when it actually had an inventory transfer transaction more than 180 days.

Here is the query:

select b.code 'Item No.', b.name 'Description', b.Wh, b.ap 'Average Price', b.Bal 'Total Qty', b.Val 'Total Value',
isnull(case when b.days <30 then b.bal end,0)'0-30 Days (Qty)',
isnull(case when b.days between 30 and 60 then b.bal end,0) '30-60 Days (Qty)',
isnull(case when b.days between 60 and 90 then b.bal end,0) '60-90 Days (Qty)',
isnull(case when b.days between 90 and 120 then b.bal end,0) '90-120 Days (Qty)',
isnull(case when b.days between 120 and 150 then b.bal end,0) '120-150 Days (Qty)',
isnull(case when b.days between 150 and 180 then b.bal end,0) '150-180 Days (Qty)',
isnull(case when b.days >180 then b.bal end,0) 'Above 180 Days (Qty)'
from (
select a.code,a.name,a.wh,a.ap,a.bal,a.val,datediff(dd,dt,getdate())'days'
from (
select max(t0.itemcode)'Code',max(t0.Dscription)'Name',
max(t0.Warehouse)'Wh', max(t1.avgprice) 'ap',
sum(t0.inqty-t0.outqty)'Bal',sum(t0.transvalue)'Val',max(t0.docdate)'dt'
from oinm t0 inner join oitm t1 on t0.itemcode=t1.itemcode
inner join oitw t2 on t0.itemcode=t2.itemcode and t0.warehouse=t2.whscode
where t0.warehouse='[%1]'
group by t0.itemcode
)a
)b order by code

Thank you in advance for any help you can provide.

Kind regards,

Larry T.