‎2007 Jan 19 7:48 AM
Hi Gurus,
I have to select records from <TABLE > with condition <fieldname> EQ 'X'.
<fieldname> will be from selection screen parameter value <P_fieldname>.
How can i make a where condition?
my where condition shoule be like WHERE <P_FIELDNAME> EQ 'X'.
PLS HELP...
‎2007 Jan 19 7:51 AM
Hi,
<b>select * from <table>
into <inttable>
where <p_fieldname> eq 'X'.
</b>
‎2007 Jan 19 7:51 AM
Try understanding this code ..
select * from <dbtable>
into itab
where <p_fldname> eq 'X'.
‎2007 Jan 19 10:02 AM
‎2007 Jan 19 7:55 AM
hi,
If you are already working an 6.40 (or higher) than you can simply concatenate the WHERE condition into a string and code:
DATA:
gd_where_conditions TYPE string.
SELECT * FROM ...
WHERE ( gd_where_conditions ).
However, if you are working on 6.20 (or less) than you could use the following function module to create your dynamic WHERE condition(s): RH_DYNAMIC_WHERE_BUILD
The function module returns the WHERE conditions in CONDTAB. Thus, you could code:
TYPES: BEGIN OF ty_s_clause.
TYPES: line(72) TYPE c.
TYPES: END OF ty_s_clause.
DATA:
gt_where_clauses TYPE STANDARD TABLE OF ty_s_clause
WITH DEFAULT KEY.
DATA:
gt_condtab TYPE STANDARD TABLE OF hrcond.
Fill gt_condtab with the required conditions
CALL FUNCTION 'RH_DYNAMIC_WHERE_BUILD'
EXPORTING
dbtable = space " can be empty
TABLES
condtab = gt_condtab
where_clause = gt_where_clauses
EXCEPTIONS
empty_condtab = 01
no_db_field = 02
unknown_db = 03
wrong_condition = 04.
Select your data
SELECT * FROM ...
WHERE (gt_where_clauses).
hope this helps.
plz reward if helpful
‎2007 Jan 19 8:00 AM
hi,
parameters : p_field like <type>.
select * from <table>
into <itab>
where <p_field> = 'X'.
‎2007 Jan 19 8:01 AM
hi,
parameters : p_field like <type>.
select * from <table>
into <itab>
where <p_field> = 'X'.
‎2007 Jan 19 8:07 AM
Syntax wise this code is working but its giving dump while executing , i guess it is not possible
REPORT abc.
TABLES : mara.
PARAMETERS : p_field LIKE mara-matnr,
p_tab LIKE dd03l-tabname.
FIELD-SYMBOLS: <fs> TYPE ANY.
ASSIGN p_field TO <fs>.
SELECT SINGLE matnr FROM (p_tab) INTO mara-matnr WHERE <fs> = '000000000000001518'.
WRITE : mara-matnr.