abap获取日期_ABAP-日期转换成中文

这个ABAP函数将日期(例如080808)转换为中文格式,如2008年08月08日。通过内部调用函数'CONVERT_DATE_TO_INTERNAL'获取日期,然后逐个将年、月、日的数字转换为中文字符。
摘要由CSDN通过智能技术生成

FUNCTION ZDATE_CONVERT_CN.

*"----------------------------------------------------------------------

*"*"Local interface:

*"  IMPORTING

*"     VALUE(I_DATUM) TYPE  SYDATUM DEFAULT SY-DATUM

*"  EXPORTING

*"     VALUE(E_YEAR) TYPE  CHAR10

*"     VALUE(E_MONTH) TYPE  CHAR6

*"     VALUE(E_DAY) TYPE  CHAR8

*"     REFERENCE(E_CNDAT) TYPE  CHAR24

*"----------------------------------------------------------------------

* Input 080808 ==>2008.08.08

DATA: l_datum TYPE sy-datum.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

date_external            = i_datum

IMPORTING

date_internal            = l_datum

EXCEPTIONS

date_external_is_invalid = 1

OTHERS                   = 2.

CHECK sy-subrc EQ 0.

DATA:l_xyear TYPE c LENGTH 8, " 年

l_month TYPE c LENGTH 2, " 月

l_xdate TYPE c.          " 日

DATA: l_year1 TYPE c LENGTH 2,

l_year2 TYPE c LENGTH 2,

l_year3 TYPE c LENGTH 2,

l_year4 TYPE c LENGTH 2.

*Year

l_xyear = l_datum(4) .

l_year1 = l_xyear(1) .

l_year2 = l_xyear+1(1) .

l_year3 = l_xyear+2(1) .

l_year4 = l_xyear+3(1) .

*Month

l_month   =  l_datum+4(2) .

*Day

l_xdate   =  l_datum+6(2).

*Convert Year to Chinese

PERFORM frm_digit_to_chinese USING l_year1

CHANGING l_year1.

PERFORM frm_digit_to_chinese USING l_year2

CHANGING l_year2.

PERFORM frm_digit_to_chinese USING l_year3

CHANGING l_year3.

PERFORM frm_digit_to_chinese USING l_year4

CHANGING l_year4.

CONCATENATE l_year1 l_year2 l_year3 l_year4 INTO l_xyear .

CONCATENATE l_xyear '年' INTO e_year.

CONDENSE e_year.

*Convert Month To Chinese

PERFORM frm_digit_to_chinese USING l_month

CHANGING e_month.

CONCATENATE e_month '月' INTO e_month.

CONDENSE e_month.

*Convert Day To Chinese

PERFORM frm_digit_to_chinese USING l_xdate

CHANGING e_day   .

CONCATENATE e_day '日' INTO e_day.

CONDENSE e_day.

*Concatenate Year Month Day inot Chinese Character.

CONCATENATE e_year e_month e_day INTO e_cndat.

CONDENSE e_cndat.

ENDFUNCTION.

*----------------------------------------------------------------------*

***INCLUDE LZDATE_CONVERT_CNF01 .

*----------------------------------------------------------------------*

*&---------------------------------------------------------------------*

*&      Form  frm_digit_to_chinese

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM frm_digit_to_chinese USING f_in

CHANGING f_out.

CASE f_in.

* For year

WHEN '0' .

f_out = '零'.

WHEN '1' .

f_out = '一'.

WHEN '2' .

f_out = '二'.

WHEN '3'.

f_out = '三'.

WHEN '4'.

f_out = '四'.

WHEN '5'.

f_out = '五'.

WHEN '6'.

f_out = '六'.

WHEN '7'.

f_out = '七'.

WHEN '8'.

f_out = '八'.

WHEN '9'.

f_out = '九'.

* Following is for Month and Day

WHEN '01' .

f_out = '一'.

WHEN '02' .

f_out = '二'.

WHEN '03'.

f_out = '三'.

WHEN '04'.

f_out = '四'.

WHEN '05'.

f_out = '五'.

WHEN '06'.

f_out = '六'.

WHEN '07'.

f_out = '七'.

WHEN '08'.

f_out = '八'.

WHEN '09'.

f_out = '九'.

WHEN '10'.

f_out = '十'.

WHEN '11'.

f_out = '十一'.

WHEN '12'.

f_out = '十二'.

WHEN '13'.

f_out = '十三'.

WHEN '14'.

f_out = '十四'.

WHEN '15'.

f_out = '十五'.

WHEN '16'.

f_out = '十六'.

WHEN '17'.

f_out = '十七'.

WHEN '18'.

f_out = '十八'.

WHEN '19'.

f_out = '十九'.

WHEN '20'.

f_out = '二十'.

WHEN '21' .

f_out = '二十一'.

WHEN '22' .

f_out = '二十二'.

WHEN '23'.

f_out = '二十三'.

WHEN '24'.

f_out = '二十四'.

WHEN '25'.

f_out = '二十五'.

WHEN '26'.

f_out = '二十六'.

WHEN '27'.

f_out = '二十七'.

WHEN '28'.

f_out = '二十八'.

WHEN '29'.

f_out = '二十九'.

WHEN '30'.

f_out = '三十'.

WHEN '31'.

f_out = '三十一'.

ENDCASE.

ENDFORM.                    " frm_digit_to_chinese

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值