Saturday, May 10, 2008

SAP ABAP adding days to Dates

SAP ABAP Using the ABAP inbuilt functionality to add Sates.

The easiest way to add or subtract days from any date filed in ABAP is shown below. Basically ABAP has an inbuilt functionality with the help of which you can add or subtract dates from the date field.

See the example given below.

REPORT ZEX_DATEADD .

*Using the ABAP inbuilt functionality to add dates.
* Data Declaration
Parameters: P_DATE1       TYPE D.

Data:       D_DATE1       TYPE D.

* 15 Days after the input date
D_Date1 = P_DATE1 + 15.
Write:/ 'Input Date', P_DATE1, '15 Days after the input date.'.
WRITE / D_DATE1.
SKIP.
* 50 Days after the input date
D_Date1 = P_DATE1 + 50.
Write:/ 'Input Date', P_DATE1, '50 Days after the input date.'.
WRITE / D_DATE1.
SKIP.
* 500 Days after the input date
D_Date1 = P_DATE1 + 500.
Write:/ 'Input Date', P_DATE1, '500 Days after the input date.'.
WRITE / D_DATE1.
SKIP.

Write:/ 'Going Back in Time'.
SKIP.

* 15 Days before the input date
D_Date1 = P_DATE1 - 15.
Write:/ 'Input Date', P_DATE1, '15 Days before the input date.'.
WRITE / D_DATE1.
SKIP.
* 50 Days before the input date
D_Date1 = P_DATE1 - 50.
Write:/ 'Input Date', P_DATE1, '50 Days before the input date.'.
WRITE / D_DATE1.
SKIP.
* 500 Days before the input date
D_Date1 = P_DATE1 - 500.
Write:/ 'Input Date', P_DATE1, '500 Days before the input date.'.


If you input the following date

01012000

Then the output would be as follows.

Adding Date                                                 
                                                            
Input Date 01012000 15 Days after the input date.           
01162000                                                    
                                                            
Input Date 01012000 50 Days after the input date.           
02202000                                                    
                                                            
Input Date 01012000 500 Days after the input date.          
05152001                                                    
                                                            
Going Back in Time                                          
                                                            
Input Date 01012000 15 Days before the input date.          
12171999                                                    
                                                            
Input Date 01012000 50 Days before the input date.          
11121999                                                    
                                                            
Input Date 01012000 500 Days before the input date.         
08191998                                                    
                           
                                 
                                                            

No comments:

Post a Comment