Monday 28 April 2014

How to find the number of days between two date in SAP ABAP using Function Module

Following are the codes to find the number of days between two date in SAP ABAP using Function Module
*&---------------------------------------------------------------------*
*& Report  ZTESTR_5
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ztestr_5.

DATA lv_days TYPE p.

PARAMETERS p_date1 TYPE sy-datum,
             p_date2 TYPE sy-datum.

CALL FUNCTION '/SDF/CMO_DATETIME_DIFFERENCE'
 EXPORTING
   DATE1                  p_date1
*   TIME1                  =
   DATE2                  p_date2
*   TIME2                  =
 IMPORTING
   DATEDIFF               lv_days
*   TIMEDIFF               =
*   EARLIEST               =
 EXCEPTIONS
   INVALID_DATETIME       1
   OTHERS                 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.


WRITE / lv_days.

Similarly , you can also find the time difference by populating the time1 and time2 parameter.
Thanku , please do share and comment.