1, 计算两日期之间间隔的天数
FIMA_DAYS_AND_MONTHS_AND_YEARS
计算两日期之间间隔的天数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
DATA: days TYPE i, months TYPE i, years TYPE i. CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS' EXPORTING i_date_from = '20130101' i_date_to = '20141001' i_flg_separate = ' ' "是否单独计算 若有标识,则返回两日期相差的天数 IMPORTING e_days = days "返回天数:638 e_months = months "返回月数:21 e_years = years. "返回年数:2 * 单独计算 CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS' EXPORTING i_date_from = '20130101' i_date_to = '20141001' i_flg_separate = 'X' "标识 'X' IMPORTING e_days = days "返回天数:0 e_months = months "返回月数:9 e_years = years. "返回年数:1 |
2, 比较两个日期大小
FIMA_DATE_COMPARE
比较两个日期大小,返回结果是关系操作符:GT、EQ、LT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
TYPE-POOLS trff . DATA log_op TYPE trff_type_c_2. CALL FUNCTION 'FIMA_DATE_COMPARE' EXPORTING i_flg_intraday = ' ' i_date = '20140101' i_time = '000000' i_sincl = '0' "计算期间开始的排除标识 i_sult = ' ' "计算期间开始的月末标识符 i_comp_date = '20140201' "比较日期 i_comp_time = '000000' "比较时间 i_comp_sincl = '0' "计算期间结束的包含标识 i_comp_sult = ' ' "计算期间结束的月末标识符 IMPORTING e_log_op = log_op. "返回比较结果:LT |
3, 两日期的时间差
SD_DATETIME_DIFFERENCE
两个日期作差,即是两个日期相减,包括当天时间。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
DATA: datediff TYPE p, timediff TYPE p, earliest TYPE c. CALL FUNCTION 'SD_DATETIME_DIFFERENCE' EXPORTING date1 = '20140101' time1 = '240000' date2 = '20140101' time2 = '083000' IMPORTING datediff = datediff "返回日期差:0 timediff = timediff "返回时间差:16 earliest = earliest "返回时间正负:2,1-负 0-相等 2-正 EXCEPTIONS invalid_datetime = 1 OTHERS = 2. |
4, 时间:12/24小时制转换
HRVE_CONVERT_TIME
12小时制与24小时制的时间转换,例如:07:00:00 pm -> 19:00:00。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
DATA: lv_in_time TYPE tims, lv_out_time TYPE tims, lv_am_pm TYPE c. lv_in_time = '060000'. CALL FUNCTION 'HRVE_CONVERT_TIME' EXPORTING type_time = 'B' " A = 24小时制 -> 12小时制 B = 12小时制 -> 24小时制 input_time = lv_in_time input_am_pm = 'PM' IMPORTING output_time = lv_out_time output_am_pm = lv_am_pm EXCEPTIONS parameter_error = 1 OTHERS = 2. WRITE:/ | Input Time - { lv_in_time }|. " 输出:060000 WRITE:/ |Output Time - { lv_out_time }|. " 输出:180000 |
5, 获取所有的月份名字
MONTH_NAMES_GET
获取所有的月份名字信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
DATA return_code TYPE sy-subrc. DATA month_names TYPE STANDARD TABLE OF t247. CALL FUNCTION 'MONTH_NAMES_GET' EXPORTING language = sy-langu "系统当前语言 IMPORTING return_code = return_code "返回 SY-SUBRC TABLES month_names = month_names "返回月份信息 EXCEPTIONS month_names_not_found = 1 OTHERS = 2. |
month_names 明细内容:
6, 获取所有的星期名字
WEEKDAY_GET
获取所有的星期名字
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
DATA return_code TYPE sy-subrc. DATA weekday TYPE STANDARD TABLE OF t246. CALL FUNCTION 'WEEKDAY_GET' EXPORTING language = sy-langu "系统当前语言 IMPORTING return_code = return_code "返回 SY-SUBRC TABLES weekday = weekday "返回星期名字信息 EXCEPTIONS weekday_not_found = 1 OTHERS = 2. |
weekday 内容明细:
7, 查看日期属性 包括:该日期是星期几,第几天(周2=2),是不是公共假期等 需要输入国家日历
DAY_ATTRIBUTES_GET
查看日期属性 包括:该日期是星期几,第几天,是否公共假期等;
公共假期等内容需要输入国家日历。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
DATA: year_of_valid_from TYPE scal-year, year_of_valid_to TYPE scal-year, return_code TYPE sy-subrc. DATA day_attributes TYPE STANDARD TABLE OF casdayattr. CALL FUNCTION 'DAY_ATTRIBUTES_GET' EXPORTING factory_calendar = ' ' "工厂日历ID holiday_calendar = ' ' "假期日历ID date_from = '20140101' "开始日期 date_to = '20140110' "截止日期 language = sy-langu "系统当前语言 non_iso = ' ' IMPORTING year_of_valid_from = year_of_valid_from year_of_valid_to = year_of_valid_to returncode = return_code TABLES day_attributes = day_attributes "返回日期每日属性 EXCEPTIONS factory_calendar_not_found = 1 holiday_calendar_not_found = 2 date_has_invalid_format = 3 date_inconsistency = 4 OTHERS = 5. |
day_attributes 内容明细:
8, 弹出日历对话框
F4_CLOCK 弹出时间对话框,供用户选择时间
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
PARAMETERS:p1(6) TYPE c. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p1. DATA:l_date TYPE sy-datum. CALL FUNCTION 'F4_DATE' EXPORTING date_for_first_month = sy-datum IMPORTING select_date = l_date "用户选择后返回的日期 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. |
为 F4 帮助显示日历,弹出日历对话框,供用户选择日期
显示效果:
9, 弹出选择年和月的对话框
POPUP_TO_SELECT_MONTH
为 F4 帮助显示月份:弹出选择年和月的对话框
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
PARAMETERS: p_year TYPE mard-lfgja DEFAULT sy-datum+0(4), p_month TYPE mard-lfmon. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_month. DATA: actual_month LIKE isellist-month, selected_month LIKE isellist-month, return_code TYPE sy-subrc. CONCATENATE p_year sy-datum+4(2) INTO actual_month. CALL FUNCTION 'POPUP_TO_SELECT_MONTH' EXPORTING actual_month = actual_month "传入年份 factory_calendar = ' ' "工厂日历 ID holiday_calendar = ' ' "假日日历 ID language = sy-langu "当前系统语言 start_column = 8 "弹出框屏幕位置 start_row = 5 "弹出框屏幕位置 IMPORTING selected_month = selected_month "返回用户输入月份 return_code = return_code "返回 sy-subrc EXCEPTIONS factory_calendar_not_found = 1 holiday_calendar_not_found = 2 month_not_found = 3 OTHERS = 4. IF return_code = 0. p_year = selected_month+0(4). p_month = selected_month+4(2). ENDIF. |
效果显示:
10, 弹出时间对话框
F4_CLOCK
为 F4 帮助显示时间,弹出时间对话框,供用户选择时间
1 2 3 4 5 6 7 8 9 10 11 12 |
PARAMETERS:p1(6) TYPE c. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p1. DATA: l_time TYPE sy-uzeit. CALL FUNCTION 'F4_CLOCK' EXPORTING start_time = sy-uzeit display = ' ' IMPORTING selected_time = l_time. |
效果显示:
11, 弹出选择周的对话框
POPUP_CALENDAR_SDB
1 2 3 4 5 6 7 8 9 10 11 12 13 |
DATA: begin_date TYPE sy-datum, end_date TYPE sy-datum. CALL FUNCTION 'POPUP_CALENDAR_SDB' EXPORTING sel_day = 'X' "启用天 选择 sel_week = 'X' "启用周 选择 sel_month = 'X' "启用月 选择 sel_interval = 'X' focus_day = sy-datum "默认选择日期 IMPORTING begin_date = begin_date "返回选择周第一天 end_date = end_date. "返回选择周最后一天 |
效果显示:
12, 获得当前的财政年(fiscal year)
GET_CURRENT_YEAR
获得当前的财政年(Fiscal year)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
DATA: currm TYPE bkpf-monat, curry TYPE bkpf-gjahr, prevm TYPE bkpf-monat, prevy TYPE bkpf-gjahr. CALL FUNCTION 'GET_CURRENT_YEAR' EXPORTING bukrs = '3010' "输入公司代码 date = sy-datum "输入日期 IMPORTING currm = currm "当前会计期间 curry = curry "当前会计年度 prevm = prevm "上期会计期间 prevy = prevy. "上期会计年度 |
13, 获得期间首日
FIRST_DAY_IN_PERIOD_GET
14, 获得期间末日
LAST_DAY_IN_PERIOD_GET
以上。
发表评论