Application Development and Automation 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: 
Read only

Select Query

Former Member
0 Likes
566

Hi,

I want to select a field from a database table where the field name will be mentioned only at runtime.

How to write it?

Please help me,

Regards,

Arunsri.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
548

i

Edited by: saslove sap on Mar 27, 2008 12:49 PM

5 REPLIES 5
Read only

Former Member
0 Likes
548

hi check this ...

code

DATA: itab TYPE STANDARD TABLE OF mara.

DATA: wa TYPE mara.

DATA: where(72).

DATA: where1(72).

Populate.

wa-matnr = 'TEST'.

wa-mtart = 'M1'.

APPEND wa TO itab.

Where clause

where = 'MATNR'.

where1 = 'MTART'.

READ TABLE itab INTO wa WITH KEY (WHERE) = 'TEST'

(WHERE1) = 'M1'.

IF sy-subrc = 0.

WRITE: / 'found'.

ENDIF.

[/code]

regards,

venkat.

Read only

Former Member
0 Likes
548

SELECT (FIELD_NAME) INTO L_FIELD

FROM DB_TABLE

WHERE ....

FIELD_NAME IS A VARIABLE (CHAR 30) where you put your field name

Example

FIELD_NAME = 'LIFNR'

SELECT (FIELD_NAME) from LFA1 WHERE ...

Read only

Former Member
0 Likes
549

i

Edited by: saslove sap on Mar 27, 2008 12:49 PM

Read only

0 Likes
548

Hi

You can do this by the following method.

tables: mara.

data: temp type char20 value 'MATNR MTART'.

select (temp)

into CORRESPONDING FIELDS OF MARA

from mara up to 10 rows

WHERE MTART EQ 'FERT'.

write 😕 MARA-MATNR, mara-MTART.

endselect.

Read only

Former Member
0 Likes
548

hI ,

SEE THE EXAMPLE CODE.

SELECT QUERY CONDITION VARY ACCORDING TO RADIO BUTTON SELECTED.

if r1 = 'X'.
    concatenate   'fkdat IN fkdat'
                  ' and werks = werks'
                  ' and erdat in gdate'
                  ' and fksto = space'
                  into cond.
  elseif r2 = 'X'.
    concatenate 'gexno NE space'
                ' AND fkdat IN fkdat'
                ' AND werks = werks'
                ' and erdat in gdate'
                ' AND xblnr EQ space'
                ' AND fksto = space'
                into cond.
  elseif r3 = 'X'.
    concatenate ' fkdat IN fkdat'
                ' and werks = werks'
                ' and updat <= keydat'
                ' and fksto = space'
                into cond.
  elseif r4 = 'X'.
    concatenate ' fkdat IN fkdat'
                ' and werks = werks'
                ' and updat <= keydat'
                ' and fksto = space'
                into cond.

  endif.


  select * from zged into corresponding fields of table itab
                              where (cond)
                                    order by vbeln posnr fkdat.

Regards,

Morris Bond.

Reward Points if helpful.