Appending a dynamic where clause in VO
Hi All
I am trying append a where clause dnamically to a VO
The query is
SELECT DISTINCT
pvsa.org_id AS OrgId,
GECMPoVendorsEO.VENDOR_ID AS SupplierId,
GECMPoVendorsEO.VENDOR_NAME AS SupplierName,
GECMPoVendorsEO.STANDARD_INDUSTRY_CLASS AS StdIndustryClass,
GECMPoVendorsEO.END_DATE_ACTIVE AS SupplierInactiveDate,
GECMPoVendorsEO.SEGMENT1 AS SupplierNumber
FROM PO.PO_VENDORS GECMPoVendorsEO,
po_vendor_sites_all pvsa
WHERE GECMPoVendorsEO.vendor_id = pvsa.vendor_id
AND DECODE('Y','Y', NVL(GECMPoVendorsEO.end_date_active,SYSDATE+1), SYSDATE+1) >= SYSDATE
AND DECODE('Y','Y', NVL(pvsa.inactive_date,SYSDATE+1), SYSDATE+1) >= SYSDATE
When the query is executed by OA Framework
it changes it into
SELECT * FROM (
SELECT DISTINCT
pvsa.org_id AS OrgId,
GECMPoVendorsEO.VENDOR_ID AS SupplierId,
GECMPoVendorsEO.VENDOR_NAME AS SupplierName,
GECMPoVendorsEO.STANDARD_INDUSTRY_CLASS AS StdIndustryClass,
GECMPoVendorsEO.END_DATE_ACTIVE AS SupplierInactiveDate,
GECMPoVendorsEO.SEGMENT1 AS SupplierNumber
FROM PO.PO_VENDORS GECMPoVendorsEO,
po_vendor_sites_all pvsa
WHERE GECMPoVendorsEO.vendor_id = pvsa.vendor_id
AND DECODE('Y','Y', NVL(GECMPoVendorsEO.end_date_active,SYSDATE+1), SYSDATE+1) >= SYSDATE
AND DECODE('Y','Y', NVL(pvsa.inactive_date,SYSDATE+1), SYSDATE+1) >= SYSDATE
) QRSLT
WHERE UPPER(SupplierName) like '%DEL%' AND OrgId = 468
and i need to append something like
WHERE UPPER(SupplierName) like '%DEL%' AND OrgId = 468
This clause when appended executes fine
however when i try to append
UPPER(pvsa.ATTRIBUTE12) like 'CBSI' AND OrgId = 468
then it gives me error that pvsa.ATTRIBUTE12 is invalid identifier
I need to select the value in select clause to use it outside in the where clause
but i cant select it in query since it gives me multiple values that i dont want
Have anyone faced similar issue
Is there any workaround possible for this?
Please help me out
Thanks
Husain
I have come across this issue many times.
OAF framework aliases the design time query like a result set (QRSLT, consider it like a temp table). In SQL terms, the query after appending the where clause becomes like
SELECT * from QRSLT WHERE UPPER(pvsa.ATTRIBUTE12) like 'CBSI' AND OrgId = 468.
But the ATTRIBUTE12 (also pvsa alias) are not defined in the above query and the query gives an error.
One work around I have used is to use Bind Variables with the query at design time.
Hope this helps'
Srini
Similar Messages
-
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 "delete itab where..." variant
Hi, I need to be able to delete the contents of an internal table based on a dynamic where clause. I don't want to loop through the entire table to test each record. Since the delete statement doesn't seem to allow a dynamic "where" clause I am trying to use a macro. I can't get the macro to work either.
I get the following error in my syntax check:
Statement concluding with "...FINAL_STATEMENT" ended unexpectedly.
Is there any way to get this macro to pass the syntax text or accomplish the dynamic delete?
MACRO TO FILTER OUT UNWANTED RECORDS (RETAIL OUTLETS)
DEFINE DELOUT.
DELETE MY_ITAB WHERE &1.
END-OF-DEFINITION.
Example FINAL_STATEMENT = ( ZRRDIVIS = '4' )
USING MACRO DOES NOT PASS SYNTAX CHECK
DELOUT FINAL_STATEMENT.Well, if you really need this kind of functionality, here is a code sample that I just threw together that would work. A lot of code for one little delete statement though.
report zrich_0001 .
data: begin of itab occurs 0,
fielda type c,
fieldb type c,
fieldc type c,
end of itab.
data: where_clause type string.
class lcl_source definition.
public section.
types: t_source(72).
class-data: routine(32) value 'TEMP_ROUTINE',
program(8),
message(128),
line type i.
class-data: isource type table of t_source,
xsource type t_source.
class-methods: execute_source importing im_clause type string.
endclass.
start-of-selection.
* Build the itab.
itab-fielda = '1'.
itab-fieldb = '2'.
itab-fieldc = '3'.
append itab.
itab-fielda = '3'.
itab-fieldb = '2'.
itab-fieldc = '1'.
append itab.
* Set the where clause
where_clause = 'FIELDA = ''1''.'.
* call the delete statement.
call method lcl_source=>execute_source
exporting
im_clause = where_clause.
* CLASS lcl_source IMPLEMENTATION
class lcl_source implementation.
method execute_source.
xsource = 'REPORT ZTEMP_REPORT.'.
insert xsource into isource index 1.
xsource = 'FORM & tables itab.'.
replace '&' with routine into xsource.
insert xsource into isource index 2.
xsource = 'Data: begin of xitab occurs 0,'.
append xsource to isource.
xsource = 'fielda type c,'.
append xsource to isource.
xsource = 'fieldb type c,'.
append xsource to isource.
xsource = 'fieldc type c,'.
append xsource to isource.
xsource = 'end of xitab.'.
append xsource to isource.
xsource = 'xitab[] = itab[].'.
append xsource to isource.
concatenate 'DELETE xITAB WHERE' im_clause into xsource
separated by space.
append xsource to isource.
xsource = 'ENDFORM.'.
append xsource to isource.
generate subroutine pool isource name program
message message
line line.
if sy-subrc = 0.
perform (routine) in program (program) tables itab.
else.
write:/ message.
endif.
endmethod.
endclass.
Regards,
Rich Heilman -
Dynamic itab with Dynamic Where clause
Hi, Dear All,
Can someone provide a code extract for Dynamic where clause, i had already done with dynamic itab for a given set of fields, and i need to add where clause dynamically for a given field for a given range of values.
select (i_fields) into table <dyn_table>
from (p_table)
where (v_where).
In the above except the where clause, everything is done. Please help me.
with best regards
MaheshHi,
here is the code extract for your reference.Pl. correct me.
with regards
REPORT Z_DYN_ITAB .
TYPE-POOLS: SLIS.
DATA:NAME(100) TYPE C.
TYPES: BEGIN OF ITAB_TYPE,
WORD(20),
END OF ITAB_TYPE.
DATA: ITAB TYPE STANDARD TABLE OF ITAB_TYPE WITH HEADER LINE.
DATA: vg_fields(255) TYPE c,
i_fields LIKE TABLE OF vg_fields.
DATA: it_fcat TYPE slis_t_fieldcat_alv,
is_fcat LIKE LINE OF it_fcat,
ls_layout TYPE slis_layout_alv.
DATA: it_fieldcat TYPE lvc_t_fcat,
is_fieldcat LIKE LINE OF it_fieldcat.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: dy_table type ref to data.
data: dy_line type ref to data,
xfc type lvc_s_fcat.
DATA: v_where TYPE string, " Variable for storing where clause.
v_dynamic(18) TYPE c, "variable to store select option datatype
o_field TYPE REF TO cx_root," object to catch exception
text TYPE string. "string variable to store exception text.
CONSTANTS: c_var(15) TYPE c VALUE ' IN S_RANGE'.
selection-screen begin of block b1 with frame.
parameters: p_table(30) type c default 'T001',
p_name(100) type c,
p_field(10) TYPE c. " Parameter to capture field name.
SELECT-OPTIONS: s_range FOR v_dynamic. " Select-option for range.
selection-screen end of block b1.
start-of-selection.
NAME = p_name.
SPLIT NAME AT ',' INTO TABLE ITAB.
LOOP AT ITAB.
is_fcat-fieldname = itab-word.
is_fcat-tabname = p_table.
APPEND is_fcat to it_fcat.
ENDLOOP.
LOOP AT it_fcat INTO is_fcat.
is_fieldcat-fieldname = is_fcat-fieldname.
is_fieldcat-tabname = is_fcat-tabname.
APPEND is_fieldcat TO it_fieldcat.
CONCATENATE is_fieldcat-tabname is_fieldcat-fieldname INTO
vg_fields SEPARATED BY '~'.
APPEND vg_fields TO i_fields.
ENDLOOP.
perform create_dynamic_itab.
perform get_data.
Create dynamic internal table and assign to FS
form create_dynamic_itab.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fieldcat
importing
ep_table = dy_table.
assign dy_table->* to <dyn_table>.
Create dynamic work area and assign to FS
create data dy_line like line of <dyn_table>.
assign dy_line->* to <dyn_wa>.
endform.
form get_data.
Select Data from table.
CONCATENATE p_field c_var INTO v_where.
TRY.
select (i_fields) into table <dyn_table>
from (p_table)
where (v_where).
if sy-dbcnt = 0.
write : text-t02.
endif.
*Write out data from table.
Loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
Exception Catching.
CATCH cx_root INTO o_field.
text = o_field->get_text( ).
Calling Function to give information message regarding Exception
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = text-t03
txt1 = text
txt2 = text-t04.
TXT3 = ' '
TXT4 = ' '
LEAVE TO LIST-PROCESSING.
ENDTRY.
endform. -
Dynamic IF statement...like dynamic where clause...
Hi,
I know how to do a dynamic where clause by putting (varname) like shown below -
select * from cust_mstr where (varname).
Can I do it something like this in IF statement.
if (varname).
endif.
The varname will have different conditions.
Your help will be greately appreciated.
Regards,
SumeHello Sume,
I would try to use an approach using ranges:
DATA:
gv_material TYPE matnr.
gv_material = '292-392-392-202'.
IF gv_material = '292-392-392-202'.
WRITE: / `Static check:`, gv_material, `matches!`.
ELSE.
WRITE: / `Static check:`, gv_material, `doesn't match!`.
ENDIF.
PERFORM dynamic_check
USING
gv_material
'I'
'EQ'
'292-392-392-202'
space.
PERFORM dynamic_check
USING
gv_material
'I'
'CP'
'*292*'
space.
PERFORM dynamic_check
USING
gv_material
'I'
'CP'
'*ABC*'
space.
*& Form dynamic_check
FORM dynamic_check USING pv_value TYPE clike
pv_sign TYPE ddsign
pv_option TYPE ddoption
pv_low TYPE string
pv_high TYPE string.
DATA lr_range TYPE RANGE OF string.
DATA ls_range LIKE LINE OF lr_range.
ls_range-sign = pv_sign.
ls_range-option = pv_option.
ls_range-low = pv_low.
ls_range-high = pv_high.
APPEND ls_range TO lr_range.
IF pv_value IN lr_range.
WRITE: / `Dynamic check matches: `, pv_value, ls_range-sign, ls_range-option, ls_range-low, ls_range-high.
ELSE.
WRITE: / `Dynamic check doesn't match:`, pv_value, ls_range-sign, ls_range-option, ls_range-low, ls_range-high.
ENDIF.
ENDFORM. "dynamic_check
For values of SIGN and OPTION check the values of the domains used in the data elements of the parameters of form dynamic_check.
Output is like:
Static check: 292-392-392-202 matches!
Dynamic check matches: 292-392-392-202 I EQ 292-392-392-202
Dynamic check matches: 292-392-392-202 I CP *292*
Dynamic check doesn't match: 292-392-392-202 I CP *ABC*
Edited by: Alejiandro Sensejl on Aug 11, 2010 8:23 PM:
Unfortunately I don't know why the code-tag isn't working, I sent a mail to SCN tech-team about this... Sorry, but you have to copy the code somehow to have a look at it -
Dynamic WHERE clause in SELECT statement
Hi,
I need to extract (SELECT) all the products in different salesorganizations. Since a product can be available in more than 1 salesorg I have created several properties in the PRODUCT dimension - 1 for each salesorganization (naming: Sxxxx where xxxx is the salesorganization number).
Since I need to prefix the salesorganization property with an "S" I have created a property on the SALESORG dimension called SALESORG.
Therefore I need to create a dynamic WHERE clause in the SELECT statement. Currently my script is:
*SELECT(%SORG%, "[SALESORG]",SALESORG, [ID]=%SALESORG_SET%)
*SELECT(%PROD%, "[ID]",PRODUCT, [%SORG%]="X")
My first SELECT find the Sxxx (equal to the property I need in the PRODUCT dimension). My second SELECT uses the variable in the first SELCT statement to use the correct property for the WHERE clause.
Unfortunately the code is not validated - any suggestions?
/LarsHi Lars,
If you run it from a DM package without validating it, does it still work? I would bet it does.
If this is the case I would open a message with SAP (it would be an enhancement request). Until they fix the validation code, you would just have to live with the script not validating.
Cheers,
Ethan -
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. -
How to add a dynamic where clause for a sql based VO with group by query?
Hi,
Here is my case, I have a sql query based VO with the query like "select status, count(*) StatusCount from my_table group by status". Now I used the following java code trying to dynamically add the where clause to my VO to filter the rows based the type attribute in my DB table.
vo.setWhereClause("type='MyType1' ");
vo.executeQuery();
Then I got the sql syntax error. Looks like the ADF has added the where clause to the end of my sql so my sql becomes "select status, count(*) StatusCount from my_table group by status where type='MyType1' ". But what I expected was the correct syntax "select status, count(*) StatusCount from my_table where type='MyType1' group by status".
Does anyone know if this is an ADF bug? Or is there any other way to achieve my goal?
Thanks,
Chunyang
Edited by: Chunyang on Dec 13, 2012 9:09 PMHi,
When you use setWhereClause on the VO, it is applied on top of the VO query. I.e, assume your VO has the following query.
select empno, ename from empNow, if you apply the where clause programatically, only the two attributes that you are using in the select statement could be used. I.e
select * from (select empno, ename from emp) where ename='KING' - VALID
select * from (select empno, ename from emp) where deptno=10 - INVALID (because the inner query - the one you've defined as query for your vo does not have deptno attribute selected)If you would need to set a dynamic where clause, you need to make them available in your select statement / use bind variables.
-Arun -
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
Maybe you are looking for
-
How can I make a Java program pyramid using for loops??
Hi guys, so I'm stuck with my program here... I don't know how to make it work, and i've been trying really hard.. So now i give up and need some guidance.. Please help me here. Your job in this assignment is to write programs to solve each of these
-
If my Tiger installation fails, can I go back to 10.3.9?
With so many of you having Tiger installation issues, I figured that this was worth asking. I have no problems with my current system, but need to upgrade to use certain software. If I run into major problems, can I undo the 10.4.6 install and go bac
-
I have a very short video that plays in the middle of a slide (audio before, during and after video on same slide). The slide published fine in Presenter 8 but now in 9 it does not work. When it is time in the slide for the video the slide just sta
-
Hi! Is it possible to have a sync-async communication like this: receive - open s/a bridge send (async idoc with acknowledgement in return) send - close s/a bridge? or do I have to use a receive step after the send step in the middle? I am trying to
-
Miro hitting inventory and price difference
Dear All, I would like to seek advice of the posting during MIRO on point 4 and 5 why there is a hitting on inventory account and price difference of the amount given? How system get the amount in inventory account and price difference account? Reall