‎2009 Jan 30 9:53 AM
Hi All,
I am relative new to ABAP and I would like to ask a question about checking conditions in SELECT statement in the "WHERE" part.
There are two checkboxes at the selection screen and each should disable one of conditions (marked with two stars) in the SELECT mentioned below.
My question is, whether there exists an option how to solve this problem without using solution like:
IF checkobx1.
SELECT (without one condition)
ELSEIF checkbox2.
SELECT(without other condition).
ELSE.
SELECT (with both conditions)
SELECT qprueflos qherkunft qaufnr qsa_aufnr qmatnr qwerkvorg
qpastrterm qpaendterm
qverid qobjnr vobjnr AS objnr_fa vauart
FROM qals AS q INNER JOIN vkaufk AS v
ON qaufnr = vaufnr
INTO CORRESPONDING FIELDS OF TABLE gt_qals
WHERE q~prueflos IN s_pruefl
AND q~stat35 EQ space
AND q~werk EQ loswk
AND q~herkunft IN s_herk
AND q~offennlzmk EQ 0
AND q~offen_lzmk EQ 0
AND q~pastrterm IN s_startt
AND q~paendterm LE s_endt
AND v~auart IN s_auart. "('ZCPA', 'ZCPK', 'ZCBA').
‎2009 Jan 30 10:01 AM
Hi
U can try to use the ranges:
RANGES: R1 FOR QALS-OFFENNLZMK,
R2 FOR QALS-OFFEN_LZMK.
IF CHECKBOX1
R1(3) = 'IEQ'.
R1-LOW = 0.
APPEND R1.
ELSEIF CHECKBOX2.
R2(3) = 'IEQ'.
R2-LOW = 0.
APPEND R2.
ENDIF.
SELECT ........................................
WHERE
...............................................
AND OFFENNLZMK IN R1
AND OFFEN_LZMK IN R2
...............................................Max
‎2009 Jan 30 10:01 AM
Hi
U can try to use the ranges:
RANGES: R1 FOR QALS-OFFENNLZMK,
R2 FOR QALS-OFFEN_LZMK.
IF CHECKBOX1
R1(3) = 'IEQ'.
R1-LOW = 0.
APPEND R1.
ELSEIF CHECKBOX2.
R2(3) = 'IEQ'.
R2-LOW = 0.
APPEND R2.
ENDIF.
SELECT ........................................
WHERE
...............................................
AND OFFENNLZMK IN R1
AND OFFEN_LZMK IN R2
...............................................Max
‎2009 Jan 30 10:04 AM
Hi,
You can build the where clause dynamically and pass it to the select statement. Take a look at the program demo_select_dynamic_conditions in SE38.
regards,
Advait
‎2009 Jan 30 10:08 AM
Hi,
If u write someother logic for ur requirement, definetly there will be a select query.
In ur logic also, ultimately only one Select query will be executed. so performance will be the same if u use some other logic aslo. So use ur logic.
‎2009 Jan 30 10:09 AM
You can solve the problem with dynamic creation of condition in where list
first add all mandatry values
ex: "q~prueflos IN s_pruefl" add to itab_sel_final
"AND q~stat35 EQ space" add to itab_sel_final
"AND q~werk EQ loswk" add to itab_sel_final
"AND q~herkunft IN s_herk" add to itab_sel_final
then add those check box which is selected
suppoese check1 = X then add
"AND filed = check1" add to itab_sel_final
So decide your where condtion in internal table ITAB_SEL_FINAL and then use in select statement
SELECT qprueflos qherkunft qaufnr qsa_aufnr qmatnr qwerkvorg
qpastrterm qpaendterm
qverid qobjnr vobjnr AS objnr_fa vauart
FROM qals AS q INNER JOIN vkaufk AS v
ON qaufnr = vaufnr
INTO CORRESPONDING FIELDS OF TABLE gt_qals
WHERE (itab_sel_final).
Hope this will solve your problem.
‎2009 Jan 30 10:21 AM
Hi,
With this, I think u can directly read into WHERE clause
IF checkbox1.
v_where = '& BETWEEN ''&'' AND ''&'' '.
REPLACE '&' WITH key_field INTO v_where.
REPLACE '&' WITH field_LOW INTO v_where.
REPLACE '&' WITH field_HIGH INTO v_where.
CONDENSE v_where.
ELSEIF checkbox2.
v_where = '& BETWEEN ''&'' AND ''&'' '.
REPLACE '&' WITH key_field INTO v_where.
REPLACE '&' WITH field_LOW INTO v_where.
REPLACE '&' WITH field_HIGH INTO v_where.
CONDENSE v_where.
ENDIF.
select * into corresponding fields of table ITAB
from (table_name)
where (v_where).In this key_field is your fieldname in the where clause and field_low, field_high are range of values.
If i write static query it looks like this
RANGES: MATNR1 FOR MARA-MATNR.
MATNR1-LOW = MATNR_LOW.
MATNR1-HIGH = MATNR_HIGH.
MATNR1-SIGN = 'I'.
MATNR1-OPTION = 'BT'.
APPEND MATNR1.
select * into corresponding fields of table itab
from mara where matnr BETWEEN 'M100' AND 'M200'.Hope it helps u
thanks\
Mahesh
Edited by: Mahesh Reddy on Jan 30, 2009 11:23 AM
‎2009 Feb 02 10:19 AM
I would like to thank you all for your helpfull solutions.
At last I was told to solve this problem by deleting those two conditions and add an statement like this:
IF sy-subrc = 0.
SELECT * FROM QALS INTO ls_tab
FOR ALL ENTRIES IN gt_qals
WHERE prueflos = gt_qals-prueflos.
CHECK ls_tab-offennlzmk EQ 0 AND p_allow1 EQ ''.
CHECK ls_tab-offen_lzmk EQ 0 AND p_allow2 EQ ''.
DELETE gt_qals WHERE prueflos = ls_tab-prueflos.
ENDSELECT.
ENDIF.