Some SAP objects must deal with week periods. Here I'll show a small class to deal with some of the needs that arise when making calculations with week periods. This class makes simplier to use only one object to provide the needed calculations with weeks. As usual, there is allways room for improvement.
1 - Create the Class:
2 - Create the Methods:
3 - Define Methods Parameters
4 - Insert the code in the appropriate methods:
method ADD_NUMBER.
data: l_first_day type dats.
do im_numb times.
l_first_day = get_first_day( im_week = ch_week ).
l_first_day = l_first_day + 7.
ch_week = get_from_day( im_day = l_first_day ).
enddo.
endmethod.
method DIFFERENCE.
if im_week2(4) = im_week1(4).
re_no_weeks = im_week1+4(2) - im_week2+4(2).
elseif im_week1(4) > im_week2(4).
re_no_weeks = ( ( im_week1(4) - im_week2(4) ) * 52 ) + im_week1+4(2)
- im_week2+4(2).
else.
clear: re_no_weeks.
endif.
endmethod.
method GET_FIRST_DAY.
call function 'WEEK_GET_FIRST_DAY'
exporting
week = im_week
importing
date = re_day
exceptions
week_invalid = 1
others = 2.
endmethod.
method GET_FROM_DAY.
call function 'DATE_GET_WEEK'
exporting
date = im_day
importing
week = re_week
exceptions
date_invalid = 1
others = 2.
endmethod.
method GET_LAST_DAY.
re_day = get_first_day( im_week = im_week ) + 6.
endmethod.
method SUBTRACT_NUMBER.
data: l_first_day type dats.
do im_numb times.
l_first_day = get_first_day( im_week = ch_week ).
l_first_day = l_first_day - 7.
ch_week = get_from_day( im_day = l_first_day ).
enddo.
endmethod.
No comments:
Post a Comment