|| 您当前的位置:首页 > SAP HR资源网

ABAP - 日期格式转换

来源:中国护士网  作者:www.512test.com  (查看评论)

现在提供以下一些日期格式转换的函数;

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(4TYPE c,
        lv_month(2TYPE c,
        lv_day(2TYPE 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.

考试辅导
最近更新内容
Google广告