Stock quantity Aging problem

I have the following query. Execution is taking almost 12-16 hours during month end. Please help me to fine-tune the query.
We have stock table which get updated with latest balance quantity. The quantity should be arrived against stock aging. Receipt table (GRN_DTL) consists all the items receipt till date from 01-jan-2000
Aging range is 0-30, 31-60, 61-90, 91-180 and > 180
The query is :
CREATE OR REPLACE procedure stock_value_aging is
prd_cd varchar2(15);
cl_bal number;
phy_stk number;
p_AGE          NUMBER(15);
p_YEAR_MONTH      VARCHAR2(7);
p_STOCK_QTY      NUMBER(15,2);
p_UNIT_RATE      NUMBER;
p_FINAL_RATE NUMBER(15,2);
p_RANGE VARCHAR2(6);
p_TOTAL_VALUE NUMBER(20,2);
p_DOC_NO VARCHAR2(15);
p_DOC_DATE DATE;
p_DIVISION VARCHAR2(15);
p_ITEM_NAME VARCHAR2(50);
p_cum_accp     number(20,2);
P_CAT_CODE VARCHAR2(5);
P_CAT_NAME VARCHAR2(20);
Cursor STK IS
Select prod_code,phy_stk_qty, ITEM_NAME, DIV_NAME, UNIT_PRICE, CAT_CODE, CAT_NAME from STOCK_DIV_VALUE_VIEW;
--where prod_code='S2402300';
Cursor c1 IS
SELECT A.GRd_NO,A.GRD_DATE, to_date(sysdate,'dd-mon-rr')-to_date(grd_date,'dd-mon-rr') days,
A.ACCP_QTY, C.RANGE
FROM GRN_DTL A,
RANGE_MASTER C
WHERE A.PROD_CODE=prd_cd
AND (to_date(sysdate,'dd-mon-rr')-to_date(grd_date,'dd-mon-rr') BETWEEN AGE1 AND AGE2)
AND GRD_DATE IS NOT NULL
ORDER BY GRd_dATE DESc;
Begin
     DELETE AGE_STOCK_ANALYSIS;
     COMMIT;
Open stk;
Loop
Fetch STK into prd_cd,phy_stk,P_ITEM_NAME, P_DIVISION, P_UNIT_RATE,P_CAT_CODE,P_CAT_NAME;
exit when stk%notfound;
Begin
Open C1;
          Loop
          FETCH C1 INTO P_DOC_NO, P_DOC_DATE, P_AGE, P_STOCK_QTY, P_RANGE;
          EXIT WHEN phy_stk <= 0;
          If phy_stk < p_stock_qty then
               p_stock_qty := phy_stk;
          End if;
          Insert Into AGE_STOCK_ANALYSIS
          values (prd_cd, p_age, nvl(p_stock_qty,0), nvl(p_UNIT_RATE,0),
               nvl(p_stock_qty,0)*nvl(p_unit_rate,0),P_RANGE, p_doc_no, p_doc_date,
                    p_division, p_item_name, P_CAT_CODE,P_CAT_NAME);
          phy_stk := phy_stk - p_stock_qty;
          END LOOP;     
Close C1;
          Commit;
End;
end loop;
Close stk;
End;

I do not see any relatio between the STK and C1 cursors. Are you running a cross product of the cursors?
Shouldn't C1 be a parameterised cursor in this case or?

Similar Messages

  • Reserved stock quantity from MB25 t-code in R/3

    Hello Guyz
    1. I have to extract reserved stock quantity (difference quantity) from t-code MB25 into my Inventory Cube (0IC-C03) in BW.
    2. The user has advised me that the movement type is always '301' and the storage loc. is always '9998'. The problem is, in the cube, when I look at that specific movement type and storage location, I still have multiple records divided into 'material doc. numbers'. 
    3. On the R.3 side, I have the 'Reservation number and its Item' as the key fields.
    4. How can I get my partilcuar KF from this t-code in R/3 into my cube in BW?
    5. My specific question is: The KF exists at the stor. loc. level.. how can I bring it down further at the material doc number level in the cube?
    Regards,
    Atul.

    Very helpful answer Shalini. Thanks. So, I can enhance this extractor 2LIS_03_UM with these 2 fields. Then based on this, I can extract my 'Reserved Quantity' (KF) into 0IC_C03.
    But I notice in R/3 that the 'reservation number and item' are the same for multiple document numbers. ie
    Doc No.----> Reservation No--
    > Item
    100                      ABC                                1
    101                      ABC                                1
    102                      ABC                                1
    103                      ABC                                1
    104                      ABC                                1
    But in MB25, I have
    Reservation No -
    > Item----
    >Diff. Quantity
           ABC                        1                       5000
    How can I extract my KF, if there is a one-many relationship between reservation no and item & material doc number?
    Any suggestions.. anyone??

  • Table for Stock quantity

    Hi all,
    Please tell me the table  which has got stock quantity( field in it) for a certain material.
    Thanks,
    cs

    Hi CS,
    Check out tables MARD , BSIM
    Most material stock data can be located in table MARD. LABST for actual, VMLAB for previos month's stock,
    Hope it will solve ur problem..
    <REMOVED BY MODERATOR>
    Thanks & Regards
    ilesh 24x7
    Edited by: Alvaro Tejada Galindo on Mar 4, 2008 12:41 PM

  • 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 PM

    Hi 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,
    SAGAR

    Hello,,
    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.

  • 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.Johnsen

    Hi 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

  • How to calculate total stock quantity in cube

    Dear Master
        I want to verify the data between BI report and cube whether correct or not.My report name is stock summary. It's giving report for Total quantity stock (0TOTALSTCK) for paricular date. This KF(0TOTALSTCK) inflow is 0RECTOTSTCK and outflow is 0ISSTOTSTCK. Somebody telling to get the Total quantity stock (0TOTALSTCK) value, I have to use following formula 0RECVS_VAL (Value Received into Valuated Stock) - 0ISSVS_VAL (Value issued from valuated stock). Please advice me which formula should I use to get the total stock quantity?.
    Thanks a lot in advance
    Raja

    Please let met understand better, you have the following keyfigures:
    - Receipts (Cumulative)
    - Issues (Cumulative)
    - Difference (Cumulative) populated during URules = Receipts - Issues (any routine with elaborated calculation behind?
    - Stock (non-cumulative InFlow = Receipts, OutFlow = Issues)...
    Is this correct?
    Olivier.

  • How to get Item-Code wise stock quantity and value for a previous date

    Dear Sir,
    As per the government legal requirement , we are required to furnish a list for items having stock as on a date ( date is not the current date but it is some past date)  and  in the list we need to provide material wise stock quantity and value .
    We can generate a list  for the current date , but do not know how to get it for a previous date .
    We request you to kindly guide us about such a list .
    With Thanks and Regards
    Sonia Agarwal

    hi,
    might be this reports will be help full for your requirement.
    MMBE
    MB53
    MB52
    MB5M
    MB5B
    MB5T
    MBLB
    MBBS
    MB54
    ME56
    Thanking you

  • Stock Quantity & Stock Value at vendor on a Particular Date

    HI,
    My client requirement is to get a report for Stock Quantity & Stock Value at vendor on a Particular Date .
    Please give suggestions to get the stock & value in tables or Any standard T.codes
    Note : I am getting Stock qty on paricular date In MB5B & S_P00_07000140 , but not getting the values
    Regards,
    PR

    HI,
    we can get this report thru SAP standard without vendor selection, do the following steps
    1. goto MB5B
    2. Give plant /material details
    3. give selection date
    4. select stock type option as special stock
    5. select special stoct indicator as "O" for material provided to vendor
    excute the same , you will get a report with qty and value posted for  the vendor from the plant
    here by copying this standard program we can add one more input parameter  as vendor, then we can get this report vendorwise also.
    try this and let us know
    Regards
    Sridharan

  • 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
    Darren

    compare 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.

  • Is it possible not to update Product Stock Quantity upon ADD TO CART event?

    Greetings,
    Is it possible that the Product Stock Quantity (In Stock) not to be updated on Add to Cart event or when the basket still exist?
    And the updates/decrease of quantity will only happen when the customer have successfully paid or checked out.

    Not at the moment no. BC removes the item from the system on add to cart.

  • Material on-order stock quantity calculation

    Can anyone tell me the function module or method used by SAP to determine the amount of a material on an open purchase order (not yet received)?  I need to document a BW functional spec but cannot seem to be able to document how SAP does this.
    Examples of what i am looking for are:
    MMBE, on-Order stock quantity (Per material/Plant/Storage Locaiton)
    ME2K, Selection parameters WE103 - Still to be delivered (per PO)
    Thanks.

    Ram
    I have found that function module previously but cannot seem to be able to execute it.
    Import Parameters:
    X_ELIKZ = Blank
    X_LOEKZ = Blank
    X_MATNR = my material number
    X_MEINS = Unit of Measure
    Tables:
    XTAB = <B><U><I>What do I use here?</B></U></I><BR>
    XWERKS = my plant
    No matter what I enter in XTAB (I have tried Blank, EQ, NB so far) I get an ABAP Dump:
    <I><B>The IN itab operator is used with internal tables which have the following structure:
      SIGN(1)   OPTION(2)   LOW LIKE db_field   HIGH LIKE db_field
      The OPTION column should contain only one of the following values:
       "EQ LE GE CP BT NE LT GT NP NB"
    The value 00 is not allowed here.</I></B>
    <BR><BR>
    When analyzing the error, I found table MDBS that conatians the Order Qty and GR quantity - so I think I may be able to use this instead.

  • Negative Values for Stock Quantity in BI

    Dear Experts,
    I have a report based on Inventory Management Multiprovider which is executed to check the Valuated Stock Quantity for single day input entry. ( Valuated Stock Qty is a non cumulative Key figure with Inflow as Quantity Received into Valuated Stock and outflow as Quantity Issued from Valuated Stock )
    So Valuated Stock Qty for a particular day = (Quantity Received into Valuated Stock till that day) - (Quantity Issued from Valuated Stock till that day).  So i think, checking the cube data in BI will not help to resolve the issue.
    Issue: : When I execute the report in BI for some dates I am getting Negative Values for Valuated Stock Quantity which is wrong output.
    Can this issue be resolved by filling set up tables and loading it to BI, say for last month?
    Could you please suggest any other solutions available?
    Also it will be helpful if you could explain what needs to be analyzed in ECC side (with T Codes)
    Thanks in advance
    Vinod

    Hi Vinod,
    try these transactions on the ECC side:
    MMBE to view stock of a material
    MB51 to view all material documents for your selection (i.e. material)
    The business content stock reporting in BW is mainly using datasource 2LIS_03_BF for movements and 2LIS_03_UM for revaluations. For this to work you will have to have all material documents loaded into your cube.
    Also have a look at this How To paper if you haven't yet.
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/f83be790-0201-0010-4fb0-98bd7c01e328
    Best,
    Ralf

  • Inventory Cube Stock Quantity/Value Issue

    Hi Experts,
    I have an issue regarding inventory cube about the stock value and quantity.
    The Issue is:
    1.  I Loaded the 2LIS_03_BX first to initialise the materials opening balance, after compressed ther request with the Marker (checked) .
    2.  I loaded the 2LIS_03_BF with Initialize without data transfer infopackage and compressed in the cube
    3.  And  I did full load 2LIS_03_BF and compressed with check box selected for marker update.
    The issue I have is, when the stock quantity/value  of a material ( BX , for example is taken on Dec.2011) is calculated(non cumulative key figure ex.0VALSTCKVAL/0VALSTCKQTY in the inventory cube) backwards based on Issues and received stock/value of material , I am not getting the value/stock equal to the value when the business started ( i.e for example Dec.2009, time at which the material opening stock is counted and entered in the system).
    example:  When I loaded BX ( intialize opening stock), let us suppose for Material A , have 1000kg in Dec 2011.  When the non cumulative key figure (0VALSTCKQTY/0VALSTCKVAL) is calicualted for each month or day , at the end of the period for example Dec.2009 the stock should be 100, but I am getting more than 100 like 150 for example, even though all the issued,received and 0valstckval/0valstckqty are correct upto Dec.2009.
    am i missing any steps or please let me your thoughts on this one.
    Regards
    Vamsi

    Hi,
    Please follow the steps mentioned in this link.I think 2LIS_03_BX full load should not be compressed with marker update only deltas to be updated in marker table of BF and UM.
    http://wiki.sdn.sap.com/wiki/display/BI/StepbyStepLoadingDatatoInventory+Cube
    Hope it helps.
    Regards,
    AL

  • Report that list stock quantity by product code or stock group

    hi,
    any one has code similar to this logic that lists stock quantity by product code or stock group?
    Thanks & regards
    Ruban

    hi,
    I am closing this thread

Maybe you are looking for