Application Development 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: 

need to find the last day of the previous month

Former Member
0 Kudos
358

hi folks,

the code goes like this...

data: xt247 type t247,

monthn(30) type c,

monthnumber type i,

bforwardmonth type i.

call function 'RP_LAST_DAY_OF_MONTHS'

EXPORTING

day_in = s_date

IMPORTING

last_day_of_month = e_date.

write: 'The last day of the month', e_date.

select single * from t247 into xt247

where spras = sy-langu

and mnr = e_date+4(2).

monthnumber = xt247-mnr.

write:' The month number', monthnumber.

      • determine the previous month.

bforwardmonth = monthnumber - 1.

From here I need to determine the last day of the previous month How can I do?

Thanks for your help.

Santhosh

6 REPLIES 6

Former Member
0 Kudos
144

Try:


DATA date LIKE sy-datum.
date = sy-datum.
date+6(2) = '01'.
date = date - 1.
* DATE has the date of the previous month

Rob

0 Kudos
144

Hi Santosh / Rob,

I also think that this is the best way to do it. Because it's simple, starightforward and works for all cases without reservations.

Regards,

Anand Mandalika.

Former Member
0 Kudos
144

Hi, you can try this code:

DATA:

PA_DATEE LIKE SY-DATUM,

TMP_DURATION TYPE PSEN_DURATION_DEC.

PA_DATEE = '20050301'.

TMP_DURATION-CALYY = 0.

TMP_DURATION-CALMM = 0.

TMP_DURATION-CALDD = 2.

CALL FUNCTION 'HR_SEN_CRULE_0100_DATE'

EXPORTING

ID_DATE = PA_DATEE

ID_OPERATOR = '-'

IS_DURATION = TMP_DURATION

IMPORTING

ED_DATE = PA_DATEE

EXCEPTIONS

OTHERS = 1.

CLEAR PA_DATEE.

Aware it is 2 set to TMP_DURATION-CALDD, that mean one day before 03/01.

Hope it will be hopeful.

Former Member
0 Kudos
144

Hi,

Try this one

report ztx0914.

2 type-pools ztx1. "contains ztx1_amalgamation_date

3 data: d1 like sy-datum,

4 d2 like d1,

5 num_days type p.

6 d1 = d2 = sy-datum.

7

8 subtract 1 from d1. write / d1. "yesterday's date

9 d2+6 = '01'. write / d2. "first day of current month

10 subtract 1 from d2. write / d2. "last day of previous month

11

12 num_days = sy-datum - ztx1_amalgamation_date.

13 write / num_days. "number of days since amalgamation

<b>Output</b>

On February 22, 1998, the code in Listing 9.14 produced this output:

1998/02/21

1998/02/01

1998/01/31

354

Thanks & Regards,

Judith.

0 Kudos
144

Hi Judith,

I do not see anything new that you have tried to say in this post apart from what Rob had already said. Please read the other answers that were already given to the question before you attempt to write your answer.

Regards,

Anand Mandalika.

0 Kudos
144

Hi all,

here's the shortest solution:

REPORT z123.

PARAMETERS p_datum LIKE sy-datum DEFAULT sy-datum.

DATA ultimo LIKE sy-datum.

<b>ultimo = p_datum - p_datum+6(2).</b>

WRITE: / p_datum, 20 ultimo COLOR 2.

...

it's not my solution :

it's from <a href="http://www.abapforum.com/forum/viewtopic.php?t=1434&highlight=ultimo">Andrew_</a>

regards Andreas