Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

function module for sundays in a month

Former Member
0 Likes
2,584

hai all,

i need a function module for calculating noof sundays in a month

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,532

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.

6 REPLIES 6
Read only

Former Member
0 Likes
1,532

Hi

Try to use HOLIDAY_GET

Max

Read only

Former Member
0 Likes
1,533

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.

Read only

0 Likes
1,532

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

Read only

Former Member
0 Likes
1,532

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.

Read only

Former Member
0 Likes
1,532

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.

Read only

Former Member
0 Likes
1,532

Hai thanks for the help...can close it now