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 for date calucation

Former Member
0 Kudos
408

Dear all,

please let me know what is the function module to know the number of working day in a month,

and also function module to calculate no of days between two dates.

best regards

10 REPLIES 10

Former Member
0 Kudos
188

Hi Prasad,

Use the FM

HR_RO_WORKDAYS_IN_INTERVAL for calculating number of work days in a given interval

DAYS_BETWEEN_TWO_DATES for calculating Days between two given dates.

Regards,

Swapna.

Former Member
0 Kudos
188

Hi

FM DAYS_BETWEEN_TWO_DATES

HRWPC_PCR_CHECK_WORKINGDAYS

RH_REQUEST_ON_WORKINGDAYS

reg

Ramya

Former Member
0 Kudos
188

FIMA_DAYS_BETWEEN_TWO_DATES can be used to get the number of days between two dates

to calculate the number of working days in a month I used my own coding. Please refer to the listing below.


FUNCTION /dcsea/za_vsl_count_work_days.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(CALENDAR) LIKE  TFACS-IDENT
*"     REFERENCE(START_DATE) LIKE  SY-DATUM
*"     REFERENCE(END_DATE) LIKE  SY-DATUM
*"  EXPORTING
*"     REFERENCE(NUMBER_OF_DAYS) TYPE  I
*"  EXCEPTIONS
*"      INVALID_DATE
*"      NO_CALENDAR_FOR_YEAR
*"----------------------------------------------------------------------

* Variables to be used
  DATA: wf_year(4) TYPE n,
        wf_month(2) TYPE n,
        wf_end_month(2) TYPE n,
        wf_start_day(2) TYPE n,
        wf_end_day(2) TYPE n,
        wf_check_day(1) TYPE n,
        wf_check_month(31) TYPE c,
        wf_check_year(4) TYPE n,
        wf_cnt TYPE i,
        wf_first(1) TYPE c,
        wf_year_ind(1) TYPE c,
        wf_month_ind(1) TYPE c,
        lv_str TYPE i,
        lv_month TYPE i,
        wf_exit.

* Check that both dates are specified
  IF start_date = 0 OR end_date = 0.
    RAISE invalid_date.
  ENDIF.
* Assign initial values
  wf_first = 'Y'.
  wf_year = start_date+0(4).
  wf_month = start_date+4(2).
  wf_start_day = start_date+6(2).
  wf_end_day = end_date+6(2).

* Get data for requested year(s)
  WHILE wf_year LE end_date+0(4).
    wf_check_year = wf_year.
    IF wf_year = end_date+0(4).
      wf_year_ind = 'Y'.
    ELSE.
      wf_year_ind = 'N'.
    ENDIF.

    SELECT SINGLE * FROM tfacs
      WHERE ident = calendar
        AND jahr = wf_check_year.

* Check which month
    CLEAR wf_check_month.

    CLEAR: wf_check_day.
    IF wf_first = 'Y'.
      wf_first = 'N'.
      wf_cnt = start_date+6(2).                             " - 1.
    ELSE.
      CLEAR wf_cnt.
    ENDIF.

    MOVE wf_month TO lv_month.
    lv_month = lv_month + 1.
*      wf_end_month = lv_month - 2.

    FIELD-SYMBOLS: <fs> TYPE ANY.

    DO 12 TIMES.
      lv_month = lv_month + 1.
      wf_end_month = lv_month - 2.

      IF wf_end_month = end_date+4(2).
        wf_month_ind = 'Y'.
      ELSE.
        wf_month_ind = 'N'.
      ENDIF.


      ASSIGN COMPONENT lv_month OF
             STRUCTURE tfacs TO <fs>.
      IF sy-subrc <> 0 OR lv_month = 15.
        EXIT.
      ENDIF.
      lv_str = strlen( <fs> ).

      DO.
        IF wf_cnt = lv_str OR
         ( wf_cnt GE end_date+6(2) AND
           wf_year_ind = 'Y' AND
           wf_month_ind = 'Y'  ).
          wf_exit = '1'.
          EXIT.
        ENDIF.

        wf_check_day = <fs>+wf_cnt(1). " wf_check_month+wf_cnt(1).
        IF wf_check_day = 1.
          ADD 1 TO number_of_days.
        ENDIF.
        ADD 1 TO wf_cnt.
      ENDDO.

      IF  wf_cnt GE end_date+6(2) AND
          wf_year_ind = 'Y'       AND
          wf_month_ind = 'Y'      AND
          wf_exit = '1'.
        EXIT.
      ENDIF.

      CLEAR: wf_cnt.

    ENDDO.

    wf_year = wf_year + 1.
    CLEAR: wf_month, wf_end_month.
    ADD 1 TO wf_month.
    ADD 3 TO wf_end_month.
* If record doesn't exist
    IF sy-subrc NE 0.
      RAISE no_calendar_for_year.
    ENDIF.
*    IF wf_month > end_date+4(2) AND
*       wf_year_ind = 'Y' AND
*       wf_month_ind = 'Y'.
*      EXIT.
*    ENDIF.
  ENDWHILE.

ENDFUNCTION.

Former Member
0 Kudos
188

Hi

Check the below FM's Hope this will help you.

DATE_COMPUTE_DAY u2013 Finds day of the month

DATE_CONV_EXT_TO_INT - user formatted date is converted to system date

DATE_GET_WEEK - convert date into year + week format

DATE_TO_DAY u2013 gives weekday from date

DATE_IN_FUTURE u2013 takes number of days and date - gives future date in user format and system format

MONTH_PLUS_DETERMINE u2013 add or subtract month from a date

RP_CALC_DATE_IN_INTERNAL u2013 add/subtract year/month/days from a date

WEEK_GET_FIRST_DAY u2013 take input as YYYYWW and it gives first day of the week.

MONTH_NAMES_GET u2013 language is only parameter. Returns internal table with months.

MONTH_PLUS_DETERMINE u2013 subtract months from date

regards

Arun

Former Member
0 Kudos
188

hi,

Here is a simple code to calculate difference between days,

DATA:
  w_d TYPE sy-datum VALUE '20090323',
  w_init TYPE sy-datum VALUE '20090101',
  w_days TYPE i.

w_days = w_d - w_init.

WRITE: w_days.

Regards

Sharath

Former Member
0 Kudos
188

Hi,

FM to know the no of working days:

CALL FUNCTION 'RKE_SELECT_FACTDAYS_FOR_PERIOD'

EXPORTING

I_DATAB = P_V_BEGIN_DATE

I_DATBI = P_V_END_DATE

I_FACTID = P_FABKL (Factory calender)

TABLES

ETH_DATS = p_eth_dats

EXCEPTIONS

DATE_CONVERSION_ERROR = 1

OTHERS = 2.

regarding the no of days between two dates, it can be acheived by subtracting from date and to date.

Hope it helps!!

Regards

Pavan

Former Member
0 Kudos
188

Hi Prasad,

Refer the link to get the no of working days in a month

Regards,

Rishikesh

former_member438956
Active Participant
0 Kudos
188

hiii,

u can use the following Fm...

Holiday_Get : Gives holidays for a country.It has two flags Freeday(for weekends)and Holiday(for public holidays).

DAY_IN_WEEK Input date and will give the name of the day 1-monday,2-Tuesday....

HR_99S_INTERVAL_BETWEEN_DATES Difference between two dates in days, weeks, months

FIMA_DAYS_AND_MONTHS_AND_YEARS Find the difference between two dates in years, months and days.

Regards,

Anil N.

Former Member
0 Kudos
188

Hi Prasad,

Use the FM given below to calculate number of day's between two dates.

SD_DATETIME_DIFFERENCE:

Give the difference in Days and Time for 2 dates

With luck,

Pritam.

Former Member
0 Kudos
188

try this function module.......

'/SDF/CMO_DATETIME_DIFFERENC'