*&---------------------------------------------------------------------*
*& Report ZQWE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZQWE.
DATA: DATE1 LIKE SY-DATUM,
DATE2 LIKE SY-DATUM,
DATE3 LIKE SY-DATUM,
DATE4 LIKE SY-DATUM,
DATE5 LIKE SY-DATUM,
DATE6 LIKE SY-DATUM,
DATE7 LIKE SY-DATUM.
DATA: WEEK1 LIKE SCAL-WEEK,
WEEK2 LIKE SCAL-WEEK.
DATA: DAYS TYPE I.
DATA: SUND TYPE P.
DATA: DATE_L LIKE SY-DATUM,
TIME_L LIKE SY-UZEIT.
PARAMETERS: GJAHR TYPE GJAHR OBLIGATORY,
MONAT TYPE MONAT OBLIGATORY,
TIME LIKE SY-UZEIT.
"搜索帮助
AT SELECTION-SCREEN ON VALUE-REQUEST FOR GJAHR.
CALL FUNCTION 'F4_DATE'
EXPORTING
DATE_FOR_FIRST_MONTH = SY-DATUM
IMPORTING
SELECT_DATE = DATE_L
EXCEPTIONS
CALENDAR_BUFFER_NOT_LOADABLE = 1
DATE_AFTER_RANGE = 2
DATE_BEFORE_RANGE = 3
DATE_INVALID = 4
FACTORY_CALENDAR_NOT_FOUND = 5
HOLIDAY_CALENDAR_NOT_FOUND = 6
PARAMETER_CONFLICT = 7
OTHERS = 8
.
IF SY-SUBRC = 0.
GJAHR = DATE_L+0(4).
ENDIF.
START-OF-SELECTION.
"某个月第一天
CONCATENATE GJAHR MONAT '01' INTO DATE1.
"某个月最后一天
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
DAY_IN = DATE1
IMPORTING
LAST_DAY_OF_MONTH = DATE2
EXCEPTIONS
DAY_IN_NO_DATE = 1
OTHERS = 2.
"两个日期之间的天数
DAYS = DATE2 - DATE1.
"年度,月份,天数,往前往后推
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL' "从当前的日期往前推3个月得到一个日期
EXPORTING
DATE = DATE2
DAYS = 0
MONTHS = 1
SIGNUM = '+'
YEARS = 0
IMPORTING
CALC_DATE = DATE3.
"根据日期获取到周数
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
DATE = DATE3
IMPORTING
WEEK = WEEK1
EXCEPTIONS
DATE_INVALID = 1
OTHERS = 2.
"获取该周第一天
CALL FUNCTION 'WEEK_GET_FIRST_DAY'
EXPORTING
WEEK = WEEK1
IMPORTING
DATE = DATE4
EXCEPTIONS
WEEK_INVALID = 1
OTHERS = 2.
"根据周数,获取下一周周数,星期一与星期天
CALL FUNCTION 'NEXT_WEEK'
EXPORTING
CURRENT_WEEK = WEEK1
IMPORTING
NEXT_WEEK = WEEK2
MONDAY = DATE5
SUNDAY = DATE6 .
"根据日期获取星期几
"返回为数字,数字与星期X或者monday之类对应关系TABLES: T246.
CALL FUNCTION 'DAY_IN_WEEK'
EXPORTING
DATUM = DATE4
IMPORTING
WOTNR = SUND .
WRITE:/ DATE1, DATE2, DAYS, DATE3, WEEK1, DATE4, SUND, WEEK2, DATE5, DATE6.
将日期由内部格式转换成外部格式,比如'20121020'转换成'2012.10.20',BDC的时候可能用到
CONVERT_DATE_TO_EXTERNAL
将日期由外部格式转成内部格式,从屏幕取值的时候可能用到
CONVERT_DATE_TO_INTERNAL