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

Get Previous Working Day

Former Member
0 Likes
4,517

Do you know any function module which will give me the previous working day only by ignoring saturdays and sundays and it should NOT consider holidays.

Example:

Monday's Date should give me previous friday's date.

Friday's Date should give me previous thrusday's date

Do you know any function module which will give me the previous working day only by ignoring saturdays and sundays and it should NOT consider holidays.

Example:

Monday's Date should give me previous friday's date.

Friday's Date should give me previous thrusday's date

6 REPLIES 6
Read only

Former Member
0 Likes
2,439

Hi,

To get the last day use FM 'RP_CALC_DATE_IN_INTERVAL'

and to check whether it was a working day you can use FM

call function 'DATE_CHECK_WORKINGDAY'

exporting

date = v_date

factory_calendar_id = 'FR'

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.

you need to pass the factory calendar accordingly, here the calendar if 'FR' for france working days, if sy-subrc is 4 then its not a working day.

Regards

Syed

Read only

former_member156446
Active Contributor
0 Likes
2,439

check the table: TFACS which is the factory calendar display

Read only

ThomasZloch
Active Contributor
0 Likes
2,439

DATA: date TYPE d,
      i TYPE i.

date = '20090316'.
DO.
  SUBTRACT 1 FROM date.
  i = date MOD 7.
  IF i > 1.
    EXIT.
  ENDIF.
ENDDO.
WRITE date.

Thomas

Read only

Former Member
0 Likes
2,439

HI,

Check this FM BKK_GET_PRIOR_WORKDAY

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,439

Hello Ramesh,

I assume you have your factory calendar ID with you:

DATA:
    L_V_PREDT        TYPE DATUM, "Next Day.

  L_V_PREDT = SY-DATUM - 1.

* Get the next Working Day as per Factory Calendar
  CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
    EXPORTING
      CORRECT_OPTION               = '-' " -VE  to get the previous date
      DATE                         = L_V_PREDT
      FACTORY_CALENDAR_ID          = 'HY' "--> Give your factory cal. ID here
    IMPORTING
      DATE                         = V_PREWD
    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 SY-SUBRC <> 0.
*  Do Nothing
  ENDIF.

If you want to use the FM: BKK_GET_PRIOR_WORKDAY, still then you have to use the operation:

L_V_PREDT = SY-DATUM - 1.

And pass L_V_PREDT to the FM. You can test with 23.03.2009 date & check )

Hope this helps.

BR,

Suhas

Edited by: Suhas Saha on Mar 19, 2009 4:56 PM

Read only

Former Member
0 Likes
2,439

Thanks for everyone