Standard service - a fixed amount of work that is performed at a fixed price.  Post Service

  

Friday, 24 May 2019 16:10

CDS Part 16. Usage of Built-In Functions in CDS – IV

Written by  https://sapyard.com/cds-part-16-usage-of-built-in-functions-in-cds-iv/
Rate this item
(0 votes)

In our Built In Functions in CDS we have covered SQL Functions, Unit/Currency Conversion Functions,

target="_blank" rel="noreferrer noopener" aria-label="Date Functions (opens in a new tab)" href="https://sapyard.com/abap-for-sap-hana-part-xxvii-usage-of-built-in-functions-in-cds-part-iii/" target="_blank">Date Functions and we fell short of Time function. Today we will start where we left in the last post. Let us jump into what might be the last edition in this series of Built-In Functions.

In this post let’s traverse through the Time Functions. The 4 functions listed below shall be very handy to maneuver with Time.

  1. TIME_IS_VALID
    Single Parameter needs to be passed. The field type should and must be TIMESTAMP – DEC – Length 15. Same goes with the rest of the functions in this blog.
  2. UTC TIME
    Best part of this is there is no parameter that needs to given. By default returns us the Coordinated Universal Time (UTC).
  3. ADD SECONDS
    As name suggests we add the seconds to the timestamp and the output is the sum of the numbers.
  4. SECONDS BETWEEN
    Remember our last edition had DAYS BETWEEN. Now here we have seconds between.

Also Check – Free Video Course on How to Consume HANA Models in ABAP Program?

Customs are not to be broken. How can we not provide the Code and sample output?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<code>@AbapCatalog.sqlViewName:'ZTM_FNS_SQL_V'
@AbapCatalog.compiler.compareFilter:true
@AbapCatalog.preserveKey:true
@AccessControl.authorizationCheck:#NOT_REQUIRED
@EndUserText.label:'Time Functions'
defineviewZTM_FNSasselectfromzdt_concr_reptasa{
keya.rpt_idasRPT_Comment,
a.ztimeasRPT_TMSP,
tstmp_is_valid(a.ztime)asvalid1,
tstmp_current_utctimestamp()asUTC_TM,
tstmp_add_seconds(a.ztime,cast(15asabap.dec(15,0)),'INITIAL')asADDED_TM,
//TESTINGDIFFERENCEOFSECONDS
tstmp_seconds_between(tstmp_current_utctimestamp(),a.ztime,'FAIL')asdifference
}</code>
Nothing that needs special mention . ?

If this is not interesting, we have a bonus segment. This segment shall connect to different worlds : SAP and all other.

OData: Many of you have heard and worked on this beautiful concept. But how about connecting CDS with outer world (other than SAP) through OData service???

Also Take : ABAP on HANA Training

But, before that you need to hang on and bear with us since there was a special request from one of our followers (Ishan @guptism) from Twitter ( BTW our twitter handle is twitter/sapyard. Do follow us).

The article was : https://sapyard.com/abap-for-sap-hana-part-xxiv-basic-expressions-operations-available-for-cds-view-part-ii/.

Ishan (@guptism), here you go:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<code>@AbapCatalog.sqlViewName:'ZTYPE_CAST_V'
@AbapCatalog.compiler.compareFilter:true
@AbapCatalog.preserveKey:true
@AccessControl.authorizationCheck:#NOT_REQUIRED
@EndUserText.label:'Type Casting Examples'
defineviewZTYPE_CAST
asselectfromsflightasa
{
keya.carrid,
keya.connidasoriginalConn,
keya.fldate,
cast(a.connidasabap.char(2))
ascastedConn,
a.planetypeasoriginalType,
cast(a.planetypeasabap.char(2))
ascastedType
}</code>
Observe keenly there are two warnings. Let’s see what are they.

So effectively two things needs to be kept in mind.

  1. Apply Type casting only when changing from one data type to other. If it is done within same data type the very purpose is not served.
  2. Need to be very careful such that no harm is done to data.
Output justifies the claim made earlier

Another good learning for me !!! I tried to put non primary key castedConn before fldate. But SAP did not allow me. ?

This is the end of the functions series and the special request from Ishan.

Back to CDS View exposing through OData. We already have couple of article on OData from CDS Annotations at SAPYard. But, our next article on OData from CDS would be different and interesting. Well you need to wait for some more time as there is sparse space here. We promise to get it in just two days of time without bugging too much. Please stay Tuned.

If you think our page is helpful, do not forget to share our links with your friends, colleagues and team members. Do like our facebook page and follow us at twitter and instagram.

Your feedback is most welcome. Please, please leave your comments below.

We have a very active Telegram (App) SAP Technical Group with more than 4900+ 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.

Please SUBSCRIBE to SAPYard’s Youtube Channel for Free End to End SAP Video Course and Training.

Free Step by Step Core Data Services Exercises

Read 169 times

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.