Opening & closing stock like in tally in sql

 i have multiple table . i want to calculate opening and closing stock like in tally in sql with fifo method.
i have make query.
select   dd.Date,dd.VoucherNumber,dd.Name,dd.OpeningBalance OpeningBal,
 dd.OpeningQty,dd.OpeningRate,
InwardQty=sum(case when dd.Amount >0 then dd.Quantity else 0  end), 
InwardRate=sum(case when dd.Amount >0 then dd.Rate else 0  end),
InwardValue= sum(case when dd.Amount >0 then dd.Amount else 0  end),
OutwardQty=sum(case when dd.Amount <0 then dd.Quantity else 0  end ),
OutwardRate=sum(abs(isnull((case when dd.Amount <0 then dd.Amount else 0  end)/ nullif((case when dd.Amount <0 then dd.Quantity else 0 end),0),0))),
OutwardValue=  Sum(abs(case when dd.Amount <0 then dd.Amount else 0  end)),
ClosingQty=dd.OpeningQty+ sum(case when dd.Amount >0 then dd.Quantity else 0  end)-sum(case when dd.Amount <0 then dd.Quantity else 0  end ) ,
closingRate=dbo.fnGetClosingRate(dd.OpeningBalance,sum(case when dd.Amount >0 then dd.Amount else 0  end),
 Sum(abs(case when dd.Amount <0 then dd.Amount else 0  end)),dd.OpeningQty+ sum(case when dd.Amount >0 then dd.Quantity else 0  end)-
  sum(case when dd.Amount <0 then dd.Quantity else 0  end )),
  ClosingAmout=(dd.OpeningQty+ sum(case when dd.Amount >0 then dd.Quantity else 0  end)-
  sum(case when dd.Amount <0 then dd.Quantity else 0  end ))*(dbo.fnGetClosingRate(dd.OpeningBalance,sum(case when dd.Amount >0 then dd.Amount else 0  end),
 Sum(abs(case when dd.Amount <0 then dd.Amount else 0  end)),dd.OpeningQty+ sum(case when dd.Amount >0 then dd.Quantity else 0  end)-
  sum(case when dd.Amount <0 then dd.Quantity else 0  end )))
   from 
   SELECT  [Transaction].Date, [Transaction].VoucherNumber,
   Items.Name,OpeningBalance,ItemOpening.Quantity as OpeningQty,ItemOpening.Rate as OpeningRate,
  SalesItem.FirstQty as Quantity, SalesItem.Rate ,
  SalesItem.Amount 
FROM  ItemOpening INNER JOIN
               Items ON ItemOpening.Items = Items.Oid INNER JOIN
               SalesItem ON Items.Oid = SalesItem.Item INNER JOIN
               Sales ON SalesItem.Source = Sales.Oid INNER JOIN
         [Transaction] ON Sales.Oid = [Transaction].Oid 
        --where [Transaction].Date>='2012-05-19' and [Transaction].Date<='2012-05-31'
        --and Items.Name='Bidi: 96/19x20x80 HL'
        -- group by Items.Name,[Transaction].Date,SalesItem.Rate,
        -- SalesItem.Amount
            union all
   select  [Transaction].Date,[Transaction].VoucherNumber, Items.Name,
   OpeningBalance,ItemOpening.Quantity as OpeningQty,ItemOpening.Rate as OpeningRate,
   PurchaseItem.FirstQty   ,
   PurchaseItem.Rate,
PurchaseItem.Amount 
FROM  PurchaseItem INNER JOIN
Purchase ON PurchaseItem.Source = Purchase.Oid INNER JOIN
Items on Items.Oid= PurchaseItem.Item inner join 
ItemOpening on ItemOpening.Items= Items.Oid inner join
[Transaction] ON Purchase.Oid = [Transaction].Oid
--where [Transaction].Date>='2012-05-18' and [Transaction].Date<='2012-05-31'
--and Items.Name='Bidi: 96/19x20x80 HL'
) as dd  where   dd.Date>='2012-04-01' and dd.Date<='2012-04-05'
and dd.Name='Bidi: 96/19x20x80 HL'
 group by dd.Date,dd.VoucherNumber,dd.Name,dd.OpeningBalance,dd.OpeningQty,dd.OpeningRate,dd.Rate
  order by dd.Date
but it is not give correct output. its giving result .
Date
Name
OpeningBal
OpeningQty
OpeningRate
InwardQty
InwardRate
InwardValue
OutwardQty
OutwardRate
OutwardValue
ClosingQty
closingRate
ClosingAmout
4/1/2012
A
62909.22
22
2859.51
0
0
0
10
3584.8
35848
12
2255.1
27061.2
4/5/2012
A
62909.22
22
2859.51
0
0
0
20
3584.8
71696
2
-4393.39
-8786.78
4/5/2012
A
62909.22
22
2859.51
20
3360
67200
0
0
0
42
3097.84
130109.28
expected format as
Date
Name
OpeningBal
OpeningQty
OpeningRate
InwardQty
InwardRate
InwardValue
OutwardQty
OutwardRate
OutwardValue
ClosingQty
closingRate
ClosingAmout
4/1/2012
A
62909.22
22
2859.51
0
0
0
10
3584.8
35848
12
2255.1
27061.2
4/5/2012
A
27061.2
12
2255.1
0
0
0
20
3584.8
71696
-8
0
-8786.78
4/5/2012
A
-8786.78
-8
-4393.39
20
3360
67200
0
0
0
12
3097.84
130109.28
please give solution

Suppose my  view like View_itm
Date
Item
openingItem
OpnRate
OpnAmt
ReceiveItm
Issue
ClosingQty
closingRate
ClosnigAmt
1/4/2012 
A
10
5
15
5
2
13
23.1
299
1/4/2012 
B
20
2
40
10
15
15
43
643
i have make above query for access data  but it not give expected result 
Date
Name
OpeningBal
OpeningQty
OpeningRate
InwardQty
InwardRate
InwardValue
OutwardQty
OutwardRate
OutwardValue
ClosingQty
closingRate
ClosingAmout
4/1/2012
A
62909.22
22
2859.51
0
0
0
10
3584.8
35848
12
2255.1
27061.2
4/5/2012
A
62909.22
22
2859.51
0
0
0
20
3584.8
71696
2
-4393.39
-8786.78
4/5/2012
A
62909.22
22
2859.51
20
3360
67200
0
0
0
42
3097.84
130109.28
expected result need like 
Date
Name
OpeningBal
OpeningQty
OpeningRate
InwardQty
InwardRate
InwardValue
OutwardQty
OutwardRate
OutwardValue
ClosingQty
closingRate
ClosingAmout
4/1/2012
A
62909.22
22
2859.51
0
0
0
10
3584.8
35848
12
2255.1
27061.2
4/5/2012
A
27061.2
12
2255.1
0
0
0
20
3584.8
71696
-8
0
-8786.78
4/5/2012
A
-8786.78
-8
-4393.39
20
3360
67200
0
0
0
12
3097.84
130109.28
please give solution as per possible 

Similar Messages

  • Storage location wise Opening/Closing Stock on posting date (mb5b)

    Hi,
    Report mb5b gives opening stock and closing stock as on date. In the selection screen, if we do not enter specific storage location then the opening/closing stock is displayed as sum of all storage location stocks for a given material.
    Where as if we enter storage location, it gives storage location specific output. (with Storage loc/batch stock radio button)
    My requirement is - without entering storage location in the initial screen, the system should display storage location specific opening/closing stock.
    To get this, presently I need to execute mb5b transaction individually for every storage location.
    Warm regards,
    MS

    Hi Madhavi
    This report you can have in T code MC.6 and another t code for opening and closing stock in t code MC.9
    Regards
    Vivek
    -- Reward if helpful
    Edited by: Supergene on Feb 28, 2008 3:17 PM

  • Opening & Closing Stock in transit

    Hi All,
    I Developed an abap report for Yield Statement with opening & closing Stock Quantities.
    How to Find opening & Closing For transit Stock for 641 movement.I mean how to display the current transit stocks date wise at plant level without SLOC.
    I Knew that current transit stock would be in Marc Table & previous closings in March Tables.
    I'm looking for the date logic with respect to displaying opening & closing dates of transit stock.Be it Date Wise Or Month Wise.
    Any help would be greatly appreciated.
    Thanks & Regards,
    Ravi S

    Hi Ravi,
    Please find the Link below hope they are very useful to you
    [Stock|Re: closing stock of a particular date]
    [Stock|Tables/FM for opening/closing stock for material on given posting date]
    Thanks
    kalyan

  • Tables/FM for opening/closing stock for material on given posting date

    Hi All,
    I had requirement of find the opening/closing stock for material on given posting date. The values we can find out using TCode - MB5B.
    But I cannt use MB5B to extract data because I need to find detials for thousands of material.
    Can you please adivce if their is any FM or tables through which i can find this detial on any given date apart from current date.
    Thanks & Regards,

    Hi,
    [https://forums.sdn.sap.com/click.jspa?searchID=19631709&messageID=6593903]
    [https://forums.sdn.sap.com/click.jspa?searchID=19631709&messageID=6630975]

  • How to get Opening /Closing stock value of Non Valuated stock materails

    Hello,
    We would like to know since 95% of our procurement will be for Projects and since the stock is u201CNon-Valuatedu201D stock, is there any method by which we will be in a position to get the  details of Opening Stock, Purchases & Closing Stock?
    Regards
    Sapman man

    hi
    try mb52
    enter maerial type for nonvaluated stock
    then
    execute
    you will  get output
    regards
    vijay

  • Opening & Closing Stock in P&L Statement

    Dear All,
    My client is using Tally software preior to SAP B1 Implementation. In Tally the P/L satatment shows  Opening Stock , purchases and  Closing Stock ledgers.We are not using Purchase Accounts posting system. How to map the existing SAP Ledgers  according to Tally. We are using SAP B1 2007 B.
    Please help me to map the G/L accoring to the above requirements.
    Thanks
    Srini

    Dear Srini,
    Yes of-course Tally shows OB,and Closing balance at a particular time, SAP B1 Shows them too, but in a different manner.
    1. Suppose , you have given OB to SAP on 01/04/10.(which is actually the closing balance of Tally as on 31/03/10).
        Under trial balance report OB Column is there.
         If you are trying to populate Tally's OB of 01/04/09, You Can't.
    2. Getting the OB at a particular time in SAP, depends how you are maintaining your Posting Periods.
    For Closing balance in SAP, The last column -'Balance' is actually the Closing balance as on the date for you are running Trial Balance Report.
    Hope this will help you.
    Best Regards
    Ashutosh T

  • Opening Closing Stock in transit Report

    Hi,
    I have to get the ABAP development of Stock Report. Report would have following fields
    Opening Stock
    Opening Stock in Transit Quantity
    GR Quantity
    Purchase Value
    Sold Quantity
    Rejection Quantity
    Closing Quantity
    Closing Stock in Transit Quantity
    Consumption Quantity
    In Closing quantity , It should be without stock in transit quantity.
    Could you please help me to understand ,Exact Opening Stock ,Closing sock, In Transit Stock etc? How would these be calculated? from which tables all these data would come from. Thanks in advance.
    Regarda,
    Santosh

    SantoshArya wrote:
    Hi,
    >
    > I have to get the ABAP development of Stock Report. Report would have following fields
    >
    > Opening Stock
    > Opening Stock in Transit Quantity
    > GR Quantity
    > Purchase Value
    > Sold Quantity
    > Rejection Quantity
    > Closing Quantity
    > Closing Stock in Transit Quantity
    > Consumption Quantity
    >
    > In Closing quantity , It should be without stock in transit quantity.
    >
    > Could you please help me to understand ,Exact Opening Stock ,Closing sock, In Transit Stock etc? How would these be calculated? from which tables all these data would come from. Thanks in advance.
    > Regarda,
    > Santosh
    Hi,
    You can also check these standard reports before you proceed to develop a report..
    MB52 - List of Warehouse Stocks on Hand
    MB53 - Display Plant Stock Availability
    MB5B - Stocks for Posting Date
    MB5C - Pick-Up List
    MB5L - List of Stock Values: Balances
    MB5W - List of Stock Values
    MB5T - Stock in transit CC
    MC.9 - INVCO: Material Analysis Selection, Stock
    MC.A - INVCO: Material Analysis Selection, Rec/Iss
    MC.B - INVCO: Material Analysis Selection, Turnover
    You can also consider building a query report which wil also serve your purpose quickly...
    Regards
    Shiva

  • Storage location wise opening, closing stock...date wise...report

    Hi all Experts,
    I am at client site and hav to provide a report containing opening, and closing stock (and issue qty if possible) storage location wise and date option wise.pls help
    regards
    vikas chhabra

    Hi,
    Use MB51 for date wise report
    OR
    Use MCL1, MCL5, MCL9, MCLD (If Warehouse Management you are using)
    OR
    You have to develop an own ABAP report.
    Regards,
    Biju K

  • Opening & closing stock

    Hi Expert,
        I am developing one zreport . i want to know how to calculate
    opening and closing stock using mb5b standard report.
    Thanks
    Dinesh

    Hi,
    I would be really thankful if you could send me a couple of z_reports with the input parameters and output parameters, as we too are going for implementation project. Kindly send it to [email protected]
    Your help would really be appreciated.
    Regards.

  • Crystal Query for Opening / Closing Stock

    Hi Experts,
    i need a query in crystal for Opening and Closing total Stock per date..
    i found this querys and need to join them, but o dont now how...
    thanks for any tips..
    Query 1
    =======================
    SELECT  distinct
    T0.[TransType], T0.[DocDate],  T0.[InQty], T0.[OutQty], T0.[Dscription], T0.[CalcPrice], T0.[ItemCode] FROM [dbo].[OINM]  T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode WHERE T0.[DocDate] >= {?DateInicial} and  T0.[DocDate] <= {?DateFinal} and T1.[Canceled] = 'N'
    Query 2
    =========================
    Declare @FromDate Datetime
    Declare @ToDate Datetime
    select @FromDate = min(S0.Docdate) from dbo.OINM S0 where S0.Docdate >={?Data1}
    select @ToDate = max(S1.Docdate) from dbo.OINM s1 where S1.Docdate <={?Data2}
    Select a.Itemcode, max(a.Dscription) as ItemName,
    sum(a.OpeningBalance) as OpeningBalance, sum(a.INq) as 'IN', sum(a.OUT) as OUT,
    ((sum(a.OpeningBalance) + sum(a.INq)) - Sum(a.OUT)) as Closing ,(Select i.InvntryUom from OITM i where i.ItemCode=a.Itemcode) as UOM
    from( Select N1.Itemcode, N1.Dscription, (sum(N1.inqty)-sum(n1.outqty))
    as OpeningBalance, 0 as INq, 0 as OUT
    From dbo.OINM N1

    try this
       Declare @ItmsGrpNam varchar(100)
    Declare @Whse nvarchar(10)
    Declare @Fromdate Datetime
    Declare @Todate DateTime
    select @FromDate = min(S0.Docdate) from dbo.OINM S0 where S0.Docdate >=[%0]
    select @ToDate = max(S1.Docdate) from dbo.OINM s1 where S1.Docdate <=[%1]
    select @Whse = Max(s3.Warehouse) from dbo.OINM S3 Where S3.Warehouse = [%2]
    Select  a.Itemcode, max(a.Dscription) as ItemName,
    (Select i.InvntryUom from OITM i where i.ItemCode=a.Itemcode) as UOM,
    sum(a.OpeningBalance) as OpeningBalance,
    ((sum(a.OpeningBalance) + sum(a.INq)) - Sum(a.OUT)) as Closing
    from( Select  N1.Itemcode, N1.Dscription, (sum(N1.inqty)-sum(n1.outqty))
    as OpeningBalance, 0 as INq, 0 as OUT From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
    inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod
    Where N1.DocDate < @FromDate and N1.Warehouse = @Whse and  b.ItmsGrpNam = @ItmsGrpNam
    Group By N1.ItemCode,
    N1.Dscription Union All select N1.Itemcode, N1.Dscription, 0 as OpeningBalance,
    sum(N1.inqty) , 0 as OUT From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
    inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod
    Where N1.DocDate >= @FromDate and N1.DocDate <= @ToDate
    and N1.Inqty >0  and N1.Warehouse = @Whse and  b.ItmsGrpNam = @ItmsGrpNam Group By N1.ItemCode,N1.Dscription
    Union All select  N1.Itemcode, N1.Dscription, 0 as OpeningBalance, 0 , sum(N1.outqty) as OUT
    From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
    inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod
    Where N1.DocDate >= @FromDate
    and N1.DocDate <=@ToDate and N1.OutQty > 0 and N1.Warehouse = @Whse and  b.ItmsGrpNam = @ItmsGrpNam
    Group By N1.ItemCode,N1.Dscription) a, dbo.OITM I1 ,OITB b1
    where a.ItemCode=I1.ItemCode
    and I1.ItmsGrpCod = b1.ItmsGrpCod
    Group By a.Itemcode ,I1.ItmsGrpCod , b1.ItmsGrpNam 
    Having sum(a.OpeningBalance) + sum(a.INq) + sum(a.OUT) > 0
    Order By a.Itemcode 

  • Opening & Closing Stock - Query Correction

    Dear Experts,
                             Please find the below query, where I need IN quantity & values , OUT quantity& values should  pick only from  Standard Production Order , whereas  it should not pick from special Production Order. Rest all in the same is sufficient for me.
    Declare @FromDate Datetime
    Declare @ToDate Datetime
    Declare @ItmsGrpNam varchar(100)
    select @FromDate = min(S0.Docdate) from dbo.OINM S0 where S0.Docdate >= '[%0]'
    select @ToDate = max(S1.Docdate) from dbo.OINM s1 where S1.Docdate <='[%1]'
    select @ItmsGrpNam = max(s2.ItmsGrpNam) from dbo.OITB S2 Where S2.ItmsGrpNam ='[%2]'
    Select  a.Itemcode, max(a.Dscription) as ItemName,
    (Select i.InvntryUom from OITM i where i.ItemCode=a.Itemcode) as UOM,
    sum(a.OpeningBalance) as OpeningBalance,
    sum(a.OpeningValue) as OpeningValue,
    sum(a.INq) as 'IN',
    (select SUM(ISNULL(T100.TRANSVALUE,0)) from oinm T100 WHERE T100.ITEMCODE = A.ITEMCODE
    AND T100.DOCDATE >= @FROMDATE
    AND T100.DOCDATE <= @TODATE AND T100.INQTY <> 0) AS [IN Stock Value],
    sum(a.OUT) as OUT,
    (select SUM(ISNULL(T100.TRANSVALUE,0)) from oinm T100 WHERE T100.ITEMCODE = A.ITEMCODE
    AND T100.DOCDATE >= @FROMDATE
    AND T100.DOCDATE <= @TODATE AND T100.OUTQTY <> 0)*-1 AS [OUT Stock Value],
    ((sum(a.OpeningBalance) + sum(a.INq)) - Sum(a.OUT)) as Closing ,
    (select SUM(T100.TRANSVALUE) from oinm T100 WHERE
    T100.ITEMCODE = A.ITEMCODE AND T100.DOCDATE < @TODATE) AS [Closing Value Transaction],
    (((sum(a.OpeningBalance) + sum(a.INq)) - Sum(a.OUT))*
    ISNULL((SELECT CASE WHEN
    X.PRICE = 0
    THEN
    (SELECT DISTINCT MAX(ISNULL(P.PRICE,0)) AS PRICE FROM ITM1 P WHERE PRICELIST = 1 )
    ELSE
    X.PRICE
    END
    FROM (SELECT
    DISTINCT MAX(ISNULL(B.PRICE,0)) AS PRICE
    FROM OITM T
    LEFT JOIN PCH1 B ON T.ITEMCODE = B.ITEMCODE
    INNER JOIN OPCH C ON B.DOCENTRY = C.DOCENTRY
    WHERE B.DOCENTRY =  (SELECT DISTINCT (MAX(D.DOCENTRY)) FROM OPCH D WHERE C.DOCENTRY = D.DOCENTRY
    AND C.DOCDATE <= @ToDate )
    AND A.ITEMCODE = T.ITEMCODE) X ),0))
    --(Select i.LstEvlPric from OITM i where i.ItemCode=a.Itemcode))
    as 'Closing Value',
    (Select i.LastPurDat from OITM i where i.ItemCode=a.Itemcode) as 'Last Purchase Date',
    --(Select i.LstEvlDate from OITM i where i.ItemCode=a.Itemcode) as 'Last Issue Date',
    --(Select i.ItmsGrpCod from OITM i where i.ItemCode=a.Itemcode) as 'Group code',
    (Select b.ItmsGrpNam from OITB b where  b.ItmsGrpCod = I1.ItmsGrpCod) as 'Group Name'
    from( Select  N1.Itemcode, N1.Dscription, (sum(N1.inqty)-sum(n1.outqty))
    as OpeningBalance,
    (sum(N1.Transvalue))
    as OpeningValue,
    0 as INq, 0 as OUT From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
    inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod
    Where N1.DocDate <@FromDate and b.ItmsGrpNam = @ItmsGrpNam
    Group By N1.ItemCode,N1.Dscription
    Union All
    select N1.Itemcode, N1.Dscription, 0 as OpeningBalance,0 as OpeningValue,
    sum(N1.inqty) , 0 as OUT From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
    inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod
    Where N1.DocDate >= @FromDate and N1.DocDate <= @ToDate
    and N1.Inqty >0  and b.ItmsGrpNam = @ItmsGrpNam
    Group By N1.ItemCode,N1.Dscription
    Union All
    select  N1.Itemcode, N1.Dscription, 0 as OpeningBalance,0 as OpeningValue, 0 , sum(N1.outqty) as OUT
    From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
    inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod
    Where N1.DocDate >= @FromDate and N1.Transtype != 67
    and N1.DocDate <=@ToDate and N1.OutQty > 0 and  b.ItmsGrpNam = @ItmsGrpNam
    Group By N1.ItemCode,N1.Dscription) a, dbo.OITM I1 ,OITB b1
    where a.ItemCode=I1.ItemCode
    and I1.ItmsGrpCod = b1.ItmsGrpCod
    Group By a.Itemcode ,I1.ItmsGrpCod , b1.ItmsGrpNam 
    Having sum(a.OpeningBalance) + sum(a.INq) + sum(a.OUT) > 0
    Order By a.Itemcode
    Thanks in Advance,
    Bhoopathi.K

    Hi,
    Try this:
    Declare @FromDate Datetime
    Declare @ToDate Datetime
    Declare @ItmsGrpNam varchar(100)
    select @FromDate = min(S0.Docdate) from dbo.OINM S0 where S0.Docdate >= '[%0]'
    select @ToDate = max(S1.Docdate) from dbo.OINM s1 where S1.Docdate <='[%1]'
    select @ItmsGrpNam = max(s2.ItmsGrpNam) from dbo.OITB S2 Where S2.ItmsGrpNam ='[%2]'
    Select  a.Itemcode, max(a.Dscription) as ItemName,
    (Select i.InvntryUom from OITM i where i.ItemCode=a.Itemcode) as UOM,
    sum(a.OpeningBalance) as OpeningBalance,
    sum(a.OpeningValue) as OpeningValue,
    sum(a.INq) as 'IN',
    (select SUM(ISNULL(T100.TRANSVALUE,0)) from oinm T100 WHERE T100.ITEMCODE = A.ITEMCODE
    AND T100.DOCDATE >= @FROMDATE
    AND T100.DOCDATE <= @TODATE AND T100.INQTY <> 0) AS [IN Stock Value],
    sum(a.OUT) as OUT,
    (select SUM(ISNULL(T100.TRANSVALUE,0)) from oinm T100 WHERE T100.ITEMCODE = A.ITEMCODE
    AND T100.DOCDATE >= @FROMDATE
    AND T100.DOCDATE <= @TODATE AND T100.OUTQTY <> 0)*-1 AS [OUT Stock Value],
    ((sum(a.OpeningBalance) + sum(a.INq)) - Sum(a.OUT)) as Closing ,
    (select SUM(T100.TRANSVALUE) from oinm T100 WHERE
    T100.ITEMCODE = A.ITEMCODE AND T100.DOCDATE < @TODATE) AS [Closing Value Transaction],
    (((sum(a.OpeningBalance) + sum(a.INq)) - Sum(a.OUT))*
    ISNULL((SELECT CASE WHEN
    X.PRICE = 0
    THEN
    (SELECT DISTINCT MAX(ISNULL(P.PRICE,0)) AS PRICE FROM ITM1 P WHERE PRICELIST = 1 )
    ELSE
    X.PRICE
    END
    FROM (SELECT
    DISTINCT MAX(ISNULL(B.PRICE,0)) AS PRICE
    FROM OITM T
    LEFT JOIN PCH1 B ON T.ITEMCODE = B.ITEMCODE
    INNER JOIN OPCH C ON B.DOCENTRY = C.DOCENTRY
    WHERE B.DOCENTRY =  (SELECT DISTINCT (MAX(D.DOCENTRY)) FROM OPCH D WHERE C.DOCENTRY = D.DOCENTRY
    AND C.DOCDATE <= @ToDate )
    AND A.ITEMCODE = T.ITEMCODE) X ),0))
    --(Select i.LstEvlPric from OITM i where i.ItemCode=a.Itemcode))
    as 'Closing Value',
    (Select i.LastPurDat from OITM i where i.ItemCode=a.Itemcode) as 'Last Purchase Date',
    --(Select i.LstEvlDate from OITM i where i.ItemCode=a.Itemcode) as 'Last Issue Date',
    --(Select i.ItmsGrpCod from OITM i where i.ItemCode=a.Itemcode) as 'Group code',
    (Select b.ItmsGrpNam from OITB b where  b.ItmsGrpCod = I1.ItmsGrpCod) as 'Group Name'
    from( Select  N1.Itemcode, N1.Dscription, (sum(N1.inqty)-sum(n1.outqty))
    as OpeningBalance,
    (sum(N1.Transvalue))
    as OpeningValue,
    0 as INq, 0 as OUT From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
    inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod
    Where N1.DocDate <@FromDate and b.ItmsGrpNam = @ItmsGrpNam
    Group By N1.ItemCode,N1.Dscription
    Union All
    select N1.Itemcode, N1.Dscription, 0 as OpeningBalance,0 as OpeningValue,
    sum(N1.inqty) , 0 as OUT From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
    inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod
    Where N1.DocDate >= @FromDate and N1.DocDate <= @ToDate
    and N1.Inqty >0  and b.ItmsGrpNam = @ItmsGrpNam
    Group By N1.ItemCode,N1.Dscription
    Union All
    select  N1.Itemcode, N1.Dscription, 0 as OpeningBalance,0 as OpeningValue, 0 , sum(N1.outqty) as OUT
    From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
    inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod left join OWOR t0 on t0.docentry = N1.[AppObjAbs]
    Where N1.DocDate >= @FromDate and N1.Transtype != 67
    and N1.DocDate <=@ToDate and N1.OutQty > 0 and  b.ItmsGrpNam = @ItmsGrpNam and  T0.[Type] = 's'
    Group By N1.ItemCode,N1.Dscription) a, dbo.OITM I1 ,OITB b1
    where a.ItemCode=I1.ItemCode
    and I1.ItmsGrpCod = b1.ItmsGrpCod
    Group By a.Itemcode ,I1.ItmsGrpCod , b1.ItmsGrpNam 
    Having sum(a.OpeningBalance) + sum(a.INq) + sum(a.OUT) > 0
    Order By a.Itemcode
    Thanks & Regards,
    Nagarajan

  • Calculating Opening / Closing Stock of a day

    Hi,
    I will be thankfull if any one can give us solution for calculating Inventory of a item  on a particulare given day. If some one has came across same situation please revert ASAP.
      Regards
    Anubhav

    Hi
    Have you looked at the table oinm? This has all stock transactions whether they are coming into the system or out of the system.
    Hope this helps

  • Opening closing stock receipts and issues analysis

    Hi,
    Is it possible to match the values in the MC.A (Total Receipts and Issues Values) to Gl Accounts,
    If it is possible How?

    Hi,
    from within the MC.A there is a link directly to the accounting documents that are involved.
    Go to the menu option Extras > accounting doc for material when you have the data for a material displayed.
    By careful and make sure that you have selected the correct flag on the values window of the initial selection screen.
    Steve B

  • Stock Statement - Opening & Closing Values

    Hi Guys,
    I am using the below query for  opening & Closing Stock Report.
    select a.ItemCode,a.Des, a.WareHouse , (SELECT (sum(t1.inqty - t1.outqty))
    FROM OINM t1 
    WHERE (T1.DocDate < '[%1]') and (t1.itemcode = a.itemcode) and
    (t1.warehouse = a.whs) ) as 'OB',
    a.Price,a.inqty as 'Goods Receipt',a.outqty as 'Goods Issue',
    (SELECT (sum(t1.inqty) - sum(t1.outqty))
    FROM OINM t1  
    WHERE (T1.DocDate <= '[%2]') and
    (t1.itemcode = a.itemcode) and (t1.warehouse = a.whs)) as 'Closing',
    (SELECT (sum (t1.transvalue))
    FROM OINM t1  
    WHERE (T1.DocDate <= '[%2]') and (t1.itemcode = a.itemcode) and
    (t1.warehouse = a.whs)) as 'ClosingValue'
    from (SELECT max(T0.[ItemCode]) as 'ItemCode',
    max(T0.[Dscription]) as 'Des',sum(T0.[InQty]) as 'InQty', sum(T0.[OutQty]) 'OutQty',
    t0.warehouse as 'whs' ,
    (select w1.whsname from owhs w1 where w1.whscode = t0.warehouse) as 'Warehouse',
    avg(T0.[Price]) as 'Price'
    FROM OINM T0 
    inner join oitm o1 on o1.itemcode = t0.itemcode
    inner join oitb o2 on o2.itmsgrpcod = o1.itmsgrpcod 
    WHERE (T0.[DocDate] >= '[%1]' and  T0.[DocDate] <= '[%2]')  and
    (TransType != '10000071'  and Transtype !='67' ) and
    (o2.itmsgrpnam >= '[%3]' and o2.itmsgrpnam <= '[%4]' )
    group by T0.[ItemCode],t0.warehouse)a
    But i need some changes in the Report and  below is the selection criteria,
    Pls somebody help me in achieveing this.
    Report 1:
    Item Group: Group B
    u2022 Column: Goods Issue
    Field to be fetched: Invoice Qty. for the respective FG items
    From Ware House No.: 02
    Fetching type: Cumulative for given date range
    u2022 Column: Goods Receipt
    Field to be fetched: Receipt from Production for FG items
    Receipt Warehouse: 02
    Fetching type: Cumulative for given date range
    Report 2:
    For Item Groups- Accessories, Consumables & Raw materials:
    Column: Goods Issue
    Issue from Warehouse No.: 08 ,33
    Field to be fetched: Issue for Production (BoM qty-Back-flush & Manual issue by system)
    Fetching type: Cumulative for given date range
    Column: Goods Receipt
    Receiving Warehouse No.: 08 ,33
    Field to be fetched: GRPO qty. against respective Purchase Order.
    Fetching type: Cumulative for given date range
    Report 3:
    For Item Group-WIP
    Column: Goods Issue
    Issue from Warehouse No: 04,09,17,18,20,21,23,28,29,30,31,32,34,38,39,44,45,46
    Fields to be fetched: All types of issues ( Issue for prodn. through Prodn.order, GI &
    Inventary Transfer)
    Fetching type: Cumulative for given period.
    Column: Goods Receipt
    Receiving Warehouse Nos:04,09,17,18,20,21,23,28,29,30,31,32,34,38,39,44,45,46
    Fields to be fetched: All types of Receipt (Receipt from Prodn. through Prodn.order, GR )
    Fetching Type: Cumulative for given period.
    Regards,
    Vamsi

    Dear Srini,
    Yes of-course Tally shows OB,and Closing balance at a particular time, SAP B1 Shows them too, but in a different manner.
    1. Suppose , you have given OB to SAP on 01/04/10.(which is actually the closing balance of Tally as on 31/03/10).
        Under trial balance report OB Column is there.
         If you are trying to populate Tally's OB of 01/04/09, You Can't.
    2. Getting the OB at a particular time in SAP, depends how you are maintaining your Posting Periods.
    For Closing balance in SAP, The last column -'Balance' is actually the Closing balance as on the date for you are running Trial Balance Report.
    Hope this will help you.
    Best Regards
    Ashutosh T

  • Day wise Closing stocks for the given month

    Hi,
    Please suggest me your valuable ideas for Closing Stocks Calender day wise for the given month.
    Ex : User Input 03.2013 , now report has to show daywise closing stock like below
                                            01.03.2013    140 MT
                                             02.03.2013     150 MT
                                              31.03.2013    230 MT.

    I like recursive with clause B-)
    with rec(StaV) as(
    select extract(day from date '2011-01-01')
      from dual
    union all
    select StaV+1
      from rec
    where StaV+1 <= extract(day from last_day(date '2011-01-01')))
    select ListAgg('''' || to_char(StaV) || '''',' ')
           within group(order by StaV) as days
    from rec;
    DAYS
    '1' '2' '3' '4' '5' '6' '7' '8' '9' '10' '11' '12' '13' '14' '15' '16' '17' '18' '19' '20' '21' '22' '23' '24' '25' '26' '27' '28' '29' '30' '31'

Maybe you are looking for

  • Open Items Table

    hi experts Table name for Open Items data. Thanks Keshavp. Search SDN

  • MBP 2012 - connecting to Imac 27" 2011

    Hi, Planning on buying the new MBP 2012 with Retina.  Wondering if I can connect it to my Imac 27" via thunderbolt and access the USB 3.0 of the Macbook?  In other words, I would connect a USB 3.0 card reader (Compact Flash, XQD etc.)  on the MBP  bu

  • ASA PAT UDP source port

    Is there a way to preserve the source port for UDP packets that use a PAT pool? Here is what I need: The client (1.1.1.1) sends a UDP packet from port 5060 to port 5060 on our external 2.2.2.2. This packet is port forwarded to our internal server 10.

  • Problème pot de peinture

    Bonjour à tous, J'ai réinstallé mon Photoshop CS5 sous Windows 8.1 et paf, le problème. Ça fait 15 ans que je bosse sur photoshop, autant dire que je ne suis pas un débutant. Mais je ne vois pas. Je ne travaille qu'en aplats. Quand j'utilise le "pot

  • Task Switcher goes crazy

    Hi, sometimes my MacBookPro Unibody, 3.06GHz, seem to freeze. If I hit Command-Tab, the Taskswitch-Board opens buts scrolls constantly through all applications until I hit command-tab again. Can this issue be caused by an hardware issue, or tis there