Application Development 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: 

How Many Fridays in a Month

hasba_younes
Participant
0 Kudos

Hi ABAP Experts,

is there any FM or code which can determine how many i.e. fridays are in a month?

thanks,

YNS

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello


parameters: p_mon like marv-lfmon.
parameters: p_gja like marv-lfgja.
data: date like sy-datum,
day type p,
counter type i.

concatenate p_gja p_mon '01' into date.
do.
  day =date mod 7.
  if day > 1.
     day = day - 1.
  else.
     day = day + 6.
  endif.
  if day = 5.
    counter = counter + 1.
  endif.
  date = date + 1.
  if date+4(2) > p_mon.
    exit.
  endif.
enddo.

write: 'there is', counter, 'fridays'.

8 REPLIES 8

Former Member
0 Kudos

i dont think there is fm for that

use fms

DAY_ATTRIBUTES_GET

DATE_COMPUTE_DAY

check first day of month using above fm and then you can caluculate

Former Member
0 Kudos

Hello


parameters: p_mon like marv-lfmon.
parameters: p_gja like marv-lfgja.
data: date like sy-datum,
day type p,
counter type i.

concatenate p_gja p_mon '01' into date.
do.
  day =date mod 7.
  if day > 1.
     day = day - 1.
  else.
     day = day + 6.
  endif.
  if day = 5.
    counter = counter + 1.
  endif.
  date = date + 1.
  if date+4(2) > p_mon.
    exit.
  endif.
enddo.

write: 'there is', counter, 'fridays'.

0 Kudos

Hi Maroz,

Nice one, But this may lead to an Infinite loop if the Month entered is '12'

Just a small Correction to the above Code ..

if date+4(2) NE p_mon instead of

if date+4(2) > p_mon.

0 Kudos

Thanks,

is there any possibility to see on which date is for example the second friday?

BR,

YNS

0 Kudos

Hi Younes,

When ever the Counter variable becomes 2, that DATE will be your second friday ..

0 Kudos

Hi,

Yes

what does this do?

 
  else.
     day = day + 6.
  endif.

so i uderstood that friday is always when result of Mod = 5.

so basically if i want to count the number of tuesdays it would be then 2?

thanks for your clarification.

BR,

Younes

0 Kudos

Hello

Yes

1 - monday

2 - tuesday

3 - wednesday

4 - thursday

5 - friday

6 - saturday

7 - sunday

0 Kudos

Thanks for your comment.

what if i wanted to make the interval of the months variable.

if i have custom defined start and end of months.

and this is maintained in a table? Fiscal Year Variant (See T009B)

thanks,

BR,

YOunes