OraclePreparedStatement and dynamic where clause
I am trying to figure out a better and more efficient way to construct a dynamic sql statement where the one or more parameters can be passed which would be included in the where clause. I know I can simply use a case or if statement to build the where clause but I cant believe this is the only/best way to do it.
I was playing with OraclePreparedStatement but it only seems to work when the where columns are known. I need something like:
select something from somewhere
where ? = ?
And I can simply set 1 to be a column and 2 to be a value. I suppose I could sublcass or create my own class that does this.
Any help would be appreciated.
Ryan
>>>However, the problem is that my current structure doesn't all me to write any SQL to be written
on DAL
You cannot use dynamic sql in DAL? Have a stored procedure where you build dynamic sql and call it from
within DAL.
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence
Similar Messages
-
Dynamic where clause in my query
I am using a view
select * from vw_pt_inv_customer
My requirement is have a web page where users can search for customers by filling in a form which has the following feilds: - User can fill in the form with all the feilds or not. I want a dynamic where clause.. how can i get this work for me?
Title
Firstname
Surname
Address1
Address2
Postcode
Telephone No879796 wrote:
I am using a view
select * from vw_pt_inv_customer
My requirement is have a web page What web frame work is used? Apex? Something else?
where users can search for customers by filling in a form which has the following feilds: - User can fill in the form with all the feilds or not. I want a dynamic where clause.. how can i get this work for me?Dynamic where clauses are a Very Bad Idea (tm).
And having an open ended search function on a web page is also not a great idea.
If you are using Apex, the for performance (and even query flexibility) it will be better creating a separate reporting region for each unique query. A boolean rendering condition checks the existing bind variables in order to determine if that specific reporting region should be executed.
This results in a reporting region having a proper and dedicated SQL query (no hacking of the where clause) and that region only being rendered for the proper combination of supplied filter criteria.
A slightly more complex, but more flexible approach, is using a generic reporting region that calls a PL/SQL function that creates returns the SQL query for execution and rendering. The approach to this is very similar to constructing a SQL ref cursor (dynamically) for a client. The only difference is that instead of creating the actual ref cursor, the code simply needs to return the SQL source code statement - with bind variables. The Apex run-time does the rest (does the binds and execution and rendering).
If you are not using Apex - you should still consider these approaches. And not hacking a single SQL to cater for all different types of filter conditions. -
Dynamic where clause in select query
Hi
I'm trying for a dynamic query and in the dynamic where clause i'm checking a field for constant.....for instance if i wanna to use WERKS EQ '0478' how to declare it in dync where clause. i tried for the following:
SELECT (TAB_FIELD) INTO TABLE DITAB UP TO 10 ROWS FROM (TAB_NAME) WHERE (CONDI).
heree CONDI = 'werks eq 0287' . in this case the query fails as the werks shud be equal to '0287' and not just 0287. How to handle this? i tried for the following
CONDI = 'werks eq " '0287' " ' but no luck as it is not a valid stmt as i knew.hi prabhu,
this is how u select dynamically...
DATA: COND(72) TYPE C,
ITAB LIKE TABLE OF COND.
PARAMETERS: CITY1(10) TYPE C, CITY2(10) TYPE C.
DATA WA TYPE SPFLI-CITYFROM.
CONCATENATE 'CITYFROM = ''' CITY1 '''' INTO COND.
APPEND COND TO ITAB.
CONCATENATE 'OR CITYFROM = ''' CITY2 '''' INTO COND.
APPEND COND TO ITAB.
CONCATENATE 'OR CITYFROM = ''' 'BERLIN' '''' INTO COND.
APPEND COND TO ITAB.
LOOP AT ITAB INTO COND.
WRITE COND.
ENDLOOP.
SKIP.
SELECT CITYFROM
INTO WA
FROM SPFLI
WHERE (ITAB).
WRITE / WA.
ENDSELECT.
regards,
sohi -
Dynamic Where clause in 4.6C [Literals allowed but not variables]
Good afternoon-
We have a dynamic select statement that works perfectly in 4.7 ext 2, but is causing a short dump in 4.6C. The error in the short dump says:
The current ABAP/4 program attempted to execute an ABAP/4 Open SQL
statement containing a WHERE condition of the form WHERE (itab) or
WHERE ... AND (itab). The part of the WHERE condition specified at
runtime in the internal table itab contains an invalid
value "HDR_COMP_CODE". Literals are allowed as values, but not variables.
HDR_COMP_CODE is in incoming parameter to the function module that is calling this code. It is of type BKPF-BUKRS.
Here is the code:
DATA: BEGIN OF L_WHERE_CLAUSE OCCURS 0,
TEXT_LINE(60) TYPE C,
END OF L_WHERE_CLAUSE.
CLEAR L_WHERE_CLAUSE.
IF NOT HDR_COMP_CODE IS INITIAL.
SELECT SINGLE KTOPL
INTO LV_KTOPL
FROM T001
WHERE BUKRS = HDR_COMP_CODE.
L_WHERE_CLAUSE = 'B~BUKRS = HDR_COMP_CODE'.
APPEND L_WHERE_CLAUSE.
CLEAR L_WHERE_CLAUSE.
L_WHERE_CLAUSE = 'AND'.
APPEND L_WHERE_CLAUSE.
CLEAR L_WHERE_CLAUSE.
L_WHERE_CLAUSE = 'T~KTOPL = LV_KTOPL'.
APPEND L_WHERE_CLAUSE.
CLEAR L_WHERE_CLAUSE.
L_WHERE_CLAUSE = 'AND'.
APPEND L_WHERE_CLAUSE.
CLEAR L_WHERE_CLAUSE.
ENDIF.
L_WHERE_CLAUSE = 'T~SPRAS = SY-LANGU'.
APPEND L_WHERE_CLAUSE.
CLEAR L_WHERE_CLAUSE.
SELECT BSAKNR TTXT50
INTO (LT_GL_ACCOUNT_DATA-GL_ACCOUNT, LT_GL_ACCOUNT_DATA-DESCRIPTION)
FROM SKB1 AS B INNER JOIN SKAT AS T
ON TSAKNR = BSAKNR
WHERE (L_WHERE_CLAUSE).
APPEND LT_GL_ACCOUNT_DATA.
CLEAR LT_GL_ACCOUNT_DATA.
ENDSELECT.
This EXACT query works in 4.7, has anyone run into this, or can they tell me why I might be getting the error?
Thanks,
AndyWell, in this case, unless I'm missing something, you do not requre a dynamic WHERE clause. You can use RANGES instead.
report zrich_0001.
*DATA: BEGIN OF L_WHERE_CLAUSE OCCURS 0,
*TEXT_LINE(60) TYPE C,
*END OF L_WHERE_CLAUSE.
ranges: r_bukrs for t001-bukrs.
ranges: r_ktopl for t001-ktopl.
*CLEAR L_WHERE_CLAUSE.
IF NOT HDR_COMP_CODE IS INITIAL.
clear r_bukrs. refresh r_bukrs.
r_bukrs-sign = 'I'.
r_bukrs-option = 'EQ'.
r_bukrs-low = hdr_comp_code.
append r_bukrs.
SELECT SINGLE KTOPL
INTO LV_KTOPL
FROM T001
WHERE BUKRS = HDR_COMP_CODE.
clear r_ktopl. refresh r_ktopl.
r_ktopl-sign = 'I'.
r_ktopl-option = 'EQ'.
r_ktopl-low = lv_ktopl.
append r_ktopl.
*L_WHERE_CLAUSE = 'B~BUKRS = HDR_COMP_CODE'.
*APPEND L_WHERE_CLAUSE.
*CLEAR L_WHERE_CLAUSE.
*L_WHERE_CLAUSE = 'AND'.
*APPEND L_WHERE_CLAUSE.
*CLEAR L_WHERE_CLAUSE.
*L_WHERE_CLAUSE = 'T~KTOPL = LV_KTOPL'.
*APPEND L_WHERE_CLAUSE.
*CLEAR L_WHERE_CLAUSE.
*L_WHERE_CLAUSE = 'AND'.
*APPEND L_WHERE_CLAUSE.
*CLEAR L_WHERE_CLAUSE.
ENDIF.
*L_WHERE_CLAUSE = 'T~SPRAS = SY-LANGU'.
*APPEND L_WHERE_CLAUSE.
*CLEAR L_WHERE_CLAUSE.
SELECT B~SAKNR T~TXT50
INTO (LT_GL_ACCOUNT_DATA-GL_ACCOUNT, LT_GL_ACCOUNT_DATA-DESCRIPTION)
FROM SKB1 AS B INNER JOIN SKAT AS T
ON T~SAKNR = B~SAKNR
WHERE b~bukrs in r_bukrs
and t~ktopl in r_ktopl.
APPEND LT_GL_ACCOUNT_DATA.
CLEAR LT_GL_ACCOUNT_DATA.
ENDSELECT.
Regards,
Rich Heilman -
Dynamic WHERE Clause in a Calendar
I would like to have a Calendar display values based on a dynamic WHERE clause created using PL/SQL anonymous block evaluating the values of items that the user uses as filters. I have done this dynamic SQL for reports and would lke to do the same for a Calendar.
I figured out how to do this.
I created a Hidden Item with the source value of &APP_USER.
named P50_APP_USER.
This is how my query looks now:
SELECT * FROM APX_EVENT WHERE APX_EVENT.STORE_NR IN (SELECT APX_Z.STORE_NR FROM APX_Z WHERE APX_Z.USERNAME = :P50_APP_USER)
And it works.
I got the answer from this thread:
CALENDAR - SQL ORDER BY CLAUSE NOT WORKING -
How to create VO with multiple dynamic where clauses on select with UNION?
I am trying to implement the View Object for the UNION query that looks like this:
select a,b,c...
from t1,t2,...
where dynamic_where_clause1
union all
select a,b,c,...
from t11,t12, ...
where dynamic_where_clause2
There are up to 60 input parameters that are used to generate dynamic where clauses. They are actually created by calling PL SQL function.
So far, I was not able to assign both where clauses to the view object. Is there a workable solution for this problem, besides resorting to programmatic View Object?
I understand that recommended way with UNIONs is to wrap both queries into a parent select:
select * from (
select a,b,c...
from t1,t2,...
where ... -- table relationship joints
union all
select a,b,c,...
from t11,t12, ...
where ... -- table relationship joints
) QRSLT
where dynamic_where_clause
Unfortunately this approach doesn't work here, since individual selects are producing unmanageable amount of data and resulting query takes forever to complete.I afraid I would not have any real benefits from using VO if I replace the entire query with every request. Actually, the performance may suffer.
I solved the problem by creating a POJO Data Control and invoking the custom select query from java. Not sure if it is the best approach to the problem, but implementation time is limited and it works.
Actually, this is not the first time I see the need to implement VO with complicated SQL like select with unions and dynamic pieces. It would be nice to find a solution and not resort to workarounds.
Edited by: viksicom on Aug 2, 2012 8:48 AM -
Is iot possible to use a dynamic where clause in a loop? If so how to you code this?
i.e. Loop at itab in wa where (dynamic_where_clause)...
endloop...
Moderator message: please read ABAP documentation for your SAP release.
Edited by: Thomas Zloch on Mar 29, 2011 3:20 PMYou should be aware that a LOOP AT ... WHERE is not an optimized access .
+ because on a standard table there is not sort order,
so the loop goes over the whole table and does
something when the condition is fulfilled
+ it is optimzed for sorted tables, but only for one key!
=> so your idea must have bad performance!
If this is not a problem, then you can solve the problem
in the following way:
loop at table
if ( dynamic condition )
endif.
endloop.
But maybe is dynamic condition is not necessary, but
a some fixed if-conditions are also o.k.
Siegfried -
How to construct dynamic WHERE clause in our sqr programming ?
In my run control table I am having parameters fromdate, thrudate [mandatory parameters] and location as [Optional Parameter] how can I declare dynamic where clause to achieve this could any one help me with coding ? Here is my sample coding
Begin-Procedure Main
if $prcs_process_instance=' '
do askvalues
else
do getvalues
end-if
End_Procedure Main
Begin-Procedure askvalues
input $frmdate 'Enter From Id' type=text format=number !Mandatory Parameter
input $todate 'Enter To Id' type=text format=number !Mandatory Parameter
input $loc 'Enter Location' value=text !Optional Parameter
End-Procedure
Begin-Procedure getvalues
Begin-Select
FROMDATE
THRUDATE
SQR_LOCATION
let $frmdate=&FROMDATE
let $todate=&THRUDATE
let $loc=&SQR_LOCATION
let where=-------------------------- ?
FROM
PS_PROCESS_TBL WHERE OPRID=$PRCS_OPRID AND RUN_CNTL_ID=$PRCS_RUN_CNTL_ID
End-Select
End-Procedure getvalues
Begin-Procedure selectall
BEGIN-SELECT
SQR_EMPLID
SQR_FNAME
SQR_LNAME
SALARY
FROM
PS_SQR_FIRST_TBL WHERE SQREMPID BETWEEN $frmdate AND $todate
END-SELECT
End-Procedure selectallSQR will understand Where Clause as dynamic, when you include it in Square Brackets []
In your case, since fromdate & thrudate are mandatory values, I would code like this
let $frmdate=&FROMDATE
let $todate=&THRUDATE
let $loc=&SQR_LOCATION
let $Where_Clause = 'SQREMPID BETWEEN' || ' ' || $frmdate || ' ' || 'AND' || ' ' ||$todate
if $loc != ''
let $Where_Clause = $Where_Clause || ' '|| 'AND' || ' ' || 'LOCATION = ' || $loc
end-if
Now you can use this Dynamic Where Clause in which procedure you want. Only thing is you need to encode the where clause with brackets([$Where_Clause])
Edited by: 935179 on Sep 6, 2012 2:11 AM -
ADF dynamic where clause for VO query using BC
I'm hoping someone can help me out. I have a read only view object that I want to filter results based on some user choices. For example the user may want to see all results or they may only want to see a much smaller subset. This is for an error dashboard, the smaller subset maybe by application or maybe by application and by error severity. I think I can use a dynamic where clause but I'm not sure, Can someone get me started down the right path, or post an example that I can see.
Hi user,
You can use a dynamic where clause for this, but maybe there is a more practical option. Maybe you can have a fixed where clause, but using a bind parameter, like:
vo.application like :applicationParam. This makes an executeWithParams method available that you can call from your page, and use in the bindings. This parameter you can populate with the results of for example a poplist, with a default value of '%'.
When you do want to use a dynamic where clause, you will need to add a method to the java code of your application module, and make this method available for the client. In this method, you can use findViewObject to retrieve your VO, use VO.setWhereClause to set the whereclause to what you want, and then call VO.executeQuery. This method can then again be called from the page.
Success,
Jeroen van Veldhuizen -
Dynamic where clause for MULTIPLE values
In the following of dynamic where clause?
i have some somewhat different problem.
Is a dynamic where clause for multiple values possible?
If the inputvariable varCode1,varCode2,varCode3,varCode4 are 0 then show all id's otherwise filter the resultset on var1 and/or var2,and/or var3,and/or var4.
Example table:
create table t
(d int,var int);
insert into t values (1 ,1 );
insert into t values (2 ,1 );
insert into t values (3 ,2 );
insert into t values (4 ,3 );
insert into t values (5 ,4 );
insert into t values (6 ,4 );
insert into t values (7 ,4 );
insert into t values (8 ,4 );
insert into t values (9 ,5 );
insert into t values (10, 6);
insert into t values (11, 6);
So what i want to change the where clause upon the value of the varCodes. If var1 and var are not 0 a "AND" should be used otherwise an "OR"
select id
from tst
where var = DECODE( :varCode1, 0, var, :varCode1)
or/and(?) DECODE( :varCode2, 0, var, :varCode2)
or DECODE( :varCode3, 0, var, :varCode3)
or DECODE( :varCode4, 0, var, :varCode4)Please turn off your Caps Lock
and try this link
Dynamic WHERE clause -
Creating dynamic where clause with string delimiter " ; "
hi...
i need a solution for complex problem like, 1. start_date IN date,
end_date IN date,
shift_type IN varchar2
i will get shift_type as "first_shift" or "first_shift;second_shift" or "first_shift;second_shift;third_shift" ....etc any combination. where fist & second & third shits are nothing but 1 , 2 , 3. i need to find out data between start_date and end_date in combination of shifts ( may be 1;2 or 1;3 or 1;2;3 or 2;3 ...etc) . now i need to write this code in dynamic where clause ...i tried in different ways...but not succeeded. can anybody guide me step by step...or with script.
NOTE: there is a table called "shift" with data like
shift_type shift_mode
1 first_shift
2 second_shift
3 third_shiftHi,
Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
If the question involves parameters, give a few different sets of parameters and the results you want for each set, given the same sample data.
It's unclear that you need dynamic SQL at all.
If shift_type is a variable, that can be either a single value or a ;-delimited list (such as '1;3'), you can compare that to a column called shift_column like this:
WHERE ';' || shift_type || ';' LIKE
'%;' || shift_column || ';%'No dynamic SQL or PL/SQL required.
If you really do want to use dynamic SQL, these two pages should gives you some ideas:
http://www.oracle-base.com/articles/misc/DynamicInLists.php
http://tkyte.blogspot.com/2006/06/varying-in-lists.html -
Dynamic where clause with loop statement
Hi all,
is it possible to use a dynamic where clause with a loop statement?
Can you please advise me, how the syntax needs to be?
Thanks for your suggestions,
kind regards, Kathrin!Hi Kathrin,
If u are in ECC 6.0, please go through the code...
REPORT zdynamic_select.
TYPES:
BEGIN OF ty_sales,
vbeln TYPE vbak-vbeln, " Sales document
posnr TYPE vbap-posnr, " Sales document item
matnr TYPE vbap-matnr, " Material number
arktx TYPE vbap-arktx, " Short text for sales order item
kwmeng TYPE vbap-kwmeng, " Order quantity
vkorg TYPE vbak-vkorg, " Sales organization
kunnr TYPE vbak-kunnr, " Sold-to party
netwr TYPE vbak-netwr, " Net Value of the Sales Order
END OF ty_sales.
DATA :
gt_sales TYPE STANDARD TABLE OF ty_sales,
wa_sales TYPE ty_sales.
DATA: ob_select TYPE REF TO cl_rs_where.
DATA: ob_from TYPE REF TO cl_rs_where.
DATA: ob_where TYPE REF TO cl_rs_where,
gv_source TYPE abapsource.
START-OF-SELECTION.
*Step 1 : Prepare the select fields.
PERFORM zf_build_select.
*Step 2 : Build the from clause for the select
PERFORM zf_build_from.
*Step 3 : Build the where clause for the select
PERFORM zf_build_where.
*Step 4 : Execute the dynamic select
SELECT (ob_select->n_t_where)
FROM (ob_from->n_t_where)
INTO CORRESPONDING FIELDS OF TABLE gt_sales
WHERE (ob_where->n_t_where).
LOOP AT gt_sales INTO wa_sales.
WRITE : /5 wa_sales-vbeln,
15 wa_sales-vkorg,
20 wa_sales-kunnr,
40 wa_sales-netwr,
50 wa_sales-posnr,
60 wa_sales-matnr,
70 wa_sales-arktx,
90 wa_sales-kwmeng.
ENDLOOP.
*& Form zf_build_select
FORM zf_build_select .
CREATE OBJECT ob_select.
*Build the table name/field name combination
*Add Sales order header fields
CLEAR gv_source.
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAK'
i_fieldname = 'VBELN'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
CLEAR gv_source.
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAK'
i_fieldname = 'VKORG'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
CLEAR gv_source.
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAK'
i_fieldname = 'KUNNR'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
CLEAR gv_source.
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAK'
i_fieldname = 'NETWR'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
*Add Sales order item fields
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAP'
i_fieldname = 'POSNR'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
CLEAR gv_source.
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAP'
i_fieldname = 'MATNR'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
CLEAR gv_source.
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAP'
i_fieldname = 'ARKTX'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
CLEAR gv_source.
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAP'
i_fieldname = 'KWMENG'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
ENDFORM. " zf_build_select
*& Form zf_build_from
FORM zf_build_from .
CREATE OBJECT ob_from.
*Add opening bracket
CALL METHOD ob_from->add_opening_bracket
CLEAR gv_source.
*Add the join condition.This can be made
*fully dynamic as per your requirement
gv_source = 'VBAK AS VBAK INNER JOIN VBAP AS VBAP'.
*Add the where line
CALL METHOD ob_from->add_line
EXPORTING
i_line = gv_source.
CLEAR gv_source.
*Add the join condition.This can be made
*fully dynamic as per your requirement
gv_source = 'ON VBAKVBELN = VBAPVBELN'.
*Add the where line
CALL METHOD ob_from->add_line
EXPORTING
i_line = gv_source.
*Add the closing bracket
CALL METHOD ob_from->add_closing_bracket
ENDFORM. " zf_build_from
*& Form zf_build_where
FORM zf_build_where .
DATA :
lv_field TYPE REF TO data,
lv_field_low TYPE REF TO data,
lv_field_high TYPE REF TO data.
CREATE OBJECT ob_where.
*Add the field VBELN : Sales Document
*Use this method if you want to assign a single value to a field
*Set the value for VBELN : Sales Document Number
CALL METHOD ob_where->add_field
EXPORTING
i_fieldnm = 'VBAK~VBELN'
i_operator = '='
i_intlen = 10
i_datatp = 'CHAR'
IMPORTING
e_r_field = lv_field.
CALL METHOD ob_where->set_value_for_field
EXPORTING
i_fieldnm = 'VBAK~VBELN'
i_value = '0000120020'.
*Use this method if you want to assign a range of values
*Set a range for the Sales Document number
CALL METHOD ob_where->add_field_between_2values
EXPORTING
i_fieldnm = 'VBAK~VBELN'
i_intlen = 10
i_datatp = 'CHAR'
IMPORTING
e_r_field_low = lv_field_low
e_r_field_high = lv_field_high.
CALL METHOD ob_where->set_2values_for_field
EXPORTING
i_fieldnm = 'VBAK~VBELN'
i_value_low = '0000120020'
i_value_high = '0000120067'.
*Set the 'AND' Clause
CALL METHOD ob_where->add_and.
*Add the field MATNR : Material
CALL METHOD ob_where->add_field
EXPORTING
i_fieldnm = 'MATNR'
i_operator = '='
i_intlen = 18
i_datatp = 'CHAR'
IMPORTING
e_r_field = lv_field.
*Set the value for the Material field
CALL METHOD ob_where->set_value_for_field
EXPORTING
i_fieldnm = 'MATNR'
i_value = '000000000050111000'.
*Set the 'AND' Clause
CALL METHOD ob_where->add_and
*Add the field VKORG
CALL METHOD ob_where->add_field
EXPORTING
i_fieldnm = 'VKORG'
i_operator = '='
i_intlen = 4
i_datatp = 'CHAR'
IMPORTING
e_r_field = lv_field.
*Set the value for VKORG : Sales Organization
CALL METHOD ob_where->set_value_for_field
EXPORTING
i_fieldnm = 'VKORG'
i_value = 'GMUS'.
ENDFORM. " zf_build_where -
Passing values to Dynamic where clause as IN parameter - ADF
Hi,
I am trying to get the Dynamic where clause query output something like below,
select * from EMP where emp_id IN(200,203,204)
How to pass values from setWhereCluase(emp_id,????)
Thanks,I'd go about this a little differently (probably not the best way):
1. Create view object lk_department (lookup). In the query add a union with something like "select null as ID, 'All' as name' from dual;". This adds a null value that they can select by leaving the combo box on "All". Add a 'order by id" so the null value is the first one. When creating the combo box you want it set to navigation mode, so select the whole viewobject from the data palette rather a specific field.
2. Create a jTextField for the "Jobs" field.
3. Create an application module method that does something like:
public void filterEmployees(String job){
ViewObject vo_departments = findViewObject("lk_departments");
ViewObject vo_employees = findViewObject("employees");
String wc = "1 = 1 ";
String wc = " and job like '%"+job+"%'"
if (vo_departments.getCurrentRow().getAttribute("Id") != null) {wc += "and department_id = "+vo_departments.getCurrentRow().getAttribute("Id");}
vo_employees.setWhereClause(wc);
vo_employees.executeQuery();
this.sync;
4. In your Jclient app, you just need to call the method of your appmodule and insert the string from the textbox, using code similar to this:
AppModule b = (AppModule)panelBinding.getApplicationModule();
b.filterEmployees(jTextField.getText());
I didn't test this code, but that's how I go about the same thing. -
Dynamic where clause problem?
Hi all,
I am using 4 parameters for the attrition rate report of an employee on the selection screen.
Level
Grade
Position
Salary Range (pa0008-ansal)
i have filled the values of level, grade, position, from database tables at the initialization event.
And for the salary range i hardcoded them to 0-5000, 5001-10000 etc.. and so on.
and then showed all 4 parameters are listbox on the selection screen.
now the first 3 parameters are from infotype pa0001 and the last is from pa0008.
Now I want to select pernr, persg ,persk ,plans, begda ,endda fields from infotype pa0001, and 'ansal' field from pa0008 , with the help of a dynamic where clause, is it possible, because here it might be needed for a join as well.
Please help me out with some sample coding help.
Regards
TarunDATA: lv_query TYPE string.
lv_query = ' '.
IF position IS NOT INITIAL.
IF lv_query IS NOT INITIAL.
CONCATENATE lv_query ' and p1~plans eq position ' '' INTO lv_query.
ELSE.
CONCATENATE ' p1~plans eq position ' '' INTO lv_query.
ENDIF.
ENDIF.
IF grade IS NOT INITIAL.
IF lv_query IS NOT INITIAL .
CONCATENATE lv_query ' and p1~PERSK eq grade ' '' INTO lv_query.
ELSE.
CONCATENATE ' p1~PERSK eq grade ' '' INTO lv_query.
ENDIF.
ENDIF.
IF level IS NOT INITIAL.
IF lv_query IS NOT INITIAL .
CONCATENATE lv_query ' and p1~PERsg eq level ' '' INTO lv_query.
ELSE.
CONCATENATE ' p1~PERsg eq level ' '' INTO lv_query.
ENDIF.
ENDIF.
IF sal_slab IS NOT INITIAL.
SELECT pernr ansal begda endda FROM pa0008 INTO CORRESPONDING FIELDS OF TABLE lt_st_p8 WHERE ansal = sal_slab.
*IF lv_query IS NOT INITIAL .*
*CONCATENATE lv_query ' and p8~ansal le sal_slab ' '' INTO lv_query.*
*ELSE.*
*CONCATENATE ' p8~ansal le sal_slab ' '' INTO lv_query.*
*ENDIF.*
ENDIF.
SELECT p1~pernr
p1~persg p1~persk p1~plans p1~begda p1~endda
p8~ansal
INTO CORRESPONDING FIELDS of TABLE lt_st_p1_p8
FROM pa0001 AS p1 JOIN pa0008 AS p8 ON p1~pernr = p8~pernr
WHERE (lv_query) .
<Added code tags>
Now in case of salary slab, i have ranges like 0-5000 , 5001-10000 and so on and I showed it as a listbox on sel. screen.
So how can I read the figure after the '-'?????
And also review, if for the previous 3 parameters it is correct, or it can be shortened and accurated.
Edited by: Suhas Saha on Dec 28, 2011 1:44 PM -
Loop with dynamic where clause
hi,
In a program we need to use a loop into an internal table with a where condition is decided on run time.
"Select" from database table is using dynamic where clause and it is working fine.
For the loop part does any one have any idea on this? if we can have dynamic where clause in a loop into internal tab?
ThanksHi,
You can't use 'loop where' dynamically .
Have you already tried to use Ranges and CHECK statement?
Like:
First mount range options;
Loop at <table>.
Check using the range.
endloop.
Maybe it's works for you !!
Marcelo Ramos
Maybe you are looking for
-
Lab-PC-1200 not responding in Win2000
I was using a functioning system using a Lab-PC-1200 DAQ card and Win98 and LabView 5.1.1. I upgraded the computer to Win2000, and now I am having problems. When I first run my application, everything seems fine (I read my analog inputs from the card
-
my ipod was stolen and i finnaly was able to get into my account after they changed the password is there a way i can fid the locaition of my ipod even if it has died ?
-
Hi all, I am working on a new experimental set up for my thesis and I want to control the whole process using LabView 8. The set up has two chambers each one connected to a capacitance manometer (http://www.mksinst.com/cgi-bin/product.exe?pid=626a) a
-
How to implement Value Help for Product ID?
Hi, I have a Z-Component where I want to use the value help of the Product ID. I found several components which use this value help for Products but I can't get it to work in my component properly. Does anybody have a short tutorial how I need to pro
-
Hi, My application deployed on azure, and I managed all my file to blob storage. When i created container with public permission then it accessible for all anonymous users. When i hit URL of file (blob) from different browser, then i will get that fi