Help needed in getting the previous Quarter Data

Hello folks,
I have this procedure where i have to modify the current procedure in the following manner:
I need to get rid of the variables p_start and p_end so that i cannot see them in the crystal report and include the Frequency in the procedure to get the Data based on the Dates.
and Main requirement is" If the Frequency is Quarterly " it should get the previous quarter Data, if "Frequency is monthly" it should return the previous month data.Can anyone please let me know where shud i make changes. Am including the procedure for refernce. Any help is appreciated
Thanks a millioin,
CREATE OR REPLACE PROCEDURE hcsc_recovery_report_h(report_record in out cr_return_types.gen_cursor,
p_start       string,
p_end         string)
IS
v_startdate date;
v_enddate date;
BEGIN
v_startdate := to_date(p_start, 'YYYY/MM');
v_enddate := last_day(to_date(p_end, 'YYYY/MM'));
open report_record for
select --distinct r.recovery_id
r.event_id,
r.event_case_id,
c.client_id,
c.client_code,
c.client_name,
b.branch_group_code,
b.branch_group_description,
g.employer_group_code,
g.employer_group_name,
e.client_policy_identifier,
e.date_of_incident,
e.event_type_code,
sum(nvl(r.amount, 0)) as amt_received,
nvl(sum(case
when r.amount >= 0 then
rd.fees
else
rd.fees * (-1)
end),
0) as fees,
ec.close_date, *001* commented
(case
when ec.close_date <= to_date(to_char(v_enddate, 'MMDDRRRR') || '235959',
'MMDDRRRR HH24MISS') then
ec.close_date
else
null
end) as close_date, --*001*  added
get_case_value(ec.event_id, ec.event_case_id, v_enddate) as case_value,
nvl(etl.fee_percent_flag, 'N') workmans_comp,
max(to_char(r.recovery_date, 'FMMonthYYYY')) Year_Month,
max(to_char(r.recovery_date, 'YYYYMM')) Y_M,
max(to_date(to_char(r.recovery_date, 'MMYYYY'), 'MM/YYYY')) date_MY
from recovery r,
recovery_detail rd,
event e,
client c,
branch_group b,
employer_group g,
event_case ec,
event_type_lookup etl
where r.event_id = e.event_id
and r.event_case_id = ec.event_case_id
and ec.event_id = e.event_id
and rd.recovery_id(+) = r.recovery_id
and r.recovery_date between v_startdate and
to_date(to_char(v_enddate, 'MMDDRRRR') || '235959',
'MMDDRRRR HH24MISS')
and e.client_id = c.client_id
and g.client_id = c.client_id
and b.client_id = c.client_id
and g.employer_group_id(+) = e.employer_group_id
and b.branch_group_id(+) = g.branch_group_id
and e.event_type_code = etl.event_type_code -- SST 130852 04/14/09
group by r.event_id,
r.event_case_id,
c.client_id,
c.client_code,
c.client_name,
b.branch_group_code,
b.branch_group_description,
g.employer_group_code,
g.employer_group_name,
e.client_policy_identifier,
e.date_of_incident,
e.event_type_code,
ec.close_date,
get_case_value(ec.event_id, ec.event_case_id, v_enddate),
nvl(etl.fee_percent_flag, 'N')
having sum(nvl(r.amount, 0)) <> 0
order by c.client_code,
b.branch_group_code,
g.employer_group_code,
r.event_case_id;
Edited by: user11961230 on Oct 20, 2009 9:02 AM

user11961230 wrote:
1. I want to get rid of the p_start and p_end. So how do i declare the v_startdate and v_enddate in the following part?
v_startdate := to_date(p_start, 'YYYY/MM');
v_enddate := last_day(to_date(p_end, 'YYYY/MM'));I'm not sure what you mean by "declare".
In PL/SQL, "declare" means state (at the beginning of a block) that there will be a certain variable with a certain name (such as v_startdate) and datatype (such as DATE). You're already declaring the variables v_startdate and v_enddate correctly, right before the BEGIN statement.
Declaring a variable is not the same as initializing it, that is, giving it a value for the first time. Your next question seems to be about initializing..
2. where exactly shud i include the logic that u have mentioned. sorry a dumb questionIn place of the two assignment statments that reference p_start and p_end.
3. This time am gonna use frequency instead of report_type so that i will get rid of the p_start and p_end from the procedure.Do you mean you want to pass an argument (called frequency) that tells if you want a quarterly or a mionthly report, just like the variable report_type in my example?
If so, replace report_type in my example with frequency.
I think you want something like this:
CREATE OR REPLACE PROCEDURE hcsc_recovery_report_h
(      report_record         in out     cr_return_types.gen_cursor
,      frequency         IN           VARCHAR2
IS
     -- Declare local variables:
     v_startdate     date;
     v_enddate      date;
BEGIN
     -- Initialize v_startdate and v_enddate, depending on frequency
     IF  frequency = 'QUARTERLY'
     THEN
          v_startdate := TRUNC ( ADD_MONTHS (SYSDATE, -3)
                                       , 'Q'
          v_enddate := TRUNC (SYSDATE, 'Q');
     ELSIF  frequency = 'MONTHLY'
     THEN
          v_startdate := TRUNC ( ADD_MONTHS (SYSDATE, -1)
                         , 'MM'
          v_enddate := TRUNC (SYSDATE, 'MM');
     END IF;
     --   Subtract one second from v_enddate
          v_enddate := v_enddate - ( 1
                                        / (24 * 60 * 60)
     open report_record for
     select --distinct r.recovery_id
            r.event_id,
     and     r.recovery_date  BETWEEN  v_startdate     
                     AND       v_enddate
     ...When you post formatted text on this site (and code should always be formatted), type these 6 characters:
(small letters only, inside curly brackets) before and after sections of formatted text, to preserve spacing.
Edited by: Frank Kulash on Oct 20, 2009 2:37 PM
Changed query to use BETWEEN                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • FM to get the previous sunday date based on current date(sy-datum)

    hi all,
    Is there any function module to get the previous sunday date based on current date(sy-datum)?
    Regards,
    Kapil Sharma
    Moderator Message: Basic date related questions are not allowed
    Edited by: Suhas Saha on Sep 19, 2011 11:39 AM

    Hi,
    There are function modules to find out the current day of the week depending on sy-datum. These are as below:
    1. DATE_COMPUTE_DAY - Returns a number indicating what day of the week the date falls on. e.g. Monday is returned as a 1, Tuesday as 2,...., Sunday as 7.
    2. RH_GET_DATE_DAYNAME  - Returns the day based on the date provided, e.g. Monday, Tuesday,..., Sunday.
    Using any of the above, if you can find out the current day, then you can calculate and compute the date of the previous Sunday.
    My observation is that using the first FM might make the calculation simpler.
    Hope this is of help to you.
    Regards,
    Shayeree

  • I need to get the Current System Date and time in the format

    I need to get the Current System Date and time in the format
    *6/24/2009 11:30:29 AM*
    How do i do it ?

    I seem to be saying this a lot lately.
    Google is your friend.
    I googled "java current date format" and SimpleDateFormat featured prominently in the results.

  • How to Get the Previous Transactional Data into Special Purpose Ledger

    Hi,
    1). We have implemented Special Purpose Ledger. After implementing SPL, we are generating documents and getting the postings into SPL. Now I need to bring the previous postings which were entered before Special Purpose Ledger Setup. Please Help me on how to bring the transacctional data into Special Purpose Ledger.
    2).  Is it possible to define A/R Aging by Customers? in  Special Purpose Ledger by using Report Painter?
    3). What is the use of Allocation Cycles like Assessment and Distribution in Special Purpose Ledger?
    Please clarify me on above 3 points.
    Thanks
    Yadayya
    Edited by: Dogdays on Aug 5, 2011 8:02 AM
    Edited by: Dogdays on Aug 5, 2011 8:03 AM

    I have experience in intergrating project accounting to the general ledger in a data warehouse using discoverer to show the results.
    The solution I developed for my compnay is to ensure all entries from all sub-ledgers including manual journal entries are moved to the data warehouse tables have project information based on PA autoaccounting rules.
    The company I work for was interested in viewing reports that cubed cost centers (dept's.) to projects and to translate all entries (not just account balances) to USD for thier foriegn set of books. So, projects can be seen company wide in USD at lowest entry level. The solution I gave them solved the problem and they are able to view reports and evaluate costs by cost centers and projects on an enterprise wide application.
    If this is what you are looking for let me know.
    about my self : I have a B.S. in Computer Science (Theoretical Track) and 17 yrs of accounting and book keeping experience including consolidation and multi-currency sets of books.

  • Need to display the Current Quarter Data

    Hi Gurus,
    We have a requirement in the report as follows:
    I have a Key Figure - 0Balance. In this it should display the current quarter data.
    We have 5 plants and this report is specific to a plant X which runs 3 month behind.
    So in the variables screen, if I enter 006.2007, it should display the data of 003.2007. Please guide me through the steps...Thanks in advance.

    Hi,
    For getting current quarter data there is std variable available 0CMCQUAR , restrict KF wiht the variable and system should show you current quarter balance.
    For getting balance for previous quarter , copy the kf just created and right click on it , click on the variable right hand side -> specify offset -> put -1. and it should give last quarter data.
    Hope that helps.
    Regards
    Mr Kapadia

  • Help:Unable to get the Current Month Data

    Hello Folks,
    Hello Folks i have this scenario where i need to modify this code so that it has to return data from the Current month First Day to the previous Day if its a daily report and previous month data if its a monthly report.
    BEGIN
    if v_lowdate is null or v_highdate is null then
    select to_number(to_char(sysdate, 'DD')) into v_cur_day from dual;
    if v_cur_day < 25 then
    -- this is for the previous month run
    Select Add_Months(trunc(sysdate, 'MONTH'), -1)
    INTO V_LOWDATE
    FROM DUAL;
    SELECT Last_Day(ADD_Months(Sysdate, -1)) INTO V_Highdate From Dual;
    else
    -- this is for the current month run
    Select trunc(sysdate, 'MONTH') INTO V_LOWDATE FROM DUAL;
    SELECT Last_Day(Sysdate) INTO V_Highdate From Dual;
    end if;
    end if;
    I have replaced the above code with the code below but its still returning the previous month Data. Any help would be appreciated.
    v_lob := get_admin_value(p_admin_procedure_name => 'CLIENT_DATAFEED_CODE',p_err_msg => v_error_text);
    if v_lowdate is null or v_highdate is null then
    v_cur_day := TO_CHAR (SYSDATE, 'DD');
    IF report_type = 'D' -- Daily report
    AND v_cur_day > '01' -- (except when run on 1st of the month)
    THEN -- will cover from
    v_lowdate := TRUNC (SYSDATE, 'MONTH'); -- 1st of this month to
    v_highdate := TRUNC (SYSDATE - 1); -- yesterday
    ELSIF report_type = 'M' -- Monthly report
    OR ( report_type = 'D' -- (or Daily report
    AND v_cur_day = '01' -- if run on the 1st of the month)
    ) -- will cover from
    THEN
    v_lowdate := ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
    , -1
    ); -- 1st of last month
    v_highdate := TRUNC (SYSDATE, 'MONTH') - 1; -- last day of last month
    END IF;
    END IF:

    How are you testing this? It works for me, or at least generates the dates I think you want.
    SQL> var fake VARCHAR2(25);
    SQL> var report_type VARCHAR2(1);
    SQL> exec :fake := '16-oct-2009'; :report_type := 'M';
    PL/SQL procedure successfully completed.
    SQL> DECLARE
      2     v_cur_day  VARCHAR2(2);
      3     v_lowdate  DATE;
      4     v_highdate DATE;
      5     fake_date  DATE := TO_DATE(:fake, 'dd-mon-yyyy');
      6  BEGIN
      7     v_cur_day := TO_CHAR (fake_date, 'DD');
      8     IF :report_type = 'D' AND v_cur_day > '01' THEN
      9        v_lowdate := TRUNC (fake_date, 'MONTH'); -- 1st of this month to
    10        v_highdate := TRUNC (fake_date - 1); -- yesterday
    11     ELSIF :report_type = 'M' OR (:report_type = 'D' AND v_cur_day = '01') THEN
    12        v_lowdate := ADD_MONTHS ( TRUNC (fake_date, 'MONTH'), -1); -- 1st of last month
    13        v_highdate := TRUNC (fake_date, 'MONTH') - 1; -- last day of last month
    14     END IF;
    15     DBMS_OUTPUT.Put_Line('Low: '||TO_CHAR(v_lowdate, 'dd-mon-yyyy'));
    16     DBMS_OUTPUT.Put_Line('High: '||TO_CHAR(v_highdate, 'dd-mon-yyyy'));
    17  END;
    18  /
    Low: 01-sep-2009
    High: 30-sep-2009
    PL/SQL procedure successfully completed.
    SQL> exec :report_type := 'D';
    PL/SQL procedure successfully completed.
    SQL> /
    Low: 01-oct-2009
    High: 15-oct-2009
    PL/SQL procedure successfully completed.
    SQL> exec :fake := '01-oct-2009';
    PL/SQL procedure successfully completed.
    SQL> /
    Low: 01-sep-2009
    High: 30-sep-2009
    PL/SQL procedure successfully completed.John

  • Need to get the Last Changed date in Purchase Order.

    Dear Experts,
    I need to get a table which stores the last/ latest change for a Purchase Order.
    For a Purcahse Order, last date  Changes need to be captured , where there was some sort of activity associated with that order. That activity could be a goods receipt, an invoice payment or a change to the Purchase order.
    Thanks in advance.

    Hi,
    You can use EKPO-AEDAT.
    Tables CDHDR and CDPOS contain what chnages you have made.
    Thanks,
    Ramakrishna
    Message was edited by: Ramakrishna Prasad Ramisetti

  • Help needed to find the schema/application data size

    Hi,
    Would i request you to help me to measure schema size/(APEX)application data size.
    I've 3 applications running on same schema and now i want to move one application to new server, new schema,
    Now i need to know how much space is required for this application to host on the new server, so i should find the application size and application data size in the current server, your hep is appreciated. thanks in advance.
    Regards

    Hi,
    Would i request you to help me to measure schema size/(APEX)application data size.
    I've 3 applications running on same schema and now i want to move one application to new server, new schema,
    Now i need to know how much space is required for this application to host on the new server, so i should find the application size and application data size in the current server, your hep is appreciated. thanks in advance.
    Regards

  • Help needed in getting the Role Description from BOL Entities

    Hi All,
    I am trying to retrieve BP Role and BP Role Description and display the details at the top of account over view page.
    I am fetching the BP Role details using 'BuilRolesRel'. but i am not able to find any BOL Query to get Role Description.
    Any pointers on this is really very very helpful.
    Thanks,
    Udaya

    Hello Udaya,
    under BuilRolesRel there is a entity BuilRoles and this entity has an Attribute RLCTITLE.
    this is a Description of the role.
    Good Luck
    Eli Steklov
    Please Reward Points if it Helped

  • Help Needed! Getting the files off the recovery disc and onto the computer. How?!?

    Okay, I shut down my computer a few hours ago like normal and I restarted it again when I wanted to go on it which was later this evening. A screen popped up that said press enter to continue and a bunch of code, so I did just pressed 'Enter' like it asked. Then another screen came up that said,  "Your computer could not start up, we are finding and fixing the problems, ect ect." And then there was a percentage at the bottom of how much was completed.
    So after it was finished, my computer started to totally restart, like I just bought the computer. It had me remake everything. And when it was all done EVERYTHING except for the programs that came with the computer where gone. I noticed a recovery disc and how it was almost full, and it said it has all my programs on it and to not delete it. Well okay if it has all my programs....
    How in the world do I get everything from the recovery disc back onto my computer? 
    Please comment on any information that can help!

    The recovery partition on the hard drive does not have your programs/files. It holds the files to reinstall Windows and all original software/drivers that came on the laptop. In other words, it does exactly what just occurred.
    ******Clicking the Thumbs-Up button is a way to say -Thanks!.******
    **Click Accept as Solution on a Reply that solves your issue to help others**

  • How to get the previous price of the  list price  in a order

    Hi All,
    I need to get the previous price of the condition type in an order  to calculate the %change of price.
    for ex: the conditon ZXXX has price 600 and its changed to 400 now .( by changing the quantity etc ).
    when the price value is changing to 400 , I need to capture  the value of 600 in another condition type.
    how can i acheive this ? Any idea?
    Please provide some pointers on it.
    Thanks in advance.
    Swapna.

    Hi Viraylab,
                     check  <b>VBAP-NETPR</b> field of table <b>VBAP</b>
    It gives the net price corresponding to a line item.
    Goto Tcode VA03.See the <b>item overview</b> tab U will get <b>Net Price</b> field for indivisual line item.
    Reward points if helpful.
    Regards,
    Hemant

  • The backup disk image "/Volumes/Data/David Witkowski's Mac Pro.sparsebundle" is already in use.  Whenever Time Machine starts to backup to Time Capsuel I get the previous error message. I need some help to fix this.

    The backup disk image “/Volumes/Data/David Witkowski’s Mac Pro.sparsebundle” is already in use.  Whenever Time Machine starts to backup to Time Capsuel I get the previous error message Where can I find this disk image?. I need some help to fix this.
    Thanks,
    David W

    There are multiple answers and solutions if you look just to the right under the heading of More Like This.

  • I have an iphone 4, need to get to cellular network data, it will only go as far as cellular on the phone, I have straight talk service. Please help! I cannot send or receive pics!

    I have an iphone 4, need to get to cellular network data, it will only go as far as cellular on the phone, I have straight talk service. Please help! I cannot send or receive pics!

    Is there any chance that you must have it in the package of your provider as an option?

  • Get the Current Quarter  and Current Week from date

    Hi,
    I want to get the Current quarter and Current week from a given date, which function modules should i use?
    I tried using function module - 'HR_99S_GET_QUARTER' for getting the quarter but it is throwing an error while loading data. Moreover it doesnt exist in BI7.
    Similarly for current week.
    Please help. Sample code snippets would be appreciated.
    Thanks
    Jaya

    You can use FORM time_conversion wich is the one used by standard in Update Rules:
    You can select whether convert 0CALDAY to 0CALWEEK or whatever infobject formats you prefer...
      perform time_conversion
                using  '0CALDAY'
                       '0CALMONTH'
                        p_input_date
                        l_fscvtval
                changing RESULT
                         c_t_idocstate
                         c_subrc
                         c_abort.
      if c_subrc <> 0 or c_abort <> 0.
        exit.
      endif.
    form time_conversion
                   using i_timnm_from type rsiobjnm
                         i_timnm_to   type rsiobjnm
                         i_timvl
                         i_fiscvarnt  type t009b-periv
                   changing e_timvl
                            c_t_idocstate  type rsarr_t_idocstate
                            c_subrc   like sy-subrc
                            c_abort   like sy-subrc. "#EC *
    data: l_timvl  type rsd_chavl,
          l_result type rsd_chavl.
      IF i_timvl CO ' 0'.
        CLEAR e_timvl.
        EXIT.
      ENDIF.
      l_timvl = i_timvl.
      CALL FUNCTION 'RST_TOBJ_TO_DERIVED_TOBJ'
        EXPORTING
          i_timnm_from             = i_timnm_from
          i_timnm_to               = i_timnm_to
          i_timvl                  = l_timvl
          I_FISCVARNT              = i_fiscvarnt
          I_BUFFER                 = rs_c_true
        IMPORTING
          E_TIMVL                  = l_result
        EXCEPTIONS
          INCOMPATIBLE_TOBJS       = 1
          NO_INPUT_VALUE           = 2
          FISCVARNT_MISSING        = 3
          INPUT_NOT_NUMERIC        = 4
          WRONG_DATE               = 5
          WRONG_FISCPER            = 6
          X_MESSAGE                = 7
          OTHERS                   = 8
      e_timvl = l_result.
    ENDFORM.                  "TIME_CONVERSION

  • How to get the previous record value in the current record plz help me...

    In my sql how to get the previous record value...
    in table i m having the field called Date i want find the difference b/w 2nd record date value with first record date... plz any one help me to know this i m waiting for ur reply....
    Thanx in Advance
    with regards
    kotresh

    First of this not hte mysql or database forum so don;t repeate again.
    to get diff between two date in mysql use date_format() to convert them to date if they r not date type
    then use - (minus)to get diff.

Maybe you are looking for