Dynamic if conditions...
I am developing a web based Bible search with the use of a servlet that parses a text based version of the Bible. I have an HTML form which allows users to enter/select criteria to query by. I have a drop down that contains the books of the Bible, two text fields to enter word criteria, and drop-down where they can select "And" or "Or" ('God "And" Jesus'/'God "Or" Jesus'), and of course 4 text fields that allow for the input of a chapter and verse(4:3 - 4:5) to search by. All of these parameters are passed via URL to a servlet that parses the text and prints out the verses found that match the given criteria. So, obviously there are a hundred different combinations of parameter values that may or may not be null. Is there a way to create a single if statement that will allow dynamic parameters and values to be used as conditions? I'm trying to get away from creating a ton of if/else if statements to test for every possible parameter combination.
Hi!
I think the answer depends on the searchmethod. So U should perhaps be a bit more precise on the mechanism.
But as a first hint try to figure out a single search command that would contain all search parameters. Next check all parameters if they are null and if yes, set them to a default value that can fit into your search command at the parameters place.
Thomas.
Similar Messages
-
Single quote in dynamic where condition
BAPI_STUDENT_IDENTIFIC_ADD has a field called IDENTIFICATIONNUMBER. This field is later used in a dynamic where condition and causes a short dump when it contains a single quote. I will change the program that calls the BAPI to check for single quotes, but is there anything else I need to check for to ensure a correct where condition?
Thanks,
DanHi Dan,
The best way to ensure correctness of syntax of a dynamic where condition is:
Run the program in debugging mode, Get the Query that is generated dynamically and write it to some other ABAP program and perform syntax check.
This will help you to remove all the syntax errors.
Regards,
Darshil -
Dynamic select query with dynamic where condition
Hi all,
I want to use the dynamic select query with dynamic where condition. For that I used the below code but I am getting dump when using this code.
Please advice, if there is any other way to achieve this requirement.
Thanks,
Sanket Sethi
Code***************
PARAMETERS: p_tabnam TYPE tabname,
p_selfl1 TYPE edpline,
p_value TYPE edpline,
p_where1 TYPE edpline .
DATA: lt_where TYPE TABLE OF edpline,
lt_sel_list TYPE TABLE OF edpline,
l_wa_name TYPE string,
ls_where TYPE edpline,
l_having TYPE string,
dref TYPE REF TO data,
itab_type TYPE REF TO cl_abap_tabledescr,
struct_type TYPE REF TO cl_abap_structdescr,
elem_type TYPE REF TO cl_abap_elemdescr,
comp_tab TYPE cl_abap_structdescr=>component_table,
comp_fld TYPE cl_abap_structdescr=>component.
TYPES: f_count TYPE i.
FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,
* <ls_outtab> TYPE ANY,
<l_fld> TYPE ANY.
struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).
elem_type ?= cl_abap_elemdescr=>describe_by_name( 'F_COUNT' ).
comp_tab = struct_type->get_components( ).
comp_fld-name = 'F_COUNT'.
comp_fld-type = elem_type.
APPEND comp_fld TO comp_tab.
struct_type = cl_abap_structdescr=>create( comp_tab ).
itab_type = cl_abap_tabledescr=>create( struct_type ).
l_wa_name = 'l_WA'.
CREATE DATA dref TYPE HANDLE itab_type.
ASSIGN dref->* TO <lt_outtab>.
*CREATE DATA dref TYPE HANDLE struct_type.
*ASSIGN dref->* TO <ls_outtab>.
* Creation of the selection fields
APPEND p_selfl1 TO lt_sel_list.
APPEND 'COUNT(*) AS F_COUNT' TO lt_sel_list.
** Creation of the "where" clause
*CONCATENATE p_selfl1 '= '' p_value ''.'
* INTO ls_where
* SEPARATED BY space.
*APPEND ls_where TO lt_where.
* Creation of the "where" clause
APPEND p_where1 TO lt_where.
* Creation of the "having" clause
l_having = 'count(*) >= 1'.
* THE dynamic select
SELECT (lt_sel_list)
FROM (p_tabnam)
INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>.
* WHERE (lt_where).Hi Sanket,
The above given logic of mine works for you, put the code in the If condition and try-
just like below:
IF NOT P_EBELN IS INITIAL.
lt_where = '& = ''&'' '.
REPLACE '&' WITH p_ebeln INTO lt_where.
REPLACE '&' WITH field_value INTO lt_where.
SELECT (lt_sel_list) INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>
FROM (p_tabnam)
WHERE (lt_where).
ENDIF.
thanks\
Mahesh -
Issue with Dynamic WHERE condition in Cursor in FUNCTION.
Hi All,
I am facing an issue with cursor having dynamic WHERE condition in a function.
Below is the FUNCTION:
CREATE OR REPLACE FUNCTION EXCEPTION_MERGE(TABLE_NAME IN VARCHAR2, TAB_NAME IN VARCHAR2)
RETURN VARCHAr2
IS
stmt_tabcols VARCHAR2(32767);
v_columnname VARCHAR2(32767);
CURSOR C1 IS
SELECT 'A.'||A.COLUMN_NAME ||' = '|| 'B.'||B.COLUMN_NAME COLUMN_NAME
FROM
SELECT COLUMN_ID, COLUMN_NAME
FROM USER_TAB_COLUMNS
WHERE TABLE_NAME = TABLE_NAME
AND COLUMN_NAME NOT IN ('ERROR_TAB_ID','ERROR_LOAD_DATE')
) A,
SELECT COLUMN_ID, COLUMN_NAME
FROM USER_TAB_COLUMNS
WHERE TABLE_NAME = TAB_NAME
) B
WHERE A.COLUMN_ID = B.COLUMN_ID;
BEGIN
FOR TABCOL IN C1
LOOP
stmt_tabcols := stmt_tabcols ||TABCOL.COLUMN_NAME||',';
END LOOP;
stmt_tabcols := RTRIM(stmt_tabcols, ',');
RETURN stmt_tabcols;
END;
SELECT EXCEPTION_MERGE('WC_W_TEST_FS','WC_W_TEST_FS_GBL') FROM DUAL;It throws, below error:
ORA-06502 : PL/SQL : Numeric or value error : character string buffer too smallIf I REPLACE TABLE_NAME and TAB_NAME with hard coded values , it works fine. Can somebody look at the code and let me know the issue.
Edited by: ace_friends22 on Sep 9, 2012 1:08 PMEtbin neatly demonstrating the value of posting code in a manner which makes it easy to read.
It's obviously an naming/scoping issue. Faced with a join like this:
where table_name = table_namethe engine looks for something called table_name in the current scope. It finds it, a column on USER_TAB_COLUMNS and applies it to both sides of the filter. It has no way of knowing that there is also a parameter called TABLE_NAME, because that is outside its current scope. Consequently the query will join every table in your schema regardless of what values you pass, and that's why you blow the buffer.
Takw etbin's advice and name your parameter with a prefix:
where table_name = p_table_nameThis isn't a column in USER_TAB_COLUMNS which will force the engine to look in the next scope up, which in your case is the function, where it will find your parameter and so generate a query for the passed values only.
Cheers, APC
Edited by: APC on Sep 9, 2012 8:03 AM -
Hi, I'm building a procedure with 4 parameters το pass in input and I ask if it's possible to build a select inside the procedure with a dynamic where condition.
The query with 2 conditions is the following:
SELECT count(incident_number) FROM cs.cs_incidents_all_b
1st condition
WHERE (TO_DATE(incident_attribute_6,'dd-mm-yyyy hh24:mi') BETWEEN TO_DATE(p_create_date_ll,'dd-mm-yyyy hh24:mi') AND TO_DATE(p_create_date_ul,'dd-mm-yyyy hh24:mi'))
2nd condition
AND external_attribute_4 BETWEEN p_resolv_time_ll AND p_resolv_time_ul;
The first condition has to be always valid, but the second one, depending on the parameters has to be satisfied or not.
The first 2 parameters (p_create_date_ll and p_create_date_ul) are always written as a string (so the first condition always works).
The second pair of paramenters (p_resolv_time_ll and p_resolv_time_ul) can be written as numbers (from a form), or written both as '*'
So, If the parameters p_resolv_time_ll and p_resolv_time_ul are numbers, I should retrieve a small set of data (all the 2 where condition have to work),
while if they are both '*' ONLY the first condition has to work. Practically, in this last case the 2nd condition is how it was commented.
Is it possible to build something that satisfy my request ?
Thanks in advance
AlexYes I know....
If I use an IF THEN ELSE statement I can write 2 different queries with 2 different where conditions....but I want to avoid this solution because I have 4 pair of these parameters which can assume differents values and depending on their values I have to use different where conditions
If I use an IF THEN ELSE statement, this means to write 16 different queries....
I already used DECODE or CASE but they not satisfy my request....
Anybody has others ideas ?
Thanks -
Dynamic SELECT conditions in background - problem
Hello,
I faced a strange problem. I have function module which uses dynamic conditions in SELECT statement. Everything works fine in foreground processing, but in background the function gives no values. You can find a piece of code below. It's a bit long but as mentioned - works fine in foreground, so seems to be non-coding error... I'd be thankful for any ideas...
data: itwa_where_cond(72) occurs 20 with header line,
wa_where_cond(72) type c,
clear: itwa_where_cond[], itwa_where_cond.
move 'BZOBJ = ''0''' to wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate 'AND KADKY >= ''' l_date_start '''' into wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate 'AND KADKY <= ''' l_date_end '''' into wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate 'AND MATNR = ''' wa_matwrk-matnr '''' into wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate 'AND WERKS = ''' wa_matwrk-werks '''' into wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate 'AND KOKRS = ''' pi_kokrs '''' into wa_where_cond.
append wa_where_cond to itwa_where_cond.
if not pi_freig is initial.
clear wa_where_cond.
concatenate 'AND FREIG =''' pi_freig '''' into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
if not pi_tvers is initial.
clear wa_where_cond.
concatenate 'AND TVERS = ''' pi_tvers '''' into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
if not pi_klvar is initial.
clear wa_where_cond.
concatenate 'AND KLVAR = ''' pi_klvar '''' into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
if not pi_feh_sta is initial.
clear wa_where_cond.
concatenate 'AND FEH_STA = ''' pi_feh_sta '''' into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
if not pi_kkzma is initial.
clear wa_where_cond.
concatenate ' AND KKZMA = ''' pi_kkzma '''' into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
SELECT * FROM KEKO into corresponding fields of table it_keko
WHERE (itwa_where_cond).
Regards,
GrzegorzhI,
TAKE THIS CODE... HOPE IT WORKS FOR YOU....
clear: itwa_where_cond[], itwa_where_cond.
move `BZOBJ = '0'` to wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate `AND KADKY >= '` l_date_start `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate `AND KADKY <= '` l_date_end `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate `AND MATNR = '` wa_matwrk-matnr `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate `AND WERKS = '` wa_matwrk-werks `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate `AND KOKRS = '` pi_kokrs `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
if not pi_freig is initial.
clear wa_where_cond.
concatenate `AND FREIG = '` pi_freig `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
if not pi_tvers is initial.
clear wa_where_cond.
concatenate `AND TVERS = '` pi_tvers `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
if not pi_klvar is initial.
clear wa_where_cond.
concatenate `AND KLVAR = '` pi_klvar `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
if not pi_feh_sta is initial.
clear wa_where_cond.
concatenate `AND FEH_STA = '` pi_feh_sta `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
if not pi_kkzma is initial.
clear wa_where_cond.
concatenate `AND KKZMA = '` pi_kkzma `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
SELECT * FROM KEKO into corresponding fields of table it_keko
WHERE (itwa_where_cond).
REGARDS
SIDDARTH -
Dynamic where condition in Select statement
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 Srinivassee 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). -
Using 'Greater than/less than' in dynamic where condition
Hi Guys,
I am trying to use a logical expression with GT/LT condition in dynamic where, butits giving dump "expression worngly parenthesised' . My query runs perfectly fine when the logical expression does not have 'GT/LT' . Is there a different way of using GT/LT in dynamic where or is it not posiible at all?? Please find my query below -
IF vendor IS NOT INITIAL.
i_where_clause = 'a~lifnr = vendor'.
APPEND i_where_clause.
CLEAR i_where_clause.
ENDIF.
IF to_date IS NOT INITIAL.
i_where_clause = 'a~zzearliestdep LT to_date'.
APPEND i_where_clause.
CLEAR i_where_clause.
ENDIF.
IF from_date IS NOT INITIAL.
i_where_clause = 'a~zzlatestdep GT from_date'.
APPEND i_where_clause.
CLEAR i_where_clause.
ENDIF.
SELECT aebeln alifnr azzearliestdep azzlatestdep
bebelp belikz b~kzabs
INTO CORRESPONDING FIELDS OF TABLE i_podetails
UP TO max_hits ROWS
FROM ( ekko AS a INNER JOIN ekpo AS b
ON aebeln = bebeln )
WHERE a~ebeln = ebeln AND
(i_where_clause).Hi,
Try this -
IF vendor IS NOT INITIAL.
i_where_clause = 'a~lifnr = vendor'.
APPEND i_where_clause.
ENDIF.
IF to_date IS NOT INITIAL.
if i_where_cause[] is not initial.
i_where_clause = 'AND'
append i_where_cause.
endif.
i_where_clause = 'a~zzearliestdep LT to_date'.
APPEND i_where_clause.
ENDIF.
IF from_date IS NOT INITIAL.
if i_where_cause[] is not initial.
i_where_clause = 'AND'
append i_where_cause.
endif.
i_where_clause = 'a~zzlatestdep GT from_date'.
APPEND i_where_clause.
CLEAR i_where_clause.
ENDIF.
Cheers.
\[removed by moderator\]
Edited by: Jan Stallkamp on Jun 26, 2008 1:08 PM -
Dynamic where condition - Problem
Hi All,
I have a problem in a select statement where I use a dynamic condition.It gives me a dump
SAPSQL_WHERE_PARENTHESES
CX_SY_DYNAMIC_OSQL_SYNTAX.
Please find the below code which I implemented.
*SELECT * FROM ZXR5*
WHERE (SOURCE).
The value of SOURCE is 'MATNR EQ '000000000000200066'.
When I checked the help, it is advised to use a CATCH exception which I did as below:
TRY.
*SELECT * FROM ZXR5*
WHERE (SOURCE).
CATCH cx_sy_dynamic_osql_error.
MESSAGE `Wrong WHERE condition!` TYPE 'I'.
ENDTRY.
Now, the select statement gives an exception and is not executing to fetch the values.
I need some input on the above issue. Any help on this would be greatly appreciated.
Regards,
Rajmohamed.MHi Vijay,
I tried the same and all the time, the select statement gives me an exception and wont proceed.
TRY.
SELECT * FROM ZXR5
INTO TABLE <L_ZXR5>
WHERE (SOURCE).
CATCH cx_sy_dynamic_osql_error.
MESSAGE `Wrong WHERE condition!` TYPE 'I'.
ENDTRY.
Regards,
Raj -
Hey All,
I am doing something a little strange. Basically I have a database table with some coldfusion If statments. Things like
"age GT 18" or
"name eq 'frank'"
etc. Basically it's a dynamic rule engine. Allows my users to place triggers in an app. Question is, how do I evalulate those conditions. I pull them from the database, loop over the query, but I can't actually get CF to parse the contructed IF statment. For example...
<cfset YearsOld = 67>
<cfquery name="GetConditions" datasource="webserver">
Select *
From SignUpFormAdditionalActions
Where Active = 1
</cfquery>
<cfoutput>
<cfloop query="GetConditions">
<cfif GetConditions.Condition>
Met #GetConditions.Name#. #GetConditions.Content#<br />
</cfif>
</cfloop>
</cfoutput>
And here is what my database looks like
I know this should be easy, I'm just kinda having a brain fart. Thanks!Ah I figured it out. Using DE and evaluate.
<cfquery name="GetConditions" datasource="webserver">
Select *
From SignUpFormAdditionalActions
Where Active = 1
</cfquery>
<cfoutput>
<cfset YearsOld = 67>
<cfloop query="GetConditions">
<cfset result = #Evaluate(GetConditions.condition)#>
<cfif result eq "yes">
Passed #GetConditions.name#<br />
<cfelse>
Failed #GetConditions.name#<br />
</cfif>
</cfloop>
</cfoutput> -
How to execute procedure with dynamic where condition.
Hi All,
I am facing a probelem
Issue :
I am having a parameter p_id in my procedure based on the value of this parameter i want to change the where condition.
How to do so?
Code:---------
create or replace procedure p_1
( p_id in emp_dummy.empno%type)
is
parameter_1 varchar2(2000);
v_sal number;
begin
if p_id = 1 then
parameter_1 := 'where empno = 1';
else
parameter_1 := 'where 1=1';
end if;
select salary into v_sal from emp_dummy||' '||parameter_1;
end;Dynamic SQL is not the best of ideas, but if you must...
EXECUTE IMMEDIATE 'select salary from emp_dummy where empno=nvl(:x,empno)' into v_sal using p_id;Then if you pass in the p_id to the procedure it will select the salary for that employee and if null is passed in then it will select the salary for all employees. Now here's a problem because you are trying to return a single value and if you don't specify the employee then it will try and return multiple values from that select, so you probably want to do something like give the sum of the salaries...
EXECUTE IMMEDIATE 'select sum(salary) from emp_dummy where empno=nvl(:x,empno)' into v_sal using p_id; -
Dump using Dynamic WHERE condition (EXISTS + subquery)
Hi experts,
I want to use dynamic WHERE here, but I got a problem when using EXISTS + subuery.
Here is my code snippet:
And the actual SQL sentence should be like this:
When I execute this program, an exception CX_SY_DYNAMIC_OSQL_SEMANTICS is raised and the program dumps.
Dump Information:
Short text
A dynamically specified column name is unknown.
Error analysis
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SEMANTICS', was
not caught in
procedure "FRM_GET_ALL_PROD_ORDERS" "(FORM)", nor was it propagated by a
RAISING clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
An Open SQL clause was specified dynamically. The contained field name
"EXISTS" does not exist in any of the database tables from the FROM clause.
I'm confused because the plain text of my WHERE condition looks good. Could you tell me why I encountered this problem?
Many thanks,
ShelwinHi Shelwin !
Testing your code i dont have dump, using this:
REPORT z_test MESSAGE-ID z_test_msgs.
DATA: lt_where_tab1 TYPE STANDARD TABLE OF edpline WITH HEADER LINE,
lt_where_tab2 TYPE STANDARD TABLE OF edpline WITH HEADER LINE,
gt_detail TYPE STANDARD TABLE OF caufv WITH HEADER LINE.
CONCATENATE 'EXISTS (SELECT J_1~STAT FROM JEST AS J_1 INNER JOIN TJ02T AS T_1'
'ON J_1~STAT EQ T_1~ISTAT'
'WHERE J_1~OBJNR EQ CAUFV~OBJNR'
'AND J_1~INACT EQ '' '''
'AND T_1~SPRAS EQ ''E'''
'AND T_1~TXT04 EQ ''CRTD'')'
INTO lt_where_tab1.
CONCATENATE 'NOT EXISTS (SELECT J_2~STAT FROM JEST AS J_2 INNER JOIN TJ02T AS T_2'
'ON J_2~STAT EQ T_2~ISTAT'
'WHERE J_2~OBJNR EQ CAUFV~OBJNR'
'AND J_2~INACT EQ '' '''
'AND T_2~SPRAS EQ ''E'''
'AND T_1~TXT04 IN (''TECO'' , ''DLFL'', ''DLV'', ''CLSD''))'
INTO lt_where_tab2.
SELECT aufnr ftrms gltrs
FROM caufv
INTO CORRESPONDING FIELDS OF TABLE gt_detail
WHERE (lt_where_tab1)
AND (lt_where_tab2).
BREAK-POINT.
Regards,
Edited for error on image. -
Dynamic select conditions within a Join sql_cond - (cond_syntax)
Hello,
I have many programs where I use sql_cond - (cond_syntax) syntax ( http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP_DYNAMIC.htm )
Example
TRY.
SELECT ebeln ebelp sakto
FROM ekkn
INTO TABLE i_ekkn
WHERE (cond_syntax).
CATCH cx_sy_dynamic_osql_error.
MESSAGE `Wrong WHERE condition!` TYPE 'I'.
ENDTRY.
My problem now is that I am trying to do the same in a select join:
TRY.
SELECT bsbukrs bsmonat bsgjahr bsgsber bshkont sktxt50 bssegment bkusnam
bsblart bsbelnr bkbktxt bsbuzei bsmwskz bswrbtr bsbuzid bsbudat bsxblnr bsbschl
bkwaers bsaugbl bszuonr bsshkzg bsdmbtr bktcode bk~stblg
INTO TABLE i_bsis
FROM bsis AS bs
INNER JOIN bkpf AS bk ON bsbelnr = bkbelnr AND
bsbukrs = bkbukrs AND
bsgjahr = bkgjahr AND
bsblart = bkblart AND
bk~stblg = ''
INNER JOIN skat AS sk ON sk~spras = 'S'AND
bshkont = sksaknr
WHERE
bs~bukrs IN s_bukrs AND "
bk~bukrs IN s_bukrs AND "
bs~hkont IN s_racct AND "
bs~zuonr IN s_lifnr AND "
bs~zuonr IN s_kunnr AND "
bs~belnr IN s_belnr AND "
( bs~budat BETWEEN date1 AND p_date2 )
(cond_syntax) AND
bk~waers IN s_waers AND
bk~xblnr IN s_xblnr AND "
bs~gsber IN s_div AND "
bk~usnam IN s_usnam. "
CATCH cx_sy_dynamic_osql_error.
MESSAGE `Wrong WHERE condition!` TYPE 'I'.
ENDTRY.
But it is not working at all, it only returns sy-subrc = 4 and if I change for 'bs~budat >= date1' it return all records from table
does anybody have use this in an inner join?
Thanks for your help.hI,
TAKE THIS CODE... HOPE IT WORKS FOR YOU....
clear: itwa_where_cond[], itwa_where_cond.
move `BZOBJ = '0'` to wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate `AND KADKY >= '` l_date_start `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate `AND KADKY <= '` l_date_end `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate `AND MATNR = '` wa_matwrk-matnr `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate `AND WERKS = '` wa_matwrk-werks `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
clear wa_where_cond.
concatenate `AND KOKRS = '` pi_kokrs `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
if not pi_freig is initial.
clear wa_where_cond.
concatenate `AND FREIG = '` pi_freig `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
if not pi_tvers is initial.
clear wa_where_cond.
concatenate `AND TVERS = '` pi_tvers `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
if not pi_klvar is initial.
clear wa_where_cond.
concatenate `AND KLVAR = '` pi_klvar `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
if not pi_feh_sta is initial.
clear wa_where_cond.
concatenate `AND FEH_STA = '` pi_feh_sta `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
if not pi_kkzma is initial.
clear wa_where_cond.
concatenate `AND KKZMA = '` pi_kkzma `'` into wa_where_cond.
append wa_where_cond to itwa_where_cond.
endif.
SELECT * FROM KEKO into corresponding fields of table it_keko
WHERE (itwa_where_cond).
REGARDS
SIDDARTH -
Building a dynamic IF condition
Hi all,
Is there a way to check if a dynamically built logical expression is true or false? For example, I have two values val_1 and val_2 in a table, and a logical operator also stored in my table, how do I check ( val_1 <operator> val_2 ) at run time?
I tried to concatenate this into a string and check but it does not work. Any ideas?
Thanks,
NithyaYou can try Defining a Macro or do it by Ranges:
<b>If you want to use a Macro, Try something like this:</b>
DATA: t_t001 TYPE t001 OCCURS 0 WITH HEADER LINE.
DEFINE my_dynamic_check.
if &1 &2 &3.
write:/ 'Success'.
else.
write:/ 'Failed'.
endif.
END-OF-DEFINITION.
SELECT * FROM t001 INTO TABLE t_t001.
LOOP AT t_t001.
my_dynamic_check t_t001-bukrs eq 'US01'. "US01 can be replaced by a company code in table T001
ENDLOOP.
<b>Or if You want to use Ranges:</b>
ranges: r_datum for sy-datum.
r_datum-sign = 'I'.
r_datum-option = 'EQ'.
r_datum-low = sy-datum.
apppend r_datum.
If sy-datum in r_datum.
Endif.
Thanks, Ankur
Award if the info is useful
Message was edited by:
ankur malhotra -
Hi Forum!
I want to know if it's possible to build a dynamic logical expression for IF or CASE instructions and get it evaluated.
For example:
data: LogExp type string.
LogExp = 'Sy-subrc eq 0'.
IF (LogExp).
Endif.
Or
data: Var type string,
LogExp type i.
LogExp1 = 0.
LogExp2 = 4.
Var = 'Sy-subrc'.
Case (Var).
When (LogExp1).
When (LogExp2).
When others.
Endcase.
Thanks in advance.
John.Hi John,
in general your idea of dynamic logical expression is not possible in ABAP.
But you can use the operator IN in combination with range tables. You have define all variables in your statement. Empty range tables will be treated as true.
See this example:
data lt_r_subrc type range of sy-subrc.
data ls_r_subrc like line of lt_r_subrc.
ls_r_subrc-sign = 'I'.
ls_r_subrc-option = 'EQ'.
ls_r_subrc-low = 0.
insert ls_r_subrc into table lt_r_subrc.
if sy-subrc in lt_r_subrc.
" do something
endif.
Just modify the range tables for different conditons.
Regards,
Axel
Maybe you are looking for
-
SAP BW Multidimensional OLEDB Provider and NOPROMPT option
Hello I'm trying to connect to a SAP system using the SAP BW oleDB provider with this kind of connection string: Provider=MDrmSap.2;Data Source=SAP VPN;Password=PASSWORD;User ID=USERID;Location="";Integrated Security=False;Persist Security Info=True;
-
MacBook Pro goes to sleep when copying files from attached drives
I have noticed that since installing Yosemite my MacBook Pro goes to sleep when it is in the middle of copying a large number of files. When I wake it up the copying continues. I have also noticed that when I am watching videos from my shared iTunes
-
Propagate data in Shared memory.
Hello Gurus, Need some help regarding Propagating data between application server in shared memory. There is a button in SHMM to propagate date between various app. server. Question: What are the configuration steps to distribute data. Is there any d
-
Hello! I am very new to appdev. I am keen to develop in this field. Where should I begin!!! Please advice some beginners guide or pointer. Reg Dhananjey
-
Please advise