Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Factory calendar function

Former Member
0 Likes
3,247

Hi,

Can someone help me to figure this out. I deducted 4 days from the requested date and went to factory calendar. Factory calendar gives next business day (8/1/05) which is not what we want. Need 4 days before del. date. Saturday and Sunday in between is throwing the date off. Is there another function to accomplish this. Thanks in advance for your help.

For example this is what I need:

Requested Del Date = 8/01/05 (monday)

Planned Del Time = 4 days

do not count saturday and sunday - then go back four days 8/01, 7/29, 7/28, 7/27 - planned GI should be 7/26.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,617

Hi Kanya

Please check the following link:

You can subtract the number you get from the current date

Hope it may server your purpose

Regards

Ashish

11 REPLIES 11
Read only

Former Member
0 Likes
1,617

Based on your previous post, I am assuming you are using 'DATE_CONVERT_TO_FACTORYDATE'. In the solution that Rich proposed, use '-' instead of '+'.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,617

Instead of adjusting forward, adjust backward.....




* Use "-" instead of "+"
  call function 'DATE_CONVERT_TO_FACTORYDATE'
       exporting
            correct_option      = '-'  " Adjustment
            date                = d1   " Date In
            factory_calendar_id = 'P6' " Calendar Id
       importing
            date                = xdate.  " Date out


Regards,

Rich Heilman

Message was edited by: Rich Heilman

Read only

Former Member
0 Likes
1,618

Hi Kanya

Please check the following link:

You can subtract the number you get from the current date

Hope it may server your purpose

Regards

Ashish

Read only

0 Likes
1,617

I'm think that I have have misunderstood the first time around. You need to go back 4 days not including the non-working days, right? Try this code..

Enter 08/01/2005 in the parameters field, the output will be 07/26/2005.



report  zrich_0002.



parameters: p_datum type sy-datum.


do 4 times.

  p_datum = p_datum - 1.

  call function 'DATE_CONVERT_TO_FACTORYDATE'
       exporting
            correct_option      = '-'
            date                = p_datum
            factory_calendar_id = 'P6'
       importing
            date                = p_datum.


enddo.

write:/ p_datum.

Here you are subtracting one day at a time, and check to see if there is a calendar adjustment which can be applied.

Regards,

Rich Heilman

Message was edited by: Rich Heilman

Read only

0 Likes
1,617

Rich solution is OK for your problem, only you have to change the calendar ID. You get out this information from T001W

Read only

Former Member
0 Likes
1,617

Hi

Check also the function module:

WDKAL_DATE_ADD_FKDAYS

Cheers

Ashish

Read only

Former Member
0 Likes
1,617

Thanks guys. It gives me 7/28/05 but I am looking for 7/26 which gives me 4 days excluding Sat. and Sunday. Is there a way we could exclude weekends going back for calendar function?

Read only

0 Likes
1,617

Yes, please try the code in my last answer.

Please don't forget to award points for helpful answers.

Thanks.

Regards,

Rich Heilman

Read only

0 Likes
1,617

I runned Rick solution and the result is correct.

If you can't obtain a right result, probably you use a wrong calendar id, or in your calendar is wrong

Read only

Former Member
0 Likes
1,617

Hi,

Here is a working example using the FM I gave you last time. I used a date of November 28th 2005 as input date and asked the system to back-calculate by 4 days using our custom calendar. Now while 26 and 27 are saturday and sunday, in our custom calendar, 24 and 25 are marked as holidays. So my first previous working day is 23rd November, 2nd is 22nd, and 3rd is 21st, but again I hit Saturday and Sunday on 20th and 19th. So my 4th working day backwards is 18th November. I hope this is what you are looking for and it worked for me.


REPORT ztest1 .

PARAMETERS: p_date LIKE sy-datum.

DATA: v_input_date   LIKE sy-datum,
      v_output_date  LIKE sy-datum.

START-OF-SELECTION.

  CALL FUNCTION 'BUSINESS_DATE_CREATE'
    EXPORTING
*     BLEIB_IM_MONAT           = ''
      datum_ein                = p_date
      geschaeftstage           = 4
      kalender                 = 'Z6'
      richtung                 = '-'
   IMPORTING
      datum_aus                = v_output_date
   EXCEPTIONS
      calendar_not_found       = 1
      date_out_of_range        = 2
      OTHERS                   = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

Regards,

Srinivas

Read only

Former Member
0 Likes
1,617

Thanks to all of you. Rich, thanks for all your help. Finally it worked after I followed your last suggestion. Gave all of you ponts.