Friday, June 4, 2010

Get number of first week base on calender view

How to get number of first week in a month base on calender view.
For example : on year 2010 month 01, number of first week is 2009 - 54
and on year 2010 month 02, number of first week is 2010 - 05

REPORT ZMM_GET_FIRST_WEEK.
DATA: W_DATE LIKE SY-DATUM,
W_DATE_VALUE TYPE I,
W_SISA TYPE I,
W_WEEK LIKE SCAL-WEEK.
DATA: W_YY(4), W_MM(2).
PARAMETERS: P_YYMM(6) TYPE N.
START-OF-SELECTION.
CONCATENATE P_YYMM '01' INTO W_DATE.
*--
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
DATE = W_DATE
IMPORTING
WEEK = W_WEEK
EXCEPTIONS
DATE_INVALID = 1
OTHERS = 2.
*-- .
W_DATE_VALUE = W_DATE.
W_SISA = W_DATE_VALUE MOD 7.
IF W_SISA >= 2 AND W_SISA <= 5.
WRITE: / 'WEEK =', W_WEEK.
ELSE.
W_YY = W_WEEK+0(4).
W_MM = W_WEEK+4(2).
IF W_MM = 52.
W_YY = W_YY + 1.
W_MM = 1.
ELSE.
W_MM = W_MM + 1.
ENDIF.
CONCATENATE W_YY W_MM INTO W_WEEK.
WRITE: / 'WEEK =', W_WEEK.
ENDIF.

No comments: