<?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: How to execute a select query which is present in a string. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-execute-a-select-query-which-is-present-in-a-string/m-p/4979375#M1160359</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Aslam&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use parts of the string and use it some thing similar to below snippet:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;PARAMETERS: carr_id TYPE spfli-carrid,
 conn_id TYPE spfli-connid.
 
DATA: where_clause TYPE STRING,
 and(4),
 wa_spfli TYPE spfli.
 
IF carr_id IS NOT INITIAL.
 CONCATENATE 'CARRID = ''' carr_id '''' INTO where_clause.
 and = ' AND'.
ENDIF.
IF conn_id IS NOT INITIAL.
 CONCATENATE where_clause and ' CONNID = ''' conn_id ''''
 INTO where_clause.
ENDIF.
SELECT * FROM spfli INTO wa_spfli WHERE (where_clause).
 WRITE: / wa_spfli-carrid, wa_spfli-connid, wa_spfli-cityfrom,
 wa_spfli-cityto, wa_spfli-deptime.
ENDSELECT.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 01 Jan 2009 16:18:53 GMT</pubDate>
    <dc:creator>former_member156446</dc:creator>
    <dc:date>2009-01-01T16:18:53Z</dc:date>
    <item>
      <title>How to execute a select query which is present in a string.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-execute-a-select-query-which-is-present-in-a-string/m-p/4979371#M1160355</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;&lt;/P&gt;&lt;P&gt;I am having string variable. This String Variable is holding a simple SELECT QUERY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For Example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;String qry.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;qry = select * into i_table from vbak.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now i want this query inside this string to be executed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any Functional Module or Is there any other way by which I can achieve this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in Advance.&lt;/P&gt;&lt;P&gt;Aslam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jan 2009 10:51:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-execute-a-select-query-which-is-present-in-a-string/m-p/4979371#M1160355</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-01T10:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a select query which is present in a string.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-execute-a-select-query-which-is-present-in-a-string/m-p/4979372#M1160356</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As of my knowledge you cannot execute the string which contains the select query...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead you can have the where clause in the variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select * into i_table from vbak where &amp;lt;var&amp;gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jan 2009 10:58:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-execute-a-select-query-which-is-present-in-a-string/m-p/4979372#M1160356</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-01T10:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a select query which is present in a string.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-execute-a-select-query-which-is-present-in-a-string/m-p/4979373#M1160357</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can do it other way. Please check the sample code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES : BEGIN OF x_marc,&lt;/P&gt;&lt;P&gt;        matnr TYPE matnr,&lt;/P&gt;&lt;P&gt;        werks TYPE werks_d,&lt;/P&gt;&lt;P&gt;       END OF x_marc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: i_marc TYPE STANDARD TABLE OF x_marc,&lt;/P&gt;&lt;P&gt;      l_marc TYPE char40 VALUE 'MARC'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: l_field TYPE STANDARD TABLE OF string,&lt;/P&gt;&lt;P&gt;      l_where TYPE STANDARD TABLE OF string,&lt;/P&gt;&lt;P&gt;      wa_field TYPE string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PARAMETERS: p_matnr TYPE matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa_field = 'MATNR'.&lt;/P&gt;&lt;P&gt;APPEND wa_field TO l_field.&lt;/P&gt;&lt;P&gt;CLEAR: wa_field.&lt;/P&gt;&lt;P&gt;wa_field = 'WERKS'.&lt;/P&gt;&lt;P&gt;APPEND wa_field TO l_field.&lt;/P&gt;&lt;P&gt;CLEAR: wa_field.&lt;/P&gt;&lt;P&gt;wa_field = 'MATNR = P_MATNR'.&lt;/P&gt;&lt;P&gt;APPEND wa_field TO l_where.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT (l_field) FROM (l_marc)&lt;/P&gt;&lt;P&gt;  INTO TABLE i_marc WHERE (l_where).&lt;/P&gt;&lt;P&gt;IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You put the select part in a perform. Use can use it as function module.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jan 2009 11:11:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-execute-a-select-query-which-is-present-in-a-string/m-p/4979373#M1160357</guid>
      <dc:creator>Subhankar</dc:creator>
      <dc:date>2009-01-01T11:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a select query which is present in a string.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-execute-a-select-query-which-is-present-in-a-string/m-p/4979374#M1160358</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. we can declare types dynamically&lt;/P&gt;&lt;P&gt;2. Internal table dynamically&lt;/P&gt;&lt;P&gt;3. Select querry dynamically&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;just copy paste this code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the code for your question&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA:v_fieldname&lt;/P&gt;&lt;P&gt;TYPE fieldname,&lt;/P&gt;&lt;P&gt;l_PROG TYPE string,&lt;/P&gt;&lt;P&gt;v_mess TYPE string,&lt;/P&gt;&lt;P&gt;l_sid TYPE string,&lt;/P&gt;&lt;P&gt;wa_ddfields TYPE dntab.&lt;/P&gt;&lt;P&gt;DATA i_tab TYPE STANDARD TABLE OF string.&lt;/P&gt;&lt;P&gt;DATA:l_str TYPE string,&lt;/P&gt;&lt;P&gt;l_str1 TYPE string.&lt;/P&gt;&lt;P&gt;PARAMETERS matnr type marc-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;end-of-SELECTION.&lt;/P&gt;&lt;P&gt;*build the subroutine pool&lt;/P&gt;&lt;P&gt;APPEND 'PROGRAM subpool.' TO i_tab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND `LOAD-OF-PROGRAM.` TO i_tab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND `DATA i_tab1 TYPE TABLE OF vbak.`      TO i_tab.&lt;/P&gt;&lt;P&gt;APPEND `DATA l_rows TYPE i.`      TO i_tab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND `select * into table i_tab1 from vbak.` To i_tab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;append 'DESCRIBE TABLE i_tab1 LINES l_rows.' to i_tab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;append 'Write :  l_rows .' to i_tab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;GENERATE SUBROUTINE POOL i_tab NAME l_PROG&lt;/P&gt;&lt;P&gt;MESSAGE v_mess&lt;/P&gt;&lt;P&gt;SHORTDUMP-ID l_sid.&lt;/P&gt;&lt;P&gt;IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;PERFORM ('LOOP_AT_TAB') IN PROGRAM (l_PROG) IF FOUND.&lt;/P&gt;&lt;P&gt;ELSEIF sy-subrc = 4.&lt;/P&gt;&lt;P&gt;MESSAGE v_mess TYPE 'I'.&lt;/P&gt;&lt;P&gt;ELSEIF sy-subrc = 8.&lt;/P&gt;&lt;P&gt;MESSAGE l_sid TYPE 'I'.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: vijay wankhade on Jan 1, 2009 5:34 PM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: vijay wankhade on Jan 1, 2009 5:34 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jan 2009 16:09:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-execute-a-select-query-which-is-present-in-a-string/m-p/4979374#M1160358</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-01T16:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a select query which is present in a string.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-execute-a-select-query-which-is-present-in-a-string/m-p/4979375#M1160359</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Aslam&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use parts of the string and use it some thing similar to below snippet:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;PARAMETERS: carr_id TYPE spfli-carrid,
 conn_id TYPE spfli-connid.
 
DATA: where_clause TYPE STRING,
 and(4),
 wa_spfli TYPE spfli.
 
IF carr_id IS NOT INITIAL.
 CONCATENATE 'CARRID = ''' carr_id '''' INTO where_clause.
 and = ' AND'.
ENDIF.
IF conn_id IS NOT INITIAL.
 CONCATENATE where_clause and ' CONNID = ''' conn_id ''''
 INTO where_clause.
ENDIF.
SELECT * FROM spfli INTO wa_spfli WHERE (where_clause).
 WRITE: / wa_spfli-carrid, wa_spfli-connid, wa_spfli-cityfrom,
 wa_spfli-cityto, wa_spfli-deptime.
ENDSELECT.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jan 2009 16:18:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-execute-a-select-query-which-is-present-in-a-string/m-p/4979375#M1160359</guid>
      <dc:creator>former_member156446</dc:creator>
      <dc:date>2009-01-01T16:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a select query which is present in a string.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-execute-a-select-query-which-is-present-in-a-string/m-p/4979376#M1160360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you can execute select querry in string also.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jan 2009 16:36:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-execute-a-select-query-which-is-present-in-a-string/m-p/4979376#M1160360</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-01T16:36:28Z</dc:date>
    </item>
  </channel>
</rss>

