03-15-2007 1:30 PM
Hi Friends,
I have a scenario, where i need to fetch consumption data of the consumers. This need to be done on a monthly basis , Every second Saturday of the month.
So, Can anybody suggest me how do i need to fetch data between two second saturdays. How do i need to write the logic for this.
Thank you
ananya
03-15-2007 2:05 PM
hai ,
try this once.
PROGRAM YH649_TEST.
PARAMETER:
P_MONTH TYPE I,
P_YEAR TYPE I.
DATA RDATE TYPE D VALUE '19000101'. "its monday
DATA W_DATE TYPE D.
DATA W_DATE1 TYPE D.
DATA W_DAYS TYPE I.
DATA W_MOD TYPE I.
W_DATE+0(4) = P_YEAR.
W_DATE+4(2) = P_MONTH.
W_DATE+6(2) = '01'.
W_DAYS = W_DATE - RDATE.
W_MOD = W_DAYS MOD 7.
IF W_MOD NE 6.
W_MOD = 12 - W_MOD.
ELSE.
W_MOD = 13.
ENDIF.
ADD W_MOD TO W_DATE.
WRITE W_DATE. " given month second saturday
W_DATE1 = W_DATE.
W_DATE1+6(2) = '01'.
IF W_DATE+4(2) LT 12.
W_DATE14(2) = W_DATE4(2) + 1.
ELSE.
W_DATE1+4(2) = '01'.
W_DATE10(4) = W_DATE10(4) + 1.
ENDIF.
W_DAYS = W_DATE1 - RDATE.
W_MOD = W_DAYS MOD 7.
IF W_MOD NE 6.
W_MOD = 12 - W_MOD.
ELSE.
W_MOD = 13.
ENDIF.
ADD W_MOD TO W_DATE1.
WRITE W_DATE1. "next month second saturday
then select * from ....date between w_date and w_date1
regards
ananth.
03-15-2007 1:53 PM
Hi ananya,
data:
Result type d,
fm_date type d, " date
fm_day(10) type c, " Day
fm_month type i, " Month
fm_year type i. " Year
fm_date = sy-datum.
fm_day = fm_date MOD 7.
CASE fm_day.
WHEN 1.
write: 'Sunday'.
WHEN 2.
write: 'Monday'.
WHEN 3.
write: 'Tuesday'.
WHEN 4.
write: 'Wednesday'.
WHEN 5.
write: 'Thursday'.
WHEN 6.
write: 'Friday'.
WHEN 0.
write: 'Saturday'.
ENDCASE. " CASE fm_day
When you get result as "Monday" --- > Result = fm_date + 13
When you get result as "Tuesday" --- > Result = fm_date + 12
When you get result as "Wednesday" --- > Result = fm_date + 11
When you get result as "Thusday" --- > Result = fm_date + 10
When you get result as "Friday" --- > Result = fm_date + 9
When you get result as "Satutday" --- > Result = fm_date + 8
When you get result as "Sunday" --- > Result = fm_date + 7
Second saturday date of your required month is " Result ".
<b>Reward,If helpful....
Hope, your Problem is solved....</b>
Regards,
V.Raghavender.
Message was edited by:
Raghavender Vadakattu
03-15-2007 2:05 PM
hai ,
try this once.
PROGRAM YH649_TEST.
PARAMETER:
P_MONTH TYPE I,
P_YEAR TYPE I.
DATA RDATE TYPE D VALUE '19000101'. "its monday
DATA W_DATE TYPE D.
DATA W_DATE1 TYPE D.
DATA W_DAYS TYPE I.
DATA W_MOD TYPE I.
W_DATE+0(4) = P_YEAR.
W_DATE+4(2) = P_MONTH.
W_DATE+6(2) = '01'.
W_DAYS = W_DATE - RDATE.
W_MOD = W_DAYS MOD 7.
IF W_MOD NE 6.
W_MOD = 12 - W_MOD.
ELSE.
W_MOD = 13.
ENDIF.
ADD W_MOD TO W_DATE.
WRITE W_DATE. " given month second saturday
W_DATE1 = W_DATE.
W_DATE1+6(2) = '01'.
IF W_DATE+4(2) LT 12.
W_DATE14(2) = W_DATE4(2) + 1.
ELSE.
W_DATE1+4(2) = '01'.
W_DATE10(4) = W_DATE10(4) + 1.
ENDIF.
W_DAYS = W_DATE1 - RDATE.
W_MOD = W_DAYS MOD 7.
IF W_MOD NE 6.
W_MOD = 12 - W_MOD.
ELSE.
W_MOD = 13.
ENDIF.
ADD W_MOD TO W_DATE1.
WRITE W_DATE1. "next month second saturday
then select * from ....date between w_date and w_date1
regards
ananth.
03-15-2007 3:24 PM
Hi,
I do know from where you fatch consumption data but i may be able to help find out date of two secong saturdays. If i undertand your requirement correctly, you can the data between of 2nd saturday of current month and 2nd saturday preious month. For this the very first task for you is to get this dates.
First create a new calender using transaction SCAL, let's say 'Z1'. In this calender setup only 2nd saturday of each month as working day.
I suggest you to schedule your program in background. As a start condition, schedule it based on date/time. Give the period value as daily. On the restriction table enter the calender ID 'Z1" and select alway execute job.
This way your report will only run on 2nd saturday of each month and you will get that date ( sy-datum ) in your report.
To get the date of previous staturday, do as follow.
- Select from table TFACS for IDENT = 'Z1" and JAHR = "current fiscal year". This table stores "factory calender". There is a single entry for calender in each year. The data is stored like this, field MON01 holds the values of month-1 ( january), MON02 holds the values of month-2 ( February) and so on unto MON12.
The way data is store in MON01 to MON12 is; let's take a example of january, field MON01 has string of '1' and '0' and total digis are 31 ( since january has 31 day ). All other fields will have number digits based on the month and year. "1" indicates the working day in calender month while '0' indicates non-working day. In your case, for calender 'Z1', all the month fields MON01 - MON12 will only have one digit as '1', which is second saturday of that month.
You already got the date of 2nd saturday of current month. ( sy-datum ). Based on the current month, you read the field from table TFACS for previous month. For march the prevous month data would be in MON02. You read this field and wherever you find digit '1' that particular date is the date of 2nd saturday of previous month.
Instead of prevous 2nd saturday you want next month 2nd saturday, you can easily get that too by above method.
The descirption above sound complex but believe me it is easy to implement and its a sure solution for your issue.
Let me know if you have any question.
Regards,
RS
03-16-2007 5:35 AM
Hi Ananya,
go through the below code
data:
w_date type d,
w_sdate type d,
w_days type i,
w_mod type i.
w_date = sy-datum.
concatenate w_date+0(6) '14' into w_sdate.
w_days = w_sdate.
w_mod = w_days mod 7.
case w_mod.
when 1.
w_date = w_sdate - 1.
when 2.
w_date = w_sdate - 2.
when 3.
w_date = w_sdate - 3.
when 4.
w_date = w_sdate - 4.
when 5.
w_date = w_sdate - 5.
when 6.
w_date = w_sdate - 6.
when 0.
w_date = w_sdate.
endcase.
write:/ 'The Second saturday of the current month is ',w_date.
in the similar way u can find the second saturday of the previous month.
From those two u can calculate the no of days between two second saturdays.
Reward if Helpful.
03-16-2007 5:39 AM
Hi,
Use the FM:
<b>RP_CALC_DATE_IN_INTERVAL</b> Add/subtract years/months/days from a date
Hope this helps.
Reward if helpful.
Regards,
Sipra