<?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 Like ORACLE SQL SELECT in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-like-oracle-sql-select/m-p/6893280#M1480332</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Open SQL does not support using literals in the selection field list as you've tried in your first SQL statement. Also, your second SQL statement is wrong, since you need to do a [group by|http://help.sap.com/abapdocu_70/en/ABAPGROUPBY_CLAUSE.htm] if you use an aggregate function like &lt;EM&gt;sum&lt;/EM&gt; along with non-aggregated fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now in theory you could of course attempt to get around the Open SQL limitation by grabbing some arbitrary one-character and two character field (e.g. mara-lvorm and mara-zeivr) and select those along with the material number in your range table. After the select you could overwrite the dummy information with 'I' and 'EQ' using the [modify .. transporting|http://help.sap.com/abapdocu_70/en/ABAPMODIFY_ITAB_SINGLE.htm#!ABAP_ONE_ADD@1@] statement. But that's just for sake of completeness, you &lt;STRONG&gt;really don't want to do this&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's what I'd try: You did already a join on &lt;EM&gt;vbrk&lt;/EM&gt; and &lt;EM&gt;vbrp&lt;/EM&gt;, so why not join more than two tables?! Now, instead of using the tables that you've specified, I'd revert to the SD index table &lt;EM&gt;vrpma&lt;/EM&gt;, to allow efficient lookup's of billing documents by material number (and we're even lucky, because the &lt;EM&gt;fkdat&lt;/EM&gt; field is also present, so we can even skip &amp;lt;em&amp;gt;vbrk&amp;lt;/em&amp;gt;). Here's what I'd use:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
select VRPMA~VBELN VRPMA~FKDAT sum( VBRP~FKIMG ) into table ITAB1
       from MARA inner join VRPMA on
            VRPMA~MATNR = MARA~MATNR
       inner join VBRP on
            VBRP~VBELN = VRPMA~VBELN and
            VBRP~POSNR = VRPMA~POSNR
       where MARA~PRDHA  in R_PRDHA and
             VRPMA~FKDAT in R_FKDAT
       group by VRPMA~VBELN VRPMA~FKDAT.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please note that this is untested and you should actually validate that the results are correct. Note that under some circumstances the secondary index tables like &lt;EM&gt;vrpma&lt;/EM&gt; might not be correct (one cause could be for example poorly coded exits), but that should rarely be the case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By using the secondary index table and joining them all you allow the database to pick the best access path and ideally you actually end up with the best one... &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers, harald&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 13 May 2010 08:05:44 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-05-13T08:05:44Z</dc:date>
    <item>
      <title>Open SQL SELECT Like ORACLE SQL SELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-like-oracle-sql-select/m-p/6893277#M1480329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi experts,&lt;/P&gt;&lt;P&gt;how can i use 1st SQL is listed below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TABLES : T179, VBRK.&lt;/P&gt;&lt;P&gt;SELECT-OPTIONS : s_prdha FOR t179-prodh OBLIGATORY,&lt;/P&gt;&lt;P&gt;                 s_fkdat FOR vbrk-fkdat OBLIGATORY.&lt;/P&gt;&lt;P&gt;RANGES : R_MATNR FOR MARA-MATNR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;UL&gt;&lt;LI level="2" type="ul"&gt;&lt;P&gt;(1st SQL)***************************&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;P&gt;SELECT 'I' 'EQ' matnr&lt;/P&gt;&lt;P&gt;  INTO TABLE r_matnr FROM mara&lt;/P&gt;&lt;P&gt;  WHERE prdha IN s_prdha.&lt;/P&gt;&lt;P&gt;IF sy-subrc  = 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;UL&gt;&lt;LI level="2" type="ul"&gt;&lt;P&gt;(2nd SQL)**************************&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;P&gt;  SELECT vbrk&lt;SUB&gt;vbeln vbrk&lt;/SUB&gt;fkdat SUM( vbrp~fkimg )&lt;/P&gt;&lt;P&gt;    INTO TABLE itab1&lt;/P&gt;&lt;P&gt;    FROM vbrk AS vbrk&lt;/P&gt;&lt;P&gt;    INNER JOIN vbrp AS vbrp ON vbrk&lt;SUB&gt;vbeln = vbrp&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;    WHERE matnr IN r_matnr&lt;/P&gt;&lt;P&gt;    AND fkdat IN s_fkdat.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 May 2010 06:57:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-like-oracle-sql-select/m-p/6893277#M1480329</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-13T06:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Open SQL SELECT Like ORACLE SQL SELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-like-oracle-sql-select/m-p/6893278#M1480330</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think you construct this SELECT statement in Open SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alternatively you can try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;R_MATNR-SIGN = `I`.
R_MATNR-OPTION = `EQ`.

SELECT MATNR FROM MARA
INTO R_MATNR-LOW WHERE prdha IN s_prdha.

APPEND R_MATNR.

ENDSELECT.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Else:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA:
IT_MATNR TYPE STANDARD TABLE OF MATNR,
WA_MATNR TYPE MATNR.

SELECT MATNR INTO TABLE IT_MATNR WHERE prdha IN s_prdha.

CHECK SY-SUBRC = 0.

LOOP AT IT_MATNR INTO WA_MATNR.
  R_MATNR-SIGN = `I`.
  R_MATNR-OPTION = `EQ`.
  R_MATNR-LOW = WA_MATNR.
  APPEND R_MATNR.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 May 2010 07:13:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-like-oracle-sql-select/m-p/6893278#M1480330</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2010-05-13T07:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Open SQL SELECT Like ORACLE SQL SELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-like-oracle-sql-select/m-p/6893279#M1480331</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Suhas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't want to use select - endselect statement or a extra loop.&lt;/P&gt;&lt;P&gt;I know about the same, is there any other way???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for reply&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 May 2010 07:24:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-like-oracle-sql-select/m-p/6893279#M1480331</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-13T07:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: Open SQL SELECT Like ORACLE SQL SELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-like-oracle-sql-select/m-p/6893280#M1480332</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Open SQL does not support using literals in the selection field list as you've tried in your first SQL statement. Also, your second SQL statement is wrong, since you need to do a [group by|http://help.sap.com/abapdocu_70/en/ABAPGROUPBY_CLAUSE.htm] if you use an aggregate function like &lt;EM&gt;sum&lt;/EM&gt; along with non-aggregated fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now in theory you could of course attempt to get around the Open SQL limitation by grabbing some arbitrary one-character and two character field (e.g. mara-lvorm and mara-zeivr) and select those along with the material number in your range table. After the select you could overwrite the dummy information with 'I' and 'EQ' using the [modify .. transporting|http://help.sap.com/abapdocu_70/en/ABAPMODIFY_ITAB_SINGLE.htm#!ABAP_ONE_ADD@1@] statement. But that's just for sake of completeness, you &lt;STRONG&gt;really don't want to do this&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's what I'd try: You did already a join on &lt;EM&gt;vbrk&lt;/EM&gt; and &lt;EM&gt;vbrp&lt;/EM&gt;, so why not join more than two tables?! Now, instead of using the tables that you've specified, I'd revert to the SD index table &lt;EM&gt;vrpma&lt;/EM&gt;, to allow efficient lookup's of billing documents by material number (and we're even lucky, because the &lt;EM&gt;fkdat&lt;/EM&gt; field is also present, so we can even skip &amp;lt;em&amp;gt;vbrk&amp;lt;/em&amp;gt;). Here's what I'd use:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
select VRPMA~VBELN VRPMA~FKDAT sum( VBRP~FKIMG ) into table ITAB1
       from MARA inner join VRPMA on
            VRPMA~MATNR = MARA~MATNR
       inner join VBRP on
            VBRP~VBELN = VRPMA~VBELN and
            VBRP~POSNR = VRPMA~POSNR
       where MARA~PRDHA  in R_PRDHA and
             VRPMA~FKDAT in R_FKDAT
       group by VRPMA~VBELN VRPMA~FKDAT.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please note that this is untested and you should actually validate that the results are correct. Note that under some circumstances the secondary index tables like &lt;EM&gt;vrpma&lt;/EM&gt; might not be correct (one cause could be for example poorly coded exits), but that should rarely be the case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By using the secondary index table and joining them all you allow the database to pick the best access path and ideally you actually end up with the best one... &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers, harald&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 May 2010 08:05:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-like-oracle-sql-select/m-p/6893280#M1480332</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-13T08:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: Open SQL SELECT Like ORACLE SQL SELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-like-oracle-sql-select/m-p/6893281#M1480333</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Harald provide very useful details about message.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 May 2010 11:10:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/open-sql-select-like-oracle-sql-select/m-p/6893281#M1480333</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-13T11:10:45Z</dc:date>
    </item>
  </channel>
</rss>

