Query monthly sales by BP and item code
I am new to the forum and have only a basic training in sql, but hopefully someone can help - I am after a query that shows the total volume sales by customer and item (i.e. Jun, Jul, Aug etc). I have searched the forum and found several queries which come close to what I need but none are exactly my requirement. I need to be able to enter the from and to dates as variables.
Many thanks
Hi,
Try this query:
Declare @fromdate as datetime
Declare @Todate as datetime
Declare @Code as nvarchar(25)
set @fromdate = ( select min(Ta.[docDate]) from inv1 ta where Ta.[docDate] >= [%0])
set @Todate = ( select max(Tb.[docDate]) from inv1 tb where Tb.[docDate] <= [%1])
set @code = (select max(Tc.[cardName]) from OINV tC where Tc.[cardName] = [%2])
SELECT [Name] as Itemcode,[C] as Customername, [Jan]= sum([1]), [Feb]= sum([2]), [Mar]= sum([3]), [Apr]= sum([4]), [May]= sum([5]), [June]= sum([6]), [July]= sum([7]), [Aug]= sum([8]), [Sept]= sum([9]), [Oct]= sum([10]), [Nov]= sum([11]), [Dec]= sum([12]), total = sum (isnull([1],0)+ isnull([2],0) + isnull([3],0) + isnull([4],0) + isnull([5],0) + isnull([6],0) + isnull([7],0) + isnull([8],0) + isnull([9],0)+ isnull([10],0) + isnull([11],0) + isnull([12],0))
from
(SELECT T0.itemcode as Name, t2.cardname as C, t1.quantity
* t1.price [stock_value], month(T1.[docDate]) as month FROM OITM T0 INNER JOIN INV1 T1 ON T0.itemcode = T1.itemcode INNER JOIN OINV T2 ON T1.docentry = T2.docentry WHERE T1.[docDate] between @fromdate and @todate and T2.[cardName] = @code GROUP BY T0.itemcode,T1.[docDate],t2.cardname,t1.quantity, t1.price ) S
Pivot
(sum([stock_value]) For Month IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
group by [Name],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[C]
Thanks & Regards,
Nagarajan
Similar Messages
-
How to send Sales Document Number and Item to BAPI_ACC_DOCUMENT_POST?
Hello SAPients,
We are using BAPI_ACC_DOCUMENT_POST to create an accounting document similar to what FB01 does, in FB01 you can type the number and position of a Sales Document even if you are using an Account Receivable account number. But in the BAPI, the ACCOUNTRECEIVABLE table doesn't have a field to include those numbers. How should I pass the sales order number and item to the BAPI? I have tried several things but every time I receive more complicated error messages.
Thank you in advance for your kind help.Let me know if you have any questions:
Loop through your records and fill in the appropriate structure based on record type (GL, Vendor or Customer)
IF NOT pcard_post_rec-zlsapac IS INITIAL.
gt_gl_item-itemno_acc = ls_posnr.
gt_gl_item-gl_account = pcard_post_rec-zlsapac.
gt_gl_item-comp_code = pcard_post_rec-zlsapco.
"gt_gl_item-pstng_date = pcard_post_rec-zlgpsdt.
gt_gl_item-pstng_date = gv_posting_date.
gt_gl_item-doc_type = doctype.
gt_gl_item-alloc_nmbr = ls_assignment.
gt_gl_item-ref_key_3 = pcard_post_rec-zlgvend.
IF pcard_post_rec-zlsapac < 500000.
gt_gl_item-item_text = ''.
ELSE.
gt_gl_item-item_text = pcard_post_rec-zlguser.
ENDIF.
gt_gl_item-costcenter = pcard_post_rec-zlsapcc.
gt_gl_item-orderid = lv_ordnum.
APPEND gt_gl_item.
ELSEIF NOT pcard_post_rec-zlsapven IS INITIAL.
gt_ap_item-itemno_acc = ls_posnr.
gt_ap_item-vendor_no = pcard_post_rec-zlsapven.
gt_ap_item-comp_code = pcard_post_rec-zlsapco.
gt_ap_item-alloc_nmbr = ls_assignment.
gt_ap_item-ref_key_3 = pcard_post_rec-zlgvend.
IF pcard_post_rec-zlsapac < 500000.
gt_ap_item-item_text = ''.
ELSE.
gt_ap_item-item_text = pcard_post_rec-zlguser.
ENDIF.
APPEND gt_ap_item.
ELSEIF NOT pcard_post_rec-zlsapcus IS INITIAL.
gt_ar_item-itemno_acc = ls_posnr.
gt_ar_item-customer = pcard_post_rec-zlsapcus.
gt_ar_item-comp_code = pcard_post_rec-zlsapco.
gt_ar_item-alloc_nmbr = ls_assignment.
gt_ar_item-ref_key_3 = pcard_post_rec-zlgvend.
IF pcard_post_rec-zlsapac < 500000.
gt_ar_item-item_text = ''.
ELSE.
gt_ar_item-item_text = pcard_post_rec-zlguser.
ENDIF.
APPEND gt_ar_item.
ENDIF. -
Sales order doc and item fields in customer line item report(FBL5N)
Hi All,
We have some billing documents and the accounting docs are created as well. However, in the FBL5N report, we are not able to display the sales order doc and item info even though the columns are avaliable in the layout.
Anyone can help?
Thanks,
TeoHiya,
You said you had the Order/Sales Doc field on the layout already.
Have you ever been able to view the Order? All I can view is the Billing Doc, and I would think that is logical, since the Order is not the immediately prceeding document for the Accounting Doc. The Accounting Doc is created off the Billing Doc and that is what is updated in BSEG. The Sales Order is not updated in BSEG (I haven't seen that happen).
In the event of a GR into stock posting, the Product Cost Collector or PO is the immediately preceeding document and hence updated in BSEG.
Cheers. -
Free form partner function field in Sales document header and item..
Hello Experts,
Is there anyway we can use the partner functions functionality in Sales document header and item level, so that we can enter a free form number in the Partner field? I mean is it possible to be able to enter a free form number WITHOUT getting validated against corresponding master data like Customer or Vendor master, Contact person, Personnel or User master records?Hi,
It is not possible.
Because partner function will be determined in the sales document header and item as per the configuration you have done in the partner determination.
It is not possible to enter a number wihich is not created and assigned.
Regards,
Mullairaja -
Mass maintenance of Sales orders,or/and items
Hi friends
Need some help.
Is there a transaction in SAP by which we can reject large numbers of sales orders, or/and items in sales orders in a mass maintenance way.
We dont want to use MASS or VA05.HI
Being an SD consultant if u know about how to record transactions in LSMW or BDC
it will be very useful
for exampl like if u want to create condition records for 12000 maaterials if u create lsmw and do recording u rwork will be easy
if u dont know about LSMW or BDC
just sit with u r abapper and ask him to do LSMW also u try to learn
it is not mandatory but having an idea about LSMW and BDC or SCAT will be more useful
regards -
BP Catalog numbers and Item Codes Display
Hello
Is there any way that BP catalog numbers and item codes can be display together.
Or is there any work around available.
I have a client who wishes to use i.e view both the item code and the BP Cat Number on their screen..,
we create a formatted search and this worked.
However the purchase orders which are automattically generated through another Add-on cant use a formatted search to work.
Thanks for your help in advance.
DDear Darpal,
Kindly check note 1059015 which describes the workaround to display both Item Number and the Business Partner.
Regards,
Varun
SAP Business One Forum Team -
Linking Sales Order Header and Item into a DSO
I am trying to combine my Sales Order Header and Item into a DSO.
I created individual DSOs for each extractor and loaded successfully. I then created a new DSO with the Document number as the key field and loaded the data. However, when I check the new DSO, the data is not combined but seperated on one line.
To make it clearer
DSO1
CH1 CH2 CH3 KF1
DSO2
CH1 CH4 CH5 KF2
In my new DSO3, I used CH1 as the key field and when I load data, I expect to see
CH1 CH2 CH3 CH4 CH5 KF1 KF2
But I get
CH1 CH2 CH3 KF1
CH1 CH4 CH5 KF2
Is there something I'm doing wrong?Hi Siggi
I'm not sure what you mean.
What I am trying to achieve on the long run is to combine Sales Order and Billing into a cube. But first i need to get the orders into a DSO and also Billing into another DSO. And then combine into a consolidated DSO before going to a cube. Please correct if this approach is wrong.
In the meantime, I am trying to combine the sales order item and header into one DSO. -
Field sales related tables and Transaction code
Dear SAPGurus,
I have been working with field sales activities in mySAP CRM..
Can I have the list of the tables and transaction code related to Field sales sales activies..
I am grateful for ur help....
I would like to appreciate u by rewarding the points
Thanks a lotHi Pratik Patel,
Thank u very much for sending the table names.They are all very useful unto me
Can I have the more table in this area
If u have the CRM Data model and its relationship...Pls share with me..
I appreciate ur help by rewarding the points
Regards,
CRM Consultant -
Query to display BOMs Header and Item
Hello SAP gurus
I am trying to create a query to display BOMs with header and item. For that I am using tables MAST, STKO and STPO.
The table join is:
MAST -> STKO -> STPO
MAST - WERKS, STLNR and STLAL
STKO - STLNR and STPOZ
The system dont show anything...
Can someone help me?
Thanks in advance.
Adelmo SilvaYes, it works but...
If I have 2 alternatives, the system show everything even if i select alternative 1 or 2.
I am missing something... because system is showing all alternatives...
System is showing something like this:
Material BOM AltBOM BOM St Item ICt Component Valid from Quantity Un
726121012 00131075 1 01 0010 L 109219 17-12-2007 0,200 KG
726121012 00131075 1 01 0020 L 109230 17-12-2007 0,003 KG
726121012 00131075 1 01 0030 L 109232 17-12-2007 1,166 M2
726121012 00131075 1 01 0040 L 726004012 17-12-2007 0,120 M3
726121012 00131075 1 01 0010 L 109526 17-12-2007 0,200 KG
726121012 00131075 1 01 0020 L 109232 17-12-2007 1,166 M2
726121012 00131075 1 01 0030 L 726004012 17-12-2007 0,120 M3
Edited by: Adelmo Silva on Jan 9, 2008 9:07 AM -
How to make pricing field as output only in sales order header and item lev
Hi ,
I want to make the field PRICING DATE as output only both at header and item level. How can i do pls guide me in detail.
Regards
SunainaHi Sunaina ,
Through User Exit you get this requirement plese take help of ABAPer to activate the user exit according to your requirement.
Try With this User Exit
Program MV45AFZZ
USEREXIT_FIELD_MODIFICATION
This user exit can be used to modify the attributes of the screen fields.
To do this, the screen fields are allocated to so-called modification groups 1 - 4 and can be edited together during a modification in ABAP. If a field has no field name, it cannot be allocated to a group.
The usage of the field groups (modification group 1-4) is as follows:
Modification group 1: Automatic modification with transaction MFAW
Modification group 2: It contains 'LOO' for step loop fields
Modification group 3: For modifications which depend on check tables or on other fixed information
Modification group 4: is not used
The FORM routine is called up for every field of a screen. If you require changes to be made, you must make them in this user exit.
This FORM routine is called up by the module FELDAUSWAHL.
See the Screen Painter manual for further information on structuring the interface.
I hope it will help you,
Regards,
Murali. -
When I create an new item and assign it to an item group and also a warehouse, what takes precedence with regards to the G/L account codes? Many Thanks,
HI Ciara
Can you please elaborate your question?
Thanks
Abhishek Shanbhogue -
To get service order from sales order number and item number
The select on AUFK takes much longer time than the transaction which is used to get the sevice order number starting from VA03. ( select one line item. goto repairs, then select the repairs column and goto SM Order). Is there any other table than AUFK from which i can get service order number.
Hi!
Check, if you have an entry in table VBFA for your sales order (sales order in VBELV, POSNV, AUFK in VBELN and POSNN, VBTYP_N might be 'C').
If so, your select will be much faster by using VBFA.
Regards,
Christian -
Hello,
We are looking for a Query that will show all of our items and monthly sale by Qty and Amt. This includes items that do not have sales for that month - those fields would just be left blank.
So, header would be...
Item #...Jan Qty...Feb Qty...Mar Qty...etc...Jan Amt...Feb Amt...etc...
Does anyone know a Query that can do this?
Sales analysis will just show only items that have sold.
This is similar to Queries we have asked for in the past that shows all items.
Thanks!
Mikecreo que nececitan algo como esto:
DECLARE @FECHAINI DATE = '2015-01-01';
DECLARE @FECHAFIN DATE = '2015-02-28';
DECLARE @sql nvarchar(MAX) = '';
DECLARE @columns_1 nvarchar(MAX) = '';
DECLARE @columns_2 nvarchar(MAX) = '';
SET @columns_1 = STUFF(
SELECT DISTINCT
',Piezas_Mes' + cast( MONTH(DocDate) as varchar) + '_año_' + cast( YEAR(DocDate) as varchar)
FROM
(SELECT DocDate FROM OINV where DocDate BETWEEN @FECHAINI AND @FECHAFIN) AS P
FOR XML PATH('')
), 1, 1, '');
SET @columns_2 = STUFF(
SELECT DISTINCT
',Monto_Mes' + cast( MONTH(DocDate) as varchar) + '_año_' + cast( YEAR(DocDate) as varchar)
FROM
(SELECT DocDate FROM OINV where DocDate BETWEEN @FECHAINI AND @FECHAFIN) AS P
FOR XML PATH('')
), 1, 1, '');
SET @sql = N'
select
Z.PRODUCTO,
Z.DESCRIPCION,
' + @columns_1 + ',' + @columns_2 + N'
from
select
FROM
SELECT
a.ItemCode AS PRODUCTO,
a.Dscription AS DESCRIPCION,
''Piezas_Mes'' + cast( MONTH(b.DocDate) as varchar) + ''_año_'' + cast( YEAR(b.DocDate) as varchar) AS MES,
a.Quantity AS CANTIDAD
FROM INV1 AS a
INNER JOIN OINV AS b
ON a.DocEntry=b.DocEntry
INNER JOIN OCRD AS c ON b.CardCode = c.CardCode
WHERE b.DocType = ''I'' AND b.DocDate BETWEEN ''' + CAST( @FECHAINI AS VARCHAR) + ''' AND ''' + CAST( @FECHAFIN AS VARCHAR) + '''
UNION ALL
SELECT
d.ItemCode AS PRODUCTO,
d.Dscription AS DESCRIPCION,
''Piezas_Mes'' + cast( MONTH(e.DocDate) as varchar) + ''_año_'' + cast( YEAR(e.DocDate) as varchar) AS MES,
(d.Quantity * -1) AS CANTIDAD
FROM RIN1 AS d
INNER JOIN ORIN AS e
ON d.DocEntry = e.DocEntry
INNER JOIN OCRD AS f ON e.CardCode = f.CardCode
WHERE e.DocType = ''I'' AND e.DocDate BETWEEN ''' + CAST (@FECHAINI AS VARCHAR) + ''' AND ''' + CAST( @FECHAFIN AS VARCHAR) + '''
) as TABLADATOS
pivot
SUM(TABLADATOS.CANTIDAD) for TABLADATOS.MES IN(' + @columns_1 + N')
) as P
) as Z
inner join
select
from
SELECT
a.ItemCode AS PRODUCTO,
a.Dscription AS DESCRIPCION,
''Monto_Mes'' + cast( MONTH(b.DocDate) as varchar) + ''_año_'' + cast( YEAR(b.DocDate) as varchar) AS MES,
a.LineTotal AS TOTAL
FROM INV1 AS a
INNER JOIN OINV AS b
ON a.DocEntry=b.DocEntry
INNER JOIN OCRD AS c ON b.CardCode = c.CardCode
WHERE b.DocType = ''I'' AND b.DocDate BETWEEN ''' + CAST( @FECHAINI AS VARCHAR) + ''' AND ''' + CAST( @FECHAFIN AS VARCHAR) + '''
UNION ALL
SELECT
d.ItemCode AS PRODUCTO,
d.Dscription AS DESCRIPCION,
''Monto_Mes'' + cast( MONTH(e.DocDate) as varchar) + ''_año_'' + cast( YEAR(e.DocDate) as varchar) AS MES,
(d.LineTotal * -1) AS TOTAL
FROM RIN1 AS d
INNER JOIN ORIN AS e
ON d.DocEntry = e.DocEntry
INNER JOIN OCRD AS f ON e.CardCode = f.CardCode
WHERE e.DocType = ''I'' AND e.DocDate BETWEEN ''' + CAST( @FECHAINI AS VARCHAR) + ''' AND ''' + CAST( @FECHAFIN AS VARCHAR) + '''
) as TABLADATOS
pivot
SUM(TABLADATOS.TOTAL) for TABLADATOS.MES IN (' + @columns_2 + N')
) as P
) as Y
on Z.PRODUCTO = Y.PRODUCTO and Z.DESCRIPCION = Y.DESCRIPCION
order by
PRODUCTO,
DESCRIPCION;';
EXEC sp_executesql @sql;
SALUDOS ... -
We have all the Item Code with 6 digit with a leading zero..(e.g. 030351, 030201). I want to write a query or a formatted search on item code where i can just type put the item code without '0' (e.g. 30351) and it will convert in to original item code (030351)
i have written code...
if len(itemcode) = 5 then
select [RDR1.ITEMCODE] = REPLICATE(ITEMCODE),0,6)
is this right? Can you help me with this?Hello,
The correct is:
declare @ItemCode nvarchar(max)
set @ItemCode = (select $[$38.1.0])
select case when Len(@ItemCode) < 6 then
(select right(replicate('0',6)+@ItemCode,6))
else
(select @ItemCode)
end
Regards,
J -
How to header and item data of sales order using bapi interface
hi friends,
i am geetha, i having a problem like how to upload sales oder header and item data through va01 tcode using BAPI FUNCTION MODULES.
i need bapi function modules for header adn item data and brief explation on that , how to pass importing and tables parameters to get exact output .
regards
geetha.Use : BAPI_SALESORDER_CREATEFROMDAT2
Sales order: Create Sales Order
Functionality
You can use this method to create sales orders.
You must enter at least sales order header data (via ORDER_HEADER_IN structure) and partner data (via the ORDER_PARTNERS table) as input parameters.
Enter the item data via the ORDER_ITEMS_IN table. You can allocate item numbers manually, by filling in the relevant fields, or the system does it, according to the settings for Customizing, by leaving the relevant fields blank.
If you have configurable items, you must enter the configuration data in the ORDER_CFGS_REF, ORDER_CFGS_INST, ORDER_CFGS_PART_OF and ORDER_CFGS_VALUE tables.
Credit cards can be transferred via the BAPICCARD structure, on the one hand, data for card identification, on the other, data for a transaction which has taken place in an external system.
Once you have created the sales order successfully, you will receive the document number (SALESDOCUMENT field). Any errors that may occur will be announced via the RETURN parameter.
If no sales area has been created in the sales order header, then the system creates the sales area from the sold-to party or ship-to party, who has been entered in the partner table. If a clear sales area cannot be created, you will receive a system message, and the sales order will not be created.
Notes
1. Mandatory entries:
ORDER_HEADER_IN : DOC_TYPE Sales document type
SALES_ORG Sales organization
DISTR_CHAN Distribution channel
DIVISION Division
ORDER_PARTNERS..: PARTN_ROLE Partner role, SP sold-to party
PARTN_NUMB Customer number
ORDER_ITEMS_IN..: MATERIAL Material number
2. Ship-to party:
If no ship-to party is entered, use the following: Ship-to party =
sold-to party.
3. Commit control:
The BAPI does not have a database commit. This means that the relevant application must leave the commit, in order that can be carried out on on the database. The BAPI BAPI_TRANSACTION_COMMIT is available for this.
4. German key words:
The following key words must be entered in German, independantly of
the logon language:
DOC_TYPE Sales document type, for example: TA for standard order
PARTN_ROLE Partner role, for example: WE for ship-to party
Further information
You can find further information in the OSS. The note 93091 contains general information on the BAPIs in SD.
Parameters
SALESDOCUMENTIN
ORDER_HEADER_IN
ORDER_HEADER_INX
SENDER
BINARY_RELATIONSHIPTYPE
INT_NUMBER_ASSIGNMENT
BEHAVE_WHEN_ERROR
LOGIC_SWITCH
TESTRUN
CONVERT
SALESDOCUMENT
RETURN
ORDER_ITEMS_IN
ORDER_ITEMS_INX
ORDER_PARTNERS
ORDER_SCHEDULES_IN
ORDER_SCHEDULES_INX
ORDER_CONDITIONS_IN
ORDER_CONDITIONS_INX
ORDER_CFGS_REF
ORDER_CFGS_INST
ORDER_CFGS_PART_OF
ORDER_CFGS_VALUE
ORDER_CFGS_BLOB
ORDER_CFGS_VK
ORDER_CFGS_REFINST
ORDER_CCARD
ORDER_TEXT
ORDER_KEYS
EXTENSIONIN
PARTNERADDRESSES
Exceptions
Function Group
2032
Maybe you are looking for
-
Itouch 3rd gen not recognised in Windows vista but ok in itunes (code 10 error)
Windows Vista pc running latest itunes. pc will recognise itouch 3rd gen in itunes but not in explorer. device driver posts a code 10 error. checked for update driver, response in latest driver installed (digital camera). Need help to be able to dow
-
ME22N : Change PO Line item to Display Mode, After All quantity has GRN
Hi Experts, In ME22N, PO change mode if the line item has checked with 'Delivery Completed' Indicator in 'Delivery' tab I want to shows that row always in 'Display' mode. Please help me to modify that table control within the exit. I'm using, Enhanc
-
How do you reset an iPod?
I got my daughter an iPod touch for Vday and we can't create an Apple id so she can order songs and games. The error is saying that the emaill is already being used. I think we need to start completely over, how do I do that?
-
Why is my user id/pw not accepted by ICloud on my iPad but it is accepted by iCloud on my computer? I am using the same password for both.
-
hi I have a curve 9300 using os 6 and the latest app world 2.1.1.. something when i try to download apps it initiates the download then after a couple of seconds after starting it shows the error message "there was a problem during installation. Ple