FUNCTION zfm_get_chinese_date.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(IV_DATE) TYPE SY-DATUM DEFAULT SY-DATUM
*" REFERENCE(IV_FLAG) TYPE CHAR1 OPTIONAL
*" EXPORTING
*" REFERENCE(EV_DATE) TYPE SY-DATUM
*" REFERENCE(EV_DATE_TEXT) TYPE CHAR20
*" REFERENCE(EV_ANIMAL_SIGN) TYPE CHAR10
*"----------------------------------------------------------------------
DATA: lv_year TYPE char4 ,
lv_month TYPE scmamonth ,
lv_day TYPE char2,
lv_year_export TYPE char4 ,
lv_month_export TYPE scmamonth ,
lv_day_export TYPE day_nr,
lv_year_add TYPE char4,
lv_month_add TYPE char2 ,
lv_day_add TYPE char3,
lv_run TYPE c,
lv_con_date TYPE sy-datum,
lv_set_date TYPE sy-datum,
lv_date_export TYPE char20,
lv_get_day TYPE i.
* DATA:LR_CONVERT TYPE REF TO CL_RPE_CONVERT.
* CREATE OBJECT LR_CONVERT.
*取得输入的日期
lv_year = iv_date+0(4) .
lv_month = iv_date+4(2) .
lv_day = iv_date+6(2) .
DATA:lv_1942 TYPE i.
IF lv_year < 1900.
lv_1942 = ( 1942 - lv_year ) / 19.
lv_year = lv_year + ( 19 * lv_1942 ).
ENDIF.
IF lv_year > 2100.
lv_1942 = ( lv_year - 1942 ) / 19.
lv_year = lv_year + ( 19 * lv_1942 ).
ENDIF.
DATA:lv_times TYPE i,
lv_index TYPE i,
lv_data TYPE i.
DATA:lv_month_add_int TYPE i,
lv_data_int TYPE i,
lv_data_13 TYPE char2,
lv_string TYPE string,
lv_string_i TYPE i,
lv_xstring TYPE xstring.
lv_year_add = lv_year.
*反算
IF iv_flag = 'X'.
READ TABLE gt_data WITH KEY year = lv_year_add.
IF sy-subrc = 0 .
lv_month_add = gt_data-data+14(2)."取农历1.1对应的阳历
lv_day_add = gt_data-data+16(2).
CONCATENATE lv_year_add lv_month_add lv_day_add INTO lv_con_date.
lv_day_add = lv_day.
lv_times = lv_month - 1.
lv_index = 0.
DO lv_times TIMES. "根据差异的月份计算天数
lv_data = gt_data-data+lv_index(1).
lv_index = lv_index + 1.
lv_day_add = lv_day_add + 29 + lv_data.
ENDDO.
lv_set_date = lv_con_date + lv_day_add - 1.
*是否为闰月,如果为闰月,再加上一遍闰月的天数
IF gt_data-data+13(1) > '0'.
lv_string = gt_data-data+13(1).
CASE lv_string.
WHEN 'A'.
lv_string = '10'.
WHEN 'B'.
lv_string = '11'.
WHEN 'C'.
lv_string = '12'.
ENDCASE.
IF lv_string <= lv_month.
lv_set_date = lv_set_date + 29 + gt_data-data+12(1).
ENDIF.
ENDIF.
lv_date_export = lv_set_date.
lv_year_export = lv_set_date+0(4) .
lv_month_export = lv_set_date+4(2) .
lv_day_export = lv_set_date+6(2) .
CONCATENATE lv_year_export lv_month_export lv_day_export INTO ev_date.
RETURN.
ENDIF.
ENDIF.
*初始化
DO.
READ TABLE gt_data WITH KEY year = lv_year_add.
IF sy-subrc = 0.
lv_month_add = gt_data-data+14(2).
lv_day_add = gt_data-data+16(2).
CONCATENATE lv_year_add lv_month_add lv_day_add INTO lv_con_date.
CONCATENATE lv_year lv_month lv_day INTO lv_set_date.
lv_get_day = lv_set_date - lv_con_date.
IF lv_get_day < 0.
lv_year_add = lv_year_add - 1."计算跨年的情况
ELSE.
EXIT.
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDDO.
lv_day_add = 1. lv_month_add = 1.
DO lv_get_day TIMES.
lv_day_add = lv_day_add + 1.
READ TABLE gt_data WITH KEY year = lv_year_add.
IF sy-subrc = 0.
lv_month_add_int = lv_month_add - 1.
lv_data_int = gt_data-data+lv_month_add_int(1) + 30.
lv_data_13 = gt_data-data+12(1) + 30.
IF lv_day_add = lv_data_int OR ( lv_run = 'X' AND lv_day_add = lv_data_13 ).
lv_string = gt_data-data+13(1).
CASE lv_string.
WHEN 'A'.
lv_string = '10'.
WHEN 'B'.
lv_string = '11'.
WHEN 'C'.
lv_string = '12'.
ENDCASE.
IF lv_run = '' AND lv_month_add = lv_string.
lv_run = 'X'.
ELSE.
lv_run = ''.
lv_month_add = lv_month_add + 1.
ENDIF.
lv_day_add = 1.
ENDIF.
ENDIF.
ENDDO.
lv_year_export = lv_year_add.
lv_month_export = lv_month_add.
lv_day_export = lv_day_add.
CONCATENATE lv_year_export lv_month_export lv_day_export INTO ev_date.
**农历描述
DATA:lv_count TYPE i.
DATA:lv_dd_string TYPE char100 VALUE '初一初二初三初四初五初六初七初八初九初十十一十二十三十四十五十六十七十八十九二十廿一廿二廿三廿四廿五廿六廿七廿八廿九三十'.
DATA:lv_mm_string TYPE char20 VALUE '正二三四五六七八九十冬腊'.
lv_count = ( lv_day_add - 1 ) * 2.
lv_date_export+6(2) = lv_dd_string+lv_count(2).
lv_count = lv_month_add - 1.
CONCATENATE lv_mm_string+lv_count(1) '月' INTO lv_date_export+4(2).
ev_date_text = lv_date_export.
**天干地支
DATA:lv_tg_string TYPE char10 VALUE '甲乙丙丁戊己庚辛壬癸'.
DATA:lv_dz_string TYPE char12 VALUE '子丑寅卯辰巳午未申酉戌亥'.
DATA:lv_sx_string TYPE char12 VALUE '鼠牛虎兔龙蛇马羊猴鸡狗猪'.
DATA:lv_year_text TYPE char20.
DATA:lv_mod TYPE i.
lv_mod = ( ( lv_year_export - 4 ) MOD 10 ).
lv_year_text = lv_tg_string+lv_mod(1).
lv_mod = ( ( lv_year_export - 4 ) MOD 12 ).
CONCATENATE lv_year_text lv_dz_string+lv_mod(1) '年' INTO lv_year_text.
CONCATENATE lv_year_text ev_date_text INTO ev_date_text.
CONCATENATE '属相:' lv_sx_string+lv_mod(1) INTO ev_animal_sign
ENDFUNCTION.
阅读(1453) | 评论(0) | 转发(0) |