http://erp.sarang.net/?task=bbs&order=read&inf_seq_no=8&id=28690&page=3&mode=&list_count=10&thread=ok&main_order=2&menu_wise=
FUNCTION zhr_convert_date_lunar.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(I_DATE) LIKE SY-DATUM DEFAULT '19740225'
*" REFERENCE(LUNAR) TYPE C DEFAULT 'X'
*" REFERENCE(CURR) TYPE C DEFAULT 'X'
*" REFERENCE(YOON) TYPE C OPTIONAL
*" EXPORTING
*" REFERENCE(O_DATE) LIKE SY-DATUM
*"----------------------------------------------------------------------
** 1882~2050년도까지가능
** LUNAR 체크시 양력날짜를 음력으로 표시
** CURR 체크시 변환한 날짜를 현재연도로 표시
* TABLES : zhrt042.
**임시테이블
DATA : yd LIKE zhrt042 OCCURS 100 WITH HEADER LINE,
md LIKE zhrt042 OCCURS 10 WITH HEADER LINE,
dt LIKE zhrt042-data OCCURS 10 WITH HEADER LINE.
**임시변수들
DATA : rem1 TYPE i,
rem2 TYPE i,
rem3 TYPE i.
DATA : year(4),
month(2),
day(2),
syear(4) TYPE n,
smonth(2) TYPE n,
sday(2) TYPE n,
d1 LIKE zhrt042-data.
DATA : lyear(4),
lmonth(2),
lday(2),
y1(4) TYPE n,
y2(4) TYPE n,
m1 TYPE i,
mm(2),
leapyes TYPE i,
td(16) TYPE p,
i TYPE i,
j TYPE i,
j2 TYPE i,
a TYPE i,
b TYPE i,
c TYPE i,
m1_1 TYPE i,
y(4) TYPE n,
m1_i TYPE n,
y1_i TYPE i.
SELECT * FROM zhrt042
APPENDING TABLE yd
WHERE gubun = 'Y'.
SELECT * FROM zhrt042
APPENDING TABLE md
WHERE gubun = 'M'.
year = i_date(4).
month = i_date+4(2).
day = i_date+6(2).
** 음력을 양력으로
IF lunar = 'X'. "
IF curr = 'X'.
year = sy-datum(4).
ENDIF.
lyear = year.
lmonth = month.
lday = day.
y1 = lyear - 1840.
m1 = lmonth - 1.
leapyes = 0.
READ TABLE yd INDEX y1.
IF yd-data+m1(1) > 2.
IF yoon = 'X'.
leapyes = 1.
CASE yd-data+m1(1).
WHEN 3 OR 5.
mm = 29.
WHEN 4 OR 6.
mm = 30.
ENDCASE.
ENDIF.
ELSE.
CASE yd-data+m1(1).
WHEN 1 OR 3 OR 4.
mm = 29.
WHEN 2 OR 5 OR 6.
mm = 30.
ENDCASE.
ENDIF.
td = 0. i = 1. j = 0.
WHILE i < y1.
CLEAR : yd.
j = 0.
READ TABLE yd INDEX i.
WHILE j < 12.
CASE yd-data+j(1).
WHEN 1.
td = td + 29.
WHEN 2.
td = td + 30.
WHEN 3.
td = td + 58.
WHEN 4.
td = td + 59.
WHEN 5.
td = td + 59.
WHEN 6.
td = td + 60.
ENDCASE.
ADD 1 TO j.
ENDWHILE.
ADD 1 TO i.
ENDWHILE.
j = 0.
READ TABLE yd INDEX y1.
WHILE j < m1.
CASE yd-data+j(1).
WHEN 1.
td = td + 29.
WHEN 2.
td = td + 30.
WHEN 3.
td = td + 58.
WHEN 4.
td = td + 59.
WHEN 5.
td = td + 59.
WHEN 6.
td = td + 60.
ENDCASE.
ADD 1 TO j.
ENDWHILE.
IF leapyes = 1.
CASE yd-data+m1(1).
WHEN 3 OR 4.
td = td + 29.
WHEN 5 OR 6.
td = td + 30.
ENDCASE.
ENDIF.
td = td + lday + 22.
y1 = 1840.
DO.
y1 = y1 + 1.
a = y1 MOD 400.
b = y1 MOD 100.
c = y1 MOD 4.
IF ( a = 0 ) OR ( b <> 0 ) AND ( c = 0 ).
y2 = 366.
ELSE.
y2 = 365.
ENDIF.
IF td <= y2 .
EXIT.
ELSE.
td = td - y2.
ENDIF.
ENDDO.
syear = y1.
LOOP AT md WHERE keyn = 2.
md-data = y2 - 337.
MODIFY md INDEX 2.
ENDLOOP.
CLEAR : md.
m1 = 0.
DO.
ADD 1 TO m1.
READ TABLE md INDEX m1.
IF ( td <= md-data ).
EXIT.
ELSE.
td = td - md-data.
ENDIF.
ENDDO.
FUNCTION zhr_convert_date_lunar.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(I_DATE) LIKE SY-DATUM DEFAULT '19740225'
*" REFERENCE(LUNAR) TYPE C DEFAULT 'X'
*" REFERENCE(CURR) TYPE C DEFAULT 'X'
*" REFERENCE(YOON) TYPE C OPTIONAL
*" EXPORTING
*" REFERENCE(O_DATE) LIKE SY-DATUM
*"----------------------------------------------------------------------
** 1882~2050년도까지가능
** LUNAR 체크시 양력날짜를 음력으로 표시
** CURR 체크시 변환한 날짜를 현재연도로 표시
* TABLES : zhrt042.
**임시테이블
DATA : yd LIKE zhrt042 OCCURS 100 WITH HEADER LINE,
md LIKE zhrt042 OCCURS 10 WITH HEADER LINE,
dt LIKE zhrt042-data OCCURS 10 WITH HEADER LINE.
**임시변수들
DATA : rem1 TYPE i,
rem2 TYPE i,
rem3 TYPE i.
DATA : year(4),
month(2),
day(2),
syear(4) TYPE n,
smonth(2) TYPE n,
sday(2) TYPE n,
d1 LIKE zhrt042-data.
DATA : lyear(4),
lmonth(2),
lday(2),
y1(4) TYPE n,
y2(4) TYPE n,
m1 TYPE i,
mm(2),
leapyes TYPE i,
td(16) TYPE p,
i TYPE i,
j TYPE i,
j2 TYPE i,
a TYPE i,
b TYPE i,
c TYPE i,
m1_1 TYPE i,
y(4) TYPE n,
m1_i TYPE n,
y1_i TYPE i.
SELECT * FROM zhrt042
APPENDING TABLE yd
WHERE gubun = 'Y'.
SELECT * FROM zhrt042
APPENDING TABLE md
WHERE gubun = 'M'.
year = i_date(4).
month = i_date+4(2).
day = i_date+6(2).
** 음력을 양력으로
IF lunar = 'X'. "
IF curr = 'X'.
year = sy-datum(4).
ENDIF.
lyear = year.
lmonth = month.
lday = day.
y1 = lyear - 1840.
m1 = lmonth - 1.
leapyes = 0.
READ TABLE yd INDEX y1.
IF yd-data+m1(1) > 2.
IF yoon = 'X'.
leapyes = 1.
CASE yd-data+m1(1).
WHEN 3 OR 5.
mm = 29.
WHEN 4 OR 6.
mm = 30.
ENDCASE.
ENDIF.
ELSE.
CASE yd-data+m1(1).
WHEN 1 OR 3 OR 4.
mm = 29.
WHEN 2 OR 5 OR 6.
mm = 30.
ENDCASE.
ENDIF.
td = 0. i = 1. j = 0.
WHILE i < y1.
CLEAR : yd.
j = 0.
READ TABLE yd INDEX i.
WHILE j < 12.
CASE yd-data+j(1).
WHEN 1.
td = td + 29.
WHEN 2.
td = td + 30.
WHEN 3.
td = td + 58.
WHEN 4.
td = td + 59.
WHEN 5.
td = td + 59.
WHEN 6.
td = td + 60.
ENDCASE.
ADD 1 TO j.
ENDWHILE.
ADD 1 TO i.
ENDWHILE.
j = 0.
READ TABLE yd INDEX y1.
WHILE j < m1.
CASE yd-data+j(1).
WHEN 1.
td = td + 29.
WHEN 2.
td = td + 30.
WHEN 3.
td = td + 58.
WHEN 4.
td = td + 59.
WHEN 5.
td = td + 59.
WHEN 6.
td = td + 60.
ENDCASE.
ADD 1 TO j.
ENDWHILE.
IF leapyes = 1.
CASE yd-data+m1(1).
WHEN 3 OR 4.
td = td + 29.
WHEN 5 OR 6.
td = td + 30.
ENDCASE.
ENDIF.
td = td + lday + 22.
y1 = 1840.
DO.
y1 = y1 + 1.
a = y1 MOD 400.
b = y1 MOD 100.
c = y1 MOD 4.
IF ( a = 0 ) OR ( b <> 0 ) AND ( c = 0 ).
y2 = 366.
ELSE.
y2 = 365.
ENDIF.
IF td <= y2 .
EXIT.
ELSE.
td = td - y2.
ENDIF.
ENDDO.
syear = y1.
LOOP AT md WHERE keyn = 2.
md-data = y2 - 337.
MODIFY md INDEX 2.
ENDLOOP.
CLEAR : md.
m1 = 0.
DO.
ADD 1 TO m1.
READ TABLE md INDEX m1.
IF ( td <= md-data ).
EXIT.
ELSE.
td = td - md-data.
ENDIF.
ENDDO.
smonth = m1.
sday = td.
CONCATENATE syear smonth sday INTO o_date.
*-- 양력을 음력으로
ELSE.
ENDIF.
ENDFUNCTION.