Order my select statement by fiscal year
I want to order my select statement by
fiscal year of DATE_OF_SEPARATION,
inst_num,
trauma_num
The fiscal year is between YYYY/04/01 to YYYY+1/03/31
How would I write the order by statement
order by
inst_num,
trauma_num
Thanks
Brendon
either use your own calender in an auxiliary table
or write a function and order by function.
1. create table my_fiscal_year (day date, fiscal_year number);
select
fiscal_year
from
,my_fiscal_year
where
date_of_separation = my_fiscal_year.day
order by
my_fiscal_year.fiscal_year
2.
create function f_get_fiscal_year(p_date date) return number is
l_year number ;
begin
if to_char(p_date,'MM') between '01' and '03' then
l_year := to_number(to_char(trunc(p_date,'YEAR'),'YYYY')) - 1;
else
l_year := to_number(to_char(trunc(p_date,'YEAR'),'YYYY')) ;
end if ;
return l_year ;
end ;
order by
f_get_fiscal_year (date_of_separation)
Similar Messages
-
Selection criteria is fiscal year/period but need to restrict KF by date
Hi,
I have query where selection criteria is based on fiscalyear/period and in result I need to have Netvalue for all the sales order by created on date for that fiscal year/period.
For eg if I have entered fiscal year/period as 008.2007, I should get net value for all the orders that have created on date between 08/01/2007 to 08/31/2007.
Can anyone help me about this please.Hi DV
Here is the code
put it in I_STEP=2
WHEN 'EXIT NAME"
READ TABLE I_T_VAR_RANGE INTO loc_var_range with key vnam = 'userinput variable name'
v_fiscal_year = loc_var_range-low_0(4)
v_period = loc_var_range-low+4(3)
CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
EXPORTING
i_gjahr = v_fiscal_year
I_MONMIT = 00
i_periv = Give your fiscal year variant name
i_poper = v_per
IMPORTING
e_date = v_date_beg
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.
CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
EXPORTING
i_gjahr = v_fiscal_year
I_MONMIT = 00
i_periv = Give your fiscal year variant name
i_poper = v_per
IMPORTING
e_date = v_date_end
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.
CLEAR s_range.
MOVE:
v_date_beg TO loc_range-low,
v_date_end TO loc_range-high.
loc_range-sign = 'I'.
loc_range-opt = 'BT'.
APPEND s_range TO e_t_range.
Thanks
Tripple k -
Dynamic date in the selection according to fiscal year variant
Hi
Is it possible to set dynamic date input parameter from the fiscal year variant sap table (OB29 transaction).
For example when I run valuation (F.05) I want the value date input field to be the last day of the previous period.
Thanks
OferHi,
The dynamic dates on the selection parameters may come from the variant.
You need to create the variants accordingly to your requirements and specify how the date on the selection screen has to be calculated.
You have different options for this purpose.
T T: Table Variable from TVARVC
D D: Dynamic date calculation -
Evaluated order of Pivot and UnPivot in select statement
My research which evaluated order of select statement is below.
1 from
2 where (Join condition)
3 start with
4 connect by
5 where (filter of rows)
6 group by
7 having
8 model
9 select
10 order byMy question is Where Pivot clause and UnPivot clause ?
http://download.oracle.com/docs/cd/E16338_01/server.112/e10592/statements_10002.htmProvided that you can specify columns created by the PIVOT clause both in the select and in the Order By clause, I think the pivot must be executed before them:
SQL> r
1 select job, d10,d20,d30 from emp
2 pivot (sum(sal) for deptno in (10 as D10, 20 as d20, 30 as d30))
3* order by d20
JOB D10 D20 D30
CLERK 800
CLERK 1100
MANAGER 2975
ANALYST 3000
ANALYST 3000
SALESMAN 1600
PRESIDENT 5000
MANAGER 2450
SALESMAN 1500
SALESMAN 1250
CLERK 1300
MANAGER 2850
SALESMAN 1250
CLERK 950
Selezionate 14 righe.
Piano di esecuzione
Plan hash value: 1739977809
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 14 | 518 | 5 (40)| 00:00:01 |
| 1 | SORT ORDER BY | | 14 | 518 | 5 (40)| 00:00:01 |
| 2 | HASH GROUP BY PIVOT| | 14 | 518 | 5 (40)| 00:00:01 |
| 3 | TABLE ACCESS FULL | EMP | 14 | 518 | 3 (0)| 00:00:01 |
-----------------------------------------------------------------------------Max -
Purchase order not appearing as commitment for next fiscal year in KOB2
Hi Experts
Any help on this is highly appreciated.Our Fiscal year 2008 is ending on 27th september and fiscal year 2009 will start on 28th September.
We have some purchase orders created with delivery date as 30th september which falls into next fiscal year. Somehow these purchase orders are not appearing as commitments in KOB2 report even with data ranges for next fiscal year.
However we have many similar Purchase orders with delivery date in fiscal year 2008 with same internal order as account assignment and they are correctly appearing as commitments in KOB2 report.
Can you please let us know what could be the reason for purchase orders with delivery date as 30th september not appearing in KOB2 report.
Regards,
SantoshHi Ashok
Thanks for your continued support on this. I was going through these notes today.
One observation I made was cost elements in our system were valid till 27th september only when problematic POs were created.However their validity was subsequently extended after the creation of Purchase orders.This might be the reason for system not recognising these POs as commitments.
SAP Note 534993 seems to suggest that we need to run report RKANBU01 for all such purchase orders to redetermine commitments.I am in the process of testing this out in our systems.
Could you please let me know if my understanding is correct. Thanks again.
Regards,
Santosh -
Sql query with dynamic fiscal year
Hi,
I wrote this query with static fiscal year and fiscal period, I need info on making the variables dynamic
Fiscal year : starts from July1st. So this year until June'30 it is '2011' and from July'1st its '2012'
Fiscal period: July1st its '1' and June'1st its '12'
Query:
select distinct o.c_num, o.ac_num, s.sub_ac_num, o.fiscal_year, o.ac_exp_date, s.sub_ac_ind
from org_account o
left outer join sub_account s
on o.c_num = s.c_num and o.ac_num = s.ac_num
where (o.ac_exp_date >= CURRENT_DATE or o.ac_exp_date is null)
and o.fiscal_year = *'2011'* --> need to be dynamic
and o.fiscal_period = *'12'* --> need to be dynamic
thanks,
Mano
Edited by: user9332645 on Jun 2, 2011 6:55 PMHi, Mano,
Welcome to the forum!
Whenever you have a question, please post a little sample data (CREATE TABLE and INSERT statements), and the results you want from that data.
Always say which version of Oracle you're using.
Since this is your first thread, I'll post some sample data for you:
CREATE TABLE table_x
( dt DATE
INSERT INTO table_x (dt) VALUES (DATE '2010-12-31');
INSERT INTO table_x (dt) VALUES (DATE '2011-01-01');
INSERT INTO table_x (dt) VALUES (DATE '2011-06-02');
INSERT INTO table_x (dt) VALUES (DATE '2011-06-30');
INSERT INTO table_x (dt) VALUES (DATE '2011-07-01');Is this the output you would want from that data?
DT FISCAL_YEAR FISCAL_PERIOD
31-Dec-2010 2011 06
01-Jan-2011 2011 07
02-Jun-2011 2011 12
30-Jun-2011 2011 12
01-Jul-2011 2012 01If so, here's one way to get it:
SELECT dt
, TO_CHAR ( ADD_MONTHS (dt, 6)
, 'YYYY'
) AS fiscal_year
, TO_CHAR ( ADD_MONTHS (dt, 6)
, 'MM'
) AS fiscal_period
FROM table_x
ORDER BY dt
;Since your fiscal year starts 6 months before the calendar year, you need to add 6 months to the actual date to get the fiscal year and month.
The query above produces strings for fiscal_year and fiscal_period. If you'd rather have NUMBERs, then use EXTRACT instead of TO_CHAR:
SELECT dt
, EXTRACT ( YEAR
FROM ADD_MONTHS (dt, 6)
) AS fiscal_year
, EXTRACT ( MONTH
FROM ADD_MONTHS (dt, 6)
) AS fiscal_period
FROM table_x
ORDER BY dt
;The first query will work in Oracle 6 (and higher).
I'm not sure when EXTRACT was introduced. It definitely works in Oracle 10, and may be available in earlier versions, too. -
How to give the Fiscal year period in RSA3 for checking the data.
Hi BW Experts, good morning.
We have loaded the data monthlywise with selection parameters as Fiscal Year Period(FISCPER).
While checking the data consistency in both R/3 and BI, the selection parameter which i have given is in the format of 001.2005
I got the records in BI side.
But if we give the same format In RSA3 in the Fiscal Year Period tab , we r getting 0 records.
So kindly help me how to enter the selection parameters for 1 month.
Thanks
AnjaliHi sanyam ,
Thanks for the help.
I got it now.
Thank you so much
Bye
Regards
Anjali -
How to get fiscal period based on date and Fiscal year?
Hi Guys,
Can anybody tell me how to get Fiscal period based on date and Fiscal Year or fiscal year variant?
Thanks,
Gopi.Hi,
Please refer the code below:
*: Report: ZFISCALYR :
*: Date : 2004 :
*: Description: Demonstrates how to return the corresponding fiscal :
*: year and posting period for a company code and posting :
*: date or posting date and fiscal year variant. :
REPORT zfiscalyr NO STANDARD PAGE HEADING.
TABLES: ekko.
PARAMETERS: p_bukrs TYPE ekko-bukrs,
p_bedat TYPE ekko-bedat.
DATA: gd_fiscalyr TYPE bapi0002_4-fiscal_year,
gd_fiscalp TYPE bapi0002_4-fiscal_period.
DATA: gd_fiscalyr2 TYPE T009B-BDATJ,
gd_fiscalp2 TYPE bapi0002_4-fiscal_period.
DATA: gd_periv TYPE t009-periv.
*START-OF-SELECTION.
START-OF-SELECTION.
* get fiscal year and period - (requires date and company code)
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
companycodeid = p_bukrs
posting_date = p_bedat
IMPORTING
fiscal_year = gd_fiscalyr
fiscal_period = gd_fiscalp.
* Alternative fiscal year function module
* - (requires date and fiscal year variant code from T009 table)
* gets first entry in fiscal year variant table (will need to choose
* correct one from table rather than just using first entry)
SELECT SINGLE periv
FROM t009
INTO gd_periv.
* get fiscal year and period
CALL FUNCTION 'DETERMINE_PERIOD'
EXPORTING
date = p_bedat
* PERIOD_IN = '000'
version = gd_periv
IMPORTING
period = gd_fiscalp2
year = gd_fiscalyr2
EXCEPTIONS
period_in_not_valid = 1
period_not_assigned = 2
version_undefined = 3
OTHERS = 4.
*END-OF-SELECTION.
END-OF-SELECTION.
WRITE:/ 'From function module: BAPI_COMPANYCODE_GET_PERIOD',
/ 'Fiscal year is:', gd_fiscalyr,
/ 'Fiscal period is:', gd_fiscalp.
SKIP.
WRITE:/ 'From function module: DETERMINE_PERIOD',
/ 'Fiscal year is:', gd_fiscalyr2,
/ 'Fiscal period is:', gd_fiscalp2.
Thanks,
Sriram Ponna.
Edited by: Sriram Ponna on Apr 17, 2008 8:59 PM -
Internal order posted and settled to auc in incorrect ccode and fiscal year
Hi,
We created an internal order in ian ncorrect company code and settled the cost to AUC in previous fiscal year.
I would like to know what options do you recommend to move the AUC cost from incorrect company code to internal order in a correct company in the current fiscal year. Our AUC account is set up as control account and cannot be manually posted to.
I understand Internal order settlement to AUC for previous fiscal period cannot be reversed in the current year?.
Kindly advise
UmangHi
Select the Internal order > Reverse the settlement in the same year...(KO88)
Try to transfer the balance from this IO to new IO in the other co code from (F-02)..
You need to have Inter Co clearing accounts in the IMG....
now settle the new IO to new asset (AUC) in the other company
Br, Ajay M -
If I want to order by dateAdded to I have to include it in the select statement like
If I do this:
<cfquery name="chart" datasource="#datasource#">
select behaviourID,score, dateAdded2 = convert(varchar,
dateAdded , 101)
from staff_charts_data
where userID =
<cfqueryparam value="#arguments.userID#"
cfsqltype="cf_sql_integer"> AND
NOT score = 5
</cfquery>
If I want to order by dateAdded to I have to include it in
the select statement like so:
<cfquery name="chart" datasource="#datasource#">
select behaviourID,score, dateAdded2 = convert(varchar,
dateAdded , 101),dateAdded
from staff_charts_data
where userID =
<cfqueryparam value="#arguments.userID#"
cfsqltype="cf_sql_integer"> AND
NOT score = 5
</cfquery>you should be able to order by dateAdded without it being in
the select clause. The only time the order by field has to be in
the select clause is when your query has an aggregate and group by
clause, like this:
select field1, field2, max(field3) as youralias
from sometables
where whatever
group by field1, field2
order by ???
You can only order field1, field2, max(field3) or youralias.
You can't order by field4. -
Fiscal year 2010 Not allowed while creating Process order in COR1
Dear Friends,
We have gone SAP live in the month of October. The fiscal yeat we are using is 2011 as the client is Indian client. I have made the fiscal year variant for 2011 (V3). The FI document posting with Fiscal year 2011. It is also creating the Controlling document and Profit center document without any problem.
We have also made the period open as 2011 in MMpv and MMRV. The goods receipts is working fine and the finance entry and material document gets generated for the fiscal year 2011.
Now we are creating the process order in COR1 and getting the error message Fiscal year 2010 not allowed as below.
Fiscal year 2010 is not allowed
Message no. F5568
Diagnosis
The fiscal year entered (2010) is different from the fiscal year derived from the posting date and fiscal year variant (2011).
System Response
Error.
Procedure
Correct the fiscal year entered.
In KP26 we have maintianed for activity price for 2010 & 2011 and the system is picking the data for the fiscal year 2010 data and not the FY 2011 data.
I have checked in OKEQ (Costing version '0') The valide start date for FY2011 is 01.04.2010.
Is there any other place to maintain the fiscal year in Controlling area or Prodduction Planning???
I last my patient last 5 days doing R&D. Can any one help me where the fiscal year is picking and why it is picking FY 2010??
Regards,
DevendranHi Ajay,
Thank you for your comments. I have checked the Factory calendar and that is 2010 (January to December). We have tried to change to 2011 but the system automatically picking the date from January 1st 2011 to 31st December 2011. I am unable to create calendar year with date from 01.04.2010.
I have discussed with my PP consultant about this issue, he is telling the factory calendar nowhere related to Fiscal year. Do you have any idea how to change the factory calendar of 2011 from 01.04.2010 to 31.03.2011?? Is there any there reason why my system considering the Fiscal year 2010 instead of 2011???
Your inputs will defenitely help me to get an clue.
Regards,
Devendran -
Fiscal Year Not allowed while creating the Process order (COR1)
Hi Friends,
My Indian client is following the Fiscal year of 2011 for the period of April 2010 to March 2011). We have gone live one month before. But now the problem we are facing is while creating the process order (T.Code COR1) system gives the error message "Fiscal year 2010 is not allowed".
The Diagnosis shows as below
Fiscal year 2010 is not allowed
Message no. F5568
Diagnosis
The fiscal year entered (2010) is different from the fiscal year derived from the posting date and fiscal year variant (2011).
System Response
Error.
Procedure
Correct the fiscal year entered.
I have Checked the Controlling area version. Fiscal Year 2011 starts from 01.04.2010. This issue is only at the time of Process oder creation and not in other module like FI, MM, SD, PS, QM and PM. I have checked with V3 Variant also and there is no problem with that.
Can any one help me where the setting is missing or what whould be the probable reason for this issue.
Regards,
DevaHi Prakash,
Thank you for your reply. I have checked the MMPV and MMRV set up and that is fine with fiscal year 2011. We are also processed lot many Material receipts for the fiscal year 2011. I have checked with OB52 for finace it is opened for the entire year of 2011 from 2009 for all periods.
We are facing only when we try to create the process order. When we enter the starte date as 24.11.2010 the derived period shows as fiscal year 2011. But entered fiscal year shows as 2010. We are not entering any other dates in the process order.
Is there any other probablity the date is picking from any Production related set ups??
The costing version fiscal year 2011 starts from 01.04.2010. So no problem with Controlling area. I have Checked the Factory calendar. The calendar starts from 01.01.2010 to 31.12.2010 for the year 2010.
Is there any other possibility of the missing settings or problem in date control???
Regards,
Deva -
FISCAL year from Date in the Selection Screen.
Hi Folks,
Is there any function module which returns the Fiscal year if we provide the date in ranges.
I mean, I have a select option for date in the selection screen.So,if a user enters the date say 01042007 01042007 it should return the corresponding fiscal year.
Kindly let me know if anyone here has any idea regarding this.
Thanks,
K.Kiran.Hello,
Check these FM's
FTIS
FTI_FISCAL_YEAR_MONTH_GET
KBPA Budget/Plan - application-specific
KBPA_GET_START_FISCAL_YEAR Determine Start Year for Funds Management
KBPA_GET_START_FISCAL_YEAR_OPT
Vasanth -
Using ORDER BY for column that's not in SELECT statement of select list?
Hi all.
I have a select list on an APEX page at apex.oracle.com, and I would like to order this by the value of column UnitOrder.
The SQL is as follows:
SELECT DISTINCT foodunit.name AS display_value, foodunit.foodunitid AS return_value
FROM foodunit, food
WHERE foodunit.foodid = :P18_FOODID
ORDER BY foodunit.unitorder ASC;Off course, this code won't work. And since it's a select list, I can't just add foodunit.unitorder to the SELECT statement. Also, I can't get rid of the DISTINCT, because then for some reason it tends to display an infinite amount of the same row...
The point of ordering it by UnitOrder is that all units who begin with gram, ml, mg, kg,... etc, will be shown on top of the select list. All other food units will be shown on the second place and so on.
The column UnitOrder holds either 1 or 2 as a value. 1 is the value for all rows that should be displayed at the top of the select list, 2 is the value for all the rest.
So, what I want is that all rows in which the UnitOrder is 1, get displayed on top of the select list. Usually only 2 list items get shown in the select list at a time, depening on which food item a user has selected. The select list then refines to certain rows that match the foodid etc etc..
If anyone has an idea, I'd be very happy to hear about it.Thanks! I didn't think about using a join. Code works now, and is as follows:
SELECT foodunit.name AS display_value, foodunit.foodunitid AS return_value
FROM foodunit
INNER JOIN food
ON food.foodid = foodunit.foodid
WHERE foodunit.foodid = :P18_FOODID
ORDER BY foodunit.unitorder ASC; -
SELECT statement INTO TABLE - what determines order of entries in in.table?
Hello everyone.
I habe a question: A select statement selects multiple entries from a data base table that are put into an internal table.
The question : What determines the order of the entries in the internal table?
And what might change the order all of a suddden in that internal table?
Could reorg. activities/archiving (even ongoing) cause any different result in the order as before ?
I do not mean different entries but I rather refer to the sorting of the internal table, if it is not explicitly stated in the select or in parts of the coding.
Any explaination is appreciated!
Thanks!
CN.Hi,
Its not the order in which you specify the fields in the where clause that affects the sequence of the selection.
What I said is that by default the entries are sorted by the primary key of the table.
I did a bit of a test out of curiosity and after seeing so many different replies on the thread. I was surprised to see the results of the different scenarios.
REPORT Z_TEST_SELECTION .
tables vbap.
data it_vbap type table of vbap.
data it_vbak type table of vbak.
select-options s_vbeln for vbap-vbeln.
select-options s_posnr for vbap-posnr.
"======================================================================
"s_vbeln has following entries
" 5
" 6
" 1
" 2
"s_posnr has following entries.
" 10
" Sorts in ascending order by VBELN and POSNR by default
select * up to 20 rows from vbap into table it_vbap.
refresh it_vbap.
"Below two cases are absolutely unreliable and I would suggest that a
"sort should be mentioned after these statements. So when we use select
"options specify values with the in clause, the sort is not reliable.
"Strangely , neither the sequence is not determined by the order in
"which the data was entered in the select option nor in the sequence of
"the primary key. And this is still a mystery to me about the order in which
"the entries are selected.
" Any answeres anyone ?
"1.
select * from vbap into table it_vbap
where vbeln in ('0000000002','0000000006','0000000005','0000000001')
and posnr in s_posnr.
* Resulted in
*900 |0000000001|000010|
*900 |0000000005|000010|
*900 |0000000006|000010|
*900 |0000000002|000010|
"=========================================================
"2.
select * from vbap into table it_vbap
where posnr in s_posnr
and vbeln in s_vbeln.
* Resulted in
*900 |0000000002|000010|
*900 |0000000001|000010|
*900 |0000000005|000010|
*900 |0000000006|000010|
refresh it_vbap.
"Here the orders were selected in Decending order of Sales order, however
"the posnr is not mentioned in the order by clause, hence posnr was
"still in ascending order.
select * from vbap into table it_vbap
where posnr in s_posnr and vbeln in s_vbeln
order by vbeln descending.
write : 'done!'.
refresh it_vbap.
"Here the orders were selected in Descending order of Sales order.
select * from vbak into table it_vbak where vbeln in s_vbeln
order by vbeln descending.
" The entries were selected in the ascending order of the key VBELN and
" POSNR, so it seems that for all entries does not affect the selection of records.
select * from vbap into table it_vbap
for all entries in it_vbak
where vbeln = it_vbak-vbeln
and posnr in s_posnr.
Of course if you change the order of the primary key (in the transparent table, not in the where clause), the entries will be sorted as per the changed key.
But we seldom change the the sequence of the primary key. In most cases we normally add a new field and make it a key field in addition to the existing key fields.
I hope this helps you.
There might be many more cases and examples than given above, which you can try and reply on this post. Lets see what we come up with.
regards,
Advait
Maybe you are looking for
-
Oracle 8.1.6 Driver Misbehavior
i have installed oracle 8.1.6 Client(with Driver) on a Fresh Win NT PC.WHen i test database connection through ODBC 32-bit Test,it is failing. Also,WHen i test database connection from java thro' JDbcOdbc Driver,Dr.Watson error(Access violation) occu
-
WSDL / Web Service Skeleton code Generation Tool
Hello, My name is Joe Roberts. I am a developer in the Oracle Insurance Global Business Unit, A recent Oracle acquisition. I currently have the need to create a web service based on a schema that has certain base fields that never change and certain
-
My dvd burner cannot perform lead out
hi everyone.... i attached my DVD burner (41N5629) from my x61 to my desktop PC running win XP SP3, using nero 8, at first the burning process work fine until nero perform the lead out, when an error message would appear. I ve tried different brand o
-
Add code To stander Java Clsess
I have requirement to add button in stander OA Page To Print Report I need to implement this solution http://apps2fusion.com/at/ps/260-integrating-xml-publisher-and-oa-framework I Follow this step 1- take all mds file from CE application to my projec
-
How can we get debug info without adding IP in CFServer?
Do we have tag or some code which will give debug information?. <cfdump var="#http#"> on onrequestend.cfm will give me http varible information....any other way?.