Checking for X continuous periods for a certain item
Hi,
simplified, I have a table like this:
ROWNUM VEHICULE_ID FROM(DD/MM/YYYY) TILL(DD/MM/YYYY)
==============================================
1 1 10/09/2009 02/02/2010
2 2 01/01/2010 31/12/2010
3 1 01/01/2010 31/12/2010
4 3 01/10/2009 31/03/2010
5 1 01/08/2009 01/03/2010
6 1 01/02/2010 01/09/2010
7 1 01/03/2010 30/06/2010
Now, I have to determine all the vehicules that have at least 3 continuous periods between 01/01/2010 and 30/06/2010.
When I apply this question to the above data, then it should return vehicule_id 1.
The 3 continuous periods for vehicule_id 1 are:
A)
rownum 3: 01/01/2010 - 31/12/2010 ==> 01/01/2010 - 30/06/2010: OK
B)
rownum 5: 01/08/2009 - 01/03/2010 ==> 01/01/2010 - 01/03/2010: OK
+ rownum 6: 01/02/2010 - 01/09/2010 ==> 02/03/2010 - 30/06/2010: OK
C)
rownum 1: 10/09/2009 - 02/02/2010 ==> 01/01/2010 - 02/02/2010
+ rownum 7: 01/03/2010 - 30/06/2010 ==> 01/03/2010 - 30/06/2010: OK
+ rownum 6: 01/02/2010 - 01/09/2010 ==> 03/02/2010 - 28/02/2010: OK ==> This period was not yet used in the periods for B), so we could still use it here.
The best solution I can find for this is to create a cursor and check if for every date between 01/01/2010 and 30/06/2010 at least 3 diffent periods are valid, but this not very fast and generic if the period should change.
Does anybody have an idea how you could get this information via sql or pl/sql?
Thanks in advance for any help about this,
Geert
Hi, Geert,
You can use analytic functions to find how many registrations were active at any point in time.
In the query below, s_cnt is the number of registrations active at the beginning of the period of interest (this is the same for every row with the same vehicule_id), and e_cnt is the number of other registrations remaining active at the time each registration ends. (If the number of concurrent registrations ever falls below 3, it will do so at a time when some registration ends, so it is only necessary to test those points.) The vehicule_ids you want are those where e_cnt is at least 3, and e_cnt is never less than 3 during the period of interest.
VARIABLE period_sdat VARCHAR2 (10)
VARIABLE period_edat VARCHAR2 (10)
VARIABLE min_cnt NUMBER
EXEC :period_sdat := '01/01/2010';
EXEC :period_edat := '30/06/2010';
EXEC :min_cnt := 3;
WITH got_cnt AS
SELECT t.*
, COUNT ( CASE
WHEN sdat <= TO_DATE (:period_sdat, 'DD/MM/YYYY')
THEN 1
END
) OVER ( PARTITION BY vehicule_id) AS s_cnt
, COUNT (1) OVER ( PARTITION BY vehicule_id
ORDER BY sdat
RANGE BETWEEN UNBOUNDED PRECEDING
AND edat - sdat FOLLOWING
- COUNT (1) OVER ( PARTITION BY vehicule_id
ORDER BY edat
) AS e_cnt
FROM t
WHERE sdat <= TO_DATE (:period_edat, 'DD/MM/YYYY')
AND edat >= TO_DATE (:period_sdat, 'DD/MM/YYYY')
SELECT vehicule_id
FROM got_cnt
WHERE s_cnt >= :min_cnt
GROUP BY vehicule_id
HAVING SUM ( CASE
WHEN e_cnt < :min_cnt
AND edat < TO_DATE (:period_edat, 'DD/MM/YYYY')
THEN 1
ELSE 0
END
) = 0
;The tricky part here is computing e_cnt. This is the number of prior registrations begun, minus the number of prior registrations ended. The number of prior registrations ended is a straightforward analytic function, but the number of prior registrations begun requires a windowing clause, because "prior" here means "prior to edat", not sdat, which is used for the ORDER BY.
Edited by: Frank Kulash on Apr 2, 2010 11:22 AM
Similar Messages
-
I need to load for a historical period for sales order ? how to load it?
Hi all,
I need to load the data for the historical period. Say 012.2008 month data. I have deleted the set up tables and trying to reload the setup tables.
but i can find the calendar year, month nor fiscal period.
i can see only sales document number along witht the company code.
How to identify the sales document number for 012.2008 from r/3 and run the setup tables.
Pls help me on this!!
Thanks
PoojaHi,
You are trying to do a historical load for 2LIS_11? In that case, check the VBAK/VBAP table, and find the document ranges based on the posting date. VBAK will give you the ranges, while putting the same range in VBAP wll give you the number of item documents that would be loaded. You would be able to split the doc ranges in that case for doing parallel setups.
Alternatively if the data volume is low, do a full setup and then put the selections in the info package itself.
Regards. -
Appears to be flash or Acrobat issue???
Probably caused by the Google Toolbar extension. Disable it to verify it as the cause.
-
Time out period for PO approvals in worklist
Hi all,
Can any one know how to check the time out period for PO approvals in worklist other thant workflow builder like from system adminstrator or a query etc.,
Thanks in advance,
Regards,
PramodHi,
The following note might solve your problem :
1330433.
Thanks and Regards,
Vignesh Ravikumar -
Report of Balance GRs for a particular period.
Dear Gurus,,
How can I generate a report of balance/pending GRs for a particular period for invoice parking.i.e Materials recd.,GR prepared but Invoice is not recd.or parked againest such GRs.
ThanksHi
Try with ME2N or ME2M or ME2L with selection parameter RECHNUNG - open invoice.
Thanks/karthik -
How to find expense and revenue of a company code for a particular period
Hi Gurus,
I am new to FI. I need to find out the revenue, expense and gross profit of a company code for a particular period.
for eg: I need to find the revenue, expense and GP of a comapany code 'ZYZM' for the month of july. Is there
any standard report for this or any way to see P&L statement for this period?
Thanks and regards,
Ashish KumarHi Ashish
You can use report S_PL0_86000030 - G/L Account Balances (New) for the period wise report.
You can select as Mani mention P&L account statement type as X in dynamic selection and give the period for which you require the balance.
The report will give you the three balances
Opening
Till previous period
for the period
Hope this report will help you.
Regards
Pankaj P -
CRM Availability Check not working for certain Item Category
Hi there,
I have a situation where for certain order type/item category combinations, the availability check on the same material is not working.
The check is set up to happen in SAP ECC.
I have checked the config. under SPRO->CRM->Basic Functions->Availability Check->Availability Check using SAP ECC
as per many SDN posts on this, and everything looks fine.
The new item category, which was a copy of an existing one, works (i.e. gives availability) for certain order types, but not others.
If I create the same order directly in ECC, it works correctly every time.
I searched the code (from consultants who set it up originally) and can see nothing specific to the order type/ item category.
I also put a breakpoint on AVAILABILTY_CHECK function module in SAP ECC - it is not being hit, in the case where check is not successful.
Breakpoints in MV45AFZZ (Sales Order userexit) also not being hit, but they are hit for the Order/item category combination when it works successfully.
Any suggestions on where else this could be configured would be appreciated!
thanks,
DavidHi David,
One 'simple' reason for this could be that the copied item category does not have the
ATP Profile set up in the item category in the IMG. Make sure you have an ATP profile assigned in the area 'ATP Profile' in the item category.
Please see as well the SCN Wiki link:
Availability Check CRM-BTX-BF-ATP - CRM - SCN Wiki
Best regards
Christophe -
Check List for closing posting period
Hi everyone,
What should be the complete check list (activity to be done) before closing the posting period in MMHi,
In fact when ever you complete the month you have to close the period for the previous month.This you can do at the T.code MMPV.
1)before closing the period check wheather the Back posting is allowed at SPRO-logistics general -material master-basic settings-company code settings for the financial year.
2)There will be peiod indicatotors.You have to check them.
3)unless and untill you dont close the period your inventory management settings will not allow you to furthur stating a warning message that 'posting period is in previous month'.
Regards,
Raghu -
I am getting a message that my complementary use period for "pdf complete" is expired. Must I buy "pdf complete" to continue to download pdf files? I didn't download anything on my previous macbook pro to download pdf files, and I definitely didn't pay for pdf downloading software.
PDF Complete is not necessary. Apple's Preview application and Adobe's Acrobat Reader (both free) are all most people need for pdfs.
If you want to create pdf documents there are any number of applications for it. Easiest might be to just print to pdf, (File menu > Print > PDF button) in many applications.
Best of luck. -
E613 SYST: You cannot determine the period for rule 03
Dear All,
We are configuring asset module and using MSTL dep key for Tax books. When we tried to create an asset with MSTL dep key, we encountered error - 'E613 SYST: You cannot determine the period for rule 03'. when verified config OAVH Define Calender Assignments transaction, Period control '03' is missing for fiscal year variant K4. Period control is exisiting in Maintain Period Control and but not in Define Calender Assignment. What I understand these period controls are being delivered by SAP. Not sure why period control '03' is missing. all other period control keys are available.
question is how to add period control 03 so that we can use MSTL dep key. we are currently using 4.7c. Any suggestions would be appreciated.
thanks
Sunilmessage went abruptly before I finish.
+++++++++
continuing from previous email
Period control 01 has following entry in the transaction
Fiscal Year Variant Per control Name of the period control Year Month Day Period Mid Month
K4 01 Pro rata at period start date blank 0 0 blank not selected
If I follow SAP help to define period control '03', then I just need to copy period control '01' which is listed above and select 'Mid Month' check box.
Wondering anyone did this in the past. MSTL depreciation key is being used in MACRS tax for US. I am sure people who have implemented assets module for US with tax dep, they might have encountered this issue.
thanks
Sunil -
Entire system crashes when fire fox is run for a short period of time
So I've been building a new PC over the last 3 months and today it's finally complete. When I run Firefox for a short period of time (shortest so far is 10 seconds, longest is roughly 30 minutes) my entire system will just freeze up. Display stays on but nothing I do will update the display and I will need to forcefully shut down the entire PC.
I would rather not switch to a different browser.
I'm certain this only happens with Firefox because it does not happen with IE, and I've been using Chrome for the last 10 mins without an issue. It does not seem to crash is safe mode.
Not sure if I was getting unlucky but I was using the British version of fire fox and it would seem to crash more constantly then the American one.
*EDIT*
I just got the same crash with chrome. But it took a lot longer to happen compared to Firefox. I'm really confused as to what's happening now, I'm going to close my browsers all together now and try doing something else for a few hours, I don't think it's because my system is getting over powered because my stuff is very high end.
I will post my system specs, then leave and come back in a few hours, to check for replies. Sorry if I take a while to get back to you.
If you need additional information just ask.
Specs
Processor-i7 3930k
Mobo-asus p9x79 extreme
Graphics card-amd 7970
RAM-g.skill 16gb 1600mhz
I think that's the necessary specs.
I'll see you all in a while.Do a malware check with some malware scanning programs on the Windows computer.<br />
You need to scan with all programs because each program detects different malware.<br />
Make sure that you update each program to get the latest version of their databases before doing a scan.<br /><br />
*http://www.malwarebytes.org/mbam.php - Malwarebytes' Anti-Malware
*http://www.superantispyware.com/ - SuperAntispyware
*http://www.microsoft.com/security/scanner/en-us/default.aspx - Microsoft Safety Scanner
*http://www.microsoft.com/windows/products/winfamily/defender/default.mspx - Windows Defender: Home Page
*http://www.safer-networking.org/en/index.html - Spybot Search & Destroy
*http://www.lavasoft.com/products/ad_aware_free.php - Ad-Aware Free
See also:
*"Spyware on Windows": http://kb.mozillazine.org/Popups_not_blocked -
My iPhone 5 continuously searches for mail, no matter what time period I set it for in settings. Has anyone else experienced this?
My iPhone 5 continuously searches for mail
How do you know this?
no matter what time period I set it for in settings
You realize that Mail App checks for mail every time it's opened and that the fetch interval you set applies only to background checks when the app is closed, right? -
Error while running a query-Input for variable 'Posting Period is invalid
Hi All,
NOTE: This error is only cropping up when I input 12 in the posting period variable selection. If I put in any other value from 1-11 I am not getting any errors. Any ideas why this might be happening?
I am getting the following error when I try and run a query - "Input for variable 'Posting Period (Single entry, mandatory)' is invalid" - On further clicking on this error the message displayed is as follows -
Diagnosis
Variable Posting Period (Single Value Entry, Mandatory) is used as a lower limit (X) and an upper limit () in an interval selection. This limit has the value #.
System Response
Procedure
Enter a different value for variable Posting Period (Single Value Entry, Mandatory). If the value of the other limit is determined by another variable, you can change its value also.
Procedure for System AdministrationOK.
Well, if the variable is not used in any interval selection, then I would say "something happened to it".
I would make a copy of the query and run it to check if I get the same problem with period 12.
-> If not, something is wrong in the original query (you can proceed as below, if changes to original are permitted).
If so, then try removing the variable completely from the query and hardcode restriction to 12.
-> If problem still persists, I would have to do some thinking.
If problem is gone, then add the variable again. Check.
-> If problem is back, then the variable "is sick". Only quick thing to do, is to build an identical variable and use that one.
If problem also happens with the new variable, then it's time to share this experience with someone else and consider raising an OSS.
Good luck!
Jacob
P.S: what fisc year variant are you using?
Edited by: Jacob Jansen on Jan 25, 2010 8:36 PM -
Reg: Query Problem for New Posting Period
Hi Xperts,
While I try to Map the A/P Invoices with their respective Outgoing Payment,
I used the following Query and it's Query Printlayout
SELECT T0.DocNum [Payment#], T0.DocDate [Payment Date],
T0.CardCode, T0.CardName, T1.InvoiceId, T2.DocNum [AP Inv#],
T2.NumatCard [Bill No.], T2.DocDate [Bill Date], T1.selfInv,
T1.SumApplied, T1.WtAppld, T0.NoDocsum
FROM [dbo].[OVPM] T0 INNER JOIN
[dbo].[VPM2] T1 ON T1.[DocNum] = T0.DocNum
INNER JOIN [dbo].[OPCH] T2 ON T2.[DocEntry] = T1.DocEntry
WHERE T0.Cardname='[%0]' and T0.DocDate='[%1]' and
T0.DocNum='[%2]'
I got the above query from our Expert Mr.Sambath only.
Now what is the problem is the query is retrieving the payment details of old Posting Period only and not the current posting period.
In detail, I used 'Primary' Series for FY08-09, Period indicator 'Default'
Now I'm using 'Primary1' Series for FY09-10, Period indicator '0910'
Thanx in adv.
Regards,
BalaHi Bala,
Looking at your query, it is not query issue ,it is your data issue.
Please check if you have data in VPM2 table which is bank transfer payment method
Thank you
Bishal
Edited by: Bishal Adhikari on Apr 9, 2009 8:48 AM -
Error that "specify a value for variable posting period (single value entry
hi
My query is running testing fine in RSECADMIN under some username..but when i try and open it using analyzer (under same username) it gives me error that "specify a value for variable posting period (single value entry, mandatry)" it does'nt even asks to enter variable values and gives this error message.
However the same query appears to be working fine under different username.
plz advise.Hi Abhinav,
Just do one thing compare the Roles of two different users for which Query is getting executed and not.
Check the Object S_RFC.
Compare the Objects detail for Both the Users.
Please Assign points if useful.
Regards,
Rajdeep.
Maybe you are looking for
-
I downloaded 4.0 when prompted yesterday. Seemed to download normally but did not automatically start following download even though that option was checked. The shortcut now is broken and efforts to fix it fail because the file cannot be found. Chec
-
My fico vs credit karma vs equifax credit monitoring
As you all can see I am new here and have just begun my credit repair journey I'm hoping that some one can shed some light on credit score questions and educate me in the differences. I have recently started using credit karma and they tell me the my
-
Excise Report - Statuary Reports
Hi All, I have installed 2007 B Demo Version, but i am not getting where is the excise report (Country Specific - India). Even I serched on google and its showing the avaulability of excise reports in 2007 B. Can anybody tell me the location of Statu
-
Configuration for JDBC support in Jakarta-Tomcat-4.0
I have used JSP pages which call packaganame.classname in the useBean directive. This works fine when I have simple programs, but when my class uses JDBC connectivity, this does not work. I get NullPointerException on the browser. I am currently usin
-
Hi,I am using the server socket in Java to listen on a port on a computer.. I am using the windows platform I use ms vj++6.0 I am facing a peculiar problem. about once in 10 messages received by my server socket, The server socket hangs . Hangs means