ABAP顾问
分类:
2008-07-25 11:29:37
REPORT z_barry_test NO STANDARD PAGE HEADING .
PARAMETERS: date1 LIKE sy-datum DEFAULT '20081016',
date2 LIKE sy-datum DEFAULT '20081017',
p_cal LIKE tfacd-ident DEFAULT 'CN' .
DATA: days TYPE i.
PERFORM get_work_days USING date1 date2 days p_cal.
WRITE : date1, date2, days.
PERFORM add_workingday USING date1 days p_cal date2.
WRITE : / date1, date2, days.
*&---------------------------------------------------------------------*
*& Form add_workingday
*&---------------------------------------------------------------------*
* 根据工厂日历添加正负N天获得新日期
*----------------------------------------------------------------------*
FORM add_workingday USING value(p_date1) p_days p_cal p_date2.
DATA: return LIKE sy-subrc .
IF p_days <> 0 .
CALL FUNCTION 'BKK_ADD_WORKINGDAY'
EXPORTING
i_date = p_date1
i_days = p_days
i_calendar1 = p_cal
IMPORTING
e_date = p_date2
e_return = return.
ELSE.
p_date2 = p_date1 .
ENDIF.
ENDFORM. "add_workingday
*&---------------------------------------------------------------------*
*& Form get_work_days
*&---------------------------------------------------------------------*
* 根据工厂日历计算两个日期间的工作日(包含起始、结束日期)
*----------------------------------------------------------------------*
FORM get_work_days USING value(p_date1) value(p_date2) p_days p_cal.
DATA: no_workingday,holiday.
p_date1 = p_date1 - 1 .
WHILE p_date1 < p_date2.
p_date1 = p_date1 + 1.
CALL FUNCTION 'BKK_CHECK_HOLIDAY'
EXPORTING
i_date = p_date1
i_calendar1 = p_cal
IMPORTING
e_x_no_workingday = no_workingday
e_x_is_holiday = holiday
EXCEPTIONS
not_found = 1
calendar_error = 2
OTHERS = 3.
IF no_workingday <> 'X'.
p_days = p_days + 1.
ENDIF.
ENDWHILE.
ENDFORM. "get_work_days