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: 

Number of weekdays

Former Member
0 Kudos

I need to find the number of week days(mon-fri) in a given month. I have used the FM DATE_CONVERT_TO_FACTORYDATE to get the difference between the first and the last day of the month. However it is not giving me the correct output. could someone please let me know how I can get the desired output?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

You can try:


REPORT ztest MESSAGE-ID 00.

DATA: start_date   TYPE sy-datum,
      day_name     TYPE hrvsched-daytxt,
      no_week_days TYPE i,
      this_month(2).

start_date   = sy-datum.
this_month   = sy-datum+4(2).
start_date+6 = '01'.

DO.
  CALL FUNCTION 'RH_GET_DATE_DAYNAME'
    EXPORTING
      langu               = sy-langu
      date                = start_date
    IMPORTING
      daytxt              = day_name
    EXCEPTIONS
      no_langu            = 1
      no_date             = 2
      no_daytxt_for_langu = 3
      invalid_date        = 4
      OTHERS              = 5.

  IF day_name <> 'Saturday' AND
     day_name <> 'Sunday'.
    no_week_days = no_week_days + 1.
  ENDIF.

  start_date = start_date + 1.
  IF start_date+4(2) <> this_month.
    EXIT.
  ENDIF.

ENDDO.

WRITE: 'This month has', no_week_days, 'week days'.

Rob

6 REPLIES 6

Former Member
0 Kudos
hi,

Chk this code given by amit

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

ferry_lianto
Active Contributor
0 Kudos

Hi,

Please check this sample code from other thread.


report zrich_0002.
 
data: duration_in_days type i.
 
parameters: s_date type sy-datum,
            e_date type sy-datum.
 
call function 'DURATION_DETERMINE'
 exporting
   factory_calendar                 = 'P6'
 importing
   duration                         = duration_in_days
 changing
   start_date                       = s_date
   end_date                         = e_date
 exceptions
   factory_calendar_not_found       = 1
   date_out_of_calendar_range       = 2
   date_not_valid                   = 3
   unit_conversion_error            = 4
   si_unit_missing                  = 5
   parameters_not_valid             = 6
   others                           = 7.

Regards,

Ferry Lianto

Former Member
0 Kudos

Try FM: RKE_SELECT_FACTDAYS_FOR_PERIOD

Thanks,

Santosh

Former Member
0 Kudos

Hello,

In your system, there would be one or more calendars defined, get the 2 byte calendar id to be used to get check the holiday from the functional people (or check txn SCAL, or tables THOC*).

Now, you have some function modules you can use to check the work-days (I do not think you have one which will give you the no of working days for a period, so you may have to run it for each date to count the no of days), the code may look like

*say your period is from w_fromdate to w_todate, and

  • calendar is in w_calid

data : w_date like sy-datum.

data : no_of_workdays type i.

w_date = w_fromdate.

do.

CALL FUNCTION 'DATE_CHECK_WORKINGDAY'

EXPORTING

DATE = w_date

FACTORY_CALENDAR_ID = w_calid

MESSAGE_TYPE = 'W'

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.

no_of_workday = no_of_workday + 1.

endif.

w_date = w_date + 1.

if w_date gt w_todate.

exit.

endif.

enddo.

*no_of_workdays shall get you the count of work days

Vasanth

Former Member
0 Kudos

You can try:


REPORT ztest MESSAGE-ID 00.

DATA: start_date   TYPE sy-datum,
      day_name     TYPE hrvsched-daytxt,
      no_week_days TYPE i,
      this_month(2).

start_date   = sy-datum.
this_month   = sy-datum+4(2).
start_date+6 = '01'.

DO.
  CALL FUNCTION 'RH_GET_DATE_DAYNAME'
    EXPORTING
      langu               = sy-langu
      date                = start_date
    IMPORTING
      daytxt              = day_name
    EXCEPTIONS
      no_langu            = 1
      no_date             = 2
      no_daytxt_for_langu = 3
      invalid_date        = 4
      OTHERS              = 5.

  IF day_name <> 'Saturday' AND
     day_name <> 'Sunday'.
    no_week_days = no_week_days + 1.
  ENDIF.

  start_date = start_date + 1.
  IF start_date+4(2) <> this_month.
    EXIT.
  ENDIF.

ENDDO.

WRITE: 'This month has', no_week_days, 'week days'.

Rob

Former Member
0 Kudos

Thanks a lot Rob. This is exactly what i needed.