‎2007 Jul 24 1:59 PM
Hi friends,
I need to display the last date of previous month in the selection screen. For example today date is 24.07.2007 I need to display 30.06.2006. If the last month contains 31 days then I need to display 31.06.2006 like that. How to prepare the logic
Thanks.
‎2007 Jul 24 2:01 PM
hi,
Try this
DATA: L_DATE LIKE SY-DATUM,
L_YEAR(4) TYPE n,
L_MONTH(3) TYPE n,
L_MONYR(7) TYPE n.
L_DATE = sy-datum. (here l_date = "input you give")
l_year = l_date(4).
l_month = l_date+4(2).
L_MONTH = L_MONTH - 1.
IF L_MONTH LT 1.
L_YEAR = L_YEAR - 1.
L_MONTH = 12.
ENDIF.
Message was edited by:
Roja Velagapudi
‎2007 Jul 24 2:02 PM
Hey bharat,
Use this FM to get the date .
calculating past 1 month date
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
DATE = sy-datum
DAYS = 0
MONTHS = 1
SIGNUM = '-'
YEARS = 0
IMPORTING
CALC_DATE = v_date.
Rewards if helpful
Azad.
‎2007 Jul 24 2:02 PM
Hi,
Check the following link:
http://www.sap-img.com/abap/determine-last-day-of-the-previous-month.htm
Regards,
Bhaskar
‎2007 Jul 24 2:03 PM
Hi,
There's a function module 'OIL_LAST_DAY_OF_PREVIOUS_MONTH' that is used to determine the last day of the previous month.
<b>Sample:</b>
parameters : date1 like sy-datum.
CALL FUNCTION 'OIL_LAST_DAY_OF_PREVIOUS_MONTH'
EXPORTING
I_DATE_OLD = date1
IMPORTING
E_DATE_NEW = date1Regards
Sudheer
‎2007 Jul 24 2:15 PM
HI,
Use this funcation module. and here is the complete code.. put this code in the initialization section .
DATA : LV_LASTMONTH TYPE SY-DATUM,
LV_MONTH(2) TYPE N,
LV_LASTDAY TYPE SY-DATUM..
LV_LASTMONTH = SY-DATUM.
LV_MONTH = LV_LASTMONTH+4(2).
LV_MONTH = LV_MONTH - 1.
LV_LASTMONTH+4(2) = LV_MONTH.
CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'
EXPORTING
DAY_IN = LV_LASTMONTH
IMPORTING
LAST_DAY_OF_MONTH = LV_LASTDAY
EXCEPTIONS
DAY_IN_NOT_VALID = 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.
Thanks
Mahesh
‎2007 Jul 24 2:16 PM
Hi,
You can use the function module "RP_CALC_DATE_IN_INTERVAL" to calculate the previous month and function module "RP_LAST_DAY_OF_MONTHS" to get the last date of the month.
Try using this code.
Data : m_date type sy-datum,
Last_date type sy-datum.
*calculating previous1 month date
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
DATE = sy-datum
DAYS = 0
MONTHS = 1
SIGNUM = '-'
YEARS = 0
IMPORTING
CALC_DATE = m_date.
Get the last date of the month
CALL FUNCTION RP_LAST_DAY_OF_MONTHS
EXPORTING
DAY_IN = m_date
IMPORTING
LAST_DAY_OF_MONTH = last_date.
Reward points if it was useful.
Regards,
Hema.
‎2007 Jul 24 2:48 PM
Hi,
Are you talking about hardcoding the date in selection-screen??
If you have a variant you can activate dynamic date calculation for the date variable, so that the selection screen will be populated automatically.
Goto SE38 - select variant - selection variable- check dynamic selection.- give the option u need
Let me know if you need help on this.