SAP COMPUTE_YEARS_BETWEEN_DATES Function Module for Calculate date differences
COMPUTE_YEARS_BETWEEN_DATES is a standard compute years between dates SAP function module available within SAP R/3 or S/4 Hana systems, depending on your version and release level. It is used for Calculate date differences processing and below is the pattern details for this FM, showing its interface including any import and export parameters, exceptions etc. there is also a full "cut and paste" ABAP pattern code example, along with implementation ABAP coding, documentation and contribution comments specific to this or related objects.
See here to view full function module documentation and code listing for compute years between dates FM, simply by entering the name COMPUTE_YEARS_BETWEEN_DATES into the relevant SAP transaction such as SE37 or SE38.
Function Group: RPDA
Program Name: SAPLRPDA
Main Program:
Appliation area: P
Release date: 17-Aug-1992
Mode(Normal, Remote etc): Normal Function Module
Update:
Function COMPUTE_YEARS_BETWEEN_DATES pattern details
In-order to call this FM within your sap programs, simply using the below ABAP pattern details to trigger the function call...or see the full ABAP code listing at the end of this article. You can simply cut and paste this code into your ABAP progrom as it is, including variable declarations.CALL FUNCTION 'COMPUTE_YEARS_BETWEEN_DATES'"Calculate date differences.
EXPORTING
FIRST_DATE = "
* MODIFY_INTERVAL = ' ' "
SECOND_DATE = "
IMPORTING
YEARS_BETWEEN_DATES = "
EXCEPTIONS
SEQUENCE_OF_DATES_NOT_VALID = 1
IMPORTING Parameters details for COMPUTE_YEARS_BETWEEN_DATES
FIRST_DATE -
Data type: PREL-BEGDAOptional: No
Call by Reference: No ( called with pass by value option)
MODIFY_INTERVAL -
Data type:Default: ' '
Optional: Yes
Call by Reference: No ( called with pass by value option)
SECOND_DATE -
Data type: PREL-ENDDAOptional: No
Call by Reference: No ( called with pass by value option)
EXPORTING Parameters details for COMPUTE_YEARS_BETWEEN_DATES
YEARS_BETWEEN_DATES -
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
EXCEPTIONS details
SEQUENCE_OF_DATES_NOT_VALID -
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
Copy and paste ABAP code example for COMPUTE_YEARS_BETWEEN_DATES Function Module
The ABAP code below is a full code listing to execute function module POPUP_TO_CONFIRM including all data declarations. The code uses the original data declarations rather than the latest in-line data DECLARATION SYNTAX but I have included an ABAP code snippet at the end to show how declarations would look using the newer method of declaring data variables on the fly. This will allow you to compare and fully understand the new inline method. Please note some of the newer syntax such as the @DATA is not available until a later 4.70 service pack (SP8), which i why i have stuck to the origianl for this example.DATA: | ||||
lv_first_date | TYPE PREL-BEGDA, " | |||
lv_years_between_dates | TYPE PREL, " | |||
lv_sequence_of_dates_not_valid | TYPE PREL, " | |||
lv_modify_interval | TYPE PREL, " ' ' | |||
lv_second_date | TYPE PREL-ENDDA. " |
  CALL FUNCTION 'COMPUTE_YEARS_BETWEEN_DATES' "Calculate date differences |
EXPORTING | ||
FIRST_DATE | = lv_first_date | |
MODIFY_INTERVAL | = lv_modify_interval | |
SECOND_DATE | = lv_second_date | |
IMPORTING | ||
YEARS_BETWEEN_DATES | = lv_years_between_dates | |
EXCEPTIONS | ||
SEQUENCE_OF_DATES_NOT_VALID = 1 | ||
. " COMPUTE_YEARS_BETWEEN_DATES |
ABAP code using 7.40 inline data declarations to call FM COMPUTE_YEARS_BETWEEN_DATES
The below ABAP code uses the newer in-line data declarations. This allows you to see the coding differences/benefits of the later inline syntax. Please note some of the newer syntax below, such as the @DATA is not available until 4.70 EHP 8."SELECT single BEGDA FROM PREL INTO @DATA(ld_first_date). | ||||
DATA(ld_modify_interval) | = ' '. | |||
"SELECT single ENDDA FROM PREL INTO @DATA(ld_second_date). | ||||
Search for further information about these or an SAP related objects