Please bear with my style of presentation. I do not believe in the orthodox text book flow. Isn’t it kind of boring? So, I try to be funny, add lots of emojis in the so called serious SAP blog and try to refresh your jammed brain. After all, learning serious stuffs can be fun too.
We have extra spice this time. Special Segment. Don’t miss it !!!
The new story goes this way. We have 3 important things to deal when DATE is talked about. DAY, MONTH and YEAR. We are limiting our discussion to first two in this article. Let’s get started.
1. ADD DAYS
2. ADD MONTHS
3. DAYS BETWEEN TWO DATES
4. DATE VALIDATION
1. ADD DAYS:
Do you recall? There are some numbers on either side of the great “0” on number line, called as INTEGERS. That’s the hint to define ADD_DAYS in CDS Views.
Yes, absolutely. ADD_DAYS can be used not just for adding but also SUBTRACTING.
Thumb rule of ADD_DAYS function is, one needs to pass:
i. First Parameter : Date to which days to be added
ii. Second Parameter : Number of Days to be added
iii. Third Parameter : Error Handling- Four values can be :
- “FAIL” (an error raises an exception)
- “NULL” (an error returns the null value)
- “INITIAL” (an error returns the initial value)
- “UNCHANGED” (an error returns the unmodified value of date)
Also Read : What’s there in the Date?
2. ADD MONTHS
Straight forward with three parameters. One each for input date, number of months to be added and error handling respectively.
Names can be misleading . One can even subtract. ?
3. DAYS BETWEEN TWO DATES
Don’t be smart here. Never calculate the days between two DATES. It can ruin your day. ?
Back to CDS, two inputs, one for first extreme and other for other extreme.
4. DATE VALIDATION
What more can you ask, this can be used to validate the date and know whether your DATE was valid ( if not, just WISH to have another ) or NOT. ?
Output returns either “1” or “0”.
For all the above functions ONE Code Example is used. But to provide an enthralling and excruciating experience, we have MORE than ONE Test Case.
@EndUserText.label:'Test Date and Time'
Food for Thought –
What do you think would be the output of below code snippet?
To find the answer, check this. Maths in ABAP
TEST CASE 1 (only look for P_ADD_DAYS):
Wondering why the “-735740” was given in P_ADD_DAYS …..There is something called as BVA in Software Testing…Go and check it out for yourself what does that mean.
Now, let’s analyse what we have done:
|-735740||2015-05-21||00010102||00010102||As per expectation|
On 20th May 2015, it was 735740 calendar days. If 01/01/0001 + 735740 = 20/05/2015, then 20/05/2015 – 735740 should be 01/01/0001. But the output is showing 00/00/0000. Why? Any explanation?
TEST CASE 2:
(the special segment which we promised above) .. disappointed? ?
In continuation with the previous topic, in this section we will explore two more functions.
Huge list of parameters (just 5) needs to be passed in order to combine date and time AND also convert to different timezone.
First input is date, second is time, third timezone, fourth client and finally error handling.
Straight as an arrow, just pass the session client and get system’s Time Zone.
Note: It is very important to pass Client while working in HANA.
TEST CASE 3:
@EndUserText.label:'Test Date and Time 2'
As usual we need test and validate. It has become a custom which can be broken, but I will refrain. ?
Time was picked from the database table. However, date was system date.
With that we come to an end of another article. Hope as promised earlier your fate and mine would change.
Please Follow, Share, Comment, Ask, Challenge.
We have a very active Telegram (App) SAP Technical Group with more than 3750+ SAP Technical Practitioners from 6 Continents of the SAP World. Please join it using below link.
Telegram SAP Technical Discuss Group. You need to install the Telegram App first on your mobile device. Once you have it on your mobile, you can join the group and also access it from the Web on your computer and laptop.
Free SAP ABAP for HANA Training Tutorials Exercises.
- ABAP on SAP HANA. Part I. First Program in ABAP HANA
- ABAP on SAP HANA. Part II. ADT Eclipse and HANA Studio
- ABAP on SAP HANA. Part III. Debugging in ADT
- CDS Part 1. Core Data Services – Introduction
- CDS Part 2. Core Data Services – Deep Dive
- ABAP on SAP HANA. Part VI. New Age Open SQL ABAP 740
- ABAP on SAP HANA. Part VII. SQL Script and SAP HANA Stored Procedure
- ABAP on SAP HANA. Part VIII. ADBC – ABAP DataBase Connectivity
- ABAP on SAP HANA. Part IX. AMDP – ABAP Managed Database Procedure
- ABAP on SAP HANA. Part X. AMDP with SELECT OPTIONS
- ABAP on SAP HANA. Part XI. Are Native SQL and Open SQL Competitors?
- ABAP on SAP HANA. Part XII. Open SQL, CDS or AMDP, which Code to Data Technique to use?
- ABAP on SAP HANA. Part XIII. Sample Functional Specification of HANA Project
- ABAP on SAP HANA: Part XIV. HANA Ready, HANA-tization & HANA Plus
- CDS Part 3. Expose CDS Views as OData Service through Annotation
- ABAP on SAP HANA: Part XVI. HANAtization
- ABAP on SAP HANA: Part XVII. ATC – ABAP Test Cockpit Setup & Exemption Process
- SAP ABAP on HANA: Part XVIII. SALV IDA (Integrated Data Access)
- ABAP for SAP HANA. Part XIX. Sample Technical Specification of HANA Project
- ABAP for SAP HANA. Part XX. ALV Report On SAP HANA – Opportunities And Challenges
- 4 Useful Tips on ABAP and ABAP on HANA
- Associations in HANA – A Conceptual Approach
- CDS Part 5. ABAP CDS Views With Authorization
- ABAP for SAP HANA. Part XXII. How to Consume Native HANA Views Using ADBC?
- CDS Part 6. Basic Expressions & Operations Available for CDS View – I
- 115 ABAP for SAP HANA Interview Questions & Answers
- CDS Part 7. Basic Expressions & Operations Available for CDS View – II
- CDS Part 8. Usage of Built-In Functions in CDS – I
- CDS Part 9. Usage of Built-In Functions in CDS – II
- CDS Part 10. Usage of Built-In Functions in CDS – III
- CDS Part 11. How to Consume CDS View in Smart Business Service KPI Fiori Apps?
- CDS Part 12. Useful 6 CDS Related Tools in ADT
- CDS Part 13. Key Definition in CDS Views
- CDS Part 14. ABAP Annotations for Translatable Texts in CDS Views
- CDS Part 15. Associations in CDS Views – I