cancel
Showing results for 
Search instead for 
Did you mean: 

Calculation with dates

Former Member
0 Kudos

Hi experts,

My question is how can I add year, month, or date into a datum in case of sapscript.

For Example:

I want to do something like that: '01.01.2008'+5 month

and the expected result is '01.06.2008'

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi

Check this FM CALCULATE_DATE

Regards

Gregory

Former Member
0 Kudos

"In script write this code.
/: PERFORM  get_date IN PROGRAM  (SY-REPID)
/: USING  &DATE&              "DATE FIELD
/: CHANGING  &DATE2&
/: ENDFORM

AS: &DATE2&  "output

"In print program write the this routine

FORM get_date TABLES in_tab STRUCTURE itcsy out_tab STRUCTURE itcsy.

  DATA: date TYPE sy-datum,
  from_date(10),
  out_date(10),

  read table in_tab WITH KEY 'DATE'.
  IF sy-subrc EQ 0.
    from_date = in_tab-value.  "will be in 12.01.2008 format
    CONCATENATE from_date+6(4) from_date+3(2) from_date+0(2)
    INTO date.

    CALL FUNCTION 'MONTH_PLUS_DETERMINE'
      EXPORTING
        months  = '5'   "add months
        olddate = date
      IMPORTING
        newdate = date.
  ENDIF.

  READ TABLE out_tab WITH KEY 'DATE2'.
  IF sy-subrc EQ 0.
    CONCATENATE date+6(2) date+4(2) date+0(4) INTO out_date
    SEPARATED BY '.'
    out_tab-value = out_date.
    MODIFY out_tab INDEX 1.
  ENDIF.
ENDFORM.
Former Member
0 Kudos

Hello,

Here it is.


PARAMETERS: DATE LIKE SY-DATUM,
            MONTH(2).

DATE+4(2) =  DATE+4(2) + MONTH.
WRITE DATE.
" LIke wise for year ---> DATE+0(4)
" Like wise for days ---> DATE+6(2)

Hope this will solve ur issue.

Cheers,

Vasanth

former_member196280
Active Contributor
0 Kudos

Call external sub-routine inside your form

Go through this example

Ex.

/: PERFORM <Subroutine name> IN PROGRAM <subroutine prog name>

/:USING &<field name>&

/:CHANGING &<field name1&

/:ENDPERFORM

Then create subroutine pool program and you have to write the code.

FORM ><subroutine name> tables int_cond structure itcsy

outt_cond structure itcsy.

data : value(20), value1(20). "do your own declarations

Read int_cond table index 1.

value = int_cond-value.

value1 = value1 + value.

Read outt_cond table index 1.

outt_cond-value = value1.

Modify outt_cond index 1.

ENDFORM.

Just rough idea given above.

Regards,

SaiRam

Former Member
0 Kudos

Hello,

You would have to call a form routine in a program to execute this calculation and give the result back.

Regards,

John.