Monday, October 31, 2016

Schedule duration on factory calendar in ERP

form schedule
  using
    iv_start_date type d
    iv_factorty_calendar type wfcid
    iv_length type i
  changing ev_end_date type d.

  data lv_factory_date type facdate.

  clear ev_end_date.

  call function 'DATE_CONVERT_TO_FACTORYDATE'
    exporting
      date                         = iv_start_date
      factory_calendar_id          = iv_factorty_calendar
    importing
      factorydate                  = lv_factory_date
    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.
    write / 'Exception'.
    ev_end_date = iv_start_date + iv_length.
    return.
  endif.

  add iv_length to lv_factory_date.

  call function 'FACTORYDATE_CONVERT_TO_DATE'
    exporting
      factorydate                  = lv_factory_date
      factory_calendar_id          = iv_factorty_calendar
    importing
      date                         = ev_end_date
    exceptions
      calendar_buffer_not_loadable = 1
      factorydate_after_range      = 2
      factorydate_before_range     = 3
      factorydate_invalid          = 4
      factory_calendar_id_missing  = 5
      factory_calendar_not_found   = 6
      others                       = 7.

  if sy-subrc <> 0.
    write / 'Exception'.
    ev_end_date = iv_start_date + iv_length.
  endif.

endform.

No comments:

Post a Comment

SAP ABAP: Determine Timezone for Plant

    DATA:       lt_tzone TYPE STANDARD TABLE OF tznzone WITH DEFAULT KEY,       l_tzone  TYPE tznzone.     " get time zone for plant   ...