‎2007 May 29 9:49 AM
Hi ABAPers,
My requirement is that, i have one period(date) select-option in my selection screen.
Now the problem was basing on the month the first and last date of that particular month should be initialised.
For Ex:- present month was may, so in selection screen the date should be,
PERIOD 05/01/2007 TO 05/31/2007
Can any one send me the code for that.
Thanks in Advance.
Regards,
Ramana Prasad. T
‎2007 May 29 11:02 AM
Hi,
you can use this code just copy paste and run
SELECT-OPTIONS: s_date FOR sy-datum OBLIGATORY.
DATA: l_date TYPE sy-datum.
INITIALIZATION.
s_date-sign = 'I'.
s_date-option = 'EQ'.
s_date-low = sy-datum.
s_date-low+6(2) = '01'.
s_date-sign = 'I'.
s_date-option = 'EQ'.
s_date-high = sy-datum - l_date+6(2) .
s_date-high4(2) = s_date-high4(2).
CASE sy-datum+4(2).
WHEN '1' OR '3' OR '5' OR '7' OR '8' OR '10' OR '12'.
s_date-high+6(2) = '31'.
WHEN '4' OR '6' OR '9' OR '11'.
s_date-high+6(2) = '30'.
WHEN '2' .
s_date-high+6(2) = '28'.
ENDCASE.
APPEND s_date.
regards ,
Sudha.
reward points if useful.
‎2007 May 29 9:50 AM
‎2007 May 29 9:52 AM
select-options: s_date for coep-budat default '01012007' to '31122007'
‎2007 May 29 9:53 AM
use this function module to get the last days of the month
RP_LAST_DAY_OF_MONTHS
regards
gowri
‎2007 May 29 9:54 AM
Hi
Select-options : s_date for sy-datum
in the intialization write the code as
Initialization.
data: v_date1 like sy-datum, v_date2 like sy-datum.
concatenate sy-datum+0(6) '01' to date1.
concatenate sy-datum+0(6) '31' to date2. (you can give, 30 or 28 depending on month condition).
s_date-low = date1.
s_date-high= date2.
s_date-sign = 'I'.
s_date-option = 'BT'.
append s_date.
now month start date and end date are defaulted into Low and high fields of date
Reward points if useful
Regards
Anji
‎2007 May 29 9:55 AM
Hi Ramana ,
Use the event Initialization ,
Since the first day will always be 1st so you can assign this value as the start date and to get the last date use the FM RP_LAST_DAY_OF_MONTHS.
Pass the current date to this FM , this will give the last day of the month.
Hope this helps.
Regards
Arun
‎2007 May 29 9:56 AM
Hi
SELECT-OPTIONS SO_DATUM FOR SY-DATUM.
INITIALIZATION.
SO_DATUM(3) = 'IBT'.
SO_DATUM-LOW = SY-DATUM.
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
DAY_IN = SY-DATUM
IMPORTING
LAST_DAY_OF_MONTH = SO_DATUM-HIGH.
APPEND SO_DATUM.Max
‎2007 May 29 9:59 AM
initalization
call the function module BAPI_COAREA_GETPERIODLIMITS for getting the start data and end date for the peroid using the Controlling area ...
then passit to the 2 variable like start_date and end_date .....
select-options : period for sy-datum defualt sy-datum.
at selection-screen .
loop at sceen .
if screen-fields = period-low
period = start_date
elseif screen-fields = period-high
period = end_date
endif .
endloop.
‎2007 May 29 10:01 AM
HI,
select-OPTIONS date for sy-datum.
DATA:DAT TYPE SY-DATUM.
INITIALIZATION.
DAT = SY-DATUM.
date-sign = 'I'.
date-option = 'BT'.
DAT+6(2) = '01'.
DATE-LOW = DAT.
DAT4(2) = DAT4(2) + 1.
DAT = DAT - 1.
DATE-HIGH = DAT.
APPEND DATE.
rgds,
bharat.
‎2007 May 29 10:03 AM
hi,
we can use ranges for displaying default values.
ranges : r_date for mara-erdat. * <tablename>-<fieldname>
r_date-sign = 'I'.
r_date-options = BT.
r_date-low = '05/01/2007'.
r_date-high = '05/31/2007'.
append r_date.
clear r_date.
Reward with points if helpful.
Message was edited by:
Vinutha YV
‎2007 May 29 10:04 AM
hi ramana,
data: f_ date type sy-datum,
l_date type sy-datum.
f_date = sy-datum.
l_date = sy-datum + 30.
initilization.
s.op-low = f_date.
s.op-high = l_date.
s.op-sign = 'I'.
s.op-option = 'BT'.
append s.op.
it works for the date, if it's the first day of the month,
otherwise u can make sy-datum as first day of the month then u can pass those dates to local variables,
then it works.
regards,
seshu.
‎2007 May 29 10:10 AM
Hi Ramana Prasad ,
just try this code.....
LOAD-OF-PROGRAM.
DATA: v_date TYPE sy-datum.
v_date = sy-datum.
v_date+6(2) = '01'.
SELECT-OPTIONS: s_dat FOR sy-datum .
INITIALIZATION.
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
day_in = sy-datum
IMPORTING
last_day_of_month = s_dat-high.
s_dat-low = v_date.
APPEND s_dat TO s_dat[].
Regards,
Naveen Natarajan
‎2007 May 29 10:13 AM
Try this code.
SELECT-OPTIONS so_datum FOR sy-datum.
INITIALIZATION.
so_datum-low = sy-datum.
so_datum-low+6(2) = '01'.
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
day_in = sy-datum
IMPORTING
last_day_of_month = so_datum-high.
APPEND so_datum.
‎2007 May 29 10:18 AM
Hi,
There's a function module <b>'OIL_LAST_DAY_OF_PREVIOUS_MONTH'</b> that is used to determine the last day of the previous month. from this you can derive the first date of the current month.
Sample:
parameters : date1 like sy-datum.
CALL FUNCTION 'OIL_LAST_DAY_OF_PREVIOUS_MONTH'
EXPORTING
I_DATE_OLD = date1
IMPORTING
E_DATE_NEW = date1
.
data date2 like sy-datum.
date2 = date1 + 1.
write date2.
If you put 27.12.2005 as the input date, date2 you will get as 01.12.2005.
Or else you can use the following code:
v_startdate = sy-datum.
v_startdate+6(2) = '01'.
v_enddate = v_startdate.
if v_enddate+4(2) >= '01' AND v_enddate >= '11'.
v_endate4(2) = v_enddate4(2) + 1.
elseif v_enddate = '12'.
v_enddate+4(2) = '01'.
v_enddate(4) = v_enddate(4) + 1.
endif.
v_enddate = v_enddate - 1.
With the following FM you can determine last day of month
<b>RP_LAST_DAY_OF_MONTHS</b> .
Hope this helps.
Reward if helpful.
Regards,
Sipra
‎2007 May 29 10:20 AM
Hi Ramana
The only way of solving your problem is to use Function modules instead of ranges/select options,because you need the periods based on particular month which may differ so if u specify the criteria in the FM it will provide you the exact solution.
Call Function RP_LAST_DAY_OF_MONTHS.
report name = ' '.
month = ' '.
exceptions.
REWARD IF USEFUL...!!
‎2007 May 29 10:22 AM
use some simple code instead of loading a function group in the memory...
you can simply put '01' as the first date
data : lv_date type sy-datum.
lv_date = sy-datum
lv_date+6(2) = '01'.
this gives you the first date of the current month.
now for the last date, just do a simple if-else.
if lv_date+4(2) is one of these - 01, 03, 05, 07, 08, 10, 12 then use 31 as the last two characters
if it is 02 then do the leap year calculation -
A year is a leap year if it is evenly divisible by 4
...but not if it's evenly divisible by 100
...unless it's also evenly divisible by 400
for leap year use 29 else use 28
else put 30 as the last two characters.
regards,
Priyank
‎2007 May 29 11:12 AM
Hi All,
Thanks for ur code.
Especially sudha thanks for ur code.
i have assigned the points.
Regards
Ramana Prasad.T
‎2007 May 29 11:01 AM
Hi,
you can use this code just copy paste and run
SELECT-OPTIONS: s_date FOR sy-datum OBLIGATORY.
DATA: l_date TYPE sy-datum.
INITIALIZATION.
s_date-sign = 'I'.
s_date-option = 'EQ'.
s_date-low = sy-datum.
s_date-low+6(2) = '01'.
s_date-sign = 'I'.
s_date-option = 'EQ'.
s_date-high = sy-datum - l_date+6(2) .
s_date-high4(2) = s_date-high4(2).
CASE sy-datum+4(2).
WHEN '1' OR '3' OR '5' OR '7' OR '8' OR '10' OR '12'.
s_date-high+6(2) = '31'.
WHEN '4' OR '6' OR '9' OR '11'.
s_date-high+6(2) = '30'.
WHEN '2' .
s_date-high+6(2) = '28'.
ENDCASE.
APPEND s_date.
regards ,
Sudha.
reward points if useful.
‎2007 May 29 11:02 AM
Hi,
you can use this code just copy paste and run
SELECT-OPTIONS: s_date FOR sy-datum OBLIGATORY.
DATA: l_date TYPE sy-datum.
INITIALIZATION.
s_date-sign = 'I'.
s_date-option = 'EQ'.
s_date-low = sy-datum.
s_date-low+6(2) = '01'.
s_date-sign = 'I'.
s_date-option = 'EQ'.
s_date-high = sy-datum - l_date+6(2) .
s_date-high4(2) = s_date-high4(2).
CASE sy-datum+4(2).
WHEN '1' OR '3' OR '5' OR '7' OR '8' OR '10' OR '12'.
s_date-high+6(2) = '31'.
WHEN '4' OR '6' OR '9' OR '11'.
s_date-high+6(2) = '30'.
WHEN '2' .
s_date-high+6(2) = '28'.
ENDCASE.
APPEND s_date.
regards ,
Sudha.
reward points if useful.
‎2007 May 29 11:03 AM
Hi,
Try with this code:
data : v_startdate like sy-datum,
v_enddate like sy-datum,
m_enddate like sy-datum,
v_endate like sy-datum.
select-options : s_date for sy-datum.
initialization.
v_startdate = sy-datum.
v_startdate+6(2) = '01'.
v_enddate = v_startdate.
if v_enddate+4(2) >= '01' AND v_enddate >= '11'.
v_endate4(2) = v_enddate4(2) + 1.
elseif v_enddate = '12'.
v_enddate+4(2) = '01'.
v_enddate(4) = v_enddate(4) + 1.
endif.
*v_enddate = v_enddate - 1.
m_enddate = v_enddate + 30.
s_date-low = v_enddate.
s_date-high = m_enddate.
append s_date.
Regards,
Bhaskar