‎2011 Feb 18 6:57 AM
Hi,
I have 10 fields on selection-screeen. In which ever field the user enters single values or ranges,i should pick that field dynamically and pass that field along with value range to Where condition of Select statement.How can i achieve this? Please help.
Regards
K Srinivas
‎2011 Feb 18 8:07 AM
see the following example:
data : begin of itab occurs 0,
matnr like mara-matnr,
end of itab.
ypes: begin of ty_s_clause.
types: line(72) type c.
types: end of ty_s_clause.
data : begin of gt_condtab occurs 0.
include structure hrcond.
data : end of gt_condtab.
FIELD-SYMBOLS <fs_wherecond> TYPE ty_s_clause.
data:
gt_where_clauses type standard table of ty_s_clause
with default key.
gt_condtab-field = 'MATNR'.
gt_condtab-opera = 'EQ'.
gt_condtab-low = '000000000000000111'.
append gt_condtab.
clear gt_condtab.
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 matnr from mara into table itab where (gt_where_clauses).
‎2011 Feb 18 7:07 AM
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 matnr from mara into table itab where (gt_where_clauses).
‎2011 Feb 18 8:02 AM
Thanks for the reply.How the entries should be populated to gt_condtab and gt_where_clauses.When im executing the FM,entering db name im not getting values in gt_condtab and gt_where_clauses. Pls help.
Regards
K Srinivas
‎2011 Feb 18 8:13 AM
Hi,
Simply check the fields whether they are populated or not and build the where clause.
[Dynamic Where Clause|http://www.howforge.com/dynamic-where-clause-in-abap-4]
‎2011 Feb 18 8:07 AM
see the following example:
data : begin of itab occurs 0,
matnr like mara-matnr,
end of itab.
ypes: begin of ty_s_clause.
types: line(72) type c.
types: end of ty_s_clause.
data : begin of gt_condtab occurs 0.
include structure hrcond.
data : end of gt_condtab.
FIELD-SYMBOLS <fs_wherecond> TYPE ty_s_clause.
data:
gt_where_clauses type standard table of ty_s_clause
with default key.
gt_condtab-field = 'MATNR'.
gt_condtab-opera = 'EQ'.
gt_condtab-low = '000000000000000111'.
append gt_condtab.
clear gt_condtab.
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 matnr from mara into table itab where (gt_where_clauses).
‎2011 Feb 18 8:24 AM
We can use a simple STRING concatenated also. Example:
DATA : l_where TYPE string,
i_marc TYPE STANDARD TABLE OF marc.
CONSTANTS: l_quote TYPE char1 VALUE ''''.
PARAMETERS : p_plant TYPE marc-werks.
CONCATENATE 'WERKS' space '=' space l_quote p_plant l_quote space
'AND' space 'PERKZ' space '=' space l_quote 'M' l_quote
INTO l_where RESPECTING BLANKS.
SELECT * FROM marc INTO TABLE i_marc WHERE (l_where).
‎2011 Feb 18 8:25 AM
Hello,
Are the screen elements PARAMETERS or SELECT-OPTIONS?
If they are all SELECT-OPTIONS you can use all the elements in the WHERE clause of the SELECT statement e.g.,
SELECT field1 field2 field3
FROM dbtable
INTO TABLE itab
WHERE
field1 = s_elem1 AND
field2 = s_elem2 AND
field3 = s_elem3 .... so on & so forthBR,
Suhas
‎2011 Feb 18 3:02 PM
I also have a strange feeling that the IN operator has been re-invented in this thread...just slightly more complicated.
Thomas