‎2008 May 29 11:36 AM
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?
‎2008 May 29 11:37 AM
WHERE objnr like srch_str.
srch_str should contain ' %' sign for LIKE to work.
‎2008 May 29 11:37 AM
WHERE objnr like srch_str.
srch_str should contain ' %' sign for LIKE to work.
‎2008 May 29 1:17 PM
before the select query i used this statement.
CONCATENATE '%' cntlarea '%' INTO srch_str.
but i want to search from the 2nd position.
eg: suppose objnr = KS1000AP01DESHLF .
and cntlarea = '1000'.
so the search should start at the 2nd position.
‎2008 May 29 1:29 PM
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
‎2008 May 29 11:38 AM
Hello.
Do something like this.
DATA: w_obj TYPE objnr.
CONCATENATE '%' srch_str INTO w_obj.
SELECT objnr FROM cosp INTO TABLE gt_itab
WHERE objnr like w_obj.
Best regards.
Valter Oliveira.
‎2008 May 29 11:38 AM
if you want to give 3 characters ex abc
give the scrch_str as %abc%
parameters : scrch_str type string.
SELECT objnr FROM cosp INTO TABLE gt_itab
WHERE objnr like srch_str.
reward if helpful
prasanth
‎2008 May 29 2:03 PM
hi,
In ABAP we have 2 types of wild characters.
One is '%' which means that it can replace any number of characters.
Another one is '_' which is underscore. it is used to replace single character. so you can use this. As the substring starts from 3rd character use 2 underscores which gets the required results.
suppose field1 is 18 characters,
field2 is 16 characters,
temp is '_'.
first take subtring into field2 then concatenate two times with '_' to string field1.so that it can take any 2 values in the records.
Hope this is helpful to you.
Reward points if helpful,
Thanks and Regards
‎2008 May 29 2:14 PM
He's right..
This worked
TABLES: cosp.
DATA:
BEGIN OF gt_itab OCCURS 0,
objnr LIKE cosp-objnr,
END OF gt_itab.
DATA:
cntlarea(22) TYPE c VALUE '1000',
srch_str(50).
START-OF-SELECTION.
CONCATENATE '__' cntlarea '%' INTO srch_str.
SELECT objnr FROM cosp INTO table gt_itab
WHERE objnr LIKE srch_str.
BREAK-POINT.