Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

date

Former Member
0 Likes
920

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.

7 REPLIES 7
Read only

Former Member
0 Likes
895

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

Read only

Former Member
0 Likes
895

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.

Read only

Former Member
0 Likes
895
Read only

Former Member
0 Likes
895

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 = date1

Regards

Sudheer

Read only

Former Member
0 Likes
895

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

Read only

Former Member
0 Likes
895

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.

Read only

Former Member
0 Likes
895

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.