‎2008 Jul 23 1:12 PM
Hi all
I am new to ABAP so i don't know how relevant the question is.
I have a variable say svar.
I want a select query using LIKE that helps me fetch data that starts with svar.
Something like 'ABC%'.
The only thing here is that it is a variable so i cannot use: 'svar%' or svar+'%' or anything like that.
Kindly suggest.
Thanks and Regards
Avinash
‎2008 Jul 23 1:15 PM
hi,
your variable has to contain 'SVAR' and %, than it will work:
WHERE field LIKE variable
varibale's value is 'SVAR%', all records will be selected where field starts with 'SVAR'
hope this helps
ec
‎2008 Jul 23 1:15 PM
hi check this..
PARAMETERS srch_str(20) TYPE c.
CONCATENATE '%' srch_str '%' INTO srch_str.
DATA text_tab TYPE TABLE OF doktl.
SELECT *
FROM doktl
INTO TABLE text_tab
WHERE doktext LIKE srch_str.
% is for single char
is for string of char
‎2022 Jun 02 2:15 PM
``The use of the wildcard characters "_" and "%" corresponds to the standard of SQL.``
Wildcard character Description Example
% Any string of zero or more characters. WHERE title LIKE '%computer%' finds all book titles with the word 'computer' anywhere in the book title.
_ (underscore) Any single character. WHERE au_fname LIKE '_ean' finds all four-letter first names that end with ean (Dean, Sean, and so on).
‎2008 Jul 23 1:16 PM
Hi Avinash,
Change the variable name. In the select query just search with 'svar%' or svar+'%' . After the select query you can pass it into the variable. Try it out.
Regards,
Swapna.
‎2008 Jul 23 1:19 PM
u can use like in the select query.
But if u want the comparision to be done with a variable..then u can not use like in that case.
one thing u can do..If u know the postioning of the letters in the table field that are to be compared with the var1. then u can achieve this. Supose u want to compare 4 characters in the table field starting with the 3rd digit.
then in the where condition u can write something as...
where zfield+2(4) = WF_VAR1.
‎2008 Jul 23 1:25 PM
I tried the same thing but it gave an error that no such field exists.
What I mean is if I modify the field on which the search is based..it says no such field exist.
‎2008 Jul 23 1:30 PM
‎2008 Jul 23 1:25 PM
Check the sample ././
How to use the LIKE in select statement
REPORT ZTEST_SIMPLE.
data: svar(4).
data: it_flight type sflight_tab1.
svar = 'A%'.
select * from sflight
into table it_flight
where carrid like svar.
break-point.
‎2008 Jul 23 1:30 PM
Thanks everyone, a small error on my part also.
Yes If I append the variable by the wild card character it works...
I was doing a small mistake with that.
‎2023 Sep 04 6:05 AM
SELECT CASE
WHEN pac.PAC_NOME LIKE 'RN%' THEN ESP.ESP_COD = 'PED'
ELSE ESP.ESP_COD
END ESPECIALIDADEID
-- v.ESPECIALIDADE as especialidadedescricao,
-- 'O' AS fonte
FROM
PAC
INNER JOIN HSP ON HSP.HSP_PAC = PAC.PAC_REG
INNER JOIN v_esp_medico v ON hsp.hsp_mde = v.MEDICO
INNER JOIN esp ON esp.ESP_NOME = v.ESPECIALIDADE
INNER JOIN LOC ON LOC.LOC_COD = HSP.HSP_LOC
INNER JOIN STR ON STR.STR_COD = LOC.LOC_STR
INNER JOIN SMK ON hsp.hsp_proc1 = smk.smk_cod
WHERE HSP_dthra >= :data_ini
AND hsp_dthra <= :data_final
SQL Error [42000]: [-5015] (at 68): Missing keyword:END
BECAUSE?
‎2023 Sep 04 6:06 AM