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

Find a working day

Former Member
0 Likes
1,272

Hello experts,

I need to subtract number of days (L_DAYS) from a date (L_DATE) and the result should be a working day. Any FM's to do this?

Thanks,

9 REPLIES 9
Read only

Former Member
0 Likes
1,212

Or can someone tell me how to check a date (P_DATE) is a working date in a factory calender?

Read only

0 Likes
1,212

Hello,

Please use function DATE_CHECK_WORKINGDAY.

Thanks,

Venu

Read only

Former Member
0 Likes
1,212

Please check this link:[]

Cheers,

Vikram

Read only

Former Member
0 Likes
1,212

Hello,

I never found a FM to do this so I made my own based on DATE_CONVERT_TO_FACTORYDATE. Offset is the number of days, correct_option is future or past.


FUNCTION z_date_convert_to_factorydate.
*"*"Local interface:
*"  IMPORTING
*"     VALUE(CORRECT_OPTION) LIKE  SCAL-INDICATOR DEFAULT '+'
*"     VALUE(DATE) LIKE  SCAL-DATE DEFAULT SY-DATUM
*"     VALUE(FACTORY_CALENDAR_ID) LIKE  SCAL-FCALID DEFAULT 'C1'
*"     VALUE(OFFSET) TYPE  INT4 DEFAULT 0
*"  EXPORTING
*"     VALUE(XDATE) LIKE  SCAL-DATE
*"     VALUE(FACTORYDATE) LIKE  SCAL-FACDATE
*"     VALUE(WORKINGDAY_INDICATOR) LIKE  SCAL-INDICATOR

  CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
       EXPORTING
            correct_option   = correct_option
            date  = date
            factory_calendar_id  = factory_calendar_id
       IMPORTING
            date  = xdate
            factorydate   = factorydate
            workingday_indicator  = workingday_indicator
       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 NOT workingday_indicator IS INITIAL.
    SUBTRACT 1 FROM offset.
  ENDIF.

  IF offset > 0.
    DO offset TIMES.
      CASE correct_option.
        WHEN '+'.
          ADD 1 TO xdate.
        WHEN '-'.
          SUBTRACT 1 FROM xdate.
      ENDCASE.
      CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
           EXPORTING
                correct_option  = correct_option
                date  = xdate
                factory_calendar_id  = factory_calendar_id
           IMPORTING
                date  = xdate
                factorydate   = factorydate
                workingday_indicator         = workingday_indicator
           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.
    ENDDO.
  ENDIF.
ENDFUNCTION.

Regards,

Michael

Edited by: Rob Burbank on Dec 15, 2009 4:40 PM

Read only

0 Likes
1,212

Adrian,

Do Offset times will not work or might not work depending on the requirement.

Don't know if his requirement is L_DATE - LDAYS or L_DATE - L_DAYS (working)

Ex of first one is 12/15/2009 - 5 days that is 10/12/2009 (includes saturday and sunday)

Ex. for later one is 12/15/2009 - 5 working days that is 12/8/2009 (excludes saturday and sunday)

For the first example can directly deduct those many days and use the FM DATE_CONVERT_TO_FACTORYDATE and find if it is a working day or not.

For the 2nd example the above code i have given will work.

Regards

Sandeep

Read only

Former Member
0 Likes
1,212
 
DATA: lv_working_indicator  TYPE CIND.
DATA: lv_count TYPE i.
DATA: lv_date TYPE sydatum.

lv_date = l_date
  DO.
    CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
         EXPORTING
              correct_option          = '-'
              date                    = lv_date
              factory_calendar_id     = 'Z3'
         IMPORTING
              workingday_indicator    = lv_working_indicator
         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 lv_working_indicator IS INITIAL.
      lv_count = lv_count + 1.
    ENDIF.

    IF lv_count = l_days.
      lv_required_working_date = lv_date.
      EXIT.
    ENDIF.
    lv_date  = lv_date - 1.

  ENDDO.

The above code should get you the required working day

Read only

former_member156446
Active Contributor
0 Likes
1,212

table TFACS has the factory calender... if you can split the date into year month and date and hit table TFACS if the result is 1 its a working day 0 for a holiday

Read only

Former Member
0 Likes
1,212

solved myself

Read only

0 Likes
1,212

>

> solved myself

Glad you got it going, but you'll notice that a number of people tried to give you a helping hand - maybe they deserve some points for their efforts.

If none of them helped at all, you could at least update the forum on how you solved this. That is part of

Rob