Calculate next working day in future

Hi,
I hope somebody of you could help me here. I have the requirement to find the next working day 2 days after the visit. I need to join two tables which have an N to N relation.
This is the first source table tbl_cust with customer and visiting day:
customer_id    Name     visit_day       company_id
1                   Tobias    27.08.2011  100
2                   Hans      30.08.2011  100
3                   Lars       27.08.2011   200
4                   Dave      29.08.2011   200The second table tbl_comp_days includes the days where the different companies work:
company_id  company_day    working_day (yes/no)
100             27.08.2011       no
100             28.08.2011       no
100             29.08.2011       yes
100             30.08.2011       yes
100             31.08.2011       yes
100             01.09.2011       yes
200             27.08.2011       yes
200             28.08.2011       yes
200             29.08.2011       no
200             30.08.2011       yes
200             31.08.2011       yes
200             01.09.2011       yesNow I want to calculate the second next work of the company joined with the customer visit_day
Means: tbl_cust.visit_day + 2
when tbl_comp_days.working_day is yes
if tbl_cust.visit_day is not a working day find the next possible working day + 2 working days
Output example:
customer_id    Name     visit_day       visit_day_plus_2
1                   Tobias    27.08.2011  31.08.2011
2                   Hans      30.08.2011  01.09.2011
3                   Lars       27.08.2011   30.08.2011
4                   Dave       29.08.2011   01.09.2011Thanks for your help
Tobias

Hi, Tobias,
Here's one way:
WITH     got_r_num    AS
     SELECT     c.customer_id, c.name, c.visit_day, d.company_day  AS visit_day_plus_2
     ,     ROW_NUMBER () OVER ( PARTITION BY  c.customer_id
                               ORDER BY          d.company_day
                       )         AS r_num
     FROM    tbl_cust       c
     JOIN     tbl_comp_days  d  ON   c.company_id  = d.company_id
                             AND  c.visit_day   < d.company_day
                      AND  c.visit_day   >= d.company_day + 10     -- See note
     WHERE   d.working_day       = 'yes'
SELECT     customer_id, name, visit_day, visit_day_plus_2
FROM     got_r_num
WHERE     r_num     = 2
;If you'd post CREATE TABLE and INSERT statements for the sample data, then I could test it.
The last join condition ( c.visit_day >= d.company_day + 10) isn't strictly necessary. Depending on the size of the company_day table, it may make execution faster, by limiting the join to days soon after visit_day, rather than any time after visit_day. As I wrote it, it assumes that there will always be at least 2 working days in any period of 10 consecutive days. (In my company, there are always at least 2 working days in a period of 5 consecutive days.) You cam change the "magic number" 10 to anything else, or you can omit that condition altogether.
Edited by: Frank Kulash on Aug 23, 2011 10:49 AM
Added note.

Similar Messages

  • FM for Holiday & Next Working day

    HI All,
    Please suggest any  single FM, which can give the current day is Holiday or not. If, Yes, the what is the next working day for a Facorty calender ID.
    Both validation should be happend in a single FM.
    Thanks & Regards,
    Prabhakar.
    Moderator message: FAQ, please search for previous discussions of this topic.
    Edited by: Thomas Zloch on Apr 18, 2011 6:13 PM

    hi ,
    Pls check this FM
    CALL FUNCTION 'BKK_CHECK_HOLIDAY'
            EXPORTING
              i_date            = wf_cntdt
              i_calendar1       = 'B1'
            IMPORTING
              e_x_no_workingday = wf_holi.
    *get actual working days upto report date.
      it_act_work_days-dat_from  = w_date-low.
      it_act_work_days-dat_to    = w_date-high.
      APPEND it_act_work_days.
    *calculate actual working days.
      CALL FUNCTION 'WFCS_FCAL_WDAYS_GET_S'
        EXPORTING
          pi_time_interval = it_act_work_days
          pi_fcalid        = 'B1'
        IMPORTING
          pe_wdays         = wf_actdays.
    regards
    Deepak.
    Edited by: Deepak Dhamat on Apr 18, 2011 12:31 PM

  • Netdue date alteration with next working day

    Hi,
    I have one report for Accounts Receivables .
    In this when net due date falls on holiday, i need to shift this "net due date"  to a next working day.
    I have one FM "DATE_CONVERT_TO_FACTORYDATE" which i can use for the purpose.
    As a input to this FM we need to give Factory calendar ID which is an attribute to Infoobject 0PLANT.
    Unfortunately i do not have 0PLANT in my datamodel. But i do have 0COMP_CODE in my datamodel.
    As i do not have any link between Factory calendar ID and 0COMP_CODE i am searching for an appropriate solution so that i could use this FM to shift net due date to Next working if the net due date is an holiday.
    Any Ideas?

    Simran
    I am not sure if we can get a direct link from 0plant to 0comp_code, but you can enhance the master data of the 0company code to add the factory caledar and load them manually into 0plant.
    Let me know if this helps..
    Regards,
    Avinash

  • Billing date of 2nd/4th saturday getting pushed to next working day.

    whenever my client trying to create bill of service order, bills on 2nd/4th saturday, the billing date is getting pushed to next working day. I checked their calender, they have maintained 2nd/4th saturday as holiday in holiday calender. However the validity is only till 2009. But the bills are getting still getting pushed. Am not too keen on using validation, please help.

    Hi,
    Are they creating invoices thru back ground ( using batch job ) ? in this case in the holiday calendar 2n'd and 4'th saturday is holiday, so the system is proposing new work day. you have to check all the three calendars once again let me know.
    Thanks,
    Chandu.

  • Calculate the working days having the start and end dates only

    Hi,
    Can BIP be able to calculate the working days having the start and end dates only? It is like the NETWORKDAYS function in Excel. (i.e. excluding weekends and holidays).
    Thanks.

    Not out of the box.
    But You could extend your BIP functions
    Look at here:
    http://blogs.oracle.com/xmlpublisher/2009/05/bip_by_extension.html
    Based on that what you need is similar to the following Java code:
    http://objectlabkit.sourceforge.net/
    regards
    Jorge A.

  • URGENT: Add Non-working day value to the next working day

    Hello expertz!
    I have a requirement were i need to shift the values of the non-working days to the next working day. The report allready works, showing only the values for the working days, but for example if i have the amount of 100 on 06.12.2009 (saturday) i want that this value is added to the amount of 09.12.2009, which is the next working day.
    Does anybody knows a solution to do this? Is this possible in BEx?
    Please advise if you think this is not possible.
    Thanks for the help.
    Nuno

    Hi Anil,
    I really appreciate your suggestion, but i'm still not getting the point. How to store the value of the non-working day in a variable and then add it where? Can you please clarify?
    Thank you very much for your help.
    Nuno

  • Function  in param, start_date & number , return sums next working day

    Hi Friends,
    I need a funtion which can take in parameters as start_date and number , sum them as new date and return new_start_date as workind day.
    Suppose '15-SEP-2009' + 6 should return 23-SEP-2009 as new date.
    Basically the sum of date and number should return next working day (excluding saturday,sunday).
    e.g '15-SEP-2009' + 6 =21-SEP-2009 , but it includes saturday and sunday , so it should return 23-SEP-2009.
    Thanks
    Niren

    Hi, Niren,
    The first respondent gave a better function for testing for work days (Monday through Friday). If there's a bug with Saturdays, I'm sure that can fixed. Also,that function depends on your NLS settings. If that's an issue for you, that can be fixed, too. The idea that there are 5 work days in any 7 consecutive days will cut down the execution time considerable.
    A function like I suggested would be useful if you had to consider holidays as well as weekends.
    Here's an untested example:
    CREATE OR REPLACE FUNCTION  work_days_away
    (      in_start_date         DATE
    ,      in_day_cnt         NUMBER
    RETURN     DATE
    DETERMINISTIC
    IS
         IF  in_start_date - TRUNC (in_start_date, 'IW') >= 5
         OR  is_holiday (in_start_date)
         THEN
              RETURN  work_days_away ( in_start_date + 1
                               , in_day_cnt
         ELSIF  in_day_cnt >= 1
         THEN
              RETURN  work_days_away ( in_start_date + 1
                               , in_day_cnt    - 1
         ELSE
              RETURN  in_start_date;
         END IF;
    END     work_days_away;This use the date format 'IW', which does not depend on NLS settings, rather than 'D', which does.

  • Schedule line confirmation on next working day

    Hi,
    For a sales org, (IE93) in a sales order if we request delivery on 25.12.2009 (Xmas day), APO availability check is performed and it is confirming on the next/prior working day.
    But in case of other sales org(GB93) it is confirming on the same day(on Xmas itself, which is a holiday)..
    We want the same control for GB93 also.. Any idea?
    Regards,
    Mayil

    Hi,
    Check the Factory calender Assignmene for these two COMPANY CODES, PLANT, in OVR3
    I believe the Factory calender is different for these two Organisational Units.
    Check the Factory calender settings in OVR3 transaction code
    Please revert back if you need further details
    thanks,
    santosh

  • Calculate x working days before date

    Dear experts,
    I am trying to find a date that is x working days before another.
    Is that a function module about this?
    Thank you in advance,
    Roxani

    Hi Roxani,
    You can use FM END_TIME_DETERMINE.
    There:
    - Insert in duration the number of days that you want to subtract with the minus sign (ex: -1 for previous working day)
    - Also, insert your factory calendar that you want to be the source of your working days.
    - And, of course, the desired starting date.
    Hope that helps!
    Kind regards,
    Garcia

  • Due date column to calculate 7 working days

    Can you help me with formula to calculate the Due date default to 7 business days from created date. and due date should not be in weekend.

    Refer to the following post, hope it helps
    http://sharepoint.stackexchange.com/questions/88149/formula-to-show-differens-between-dates-without-weekends-and-holidays
    Cheers,

  • How can i find out the next 2 working days.

    Hi Experts,
    Based on a given date, i would like to find out the next 2 working days.
    Help me out.
    Regards,
    Mansi.

    Hi,
    Use this FM WRF_PSCD_GET_NEXT_WORKDAY
    first get the first working day and pass that day again to get the next working day
    and also pass the calender id for the same
    Import parameters               Value
    I Import parameters               Value
    I_DATE                          09/15/2007
    I_CALENDAR1                     US
    I_CALENDAR2
    Export parameters               Value
    E_WORKDAY                       09/17/2007
    Regards
    Shiva

  • CALCULATE THE NEXT WORKING DATE ACCORDING TO THE CALENDAR

    Hello,
    Could somebody tell me the name of any function module or abap class to determine the next working day according to calendar. I need add (let say) 30 days to the date but only working days (I dont take into acount sunday, easter etc.)
    Thanks in Advance
    Adam

    try function BKK_ADD_WORKINGDAY
    or WDKAL_DATE_ADD_FKDAYS
    Cheers
    Thomas

  • Need to get available working day

    Hi All,
    I'm using oracle 9i version.
    i have a procedure which will take 1 in parameter and 1 out parameter.
    we will pass one inputdate
    now the date which i passed is sunday or holiday then we have to return the next working day that holiday list i'm getting form holiday_list table.
    now the problem is suppose i passed a date which is sunday so now i have to return like the inputdate+1 so that it will be monday . but now i need to check weather that monday also holiday or not in the holiday list
    if it is then i have to go for next like INputdate+2 again there also i have to check the same for this till i get a available date .
    can some suggest how to handle this problem.
    Thanks in advance
    -RG

    SQL> select * from holidays;
    DT
    01-JUL-07
    11-JUL-07
    02-JUL-07
    07-JUL-07
    SQL> exec :your_date := '07-jul-2007';
    PL/SQL procedure successfully completed.
    SQL>  select min(dt) dt
      2   from(
      3     select trunc(to_date(:your_date,'dd/mm/yyyy')) + level - 1 dt
      4     from (select case when count(*) <= 8 then 9 else count(*) end cnt
      5         from holidays
      6         where dt >= trunc(to_date(:your_date,'dd/mm/yyyy')))
      7     connect by level <= cnt
      8     )
      9   where to_char(dt,'fmday') != 'sunday'
    10   and dt not in(select dt
    11                 from holidays
    12                 where dt >= trunc(to_date(:your_date,'dd/mm/yyyy')))
    13   /
    DT
    09-JUL-07
    Message was edited by:
            jeneesh
    curved path......                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Working Days 0NUMWDAY

    Hi,
    Just realize there is an attribute called 0NUMWDAY under 0FISCPER, does any one know how system calculate this working days. I tested it, some holiday is excluded (such as Jan 01), however some holiday is not.
    Victor

    try this
    with t as (
    select to_date('01/01/2009','dd/mm/yyyy') + level - 1,to_char(to_date('01/01/2009','dd/mm/yyyy') + level - 1,'Day') from dual
    where trim(to_char(to_date('01/01/2009','dd/mm/yyyy') + level - 1  ,'Day'))  not in ('Saturday', 'Sunday')
    connect by to_date('01/01/2009','dd/mm/yyyy') + level < add_months(to_date('01/01/2009','dd/mm/yyyy'),1) + 1
    select * from tEdited by: alvinder on Mar 25, 2009 4:07 PM

  • Working day for a Holiday Calendar

    Hi, experts.
    I'm looking for a FM that returns me the next working day based on a Holiday Calendar (SCAL).
    It should have the same functionality as Factory Calendar FM FIMA_DAY_CONVERT_TO_WORKINGDAY.
    Can you help me out?
    Thanks in advance,
    Flavia

    Use this function module & make sure you pass the plant details, as factory calendar mostly depeneds on the Plant.
    Below is just an example to get the plant depending on Requisition & pass it to the function module.
    Createdate --> will be the current date.
    SELECT SINGLE t~fabkl
           INTO lv_fabkl
           FROM ( t001w AS t
             INNER JOIN eban AS e ON ewerks = twerks )
           WHERE banfn = reqnumber.
    CALL FUNCTION 'FKK_ADD_WORKINGDAY'
      EXPORTING
        i_date            = createdate
        i_days            = days
        I_CALENDAR1       = lv_fabkl
      I_CALENDAR2       =
    IMPORTING
       E_DATE            = workingday.
      E_RETURN          =

Maybe you are looking for

  • Problem with uninstallation/reinstallation

    My iTunes was crashing everytime I tried to open it, so I tried uninstalling it. It won't let me remove Quicktime or Itunes now. It says the feature I'm trying to use is a network resource that is unavailable. When I try to install itunes + quicktime

  • Add sound to JFrame

    I have a button in my JFrame and want to assign sound to it. ActionListener code is already written, only the sound part is left. Thanks for helping.(clear as you can get because im new in java)

  • New delay issues with already created projects in Captivate 6

    Good afternoon, I have about 20 projects that I've created with Captivate 6 with the past few months that are in need of some minor updating. They've always run fine, but when I open them for editing, I'm finding such things as a 10 second delay afte

  • Photo Import Broken - Fixed with USB Change

    Everything worked perfectly with the iPhone, camera, iTunes, and iPhoto. But iPhoto always showed 0 photos. Image Capture also showed 0. Only PhoneView showed photos and let me export them. Tried every fix I could think of even deleting the DCIM fold

  • Database Control -- sending ORA -errors to mailbox

    Hello All, I trying set up Database Control to send ORA-errors to my mail box but don't know how to go about it. Pls Help