FM to get 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

Hi Kapil,
You can follow the logic below:
data:
l_date like sy-datum, **TODAY
l_date2 like sy-datum, **Previous Sunday
data:
l_daynr like HRVSCHED-DAYNR.
*Get today's date
l_date = sy-datum.
*Gey today's day (Monday, Tuesday, etc.)
CALL FUNCTION 'HRIQ_GET_DATE_DAYNAME'
EXPORTING
langu = 'EN'
date = l_date
IMPORTING
daynr = l_daynr.
CASE l_daynr.
*If it is Monday
WHEN 1.
-Subtract 2 days for the previous Sunday
CALL FUNCTION 'HR_SEN_CALE_DAYS_DATE'
EXPORTING
id_date = l_date
id-operator = '-'
is_duration = 2
IMPORTING
ed_date = l_date2.
*If it is Tuesday
WHEN 2.
CALL FUNCTION 'HR_SEN_CALE_DAYS_DATE'
EXPORTING
id_date = l_date
id-operator = '-'
is_duration = 3
IMPORTING
ed_date = l_date2.
*If it is Wednesday
WHEN 3.
CALL FUNCTION 'HR_SEN_CALE_DAYS_DATE'
EXPORTING
id_date = l_date
id-operator = '-'
is_duration = 4
IMPORTING
ed_date = l_date2.
*If it is Thursday
WHEN 4.
CALL FUNCTION 'HR_SEN_CALE_DAYS_DATE'
EXPORTING
id_date = l_date
id-operator = '-'
is_duration = 5
IMPORTING
ed_date = l_date2.
*If it is Friday
WHEN 5.
CALL FUNCTION 'HR_SEN_CALE_DAYS_DATE'
EXPORTING
id_date = l_date
id-operator = '-'
is_duration = 6
IMPORTING
ed_date = l_date2.
*If it is Saturday
WHEN 6.
CALL FUNCTION 'HR_SEN_CALE_DAYS_DATE'
EXPORTING
id_date = l_date
id-operator = '-'
is_duration = 7
IMPORTING
ed_date = l_date2.
*If it is Sunday
WHEN 7.
CALL FUNCTION 'HR_SEN_CALE_DAYS_DATE'
EXPORTING
id_date = l_date
id-operator = '-'
is_duration = 8
IMPORTING
ed_date = l_date2.
ENDCASE.
Regards,
Dilek

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

  • How to get previous day data if i dont have current day data.

    Hello Gurus,
    I have a stock levels data in ODS. when there is no movements, we are not getting any stocks into ODS. So we have to get previous day data as it is for current day data into another ODS.
    Could you please help me in this regard.
    Thanks in advance,
    Rama

    Rama -    
            0CALDAY can't help us in this scenario .
    Step 1 :
        To do this - You have to add one ZDATE (InfoObject ) to 1st ODS. ZDATE is updated by itself from current date of system  when ever you are loading data to 1st ODS.
    Step 2:
       You have to do full update to 2nd ods.At the selection screen of InfoPackage  (from 1st ODS to 2nd ODS ) you have to write following code for ZDATE.
    pseudo Code:
    1) Select fields "Rec_INSERT","Time stamp","Request Status" and "Request ID"  where ICUBE = ODS1 from table "RSMONICDP"
    2) Populate above selected fields data in INTERNAL TABLE
    3) Sort INTERNAL TABLE by Time stamp .
    4)
         If (Record Count = ' 0 ' for current date in internal table )
         update records from  ODS1 to ODS2 where ZDATE = "yesterday date"
         else
         update records from ODS1 to ODS2 where ZDATE= "today date"
         endif.
    Make sure this is full update not delta update from ODS1 to ODS2
    I am sorry, I m not good in Coding but I am sure if  u use this logic,You can meet your requirement.
    I hope you can understand my logic. Let me know if you have any questions,
    Anesh B .

  • Get previous bill date using SQL

    Hi,
    I am table which holds records for bill generation. I have column name gene_bill_date which is date field and it holds a value the date on which the particular bill was generated.
    Now I am trying to get previous bill date, not the current bill date. I can to Max(gene_bill_date) to get current bill date, but how do I get previous bill date?
    thanks

    Hi,
    Sorry, it's unclear what you're asking.
    You didn't post any sample data, so I'll use the scott.emp table to illustrate. Let's say we're interested in deptno=30 only, just to reduce the output from 14 rows to 6.
    If, for every row, you need to know the most recent gene_bill_date before the one on that row, you can do something like this:
    SELECT     ename
    ,     hiredate
    ,     LAG (hiredate) OVER (ORDER BY hiredate)     AS prev_hiredate
    FROM     scott.emp
    WHERE     deptno     = 30
    ;Output:
    ENAME      HIREDATE    PREV_HIREDA
    ALLEN      20-Feb-1981
    WARD       22-Feb-1981 20-Feb-1981
    BLAKE      01-May-1981 22-Feb-1981
    TURNER     08-Sep-1981 01-May-1981
    MARTIN     28-Sep-1981 08-Sep-1981
    JAMES      03-Dec-1981 28-Sep-1981Are you only interested in the 2 most recent dates in the whole result set?
    If so, do a Top-N Query , like this:
    WITH     got_r_num     AS
         SELECT     ename
         ,     hiredate
         ,     RANK () OVER (ORDER BY hiredate  DESC)     AS r_num
         FROM     scott.emp
         WHERE     deptno     = 30
    SELECT     *
    FROM     got_r_num
    WHERE     r_num     <= 2
    ;Output:
    ENAME      HIREDATE         R_NUM
    JAMES      03-Dec-1981          1
    MARTIN     28-Sep-1981          2 
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.

  • Getting previous weeks data based on parameters entered

    I am using CRXI. I have a RT that gives me the current week data but I need to be able to report on previous week data based on the paraments so if I enter dates between sunday and saturday of one week it will report on those data plus the same days of the previous week. I looked at the lastfullweek function, but not sure how to implement it in my scenerio. any ideas?
    Ralph

    That worked, thankyou. My next question along the same lines, is I am also having a third column that will indicate the percent change. for example
    Current             Previous              % Change
    97                    108
    I am trying to computer the % change between curent and previous basically it would look at previous as being the control and computer positive or negative based on what current is. I can do the math formulas, but I'm not sure what to comute to find the % change.
    Ralph

  • Deriving previous Fiscal Period based on current date

    Hi All,
    I have a requirement wherein I need to derive the previous fiscal period based on the current date. Is there any standard FM to get the same? If not can you let me know if there is any other way of deriving it?
    Thanks
    Sundar

    Hi Srinivas, thanks for your reply. What you have suggested will work fine if I am looking for current fiscal period. I want previous fiscal period. How do I get that?
    Thanks
    Sundar

  • Getting the Sunday dates using Next_Day

    The requirement is:
    Get the Sunday of this week and Sunday of the last week. As system date is 02-July, this Sunday is 01-July and last week Sunday is 24-Jun. If say suppose the system date is 01-July, then this Sunday should be 24-Jun and last Sunday should be 17-Jun. I tried something like :
    Select
    Next_Day(sysdate-8,'SUNDAY') sunday,
    Next_Day(sysdate,'SUNDAY') End_Sunday,
    To_Char(Next_Day(sysdate-8,'SUNDAY'),'YYYYMMDD') sun_mm,
    1 Fl
    From
    Dual
    Union
    Select
    Next_Day(sysdate-16,'SUNDAY') sunday,
    Next_Day(sysdate-16,'SUNDAY')+7 End_Sunday,
    To_Char(Next_Day(sysdate-16,'SUNDAY'),'YYYYMMDD') sun_mm,
    2 Fl
    From
    Dual
    I know the above doesn't work due to -16. Need some help in meeting the requirement.
    Thanks
    Chaitanya.S.S.K

    Micheals,
    this?
    SQL> alter session set nls_territory=germany;
    Session altered.
    SQL>  WITH t AS  ( SELECT SYSDATE AS DT FROM dual
      2               UNION ALL
      3       SELECT TO_DATE('07/01/2007','MM/DD/YYYY') FROM dual
      4         UNION ALL
      5       SELECT TO_DATE('07/02/2007','MM/DD/YYYY') FROM dual
      6       UNION ALL
      7       SELECT TO_DATE('06/30/2007','MM/DD/YYYY') FROM dual)
      8   SELECT DT, CASE WHEN TO_CHAR(DT,'DY')='SUN' THEN
      9                       TRUNC(dt,'d')-7
    10       ELSE 
    11           TRUNC(dt,'d')
    12       END last_sunday
    13   FROM  t;
    DT       LAST_SUN
    03.07.07 02.07.07
    01.07.07 18.06.07
    02.07.07 02.07.07
    30.06.07 25.06.07
    SQL> alter session set nls_territory=america;
    Session altered.
    SQL>  WITH t AS  ( SELECT SYSDATE AS DT FROM dual
      2               UNION ALL
      3       SELECT TO_DATE('07/01/2007','MM/DD/YYYY') FROM dual
      4         UNION ALL
      5       SELECT TO_DATE('07/02/2007','MM/DD/YYYY') FROM dual
      6       UNION ALL
      7       SELECT TO_DATE('06/30/2007','MM/DD/YYYY') FROM dual)
      8   SELECT DT, CASE WHEN TO_CHAR(DT,'DY')='SUN' THEN
      9                       TRUNC(dt,'d')-7
    10       ELSE 
    11           TRUNC(dt,'d')
    12       END last_sunday
    13   FROM  t;
    DT        LAST_SUND
    03-JUL-07 01-JUL-07
    01-JUL-07 24-JUN-07
    02-JUL-07 01-JUL-07
    30-JUN-07 24-JUN-07

  • Problem with getting the Grouping Separator based on Current Locale

    Hi
    I have created a java swing application. In which I try to get the grouping separator based on System language and location(Control panel).
    But it always take comma as GroupingSeparator.
    I set the region and language to South Africa. Now It should take blank space as a GroupingSeparator but it takes comma.Here is my code:
    private char mcharDecimalSeparator;
    private char mcharGroupingSeparator;
    DecimalFormatSymbols objDecimalFormat;
    mcharDecimalSeparator = objDecimalFormat.getDecimalSeparator();
    mcharGroupingSeparator = objDecimalFormat.getGroupingSeparator();Any help will be appreciated '
    Thanks
    Sonal

    From what I see here I'd say you'd get an NPE at line 4...
    The point is: why do you care?
    You should leave parsing and formatting to localeaware library classes like NumberFormat.
    bye
    TPD

  • How to get previous month data from current month values

    Hi Experts,
    I have made one universe from BW Query in which Fiscal year period is entered in interval.
    I have made a universe from that and want to develop webI reports on top of that.
    In my webI reports, i have used one cross tab. In Rows section i have added Company Code and in Column section i have used Fiscal Year/Period and in Value section i have added Sales Value. I want this value of previous month.
    Requirement:
    Ex.
                            Feb'09          Mar'09     and so on...
    Comp_code1   Sales of Jan'09         Sales of Feb'0f         and so on....
    I am getting this.
    Ex.
                            Feb'09          Mar'09     and so on...
    Comp_code1   Sales of Feb'09         Sales of Mar'09         and so on....
    I hope i have clear my requirements.
    Please help as soon as possible.
    Thanks in Advance,
    Rishit

    Hi Rishit,
    Follow the below steps to get the desired result.
    Step1: Convert your fiscal year period from char to a date in your database or in your designer however its feasible.
    to_date('substr('009.2009',2)','mm.yyyy')
    you will get the result 01 sep 2009
    Step2: Convert this format to 01/09/2009 by using date functions.
    Step3: Create a Detail associated to the 'date' field (typically your fiscal period).
    Step4: Create a cross tab Like : Rows section should have Company Code and in Column section should have 'date'(created detail) and in Value section should be Sales Value.
    you should get the following result.
    01/02/2009 01/03/2009 and so on...
    Comp_code1 Sales of Feb'09 Sales of Mar'09 and so on....
    Step5: Use the following formula in your Column (date) formula bar.
    =(<date>-1)-DayNumberOfMonth(<date>-1)+1
    You will get the following result:
    01/01/2009 01/02/2009 and so on...
    Comp_code1 Sales of Feb'09 Sales of Mar'09 and so on....
    Format the cell according to your reruirement.
    Let me know if you will get any break in the above steps.
    Regards,
    Swati.

  • Getting Previous Period Date

    Hello - I'm wondering if anyone can help.
    Im currently developing a tool which filters and aggregates some data. I have the user to be able to select a period for example - 01/01/2010 to 07/10/2010.
    Then, I want to compare the selected data with the same period of the previous.
    I understand that I think I get do this with the .getTime function but Im at a loose end as to how to achieve this. Another example is if the user selects 2 years, e.g. 01/01/2010 - 01/01/2008 the comparison period would be 01/01/2006 - 01/01/2008
    Please help!
    Thanks
    Craig
    public function filterAll(evt:Event):void
                    var tmpDate:Date = selectedFrom.selectedDate
                    var tmpDate2:Date = selectedTo.selectedDate
                    tmpDate.time = tmpDate.getTime();
                    tmpDate2.time = tmpDate2.getTime(); // this needs to be the previous period
                    trace (tmpDate)
                    trace (tmpDate2) // trace previous period

    Think I've done it! Here is the function for anyone that is interested!
    public function getPreviousPeriod(From:Date,To:Date, fromOrTo:String):Date
                    var diffNum:Number = From.getTime() - To.getTime();
                    var tmpDate:Date = new Date
                    var tmpDate2:Date = new Date
                    tmpDate.time = From.getTime();
                    tmpDate2.time = To.getTime();
                    tmpDate.time = tmpDate.getTime() + diffNum
                    tmpDate2.time = tmpDate2.getTime() + diffNum
                    if (fromOrTo == "From")
                        trace ("FROM")
                        return tmpDate;
                    else
                        trace ("TO")
                        return tmpDate2;

  • Getting Previous year Data

    Hi,
    My db has following:
    Year Sales Target (10 % more of Previous year's Sales)
    2007 10000 -
    2008 15000 11000
    2009 18000 19500
    2010 20000 19800
    2011 10000 22000
    I have a filter set to retrieve data for Current Year and (Current - 3) years, and I get following
    Year Sales Target (10 % more of Previous year's Sales)
    2008 15000 0
    2009 18000 19500
    2010 20000 19800
    2011 10000 22000
    I want to display the value (Target) for 'Year 2008' (as the previous year sales data is present);
    Is it possible to get it?
    Regareds,
    Jitendra

    Matt!
    Would you please explain, how to achieve this in Pivot?
    Regards,
    Jitendra

  • How to get previous month's values for current month

    Hi..
    I have a requirement on a report, where for a particular month, the key figure value should be from the previous month.
    Eg: KF1 value for Sept 2007 should come from Aug 2007, KF value for Dec 2007 should be the value of Nov 2007, etc.
    There are other key figures on the report which do not need this logic. It is only for one key figure.
    Should we do this on the backend or front-end, and how? Any tips will be appreciated.
    Thanks
    R.

    hi,
    Use a Restricted Keyfigure.
    Drag your KF1 and Drag Calandar Month with a Variable Current Cal Month with variable Offset to -1.
    KEERTTHi

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Auto filling forms based off of previously entered data.

    Looking for a way to create a feild that will auto fill based on previously entered data.  For example.
    First________
    Middle_______
    Last_________
    Ideally i could take someones names they enter and auto fill a feild for Last, First, Middle or even a Last, First, Middle Initial.
    any thoughts??
    Thanks!

    Played around with this today...been very busy with other work and got this to work for Last, First mi
    // Get the field values, as strings
    var i = this.getField("first").valueAsString;
    var j = this.getField("middle").valueAsString;
    var k = this.getField("last").valueAsString;
    // Set this field's value if both fields are not blank
    // otherwise, set this field to blank
    if (i && j && k) {
         event.value = k + ", " + i + " " + j.slice(0, 1);
    } else {
         event.value = "";
    I am brand new to this and was curious are these "var i , j, and k" just for this field.  Or will these continue to be how I refer to the first , middle and last fields?
    Also, other than just playing around with this, is there another way to learn this stuff?  I find it fascinating.
    all the best

  • I'm in cycle mode, and 'merge' is clicked in preferences. However, when I record, my previous track data keeps getting overwritten. Does anyone know what I'm doing wrong. Interestingly, I can still see the data in the region.

    I'm in cycle mode, and 'merge' is clicked in preferences. However, when I record, my previous track data keeps getting overwritten. Does anyone know what I'm doing wrong. Interestingly, I can still see the data in the region.

    jamestait wrote:
    when I record, my previous track data keeps getting overwritten.
    since you didn't specify, are you recording in a single take?
    http://www.bulletsandbones.com/GB/GBFAQ.html#multipassrecording
    (Let the page FULLY load. The link to your answer is at the top of your screen)

Maybe you are looking for