cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Production order item availability

Yulolo14
Explorer
840

Hello guys

i need a query from production order that will show the item planned qty against the qty available from 3 warehouses. Query looks something like this.

IMG_4447.jpeg

I was able to do it but the warehouses are aligned vertically and it doubling the item number so as its Qty.

This is the code I used. 

SELECT T0."DocNum", T1."ItemCode",T1."PlannedQty", T2."WhsCode", T2."OnHand",T0."PostDate", T0."StartDate", T0."DueDate", T0."Status" FROM OWOR T0 INNER JOIN WOR1 T1 ON T0."DocEntry" = T1."DocEntry" INNER JOIN OITW T2 ON T1."ItemCode" = T2. "ItemCode" WHERE T0."Status" = 'P' and T2."WhsCode" IN ('RM','FG') and T0."StartDate" >= [%0] and T0."DueDate" <= [%1]

sss.PNG

Item here is being double.

Looking forward for sap community help.
thanks in advance guys.  

Accepted Solutions (1)

Accepted Solutions (1)

SonTran
Active Contributor
0 Kudos

Hi,

You can refer this topic to convert from line to column.

https://forum.sapb1.vn/community/saphana/cach-pivot-ket-qua-truy-van-trong-sap-hana/#post-154

Hope this helps,

Son Tran

Yulolo14
Explorer
0 Kudos
hello.. this wouldn't work as i need also data from OITW to match to the itemcode. someone told to use subquery but i encounter an error...
Yulolo14
Explorer
0 Kudos

this is the code: SELECT T0."DocNum" , T1."ItemCode" , T1."PlannedQty" , T1."wareHouse" , (SELECT OnHand FROM OITW WHERE WhsCode = 'RM' AND ItemCode = T1."ItemCode") AS "OnHand\_RM" , (SELECT OnHand FROM OITW WHERE WhsCode = 'FG' AND ItemCode = T1."ItemCode") AS "OnHand\_FG" , T0."PostDate" , T0."StartDate" , T0."DueDate" , T0."Status" FROM OWOR T0 INNER JOIN WOR1 T1 ON T0."DocEntry" = T1."DocEntry" WHERE T0."Status" = 'P' AND T1."wareHouse" IN ('RM', 'FG') AND T0."StartDate" >= [%0] AND T0."DueDate" <= [%1]

SAP returns with an error. "1). [SAP AG][LIBODBCHDB DLL][HDBODBC] Syntax error or access violation;257 sql syntax error: line 1 col 8 'Received Alerts' (OAIB) (at pos 8)"

Maybe you can help me out to dedug the query... thanks a lot bro..

SonTran
Active Contributor

Try this

select T0.DocEntry, T0.StartDate, T0.DueDate,T0.Status, T1.ItemCode, T1.PlannedQty, 
sum(case when T2.WhsCode='RM' then T2.OnHand else 0 end) as 'OnHand_RM',
sum(case when T2.WhsCode='FG' then T2.OnHand else 0 end) as 'OnHand_FG'
from OWOR T0 join WOR1 T1 on T0.DocEntry=T1.DocEntry and T1.ItemType=4
left join OITW T2 on T1.ItemCode=T2.ItemCode and  T2.WhsCode in ('RM', 'FG')
where T0.Status ='P' and T0.StartDate>=[%0] and T0.StartDate <=[%1]
group by T0.DocEntry, T0.StartDate, T0.DueDate,T0.Status, T1.ItemCode, T1.PlannedQty
Yulolo14
Explorer
0 Kudos

Hello SonTran,

 

the code works.. but can i ask what is the role of T1."ItemType"=4 ?

SonTran
Active Contributor
0 Kudos

There are 2 component types in production order:

  • 4: Item
  • 290: Resource
Yulolo14
Explorer
0 Kudos
I see... thanks for the help bro... you are a life saver...
neilos
Active Participant
0 Kudos
Thats a great solution

Answers (0)