<?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: parameter probleam in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409954#M1242322</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nayar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;see the below examples and write as wish&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
Dynamic where clause
You can use an internal table to build a dynamic where clause:

data: where_tab(30) occurs 1 with header line,                      
         where_clause(30) type c.                                      

* Build the where clause. Will look like this when finished
* WHERE ZAFSTMD02 = 'X' AND rbusa = '5145'

* With a constant, result: ZAFSTMD01 = 'X'
concatenate 'ZAFSTMD' zcostcheck-zmaaned  ' = ''X'''  into where_clause.                               

* Append to internal table where_tab
append where_clause to where_tab.                                   

* With a variable, result: AND rbusa = '5145'
concatenate 'AND rbusa = '  ''''  i_tab-zgsber  ''''
append where_clause to where_tab.                                   

* Select
select * from zcostfreq                                            
     where (where_tab).                                               
endselect.                                                         
        
Note that you can combine static and dynamic where clauses:

select * from zcostfreq                                            

     where bukrs = '2021' AND
                              (where_tab).                                               
endselect.                                       
 

 

Using a dynamic table name
This report prints the number og entries in a table. The table name is specified by a parameter.


data:
  l_count type i.

parameters:
 p_tab type tabname.

start-of-selection.
  select count(*) from (p_tab) into l_count.
  write: / 'Number of entries in table ', p_tab, l_count.
 

Dynamic retrieval and writing of data
In this example, data is retrieved from the table selected on the selection screen, and the contents of the table is written to the screen.


DATA:
* Create variable that can contain referecene to any data
  dataref TYPE REF TO data.


FIELD-SYMBOLS:
  &amp;lt;row&amp;gt;         TYPE ANY,
  &amp;lt;component&amp;gt;   TYPE ANY.

PARAMETERS:
 p_tab TYPE tabname.



START-OF-SELECTION.
* Create a workarea for the tabel selected on the selection screen

  CREATE DATA dataref TYPE (p_tab).

* The variable dataref cannot be accessed directly, so a field symbol is
* used
  ASSIGN dataref-&amp;gt;* TO &amp;lt;row&amp;gt;.

  SELECT *
    FROM (p_tab) UP TO 10 ROWS
    INTO &amp;lt;row&amp;gt;.

    NEW-LINE.
    DO.
*     Write all the fields in the record    
      ASSIGN COMPONENT sy-index
        OF STRUCTURE &amp;lt;row&amp;gt;
        TO &amp;lt;component&amp;gt;.
      IF sy-subrc &amp;lt;&amp;gt; 0.
        EXIT.
      ENDIF.
      WRITE &amp;lt;component&amp;gt;.
    ENDDO.
  ENDSELECT.
 

Dynamic SELECT 
 

TYPES:
  BEGIN OF st_bseg,
    bukrs LIKE bseg-bukrs,
    belnr LIKE bseg-belnr,
    dmbtr LIKE bseg-dmbtr,
  END OF st_bseg.

DATA:
  sel_list   TYPE STANDARD TABLE OF edpline,
  li_bseg    TYPE STANDARD TABLE OF st_bseg,
  l_bseg     TYPE st_bseg.


START-OF-SELECTION.
  APPEND 'bukrs belnr dmbtr' TO sel_list.

  SELECT (sel_list)
    FROM bseg  UP TO 100 ROWS
    INTO TABLE li_bseg.

  LOOP AT li_bseg INTO l_bseg.
    WRITE : / l_bseg-bukrs, l_bseg-belnr, l_bseg-dmbtr.

  ENDLOOP.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Prabhudas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 02 Apr 2009 13:41:03 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-04-02T13:41:03Z</dc:date>
    <item>
      <title>parameter probleam</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409944#M1242312</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;when user enters the any fieldname from MARC table related , the only that field descrption &lt;/P&gt;&lt;P&gt;should come in WE variable in selection screen.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if no field existing in MARC , then error message will come..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can somebody give the logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;selection-screen begin of line.&lt;/P&gt;&lt;P&gt;parameters:p_selec1 like dd02l-tabname ,&lt;/P&gt;&lt;P&gt;            we(200).&lt;/P&gt;&lt;P&gt;selection-screen end of line.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Mar 2009 10:43:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409944#M1242312</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-25T10:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: parameter probleam</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409945#M1242313</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;Check this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TABLES:dd03l.
PARAMETERS:p_fname TYPE fieldname.

AT SELECTION-SCREEN.
  SELECT SINGLE * FROM dd03l WHERE tabname = 'MARC' AND fieldname = p_fname.
  IF sy-subrc NE 0.
    MESSAGE E016(rp) WITH 'Enter Proper Field'.
  ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Mar 2009 11:01:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409945#M1242313</guid>
      <dc:creator>former_member188829</dc:creator>
      <dc:date>2009-03-25T11:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: parameter probleam</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409946#M1242314</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can set the values in AT SELECTION-SCREEN EVENT.&lt;/P&gt;&lt;P&gt;If you press enter the vent will be execute and values will be changed &lt;/P&gt;&lt;P&gt;Or use SY-ucomm = 'ONLI'  --&amp;gt;F8&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;parameters:p_selec1 like dd02l-tabname ,
we(200).
selection-screen end of line.

at selection-screen.
Select query.                             " If you press enter
IF SY-SUBRC NE 0.                  " No records present
we = 'ERROR'
ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Gurpreet&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Mar 2009 11:03:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409946#M1242314</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-25T11:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: parameter probleam</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409947#M1242315</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;use thuis.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AT SELECTION-SCREEN on parametere.&lt;/P&gt;&lt;P&gt;  SELECT SINGLE field  FROM dd03l WHERE tabname = 'MARC' AND fieldname = p_fname.&lt;/P&gt;&lt;P&gt;  IF sy-subrc NE 0.&lt;/P&gt;&lt;P&gt;    MESSAGE 'No record found '. type 'E'.&lt;/P&gt;&lt;P&gt;  ENDIF&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Mar 2009 10:19:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409947#M1242315</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-26T10:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: parameter probleam</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409948#M1242316</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;Try this way...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:p_selec1 LIKE dd03l-fieldname ,
we(200).
SELECTION-SCREEN END OF LINE.


AT SELECTION-SCREEN .
* Write the logic to fetch the data into we varaible if we is inital show the error message
WE = 'Test'.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Mar 2009 18:33:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409948#M1242316</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-26T18:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: parameter probleam</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409949#M1242317</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;Hi, try this one.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;TABLES : dd03l.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA : v_fieldname type fieldname.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA : v_ddtext type as4text.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PARAMETERS : p_fname TYPE fieldname user-command com .&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;parameters : WE(200) type c.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AT SELECTION-SCREEN.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;  &lt;STRONG&gt;SELECT SINGLE fieldname  FROM dd03l&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;              &lt;STRONG&gt;into v_fieldname&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;             &lt;STRONG&gt;WHERE tabname = 'MARC' AND fieldname = p_fname.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;  &lt;STRONG&gt;IF sy-subrc NE 0.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;    &lt;STRONG&gt;MESSAGE E000(sd)  WITH 'Enter Proper Field'.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;  &lt;STRONG&gt;else.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;     &lt;STRONG&gt;select single ddtext from DD03t&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;                &lt;STRONG&gt;into v_ddtext&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;                &lt;STRONG&gt;where tabname = 'MARC'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;                &lt;STRONG&gt;and fieldname = p_fname&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;                &lt;STRONG&gt;and ddlanguage = 'EN'.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  &lt;STRONG&gt;endif.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;at selection-screen output.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;     &lt;STRONG&gt;we = v_ddtext.&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Mar 2009 10:41:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409949#M1242317</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-27T10:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: parameter probleam</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409950#M1242318</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Let me know if this works or not.&lt;/P&gt;&lt;P&gt;Thanks..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Mar 2009 10:43:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409950#M1242318</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-27T10:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: parameter probleam</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409951#M1242319</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;AT SELECTION-SCREEN on p_field1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT SINGLE field1 FROM dd03l &lt;/P&gt;&lt;P&gt;     INTO l_field1&lt;/P&gt;&lt;P&gt;WHERE tabname = 'MARC' AND fieldname = p_field1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF sy-subrc NE 0.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Error Message*&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Joan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Apr 2009 10:03:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409951#M1242319</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-02T10:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: parameter probleam</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409952#M1242320</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;SELECTION-SCREEN BEGIN OF LINE.&lt;/P&gt;&lt;P&gt;PARAMETERS: p_matnr TYPE MARC-MATNR OBLIGATORY.&lt;/P&gt;&lt;P&gt;SELECTION-SCREEN END OF LINE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AT SELECTION-SCREEN ON p_matnr.&lt;/P&gt;&lt;P&gt;   DATA:l_aaaaa TYPE MARC-MATNR .&lt;/P&gt;&lt;P&gt;  CLEAR l_aaaa.&lt;/P&gt;&lt;P&gt;  SELECT SINGLE MATNR &lt;/P&gt;&lt;P&gt;    INTO l_werks&lt;/P&gt;&lt;P&gt;   FROM MARC&lt;/P&gt;&lt;P&gt;   WHERE MARC = p_matnr &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF sy-subrc NE 0.&lt;/P&gt;&lt;P&gt;    MESSAGE e208(00) WITH 'E03: Invalid entry'(e03).&lt;/P&gt;&lt;P&gt;  ENDIF.                               " IF sy-subrc NE 0.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Apr 2009 13:18:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409952#M1242320</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-02T13:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: parameter probleam</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409953#M1242321</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; Try this code. I hope it can solve ur req.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TABLES:dd03l.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PARAMETERS:p_fname TYPE fieldname.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : lv_field type char300.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AT SELECTION-SCREEN.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SELECT SINGLE * FROM dd03l into lv_field&lt;/P&gt;&lt;P&gt;    WHERE tabname = 'MARC'&lt;/P&gt;&lt;P&gt;    AND fieldname = p_fname.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF sy-subrc NE 0.&lt;/P&gt;&lt;P&gt;    MESSAGE E001(0) WITH 'Enter Proper Field'.&lt;/P&gt;&lt;P&gt;    ELSE.&lt;/P&gt;&lt;P&gt;    MESSAGE S001(0) WITH 'Field exists'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Apr 2009 13:37:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409953#M1242321</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-02T13:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: parameter probleam</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409954#M1242322</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nayar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;see the below examples and write as wish&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
Dynamic where clause
You can use an internal table to build a dynamic where clause:

data: where_tab(30) occurs 1 with header line,                      
         where_clause(30) type c.                                      

* Build the where clause. Will look like this when finished
* WHERE ZAFSTMD02 = 'X' AND rbusa = '5145'

* With a constant, result: ZAFSTMD01 = 'X'
concatenate 'ZAFSTMD' zcostcheck-zmaaned  ' = ''X'''  into where_clause.                               

* Append to internal table where_tab
append where_clause to where_tab.                                   

* With a variable, result: AND rbusa = '5145'
concatenate 'AND rbusa = '  ''''  i_tab-zgsber  ''''
append where_clause to where_tab.                                   

* Select
select * from zcostfreq                                            
     where (where_tab).                                               
endselect.                                                         
        
Note that you can combine static and dynamic where clauses:

select * from zcostfreq                                            

     where bukrs = '2021' AND
                              (where_tab).                                               
endselect.                                       
 

 

Using a dynamic table name
This report prints the number og entries in a table. The table name is specified by a parameter.


data:
  l_count type i.

parameters:
 p_tab type tabname.

start-of-selection.
  select count(*) from (p_tab) into l_count.
  write: / 'Number of entries in table ', p_tab, l_count.
 

Dynamic retrieval and writing of data
In this example, data is retrieved from the table selected on the selection screen, and the contents of the table is written to the screen.


DATA:
* Create variable that can contain referecene to any data
  dataref TYPE REF TO data.


FIELD-SYMBOLS:
  &amp;lt;row&amp;gt;         TYPE ANY,
  &amp;lt;component&amp;gt;   TYPE ANY.

PARAMETERS:
 p_tab TYPE tabname.



START-OF-SELECTION.
* Create a workarea for the tabel selected on the selection screen

  CREATE DATA dataref TYPE (p_tab).

* The variable dataref cannot be accessed directly, so a field symbol is
* used
  ASSIGN dataref-&amp;gt;* TO &amp;lt;row&amp;gt;.

  SELECT *
    FROM (p_tab) UP TO 10 ROWS
    INTO &amp;lt;row&amp;gt;.

    NEW-LINE.
    DO.
*     Write all the fields in the record    
      ASSIGN COMPONENT sy-index
        OF STRUCTURE &amp;lt;row&amp;gt;
        TO &amp;lt;component&amp;gt;.
      IF sy-subrc &amp;lt;&amp;gt; 0.
        EXIT.
      ENDIF.
      WRITE &amp;lt;component&amp;gt;.
    ENDDO.
  ENDSELECT.
 

Dynamic SELECT 
 

TYPES:
  BEGIN OF st_bseg,
    bukrs LIKE bseg-bukrs,
    belnr LIKE bseg-belnr,
    dmbtr LIKE bseg-dmbtr,
  END OF st_bseg.

DATA:
  sel_list   TYPE STANDARD TABLE OF edpline,
  li_bseg    TYPE STANDARD TABLE OF st_bseg,
  l_bseg     TYPE st_bseg.


START-OF-SELECTION.
  APPEND 'bukrs belnr dmbtr' TO sel_list.

  SELECT (sel_list)
    FROM bseg  UP TO 100 ROWS
    INTO TABLE li_bseg.

  LOOP AT li_bseg INTO l_bseg.
    WRITE : / l_bseg-bukrs, l_bseg-belnr, l_bseg-dmbtr.

  ENDLOOP.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Prabhudas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Apr 2009 13:41:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409954#M1242322</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-02T13:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: parameter probleam</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409955#M1242323</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;Try this...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: D_TYPE,
D_FIELD(35).
DATA: D_TEST TYPE P.
FIELD-SYMBOLS: &amp;lt;F&amp;gt;.
D_FIELD = 'D_TEST'.
D_TYPE = 'P'.
ASSIGN (D_FIELD) TO &amp;lt;F&amp;gt; TYPE D_TYPE.


Additionally you can use the option DECIMALS of the ASSIGN statement if your type is 'P'. You can even change the type at runtime of previously assigned field symbol like

ASSIGN &amp;lt;F&amp;gt; TO &amp;lt;F&amp;gt; TYPE 'C'.

One more thing for dynamic programing. With the following coding you can access every DDIC table with the key you want:


SELECT SINGLE * FROM (DF_TNAME) INTO S_TMP WHERE (IF_KEY).
if sy-subrc ne 0.
message 'Wrong input' type 'E'.
endif.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Prabhudas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Apr 2009 13:43:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/parameter-probleam/m-p/5409955#M1242323</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-02T13:43:13Z</dc:date>
    </item>
  </channel>
</rss>

