Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

where condition in select query

Former Member
0 Likes
1,591

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?

1 ACCEPTED SOLUTION
Read only

Sm1tje
Active Contributor
0 Likes
1,262

WHERE objnr like srch_str.

srch_str should contain ' %' sign for LIKE to work.

7 REPLIES 7
Read only

Sm1tje
Active Contributor
0 Likes
1,263

WHERE objnr like srch_str.

srch_str should contain ' %' sign for LIKE to work.

Read only

Former Member
0 Likes
1,262

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.

Read only

Former Member
0 Likes
1,262

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

Read only

valter_oliveira
Active Contributor
0 Likes
1,262

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.

Read only

prasanth_kasturi
Active Contributor
0 Likes
1,262

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

Read only

Former Member
0 Likes
1,262

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

Read only

0 Likes
1,262

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.