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

Calculating date using Factory Calendar

Former Member
0 Likes
5,733

Hello SAP Guru's,

I have to calculate a date which is basically system date (sy-datum) + 60 days. The 60 days should not include holidays or weekends (Saturday & Sunday) from the factory calendar. How do I calculate this?

The final date calculated should not fall on a weekend or on holidays defined in the factory calendar.

Sincerely,

Ketan

5 REPLIES 5
Read only

Former Member
0 Likes
2,290

Hi,

U can use the work schedule for this purpose.

use below function module,

CALL FUNCTION 'HR_PERSON_READ_WORK_SCHEDULE'

EXPORTING

BEGIN_DATE = BEG_DATE

END_DATE = END_DATE

  • GROUPING_DWS =

  • GROUPING_ATTENDENCE =

  • GROUPING_SUBSTITUTE =

  • READ_FROM_DATABASE = ' '

  • IM_READ_NO_LOCKED_RECORDS =

TABLES

PERNR_TAB = ITAB

PSP = PSP

DAY_PSP = DAY_PSP

  • EXCEPTIONS

  • ERROR_IN_BUILD_PSP = 1

  • OTHERS = 2

u can fin tprog filed in structure PSP, there u can find two values "normal" and "off".

u can find number normal days in that period.

Thanks and Regards,

Read only

0 Likes
2,290

Hi Chandra,

Thanks for your reply but we do not maintain Work schedule. We only maintain the factory calendar so can we only calculate on the basis of the factory calendar?

Sincerely,

Ketan

Read only

0 Likes
2,290

In SAP where factory calender maintaining, can u please tell me, so that i can help u.

Thanks and Regards,

Read only

Former Member
0 Likes
2,290

Hi,

Use FM: DATE_CONVERT_TO_FACTORYDATE

Read only

Former Member
0 Likes
2,290

Hi,

Process the below logic, you will get the required output.

wk_date = sy-datum.

add_days = 60. (60 days)

fact_cal = xxxxx. (factory calendar)

CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'

EXPORTING

correct_option = cr_opt

date = wk_date

factory_calendar_id = fact_cal

IMPORTING

date = wk_date

factorydate = fact_date

workingday_indicator = wk_ind

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.

add_days = add_days - 1.

DO add_days TIMES.

CASE cr_opt.

WHEN '+'.

wk_date = wk_date + 1.

WHEN '-'.

wk_date = wk_date - 1.

ENDCASE.

CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'

EXPORTING

correct_option = cr_opt

date = wk_date

factory_calendar_id = fact_cal

IMPORTING

date = wk_date

factorydate = fact_date

workingday_indicator = wk_ind

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.

write : / wk_date.

Hope this will solve ur problem.