ABAP实现农历转成公历
一個牛逼到渣的程序。
*因為要加很多的數據,所以用宏來添加算了
DEFINE?ADD_TABLE?.
??&1-NAME?=?&2?.
??APPEND?&1?.
END-OF-DEFINITION?.
*這里是天干的表
DATA:?BEGIN?OF?R_TIANGAN,
????????NAME(2)?TYPE?C,
??????END?OF?R_TIANGAN?.
DATA:?I_TIANGAN?LIKE?R_TIANGAN?OCCURS?0?WITH?HEADER?LINE?.
*這里是地支的表
DATA:?BEGIN?OF?R_DIZHI,
????????NAME(2)?TYPE?C,
??????END?OF?R_DIZHI?.
DATA:?I_DIZHI?LIKE?R_DIZHI?OCCURS?0?WITH?HEADER?LINE?.
*這里是屬相表,不過我也沒有用,如果誰想用可以添加功能
DATA:?BEGIN?OF?R_SHUXIANG,
????????NAME(2)?TYPE?C,
??????END?OF?R_SHUXIANG?.
DATA:?I_SHUXIANG?LIKE?R_SHUXIANG?OCCURS?0?WITH?HEADER?LINE.
*這里是天的名字,初一………
DATA:?BEGIN?OF?R_DAYNAME?,
????????NAME(4)?TYPE?C,
??????END?OF?R_DAYNAME?.
DATA:?I_DAYNAME?LIKE?R_DAYNAME?OCCURS?0?WITH?HEADER?LINE?.
*這里是月的名字,正月………
DATA:?BEGIN?OF?R_MONNAME?,
????????NAME(2)?TYPE?C,
??????END?OF?R_MONNAME?.
DATA:?I_MONNAME?LIKE?R_MONNAME?OCCURS?0?WITH?HEADER?LINE?.
*這里是月的差額數據
DATA:?BEGIN?OF?R_MONTHADD?,
????????NAME?TYPE?I,
??????END?OF?R_MONTHADD?.
DATA:?I_MONTHADD?LIKE?R_MONTHADD?OCCURS?0?WITH?HEADER?LINE?.
*這里就是農歷轉換表的數據,每100一更新
DATA:?BEGIN?OF?R_NONGLIDATA,
????????NAME?TYPE?I,
??????END?OF?R_NONGLIDATA?.
DATA:?I_NONGLIDATA?LIKE?R_NONGLIDATA?OCCURS?0?WITH?HEADER?LINE?.
*這里輸入日期,是公歷日期
PARAMETER?P_DATUM?LIKE?SY-DATUM?.
START-OF-SELECTION?.
**加數據,就不用多說了
??ADD_TABLE?I_TIANGAN?'甲'?.
??ADD_TABLE?I_TIANGAN?'乙'?.
??ADD_TABLE?I_TIANGAN?'丙'?.
??ADD_TABLE?I_TIANGAN?'丁'?.
??ADD_TABLE?I_TIANGAN?'戊'?.
??ADD_TABLE?I_TIANGAN?'己'?.
??ADD_TABLE?I_TIANGAN?'庚'?.
??ADD_TABLE?I_TIANGAN?'辛'?.
??ADD_TABLE?I_TIANGAN?'壬'?.
??ADD_TABLE?I_TIANGAN?'癸'?.
??ADD_TABLE?I_DIZHI?'子'.
??ADD_TABLE?I_DIZHI?'丑'.
??ADD_TABLE?I_DIZHI?'寅'.
??ADD_TABLE?I_DIZHI?'卯'.
??ADD_TABLE?I_DIZHI?'辰'.
??ADD_TABLE?I_DIZHI?'巳'.
??ADD_TABLE?I_DIZHI?'午'.
??ADD_TABLE?I_DIZHI?'未'.
??ADD_TABLE?I_DIZHI?'申'.
??ADD_TABLE?I_DIZHI?'酉'.
??ADD_TABLE?I_DIZHI?'戌'.
??ADD_TABLE?I_DIZHI?'亥'.
??ADD_TABLE?I_SHUXIANG?'鼠'?.
??ADD_TABLE?I_SHUXIANG?'牛'?.
??ADD_TABLE?I_SHUXIANG?'虎'?.
??ADD_TABLE?I_SHUXIANG?'兔'?.
??ADD_TABLE?I_SHUXIANG?'龍'?.
??ADD_TABLE?I_SHUXIANG?'蛇'?.
??ADD_TABLE?I_SHUXIANG?'馬'?.
??ADD_TABLE?I_SHUXIANG?'羊'?.
??ADD_TABLE?I_SHUXIANG?'猴'?.
??ADD_TABLE?I_SHUXIANG?'雞'?.
??ADD_TABLE?I_SHUXIANG?'狗'?.
??ADD_TABLE?I_SHUXIANG?'豬'?.
??ADD_TABLE?I_DAYNAME?'初一'?.
??ADD_TABLE?I_DAYNAME?'初二'?.
??ADD_TABLE?I_DAYNAME?'初三'?.
??ADD_TABLE?I_DAYNAME?'初四'?.
??ADD_TABLE?I_DAYNAME?'初五'?.
??ADD_TABLE?I_DAYNAME?'初六'?.
??ADD_TABLE?I_DAYNAME?'初七'?.
??ADD_TABLE?I_DAYNAME?'初八'?.
??ADD_TABLE?I_DAYNAME?'初九'?.
??ADD_TABLE?I_DAYNAME?'初十'?.
??ADD_TABLE?I_DAYNAME?'十一'?.
??ADD_TABLE?I_DAYNAME?'十二'?.
??ADD_TABLE?I_DAYNAME?'十三'?.
??ADD_TABLE?I_DAYNAME?'十四'?.
??ADD_TABLE?I_DAYNAME?'十五'?.
??ADD_TABLE?I_DAYNAME?'十六'?.
??ADD_TABLE?I_DAYNAME?'十七'?.
??ADD_TABLE?I_DAYNAME?'十八'?.
??ADD_TABLE?I_DAYNAME?'十九'?.
??ADD_TABLE?I_DAYNAME?'二十'?.
??ADD_TABLE?I_DAYNAME?'廿一'?.
??ADD_TABLE?I_DAYNAME?'廿二'?.
??ADD_TABLE?I_DAYNAME?'廿三'?.
??ADD_TABLE?I_DAYNAME?'廿四'?.
??ADD_TABLE?I_DAYNAME?'廿五'?.
??ADD_TABLE?I_DAYNAME?'廿六'?.
??ADD_TABLE?I_DAYNAME?'廿七'?.
??ADD_TABLE?I_DAYNAME?'廿八'?.
??ADD_TABLE?I_DAYNAME?'廿九'?.
??ADD_TABLE?I_DAYNAME?'三十'?.
??ADD_TABLE?I_MONNAME?'正'?.
??ADD_TABLE?I_MONNAME?'二'?.
??ADD_TABLE?I_MONNAME?'三'?.
??ADD_TABLE?I_MONNAME?'四'?.
??ADD_TABLE?I_MONNAME?'五'?.
??ADD_TABLE?I_MONNAME?'六'?.
??ADD_TABLE?I_MONNAME?'七'?.
??ADD_TABLE?I_MONNAME?'八'?.
??ADD_TABLE?I_MONNAME?'九'?.
??ADD_TABLE?I_MONNAME?'十'?.
??ADD_TABLE?I_MONNAME?'冬'?.
??ADD_TABLE?I_MONNAME?'臘'?.
??ADD_TABLE?I_MONTHADD?0?.
??ADD_TABLE?I_MONTHADD?31?.
??ADD_TABLE?I_MONTHADD?59?.
??ADD_TABLE?I_MONTHADD?90?.
??ADD_TABLE?I_MONTHADD?120?.
??ADD_TABLE?I_MONTHADD?151?.
??ADD_TABLE?I_MONTHADD?181?.
??ADD_TABLE?I_MONTHADD?212?.
??ADD_TABLE?I_MONTHADD?243?.
??ADD_TABLE?I_MONTHADD?273?.
??ADD_TABLE?I_MONTHADD?304?.
??ADD_TABLE?I_MONTHADD?334?.
??ADD_TABLE?I_NONGLIDATA?2635?.
??ADD_TABLE?I_NONGLIDATA?333387?.
??ADD_TABLE?I_NONGLIDATA?1701?.
??ADD_TABLE?I_NONGLIDATA?1748?.
??ADD_TABLE?I_NONGLIDATA?267701?.
??ADD_TABLE?I_NONGLIDATA?694?.
??ADD_TABLE?I_NONGLIDATA?2391?.
??ADD_TABLE?I_NONGLIDATA?133423?.
??ADD_TABLE?I_NONGLIDATA?1175?.
??ADD_TABLE?I_NONGLIDATA?396438?.
??ADD_TABLE?I_NONGLIDATA?3402?.
??ADD_TABLE?I_NONGLIDATA?3749?.
??ADD_TABLE?I_NONGLIDATA?331177?.
??ADD_TABLE?I_NONGLIDATA?1453?.
??ADD_TABLE?I_NONGLIDATA?694?.
??ADD_TABLE?I_NONGLIDATA?201326?.
??ADD_TABLE?I_NONGLIDATA?2350?.
??ADD_TABLE?I_NONGLIDATA?465197?.
??ADD_TABLE?I_NONGLIDATA?3221?.
??ADD_TABLE?I_NONGLIDATA?3402?.
??ADD_TABLE?I_NONGLIDATA?400202?.
??ADD_TABLE?I_NONGLIDATA?2901?.
??ADD_TABLE?I_NONGLIDATA?1386?.
??ADD_TABLE?I_NONGLIDATA?267611?.
??ADD_TABLE?I_NONGLIDATA?605?.
??ADD_TABLE?I_NONGLIDATA?2349?.
??ADD_TABLE?I_NONGLIDATA?137515?.
??ADD_TABLE?I_NONGLIDATA?2709?.
??ADD_TABLE?I_NONGLIDATA?464533?.
??ADD_TABLE?I_NONGLIDATA?1738?.
??ADD_TABLE?I_NONGLIDATA?2901?.
??ADD_TABLE?I_NONGLIDATA?330421?.
??ADD_TABLE?I_NONGLIDATA?1242?.
??ADD_TABLE?I_NONGLIDATA?2651?.
??ADD_TABLE?I_NONGLIDATA?199255?.
??ADD_TABLE?I_NONGLIDATA?1323?.
??ADD_TABLE?I_NONGLIDATA?529706?.
??ADD_TABLE?I_NONGLIDATA?3733?.
??ADD_TABLE?I_NONGLIDATA?1706?.
??ADD_TABLE?I_NONGLIDATA?398762?.
??ADD_TABLE?I_NONGLIDATA?2741?.
??ADD_TABLE?I_NONGLIDATA?1206?.
??ADD_TABLE?I_NONGLIDATA?267438?.
??ADD_TABLE?I_NONGLIDATA?2647?.
??ADD_TABLE?I_NONGLIDATA?1318?.
??ADD_TABLE?I_NONGLIDATA?204070?.
??ADD_TABLE?I_NONGLIDATA?3477?.
??ADD_TABLE?I_NONGLIDATA?461653?.
??ADD_TABLE?I_NONGLIDATA?1386?.
??ADD_TABLE?I_NONGLIDATA?2413?.
??ADD_TABLE?I_NONGLIDATA?330077.
??ADD_TABLE?I_NONGLIDATA?1197?.
??ADD_TABLE?I_NONGLIDATA?2637?.
??ADD_TABLE?I_NONGLIDATA?268877?.
??ADD_TABLE?I_NONGLIDATA?3365?.
??ADD_TABLE?I_NONGLIDATA?531109?.
??ADD_TABLE?I_NONGLIDATA?2900?.
??ADD_TABLE?I_NONGLIDATA?2922?.
??ADD_TABLE?I_NONGLIDATA?398042?.
??ADD_TABLE?I_NONGLIDATA?2395?.
??ADD_TABLE?I_NONGLIDATA?1179?.
??ADD_TABLE?I_NONGLIDATA?267415?.
??ADD_TABLE?I_NONGLIDATA?2635?.
??ADD_TABLE?I_NONGLIDATA?661067?.
??ADD_TABLE?I_NONGLIDATA?1701?.
??ADD_TABLE?I_NONGLIDATA?1748?.
??ADD_TABLE?I_NONGLIDATA?398772?.
??ADD_TABLE?I_NONGLIDATA?2742?.
??ADD_TABLE?I_NONGLIDATA?2391?.
??ADD_TABLE?I_NONGLIDATA?330031.
??ADD_TABLE?I_NONGLIDATA?1175?.
??ADD_TABLE?I_NONGLIDATA?1611?.
??ADD_TABLE?I_NONGLIDATA?200010?.
??ADD_TABLE?I_NONGLIDATA?3749?.
??ADD_TABLE?I_NONGLIDATA?527717?.
??ADD_TABLE?I_NONGLIDATA?1452?.
??ADD_TABLE?I_NONGLIDATA?2742?.
??ADD_TABLE?I_NONGLIDATA?332397?.
??ADD_TABLE?I_NONGLIDATA?2350?.
??ADD_TABLE?I_NONGLIDATA?3222?.
??ADD_TABLE?I_NONGLIDATA?268949?.
??ADD_TABLE?I_NONGLIDATA?3402?.
??ADD_TABLE?I_NONGLIDATA?3493?.
??ADD_TABLE?I_NONGLIDATA?133973?.
??ADD_TABLE?I_NONGLIDATA?1386?.
??ADD_TABLE?I_NONGLIDATA?464219?.
??ADD_TABLE?I_NONGLIDATA?605?.
??ADD_TABLE?I_NONGLIDATA?2349?.
??ADD_TABLE?I_NONGLIDATA?334123?.
??ADD_TABLE?I_NONGLIDATA?2709?.
??ADD_TABLE?I_NONGLIDATA?2890?.
??ADD_TABLE?I_NONGLIDATA?267946?.
??ADD_TABLE?I_NONGLIDATA?2773?.
??ADD_TABLE?I_NONGLIDATA?592565?.
??ADD_TABLE?I_NONGLIDATA?1210?.
??ADD_TABLE?I_NONGLIDATA?2651?.
??ADD_TABLE?I_NONGLIDATA?395863?.
??ADD_TABLE?I_NONGLIDATA?1323?.
??ADD_TABLE?I_NONGLIDATA?2707?.
??ADD_TABLE?I_NONGLIDATA?265877?.
*都是一些控制變量
??DATA:?WCY?TYPE?I,
????????WCM?TYPE?I,
????????WCD?TYPE?I.
??DATA:?NTD????TYPE?I,NIE?TYPE?I,
????????L_M????TYPE?I,L_I?TYPE?I,
????????L_K????TYPE?I,L_N?TYPE?I,
????????L_N1???TYPE?I,
????????L_NBIT?TYPE?I.
??DATA:?NONGLI(30)????TYPE?C,
????????NONGLIDAY(10)?TYPE?C,
????????SHUXIANG(10)??TYPE?C.
*取得輸入的日期
??WCY?=?P_DATUM+0(4)?.
??WCM?=?P_DATUM+4(2)?.
??WCD?=?P_DATUM+6(2)?.
*取得輸入的日期到初始日期的天數
??DATA:?L_NUM?TYPE?I?.
??READ?TABLE?I_MONTHADD?INDEX?WCM?.
??NTD?=?(?WCY?-?1921?)?*?365?+?(?WCY?-?1921?)?/?4?+?WCD?+?I_MONTHADD-NAME?-?38.
*用于判斷閏年
??L_NUM?=?WCY?MOD?400?.
??DATA:?L_NUM1?TYPE?I,L_NUM2?TYPE?I.
??L_NUM1?=?WCY?MOD?4?.
??L_NUM2?=?WCY?MOD?100?.
*如果是閏年而且是2月份以后,則天數加1
??IF?(?L_NUM?=?0?OR?(?L_NUM1?=?0?AND?L_NUM2?<>?0?)?)?AND?WCM?>?2?.
????NTD?=?NTD?+?1?.
??ENDIF?.
??L_M?=?0?.
*循環開始,設置一個循環結束標志
??WHILE?NIE?<>?1?.
????DATA:?L_M1?TYPE?I?.
????L_M1?=?L_M?+?1?.
????READ?TABLE?I_NONGLIDATA?INDEX?L_M1?.
*???判斷是否有閏月,指農歷的閏月
????IF?I_NONGLIDATA-NAME?<?4095?.
*?????沒有,則一共有12個月,因為下標從0開始,所以設置成11
??????L_K?=?11?.
????ELSE?.
??????L_K?=?12?.
????ENDIF?.
????L_N?=?L_K?.
????WHILE?L_N?>=?0?.
??????READ?TABLE?I_NONGLIDATA?INDEX?L_M1?.
??????L_NBIT?=?I_NONGLIDATA-NAME?.
??????L_I?=?1?.
??????L_N1?=?L_N?+?1?.
??????WHILE?L_I?<?L_N1?.
????????L_NBIT?=?L_NBIT?DIV?2?.
????????L_I?=?L_I?+?1?.
??????ENDWHILE?.
??????L_NBIT?=?L_NBIT?MOD?2?.
??????DATA:?L_NBIT1?TYPE?I?.
??????L_NBIT1?=?L_NBIT?+?29?.
??????IF?NTD?<=?L_NBIT1?.
????????NIE?=?1?.
????????EXIT?.
??????ENDIF?.
??????NTD?=?NTD?-?29?-?L_NBIT?.
??????L_N?=?L_N?-?1?.
????ENDWHILE?.
????IF?NIE?=?1?.
??????EXIT?.
????ENDIF.
????L_M?=?L_M?+?1?.
??ENDWHILE?.
??WCY?=?1921?+?L_M?.
??WCM?=?L_K?-?L_N?+?1?.
??WCD?=?NTD?.
**ok,計算完畢,如果有閏月的話,執行下面一段
??IF?L_K?=?12?.
????READ?TABLE?I_NONGLIDATA?INDEX?L_M?.
????DATA:?L_TEMP?TYPE?I.
????L_TEMP?=?I_NONGLIDATA-NAME?/?65536?+?1?.
????IF?WCM?=?L_TEMP?.
??????WCM?=?1?-?WCM?.
????ELSEIF?WCM?>?L_TEMP?.
??????WCM?=?WCM?-?1?.
????ENDIF.
??ENDIF.
*這里就是輸出的設置了
??L_TEMP?=?(?(?WCY?-?4?)?MOD?60?)?MOD?12?+?1?.
??DATA:?L_TEMP1?TYPE?I?.
??L_TEMP1?=?(?(?WCY?-?4?)?MOD?60?)?MOD?10?+?1?.
**取得屬相
??READ?TABLE?I_SHUXIANG?INDEX?L_TEMP?.
??SHUXIANG?=?I_SHUXIANG-NAME?.
**取得天干地支
??READ?TABLE?I_DIZHI?INDEX?L_TEMP?.
??READ?TABLE?I_TIANGAN?INDEX?L_TEMP1?.
??CONCATENATE?I_TIANGAN-NAME?I_DIZHI-NAME?'年'?INTO?NONGLI?.
??IF?WCM?<?1?.
????L_TEMP?=?-1?*?WCM?.
????READ?TABLE?I_MONNAME?INDEX?L_TEMP?.
????NONGLIDAY?=?I_MONNAME-NAME?.
??ELSE?.
????READ?TABLE?I_MONNAME?INDEX?WCM?.
??ENDIF.
**取得日期,然后輸出
??READ?TABLE?I_DAYNAME?INDEX?WCD?.
??CONCATENATE?I_MONNAME-NAME?'月'?I_DAYNAME-NAME?INTO?NONGLIDAY?.
??WRITE:?NONGLI,NONGLIDAY?.
總結
以上是生活随笔為你收集整理的ABAP实现农历转成公历的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ABAP动态取得数据的方法
- 下一篇: Notepad++中高亮显示ABAP代码