‎2009 Dec 15 7:12 PM
Hello experts,
I need to subtract number of days (L_DAYS) from a date (L_DATE) and the result should be a working day. Any FM's to do this?
Thanks,
‎2009 Dec 15 7:33 PM
Or can someone tell me how to check a date (P_DATE) is a working date in a factory calender?
‎2009 Dec 15 7:42 PM
‎2009 Dec 15 7:52 PM
‎2009 Dec 15 8:15 PM
Hello,
I never found a FM to do this so I made my own based on DATE_CONVERT_TO_FACTORYDATE. Offset is the number of days, correct_option is future or past.
FUNCTION z_date_convert_to_factorydate.
*"*"Local interface:
*" IMPORTING
*" VALUE(CORRECT_OPTION) LIKE SCAL-INDICATOR DEFAULT '+'
*" VALUE(DATE) LIKE SCAL-DATE DEFAULT SY-DATUM
*" VALUE(FACTORY_CALENDAR_ID) LIKE SCAL-FCALID DEFAULT 'C1'
*" VALUE(OFFSET) TYPE INT4 DEFAULT 0
*" EXPORTING
*" VALUE(XDATE) LIKE SCAL-DATE
*" VALUE(FACTORYDATE) LIKE SCAL-FACDATE
*" VALUE(WORKINGDAY_INDICATOR) LIKE SCAL-INDICATOR
CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
EXPORTING
correct_option = correct_option
date = date
factory_calendar_id = factory_calendar_id
IMPORTING
date = xdate
factorydate = factorydate
workingday_indicator = workingday_indicator
EXCEPTIONS
calendar_buffer_not_loadable = 1
correct_option_invalid = 2
date_after_range = 3
date_before_range = 4
date_invalid = 5
factory_calendar_not_found = 6
OTHERS = 7.
IF NOT workingday_indicator IS INITIAL.
SUBTRACT 1 FROM offset.
ENDIF.
IF offset > 0.
DO offset TIMES.
CASE correct_option.
WHEN '+'.
ADD 1 TO xdate.
WHEN '-'.
SUBTRACT 1 FROM xdate.
ENDCASE.
CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
EXPORTING
correct_option = correct_option
date = xdate
factory_calendar_id = factory_calendar_id
IMPORTING
date = xdate
factorydate = factorydate
workingday_indicator = workingday_indicator
EXCEPTIONS
calendar_buffer_not_loadable = 1
correct_option_invalid = 2
date_after_range = 3
date_before_range = 4
date_invalid = 5
factory_calendar_not_found = 6
OTHERS = 7.
ENDDO.
ENDIF.
ENDFUNCTION.
Regards,
Michael
Edited by: Rob Burbank on Dec 15, 2009 4:40 PM
‎2009 Dec 15 9:49 PM
Adrian,
Do Offset times will not work or might not work depending on the requirement.
Don't know if his requirement is L_DATE - LDAYS or L_DATE - L_DAYS (working)
Ex of first one is 12/15/2009 - 5 days that is 10/12/2009 (includes saturday and sunday)
Ex. for later one is 12/15/2009 - 5 working days that is 12/8/2009 (excludes saturday and sunday)
For the first example can directly deduct those many days and use the FM DATE_CONVERT_TO_FACTORYDATE and find if it is a working day or not.
For the 2nd example the above code i have given will work.
Regards
Sandeep
‎2009 Dec 15 9:36 PM
DATA: lv_working_indicator TYPE CIND.
DATA: lv_count TYPE i.
DATA: lv_date TYPE sydatum.
lv_date = l_date
DO.
CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
EXPORTING
correct_option = '-'
date = lv_date
factory_calendar_id = 'Z3'
IMPORTING
workingday_indicator = lv_working_indicator
EXCEPTIONS
calendar_buffer_not_loadable = 1
correct_option_invalid = 2
date_after_range = 3
date_before_range = 4
date_invalid = 5
factory_calendar_not_found = 6
OTHERS = 7.
IF lv_working_indicator IS INITIAL.
lv_count = lv_count + 1.
ENDIF.
IF lv_count = l_days.
lv_required_working_date = lv_date.
EXIT.
ENDIF.
lv_date = lv_date - 1.
ENDDO.
The above code should get you the required working day
‎2009 Dec 15 9:49 PM
table TFACS has the factory calender... if you can split the date into year month and date and hit table TFACS if the result is 1 its a working day 0 for a holiday
‎2009 Dec 17 6:30 PM
‎2009 Dec 17 6:38 PM
>
> solved myself
Glad you got it going, but you'll notice that a number of people tried to give you a helping hand - maybe they deserve some points for their efforts.
If none of them helped at all, you could at least update the forum on how you solved this. That is part of
Rob