‎2006 Aug 08 8:16 AM
I have a customized table which contains monthwise details.say 12 entries for an year.I want to fetch the previous 5 month entries from the table wrto sy-datum.
ie) if the month is 08 , then i want the records frm 03-07.
ie) if the month is 02, i want the records 01,12,11,10,09.
What logic to use?
Rgds,
SAPUSER100
‎2006 Aug 08 8:19 AM
Hello,
ranges: r_mon for monat.
l_month = sy_datum+4(2) - 5.
do 5 times.
r_mon-sign = 'I'.
r_mon-option = 'EQ'.
r_mon-low = l_month.
append r_mon.
l_mont = l_month + 1.
if l_month > 12.
l_month = 1.
endif.
enddo.
regards,
Naimesh
‎2006 Aug 08 8:19 AM
Hello,
ranges: r_mon for monat.
l_month = sy_datum+4(2) - 5.
do 5 times.
r_mon-sign = 'I'.
r_mon-option = 'EQ'.
r_mon-low = l_month.
append r_mon.
l_mont = l_month + 1.
if l_month > 12.
l_month = 1.
endif.
enddo.
regards,
Naimesh
‎2006 Aug 08 8:34 AM
hi ,
how you fetch it from an itab ?
hav to use READ st by comparing two tables or any direct way is possible ?
‎2006 Aug 08 8:41 AM
Hello,
You have to also consider the year in your selection. so, change in the logic ...
data: begin of r_mon occurs 0,
mon(2),
year(4),
end of r_mon.
l_month = sy_datum+4(2) - 1.
l_year = sy_datum+0(4).
do 5 times.
r_mon-mon = l_month.
r_mon-year = l_year.
append r_mon.
clear r_mon
l_mont = l_month - 1.
if l_month = 0 .
l_month = 12.
l_year = sy_datum+0(4) - 1.
endif.
enddo.
Once you got filled your range of the Month,
I would advice like,
loop at r_mon.
select * from ztab
appending table itab
where mon = r_mon-mon
and year = r_mon-year.
endloop.
Regards,
Naimesh
‎2006 Aug 08 8:55 AM
Hi everyone,
just a tip: I've worked a lot with date manipulation and I had a lot of tiny problems when doing so manually, you know month 13 or month 00...
Then my lazyness wakes up and then I think: "let another one do the job for you". So if you use function module ADD_TIME_TO_DATE, you'll avoid some headaches.
Best regards,
Alvaro
‎2006 Aug 08 10:21 AM
Hi
Just try out this function module.Using this you can solve your problem,i guess. Execute it in SE37 and see if it is giving the required result for you.
CCM_GO_BACK_MONTHS
Regards,
Vijay Penumaka
‎2006 Aug 08 10:29 AM
even you can check this function module,
/BEV4/PLPS__ADD_MONTH_TO_DATE
say -5 in months & give data is current date.
this works fine.
regards
srikanth