04-05-2009 2:44 AM
Hi All,
How I can Fetch data from query by passing week numbers.As there is no week field in my query ?
Regards,
04-05-2009 4:07 AM
Hi Sachin,
when I understand your question correctly, you want to pass a week-number to your report, and the data corresponding to the given data range have to be reported.
Create a function which determines the data range and the pass the determined date range to your fetch selection in the where clause like
where ldate between w_startdate and w_enddate ...
The needed Function is pretty easy programmed: First, determine the weekday of January. This gives you the number of days in the first calendar week. Let's say you want the data for week 30:
Last date = 29*7 + (number of days in the first week of the year).
First date = Last date - 7.
w_startdate = 20090101 + First date.
w_enddate = 20090101 + Last date.
These two dates have to be used for your WHERE selection.
Have fun and success,
Heinz
Additional information:
Under transaction SE37 I found the Function Module WEEK_GET_FIRST_DAY. Using this you can easily find the begin date and end date for a given week (number range 1 to 53). Here ist the code:
data: w_begin_date like scal-date,
w_end_date like scal-date,
w_week like scal-week.
CALL FUNCTION 'WEEK_GET_FIRST_DAY'
EXPORTING
week = w_week
IMPORTING
DATE = w_begin_date
EXCEPTIONS
WEEK_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.
w_end_date = w_begin_date + 6.
write: / w_begin_date, w_end_date.
w_week has to be YYYYWK (e.g. 200747).
Have success,
Heinz
Edited by: Heinz Horner on Apr 6, 2009 2:30 PM
04-07-2009 6:14 AM
Click on WIKI->SAP NetWeaver and Technology->Code Gallery
In Code Gallery you search with Tutorial Report Program to get date list of a year's particular months' particular week. You get a code snippet developed by me. It may solve your problem,I hope.
Regards.
Sarbajit.
04-07-2009 6:35 AM
Hi sachin,
Its simple,, even if you have or dont have your week no... in your table,,, do like this,,,
DATA : STR_WEEK_DATE TYPE SY-DATUM.
DATA : END_WEEK_DATE TYPE SY-DATUM.
LOOP AT I_TEMP WHERE MONTH IS INITIAL.
to calculating starting date of the week
CALL FUNCTION 'WEEK_GET_FIRST_DAY'
EXPORTING
WEEK = I_TEMP-WEEK
IMPORTING
DATE = STR_WEEK_DATE.
END_WEEK_DATE = STR_WEEK_DATE + 7.
then you get the dates for a particular week...
and from there after you can retrieve by what ever you want,,, by month, by year, by date, by week,,,
Here are some funtion modules to calculate different types of dates & weeks, which can be used if necessary.
*To calculate week no for particular date
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
DATE = SY-DATUM " any date
IMPORTING
WEEK = WEEK_NO ." Week no for particular date
*To calculate week Start & End date
CALL FUNCTION 'HRWPC_BL_DATES_WEEK_INTERVAL'
EXPORTING
DATUM = SY-DATUM " Current date (ITAB DATE)
WEEK_PST = '0'
WEEK_FTR = '0'
IMPORTING
BEGDA = STR_WEEK_DATE " Week start date
ENDDA = END_WEEK_DATE. " Week end date
*To calculate Months ending date
CALL FUNCTION 'BKK_GET_MONTH_LASTDAY'
EXPORTING
I_DATE = SY-DATUM " Any date
IMPORTING
E_DATE = END_MONTH_DATE. " Month's ending date
*to calculate particular day No for any give date.
CALL FUNCTION 'DATE_COMPUTE_DAY'
EXPORTING
DATE = SY-DATUM " any date
IMPORTING
DAY = DAYNO1. " particular day no.
*To calculate particular day name with the day no
CALL FUNCTION 'BKK_GET_DAY_OF_WEEK'
EXPORTING
I_DAY = DAYNO " week day no.
IMPORTING
E_WDAY = CURRENT_DAY_NAME. " Week day name for the week day no.
to Calculate the next week
CALL FUNCTION 'NEXT_WEEK'
EXPORTING
CURRENT_WEEK = WEEK_NO "Current week,
IMPORTING
NEXT_WEEK = WEEK_NO. " Next week
to calculating starting date of the week
CALL FUNCTION 'WEEK_GET_FIRST_DAY'
EXPORTING
WEEK = WEEK_NO "week No
IMPORTING
DATE = STR_WEEK_DATE. " Starting date of the particular week
*To Calculate particular day No for any given date
CALL FUNCTION 'DAY_IN_WEEK'
EXPORTING
DATUM = STR_WEEK_DATE " Any date
IMPORTING
WOTNR = DAY. " Day no for a giveN date