Query to show stock quantity
Hi Friends,
I have this data in a table, which stores quantity of items on the basis of tickets No.(issuing items from ticket)
This table also save data from receipt(Receipt items).
This is my table data:-
vc_id vc_date nu_qty ch_flag tick_no tic_date
1 01-10-2009 2000 A
2 11-10-2009 20 S 201 09-10-2009
3 12-10-2009 10 S 201 09-10-2009
4 12-10-2009 20 S 202 10-10-2009
5 13-10-2009 30 S 201 09-10-2009
6 13-10-2009 10 S 203 10-10-2009
7 14-10-2009 1000 A
8 14-10-2009 20 S 202 10-10-2009
Now i would like to query so that it show data(Period Wise) like:-
from vc_date between 01-10-2009 and 12-10-2009
Date Tick No. Tick Date Received Qty Issue Qty Balance Qty
01-10-2009 2000 2000
12-10-2009 201 09-10-2009 2000 30 1970
12-10-2009 202 10-10-2009 1970 20 1950
How to accomplish it ?
Regards
KarTiK PareeK
SQL> create table mytable (vc_id,vc_date,nu_qty,ch_flag,tick_no,tic_date)
2 as
3 select 1, date '2009-10-01', 2000, 'A', null, null from dual union all
4 select 2, date '2009-10-11', 20 , 'S', 201 , date '2009-10-09' from dual union all
5 select 3, date '2009-10-12', 10 , 'S', 201 , date '2009-10-09' from dual union all
6 select 4, date '2009-10-12', 20 , 'S', 202 , date '2009-10-10' from dual union all
7 select 5, date '2009-10-13', 30 , 'S', 201 , date '2009-10-09' from dual union all
8 select 6, date '2009-10-13', 10 , 'S', 203 , date '2009-10-10' from dual union all
9 select 7, date '2009-10-14', 1000, 'A', null, null from dual union all
10 select 8, date '2009-10-14', 20 , 'S', 202 , date '2009-10-10' from dual
11 /
Tabel is aangemaakt.
SQL> select max(vc_date) vc_date
2 , tick_no
3 , tic_date
4 , sum(case ch_flag when 'A' then nu_qty end) received_qty
5 , sum(case ch_flag when 'S' then nu_qty end) issue_qty
6 , sum
7 ( nvl(sum(case ch_flag when 'A' then nu_qty end),0)
8 - nvl(sum(case ch_flag when 'S' then nu_qty end),0)
9 )
10 over (order by max(vc_date),tick_no) balance_qty
11 from mytable
12 where vc_date between date '2009-10-01' and date '2009-10-12'
13 group by tic_date
14 , tick_no
15 order by vc_date
16 , tick_no
17 /
VC_DATE TICK_NO TIC_DATE RECEIVED_QTY ISSUE_QTY BALANCE_QTY
01-10-2009 00:00:00 2000 2000
12-10-2009 00:00:00 201 09-10-2009 00:00:00 30 1970
12-10-2009 00:00:00 202 10-10-2009 00:00:00 20 1950
3 rijen zijn geselecteerd.I'm not entirely sure, but I hope this is what you want ...
Regards,
Rob.
Similar Messages
-
How to query a item stock quantity for a given date
Hi there,
I need to query the stock quantity of an item for a given date. For example, i want to know how many pieces of A i have on stock at the 20th of march 2009.
I know there is a report, but i need the value for a subquery.
Regards SteffenSorry Gordon,
Your query is not wrong, far from me to insult your work. It does indeed make full sense if the business process allows the item description to change.
If not, we can avoid a "inner join" = smaller, cleaner and (theoritically) faster query
Here is your code with the little review:
SELECT T0.ItemCode, T0.Dscription, sum(T0.InQty - T0.OutQty) as 'On Hand'
FROM DBO.OINM T0
WHERE T0.DocDate <= '[%0]' and T0.ItemCode = '[%1]'
GROUP BY T0.ItemCode, T0.Dscription
Cheers
tested on 2007 SP00 PL46 -
Query to show stock value per group
Hi Experts
Would it be possible to create a query which would show me the stock value per item group in SAP? I know this can be done through Stock Audit report etc, but as we have over 300 item groups I would like to see a report which show me only the group name and the stock value within that group.
Thanks
GeoffHi Gordon,
The 2% will be because in almost all cases the query is using Last Purchase Price to calculate the value, but the stock balance on 130000 account in Financials is being generated from the FIFO values of stock. It is a problem we come up against a lot in calculating stock values - we probably wouldnt have gone down the FIFO route originally had we known!
Regards
Geoff -
Items with zero stock quantity show negative stock value in Stock reports
When running Stock reports for controlling the stock value towards the GL accounts, some items appear with zero stock quantity, but the report still shows a stock value (negative value in my case)
How can this happen, and how can I correct this situation ?
System parameters are : negative stock is not allowed, Items with zero cost price not allowed. On item level average cost price method is used.
P.K.JohnsenHi Johnsen,
I believe you have checked the" Manage Inventory by warehouse". I have noticed this issue in SAP B1 2005B but this is rectified in 2007B. The system behaves in this way as the system maintains item cost for the item for all warehouses and even if the stock is not present in the warehouse, the system would still show you a value for the same. Hope this helps. please search the forum. You'll find related threads.
Thanks,
Joseph -
It still shows confirmed quantity at sales order in case of no stock
Hi,
I have the availability check configuration, but my requirement for 0 confirmed quantities at sales order in case of no stock is not working. That is- It still shows confirmed quantity at sales order in case of no stock. Please suggest.
All the setting for availability check is done. I have set the accumulation as 3 in checking group. But still not working.
Thanks
MauryanDear Mauryan,
ATP check will work if you have already turned on ATP check in the following 3 transactions:
OVZ2
OVZG
OVZ8
You need to turn on ATP at your checking group, requirement class, and schedule line category. If one of them is off, then ATP check will not work. See note 547512, Q1.
Claire -
T-Code for reporting stock quantity difference between IM and WM
Hi All
I'm probably going to kick myself for asking this quastion but is there a report to show the stock quantity differences between IM and WM?
I have searched the forum first but cannot find info.
We have various differences in IM and WM shown in MD04 and LS26. This is usually the result of an unplanned plant to plant transfer not being recipted in at the destination plant.
If no standard T-code is available, which tables can I join to create my own query?
Thanks in advance
Darrencompare MMBE with LS26
Make sure you dont enter a storage location and storage type in selection screen of LS26.
if you post a difference with LI20, then you have just posted a difference within WM, means you moved a quantity from a bin into the difference storate type 998. The balance of both is still equal to your stock shown in MMBE. You have to clear the difference with IM by executing LI21 transaction. Only then the quantity will disappear from difference storage type and will be adjusted in MM and FI.
LX23 will only report real inconstencies and will adjust them.
If you do a MM movement like 303, then this creates a transfer request in WM, this TR needs to be converted into a TO. to move the stock from the bin to the interim storage type for goods issue.
In your case you created just a negative quant in the interim storage type for goods issue and still have a positive quant in the bin, the balance is equal to the stock shown in MMBE. -
Creating Query to show items from open sales orders with a/p invoice
Hi experts,
I am trying to create a query that will show what items/quantities are still in open sales orders that can now be filled by an incoming shipment of goods, processed through the a/p invoice.
This needs to be done using subqueries, which I have no experience with. I am trying to do this using the ORDR and RDR1 tables to show the open items from the sales orders and the OPOR and POR1 tables to show items just received in to inventory. I would like the query to show exactly the open item's, their quantities, the posting date from the sales order and the customer name that can now be filled from the new shipment through the a/p invoice.
I appreciate the assistance,
Hayden (on behalf of Todd)Hello,
try this
SELECT T0.[DocDate], T1.[ItemCode], T1.[Dscription],( T1.[Quantity] - T1.[DelivrdQty]) As "Open Qty" FROM ORDR T0 INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.[DocDueDate] <= [%0]And ( T1.[Quantity] - T1.[DelivrdQty]) != 0
Try this query in query manager.
Thanks
Manvendra Singh Niranjan
Edited by: Manvendra Singh Niranjan on Jul 13, 2011 6:27 AM -
Query that show total discount on A/R Invoice
Dear all,
I would like to have query that show summary of each invoice number that show 'Total of discount' ( 'Total of discount' = total of discount in line item + discount of total invoice ). Data that I would like to show on this query is as follow :
Invoice No, Invoice Date, Customer Code, Total before discount, 'Total of discount', Total Amount, Vat amount
Please kindly suggest the way to get this data.
Thanks you in advanced.
AngnamHi Angnam K,
Try This one...hope this will serve your purpose.
SELECT DocEntry, DocNum, CardCode, CardName, DocDate, [Total Before Discount] , [Totaldiscount]+ [OinvDiscount] as [Total of discount], VatSum [Total Tax] FROM (
SELECT T0.DocEntry,T0.[DocNum], T0.[DocDate], T0.[CardCode], T0.[CardName], SUM(T1.[LineTotal])[Total Before Discount],
SUM(T1.[PriceBefDi] * T1.Quantity *T1.[DiscPrcnt])/100 as [Totaldiscount]
,Case When T0.[DiscPrcnt] <> 0 Then (SUM(T1.[LineTotal])/ T0.[DiscPrcnt]) Else 0 end [OinvDiscount] ,T0.VatSum
FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
Group By T0.DocEntry,T0.[DocNum], T0.[DocDate], T0.[CardCode], T0.[CardName], T0.[DiscSum] ,T0.[DiscPrcnt],T0.VatSum )Sales
thanks,
Kumar
Edited by: itskumaramit on Jul 13, 2011 12:43 PM -
ABAP Query - Not showing the required changes through Z T.Code
Hi,
I have a ABAP Query for OPEN DELIVERY QUANTITY (T.Code - ZABC). I change something in QUERY and activate. After that i execute it, and saw required changes.
But when i execute it with the T.Code - ZABC, it does not show the changes. Even i Save and Test with the SQ01 t.code.
Please tell me, what is the problem in it. Why not showing the required changes through T.Code - ZABC.
Regards...HI,
Dear, it seems that you have changed the query in SQ02 and then just save it and not generated.
or may be after generation again clicked on SAVE button.
So untill unless you will not generate the query, it won't work.
Secondly, by chanegs in the query, i don't think it changes the name of the main program.
Regds,
Anil -
FHMI is updating stock quantity when GR to PO (F)
Dear gurus,
in our system, if i do GR to PO with account assignment N to a material (material type FHMI), it is not updating the stock quantity.
if i do GR to PO with act.assignment F to the same material, it's updating the stock quantity!
the settings for the act.assignment F and N is the same (consumption posting V)
FHMI is quantity updating.
could you show me some clue on why this is the case?
Edited by: Michael Y on Oct 20, 2009 6:25 PM
Edited by: Michael Y on Oct 20, 2009 6:26 PMHi Michael,
Yes, unfortunately, the need for the storage location in this case is hard-coded in the system and I would advise you not to change it:
This depends on a System Table: T156SY: There is a field in this table (XLORT) which states whether the Storage Location is mandatory in a posting or not.
When you post to a material which makes quantity update (MENGU = X) and value update (WERTU =X) with no special stock (SOBKZ = empty), reference to a purchase order (KZBEW = B) and this purchase order is not a stock transport order (KZZUG = empty), you see the following table entries in this table:
(Note: Sorry for the wrong format!!!! but I did not manage to align the table entries here, please, check in your system the right display of the table T156SY with SE16):
BUSTR WERTU MENGU SOBKZ KZBEW KZZUG KZVBR BUSTW BUSTM XLORT
101 X X B WE01 ME01 X
101 X X B A WE06 ME02
101 X X B V WE06 ME02
So, as you see here, the storage location is not needed when you update the consumption (KZVBR = A or V). The storage location is only mandatory when the consumption is not updated.
If, you make the same posting but the material is not valuated (WERTU equals space), you find the following entries:
BUSTR WERTU MENGU SOBKZ KZBEW KZZUG KZVBR BUSTW BUSTM XLORT
101 X B A WE06 ME01 X
101 X B V WE06 ME01 X
So, when the material is not valuated, the system requieres the storage location as mandatory entry (XLORT = X).
The program checks the contents of XLORT, and if the storage location is mandatory and it has not been entered, then sends the error message M7 018. Once the storage location is specified in the posting, the stock is updated in the corresponding table. The consumption is not increased this time.
As mentioned previously, this table T156SY is a system table, so I deeply recommend not to make any change at all in any of the fields of this table. This setting cannot be customized either, and no user exit or BAdI will modify this standard system behavior.
In answer to your second question, if you decide to make your material as no quantity update also, then, as you say, there will be no way in the system to force it to update the quantity later.
I hope this helps you further!
Best regards,
Esther. -
Some of the stock quantity is against un-assigned notes
Hi All,
In material moments cube, when I execute a query, I can see that Stock quantity is exactly matching with R/3 data. When I have Material Group & Material in query, theres a split up in stock quantity. Some of the stock quantity is against un-assigned notes for same material, and some are against material group say IDTI.
Example:
Material stock qty
1235 50
1245 60
Material Group Material Stock Quantity
IDTI 1235 -10
PC 1245 40
1235 60
1245 20
I had followed How to .doc on inventory while populating 0IC_C03.
Please advice on the same .
Thanks
JameelHi Bivu,
Did you some answer on the questions you had?
My client also facing the same kind of issue.
Specially I would like to know, what will be financial Impact, if we ZERO out stock and reload.
Thanks -
Query Requirement for Stock on hand.
Hi All,
Actually I am have written a query for showing a running total for an Item with all Sales Order and Purchase Order order by ship date (due date).
SELECT T0.[ItemCode], T0.[ShipDate],t2.[CardCode],t4.[OnHand],-T0.[OpenQty]*t4.[NumInSale] as StockMovt FROM RDR1 T0 INNER JOIN ORDR T2 ON T0.DocEntry = T2.DocEntry INNER JOIN OITM T4 ON T0.[ItemCode]=t4.[ItemCode] WHERE T0.[ItemCode] =[%0] and T2.[DocStatus] ='o'
UNION
SELECT T1.[ItemCode], T1.[ShipDate],t3.[CardCode], t5.[OnHand], T1.[OpenQty] as StockMovt FROM POR1 T1 INNER JOIN OPOR T3 ON T1.DocEntry = T3.DocEntry INNER JOIN oitm t5 ON T1.[ItemCode]=t5.[ItemCode] WHERE T1.[ItemCode]=[%0] and T3.[DocStatus] = 'o' ORDER BY [ShipDate]
What i require is the additional field which shows the cumulative or running total for each record. Can anyone please help in how it can be achived.
Thanks & Regards
ShivaHi Prasanna,
I made some modification to ur query and its perfectly working. I still have the other query...can you please help me.
The out put that you have asked for is as follows
# ItemCode ShipDate CardCode OnHand StockMovt
1 BAS3B 04.06.09 AUCHRA 14,320.00 -108
2 BAS3B 04.06.09 BLUMER 14,320.00 0
3 BAS3B 04.06.09 GREENTsup 14,320.00 0
4 BAS3B 05.06.09 bizzy 14,320.00 -12
5 BAS3B 05.06.09 BROWNT 14,320.00 -120
6 BAS3B 18.06.09 GOODVI 14,320.00 0
7 BAS3B 26.06.09 COLMAN 14,320.00 -15,000.00
8 BAS3B 30.06.09 GREENTsup 14,320.00 3,000.00
9 BAS3B 21.07.09 GREENTsup 14,320.00 5,000.00
10 BAS3B 03.08.09 BEALES 14,320.00 -12
11 BAS3B 05.08.09 ACORN 14,320.00 -6
12 BAS3B 16.08.09 JLEWBS 14,320.00 -120
13 BAS3B 22.08.09 GREENTsup 14,320.00 1,000.00
14 BAS3B 22.08.09 GREENTsup 14,320.00 2,000.00
15 BAS3B 25.08.09 BEALES 14,320.00 -6
16 BAS3B 25.08.09 GREENTsup 14,320.00 2,000.00
17 BAS3B 27.08.09 BEALES 14,320.00 -6
18 BAS3B 27.08.09 ELIZAS 14,320.00 -24
19 BAS3B 01.10.09 GATES 14,320.00 -120
20 BAS3B 15.01.10 GREENTsup 14,320.00 2,000.00
Further to this I need a running total for the stock movement. Basically it nothing but the difference between the last two columns.
Regards
Shiva -
Can I build a query to show monthly sales by item by business partner?
Hi all
Is it possible to build a query to show monthly sales (quantity not value) by item by business partner?
So the table would look something like this.
Jan Feb Mar Apr
Item 1 10 4 8 7
Item 2 4 3 5 6
Item 3 4 12 9 3
Item 4 1 0 1 2
Etc...
As you can see, the monthly figure needs to be quantity of the item and not sales value.
Would be grateful for any help.
Many thanks.
WendyHi,
Try this:
declare @code as varchar(15)
set @code = ( select max(ta.cardcode) from OINV ta where ta.cardcode = [%0])
Select [a] as Cardcode, [B] as Cardname, [c] as Item#, [D] as Descr,[1] as Jan,[2] as Feb,[3]as Mar,[4] as April,[5] as May,[6] as June,[7] as July ,[8] as Aug,[9] as Sept,[10] as Oct ,[11]as Nov,[12] as Dec
from(
SELECT T0.[CardCode] as A , T0.[CardName] as B, T1.[ItemCode] as C, T1.[Dscription] as D, sum(T1.[Quantity]) as t,month(T0.[DocDate]) as month FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry WHERE year( T0.[DocDate]) = 2014 and t0.cardcode = @code GROUP BY T0.[CardCode], T0.[CardName], T1.[ItemCode], T1.[Dscription],T0.[DocDate] ) S
pivot
(sum(t) for month IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
Thanks & Regards,
Nagarajan -
Stock quantity KF coming as 0 from dso A to another dso B? Please suggest.
We have one reserved stock quantity KF in prod where we are getting the values to 'A' DSO from the x data source in ECC through full update. I mean when ever there is a change to the quantity it will be updated to the A dso, if there is no change nothing will get into the A dso. if mat 1 has new 10 reserved quantity it wll come as 10 and then there is another DSO "B" where its pulling from A to B in delta update. In the B dso its a delta load from A to B. And the problem now is no matter if we have an update to mat 1 or not its pulling the quantity as 0 from A to B DSO. That is in clear scenario, mat 1 is coming as 10 yest which is right and if suppose there is no update to mat 1 today, DSO A has nothing in it which is also right. But B dso is having 0 in it which is wrong.....so this is happening for all the mat 1 .......mat 100 even if there is no quantity update in the DSO A.
For example if we have no update in the DSO A tomorrow, there is no record in DSO A but there is a mat 1 as 0 in DSO B tomorrow.
DSO A is a full update from ECC and DSO B is a delta upload from DSO A to DSO B. So all the material's are coming as 0 even if there is no update in ECC for the reserved quantity in BI. Please suggest me any approach to fix the issue.
My requirement is mat 1 should have 10 in DSO B even today even if there is no delta update. That is it should not replace the earlier/previous reserved quantity to 0 if there is no delta change.
NOTE: If there is any delta update to DSO A -50 after a couple of days, it shows the correct quantity in DSO A as 50 and DSO B as well. But will show the reserved quantity as 0 between the old (10) and new (50) delta loads.
dso B has these values
mat 1- 10 - yesterday
mat 1- 0 -today
mat 1- 0 -next day
mat 1- 50 -after couple of days
dso A has only these
mat 1- 10 -yesterday
mat 1- 50 -after couple of days
requirement in DSO B
mat 1- 10 - yesterday
mat 1- 10 ( since no change) - today
mat 1- 10 (since no change) - next day
mat 1 - 50 ( as new delta has come) - after couple of days
Edited by: Daniel on Mar 29, 2011 1:45 PMHi Daniel,
In Transformation between DSO A-->B, for KF reserved stock quantity the values are in Overwrite.
to check right click on the mapping of KF open Rule Details --> see Aggregation(it will be overwrite).
As per your requirement you can't change to summation also.
So i guess you have to go for ABAP code:
In Rule details set rule type to Routine and write use below code:
(suppose your source field is R_S_QTY)
declare an temp variable is global area.
IF R_S_QTY > '0'.
RESULT= SOURCE-FIELD->R_S_QTY.
Temp_var = RESULT.
ELSE.
RESULT = Temp_var.
ENDIF.
Hope these might resove your issue.
Thanks,
Jitender. -
Stock Quantity at Mc.9 and MMBe is not Matching
Hello,
The stock Quantity for a prticular material in MMBE is not matching with stock qunatitty in MC.9 and Mc.5
Can you please suggest me how to resolve this.
Thanks & Regards,
SAGARHello,,
MMBE is the correct value for the current stock quantity. MC.9 and the other reports use tables S031/S039 or thereabouts, which is updated incrementally each month using the previous month's record and the issues / receipts during the month. Once the file gets corrupted - and it does - in our case about 5% of records are incorrect - that incorrectness is perpetuated in the following months, and the difference remains forever.
You can determine that the S031 record is in error by starting with the current month and looking at the Val stk rec qty and the val stk iss qty movements and the valuated stock, which will allow you to calculate what the stock at the end of the previous period should be. Run MC.9 for the previous period, check the valuated stock corresponds to that calculated, and repeat with the movements. You can do this in yearly periods until you find the error and then go down finer. I find that most of our corruption occurred in the first few months of using SAP.
If anyone knows of a method to regenerate the whole record in the S tables
I would be grateful for the info.
Conclsion:MMBE reads the current stock, while MC.9 or MC.5 are transactions that are feeded from infomation structures (which are updated with lower priority than stock tables). If an update of a infostructure fails, then there is no harm to the stock table update, but your statistics are just out of sync then.
So in short, you can trust MMBE, but no the statistic transactions
Regards
Mahesh Naik.
Maybe you are looking for
-
Printer driver for HP Office Jet P2035n
I need a diver for this printer to work for school. Its the only one left with ink !
-
Can someone please let me know how to change the name of an "Event" in iPhoto. After I import photos and am in the "Last Import" viewer, I click on the event name to change it. Unfortunately it seems I only have about 2.86 nanoseconds to type in a ne
-
140MB of photos in "modified" folder, but didn't modify any of them?
I just recently upgraded to '09. I uploaded my first batch of photos the other day. It was a lot, about 1.4GB from a trip I took. I happened to be looking in the package contents for something else, but stumbled up the modified folder for the photos
-
Ich nutzte heute die Chance, eine Word-Datei (DOC) online von Adobe konvertieren zu lassen. Ich bin über das schlechte Resultat erschüttert. Während ein mitbewerber eine brauchbare Variante lieferte, war die Adobe-Version völlig unbrauchbar. Wie ist
-
i have just purchased elements 12. It will not convert a raw file for me. i have downloaded DNG convertor 8.5 but it says that my Canon 70d is not compatible. I never had a problem with my last camera canon 7d and elments 8. Can someone help me pleas