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

function module which could calculate the previous month's start date.....

Former Member
0 Likes
2,193

hi,

I want a function module which could calculate the previous month's start date and end date...

Say todays date is like 29.05.2007(start date) it should return

01.04.2007 and 30.04.2007...

IS there any FM for this ... or how to go about this scenario ???

thanks in advance

samm

hi,

I want a function module which could calculate the previous month's start date and end date...

Say todays date is like 29.05.2007(start date) it should return

01.04.2007 and 30.04.2007...

IS there any FM for this ... or how to go about this scenario ???

thanks in advance

samm

10 REPLIES 10
Read only

Former Member
0 Likes
1,872

HI,

Start date would be 01 for every month, so to find the last date for a month use RP_LAST_DAY_OF_MONTHS function module

Regards

Sudheer

Read only

Former Member
0 Likes
1,872

Get the first day is easy...for the last day you could use <b>RP_LAST_DAY_OF_MONTHS</b>

Greetings,

Blag.

Read only

Former Member
0 Likes
1,872

Hi,

Please try this.


data: wa_date like sy-datum,
      s_date  like sy-datum,
      e_date  like sy-datum.

wa_date = sy-datum - 30.

CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
  EXPORTING
    iv_date = wa_date
  IMPORTING
    ev_month_begin_date = s_date
    ev_month_end_date = e_date.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
1,872

See the below Logic :

DATA :g_date(2) TYPE n, " Date

g_month(2) TYPE n, " Month

g_year(4) TYPE n , " Year

g_bill_low(10) TYPE n, " From date

g_bill_high(10) TYPE n, " To date

g_month1(2) TYPE n, " Month

g_year1(4) TYPE n, " Year

g_date1(2) TYPE n, " Date

g_year2(4) TYPE n, " Year

g_datum LIKE sy-datum. " System date

RANGES : r_bdate FOR vbrk-fkdat. " Billing date

g_datum = p_date + 10.

g_month = g_datum+4(2).

g_year = g_datum+0(4).

IF g_month = 1.

g_year = g_year - 1.

g_month = 12.

g_date = 1.

ELSE.

g_month = g_month - 1.

g_date = 1.

ENDIF.

  • Passing the date to billing date-low

CONCATENATE g_year g_month g_date INTO g_bill_low.

r_bdate-low = g_bill_low.

r_bdate-sign = 'I'.

r_bdate-option = 'BT'.

g_month1 = g_datum+4(2).

g_year1 = g_datum+0(4).

IF g_month1 = 1.

g_year1 = g_year1 - 1.

g_month1 = 12.

ELSE.

g_month1 = g_month1 - 1.

ENDIF.

CASE g_month1.

WHEN 1.g_date1 = '31'.

WHEN 3.g_date1 = '31'.

WHEN 4.g_date1 = '30'.

WHEN 5.g_date1 = '31'.

WHEN 6.g_date1 = '30'.

WHEN 7.g_date1 = '31'.

WHEN 8.g_date1 = '31'.

WHEN 9.g_date1 = '30'.

WHEN 10.g_date1 = '31'.

WHEN 11.g_date1 = '30'.

WHEN 12.g_date1 = '31'.

ENDCASE.

g_year2 = g_year1.

IF g_month1 = 2.

g_year2 = g_year2 MOD 4 .

IF g_year2 = 0.

g_date1 = 29.

ELSE.

g_date1 = 28.

ENDIF.

ENDIF.

  • Passing the date to billing date-high

CONCATENATE g_year1 g_month1 g_date1 INTO g_bill_high.

r_bdate-high = g_bill_high.

APPEND r_bdate.

Reward Points if it is helpful

Thanks

Seshu

Read only

0 Likes
1,872

This is not a function module, but simple.

Data Temp_date type d.

Data Start_date type d. "Start of Month

Data End_date type d. "End of Month

Temp_date = sy-datum. "20070529

Temp_date+6(2) = '01' . "20070501

  • Calculate one day before current month

  • This works even if we go back a year

Last_date = Temp_date - 1. "20070430

First_date = Last_date.

First_date+6(2) = '01'. "20070401

Read only

Former Member
0 Likes
1,872

Hi,

  • Read the first and last date for the previous month

CALL FUNCTION 'RS_VARI_V_LAST_MONTH'

TABLES

p_datetab = t_date1

p_intrange = s_interchange.

  • Read table for the date range of the previous month

READ TABLE t_date1 INTO s_date2 INDEX 1 .

IF sy-subrc = 0 .

  • Set the select option value

s_date-sign = c_i .

s_date-option = c_bt.

s_date-low = s_date2-low .

s_date-high = s_date2-high .

APPEND s_date TO rt_date .

CLEAR s_date .

Hope this solves your purpose.

Award points if it helps.

-Gaurang

Read only

Peter_Inotai
Active Contributor
0 Likes
1,872

Check function modules in Function group 0002. There is FM BAPI_CCODE_GET_FIRSTDAY_PERIOD, which can help you.

Peter

Read only

Former Member
0 Likes
1,872

No FMs needed:


REPORT ztest MESSAGE-ID 00.

DATA: start LIKE sy-datum,
      end LIKE sy-datum.

end = sy-datum.
end+6(2) = '01'.
end = end - 1.

start = end.
start+6(2) = '01'.

WRITE: start, end.

Rob

Read only

Former Member
0 Likes
1,872

Hi,

to get the last of the current month, the FM is : RP_LAST_DAY_OF_MONTHS.

for ur requirement , no Fm is required.

Just copy paste the belwo code and check.

data: s type sy-datum.

sy-datum+6(2) = '01'.

sy-datum = sy-datum - 1.

write:/ sy-datum. " this is the last day of the previous month.

sy-datum+6(2) = '01'.

write: / sy-datum. " this is the first day of the last month

Revert back if nay issues.

Reward with points if helpful.

Regards,

Naveen.

Read only

Former Member
0 Likes
1,872

Hi Samir

We have a function module <b>RP_LAST_DAY_OF_MONTHS</b> to get the month's start date n end date if u enter the month alone...

call function RP_LAST_DAY_OF_MONTHS

exporting.

month = ' '.

importing.

first_date = ' '.

last_date = ' '.

exceptions.

REWARD IF USEFUL...!!