我需要将'MM/DD/YYYY'格式的日期转换为表示它在一年中的哪一天的数字。即'01/01/YYYY'=1, '12/31/YYYY'=365。在ABAP中有任何内置的功能来做到这一点吗?我试过谷歌,但我找不到任何函数做这个
一行代码:
DATA(g_day) = p_date - CONV d( p_date(4) && '0101' ) + 1.
绝对没有必要依赖系统中可能存在也可能不存在的任何功能模块。只需使用基本的内置语言元素:
DATA: l_my_date TYPE d, " note that the data type D is YYYYMMDD
l_jan_01 TYPE d, " This will be jan 1 of the needed year
l_day TYPE i.
l_my_date = ...whatever...
l_jan_01 = l_my_date.
l_jan_01+4 = '0101'. " or any other means to get the first day of the year.
l_day = l_my_date - l_jan_01 + 1.
您可以使用以下功能模块:HR_AUPBS_MONTH_DAY
.
您必须传递初始日期和结束日期,并且它将返回两者之间的天数(这是您想要的):
CALL FUNCTION 'HR_AUPBS_MONTH_DAY'
EXPORTING BEG_DA = P_BEGDA " Here you should put the first day of the year
END_DA = P_ENDDA " Here you put the date
IMPORTING NO_CAL_DAY = P_CAL_DAY. " This is what you want