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: 

Select Statement

Former Member
0 Kudos

In select Statement i want to put table name and field name as variables

please reply

1 ACCEPTED SOLUTION

former_member188685
Active Contributor
0 Kudos

Hi Umesh,

check this sample..

REPORT  ZTEST_DYNAMIC  no standard page heading                         .


parameters: tabl type DD03L-tabname,
            fld type dd03l-FIELDNAME.

data: begin of itab occurs 0,
       char(20),
      end of itab.

start-of-selection.

         select (fld)
              into table itab
              from (tabl).
              if sy-subrc = 0.

              endif.
end-of-selection.
write: tabl.
write:/ fld.
loop at itab.

write: / ITAB-char.

endloop.

Regards

vijay

9 REPLIES 9

suresh_datti
Active Contributor
0 Kudos

try

select (fld1) (fld2) from (table)

into (w_fld1,w_fld2).

Regards,

Suresh Datti

I could pass the table name to the variable but the field names had to be specified.. the above statement did not work..

Message was edited by: Suresh Datti

Former Member
0 Kudos

Hi umesh,

1. we can do like this for table name.

2.

report abc.

data : tabname(30) type c.

data : itab like table of t001 with header line.

*----


tabname = 'T001'.

select *

from (tabname)

into table itab.

break-point.

regards,

amit m.

Former Member
0 Kudos

Hi Umesh,

Please check the below select :

SELECT * FROM (V_TABLE) INTO WORK WHERE (OPTIONS).

Concatenate where condition into options.

Thanks&Regards,

Siri.

Former Member
0 Kudos
chk this prog

REPORT ychatest.

PARAMETERS : p_tabnam LIKE dd03l-tabname.

DATA : v_tbname LIKE dd03l-tabname.


SELECT tabname FROM (p_tabnam) INTO v_tbname UP TO 1 ROWS.
ENDSELECT.

WRITE : v_tbname.

Former Member
0 Kudos

Hai Umesh

Check with the link

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/select.htm

select field1

field2

from table1

into internal Table

where <Condition>.

Regards

Sreeni

former_member188685
Active Contributor
0 Kudos

Hi Umesh,

check this sample..

REPORT  ZTEST_DYNAMIC  no standard page heading                         .


parameters: tabl type DD03L-tabname,
            fld type dd03l-FIELDNAME.

data: begin of itab occurs 0,
       char(20),
      end of itab.

start-of-selection.

         select (fld)
              into table itab
              from (tabl).
              if sy-subrc = 0.

              endif.
end-of-selection.
write: tabl.
write:/ fld.
loop at itab.

write: / ITAB-char.

endloop.

Regards

vijay

Former Member
0 Kudos

I agree with Amit, but want to make slight changes..

The code should be like this

tables: MARA.

data: v_fields(100) type c,

v_ftable(30) type c,

v_ttable(30) type c,

v_where(255) type c.

Data: begin of i_makt occurs 0,

matnr like mara-matnr,

maktx like makt-maktx,

end of i_makt.

SELECT-OPTIONS S_MATNR for MARA-MATNR.

v_fields = 'MATNR MAKTX'.

V_FTABLE = 'MAKT'.

V_TTABLE = 'I_MAKT'.

V_WHERE = 'MATNR in S_MATNR'.

select (v_fields)

into table (v_ttable)

from (v_ftable)

where (v_where).

Regds

Sandip

Message was edited by: Sandip Kamdar

Former Member
0 Kudos

Hi Umesh,

Welcome to SDN...........

Select statement with table name and field name as variables is possible. This is nothing but dynamic nature providing to field names and table name.

The dynamic naturre is provided with the help of <b>( )</b> [braces). The select statement will intrepet the values in () are of field names and table name. You can query select statement with dynamic fields or with dynamic tables or with both.

The syntax for this as follows::

<b>select (field1) (field2) (field3)

from (table name)

into <internal table>.</b>

Plz be careful while passing values to these field names and table name otherwise it will gives improper results.

Thanks,

Vinay

Note: plz award points to all helpful answers and close the thread if it is solved.