<?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: Open SQL: SELECT with dynamic field list in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-with-dynamic-field-list/m-p/12020865#M1967711</link>
    <description>&lt;P&gt;I was quite sure I've already tried it, but probably when I did I made some more mistakes somewhere else...&lt;/P&gt;&lt;P&gt;Of course it works and of course thak for your help!&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jul 2019 13:20:18 GMT</pubDate>
    <dc:creator>deca</dc:creator>
    <dc:date>2019-07-31T13:20:18Z</dc:date>
    <item>
      <title>Open SQL: SELECT with dynamic field list</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-with-dynamic-field-list/m-p/12020863#M1967709</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
  &lt;P&gt;I have to write a SELECT with a dynamic list of fields. I did it several times using traditional SELECT command:&lt;/P&gt;
  &lt;P&gt;&lt;EM&gt;Traditional SELECT&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;DATA: lv_fields TYPE string.
SELECT SINGLE (lv_fields)
         FROM mara
         INTO ls_mara
        WHERE matnr = lv_matnr.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;I wish to write the same select with the new syntax (in this case I'm working on 7.52 but I still have customer with previous releases), something like this:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF ty_mara,
         matnr TYPE mara-matnr,
         laeda TYPE mara-laeda,
         pstat TYPE mara-pstat,
         mbrsh TYPE mara-mbrsh,
       END OF ty_mara.
DATA: lt_mara   TYPE STANDARD TABLE OF ty_mara.
DATA: lv_fields TYPE char1024.

* LV_FIELDS is the result of a routine, I show here as static variable 
* only for sample purpose
lv_fields = 'MATNR, LAEDA, PSTAT, MBRSH'.

SELECT @lv_fields
       FROM mara
       INTO TABLE @lt_mara
      WHERE matnr IN @s_matnr.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;This code is ok for syntax check, but if you run it, table LT_MARA is like this:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;--------------------------------------------------------
|MATNR                      | LAEDA    | PSTAT | MBRSH |
--------------------------------------------------------
|MATNR, LAEDA, PSTAT, MBRSH | 00000000 |       |       |
|MATNR, LAEDA, PSTAT, MBRSH | 00000000 |       |       |
|MATNR, LAEDA, PSTAT, MBRSH | 00000000 |       |       |
|MATNR, LAEDA, PSTAT, MBRSH | 00000000 |       |       |
|MATNR, LAEDA, PSTAT, MBRSH | 00000000 |       |       |
|MATNR, LAEDA, PSTAT, MBRSH | 00000000 |       |       |
|MATNR, LAEDA, PSTAT, MBRSH | 00000000 |       |       |
|MATNR, LAEDA, PSTAT, MBRSH | 00000000 |       |       |
--------------------------------------------------------&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;(as many rows as record in MARA that should be read according to WHERE condition)&lt;/P&gt;
  &lt;P&gt;As you can imagine, this result is not ok for me &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
  &lt;P&gt;How could I solve this matter?&lt;/P&gt;
  &lt;P&gt;Thank you and best regards!&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 09:17:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-with-dynamic-field-list/m-p/12020863#M1967709</guid>
      <dc:creator>deca</dc:creator>
      <dc:date>2019-07-31T09:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: Open SQL: SELECT with dynamic field list</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-with-dynamic-field-list/m-p/12020864#M1967710</link>
      <description>&lt;P&gt;Instead of @ use parenthesis like in the old syntax:  &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT (lv_fields)
       FROM mara
       INTO TABLE @lt_mara
      WHERE matnr IN @s_matnr.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Escaping a variable/constant in the column list is used when you want to fill a specific field of every line in the result set with the value of the object.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 10:18:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-with-dynamic-field-list/m-p/12020864#M1967710</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-07-31T10:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Open SQL: SELECT with dynamic field list</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-with-dynamic-field-list/m-p/12020865#M1967711</link>
      <description>&lt;P&gt;I was quite sure I've already tried it, but probably when I did I made some more mistakes somewhere else...&lt;/P&gt;&lt;P&gt;Of course it works and of course thak for your help!&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 13:20:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-with-dynamic-field-list/m-p/12020865#M1967711</guid>
      <dc:creator>deca</dc:creator>
      <dc:date>2019-07-31T13:20:18Z</dc:date>
    </item>
  </channel>
</rss>

