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

SELECT command using String

Former Member
0 Likes
1,332

Hi

How can I do to select data using string with range:

srch_strA = notcr-low.
srch_strb = notcr-high.

* Building selection
IF srch_strA IS NOT INITIAL AND srch_strB IS INITIAL.
  CONCATENATE '%' srch_strA '%' INTO srch_strA.

*document header
  SELECT bukrs belnr gjahr bktxt bldat xblnr 
    FROM bkpf INTO CORRESPONDING FIELDS OF TABLE it_bkpf
    WHERE bukrs EQ p_bukrs AND
          belnr IN belnr AND
          gjahr EQ p_gjahr
          AND xblnr IN xblnr
          AND BKTXT LIKE srch_strA.

ENDIF.

IF srch_strA NE '' AND srch_strB NE ''.
  CONCATENATE '*' srch_strA '*' INTO srch_strA.
  CONCATENATE '*' srch_strB '*' INTO srch_strB.

  ti_nc-sign    =  'I'.
  ti_nc-option  =  'BT'.
  ti_nc-low     =  srch_strA.
  ti_nc-high    =  srch_strB.
  append ti_nc. clear ti_nc.

*document header
  SELECT bukrs belnr gjahr bktxt bldat xblnr 
  FROM bkpf INTO CORRESPONDING FIELDS OF TABLE it_bkpf
    WHERE bukrs EQ p_bukrs AND
          belnr IN belnr AND
          gjahr EQ p_gjahr
          AND xblnr IN xblnr
          AND BKTXT IN ti_nc.

  ENDIF.

Thanks in advance.

Moderator message - Please use code tags around your code

Edited by: Rob Burbank on Nov 27, 2009 5:26 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,297

What exactly is the problem?

Rob

17 REPLIES 17
Read only

Former Member
0 Likes
1,298

What exactly is the problem?

Rob

Read only

0 Likes
1,297

I need to make a data selection but field is an string, if user put just one parameter is OK, but I need to let open range parameter selection (string) , charaters searched are in first 9 position of the string.

Read only

0 Likes
1,297

I meant - what is it about the code that you have written that doesn't work?

Rob

Read only

0 Likes
1,297

this line in Select Command

AND BKTXT IN ti_nc

Thanks for answering

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,297

Hello Rob,

I think he is trying to make a range of pattern & the SELECT does not seem to return the correct values

I was trying to replicate the same & gives wierd results.

In T001, i have 10 comp codes starting with 12. In SE16 if i give the input BUKRS = 12 to 12, it tells no values available. But if i give the input as 12 to 13* i get all the 10 values.

Can you explain this?

BR,

Suhas

Read only

0 Likes
1,297

Hello,

While building the range internal table, change the option for BT to CP


 ti_nc-sign    =  'I'.
  ti_nc-option  =  'CP'.      " This is what you have to use for the functionality you expect
  ti_nc-low     =  srch_strA.
  ti_nc-high    =  srch_strB.
  append ti_nc. clear ti_nc.

Vikranth

Read only

0 Likes
1,297

And what is the problem with that line - a syntax error, a dump, incorrect output something else?

What is the content of ti_nc at execution?

Rob

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,297

Hello Vik,

I read through SAP documentation for the OPTION of a SELECT-OPTION & it says:

Analyzable operators are "EQ", "NE", "GE", "GT", "LE", "LT", "CP" and "NP" if column high is initial, and "BT", "NB" if column high is not initial.

So my understanding is you cannot use CP with low & high values. May be i am wrong

BR,

Suhas

Read only

0 Likes
1,297

Hello Suhas,

I wasn't aware of that. If the documentation tells that then it must be true:) It also really doesn't make sense to use a high option when searching for patterns. If the OP is looking to search for patterns, he shouldn't fill the high value as pointed by you.

Vikranth

Read only

0 Likes
1,297

Ok Vikranth

I'll change it and let you know.

Thanks to all for answering.

Read only

0 Likes
1,297

Hello Tokio,

Please note that the high option should be initial when searching for patterns using CP option.

Vikranth

Read only

0 Likes
1,297

Hi Suhas,

On a research with this issue I found that the concatenate statements you are using is giving problems...

CONCATENATE '' srch_strA '' INTO srch_strA.

CONCATENATE '' srch_strB '' INTO srch_strB.

if you replace them with the below, i hope you get some output from them,

CONCATENATE srch_strA '*' INTO srch_strA.

CONCATENATE srch_strB '*' INTO srch_strB.

This is what I could find because in select query the first character * is not accepted, I dont know the reason...

Thanks,

Sid

Read only

0 Likes
1,297

Thanks Guys I'll test and let you know... in few minutes

Read only

0 Likes
1,297

Guys

I've made these changes:

1.- Please note that the high option should be initial when searching for patterns using CP option. I did it

2.-

CONCATENATE '' srch_strA '' INTO srch_strA.

CONCATENATE '' srch_strB '' INTO srch_strB.

CONCATENATE srch_strA '*' INTO srch_strA.

CONCATENATE srch_strB '*' INTO srch_strB.

Still getting all records... is there something I miss?

Thanks to all for helping

Read only

0 Likes
1,297

Hi,

Pls. use this code and check if its working...

srch_strA = notcr-low.
srch_strb = notcr-high.
 
* Building selection
IF srch_strA IS NOT INITIAL AND srch_strB IS INITIAL.
  CONCATENATE '%' srch_strA '%' INTO srch_strA.
 
*document header
  SELECT bukrs belnr gjahr bktxt bldat xblnr 
    FROM bkpf INTO CORRESPONDING FIELDS OF TABLE it_bkpf
    WHERE bukrs EQ p_bukrs AND
          belnr IN belnr AND
          gjahr EQ p_gjahr
          AND xblnr IN xblnr
          AND BKTXT LIKE srch_strA.
 
ENDIF.
 
IF srch_strA NE '' AND srch_strB NE ''.
  CONCATENATE srch_strA '*' INTO srch_strA.
  CONCATENATE srch_strB '*' INTO srch_strB.
 
  ti_nc-sign    =  'I'.
  ti_nc-option  =  'BT'.
  ti_nc-low     =  srch_strA.
  ti_nc-high    =  srch_strB.
  append ti_nc. clear ti_nc.
 
*document header
  SELECT bukrs belnr gjahr bktxt bldat xblnr 
  FROM bkpf INTO CORRESPONDING FIELDS OF TABLE it_bkpf
    WHERE bukrs EQ p_bukrs AND
          belnr IN belnr AND
          gjahr EQ p_gjahr
          AND xblnr IN xblnr
          AND BKTXT IN ti_nc.
 
  ENDIF.

Thanks,

Sid

Read only

0 Likes
1,297

Thanks to all for your very helpfull answers!!!

Siddharth your help solve it!!!

Read only

VXLozano
Active Contributor
0 Likes
1,297

Check the WHERE clause help. You can use something like:

DATA: mywhere TYPE string.
RANGES: r_range FOR table-field2.

* define your range
...
* continue

mywhere = 'field = condition AND field2 IN r_range'.

SELECT field_list
  INTO destination
  FROM table
  WHERE (mywhere).