Application Development 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: 

function module to get next working date

Former Member
0 Kudos
6,942

given the no. of days i need to find the next working day from the current date .......

is there any function module which calculates

8 REPLIES 8

Former Member
0 Kudos
1,026

CALL FUNCTION 'DATE_CHECK_WORKINGDAY'

EXPORTING

DATE = SY-DATUM

FACTORY_CALENDAR_ID = '01'

MESSAGE_TYPE = 'E'

EXCEPTIONS

DATE_AFTER_RANGE = 1

DATE_BEFORE_RANGE = 2

DATE_INVALID = 3

DATE_NO_WORKINGDAY = 4

FACTORY_CALENDAR_NOT_FOUND = 5

MESSAGE_TYPE_INVALID = 6

OTHERS = 7.

IF

SY-SUBRC = 0.

WRITE 'working day'.

ELSE.

WRITE 'not workingday'.

ENDIF.

Former Member
0 Kudos
1,026

hi Avinash,

Check the sample code:

TABLES T001W.

PARAMETERS: P_DATE LIKE SY-DATUM,

P_PLANT LIKE T001W-WERKS.

SELECT SINGLE * FROM T001W WHERE WERKS = P_PLANT.

CALL FUNCTION 'DATE_CHECK_WORKINGDAY'

EXPORTING

DATE = P_DATE

FACTORY_CALENDAR_ID = T001W-FABKL

MESSAGE_TYPE = 'E'

EXCEPTIONS

DATE_AFTER_RANGE = 1

DATE_BEFORE_RANGE = 2

DATE_INVALID = 3

DATE_NO_WORKINGDAY = 4

FACTORY_CALENDAR_NOT_FOUND = 5

MESSAGE_TYPE_INVALID = 6

OTHERS = 7.

IF SY-SUBRC EQ 0.

WRITE:/ P_DATE, 'IS A WORKING DAY IN', P_PLANT.

ELSE.

IF SY-SUBRC EQ 4.

WRITE:/ P_DATE, 'IS A HOLIDAY IN', P_PLANT.

ELSE.

WRITE:/ 'COULD NOT DETERMINE DATE'.

ENDIF.

ENDIF.

Or another one is <b>DATE_CHECK_WORKINGDAY_MULTIPLE</b>Hope this will help you.

Cheers

Sunny

Rewrd points , if found helpful

Message was edited by: Sunny

Former Member
0 Kudos
1,026

Hi avinash,

1. DATE_CHECK_WORKINGDAY

Using this FM and some EXTRA Logic,

we can achieve what u want.

2. use this logic somewhat

to get to ur requirement

(just copy paste in new program)

3. It will display all the working days,

between TWO Dates.

4.

REPORT abc.

data : num type i.

parameters : frdate type sy-datum default '20051216'.

parameters : todate type sy-datum default '20051221'.

perform getinfo using frdate todate changing num.

break-point.

&----


*& Form getinfo

&----


  • text

----


FORM getinfo USING fromdate todate CHANGING numofdays type i.

DATA : d TYPE sy-datum.

d = fromdate - 1.

DO.

d = d + 1.

IF d > todate.

EXIT.

endif.

CALL FUNCTION 'DATE_CHECK_WORKINGDAY'

EXPORTING

date = d

factory_calendar_id = '01'

message_type = 'I'

EXCEPTIONS

date_after_range = 1

date_before_range = 2

date_invalid = 3

date_no_workingday = 4

factory_calendar_not_found = 5

message_type_invalid = 6

OTHERS = 7.

IF sy-subrc = 0.

numofdays = numofdays + 1.

write 😕 d.

ENDIF.

ENDDO.

ENDFORM. "getinfo

regards,

amit m.

0 Kudos
1,026

REPORT ZRM_TEST .

PARAMETERS: DATE_1 LIKE SY-DATUM DEFAULT SY-DATUM,

BIZ_DAYS TYPE I DEFAULT 2,

FACCALID LIKE SCAL-FCALID DEFAULT 'US'.

DATA: FAC_DATE_1 LIKE SCAL-FACDATE,

DATE_2 LIKE SY-DATUM,

FAC_DATE_2 LIKE SCAL-FACDATE.

CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'

EXPORTING

DATE = DATE_1

FACTORY_CALENDAR_ID = FACCALID

IMPORTING

FACTORYDATE = FAC_DATE_1 .

FAC_DATE_2 = ABS( FAC_DATE_1 + BIZ_DAYS ).

CALL FUNCTION 'FACTORYDATE_CONVERT_TO_DATE'

EXPORTING

factorydate = FAC_DATE_2

factory_calendar_id = FACCALID

IMPORTING

DATE = DATE_2

.

WRITE: / DATE_2.

You can also try the function module DAY_ATTRIBUTES_GET.

Former Member
0 Kudos
1,026

Hi avinash,

As per form etiquette's

If satisfied , please close the thread by rewarding appropriate points to the helpful answers.

Cheers

Sunny

0 Kudos
1,026

Use this function module

CALL FUNCTION 'BKK_GET_NEXT_WORKDAY'

EXPORTING

i_date = sy-datum

i_calendar1 = 'DK'

IMPORTING

e_workday = g_fst_wrk_date

EXCEPTIONS

calendar_error = 1

OTHERS = 2.

Former Member
0 Kudos
1,026

Hi,

Use the function Module

WDKAL_DATE_ADD_FKDAYS

If it helps out . plz awzrd suitable points.

Regards,

Irfan Hussain

Former Member
0 Kudos
1,026


Below is the code required


Do 8 times.
         CALL FUNCTION 'DATE_CHECK_WORKINGDAY'
           EXPORTING
             date                       = date
             factory_calendar_id        = 'TM'
             message_type               = 'E'
           EXCEPTIONS
             date_after_range           = 1
             date_before_range          = 2
             date_invalid               = 3
             date_no_workingday         = 4
             factory_calendar_not_found = 5
             message_type_invalid       = 6
             OTHERS                     = 7.

         IF sy-subrc <> 0.
           date= date+ 1.
         else.
           exit.
         ENDIF.
       ENDDO.


Thanks,

Anand.