Monday, May 5, 2008

SAP ABAP Function Module te get Week from Date.

SAP ABAP Function Module te get Week from Date.

DATE_GET_WEEK

The following function module gets the week of the year from the entered date.

REPORT ZEX_DATEGETWEEK .


Parameters: P_date like sy-datum.

Data: d_week like SCAL-WEEK,
      d_week1(2).


* The following function module get the week of the entered date.


CALL FUNCTION 'DATE_GET_WEEK'
  EXPORTING
    DATE              = P_date
 IMPORTING
   WEEK               = d_week
 EXCEPTIONS
   DATE_INVALID       = 1
   OTHERS             = 2
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


move: d_week+4(2) to d_week1.

Write:/ 'Week ', d_week1.


If you enter the date as 05/04/2008 then the output would be as follows.

Gets the week of the year     
                              
Week  18                      





No comments:

Post a Comment