Arun Gupta
Arun Gupta

Reputation: 31

How to get month number or name in cds view

I am creating a CDS view in Hana studio where i want to get month number or name from date (YYYYMMDD) in report, but I am unable to find any function like month or anything else,

Please help.

Upvotes: 2

Views: 7341

Answers (1)

forgetaboutme
forgetaboutme

Reputation: 623

You can join table t247 that has the required information:

@AbapCatalog.sqlViewName: 'ZDD_DATE_T'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view zdd_date_test
  with parameters p_date:abap.dats(8)
  as select from demo_expressions left outer join t247 as date_information on date_information.spras = $session.system_language {
  key mandt, 
  key id, 
  num1, 
  num2, 
  date_information.ltx as long_text
  } where date_information.mnr = substring(:p_date, 5, 2);

This will return the following data from table demo_expressions:

id,num1,num2,long_text
0,90,18,November
1,19,99,November
2,83,82,November
3,87,92,November
4,15,56,November
5,29,4,November
6,38,87,November
7,74,13,November
8,26,99,November
9,35,50,November

The use of substring(:p_date, 5, 2) is what you use to extract the month number and then join table t247.

Upvotes: 2

Related Questions