2012 Oct 11 7:31 AM
I need to get all the dates from particular month and year.
Input : Year & Month
Output: All the dates of that particular month & year selected.
Is there any FM provided by SAP or if you have fulfilled such kind of requirement kindly provide the code or guide me through it.
Please reply ASAP
2012 Oct 11 9:01 AM
Hi rahul,
Just copy the below code and run it and i hope it will help to you and its simple to understand or if you want only fm just this code convert to fm use as like as FM.
PARAMETERS : p_month(2) TYPE n,
p_year(4) TYPE n.
DATA: w_date TYPE d,
w_offset TYPE i.
w_date+6(2) = '01'.
w_date+0(4) = p_year.
w_date+4(2) = p_month.
WRITE : / 'Month;',p_month , 40 'Year :' , p_year.
SKIP 3.
ULINE.
WRITE : /5 'Sun' , 10 'Mon' , 20 'Tue' ,30 'Wed' , 40 'Thu' , 50 'Fri' , 60 'Sat'.
SKIP.
WHILE w_date+4(2) = p_month.
w_offset = w_date MOD 7.
CASE w_offset.
WHEN 1.
WRITE : / w_date+6(2) UNDER 'Sun'.
WHEN 2.
WRITE : w_date+6(2) UNDER 'Mon'.
WHEN 3.
WRITE : w_date+6(2) UNDER 'Tue'.
WHEN 4.
WRITE : w_date+6(2) UNDER 'Wed'.
WHEN 5.
WRITE : w_date+6(2) UNDER 'Thu'.
WHEN 6.
WRITE : w_date+6(2) UNDER 'Fri'.
WHEN 0.
WRITE : w_date+6(2) UNDER 'Sat'.
ENDCASE.
w_date = w_date + 1.
ENDWHILE.
****
If you have any q's let me know.
Regards
Mahesh
2012 Oct 11 7:49 AM
Hi Rahul,
Use below FM u can get last day of month and year....once u got last day then u can calculate dates in months.
RP_LAST_DAY_OF_MONTHS
Regards,
Amol.
2012 Oct 11 8:01 AM
Hi Rahul,
Use DAY_ATTRIBUTES_GET give the inputs FACTORY_CALENDAR ( For India:IN),DATE_FROM and DATE_TO ( for year and month give for ex: from 01.10.2012 to 31.10.2012). The FM will list all the dates, weekday, day string and also holiday.
With regards,
2012 Oct 11 8:18 AM
Hi,
You can concatenate 01,month and year which becomes your first day of the month.
For last day you can use the FM RP_LAST_DAY_OF_MONTHS. as below:
concatenate '01' month year separated by '/' into first_date.
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
day_in = first_date
IMPORTING
last_day_of_month = last_date.
Now you have the last date and the first date so you can get all the dates in between.
Hope it serves useful to you.
2012 Oct 11 9:01 AM
Hi rahul,
Just copy the below code and run it and i hope it will help to you and its simple to understand or if you want only fm just this code convert to fm use as like as FM.
PARAMETERS : p_month(2) TYPE n,
p_year(4) TYPE n.
DATA: w_date TYPE d,
w_offset TYPE i.
w_date+6(2) = '01'.
w_date+0(4) = p_year.
w_date+4(2) = p_month.
WRITE : / 'Month;',p_month , 40 'Year :' , p_year.
SKIP 3.
ULINE.
WRITE : /5 'Sun' , 10 'Mon' , 20 'Tue' ,30 'Wed' , 40 'Thu' , 50 'Fri' , 60 'Sat'.
SKIP.
WHILE w_date+4(2) = p_month.
w_offset = w_date MOD 7.
CASE w_offset.
WHEN 1.
WRITE : / w_date+6(2) UNDER 'Sun'.
WHEN 2.
WRITE : w_date+6(2) UNDER 'Mon'.
WHEN 3.
WRITE : w_date+6(2) UNDER 'Tue'.
WHEN 4.
WRITE : w_date+6(2) UNDER 'Wed'.
WHEN 5.
WRITE : w_date+6(2) UNDER 'Thu'.
WHEN 6.
WRITE : w_date+6(2) UNDER 'Fri'.
WHEN 0.
WRITE : w_date+6(2) UNDER 'Sat'.
ENDCASE.
w_date = w_date + 1.
ENDWHILE.
****
If you have any q's let me know.
Regards
Mahesh
2012 Oct 11 9:54 AM
your requirement is fulfilled or not if not ask the questions or fulfilled just close the thread.
Regards
Mahesh