2013 Sep 24 3:19 PM
Hi experts,
I am using this line of code when choosing from table LTDXT.
SELECT variant
FROM ltdxt
INTO CORRESPONDING FIELDS OF TABLE ts_variant
WHERE report EQ sy-repid
AND ( username EQ space
OR username EQ sy-uname )
AND ( variant LIKE '%_A%'
OR variant LIKE '%A_%' ).
What I want to appear inside the table should be variants that either contain "_A" or "A_" on the name. But when I check the table, even the variant name ABTEST is appearing on the table even if it does not contain A_ or _A.
Am I missing something? Thank you!
2013 Sep 24 3:39 PM
it is expected. abap help on like:
"%" represents any character string, even an empty one, and "_" represents any character
if I read further in the ABAP help it says on wildcards:
Character that substitutes other content. In logical expressions with the
operators CP und NP, "*" usually stands for any character
string and "+" for any
individual character. In WHERE-conditions of Open SQL with the operator LIKE "%" stands for any character strings and "+" for individual characters. The special
functions of wildcard characters can be canceled using escape symbols
2013 Sep 24 3:39 PM
it is expected. abap help on like:
"%" represents any character string, even an empty one, and "_" represents any character
if I read further in the ABAP help it says on wildcards:
Character that substitutes other content. In logical expressions with the
operators CP und NP, "*" usually stands for any character
string and "+" for any
individual character. In WHERE-conditions of Open SQL with the operator LIKE "%" stands for any character strings and "+" for individual characters. The special
functions of wildcard characters can be canceled using escape symbols
2013 Sep 24 3:57 PM
Peter is correct. In your case, you can add escape characters as follows and your statement will perform correctly:
SELECT variant
FROM ltdxt
INTO CORRESPONDING FIELDS OF TABLE ts_variant
WHERE report EQ sy-repid
AND ( username EQ space
OR username EQ sy-uname )
AND ( variant LIKE '%\_A%' ESCAPE '\'
OR variant LIKE '%A\_%' ESCAPE '\' ).
2013 Sep 24 4:04 PM
Hey I also tried for the same, Its working fine
Great Piece of code.. Thanks for Sharing ..
2013 Sep 24 3:43 PM
In this case, underscore is interpreted as a meaning any single character. If you use an in instead of a like, you can test for underscore.
Neal
2013 Sep 24 3:51 PM
As said problem with '_' and %.
So do one thing..
SELECT variant FROM ltdxt INTO CORRESPONDING FIELDS OF TABLE ts_variant
WHERE report EQ sy-repid AND
( username EQ space OR username EQ sy-uname ).
Now
loop at ts_variant into ls_variant where variant CS '_A' OR variant CS 'A_' .
append ls_variant into ts_var_copy.
endloop.
br
ChanS.
2013 Sep 25 6:02 AM
Hii Dioso,
Either follow the post of
or u can do in another way.
select variant and store it into ts_variant then
filter this internal table according to ur requirement and store it into another internal table.
like,
SELECT variant
FROM ltdxt
INTO CORRESPONDING FIELDS OF TABLE ts_variant
WHERE report EQ sy-repid
AND ( username EQ space
OR username EQ sy-uname ).
if not ts_variant is initial.
loop at ts_variant into wa_variant where variant CO 'A_' or variant CO '_A'.
move wa_variant to wa_variant_final.
append wa_variant_final to ts_variant_final.
clear wa_variant_final.
endloop.
endif.
regards
Syed
2013 Sep 25 6:20 AM
Yes, '%' and '_' have other meanings in ABAP. So in order to use them in our select query, we need to provide escape expression as rightly explained by Peter and Eric.
Check these links.
http://www.sapdb.org/7.4/htmhelp/8c/ccce27c71c11d2a97100a0c9449261/content.htm
http://help.sap.com/abapdocu_702/en/abenwhere_logexp_like.htm