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.
Friday, November 1, 2013
Thursday, October 31, 2013
Convert ALV to Excel and send it by email
One of the most requested abilities for an report is the possibility to run it as a job and send the output to a given user. However, the spool output of most ALV reports is unusable as is. To solve this problem, I'll show a simple class that takes an internal table, a fieldcatalog and a user email to create a xml excel file from the field catalog with the contents of the internal table and forward it to the email supplied.
I should warn that the excel output isn't something fancy. It's just a simple table. The class can be greatly enhanced.
1 - Create a class:
3 - Create the class methods:
4 - Create the method parameters:
5 - Insert the appropriate code in each method:
I should warn that the excel output isn't something fancy. It's just a simple table. The class can be greatly enhanced.
1 - Create a class:

2 - Create the class atributes:
3 - Create the class methods:
5 - Insert the appropriate code in each method:














