Skip to Content
avatar image
Former Member

Wild Card Characters in Select Statement

Hi,

I have a program, where user enters a field. S_INGRP, from the Selection Screen.

Users may enter wild card characters in this field.

I have used the below code to handle this.

if s_ingrp-high eq space

Select <fields> into corresponding fields of itab

from table qmih where ingrp like s_matnr-low.

else

Select <fields> into corresponding fields of itab

from table qmih where ingrp in s_matnr.

endif.

This code helps me when

1.A single value with wild-card characters is provided. (eg E%)

2. The low value is with a wild-card character and high value is a exact value. (eg: E% to MM1)

But When I give both the low and the high value with wild- card characters ( eg: E% to M%) , it only returns the values for the low value (E%).

Please Help

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    Nov 18, 2011 at 06:29 AM

    hi !

    Please check you logic/Coding.

    check the low and figh values of selection and then write the coding.

    if s_matnr-low is not initial.

    select....

    else if s_matnr-high is not initial.

    elseif s_matnr-low is not initial and s_matnr-low is not initial.

    endif

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 18, 2011 at 06:58 AM

    in IF condition you are checking with

    if s_ingrp-high eq space

    this condition.

    so the code which you mentioned will not work for HIGH is not equals to space.

    So chenge the code accordingly..

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 18, 2011 at 12:43 PM

    I see similar results....But when I do wildcard to value, I get what I expected... Experiment..you can find a solution...I would try this....

    read table s_matnr into ls_matnr (described like line of s_matnr) or perhaps you'd need to loop and select appending.

    if ls_matnr-low cs '' and ls_matnr-high cs ''.

    replace '*' with '%' into ls_matnr-low.

    replace '*' with '%' into ls_matnr-high.

    select * ....

    where matnr like ls_matnr-low or

    matnr like ls_matnr-high.

    else.

    select * . . .

    where matnr in s_matnr.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi BreakPoint,

      This will return only values where matnr = matnr-low, but not the entire range between matnr-low and matnr-high

      Edited by: bachack on Nov 18, 2011 4:01 PM

      Edited by: bachack on Nov 19, 2011 4:47 AM

  • Nov 19, 2011 at 06:06 AM

    see the following example

    TABLES : mdsb.
    DATA : BEGIN OF t_mchb OCCURS 0,
           matnr LIKE mchb-matnr,
           lgort LIKE mchb-lgort,
           charg LIKE mchb-charg,
           clabs LIKE mchb-clabs,
           cumlm LIKE mchb-cumlm,
           flg(1) TYPE c,
           END OF t_mchb.
    
    
    
    SELECT-OPTIONS:matnr FOR mdsb-matnr.         "here u can inptu e120% to f20%
    
    
     SELECT * FROM mchb
              INTO CORRESPONDING FIELDS OF TABLE t_mchb
              WHERE matnr in matnr AND
             charg = 'S' 
     '
    .
    

    i run this code and work fine.

    Edited by: Krupaji on Nov 19, 2011 7:07 AM

    Add comment
    10|10000 characters needed characters exceeded