Date Calculation

<< Click to Display Table of Contents >>

Navigation:  All About ABAP Technique > English > Function Module Examples Code >

Date Calculation

Objective

Knowledge using SAP Standard Function Module to calculate the calendar system

Support

 

Contributor

Albertus Reinandang ( reinandang@yahoo.com )

 

1.BCA_US_DATES_CALC_UNIT : Calculating the difference of the start date and end date.

Example :
REPORT  ztest_fm101 NO STANDARD PAGE HEADING LINE-SIZE 1023.
 
PARAMETERS : pa_begda LIKE sy-datum DEFAULT '20080514',
             pa_endda LIKE sy-datum DEFAULT sy-datum.
 
START-OF-SELECTION.
 
  DATA : lv_count LIKE bca_us_bkk_td-term.
 
  CALL FUNCTION 'BCA_US_DATES_CALC_UNIT'
    EXPORTING
      i_start_date           = pa_begda
      i_end_date             = pa_endda
      i_periodunit           = '1'
    IMPORTING
      e_return               = lv_count.

 
  WRITE : / lv_count.
 

 

2./SAPHT/DRM_CALC_DATE : Add or subtract from the date of the input.

Example :

REPORT  ztest_fm102 NO STANDARD PAGE HEADING LINE-SIZE 1023.

 
PARAMETERS : pa_date LIKE  bkpf-bldat DEFAULT sy-datum,
             pa_day LIKE  bseg-dtws1,
             pa_month LIKE  bseg-dtws2,
             pa_sign DEFAULT '+' OBLIGATORY,
             pa_year LIKE  bseg-dtws3.
 
 
START-OF-SELECTION.
 
  DATA : lv_date LIKE sy-datum.
 
  CALL FUNCTION '/SAPHT/DRM_CALC_DATE'
    EXPORTING
      date      = pa_date
      days      = pa_day
      months    = pa_month
      sign      = '+'
      years     = pa_year
    IMPORTING
      calc_date = lv_date.
 
  WRITE : / lv_date.