02-22-2008 3:50 AM
Hi ,
My requirement is finding the first working day of the month.
for example with the FM: 'HR_JP_MONTH_BEGIN_END_DATE'i can find the first working day . After the how can i check whether it is a holiday as per the factory calender , or sunday or saturday.
I am working on 4.6C, and there are no function modules exist which start with 'BKK_",
Can any one give me the best solution?
Thanks,
Suresh.
02-22-2008 3:56 AM
Hi,
You can use "DATE_CONVERT_TO_FACTORYDATE". This will give you the next working date based on the calendar dates.
Also, you can check for various FM's using F4 (from SE37) on FACTORYDATE*
Regards,
Sandeep
02-22-2008 4:04 AM
Hi,
see this FM HOLIDAY_GET Provides a table of all the holidays based upon a Factory Calendar &/ Holiday Calendar
HOLIDAY_CHECK_AND_GET_INFO Useful for determining whether or not a date is a holiday. Give the function a date, and a holiday calendar, and you can determine if the date is a holiday by checking the parameter HOLIDAY_FOUND.
Example:
data: ld_date like scal-datum default sy-datum,
lc_holiday_cal_id like scal-hcalid default 'CA',
ltab_holiday_attributes like thol occurs 0 with header line,
lc_holiday_found like scal-indicator.
CALL FUNCTION 'HOLIDAY_CHECK_AND_GET_INFO'
EXPORTING
date = ld_date
holiday_calendar_id = lc_holiday_cal_id
WITH_HOLIDAY_ATTRIBUTES = 'X'
IMPORTING
HOLIDAY_FOUND = lc_holiday_found
tables
holiday_attributes = ltab_holiday_attributes
EXCEPTIONS
CALENDAR_BUFFER_NOT_LOADABLE = 1
DATE_AFTER_RANGE = 2
DATE_BEFORE_RANGE = 3
DATE_INVALID = 4
HOLIDAY_CALENDAR_ID_MISSING = 5
HOLIDAY_CALENDAR_NOT_FOUND = 6
OTHERS = 7.
if sy-subrc = 0 and
lc_holiday_found = 'X'.
write: / ld_date, 'is a holiday'.
else.
write: / ld_date, 'is not a holiday, or there was an error calling the function'.
endif.
Hope this helps.
02-22-2008 4:05 AM
Suresh,
This is very good ex: for your requirement.
PARAMETERS: p_date TYPE datum, " Date
p_cal TYPE wfcid. " Calendar
DATA: l_mon_start TYPE datum, " Start Date
l_mon_end TYPE datum. " End Date
DATA: flg TYPE boole_d.
START-OF-SELECTION.
CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
EXPORTING
iv_date = p_date
IMPORTING
ev_month_begin_date = l_mon_start " Month Start Date
ev_month_end_date = l_mon_end. " Month End Date
" Check Month Start end date is working day
PERFORM check_working_date USING l_mon_start CHANGING flg.
IF NOT flg IS INITIAL.
" Get next working day
CALL FUNCTION 'BKK_GET_NEXT_WORKDAY'
EXPORTING
i_date = l_mon_start
i_calendar1 = p_cal
IMPORTING
e_workday = l_mon_start " First Working Day of Month
EXCEPTIONS
calendar_error = 1
OTHERS = 2.
ENDIF.
DO.
" Check if end date is working
PERFORM check_working_date USING l_mon_end CHANGING flg.
IF NOT flg IS INITIAL.
l_mon_end = l_mon_end - 1.
ELSE.
EXIT.
ENDIF.
ENDDO.
WRITE:/ 'Start Date: ', l_mon_start,
/ 'End Date: ', l_mon_end.
&----
*& Form CHECK_WORKING_DATE
&----
FORM check_working_date USING p_date_chk TYPE datum
CHANGING p_flg TYPE boole_d.
CLEAR: p_flg.
CALL FUNCTION 'BKK_CHECK_HOLIDAY'
EXPORTING
i_date = p_date_chk
i_calendar1 = p_cal
IMPORTING
e_x_no_workingday = p_flg
EXCEPTIONS
not_found = 1
calendar_error = 2
OTHERS = 3.
ENDFORM. " CHECK_WORKING_DATE