day = ( first_of_month - c_date_reference ) MOD 7.
first_friday = first_of_month + ( ( 11 - day ) MOD 7 ).
WRITE: / first_friday DD/MM/YYYY.
Here is another sample code using a standard function module. The only interest of mine is that you do not need to know the day for 01.01.1979 in the code above.
Code:
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,
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.
* 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.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.