Storing and calculating sales per item

The case: We have a item, on that item we have a fee. If the item has sold more than 1000 copies, the fee will drop. Therefor i need to have a place that calculates/stores total sales per item. This can then be used to set the fee when i run my stored procedure
for sales etc. 
Database explained shortly: 
The sales database looks like this: 
ItemID, SalesDate, Quantity, Name.
Example: 
1399, 2014-01-01, 2, Fompa.
1081, 2014-01-01, 13, Asddd. 
1399, 2014-01-03, 1, Fompa. 
Etc. 
The item database looks like this: 
ItemID, Name, Author, etc
Now my boss asked me if i maybe should add total sales to the item database, but how is that possible? 
I have also tried to gather all items and show the total sales, but something goes wrong, the itemID are not grouping together..
here is the query: select ItemID, QUANTITY from BOOK_SALES group by ItemID, QUANTITY order by MAX(quantity) DESC
If i get this query right, is it possible to store the query within a database table? 

Hey, thanks for a fast answer. 
I modified your query a little, 
select
itemid, sum(quantity) from book_sales group by
itemid order by MAX(quantity) DESC
but still, all of the itemIDs are not being grouped together. 
Results show something like this: 
1399, 981
1081, 344
1399, 199
etc..

Similar Messages

  • Sales per item report

    hello experts
    i have made the following query but i dont want to display double and triple times values per itemcode
    i actually want to display the sum the quantity and the sum of the linetotal per item
    SELECT
    --T0.CardName
    -- T0.ShipToCode
    -- T0.DocDate
    T1.ItemCode
    , T1.Dscription
    , sum(T1.Quantity)
    , T1.LineTotal AS 'u0391u03BEu03AFu03B1 u03C0u03CEu03BBu03B7u03C3u03B7u03C2'
    --, T2.CardCode
    FROM OINV T0 
    INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
    INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
    INNER JOIN OSLP T3 ON T0.SLPCODE=T3.SLPCODE
    WHERE
    --(T0.CardName >= [%0] or [%0] = ' ')
    --and (T0.CardName<= [%1] or [%1] = ' ')
    --and (T0.ShipToCode >= [%2] or [%2] = ' ')
    --and (T0.ShipToCode <= [%3] or [%3] = ' ')
    (T2.CardCode = '80503')
    --and (T2.CardCode = [%4] or [%4] = ' ')
    AND (T0.DOCDATE BETWEEN '2011-10-01' AND '2011-10-25')
    --AND (T0.DOCDATE BETWEEN '[%5]' AND '[%6]')
    --and (T0.CANCELED= 'N')
    --and ((T3.SLPNAME BETWEEN '[%7]'AND '[%8]') OR ('[%7]'=' ' AND  '[%8]'=' '))
    group by T0.CardName,  T0.DocDate, T1.ItemCode, T1.Dscription, T1.Quantity, T1.LineTotal, T2.CardCode
    order by T1.ItemCode
    60344     test item1      1.000000     0.880000
    60360     test item2      1.000000     1.500000
    60360     test item2      1.000000     1.500000
    60360     test item2             2.000000     3.010000
    60361     test item3             2.000000     3.010000
    do you have any idea?
    thanks in advance for your time!

    HI
    try this:
    SELECT
    --T0.CardName
    -- T0.ShipToCode
    -- T0.DocDate
    T1.ItemCode
    , T1.Dscription
    , sum(T1.Quantity)
    , T1.LineTotal AS 'u0391u03BEu03AFu03B1 u03C0u03CEu03BBu03B7u03C3u03B7u03C2'
    --, T2.CardCode
    FROM OINV T0 
    INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
    INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
    INNER JOIN OSLP T3 ON T0.SLPCODE=T3.SLPCODE
    WHERE
    --(T0.CardName >= [%0] or [%0] = ' ')
    --and (T0.CardName<= [%1] or [%1] = ' ')
    --and (T0.ShipToCode >= [%2] or [%2] = ' ')
    --and (T0.ShipToCode <= [%3] or [%3] = ' ')
    (T2.CardCode = '80503')
    --and (T2.CardCode = [%4] or [%4] = ' ')
    AND (T0.DOCDATE BETWEEN '2011-10-01' AND '2011-10-25')
    --AND (T0.DOCDATE BETWEEN '[%5]' AND '[%6]')
    --and (T0.CANCELED= 'N')
    --and ((T3.SLPNAME BETWEEN '[%7]'AND '[%8]') OR ('[%7]'=' ' AND  '[%8]'=' '))
    group by T0.CardName,  T0.DocDate, T1.ItemCode, T1.Dscription, T1.LineTotal, T2.CardCode
    order by T1.ItemCode

  • Storing and calculating with big matrixes

    Hello,
    we will have to store big matrixes (let's say 3000 x 3000, numeric) and will also multipy matrix a with matrix b.
    I would like to get some advice for storing matrixes, and how to do the calculation efficiently.
    Have anybody done such things?
    thx
    Tobias

    In order to operate on matrices efficiently, you're going to want to load them from database tables into in PL/SQL arrays, so that you can operate entirely in memory. 3000x3000x4bytes per integer = 36MB, which is probably about on the limit of what you'd want to store in the database UGA.
    PL/SQL doesn't support two-dimensional arrays, so you'll need to use a one-dimensional array of one-dimensional arrays. That's pretty much equivalent, but makes the syntax a bit clumsy.
    There's bound to be Java code out there for operating with matrices (calculating determinants, multiplying, etc) so you could load those classes into the database, and save yourself the bother of writing a lot of the PL/SQL.
    c/PGA/UGA - more accurate.
    Message was edited by:
    marnold

  • New sales order and Change sales order in item level or delete at item leve

    I got one requirement. Daily i have to display one report on new sales orders created on that day and any sales order item is modified or any item is deleted or any item is added.
                      How to get the sales order numbers and position numbers which will follow above creteria. I found one function module but it is not giving position numbers and new sales order details.
             Is there any BAPI for this requirement.

    I am using "CHANGEDOCUMENT_READ" function module to get the new sales orders created and changed sales order items on a particular time. This function module is getting data from CDHDR and CDPOS tables. But only change sales orders is coming. New sales orders which is created on that time is not getting.
              One of my friend is telling like we have to activate one change pointer to retrive new sales orders also. Which is like there will be one check box.
    Is any body having idea on this. Please reply me on briefly with the code to retrive new sales orders and changed sales orders

  • Partial delivery per item in sales order and ATP - schedule lines

    Hi,
    I've problem regarding ATP- schedule lines and partial delivery flag.
    In sales order there is flag Partial delivery per item B / 1 . That means create only one delivery even with quant 0. That comes from customer master or customer info-record and it is OK.
    Please look at next example.
    Customer requires:
    10 PCS of materail A on date X. Only 5 PCS are available on date X.
    10 PCS of material B on date X 0 PCS are available on date X, 10 PCS are available on date Y.
    So if we create outbound delivery on date X it will contain only 5 PCS of material  A. No successive deliveries will be created for material A because of the flag B/1. That item is closed.
    Problem is with material B.
    The sales order will be open because of material B and on date Y we can easily create another delivery with 10 PCS of mat B.
    That is wrong. Agreement with customer is only one delivery for ALL items in sales order. If we create delivery on date X it should contain only materials which are available on date X and sales order should close.
    Do you know how to fix this problem?

    Hi,
    I've think you didn't understand my requirement. I allways get schedule lines but they are confirmed on different dates.
    Example in same sales order we have:
    Schedule line for item A:
    DATE X confirmed quantity 10
    Schedule line for an item B.
    DATE X confirmed quanitity 0 (zeroe)
    DATE Y confirmed quantity 10.
    I would like to create outbond delivery on date X with:
    item A quantity 10
    item B quantity 0.
    And if that hapens than B/0 rule will work or reference customzing that you suggested before. So order will be closed because all items are processed or referenced once.
    Do you know how to do that?
    Regards

  • Sales Analysis query per item group summarized per BP Group

    Dear experts,
    My client is requiring me to create a query that when i select a certain item group it returns a sum/total of sold items in that group per BP group
    format:
    parameter: Item Group A
    BP Group A    1,000
    BP Group B    2,000
    BP Group C   1,000
    I have managed to get total sales per BP Group but i cant seem to figure how to break it down per Item Group
    here is my query:
    SELECT T2.[GroupCode], SUM(ISNULL(T0.Debit,0) - ISNULL(T0.Credit,0)) as "Amount(LC)" FROM JDT1 T0  INNER JOIN OJDT T1 ON T0.TransId = T1.TransId and T0.TransType IN (13,14)
    INNER JOIN OCRD T2 ON T2.CardCode = T0.ShortName
    WHERE T1.[RefDate]  BETWEEN [%0] and [%1]
    GROUP BY T2.[GroupCode]
    how can I link Item Groups to JDT1?

    Hi Carlo
    Try This
    SELECT t5.ItmsGrpNam AS ItemGroup,
       t7.GroupName AS BPGroup,
       SUM(ISNULL(T0.Debit,0) - ISNULL(T0.Credit,0)) AS "Amount(LC)"
    FROM JDT1 T0
    INNER  JOIN OINV T1 ON T0.transid = T1.transid
    LEFT OUTER JOIN INV1 T3 ON T1.docentry = T3.docentry
    LEFT OUTER JOIN oitm T4 ON t4.itemcode = T3.itemcode
    LEFT OUTER JOIN oitb T5 ON T4.ItmsGrpCod = T5.ItmsGrpCod
    INNER  JOIN ocrd T6 ON T0.ShortName = T6.CardCode
    INNER JOIN OCRG T7 ON t7.GroupCode=t6.GroupCode
    WHERE T1.DocDate BETWEEN [%0] AND [%1]
    GROUP BY t5.ItmsGrpNam,
       t7.GroupName
    Rgds

  • Net price calculation for a sales order item

    I am sending the input to BAPI_SALESORDER_CREATEFROMDAT2 for a sales order item with a customer expected price and the material number (pricing group is not being filled in). When the sales order is generated, I see that net price is different from the expected price and the price is being obtained based on the material number that is being given as input. I want to know at what point of code the net price is calculated?  I tried to debug and see but with the numerous userexits and BADIs in the calls I am not successful yet. Any input is appreciated.

    It goes through different pricing routines but the start will be in function module 'PRICING'. Put a break point and run your BAPI or go to tcode VOK0 - find the condition and routines.
    Pricing will be calculated based on customer and material.
    Previous answer is pretty good, you need to fill item conditions in table in bapi also header conditions if you are using header pricing.
    Anyways, first of all create your order from VA01 and see the netprice in conditions. again, the pricing will also depends upon region of customer and material.

  • Interest calculation on Open items and cleared items

    Dear Experts
    I am trying to do needful configuration for interest indicator on which interest can be calculated for open items and cleared items as well.  But,  system is calculating interest for open items properly, but not calculating interest on cleared items with same interest indicator,  I am repeatedly getting error "interest calculation indicator is not compatible with this type of interest calculation"
    Is it possible to use same interest indicator for open line items and cleared line items of customer?
    If possible, request you share the needful config steps to do same.
    points will be awarded for usful reply.
    Best regards,
    S. Habib Pasha.

    Hello Habib,
    depending on the requests you can setup a item interest calculation or a balance interest calculation "Define calculation types".
    IIC: check settings (item selection, all cleared items, only items with payment, no cleared items) "Prepare item interest calculation"
    I guess you have setup the item interest calculation - maybe you have mixed some entries with BAIC.
    Check in "Prepare account balance interest calculation" whether you have entries with the indicator you want to use.
    At least check your entries in "Define time-based Terms" If you have entries with Balance account interest calculation the system gives even an error.
    Hope this is helpfull.
    Best regards
       Horst

  • Sales order item report based on results analysis key and status

    Hi,
    I am trying to find a a report to generate list of sales order items with following selection
            -invoicing status -invoiced/not invoices (other status)
            -result analysis key assigned to this item (VBAP-ABGRS)
            -system status /released/teco
    Basically i am CO consultant and not so familiar with the SD statuses. I tried VA05 and V.26 but all required selections are not available in these reports.
    If no standard report is available in ERP, i would like to have it in BI. Can some help me with table fields for statuses.
    Thanks in advance.
    Regards
    Raghu

    Hi Raghu
    Go to SE16 and give VBUK table and execute it there you can select the following feilds and then check wheather they are meeting your requirements or not.If they are meeting your requirements then create a new Z report by copying standard VA05 key feilds. and include the other feilds which you need.So you take your ABAP team help
    Billing status     FKSTK
    Posting Status  BUCHK
    Overall status  GBSTK
    Document category VBTYP
    Regards
    Srinath

  • Reg Open sales order item and the quantity

    Hi experts:
    I am getting open sales order item based on inner join of tables(vbak, vbap, vbep). Not using vbbe table in inner join as it doesnt carry all pending open records.
    can any one say how open sales order items  and their quantity can be retrieved?
    I searched forum and saw usage of vbuk and vbup tables, but it does not accomplish our scenario.
    Thanks in advance,
    Sashti.

    Hi,
    1) fetch the header information from VBAK table.
    2) Based on VBAK table fetch all the line items from VBAP table.
    3) Now fetch from VBFA table.
    *-Fetch from VBFA to get the delivered qty
      SELECT vbelv               " Preceding sales and distribution document
             posnv               " Preceding item of an SD document
             rfmng               " Referenced quantity in base UOM
        FROM vbfa
        INTO TABLE lt_vbfa
         WHERE vbelv   = gv_vbeln
           and vbtyp_n = 'J'.
    4) By comparing VBFA-POSNR just filter the records from the VBAP internal table. Remained lines are open lines of the sales order.
    Regards,
    ~Satya

  • Sale Order Item Level Text Field which table and field

    Hi,
    Thanks for your prompt reply and best solution.
    Can you please tell me one more thing, in sale order at item level the TEXT Field maintaining by user at transaction level now they want that field in one of the report, so can you please tell what is the table and field where i will get this sale order item level text details.

    Hello,
    is this going to work for item level text as well.
    can you tell how to proceed with this functional module
    or is there any other thing required.Please elaborate to
    understand better way.
    You can check out two table in respect to Sales TEXT i.e. STXH (STXD SAPscript text file header) and STXL(SAPscript text file lines).
    The best approach of tracing out the Text in respect to Sales Order would be to use the Function module READ_TEXT and put this FM in SE37 and execute with the following parameter.
    Client
    Text ID of text to be read
    Language of text to be read
    Name of text to be read
    Object of text to be read
    Archive handle
    Text catalog local
    When you are essentially looking to read item level Text with respect to Sales Order then your Text OBject would be VBBP.
    Regards,
    Sarthak

  • EK01 and EK02 not copied to sales order item

    Dear colleagues,
    Is it possible to have EK01/EK02 transferred to the sales order item for assembly type = "0 no assembly order processing"
    (specified in requirement class definition)? I would like to have planned production costs in EK02/EK01.
    I don't specify costing method, variant and sheet in requirement class definition (transaction ovzg)
    The steps are following:
    1. create sales order
    2. set manually proper item category (which refers to assembly type = "0 no assembly order processing")
    3. MD04 - convert generated planned order (lower-level for HALB) into production order
    4. MD04 - release HALB production order
    5. MD04 - convert generated planned order (higher-level for FERT) into production order
    6. MD04 - release FERT production order
    7. ????? we could expect EK02/EK01 in sales order item coming from production orders ?????
    I have found SAP note 857299 nevertheless it is not stated precisely there.
    Please let me know your observations in this area.
    Regards,
    Wojtek

    Hi..
    Hi
    Small change in the program will copy the PO number from Contract to sales order.In case need take help of ABAPer
    Data which is not copied
    LOCAL: VBKD-FKDAT.
    LOCAL: VBKD-FPLNR.
    LOCAL: VBKD-WKWAE.
    LOCAL: VBKD-WKKUR.
    LOCAL: VBKD-DELCO.
    LOCAL: VBKD-BSTKD.
    LOCAL: VBKD-ABSSC.
    LOCAL: VBKD-BSTDK.
    In your data declaration, you have
    LOCAL: VBKD-BSTDK
    Regds
    MM

  • How can i capture sales order items in C# and pass them to a BAPI?

    Hi everybody,
    here is another novice question for you.
    What control should i use in Visual Studio to allow the user to enter sales order items (material and qty) as a table on the screen and then put these items on a table and call the BAPI to create an order?.
    I've tried using a Datagrid and set the "edititemindex" as "1" but doesn't work.
    Any help will be greatly appretiated.
    thank you
    Javier ...

    Dear Todd,
    thanks for your reply. I'm using ASP. I tried a grid but i cannot seem to make it work, it doesn't appear at first because it's empty, i tried creating some blank rows but the same happens.
    The other thing i tried just to test is to create a row on the table "partners" to pass the needed "AG" (sold to party) and its number and the BAPI keeps returning an error "Please enter Sold ot or Ship to party". Like if the table was empty. Is there any special way to send a table to a BAPI ?. I'm sending it by ref, and i'm creating the record by first creating a structure, filling it an then calling the ADD method of the table and passing the structure. I'm i missing something here?
    Please Help, it's been days with this problem,
    I'll appreatiate it very much
    Best regards and have a great day.
    Javier ..

  • Create additional field in sales order item and copy to purchase order item

    Dear SAP Gurus,
    I am hoping that someone could help me by providing me with how to implement the following 2 requirements in the SD order and in the purchase order.
    1. I am wanting to add a custom field to the SD sales order item copying a value from the vendor customer master.
    2. I then want to add a custom field to the purchase order item and copy the value from my custom field in 1. to this new custom field..
    Can you please advise how I would go about implementing the above requirements?  I am assuming that there are exits to allow me to implement these 2 requirements.
    Many thanks
    Henry

    Hi,
    For the first requirement you can use the USEREXIT_MOVE_FIELD_TO_VBAP in report MV45AFZZ.
    For the second, as I think that you will create a RFQ you can try to use the enhancement MEREQ001.
    Regards,
    Eduardo

  • How to add three fields in Sales order item level and supress/hide many

    Hi Gurus,
    My client requirement is :
    1. Three fields to be added at Sales order Item level and they should flow till billing.
    2. Supress/hide most of the fields in Sales order, so that end user will be happy( thru SHDO how to do)
    Please share your experiences and help me.
    BEST REGARDS
    Srikanth

    Hi Subba Rao
    in VA01 screen - Material /qty/ after entering this client wants to enter three more details say X/Y/Z
    and after that he dont want to see maximum fields displayed in VA01 Screen.
    I think it makes sense.
    Regards
    Srikanth

Maybe you are looking for