<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Split string in CDS View in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326760#M5196</link>
    <description>&lt;P&gt;Hi experts, &lt;/P&gt;&lt;P&gt;I want to split a column from the select list and return the string till the first occurrence of space. &lt;/P&gt;&lt;P&gt;eg. 'SAMPLE DOC' is the value stored in BKPF-XBLNR and I want my view to return only 'SAMPLE' in this case. &lt;/P&gt;&lt;P&gt;Is this possible using string functions in ABAP CDS? &lt;/P&gt;&lt;P&gt;I tried the below code. But this does not work since the substring function expects a numeric literal as its third parameter. &lt;/P&gt;&lt;P&gt;Thanks, &lt;/P&gt;&lt;P&gt;Ajith Cheruvally &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;@AbapCatalog.sqlViewName: 'ZXXXXXX'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Test CDS for substring'
define view ZXXXXXX  as select from bkpf as posted{
    posted.mandt, 
    posted.bukrs, 
    posted.belnr, 
    posted.gjahr, 
    xblnr, 
    substring( xblnr , 1 , instr( posted.xblnr , ' ' ) ) as test
}


&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 21 Oct 2016 05:45:03 GMT</pubDate>
    <dc:creator>ajith_c</dc:creator>
    <dc:date>2016-10-21T05:45:03Z</dc:date>
    <item>
      <title>Split string in CDS View</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326760#M5196</link>
      <description>&lt;P&gt;Hi experts, &lt;/P&gt;&lt;P&gt;I want to split a column from the select list and return the string till the first occurrence of space. &lt;/P&gt;&lt;P&gt;eg. 'SAMPLE DOC' is the value stored in BKPF-XBLNR and I want my view to return only 'SAMPLE' in this case. &lt;/P&gt;&lt;P&gt;Is this possible using string functions in ABAP CDS? &lt;/P&gt;&lt;P&gt;I tried the below code. But this does not work since the substring function expects a numeric literal as its third parameter. &lt;/P&gt;&lt;P&gt;Thanks, &lt;/P&gt;&lt;P&gt;Ajith Cheruvally &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;@AbapCatalog.sqlViewName: 'ZXXXXXX'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Test CDS for substring'
define view ZXXXXXX  as select from bkpf as posted{
    posted.mandt, 
    posted.bukrs, 
    posted.belnr, 
    posted.gjahr, 
    xblnr, 
    substring( xblnr , 1 , instr( posted.xblnr , ' ' ) ) as test
}


&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Oct 2016 05:45:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326760#M5196</guid>
      <dc:creator>ajith_c</dc:creator>
      <dc:date>2016-10-21T05:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Split string in CDS View</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326761#M5197</link>
      <description>&lt;P&gt;hi Ajith,&lt;/P&gt;&lt;P&gt;What error are you actually getting, is it within CDS editor in AiE? If you have access to instr, then I presume you are using a 750 environment?, unfortunately this is not available to me as I'm still in 740 (SP 13).&lt;/P&gt;&lt;P&gt;If the editor is really throwing an error due to the numeric 3rd parameter as defined below,&lt;/P&gt;&lt;P&gt;SUBSTRING(arg, pos, len)&lt;/P&gt;arg: see below &lt;BR /&gt;&lt;BR /&gt;pos and len: positive numeric literal not equal to zero&lt;P&gt;The output from INSTR shows as INT4&lt;/P&gt;INSTR(arg, sub)arg: see below &lt;BR /&gt;&lt;BR /&gt;sub: non-empty numeric literal&lt;P&gt;INT4&lt;/P&gt;&lt;P&gt;Full reference here.&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.sap.com/abapdocu_750/en/abencds_f1_sql_functions_character.htm" target="test_blank"&gt;https://help.sap.com/abapdocu_750/en/abencds_f1_sql_functions_character.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You could try a cast around the instr function to convert it to numeric value like this. cast( 1 as abap.numc( 10 ) )&lt;/P&gt;&lt;P&gt;This works for me in 740&lt;/P&gt;&lt;P&gt;substring( xblnr , 1 , cast( 10 as abap.numc( 10 ) ) ) as test,&lt;/P&gt;&lt;P&gt;Try the cast and see how it goes&lt;/P&gt;&lt;P&gt;Sean&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 12:05:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326761#M5197</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2016-10-21T12:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: Split string in CDS View</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326762#M5198</link>
      <description>&lt;P&gt;Hi Sean, &lt;/P&gt;&lt;P&gt;Thanks for helping. &lt;/P&gt;&lt;P&gt;Specifying length statically works like in the example you wrote. &lt;/P&gt;&lt;P&gt;However, when I specify the length value dynamically, it does not accept it. &lt;/P&gt;&lt;P&gt;I tried casting INT4 to NUMC( Though it is not possible to cast INT4 to NUMC) but got the same error. &lt;/P&gt;&lt;P&gt;'Function SUBSTRING: at position  3, only Literals, possibly positive integers allowed'&lt;/P&gt;&lt;P&gt;I even tried by adding length as a parameter of type numc to the view, but still the same error. &lt;/P&gt;&lt;P&gt;Looks like it accepts only static numeric literal ... which does not help my situation. &lt;/P&gt;&lt;P&gt;Do you have any other suggestions? Please share.&lt;/P&gt;&lt;P&gt;Thanks, &lt;/P&gt;&lt;P&gt;Ajith Cheruvally&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;@AbapCatalog.sqlViewName: 'ZXXXXX'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Test CDS viewn'
define view ZXXX_XX_XX  with parameters p_test : abap.numc(2) as select from bkpf as posted{
    posted.mandt, 
    posted.bukrs, 
    posted.belnr, 
    posted.gjahr, 
    xblnr, 
    substring(xblnr , 1, :p_test) as test
    }

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Oct 2016 09:13:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326762#M5198</guid>
      <dc:creator>ajith_c</dc:creator>
      <dc:date>2016-10-22T09:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: Split string in CDS View</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326763#M5199</link>
      <description>&lt;P&gt;hi Ajith, Apologies as I can't test this out in 750, but you may try some intermediatary / inner views to solve this.&lt;/P&gt;&lt;P&gt;View 1: Creates a column with the result of the instr value in INT4, say instr_pos&lt;/P&gt;&lt;P&gt;View 2: Casts the instr_pos to char, e.g. instr_char_val&lt;/P&gt;&lt;P&gt;View 3: Casts the instr_char_val to numc, e.g. to instr_numc_val&lt;/P&gt;&lt;P&gt;View4: Use of substring function, using instr_numc_val as the len parameter.&lt;/P&gt;&lt;P&gt;Bit of a pain for sure, but as CDS functionality improves, you should be able to combine all of the 4 above in one Select statement.&lt;/P&gt;&lt;P&gt;Let us know how it goes,&lt;/P&gt;&lt;P&gt;Sean.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 14:10:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326763#M5199</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2016-10-24T14:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: Split string in CDS View</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326764#M5200</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;I am also facing same issue. Kindly suggest me how can we split any string at '_'  into two variable.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ranjeet&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 07:58:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326764#M5200</guid>
      <dc:creator>ranjeetabap</dc:creator>
      <dc:date>2017-06-22T07:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: Split string in CDS View</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326765#M5201</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;It is not working, kindly suggest me how can we split any string at '_' into two variable.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ranjeet&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 08:01:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326765#M5201</guid>
      <dc:creator>ranjeetabap</dc:creator>
      <dc:date>2017-06-22T08:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: Split string in CDS View</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326766#M5202</link>
      <description>&lt;P&gt;Hi Ajith,&lt;/P&gt;&lt;P&gt;Kindly tell me solution, how you split string at '_' into two variable.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ranjeet&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 08:06:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326766#M5202</guid>
      <dc:creator>ranjeetabap</dc:creator>
      <dc:date>2017-06-22T08:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Split string in CDS View</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326767#M5203</link>
      <description>&lt;P&gt;Did anybody ever find a solution for this?  It seems I cannot use an INSTR function or a variable in the 2nd or 3rd position of the Substring function.  This seems like a serious limitation for CDS development.  How are we supposed to split up a string if the exact position within the string varies record by record?&lt;/P&gt;&lt;P&gt;This is an example of the type of substring syntax throwing the error:&lt;/P&gt;&lt;P&gt;SUBSTRING(rate,1,instr(rate,'%'))&lt;/P&gt;&lt;P&gt;How do we determine the above instr(rate,'%') value and then use it within the substring function?&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 19:13:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326767#M5203</guid>
      <dc:creator>acapone01</dc:creator>
      <dc:date>2021-05-21T19:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Split string in CDS View</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326768#M5204</link>
      <description>&lt;P&gt;Try:&lt;/P&gt;&lt;P&gt;String Functions in ABAP CDS Views – Known Limitations and Workarounds, BY DINESH KUMAR REDDY,  AUG 9, 2018.&lt;/P&gt;&lt;P&gt;Link: &lt;A href="https://visualbi.com/blogs/sap/sap-bw-hana/sap-hana/string-functions-abap-cds-views-known-limitations-workarounds/" target="test_blank"&gt;https://visualbi.com/blogs/sap/sap-bw-hana/sap-hana/string-functions-abap-cds-views-known-limitations-workarounds/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Radek&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 12:03:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326768#M5204</guid>
      <dc:creator>radek_hosek2</dc:creator>
      <dc:date>2021-10-12T12:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: Split string in CDS View</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326769#M5205</link>
      <description>&lt;P&gt;Is there a solution to this yet? &lt;/P&gt;&lt;P&gt;substring( TextObj , 1, instr(TextObj,'  ') ) is still giving error "Function SUBSTRING: at position  3, only Literals, possibly positive integers allowed"&lt;/P&gt;&lt;P&gt;Does CDS provide a workaround for this? It should be possible to find the substring till a dynamic position based on a particular character using a single statement.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Nov 2021 12:10:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326769#M5205</guid>
      <dc:creator>former_member334095</dc:creator>
      <dc:date>2021-11-04T12:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: Split string in CDS View</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326770#M5206</link>
      <description>&lt;P&gt;Hello Ajith, &lt;/P&gt;&lt;P&gt;Did you find a solution to this probelm yet?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Meby&lt;/P&gt;</description>
      <pubDate>Thu, 04 Nov 2021 12:13:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326770#M5206</guid>
      <dc:creator>former_member334095</dc:creator>
      <dc:date>2021-11-04T12:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: Split string in CDS View</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326771#M5207</link>
      <description>&lt;P&gt;Currently only fix values are possible in ABAP SQL string functions.&lt;/P&gt;&lt;P&gt;There is a workaround by using HANA Views or Calculation Views.&lt;/P&gt;&lt;P&gt;Please have a look at &lt;A href="https://visualbi.com/blogs/sap/sap-bw-hana/sap-hana/extended-view-based-hana-views/" target="test_blank"&gt;https://visualbi.com/blogs/sap/sap-bw-hana/sap-hana/extended-view-based-hana-views/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;With Version 7.55 SQL expressions are allowed as parameter (length).&lt;BR /&gt;This should solve the problem.&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abensql_string_func.htm" target="test_blank"&gt;https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abensql_string_func.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Thorsten&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 06:38:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326771#M5207</guid>
      <dc:creator>ThorstenHoefer</dc:creator>
      <dc:date>2021-11-05T06:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Split string in CDS View</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326772#M5208</link>
      <description>&lt;P&gt;Radek, you are godsend!&lt;/P&gt;</description>
      <pubDate>Sun, 31 Jul 2022 13:15:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326772#M5208</guid>
      <dc:creator>rowieforms</dc:creator>
      <dc:date>2022-07-31T13:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: Split string in CDS View</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326773#M5209</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I found a solution that is not so "pretty", but many of you explained here that it is not possible to use dynamic values in the "STRING", "LEFT" and "RIGHT" functions, but I need the solution and that’s what I did , I hope it helps those who need the same result.&lt;/P&gt;&lt;P&gt;I created a new CDS with only the table key, the complete value and the value that I need to do the split before the "_":&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'TESTE'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
    serviceQuality: #X,
    sizeCategory: #S,
    dataClass: #MIXED
}
define view entity ZI_TESTE_ALYSSON
  as select from ztest_te_alysson
{
  field1,

  case
    when instr(field1, '_') = 2
      then LEFT( field1, 1 )

    when instr(field1, '_') = 3
      then LEFT( field1, 2 )

    when instr(field1, '_') = 4
      then LEFT( field1, 3 )

    when instr(field1, '_') = 5
      then LEFT( field1, 4 )

    when instr(field1, '_') = 6
      then LEFT( field1, 5 )

    when instr(field1, '_') = 7
      then LEFT( field1, 6 )

    when instr(field1, '_') = 8
      then LEFT( field1, 7 )

    when instr(field1, '_') = 9
      then LEFT( field1, 8 )

    when instr(field1, '_') = 10
      then LEFT( field1, 9 )

    when instr(field1, '_') = 11
      then LEFT( field1, 10 )

     else field1
      end as split
}&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2111662-image.png" /&gt;&lt;/P&gt;&lt;P&gt;If you want the dynamic value after the "_" or "/" or "-", you can change it to the command:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;when instr(field1, '/' ) = 2
then RIGHT( field1, 1 )
...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Nov 2022 20:32:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/split-string-in-cds-view/m-p/326773#M5209</guid>
      <dc:creator>former_member743581</dc:creator>
      <dc:date>2022-11-08T20:32:43Z</dc:date>
    </item>
  </channel>
</rss>

