Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic fields in select statement

Former Member
0 Kudos

Hi all,

In selection screen we are having period as select option.The values for period are 01 to 16. Based on

the values entered in selection screen for period we need to select HSLXX from FAGLFLEXT.

For example if we enter 01 to 03 in selection screen then we need to select HSL01 HSL02 HSL03

from FAGLFLEXT.

Like this we need to select fields dynamically in select statement. Can any one tell me how to restrict fields dynamically.

Regards,

Swetha

1 ACCEPTED SOLUTION

asik_shameem
Active Contributor
0 Kudos

Hi Swetha,

Look at this thread and the Same Topic is discussed.

https://forums.sdn.sap.com/click.jspa?searchID=24510876&messageID=6133607

2 REPLIES 2

asik_shameem
Active Contributor
0 Kudos

Hi Swetha,

Look at this thread and the Same Topic is discussed.

https://forums.sdn.sap.com/click.jspa?searchID=24510876&messageID=6133607

Former Member

hi Swetha,

the third select statemnet will work for you..

try this..


_Dynamic where clause in select query.._

* 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.

_Using a dynamic table name_

parameters:
 p_tab type tabname.

start-of-selection.
  select count(*) from (p_tab) into l_count.


_Dynamic retrieval and writing of data_

FIELD-SYMBOLS:
  <row>         TYPE ANY,
  <component>   TYPE ANY.

PARAMETERS:
 p_tab TYPE tabname.
 CREATE DATA dataref TYPE (p_tab).

* The variable dataref cannot be accessed directly, so a field symbol is
* used
  ASSIGN dataref->* TO <row>.

  SELECT *
    FROM (p_tab) UP TO 10 ROWS
    INTO <row>.


    NEW-LINE.
    DO.
*     Write all the fields in the record    
      ASSIGN COMPONENT sy-index
        OF STRUCTURE <row>
        TO <component>.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
      WRITE <component>.
    ENDDO.
  ENDSELECT.

Regards,

Prabhduas