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

function module for finding the days excluding sunday

Former Member
0 Likes
1,262

Hi Al,

can any one help me how to find the number of working days from starting date and to date excluding sundays,is there any function module

thanks

lokesh

4 REPLIES 4
Read only

Former Member
0 Likes
944

Hi,

U can find a Function module to add no of days to given date by skiping weekends and holidays in this thread.

Rgds,

Prakash

Read only

0 Likes
944
call function 'RKE_SELECT_FACTDAYS_FOR_PERIOD' 
exporting 
i_datab = start_date
i_datbi = end_date
i_factid = 'US' 
tables 
eth_dats = days.
Read only

Former Member
0 Likes
944

Are u referring to a indian calender id..

can u confirm whether the plant is maintained for this by checking in table T001W-FABKL FIELD .

and teh calender id in TFACD.

Then check this code..

REPORT ZEX8 .

tables : VBAK.

PARAMETERS : P_WERKS LIKE T001W-WERKS OBLIGATORY.

select-options : s_date for vbak-erdat OBLIGATORY.

DATA : WRK_DYS TYPE I ,
       TOT_DYS TYPE I ,
       HOL_DYS TYPE I.
DATA: calid LIKE tfacd-ident.
DATA : BEGIN OF ITAB OCCURS 0,
       DATE   LIKE SY-DATUM,
       END OF ITAB.

DATA : BEGIN OF IWRK OCCURS 0,
       WRDATE   LIKE SY-DATUM,
       END OF IWRK.

DATA : BEGIN OF IHOL OCCURS 0,
       HOLDAY   LIKE SY-DATUM,
       END OF IHOL.


DATA : V_DATE LIKE SY-DATUM.

      IF S_DATE-LOW ne '00000000'.
      PERFORM FILLTAB.
      ENDIF.

*     LOOP AT ITAB.
*     WRITE:/ ITAB-DATE.
*     ENDLOOP.

DESCRIBE TABLE ITAB LINES TOT_DYS.
WRITE:/ 'TOTAL NUMBER OF DAYS ARE', TOT_DYS.


     PERFORM FCT_CALID.

     PERFORM WRK_DAYS.

     PERFORM DISP_WRKDYS.

     PERFORM DISP_HOLDAYS.

form FILLTAB.
 ITAB-DATE = S_DATE-LOW.
 APPEND ITAB.
  IF S_DATE-HIGH ne '00000000'.

  IF S_DATE-LOW = S_DATE-HIGH.
  EXIT.
  ENDIF.

  ADD 1 To S_DATE-LOW.
  PERFORM FILLTAB.

  ENDIF.

endform.                    " FILLTAB
*&---------------------------------------------------------------------*
*&      Form  WRK_DAYS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form WRK_DAYS.
LOOP AT ITAB.
         V_DATE = ITAB-DATE.


 CALL FUNCTION 'DATE_CHECK_WORKINGDAY'
             EXPORTING
               date                             = V_DATE
               factory_calendar_id              = CALID
               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 EQ 0.
            IWRK-WRDATE = V_DATE.
            APPEND IWRK.
            CLEAR  IWRK.

            ELSE.
            IHOL-HOLDAY = V_DATE.
            APPEND IHOL.
            CLEAR  IHOL.

           ENDIF.

    ENDLOOP.

endform.                    " WRK_DAYS
*&---------------------------------------------------------------------*
*&      Form  DISP_WRKDYS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form DISP_WRKDYS.

DESCRIBE TABLE IWRK LINES WRK_DYS.
LOOP AT IWRK.
AT FIRST.
skip.
WRITE:/5 'WORKING DAYS'.
SKIP.
ENDAT.
WRITE:/5 IWRK-WRDATE.
ENDLOOP.

WRITE:/ 'Total number of working days are', wrk_Dys.
skip.
endform.                    " DISP_WRKDYS
*&---------------------------------------------------------------------*
*&      Form  DISP_HOLDAYS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form DISP_HOLDAYS.
DESCRIBE TABLE IHOL LINES HOL_DYS.

LOOP AT IHOL.
AT FIRST.
skip.
WRITE:/5 'NON WORKING DAYS ARE '.
SKIP.
ENDAT.
WRITE:/5 IHOL-HOLDAY.
ENDLOOP.
WRITE:/ 'Total number of NON working days are', HOL_Dys.
skip.

endform.                    " DISP_HOLDAYS
*&---------------------------------------------------------------------*
*&      Form  FCT_CALID
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form FCT_CALID.

    SELECT SINGLE fabkl INTO calid FROM t001w
           WHERE werks = P_werks.

endform.                    " FCT_CALID

regards,

vijay

Read only

Former Member
0 Likes
944

1. DATE_CHECK_WORKINGDAY

This is one useful FM

2. Try this code (just copy paste)

IT DOES EXACTLY WHAT U REQUIRE.

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

I hope it helps.