2006 Jul 01 11:17 AM
hai all,
i need a function module for calculating noof sundays in a month
2006 Jul 01 4:12 PM
Hi Satya,
Please check this piece of code. This serves ur purpose.
Calculation of number of sundays ****
*............................................
DAta : month1(2) type c,
week1 type i.
week1 = 5.
*- Function Module to fetch the Last day of the Month
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
DAY_IN = <ET>-low
IMPORTING
LAST_DAY_OF_MONTH = VAL1.
*- Function Module to get the day of the week
CALL FUNCTION 'DATE_COMPUTE_DAY'
EXPORTING
DATE = VAL1
IMPORTING
DAY = DAY1.
*- Calculation of number of sundays
month1 = val14(2).
if month1 = 31.
if DAY1 <= 2 or DAY1 = 7.
no_sundays = week1.
else.
no_sundays = week1 - 1.
endif.
elseif month1 = 30.
if DAY1 =1 or DAY1 = 7.
no_sundays = week1.
else.
no_sundays = week1 - 1.
endif.
elseif month1 = 29.
if DAY1 = 7.
no_sundays = week1.
else.
no_sundays = week1 - 1.
endif.
elseif month1 = 28.
no_sundays = 4.
endif.
If found helpful, please do reward.
Hi Satya,
Please check this piece of code. This serves ur purpose.
Calculation of number of sundays ****
*............................................
DAta : month1(2) type c,
week1 type i.
week1 = 5.
*- Function Module to fetch the Last day of the Month
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
DAY_IN = <ET>-low
IMPORTING
LAST_DAY_OF_MONTH = VAL1.
*- Function Module to get the day of the week
CALL FUNCTION 'DATE_COMPUTE_DAY'
EXPORTING
DATE = VAL1
IMPORTING
DAY = DAY1.
*- Calculation of number of sundays
month1 = val14(2).
if month1 = 31.
if DAY1 <= 2 or DAY1 = 7.
no_sundays = week1.
else.
no_sundays = week1 - 1.
endif.
elseif month1 = 30.
if DAY1 =1 or DAY1 = 7.
no_sundays = week1.
else.
no_sundays = week1 - 1.
endif.
elseif month1 = 29.
if DAY1 = 7.
no_sundays = week1.
else.
no_sundays = week1 - 1.
endif.
elseif month1 = 28.
no_sundays = 4.
endif.
If found helpful, please do reward.
2006 Jul 01 12:05 PM
2006 Jul 01 4:12 PM
Hi Satya,
Please check this piece of code. This serves ur purpose.
Calculation of number of sundays ****
*............................................
DAta : month1(2) type c,
week1 type i.
week1 = 5.
*- Function Module to fetch the Last day of the Month
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
DAY_IN = <ET>-low
IMPORTING
LAST_DAY_OF_MONTH = VAL1.
*- Function Module to get the day of the week
CALL FUNCTION 'DATE_COMPUTE_DAY'
EXPORTING
DATE = VAL1
IMPORTING
DAY = DAY1.
*- Calculation of number of sundays
month1 = val14(2).
if month1 = 31.
if DAY1 <= 2 or DAY1 = 7.
no_sundays = week1.
else.
no_sundays = week1 - 1.
endif.
elseif month1 = 30.
if DAY1 =1 or DAY1 = 7.
no_sundays = week1.
else.
no_sundays = week1 - 1.
endif.
elseif month1 = 29.
if DAY1 = 7.
no_sundays = week1.
else.
no_sundays = week1 - 1.
endif.
elseif month1 = 28.
no_sundays = 4.
endif.
If found helpful, please do reward.
2006 Jul 01 4:30 PM
Hi
You can use fm DAY_ATTRIBUTES_GET, it return all characteristics of all days between a period, here you can see the name of the day too, so you can know which are the sundays.
Max
2006 Jul 03 4:58 AM
Hi Satya,
Please check this code which is checked for syntax also. Just copy and paste the same in abap editor and check the output.
Calculation of number of sundays ****
*............................................
DAta : month1(2) type c,
week1 type i,
date1 type sy-datum,
val1 type sy-datum,
day1 type SCAL-INDICATOR,
no_sundays type i.
week1 = 5.
date1 = '20060502'.
*- Function Module to fetch the Last day of the Month
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
DAY_IN = date1
IMPORTING
LAST_DAY_OF_MONTH = VAL1.
*- Function Module to get the day of the week
CALL FUNCTION 'DATE_COMPUTE_DAY'
EXPORTING
DATE = VAL1
IMPORTING
DAY = DAY1.
*- Calculation of number of sundays
month1 = val1+6(2).
write : / month1.
if month1 = 31.
if DAY1 <= 2 or DAY1 = 7.
no_sundays = week1.
else.
no_sundays = week1 - 1.
endif.
elseif month1 = 30.
if DAY1 = 1 or DAY1 = 7.
no_sundays = week1.
else.
no_sundays = week1 - 1.
endif.
elseif month1 = 29.
if DAY1 = 7.
no_sundays = week1.
else.
no_sundays = week1 - 1.
endif.
elseif month1 = 28.
no_sundays = 4.
endif.
write : / no_sundays.
If found helpful, please do reward.
2006 Jul 03 6:14 AM
Hi,
The number of Sundays ( For that matter any day of the week ) in a month can be either 4 or 5.
The result will be 5 only when then 29 or 30 or 31 occur on Sundays.
Solution: Use the FM LAST_DAY_OF_MONTHS
to get the lastdate in the month.
if LAST_DAY_OF_MONTH+6(2) = 28.
no_of_sundays = 4.
elseif LAST_DAY_OF_MONTH+6(2) = 29.
use the Fm date_to_day.
pass the LAST_DAY_OF_MONTH to this FM and get the day of the week.
if WEEKDAY = 'SUNDAY' .
no_of_sundays = 5.
else.
no_of_sundays = 4.
endif.
elseif LAST_DAY_OF_MONTH+6(2) = 30.
use the Fm date_to_day.
pass the LAST_DAY_OF_MONTH to this FM and get the day of the week.
if WEEKDAY = 'SUNDAY' or 'MONDAY'
no_of_sundays = 5.
else.
no_of_sundays = 4.
endif.
elseif LAST_DAY_OF_MONTH+6(2) = 30.
use the Fm date_to_day.
pass the LAST_DAY_OF_MONTH to this FM and get the day of the week.
if WEEKDAY = 'SUNDAY' or 'MONDAY' or 'TUESDAY' . no_of_sundays = 5.
else.
no_of_sundays = 4.
endif.
2006 Jul 03 11:02 AM
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |