how to get the date of the first friday of the month

Question: Hi guys,
Can anybody help me on how to get the date of the first friday of the month? ex:
Input: February
Output : 02/02/2007.

Any suggestion / help would be appreciated.

Thanks!

Answer:
maybe you could maintain a calendar with working day in Friday.

Answer:
Hi,

Have a look at FM HRVE_GET_FIRST_LAST_MONDAY, this basically gives first & Last Monday of the given year. You may copy this FM to make your own Z-FM & may modify it to suit your requirement.

I hope this helps,

Regards
Raju Chitale

Answer:

CONSTANTS: c_date_reference TYPE d VALUE '19790101',
           c_friday         TYPE i VALUE 5.

DATA: first_of_month TYPE d,
      first_friday   TYPE d,
      day            TYPE i.

PARAMETERS: p_mon TYPE c LENGTH 6.

first_of_month = p_mon.
first_of_month+6(2) = '01'.

day = ( first_of_month - c_date_reference ) MOD 7.

first_friday = first_of_month + ( ( 11 - day  ) MOD 7 ).

WRITE: / first_friday DD/MM/YYYY.

OK, it's got some magic numbers, and it doesn't use structures...

m@t
_________________
TULY The quality of answers is roughly proportional to the quality of the question.

The downside of being better than everyone else is that people tend to assume you're pretentious.

Answer:
Hello everybody.

Here is another sample code using a standard function module. The only interest of mine (comparing to M@t's solution) is that you do not need to know the day for 01.01.1979.


REPORT z_find_first_day.

*----------------------------------------------------------------------*
* This program calculates the first day of the type you want :
*   - P_DAY = 1 for Monday, 2 for Tuesday,... and 7 for Sunday
*   - P_DATE is a date of the month and year you are interested in
*----------------------------------------------------------------------*
* Example :
* You search the date for the first Friday of April 2007, you enter :
*   - P_DAY = 5
*   - P_DATE must be between 1st of April 2007 and 30th of April 2007
*----------------------------------------------------------------------*
*                DATA DECLARATION
*----------------------------------------------------------------------*

DATA :
* Dates
  w_first_day_of_month  TYPE sy-datum,
  w_result_day          TYPE sy-datum,

* Day number in week
  w_day_in_week TYPE p,

* Delta
  w_delta       TYPE i.

*----------------------------------------------------------------------*
*                SELECTION-SCREEN
*----------------------------------------------------------------------*

PARAMETERS : p_day(1)  TYPE n,
             p_date    TYPE sy-datum.


*----------------------------------------------------------------------*
*                AT SELECTION-SCREEN
*----------------------------------------------------------------------*

AT SELECTION-SCREEN ON p_day.
  IF p_day > 7 OR p_day < 1.
    MESSAGE e531(0u) WITH 'You must choose a number between 1 and 7'.
  ENDIF.

*----------------------------------------------------------------------*
*                START-OF-SELECTION
*----------------------------------------------------------------------*

START-OF-SELECTION.

* Date of first day in month of P_DATE
  w_first_day_of_month = p_date.
  w_first_day_of_month+6(2) = '01'.

* Get the day number for the first day of the month of P_DATE
  CALL FUNCTION 'DAY_IN_WEEK'
       EXPORTING
            datum = w_first_day_of_month
       IMPORTING
            wotnr = w_day_in_week.

* Get the date we are looking for!
  w_delta = ( p_day - w_day_in_week ) MOD 7.
  w_result_day = w_first_day_of_month + w_delta.

* Write the result
  WRITE w_result_day.


Hope this helps.

Benoît
Copyright ?2007 - 2008 www.jt77.com