Last Working Day Variable

Hello Folks,
Any idea about the Std Variable for the last working day calculation.
I have a customised Characteristics to which I want to use this variable then what steps should I follow or by installing it through  content will it directly get attached, I mean will be available while choosing the variables for this characteristics in a query.
Thanks,
Suyog.

Hi,
Create a customer exit variable to get last working day of the month and write the following logic in ZXRSRU01:
*Last working day of the given period(Cal Yr/Month)
WHEN '<Customer exit variable>'.
DATA : BEGIN OF i_holidays OCCURS 0.
        INCLUDE STRUCTURE iscal_day.
DATA : END OF i_holidays,
      v_fdate LIKE sy-datum,
      v_ldate LIKE sy-datum.
    IF i_step = 2.
      READ TABLE i_t_var_range INTO loc_var_range
            WITH KEY vnam = '<Cal yr/month selection variabel>'.
      IF sy-subrc = 0.
          CONCATENATE loc_var_range-low
                      '01' INTO v_fdate.
* to get last day of the given period
          CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'
            EXPORTING
              day_in            = v_fdate
            IMPORTING
              last_day_of_month = v_ldate.
*To get holiday list in the given period
            CALL FUNCTION 'HOLIDAY_GET'
              EXPORTING
                holiday_calendar = <Fact cal ID>
                factory_calendar = <Fact cal ID>
                date_from        = v_fdate
                date_to          = v_ldate
              TABLES
                holidays         = i_holidays.
          SORT i_holidays BY date DESCENDING.
          DELETE ADJACENT DUPLICATES FROM i_holidays.
          DO.
            READ TABLE i_holidays WITH KEY date = v_ldate.
            IF sy-subrc NE 0.
              v_ldate = v_ldate - 1.
            ELSE.
              l_s_range-sign = 'I'.
              l_s_range-opt = 'EQ'.
              l_s_range-low = v_ldate.
              APPEND l_s_range TO e_t_range.
              CLEAR:l_s_range.
                EXIT.
              ENDIF.
          ENDDO.
     ENDIF.
    ENDIF.
Assumptions:
  Running a report by entering Cal yr/month as selection value.
hope it works...
regards,
Raju

Similar Messages

  • Is it possible to create a variable in bex with the last work day?

    Hi Gurus
    Is it possible to create a variable in bex with the last work day?
    Actually end-user every day open queries,
        - Put in selection date day - 1 or
        - put last Friday if the day is Monday or
        - put last Thursday if the day is Monday and Friday is holiday (in a calendar for example 25 the December).
    Please do the needful. It is urgent
    Thanks in advance
    Raj

    Try this logic in a customer exit:
    DATA:  l_s_range TYPE rsr_s_rangesid.
    DATA:  X_PERIOD LIKE T009B-POPER,
               X_YEAR   LIKE T009B-BDATJ.
      CASE I_VNAM.
      WHEN 'ZPREVWORKDAY'.
        DATA: l_DayOfWeek(1) TYPE C,
              l_act_date     TYPE d,
              l_prev_date    TYPE d.
        l_act_date = sy-datum.
        CALL FUNCTION  'DATE_COMPUTE_DAY'
             EXPORTING DATE = l_act_date
             IMPORTING DAY  = l_DayOfWeek.
        CASE l_DayOfWeek.
          WHEN '1'.
            l_prev_date = l_act_date - 3.
          WHEN '2'.
            l_prev_date = l_act_date - 1.
          WHEN '3'.
            l_prev_date = l_act_date - 1.
          WHEN '4'.
            l_prev_date = l_act_date - 1.
          WHEN '5'.
            l_prev_date = l_act_date - 1.
          WHEN '6'.
            l_prev_date = l_act_date - 1.
          WHEN '7'.
            l_prev_date = l_act_date - 2.
        ENDCASE.
        l_s_range-low  = l_prev_date.
        APPEND l_s_range TO e_t_range.
    ENDCASE.
    Edited by: Tyler Blouse on Feb 13, 2008 8:28 PM

  • Function module for getting teh last working day of a month.

    Hi GURUS,
    this is criteria,please help me 
    if V_T001B- FRYE1 < month entered in selection screen
              Then throw the error message
                Else
    Find the previous period and its last working day from the function module
          (i..e Assume entered date as June 2 2009 then
                   Period 6 -1 = 5.
         Pass the month 05 to function module then
                   Find last working day.
                   Keep it in a variable (V_LAST_PRD_WRKDAY)
                           Proceed further.
    thanks in advance,
    Rajeev

    Hi Rajeev,
    You can use Function Module LAST_DAY_IN_PERIOD_GET.
    Ex:
          CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
            EXPORTING
              i_gjahr = p_gjahr
              i_periv = lwa_t009b-periv
              i_poper = lwa_t009b-poper
            IMPORTING
              e_date  = s_audat-high.
    Regards,
    Ravi K

  • Dynamic selective deletion of last working day in cube

    Hi experts
    I have studied this document:
    http://scn.sap.com/community/data-warehousing/netweaver-bw/blog/2013/08/06/selective-deletion-in-process-chain
    We need to delete each month at the 6th working day all records of the last working day of the previous month.
    Thereafter we will have to reload the last working day of the previous month again.
    This means there are 2 steps to do:
    1. step:
    create program as described in the link above; this z-program will be used in process chain variant.
    2. step:
    ABAP variable in infopackage which will reload the last working day of previous month.
    Do you have the correct coding samples for both steps available?
    Thanks.

    Hi Thomas,
    I just realized that you should use LT_THX_SEL instead of L_THX_SEL. I corrected your code as:
    REPORT GP00733D41Q8YF4PERY61Y1HNAP .
    TYPE-POOLS: RSDRD, RSDQ, RSSG.
    DATA:
      L_UID       TYPE RSSG_UNI_IDC25,
      L_T_MSG     TYPE RS_T_MSG,
      L_THX_SEL   TYPE RSDRD_THX_SEL.
      L_UID = '00733D41Q8YF4PERYNZWX2EY9'.
      IMPORT I_THX_SEL TO L_THX_SEL
        FROM DATABASE RSDRBATCHPARA(DE) ID L_UID.
    *  DELETE FROM DATABASE RSDRBATCHPARA(DE) ID L_UID.
      data: wa_tab type RSDRD_S_RANGE.
    data: lt_tab type RSDRD_T_RANGE.
    wa_tab-sign = 'I'.
    wa_tab-option = 'EQ'.
    wa_tab-keyfl = 'X'.
    wa_tab-low = '20140101'.
    append wa_tab to lt_tab.
    clear l_thx_sel.
    LT_THX_SEL-IOBJNM = '0CALDAY'.
    LT_THX_SEL-TRANGE[] = LT_TAB[].
    INSERT LT_THX_SEL into table L_THX_SEL.
      CALL FUNCTION 'RSDRD_SEL_DELETION'
           EXPORTING
                I_DATATARGET      = 'ZCFM_C11'
                I_THX_SEL         = L_THX_SEL
                I_AUTHORITY_CHECK = 'X'
                I_THRESHOLD            = '1.0000E-01'
                I_MODE                 = 'C'
                I_NO_LOGGING           = ''
                I_PARALLEL_DEGREE      = 0
                I_NO_COMMIT            = ''
                I_WORK_ON_PARTITIONS   = ''
                I_REBUILD_BIA           = ''
                I_WRITE_APPLICATION_LOG   = 'X'
           CHANGING
                C_T_MSG                     = L_T_MSG.
      export l_t_msg to memory id sy-repid.
      UPDATE RSDRBATCHREP
        SET  DELETEABLE = 'X'
    I hope that will be the final solution Thomas.
    Regards
    Yasemin...

  • Weekly schedule line should pass to last working day of the week in SAg

    HI,
    In a scheduling agreement when we have weekly or monthly schedules the system displays the date in the screen as 12/2010 or 13/2010 for say a weekly schedule.
    However when the data is stored in the table the delivery date is always the first working day of the week. In this case when the week is 13/2010 the data is stored in the table as 22/03/2010.
    Is there any way to change this to the last working day of the week?
    We have some config related to define delivery intervals in IMG--> Sales and Distribution --> Sales --> Sales Documents --> Scheduling Agreements with Delivery Schedules --> Define Delivery Intervals. Will this help solve my issue? If it solves what is the procedure behind this?
    Request you to provide your inputs.
    Thank You, Lakshmikanth

    Hi,
    Seems the delivery split concept is different from this requirement. Can Delivery intervals concept help us or not? IMG--> Slaes and Distribution --> Sales --> Sales Documents --> Scheduling Agreements with Delivery Schedules --> Control EDI Inbound Processing --> Define Delivery Intervals.
    What is the procedure and assignment details for delivery intervals concept?
    Thanks, Lakshmikanth

  • How to create a recurrent event on the first or last work day of the month

    The lightning calendar allows selection of the first and last day of the month for recurrent events but for business I need to use the first and last WORK day of the month (Monday - Friday) to schedule particular tasks. In the calendar preferences under 'View' I can select the days that make up the work week but this does not transfer to an option in recurrent events. Is there another way to do this or is it just not available?

    Hi there,
    do know for the UlltimateBootCD4Win? This from CD bootable WinXP-BartPEedition with additional tools gives you the ability to make such things like partitioning, backup or formatting your HDD.
    It has many more applications which help you to maintain your system without booting your original OS.
    So I think that this CD will solve your partitioning issues.
    Heres a link: www.ubcd4win.com/
    Just try it and tell me your opinion.
    Nice weekend and greetings from the sunny south ;)

  • Display data for last working day of month

    Hi
    I am trying to chart values for the last six years but only to plot the value for the last working day of the month, except for the current month where I am taking an average of the month so far. Everything I've tried has so far failed spectacularly. Has anyone resolved a similar problem?

    If I understand your dilemma correctly, you may want to create a cross-tab and then create the chart off of the cross-tab. Is the data in your tables that you want to chart on something like this:
             4/30   5/30   6/30   7/31   8/29       Sept.
    Row 1    20      30      10      25      20    (avg for month) 
    Row 2    5         10      8       15     15    (avg for month)
    etc.
    If so, 1) can you show an example of the data and 2) what kind of chart do you want to create?

  • Work day of a calendar

    Hi all,
    I am searching for a FM which will say 3rd work day of a factory calendar or 4th work day of a factory calendar etc. I could see there are few FMs to say first work day - last work day but not the Nth work day. If we input some date and factory calendar, we should get which work day it is. For example if we give 09/02/2010 and factory calendar name it should return as 2nd workday etc. Any help will be appreciated..
    Thanks in advance.
    Moderator message: date calculation questions = FAQ, please search before posting.
    locked by: Thomas Zloch on Sep 15, 2010 4:39 PM

    hi,
    Please check with this fm DATE_CONVERT_TO_FACTORYDATE.
    Keerthi

  • Payment terms based on working days

    Dear colleagues
    I would like to base payment terms on, for example, the last working day of the month, or the last working day of the trimester instead of working with fixed days.
    Would someone know if this is possible and if so, how can that be arranged?
    Thanks and regards,
    Marlies

    Dear,
    as far as I know, this is not possible into the SAP Standard System.
    I'm sorry about it.
    Mauri

  • FUNCTION MODULE TO FIND LAST WORKING DY OF THE MONTH

    FM to find the month end working day , if the month end falls on sunday or saturday or any other public holiday, it shud exclude that day and give me the last working day of that month.
    Example: Octoberr 2004 month end falls on saturday and sunday. hence the last working day of the month will be 29 october 2004.
    Pls provide me this FM , concerned points will eb awarded.
    Rgds
    Ramada

    hi,
    kindly use this FM.
    it will help u.
    data : your_cal_id like t001w-fabkl,
            max_date  like sy-datum.
    CALL FUNCTION 'LAST_FACTORYDATE_GET'
             EXPORTING
                  factory_calendar_id          = your_cal_id
             IMPORTING
                  DATE                         = max_date
             EXCEPTIONS
                  FACTORY_CALENDAR_NOT_FOUND   = 1
                  FACTORY_CALENDAR_ID_MISSING  = 2
                  CALENDAR_BUFFER_NOT_LOADABLE = 3
                  OTHERS                       = 4
    rgds
    anver
    if hlped mark points

  • Working day formula that excludes weekends and holidays in WEBI

    Hi Guys,
    Can we calculate a working day formula that excludes weekends and holidays in WEBI OR in Universe?
    The universe I am working on is using stored procedures, so there are no joins or modelling done. Although there is a workday stored proc  that I can bring in the universe.
    I am just thinking if there is no modelling or joins done in the universe how will this help me in webi?
    Your suggestions will be very helpful.
    Thanks,
    Jitan

    One more suggestion I need from you  -
    I have a Work_Calendar_VW that has the following columns -
    Calendar_Date - 5/1/2014
    Calendar_Year - 2014
    Calendar_Month - 5
    Calendar_Day - 1
    Work_Day - 1
    Day_Type - WD (Work Day)  For Weekends this will be displayed as WE
    The columns have all dates for current year in SQL Server.
    I am going to pull this into the universe and create 2 derived tables to calculate MTD Day counts.
    Derived Table 1  - Calculate Yest Work Day... this will remove all the weekends and holidays and give me the last working day. This includes couple of case statments to check each day if it's a working day or weekend.
    For Work Day the above code will be 1 and for weekend 0
    Derived Table 2  - This will give me the count of working days in current month using the above view and Derived table 1 Below is the code  -
    SELECT COUNT(*)
    FROM Work_Calendar_VW
    WHERE [Work_Day] = 1 AND
       (Calendar_Date BETWEEN CAST(CONVERT(VARCHAR(25),MONTH(LastWoringkday()),101) + '/01/'
       + CONVERT(VARCHAR(25),YEAR(LastWoringkday()),101) AS DATE)
      AND LastWoringkday()).
    I cannot do joins because this universe has been built using stored proc and would like to implement this in BO universe.
    let me know if this is the right approach.
    Thanks,
    Jitan

  • Show Working days transaction on Weekends and Holidays

    Hi,
    I have an objective to show last working days transaction (consider Friday) on Saturday and Sunday, also
    if the next day is also a Holiday then i have to post previous days transactions on Holiday too.
    Example:I need to show Friday Sep 1,2006 Transactions on
    Sep 2,2006
    Sept 3,2006
    Sep 4,2006 (Labor Day -- Holdiay)
    Restriction:PL/SQL not allowed( i know it is hard to believe ..sorry)
    Here is the Query that i have written which takes care of Sat and Sundays.I am having problem with Posting the data on Holidays.
    -- This Query selects all working days only
    select TRADE_DATE,
    Case when PORT_ID = 'FFSEX5' then SUM(PRINCIPAL) End as FFSDirect,
    Case when PORT_ID = 'FFSEX5' then trunc(AVG(RATE),2) End as FFSDirect_Avg,
    Case when PORT_ID in ('FFSEX3', 'FFSEX2', 'CLS') then SUM(PRINCIPAL) End as FFSBroker,
    Case when PORT_ID in ('FFSEX3', 'FFSEX2', 'CLS') then trunc(AVG(RATE),2) End as FFSBroker_Avg,
    Case when PORT_ID in ('EPIEX3', 'ACK', 'ETCEX3', 'CKD') then SUM(PRINCIPAL) End as Euro3,
    Case when PORT_ID in ('EPIEX3', 'ACK', 'ETCEX3', 'CKD') then trunc(AVG(RATE),2) End as Euro3_Avg,0 AS FLAG
    FROM CV_TRADE_HIST
    Group by port_id,Trade_date
    Union
    -- Accumulates Saturdays
    select (TRADE_DATE+1) as Trade_Date,
    Case when PORT_ID = 'FFSEX5' then SUM(PRINCIPAL) End as FFSDirect,
    Case when PORT_ID = 'FFSEX5' then trunc(AVG(RATE),2) End as FFSDirect_Avg,
    Case when PORT_ID in ('FFSEX3', 'FFSEX2', 'CLS') then SUM(PRINCIPAL) End as FFSBroker,
    Case when PORT_ID in ('FFSEX3', 'FFSEX2', 'CLS') then trunc(AVG(RATE),2) End as FFSBroker_Avg,
    Case when PORT_ID in ('EPIEX3', 'ACK', 'ETCEX3', 'CKD') then SUM(PRINCIPAL) End as Euro3,
    Case when PORT_ID in ('EPIEX3', 'ACK', 'ETCEX3', 'CKD') then trunc(AVG(RATE),2) End as Euro3_Avg,0 AS FLAG
    FROM CV_TRADE_HIST Where to_char(trade_date,'dy')='fri'
    Group by port_id,Trade_date
    Union
    -- Accumulates Sundays
    select (TRADE_DATE+2) as Trade_Date,
    Case when PORT_ID = 'FFSEX5' then SUM(PRINCIPAL) End as FFSDirect,
    Case when PORT_ID = 'FFSEX5' then trunc(AVG(RATE),2) End as FFSDirect_Avg,
    Case when PORT_ID in ('FFSEX3', 'FFSEX2', 'CLS') then SUM(PRINCIPAL) End as FFSBroker,
    Case when PORT_ID in ('FFSEX3', 'FFSEX2', 'CLS') then trunc(AVG(RATE),2) End as FFSBroker_Avg,
    Case when PORT_ID in ('EPIEX3', 'ACK', 'ETCEX3', 'CKD') then SUM(PRINCIPAL) End as Euro3,
    Case when PORT_ID in ('EPIEX3', 'ACK', 'ETCEX3', 'CKD') then trunc(AVG(RATE),2) End as Euro3_Avg,0 AS FLAG
    FROM CV_TRADE_HIST Where to_char(trade_date,'dy')='fri'
    Group by port_id,Trade_date
    UNION
    -- TO ADD HOLIDAYS TO THE RECORD SET
    SELECT HOLI_DT AS TRADE_DATE,
    0 AS FFSDirect,
    0 AS FFSDirect_Avg,
    0 AS FFSBroker,
    0 AS FFSBroker_Avg,
    0 as Euro3,
    0 AS Euro3_Avg,
    0 AS Euro4,
    1 AS FLAG
    FROM V_INTR_SRC_HOLIDAY
    WHERE TO_NUMBER(TO_CHAR(HOLI_DT,'YYYY'))=2006 and TO_CHAR(HOLI_DT,'DY') NOT IN ('SAT','SUN')
    ORDER BY 1 DESC
    Logic i was trying (I NEED TO POST THE PREVIOUS DAYS TRANSACTIONS WHERE FLAG=1 WHICH IS A HOLIDAY.using Lag())
    ****My constraint is no PL/SQL and no DML is allowed.
    Please let me know is there anyway i can achieve this.I tried using Lag(), it did not work for me,Any suggestions?
    Thank you,
    Jay Brahmanapalli
    Message was edited by:
    user530625

    Here's a simple version:
    Setup:
    drop table trade_history
    create table trade_history
    ( trade_date date not null
    , amount number not null
    , ticker varchar2(6) not null
    declare
        tdate date;
        tamount number;
    begin
        tdate := trunc(sysdate);
        for i in 1..365 loop
            tdate := tdate - 1;
            tamount := 200 - i;
            insert into trade_history (trade_date, amount, ticker)
            values (tdate, tamount, 'ORCL');
        end loop;
    end;
    commit
    drop table holidays
    create table holidays
    ( holiday_date date not null
    , previous_business_date date not null
    , holiday_name varchar2(240)
    insert into holidays (holiday_date, previous_business_date, holiday_name)
    values ('25-DEC-05','24-DEC-05','Christmas Day')
    insert into holidays (holiday_date, previous_business_date, holiday_name)
    values ('26-DEC-05','24-DEC-05','Boxing Day')
    insert into holidays (holiday_date, previous_business_date, holiday_name)
    values ('06-SEP-06','05-SEP-06','A midweek example')
    insert into holidays (holiday_date, previous_business_date, holiday_name)
    values ('04-SEP-06','01-SEP-06','A Monday example')
    insert into holidays (holiday_date, previous_business_date, holiday_name)
    values ('07-AUG-06','04-AUG-06','A two day post w/e example')
    insert into holidays (holiday_date, previous_business_date, holiday_name)
    values ('08-AUG-06','04-AUG-06','A two day post w/e example')
    insert into holidays (holiday_date, previous_business_date, holiday_name)
    values ('26-DEC-06','24-DEC-06','Boxing Day 2006')
    commit
    /And a very simple example query
    select last_business_day, ticker, sum(amount), count(amount)
    from (
    select nvl(hol.previous_business_date, trade_date)
           - case to_char(nvl(hol.previous_business_date, trade_date),'D')
                        when '7' then 2
                        when '6' then 1
                        else 0
                        end last_business_day
         , ticker, amount
    from   trade_history th
    left join holidays hol on hol.holiday_date = th.trade_date
    group by last_weekday, ticker
    order by 1,2You should be able to build on that example, I hope. If you can't add the previous_business_date to your holiday table, then it gets slightly more complicated (because you have to skip back through consecutive holidays AND weekends AND any more consecutive holidays - ie in UK you'd have to skip back through Easter Monday, the Easter Weekend and Good Friday - last busines day is what we call Maundy Thursday.
    HTH
    Regards Nigel

  • Dependent demand on non-working days

    Hi Experts,
    Let me explain our scenario:
    1) We have a factory that is 90% closed for a period of time (i.e. August) for production (10% of the work centers are still working)
    2) Same factory is 100% closed for receptions.
    We have setup the system in the following calendars:
    1) Z1 --> closed on august
    2) Z2 --> opened on august
    And assigned them in the following way:
    1) Location calendar --> Z1 (we avoid purchase requisitions creation for roh's and pack's)
    2) Work centers that will stop --> Z1 (we avoid planned orders creation in these way)
    3) Work centers that will still work --> Z2 (as the work center calendar is more restrictive than location calendar)
    With this setting behavior is nearly the one we need, but we have the following problem:
    Once a planned order is created on, for example 22nd August in a working work center system is doing this:
    Basic end date: 22nd August
    Then, order is scheduled and system calculated production dated and basic start date in the following date:
    Basic end date: 01st September (first working date in Z1,  the one in the location)
    Basic start date: 31st July (last working day in Z1 calendar, the one in the location)
    Production start date: 22nd August
    Production en date: 22nd August
    So is seems that the behavior is...production dates based on work center calendar, basic dates based on location calendar.
    The problem of this is that "dependent demand" for all the components of these orders are based on "basic start dates"...which is incorrect; "dependent demand" should be placed wherever the production starts...
    Any suggestion?
    Thanks in advance,
    Raü

    Dear,
    Yes you can do this with scheduling parameter go to OPU5 and OPU3 here define Adjust date= Adjust date to operation start.
    One more thing I would like to tell you that you have no need to create to calendar you can do this with same factory calander.
    If you don't work on that particular period define work center available capacity as zero  and other day so you need to create two shift sequence in OP4A one with working Hr and another withiout working hrs.
    Assign it to your  work center with valid date. Meas up to 22 Aug on shift sequence and from 22 August another shift sequence.
    And you knows that system do the scheduling as per available capacity.
    Hope it will help you. Please try and come back.
    Regards,
    R.Brahmankar
    Edited by: R Brahmankar on Aug 1, 2009 12:38 PM

  • Query to retrieve previous working day?

    I need to write a query that will retrieve the previous working day. Therefore, it must exclude weekends and holidays.
    For example, the previous working day for Saturday, February 19 or Sunday, February 20 would be Friday, February 18. And since Monday, February 21 was a holiday for us then the previous working day would also be Friday, February 18.
    I've found some queries that allow me to find the previous working day excluding weekends, but I'm having difficulty with the holidays aspect. We have a table called CORPHOLIDAY that contains a field HOLIDAY that stores the holiday dates.
    Can I do this with a simple query? I'm not proficient with Oracle, so any and all help is appreciated. Thanks!

    Welcome to the forum!
    As Dan said, whenever you have a question, it really helps if you post CREATE TABLE and INSERT statements to create whatever tables you need, so people can re-create the problem and test their ideas. Also post the results you want from that data, and your version of Oracle.
    The sample data might be as simple as this:
    CREATE TABLE     corpholiday
    (     holiday     DATE
    INSERT INTO corpholiday (holiday) VALUES (DATE '2011-02-21');Here's one way to get the results you want. You enter a starting date (such as February 22, 2011) and the query produces the last working day before that date (in this case, February 18).
    WITH     consecutive_days     AS
         SELECT     TO_DATE ( '22-Feb-2011'     -- Input parameter
                   , 'DD-Mon-YYYY'
                   ) - LEVEL     AS a_date
         FROM     dual
         CONNECT BY     LEVEL     <= 4     -- 1 + Max. possible non-work days
    SELECT     MAX (a_date)     AS prev_work_day
    FROM           consecutive_days     c
    LEFT OUTER JOIN      corpholiday          h  ON     c.a_date     = h.holiday
    WHERE     TO_CHAR ( a_date
              , 'Dy'
              , 'NLS_DATE_LANGUAGE=ENGLISH'     -- If necessary
              )     NOT IN ('Sat', 'Sun')
    AND     h.holiday     IS NULL
    ;What you might really like for this job is a WHILE loop, something that would start at the given date, subtract one, test if that day was a work day, and, if necessary, repeat until it did find a work day. That's how you might do it in a procedural language, like PL/SQL, and that's exactly what a lot of people would do: write a PL/SQL function, that could us a WHILE loop. SQL is a non-procedural language, so it doesn't have anything like a loop. Using a CONNECT BY query, as shown above, we can simulate the behavior of a FOR loop, where we do a fixed number of iterations. The query above works by using CONNECT BY to generate the last 4 dates before the given starting date. What is that magic number 4? It's the worst case of how many consecutive days there can be (at least where I work) that is sure to have at least one work day. Where I work, holidays are always at least a week apart, so the longest you can go without a work day is like the example you gave: a Monday (or Friday) holiday, adjacent to the 2 weekend days. You may need to change the number 4 to something higher if, say, December 25 and 26 were both holidays, or if Good Friday and Easter Monday were both holidays.
    As posted, the query above works in Oracle 9 (and up), but it can be modified for earlier versions.
    Edited by: Frank Kulash on Feb 23, 2011 8:57 PM
    Added explanation

  • To get the list of working days-3 to working days+10 of every month

    Hi,
    I am looking for a query,which will give me the list of working days in a column (except Saturday and Sunday)ranging from
    [Working day- 3] to [Working day +10]of each month from (April 2014 ) till 2016 December.Could you please help me in achiving it.
    Note :Working day -3 means ,When the first working day of a month is [ 1st April ,Monday].
    So it has to result as March 27,28 and 29 as my last working days.
    Same logic applies for Working day +10(it needs to give total 10 dates,which excludes Saturday and Sunday)
    Regards,
    Ramesh

    DECLARE @monthDate datetime
    SET @MonthDate = '20140401'
    SELECT [Date]
    FROM
    SELECT [Date],ROW_NUMBER() OVER (PARTITION BY DATEDIFF(mm,0,[Date]) ORDER BY [Date]) AS Seq,
    ROW_NUMBER() OVER (PARTITION BY DATEDIFF(mm,0,[Date]) ORDER BY [Date] DESC) AS BSeq
    FROM dbo.CalendarTable(DATEADD(dd,- 10,@MonthDate),DATEADD(yy,2,@MonthDate),1,0)
    )t
    WHERE (Seq BETWEEN 2 AND 11 AND [DATE] > @MonthDate)
    OR BSeq BETWEEN 1 AND 3
    ORDER BY [Date]
    CalendarTable can be found here
    http://visakhm.blogspot.in/2010/02/generating-calendar-table.html
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Maybe you are looking for

  • Report Scripts Issue

    Hello, I try to write the report script but cannot find out how to avoide this space-"movement". Is it possible to adjust this with some command? In the manual all the scripts look fine, properly aligned and centered. Cant get that in console. WIDTH,

  • GI installtion gives error while executing root.sh for ASM diskgroup

    Dear Gurus, We are implementing a 2 node RAC configuration with ASM on vmware and openfiler on LINUX RHEL 6.2. We started our installation with grid infrastructure. While executing root.sh on node 1 it gives error diskgroup cannot be mounted and no a

  • Problem Tabbing in Adobe Reader X

    When trying to fill out forms in Adobe Reader X, I get an incredible amount of lag when tabbing.  The hourglass icon pops up with what looks like some sort of calculator symbol attached.  It takes five to ten seconds to tab over to the next field in

  • Exporting an Indesign PDF to JPEG causes logo dropshadow to have white box--why?

    Hi all, I have an Indesign document with a logo in the header. This logo (a linked .png file) has a dropshadow applied to it using Indesign's drop shadow fx (the drop shadow was not created with the graphic in a graphics program). When I export this

  • Nationwide Recall on IPODS

    I Just found out from technical support that Ipods only have a LIFE EXPECTANCY of 3yrs-4yrs.. I havent used it that much because soon after i bought the ipod, I was given an IPAD as a gift. At the time I had purchased the Ipod for around $200 canadia