Where condition in select query
my requirement is this. I want to fetch some records
from DB table. The field objnr has 12 characters.
i will supply a substring of this field. the substring
starts at the 3rd location of field.
SELECT objnr FROM cosp INTO TABLE gt_itab
WHERE objnr like srch_str.
how to do this? could u give me a possible solution?
Then you're going to have to go at it this way
TABLES: cosp.
DATA:
BEGIN OF gt_itab OCCURS 0,
objnr LIKE cosp-objnr,
END OF gt_itab.
DATA:
wk_objnr LIKE cosp-objnr,
srch_str(22) VALUE '1000',
ss_len TYPE i.
START-OF-SELECTION.
ss_len = strlen( srch_str ).
SELECT objnr FROM cosp INTO gt_itab-objnr.
CHECK gt_itab-objnr+2(ss_len) = srch_str.
APPEND gt_itab.
ENDSELECT.
Or this way.
TABLES: cosp.
DATA:
BEGIN OF gt_itab OCCURS 0,
objnr LIKE cosp-objnr,
END OF gt_itab.
DATA:
cntlarea(22) TYPE c VALUE '1000',
wk_objnr LIKE cosp-objnr,
srch_str(50),
ss_len TYPE i.
START-OF-SELECTION.
CONCATENATE '%' cntlarea '%' INTO srch_str.
ss_len = strlen( cntlarea ).
SELECT objnr FROM cosp INTO gt_itab-objnr
WHERE objnr LIKE srch_str.
CHECK gt_itab-objnr+2(ss_len) = cntlarea.
APPEND gt_itab.
ENDSELECT.
Edited by: Paul Chapman on May 29, 2008 8:33 AM
Similar Messages
-
URGENT: To change the where condition in select query at runtime ?
Hi,
I have to develop a report, 4 which I have created a selection screen with 7 Input Parameters whose value is to be filled by the user while executing the report.
On the basis of this I do the desired selection of output.
But the problem is that how do I write my select Query(where condition) if the user enetrs only 2 Input parameters or 3 or whatever he feels like.
Pls help me out...hi,
check this sample code.
Here i am populating where condition at runtime.
DATA: V_WHERE TYPE STRING.
SELECTION-SCREEN BEGIN OF BLOCK INPUT WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_VBELN FOR VBAK-VBELN,
S_ERDAT FOR VBAK-ERDAT.
SELECTION-SCREEN END OF BLOCK INPUT.
START-OF-SELECTION.
PERFORM POPULATE_WHERE.
PERFORM GET_VBAK_DATA.
*& Form POPULATE_WHERE
* Populate Where
FORM POPULATE_WHERE .
IF NOT S_ERDAT[] IS INITIAL.
CONCATENATE 'VBELN IN S_VBELN'
'AND'
'ERDAT IN S_ERDAT'
INTO V_WHERE
SEPARATED BY SPACE.
ELSE.
V_WHERE = 'VBELN IN S_VBELN'.
ENDIF.
ENDFORM. " POPULATE_WHERE
*& Form GET_VBAK_DATA
* GET VBAK DATA
FORM GET_VBAK_DATA .
SELECT VBELN
ERDAT
VBTYP
NETWR
WAERK
VKORG
VTWEG
SPART
INTO CORRESPONDING FIELDS OF TABLE IT_VBAK
FROM VBAK
WHERE VBELN IN S_VBELN
AND ERDAT IN S_ERDAT.
WHERE (V_WHERE).
endform.
Regards
Sailaja. -
Regarding dynamically assigning the where clause to select query
hi,
Please send the code regarding how to dynamically assign the where clause to select query.
thanks in advanceSELECT <fileds>
INTO TABLE itab
FROM dbase
WHERE condition. -
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). -
How to dynamically add field name in where clause of select query in web dynpro?
Hello,
Can any body tell me how i can use select query with dynamic wheere condition.
i have a requirement like there are multiple input fields and i want to select data from two database
and condition may vary .Hi
In the where clause you need to write like
WHERE NAME LIKE 'DE%'
Regards
Sudheer -
How to use string operation in where clause of select query
Hello All,
I just want to know how can i write a restriction in select query saying retrive data only begins with name "DE*".
Explaination: If my table has records and names starts with character then i want to write a query to fetch all the records in which names starts with DE*.
Thanks in advance for your quick reply...
Dev.Hi
In the where clause you need to write like
WHERE NAME LIKE 'DE%'
Regards
Sudheer -
How to formulate where clause in select query at runtime..??
I am facing a problem..
I have to generate a select query during runtime..For Ex: when user selects a row in an alv report, particular date field is to be read and another report is to be opened for that data..
I know how to make drill down report but my problem is concatenating date field...
Plz tell a solution....Hi,
Try like this....
refresh : gt_tvarvc_temp[].
gt_tvarvc_temp[] = lt_tvarvc[].
loop at gt_tvarvc_temp into gs_tvarvc_temp
where name = 'CREDIT_MEMO_DOC_TYPE'.
r_blart-sign = gs_tvarvc_temp-sign.
r_blart-option = gs_tvarvc_temp-opti.
r_blart-low = gs_tvarvc_temp-low.
append r_blart.
clear r_blart.
endloop.
concatenate 'BLART IN ' 'r_blart' into lv_condition
separated by space.
if not lv_customer_cond is initial.
if lv_condition is initial.
concatenate lv_customer_cond lv_condition
into lv_condition separated by space.
else.
concatenate lv_condition 'AND' lv_customer_cond
into lv_condition separated by space.
endif.
endif.
select bukrs belnr gjahr appending corresponding fields
of table lt_potential_credits
from bsid
where (lv_condition).
Hope its helps -
Please help - NE where condition in SELECT statement
Dear experts,
I am posting a section of my codes here for your review on performance tuning.
In my second select statement, I used a "NE" where condition. I read somewhere in this forum that using "NE" where condition is not a good decision for improving codes' performance. What alternatives can I have to achieve the same purpose? May I use "NOT IN" here instead? Or do I use a LOOP for this (a rather manual way)?
Just to let you all know that I still consider myself quite inexperienced in ABAP - please also let me know how I can better improvise my programming techniques in the posted codes here too.
I will be most glad to provide you with further information if needed - just let me know.
Many THANKS in advance!
IF p_noncis = 'X'. " Non CIS category of spend selected
" zfi_cis_mat_grp is a bespoke table that stores all CIS MATKL
" and it has two fields only - MANDT and MATKL
SELECT * FROM zfi_cis_mat_grp
INTO TABLE gt_cis_mat_grp.
IF gt_cis_mat_grp IS NOT INITIAL.
SELECT ebeln
ebelp
matkl
FROM ekpo
INTO TABLE gt_ekpo
FOR ALL ENTRIES IN gt_cis_mat_grp
WHERE matkl NE gt_cis_mat_grp-matkl. " NE where condition - is this OK?
ENDIF.
IF gt_ekpo IS NOT INITIAL.
IF s_sakto IS NOT INITIAL.
SELECT ebeln
ebelp
sakto
FROM ekkn
INTO TABLE gt_ekkn
FOR ALL ENTRIES IN gt_ekpo
WHERE ebeln = gt_ekpo-ebeln AND
ebelp = gt_ekpo-ebelp AND
sakto IN s_sakto.
IF gt_ekkn IS NOT INITIAL.
SELECT bukrs
lifnr
belnr
budat
cpudt
xblnr
ebeln
ebelp
zfbdt
zterm
zlspr
FROM bsik
INTO TABLE gt_bsik
FOR ALL ENTRIES IN gt_ekkn
WHERE bukrs IN s_bukrs AND
lifnr IN s_lifnr AND
budat IN s_budat AND
cpudt IN s_cpudt AND
xblnr IN s_xblnr AND
ebeln = gt_ekkn-ebeln AND
ebelp = gt_ekkn-ebelp AND
qsskz NE ''.
ENDIF.
ELSE.
SELECT bukrs
lifnr
belnr
budat
cpudt
xblnr
ebeln
ebelp
zfbdt
zterm
zlspr
FROM bsik
INTO TABLE gt_bsik
FOR ALL ENTRIES IN gt_ekpo
WHERE bukrs IN s_bukrs AND
lifnr IN s_lifnr AND
budat IN s_budat AND
cpudt IN s_cpudt AND
xblnr IN s_xblnr AND
ebeln = gt_ekpo-ebeln AND
ebelp = gt_ekpo-ebelp AND
qsskz NE ''.
ENDIF.
ENDIF.
ELSE. " Complete list of category of spend selected
SELECT bukrs
lifnr
belnr
budat
cpudt
xblnr
ebeln
ebelp
zfbdt
zterm
zlspr
FROM bsik
INTO TABLE gt_bsik
WHERE bukrs IN s_bukrs AND
lifnr IN s_lifnr AND
budat IN s_budat AND
cpudt IN s_cpudt AND
xblnr IN s_xblnr AND
qsskz NE ''.
ENDIF.Hi,
If you want to remove th NE option then try this way..
SELECT bukrs
lifnr
belnr
budat
cpudt
xblnr
ebeln
ebelp
zfbdt
zterm
zlspr
FROM bsik
INTO TABLE gt_bsik
WHERE bukrs IN s_bukrs AND
lifnr IN s_lifnr AND
budat IN s_budat AND
cpudt IN s_cpudt AND
xblnr IN s_xblnr .
IF SY-SUBRC EQ 0.
Delete gt_bsik where qsskz EQ ' '.
ENDIF. -
How to include conditions in select query
i want to write a select query wherein plants have to to be fetched from table vekp
and if it is a plant then the set movement type to 999 else leave for exiting.please help me on this>
deep shikha wrote:
> (This is module pool programming)
what is modulepool programming doing in form printing forum.
Please use appropriate forum next time.
кu03B1ятu03B9к -
What value we need to pass as parameter in where clause in select query
Hi ALL,
I have written following query, it was executing fine and returning me all the rows with search criteria.
SELECT *
FROM
PRTY_RQST PR
JOIN BUSN_APPLC BIAP ON BIAP.BUSN_APPLC_ID = PR.BUSN_APPLC_ID
JOIN INTN_STATS INSTS ON INSTS.INTN_STATS_ID = PR.INTN_STATS_ID
JOIN INTN_PROCES_TYP INTPTY ON INTPTY.INTN_PROCES_TYP_ID = PR.INTN_PROCES_TYP_ID
LEFT JOIN RQST_TYP RQSTYP ON RQSTYP.RQST_TYP_ID = PR.RQST_TYP_ID
JOIN ADDTN_RQST_INFO ADTINF ON PR.PRTY_RQST_ID = ADTINF.PRTY_RQST_ID
JOIN ADDTN_INFO_KEY_TYP ADDKEY ON ADTINF.ADDTN_INFO_KEY_TYP_ID = ADDKEY.ADDTN_INFO_KEY_TYP_ID
JOIN PRTY_KEY PRTKEY ON PR.PRTY_RQST_ID = PRTKEY.PRTY_RQST_ID
JOIN PRTY_KEY_TYP PRKYTP ON PRTKEY.PRTY_KEY_TYP_ID = PRKYTP.PRTY_KEY_TYP_ID
WHERE (BIAP.BUSN_APPLC_NM = 'bpel')
AND (INTPTY.INTN_PROCES_TYP_NM = 'FulfillmentOrder')
AND (PR.UPDT_BY = 'update3')
AND (INSTS.INTN_STATS_NM = 'Submitted')
AND (PR.CHLD_RQST_IND = 'N')
AND (PR.TRACK_RQST_IND = 'Y')
AND (RQSTYP.RQST_TYP_NM = 'PensionPortfolioRebalance')
AND (RQSTYP.RQST_CLASS_NM = 'Composite')
AND (PRKYTP.PRTY_KEY_TYP_NM = 'NPIN')
AND (PRTKEY.PRTY_TYP_VAL = '101101' )
AND (ADDKEY.ADDTN_INFO_KEY_TYP_NM = 'PlanNumber')
AND (ADTINF.ADDTN_RQST_TYP_VALUE = 'TBMBUpdated');
My question here is i don't want pass the value for BIAP.BUSN_APPLC_NM, still want to get the values for remaing conditions. what value i need to pass here.
I tried Null it giving me no rows. can some one help me on this.
Thank you in advance.
Vijay933325 wrote:
thank you,
since it is search criteria. I have to use OR instead of AND. this resolved my problem.
SELECT *
FROM
PRTY_RQST PR
JOIN BUSN_APPLC BIAP ON BIAP.BUSN_APPLC_ID = PR.BUSN_APPLC_ID
JOIN INTN_STATS INSTS ON INSTS.INTN_STATS_ID = PR.INTN_STATS_ID
JOIN INTN_PROCES_TYP INTPTY ON INTPTY.INTN_PROCES_TYP_ID = PR.INTN_PROCES_TYP_ID
LEFT JOIN RQST_TYP RQSTYP ON RQSTYP.RQST_TYP_ID = PR.RQST_TYP_ID
JOIN ADDTN_RQST_INFO ADTINF ON PR.PRTY_RQST_ID = ADTINF.PRTY_RQST_ID
JOIN ADDTN_INFO_KEY_TYP ADDKEY ON ADTINF.ADDTN_INFO_KEY_TYP_ID = ADDKEY.ADDTN_INFO_KEY_TYP_ID
JOIN PRTY_KEY PRTKEY ON PR.PRTY_RQST_ID = PRTKEY.PRTY_RQST_ID
JOIN PRTY_KEY_TYP PRKYTP ON PRTKEY.PRTY_KEY_TYP_ID = PRKYTP.PRTY_KEY_TYP_ID
WHERE (BIAP.BUSN_APPLC_NM = null )
OR (INTPTY.INTN_PROCES_TYP_NM = 'FulfillmentOrder')
OR (PR.UPDT_BY = 'update3')
OR (INSTS.INTN_STATS_NM = 'Submitted')
OR (PR.CHLD_RQST_IND = 'N')
OR (PR.TRACK_RQST_IND = 'Y')
OR (RQSTYP.RQST_TYP_NM = 'PensionPortfolioRebalance')
OR (RQSTYP.RQST_CLASS_NM = 'Composite')
OR (PRKYTP.PRTY_KEY_TYP_NM = 'NPIN')
OR (PRTKEY.PRTY_TYP_VAL = '101101' )
OR (ADDKEY.ADDTN_INFO_KEY_TYP_NM = 'PlanNumber')
OR (ADTINF.ADDTN_RQST_TYP_VALUE = 'TBMBUpdated');
AND (ADTINF.ADDTN_RQST_TYP_VAL_DT ='06-JUN-12 04.18.56.000000000 PM')
AND (ADTINF.ADDTN_RQST_TYP_VAL_NUM ='123123') ;
once again thank you all.But that's a completely different query than what was in the original post -
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 -
Hi Experts,
I want to fetch data from PAYR table where ZALDT date falls in the date range(s_date) or VOIDD date falls in the date range.
Which one is correct?
SELECT ZBUKR
CHECT
ZALDT
VOIDD
into table T_PAYR
from PAYR
where CHECT in s_chect
and ZALDT in s_date
or VOIDD in s_date.
OR
SELECT ZBUKR
CHECT
ZALDT
VOIDD
into table T_PAYR
from PAYR
where CHECT in s_chect
and ( ZALDT in s_date or VOIDD in s_date ).
Regards,
Sangeeta.hi,
Second one is correct
Issue resolved,please close the thread.
Thnks
Sahil -
Hi,Please help to get the output. Thanks.
create table #Real (R1 numeric, R2 numeric, R3 char(10), R4 numeric, R5 char(10))
Insert into #real values (111,900,'PN-UFT',10, 'PN') --R2 and R3 are same for this group
Insert into #real values (112,900,'PN-UFT',10, 'PN')
Insert into #real values (113,900,'PN-UFT',20, 'PN')
Insert into #real values (114,900,'PN-UFT',20, 'PN')
Insert into #real values (115,901,'PS-UFT',10, 'PS') --R2 and R3 are same for this group
Insert into #real values (116,901,'PS-UFT',10, 'PS')
Insert into #real values (117,901,'PS-UFT',20, 'PS')
Insert into #real values (118,901,'PS-UFT',20, 'PS')
Insert into #real values (119,902,'PT-UFT',10, 'PS') --R2 and R3 are same for this group
Insert into #real values (120,902,'PT-UFT',10, 'PS')
Select * from #real where (If R4=20 then pick these records else pick R4=10 records)
Output should be:
R1 R2 R3 R4 R5
113 928 PN-UFT 20 PN
114 942 PN-UFT 20 PN
117 894 PS-UFT 20 PS
118 837 PS-UFT 20 PS
119 823 PS-UFT 10 PS
120 843 PS-UFT 10 PSI need to Ignore the rows where R4=10 because I need R4=20 but if R4=20 doesn't exist then should pick R4=10.
Eaxmple-1: Here R4 has 10 and 20 so should pick records of '20''
create table #Real (R1 numeric, R2 numeric, R3 char(10), R4 numeric, R5 char(10))
Insert into #real values (111,900,'PN-UFT',10, 'PN')
Insert into #real values (112,900,'PN-UFT',10, 'PN')
Insert into #real values (113,900,'PN-UFT',20, 'PN')
Insert into #real values (114,900,'PN-UFT',20, 'PN')
My desired output is:
R1 R2 R3 R4 R5
113 900 PN-UFT 20 PN
114 900 PN-UFT 20 PN
Eaxmple-2: Here R4 has not records of ''20'' so should pick the record of ''10"
create table #Real (R1 numeric, R2 numeric, R3 char(10), R4 numeric, R5 char(10))
Insert into #real values (115,901,'PS-UFT',10, 'PS')
Insert into #real values (116,901,'PS-UFT',10, 'PS')
My desired output for this is:
R1 R2 R3 R4 R5
115 901 PS-UFT 10 PS
116 901 PS-UFT 10 PS -
Dynamis where Condition using select-options
Hi All,
I am trying to form a dynamic where clause using values entered on a selection screen. I want that if a new entry is added in the selection screen the where clause can also be modified dynamically without any change in coding. The only change required should be addition of select-option statement in the selection screen declaration.
Thanks in advance.
Anjurefer below example
L_COND_SYNTAX = 'd2ext_status = l_status and d2ext_date ne c_intdate and '
& 'd2~ext_uploaded = space'.
SELECT D1TKNUM D1SHTYP D1TPLST D1ERNAM D1ERDAT D1BFART
D1VSART D1ROUTE D1SIGNI D1EXTI1 D1~TPBEZ
D1DATBG D1UATBG D1TDLNR D2VBELN D2~POSNR
D2EXT_FAILED D2EXT_COUNT D2EXT_DATE D2EXT_TIME
D2EXT_REP_DATE D2EXT_REP_TIME
D2EXT_RES_DATE D2EXT_RES_TIME D2~EXT_ERR_TYPE
INTO TABLE PA_GT_SHIP_HEADER
FROM VTTK AS D1 INNER JOIN RIOZTM_DELSTAT AS D2
ON D1TKNUM = D2TKNUM
WHERE
D1~TKNUM IN S_TKNUM AND
D1~SHTYP IN S_SHTYP AND
AND
<b>(L_COND_SYNTAX).</b>
Plz note the backet in L_COND_SYNTAX.
Reward points if helpful -
In Select query how to fetch values through multiple parameters where conditon
Dear Experts,
I have one table(T) with 4 fields: f1, f2, f3, f4. In that based on f2, f3, f4 and parameter condition( f2 values) how to fetch f1 values. I have attached screen shot. What is the where condition in select query?
DATA: it_T type standard table of ty_T,
wa_T type ty_T.
parameters: p_f2_1 type T-f3,
p_f2_2 type T-f3,
p_f2_3 type T-f3,
p_f2_4 type T-f4,
p_f2_5 type T-f4,
p_f2_6 type T-f4.
select f1 f2 f3 f4 from T into table it_T where ?
What is the where condition ?.
Regards,
Abbas.Hi Syed,
Do all the parameters p_f2_1 ... p_f2_6 contain values for the same field f2? And do you need all the entries from the table T which contain f2 = any of the entered value? If yes, Then you can try the following where condition -
select f1 f2 f3 f4 from T into table it_T
where f2 = p_f2_1 OR
f2 = p_f2_2 OR
f2 = p_f2_3 OR
f2 = p_f2_4 OR
f2 = p_f2_5 OR
f2 = p_f2_6.
P.S: If any of the above parameters are optional as per your requirement it will be better to build a dynamic query and use it in the where condition.
Regards,
Rachna.
Maybe you are looking for
-
Do I need a new Apple ID for my iPad Air?
Hi! I have a MacBook, OS 10.5.8. I have just bought an iPad Air. I know I can't synch the two devices, as my OS is too old, but do I need a new Apple ID in order to use itunes on the new iPad? Thank you.
-
Standard Extractor for appointment dates in CRM
Hi guys, is there any standard extractor for the appointment dates in CRM !? Thanks you guys !
-
Do bought from Apple Store iPhones get locked to first sim carrier?
I have bought many iPhones for myself and my family over the years and always on contract, UNTIL the iPhone 5. When it came out, I decided to avoid all the unlocking mess and contract handset subsidy thing and buy an unlocked (or so I thought) iPhon
-
Sample Labview .vi For Random Anatomy Course
I am learning Labview and my first challenge is to build a course for one of my daughters who is taking Anatomy in her nursing program. I would like to find an example of a vi that asks a question or shows a picture and the users selects A/B/C/D of
-
Dear all, i just installed Facetime to my macbook pro , called my friend i can hear him but he couldn't hear me i don't know why ? how he could call me back? regards,