<?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 Re: Switch statement + chaining operator &amp;&amp; in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/switch-statement-chaining-operator/m-p/12504866#M2003514</link>
    <description>&lt;P&gt;Hello, &lt;/P&gt;&lt;P&gt;you used the generic type # in your expression. It looks like the 4 character long conditional value 'WORD' causes a return value of type character with length 4. BTW, if you swap the expression to ...WHEN 'PNG' THEN 'IMAGE WHEN 'DOC' THEN 'WORD' it works (I guess because the result will be typed as CHAR5, according to the value given after the first THEN). It also works when you use the concrete type string instead of #. &lt;/P&gt;&lt;P&gt;This is written in the &lt;A href="https://answers.sap.com/questions/13501248/switch-statement-chaining-operator.html"&gt;documentation&lt;/A&gt; which explains what happens here: &lt;/P&gt;&lt;P&gt;If the data type of the operand after the first THEN is known statically and matches the generic type of the formal parameter, this data type is used. &lt;/P&gt;&lt;P&gt;So, as it is documented it is not a bug &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &lt;/P&gt;&lt;P&gt;From my point of view it is better to prefer a specific type over a generic one, if possible. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;test_3 = SWITCH string( lv_content_type WHEN 'DOC' THEN 'WORD'
                                        WHEN 'PNG' THEN 'IMAGE' ) &amp;amp;&amp;amp; '_TO_PDF'.&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 11 Oct 2021 11:46:16 GMT</pubDate>
    <dc:creator>jmodaal</dc:creator>
    <dc:date>2021-10-11T11:46:16Z</dc:date>
    <item>
      <title>Switch statement + chaining operator &amp;&amp;</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/switch-statement-chaining-operator/m-p/12504865#M2003513</link>
      <description>&lt;P&gt;Hi ABAP community,&lt;/P&gt;
  &lt;P&gt;I'm using the SWITCH statement in combination with &amp;amp;&amp;amp; to create a string.&lt;/P&gt;
  &lt;P&gt;Somehow when using more than one condition, it looses a letter. Following my simple example report:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;REPORT z_test_switch.

DATA: test_1 TYPE string,
      test_2 TYPE string,
      test_3 TYPE string.

DATA(lv_content_type) = 'PNG'.

* Exprected result: IMAGE_TO_PDF

* success: IMAGE_TO_PDF
test_1 = SWITCH #( lv_content_type WHEN 'PNG' THEN 'IMAGE' ).
test_1 = test_1 &amp;amp;&amp;amp; '_TO_PDF'.
WRITE / test_1.

* success: IMAGE_TO_PDF
test_2 = SWITCH #( lv_content_type WHEN 'PNG' THEN 'IMAGE' ) &amp;amp;&amp;amp; '_TO_PDF'.
WRITE / test_2.

* fails: IMAG_TO_PDF
test_3 = SWITCH #( lv_content_type WHEN 'DOC' THEN 'WORD'
                                   WHEN 'PNG' THEN 'IMAGE' ) &amp;amp;&amp;amp; '_TO_PDF'.
WRITE / test_3. 
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;It's loosing the last letter from IMAG&lt;STRONG&gt;E&lt;/STRONG&gt; and only returns IMAG_TO_PDF instead of IMAG&lt;STRONG&gt;E&lt;/STRONG&gt;_TO_PDF when using a switch with more than one condition.&lt;/P&gt;
  &lt;P&gt;I'm on System:&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1982819-system-2021-10-11-13-19.png" /&gt;&lt;/P&gt;
  &lt;P&gt;I can't figure out, what it wrong in the last testcase. Is this may be a bug? &lt;BR /&gt;Glad about any hints!&lt;/P&gt;
  &lt;P&gt;Regards&lt;BR /&gt;Nico&lt;/P&gt;</description>
      <pubDate>Mon, 11 Oct 2021 11:13:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/switch-statement-chaining-operator/m-p/12504865#M2003513</guid>
      <dc:creator>nicorunge</dc:creator>
      <dc:date>2021-10-11T11:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Switch statement + chaining operator &amp;&amp;</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/switch-statement-chaining-operator/m-p/12504866#M2003514</link>
      <description>&lt;P&gt;Hello, &lt;/P&gt;&lt;P&gt;you used the generic type # in your expression. It looks like the 4 character long conditional value 'WORD' causes a return value of type character with length 4. BTW, if you swap the expression to ...WHEN 'PNG' THEN 'IMAGE WHEN 'DOC' THEN 'WORD' it works (I guess because the result will be typed as CHAR5, according to the value given after the first THEN). It also works when you use the concrete type string instead of #. &lt;/P&gt;&lt;P&gt;This is written in the &lt;A href="https://answers.sap.com/questions/13501248/switch-statement-chaining-operator.html"&gt;documentation&lt;/A&gt; which explains what happens here: &lt;/P&gt;&lt;P&gt;If the data type of the operand after the first THEN is known statically and matches the generic type of the formal parameter, this data type is used. &lt;/P&gt;&lt;P&gt;So, as it is documented it is not a bug &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &lt;/P&gt;&lt;P&gt;From my point of view it is better to prefer a specific type over a generic one, if possible. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;test_3 = SWITCH string( lv_content_type WHEN 'DOC' THEN 'WORD'
                                        WHEN 'PNG' THEN 'IMAGE' ) &amp;amp;&amp;amp; '_TO_PDF'.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Oct 2021 11:46:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/switch-statement-chaining-operator/m-p/12504866#M2003514</guid>
      <dc:creator>jmodaal</dc:creator>
      <dc:date>2021-10-11T11:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: Switch statement + chaining operator &amp;&amp;</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/switch-statement-chaining-operator/m-p/12504867#M2003515</link>
      <description>&lt;P&gt;Hi Nico,&lt;/P&gt;&lt;P&gt;This is the result of the way you've written the SWITCH statement.&lt;BR /&gt;&lt;BR /&gt;The data type of the resulting variable is determined at runtime ('SWITCH #').&lt;BR /&gt;Since the first condition results in 'WORD', runtime puts the resulting substring of the SWITCH statement in a variable of length '4', which it then concatenates with '_TO_PDF'.&lt;BR /&gt;&lt;BR /&gt;Notice the difference in the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;"fails: IMAG_TO_PDF: output is mapped to CHAR4 ('WORD')&lt;BR /&gt;test_3 = SWITCH #( lv_content_type WHEN 'DOC' THEN 'WORD'
                                   WHEN 'PNG' THEN 'IMAGE' ) &amp;amp;&amp;amp; '_TO_PDF'.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE&gt;"success: IMAGE_TO_PDF: output of SWITCH statement is string&lt;BR /&gt;test_3 = SWITCH string( &amp;lt;br&amp;gt;  lv_content_type WHEN 'DOC' THEN 'WORD'
 WHEN 'PNG' THEN 'IMAGE' ) &amp;amp;&amp;amp; '_TO_PDF'.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE&gt;"success: IMAGE_TO_PDF: output of SWITCH statement is CHAR12&lt;BR /&gt;"because of 'WORDDOCUMENT'&lt;BR /&gt;test_3 = SWITCH #( 
  lv_content_type WHEN 'DOC' THEN 'WORDDOCUMENT' &lt;BR /&gt;  WHEN 'PNG' THEN 'IMAGE' ) &amp;amp;&amp;amp; '_TO_PDF'.

"fails: IMA_TO_PDF: output is mapped to CHAR3 ('DOC')
test_3 = SWITCH #( lv_content_type WHEN 'DOC' THEN 'DOC'
 WHEN 'PNG' THEN 'IMAGE' ) &amp;amp;&amp;amp; '_TO_PDF'.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Oct 2021 11:46:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/switch-statement-chaining-operator/m-p/12504867#M2003515</guid>
      <dc:creator>LaurensDeprost</dc:creator>
      <dc:date>2021-10-11T11:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: Switch statement + chaining operator &amp;&amp;</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/switch-statement-chaining-operator/m-p/12504868#M2003516</link>
      <description>&lt;P&gt;Hi Laurens, hi Jan,&lt;/P&gt;&lt;P&gt;thank you both! That makes sense. I was expecting, that the generic type gets specified, after the swtich is returning a value. Because I was also testing the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;test_5 = SWITCH #( lv_content_type WHEN 'DOC' THEN 5
                                   WHEN 'PNG' THEN 'IMAGE' ).
WRITE / test_5.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And this is creating test_5 as string, not as number. &lt;/P&gt;&lt;P&gt;As always, reading the documentation helps.&lt;/P&gt;&lt;P&gt;thanks &amp;amp; best Regards&lt;/P&gt;&lt;P&gt;Nico&lt;/P&gt;</description>
      <pubDate>Mon, 11 Oct 2021 12:19:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/switch-statement-chaining-operator/m-p/12504868#M2003516</guid>
      <dc:creator>nicorunge</dc:creator>
      <dc:date>2021-10-11T12:19:45Z</dc:date>
    </item>
  </channel>
</rss>

