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: 

substract months from the given calender month

Former Member
0 Kudos

hi,

my requirement is to substract 3 month from the calendar month

ie., say my calendar month is 200701 then my output should be 200611

is there any function module to do this.

Thanks in advance.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Use FM


Subtract 3 month from date selected
      CALL FUNCTION 'HR_PT_ADD_MONTH_TO_DATE'
        EXPORTING
          dmm_datin       = date
          dmm_count       = 3
          dmm_oper        = '-'   "Subtraction operator
          dmm_pos         = space
        IMPORTING
          DMM_DAOUT       = lv_date
        EXCEPTIONS
          UNKNOWN         = 1
          OTHERS          = 2
                .

Lokesh

Please reward if post helps.

8 REPLIES 8

Former Member
0 Kudos

Use FM


Subtract 3 month from date selected
      CALL FUNCTION 'HR_PT_ADD_MONTH_TO_DATE'
        EXPORTING
          dmm_datin       = date
          dmm_count       = 3
          dmm_oper        = '-'   "Subtraction operator
          dmm_pos         = space
        IMPORTING
          DMM_DAOUT       = lv_date
        EXCEPTIONS
          UNKNOWN         = 1
          OTHERS          = 2
                .

Lokesh

Please reward if post helps.

0 Kudos

thanks for ur response

actually my input is calendar month (200709) not date.

is there any function module to calulate from that

thanks.

0 Kudos

I could not find any FM which adds month to period. I think the best option would be append 01 to your period and then pass it to the FM I mentioned. Then you can remove 01 from the date returned by the FM.

Hope it helps.

Lokesh

PS. Please reward helpful posts.

ferry_lianto
Active Contributor
0 Kudos

Hi,

Please use FM RP_CALC_DATE_IN_INTERVAL.


DATA: IDATE LIKE SY-DATUM,
      ODATE LIKE SY-DATUM.
                                          
MOVE '20070101' TO IDATE.
                                          
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
  EXPORTING
    DATE      = IDATE
    DAYS      = 0
    MONTHS    = 3
    SIGNUM    = '-'
    YEARS     = 0
  IMPORTING
    CALC_DATE = ODATE.
                                              
WRITE: ODATE(6).

Regards,

Ferry Lianto

Former Member
0 Kudos

Hi Lokesh,

use FM CCM_GO_BACK_MONTHS and extract year and month from the new date.

<b>Reward for helpful answers</b>

Satish

naimesh_patel
Active Contributor
0 Kudos

Hello Lokesh,

Convert the period into date ... let's say the first of day of the month.

Then use this FM 'MONTH_PLUS_DETERMINE'

Like:

CALL FUNCTION 'MONTH_PLUS_DETERMINE'

EXPORTING

months = -3 " Negative to subtract from old date, positive to add

olddate = gs_date " your date.

IMPORTING

newdate = gs_date.

Regards,

Naimesh Patel

former_member387317
Active Contributor
0 Kudos

i think there isn't any FM for this requirement

so you have to perform some string operation for your requirement...

use concatenate to solve your problem here..

Do something like this way...

data : urdate(6).

DATA: IDATE LIKE SY-DATUM,

ODATE LIKE SY-DATUM.

urdate = '200701'.

CONCATENATE urdate '01' INTO IDATE.

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

EXPORTING

DATE = IDATE

DAYS = 0

MONTHS = 3

SIGNUM = '-'

YEARS = 0

IMPORTING

CALC_DATE = ODATE.

WRITE: ODATE(6).

hope it will solve your problem..

Thanks & Regards

ilesh 24x7

Former Member
0 Kudos

thanks to all