前段时间做一个BDC,自动生成销售订单的,后来用户反映有一张单生成不了发票,检查后发现原来是出具发票日期竟然是1114.10.20,本来应该是2010.11.14;原因是我在做录制屏幕的时候日期字段是使用SY-DATUM,但是用户的个人数据设置中其日期格式是DD.MM.YYYY,结果自动生成的单的日期就变位了;
现在提供以下一些日期格式转换的函数;
Below are several FMs which can be used to convert date format.
1. CONVERSION_EXIT_IDATE_OUTPUT
INPUT: 20080203
OUTPUT: 03FEB2008
2. CONVERT_DATE_TO_EXTERNAL
INPUT: 20080203
OUTPUT: 02/03/2008 "According to user's default setting.
3. CONVERT_DATE_TO_INTERNAL
INPUT: 02/03/2008 "Should be same as the user's default setting
OUPUT: 20080203
We can also use following code to convert date format as per user's default setting.(change date format as per user's default setting)
以下是自己写的FUN,标准的FUN是CONVERT_DATE_FORMAT,但不能满足我的需求,我们要求根据用户的个人数据设置日期格式来改变日期的显示格式。
SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #C7EDCC; } .L1S31 { font-style. italic; color: #808080; } .L1S32 { color: #3399FF; } .L1S33 { color: #4DA619; } .L1S52 { color: #0000FF; } FUNCTION ZCONVERT_DATE_FORMAT.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(ZNAME) LIKE USR01-BNAME
*" CHANGING
*" REFERENCE(ZDATE) TYPE C
*"----------------------------------------------------------------------
DATA: lv_datfm LIKE usr01-datfm,
lv_year(4) TYPE c,
lv_month(2) TYPE c,
lv_day(2) TYPE c.
*zdate = sy-datum.
lv_year = zdate+0(4).
lv_month = zdate+4(2).
lv_day = zdate+6(2).
SELECT datfm INTO lv_datfm FROM usr01
UP TO 1 ROWS WHERE bname = zname .
ENDSELECT.
IF sy-subrc = 0.
CLEAR zdate.
CASE lv_datfm.
WHEN '1'.
CONCATENATE lv_day
lv_month
lv_year INTO zdate SEPARATED BY '.'.
WHEN '2'.
CONCATENATE lv_month
lv_day
lv_year INTO zdate SEPARATED BY '/'.
WHEN '3'.
CONCATENATE lv_month
lv_day
lv_year INTO zdate SEPARATED BY '-'.
WHEN '4'.
CONCATENATE lv_year
lv_month
lv_day INTO zdate SEPARATED BY '.'.
WHEN '5'.
CONCATENATE lv_year
lv_month
lv_day INTO zdate SEPARATED BY '/'.
WHEN '6'.
CONCATENATE lv_year
lv_month
lv_day INTO zdate SEPARATED BY '-'.
ENDCASE.
ELSE.
CLEAR zdate.
CONCATENATE lv_month
lv_day
lv_year INTO zdate SEPARATED BY '.'.
ENDIF.
ENDFUNCTION.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16978623/viewspace-680282/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/16978623/viewspace-680282/