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: 

Function Module for calculating NEXT MONTH's start date and End date

Former Member
0 Kudos

Hi Friends,

I want a function module which could calculate the next months start date and end date...

Say my input will be like 01.01.2006(start date) it should return

01.02.2006 and 28.02.2006...

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

thanks in advance

Cheers,

R.Kripa

1 ACCEPTED SOLUTION

former_member181962
Active Contributor
0 Kudos

pass any next month date to the FM LAST_DAY_OF_MONTHS.

try the following logic

*first day

data next_month(2) type n.

data next_month_first_day like sy-datum.

data next_month_last_day like sy-datum.

next_month = current_date+4(2) + 1.

concatenate current_date+0(4) next_month

'01' into next_month_first_day.

*last day

CALL FUNCTION 'LAST_DAY_OF_MONTHS'

EXPORTING

DAY_IN = next_month_first_day

IMPORTING

LAST_DAY_OF_MONTH = next_month_last_day.

Regards,

Ravi

7 REPLIES 7

former_member181962
Active Contributor
0 Kudos

pass any next month date to the FM LAST_DAY_OF_MONTHS.

try the following logic

*first day

data next_month(2) type n.

data next_month_first_day like sy-datum.

data next_month_last_day like sy-datum.

next_month = current_date+4(2) + 1.

concatenate current_date+0(4) next_month

'01' into next_month_first_day.

*last day

CALL FUNCTION 'LAST_DAY_OF_MONTHS'

EXPORTING

DAY_IN = next_month_first_day

IMPORTING

LAST_DAY_OF_MONTH = next_month_last_day.

Regards,

Ravi

Former Member
0 Kudos

RP_LAST_DAY_OF_MONTHS Determine last day of month

Former Member
0 Kudos

hi kripa,

the FM RS_VARI_V_1_NEXT_MONTH returns the next months starting date. and the FM LAST_DAY_OF_MONTHS gives the last day.


data : date like sy-datum,
       START LIKE SY-DATUM,
        END LIKE SY-DATUM,
        PEND TYPE P.

        PARAMETERS : P_DATE LIKE SY-DATUM.

                CALL FUNCTION 'LAST_DAY_OF_MONTHS'
                  EXPORTING
                    DAY_IN                  = P_DATE
                 IMPORTING
                   LAST_DAY_OF_MONTH       =  END
*                 EXCEPTIONS
*                   DAY_IN_NO_DATE          = 1
*                   OTHERS                  = 2.
.
    PEND = END.
    PEND = PEND + 1.
    START = PEND.

          CALL FUNCTION 'LAST_DAY_OF_MONTHS'
               EXPORTING
                    DAY_IN                  = START
                 IMPORTING
                   LAST_DAY_OF_MONTH       =  END.


WRITE : / START , END .

ps : reward points if helpful

Former Member
0 Kudos

Hi kripa,

1. There is no DIRECT Way.

2. We have to do in 2 steps.

3. See this code (just copy paste in new program)

U can use its FORM anywhere in your program,

for getting the desired dates.

4.

REPORT abc.

DATA : sdate TYPE sy-datum,

edate TYPE sy-datum.

PARAMETERS : dt TYPE sy-datum DEFAULT sy-datum.

*----


PERFORM getdt USING dt sdate edate.

WRITE 😕 sdate , edate.

*----


  • INDEPENDENT FORM

*----


FORM getdt USING orgdate stdate enddate.

DATA : mydate TYPE sy-datum.

CALL FUNCTION 'HR_PSD_DATES_ADD_MONTHS'

EXPORTING

v_date = orgdate

V_MONTHS = 1

IMPORTING

E_DATE = mydate

EXCEPTIONS

NOT_POSITIVE = 1

OTHERS = 2

.

CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'

EXPORTING

iv_date = mydate

IMPORTING

ev_month_begin_date = stdate

ev_month_end_date = enddate.

ENDFORM. "getdt

regards,

amit m.

Former Member
0 Kudos

data: o_date like sy-datum,

l_date like sy-datum.

parameters:i_date like sy-datum.

CALL FUNCTION 'SG_PS_GET_LAST_DAY_OF_MONTH'

EXPORTING

day_in = i_date

IMPORTING

LAST_DAY_OF_MONTH = o_date

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.

o_date = o_date + 1.

CALL FUNCTION 'SG_PS_GET_LAST_DAY_OF_MONTH'

EXPORTING

day_in = o_date

IMPORTING

LAST_DAY_OF_MONTH = l_date

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.

write: 'Begin Date of next month',o_date,

'Last day of next month',l_date.

Former Member
0 Kudos

This is the logic i ve used ....

FORM GET_NEXT_START_DATE_END_DATE .

DATA : L_MONTH_TEMP LIKE CKMLPP-POPER,

L_MONTH(2),

L_YEAR_TEMP LIKE CKMLPP-BDATJ.

L_MONTH = L_START_DATE+4(2).

L_YEAR_TEMP = L_START_DATE+0(4).

UNPACK L_MONTH TO L_MONTH_TEMP.

  • To get the next period

CALL FUNCTION 'CKML_F_DETERMINE_NEXT_PERIOD'

EXPORTING

CURRENT_PERIOD = L_MONTH_TEMP

CURRENT_YEAR = L_YEAR_TEMP

F_PERIV = '10'

IMPORTING

NEXT_PERIOD_PERIOD = L_MONTH_TEMP

NEXT_PERIOD_YEAR = L_YEAR_TEMP.

PACK L_MONTH_TEMP TO L_MONTH.

CONCATENATE L_YEAR_TEMP L_MONTH '01' INTO L_START_DATE.

CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'

EXPORTING

IV_DATE = L_START_DATE

IMPORTING

EV_MONTH_BEGIN_DATE = L_START_DATE

EV_MONTH_END_DATE = L_END_DATE.

Thanks for all ur replies

Cheers,

R.Kripa.

sergey_korolev
Active Contributor
0 Kudos

Next month bounds - 8 executable statements:

DATA:
  next_month_start TYPE d,
  next_month_end TYPE d.

next_month_start = given_date.
next_month_start+6(2) = '01'.
ADD 31 TO next_month_start.
next_month_start+6(2) = '01'.

next_month_end = next_month_start.
ADD 31 TO next_month_end.
next_month_end+6(2) = '01'.
SUBTRACT 1 FROM next_month_end.