메뉴 건너뛰기

SAP 한국 커뮤니티

workingday 기준으로 N일 후 날짜구하는 펑션입니다.

홍성현 2007.08.08 09:39 조회 수 : 5028 추천:18

 

function z_test_date.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(I_DATE) TYPE  DATUM
*"     VALUE(CNT) TYPE  I
*"  EXPORTING
*"     VALUE(O_DATE) TYPE  DATUM
*"----------------------------------------------------------------------


  data: itab like iscal_day occurs 0 with header line"휴일을 받아오는 inner table
           line type i" itab의 라인수
           isholy type c"휴일여부
           acc_date type datum, " 기준일
           res_date type datum, " 리턴일
           workingdaycnt type i" 근무일수

  acc_date = i_date.
  workingdaycnt = 0.

  check cnt > 0.

  do.
    isholy = 'N'.

*------------------------------------------------
* 기준일에 하루를 더한다.
    clear res_date.
    call function 'RP_CALC_DATE_IN_INTERVAL'
      exporting
        date      = acc_date
        days      = '1'
        months    = '00'
        signum    = '+'
        years     = '00'
      importing
        calc_date = res_date.
*------------------------------------------------

*------------------------------------------------
* 오늘 날짜가 휴일인지 체크
    clear o_date.
    clear itab.
    refresh itab.

    call function 'HOLIDAY_GET'
      exporting
        holiday_calendar = 'KR' " COUNTRY CODE
        factory_calendar = 'KR' " FACTORY ID
        date_from        = res_date
        date_to          = res_date
      tables
        holidays         = itab.

    if sy-subrc = 0.
      describe table itab lines line.
      if line <> 0.
*        loop at itab.
*        itab-date,
*        itab-freeday,
*        itab-holiday,
*        itab-holiday_id,
*        itab-txt_short,
*        itab-txt_long.
*        endloop.
        isholy = 'Y'.
      endif.
    endif.
*------------------------------------------------

    move res_date to acc_date.

    if isholy = 'N'" 휴일이 아니면 근무일을 더한다.
      add 1 to workingdaycnt .
    endif.

    if workingdaycnt = cnt.
      o_date = res_date.
      exit.
    endif.

  enddo.


endfunction.