Application Development 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: 

Help with search in string

Former Member
0 Kudos

HI,

i have a program that do search for string in some table in text field ,and the program is running OK when the user do search for one word in string.

the problem is when i do search for <b>2 or more</b> word despite that i have them in table the search is not successful. (nothing found).

e.g.

if i search word <u>Public</u> i get in ser_tab :

Public

Public Health

Public Accountants

...

but if id the search for :Public Health

i dont get anything

how i can solve this problem?

this is the code


"ql_text is the input field for the user 
 CONCATENATE '%' ql_text '%'    INTO v_pattern.  

  SELECT qualifictn txtmd
  FROM /bi0/tqualifictn
  INTO TABLE ser_tab
  WHERE langu = sy-langu
  AND  txtmd LIKE v_pattern 
  AND datefrom LE sy-datum
  AND dateto GE sy-datum.

Regards

1 ACCEPTED SOLUTION

ferry_lianto
Active Contributor
0 Kudos

Hi,

Interesting question ... please try this.


DATA: INPUT(25) VALUE 'Our Team Management'.
                                                                        
DATA: CURRENT_CHAR(1)  TYPE C,
      TOTAL_LEN        TYPE I,
      CURRENT_POSITION TYPE I.
                                                                        
DATA: FLAG(1).
                                                                        
WRITE: / INPUT(1).
TRANSLATE INPUT TO LOWER CASE.

TOTAL_LEN = STRLEN( INPUT ).
CURRENT_POSITION = 1.
                                                                        
WHILE CURRENT_POSITION < TOTAL_LEN.
  CURRENT_CHAR = INPUT+CURRENT_POSITION(1).
                                                                        
  IF FLAG = 'X'.
    CLEAR FLAG.
    TRANSLATE  CURRENT_CHAR TO UPPER CASE.
    WRITE: / CURRENT_CHAR.
  ENDIF.
                                                                        
  IF CURRENT_CHAR EQ SPACE.
    FLAG = 'X'.
  ENDIF.
                                                                        
  ADD 1 TO CURRENT_POSITION.
ENDWHILE.

Regards,

Ferry Lianto

15 REPLIES 15

ferry_lianto
Active Contributor
0 Kudos

Hi,

Please try this.


CONCATENATE '%' ql_text '%' INTO v_pattern.
CONDENSE V_PATTERN NO-GAPS.            "Add here
 
SELECT qualifictn txtmd
FROM /bi0/tqualifictn
INTO TABLE ser_tab
WHERE langu = sy-langu
AND  txtmd LIKE v_pattern   
AND datefrom LE sy-datum
AND dateto GE sy-datum.

Regards,

Ferry Lianto

0 Kudos

hi ferry

thanks for your Replay!

i try exactly like u tell and i get the 2 words without space but it still dont find the

words in the table

i have in table text like <u>Health System</u> and after i try with not gaps i get

<u>HealthSystem</u> but the subrc after the select is 0.

how i solve it?

Regards

ferry_lianto
Active Contributor
0 Kudos

Hi,

Also try to use ranges.


RANGES: r_pattern FOR apqi-groupid.

CONCATENATE '*' ql_text '*' INTO r_pattern-low.
r_pattern-sign = 'I'.
r_pattern-option = 'CP'.
append r_pattern.

SELECT qualifictn txtmd
FROM /bi0/tqualifictn
INTO TABLE ser_tab
WHERE langu = sy-langu
      AND  txtmd IN r_pattern 
      AND datefrom LE sy-datum
      AND dateto GE sy-datum.

Regards,

Ferry Lianto

0 Kudos

hi Ferry

thanks i try it and let u now soon.

Best regards

0 Kudos

hi Ferry

i try it exactly and i get in table r_pattern-low "ICPalthsystem"

when i search for health Health system

what i do wrong?

Best Regards

Former Member
0 Kudos

Hi,

You can use ranges to extract data. Define range and use the same in select.

ranges : r_txtmd for /bi0/tqualifictn-txtmd.

CONCATENATE '' ql_text '' INTO v_pattern.

r_txtmd-sign = 'I'.

r_txtmd-option = 'EQ'.

r_txtmd-low = v_pattern.

append r_txtmd.

SELECT qualifictn txtmd

FROM /bi0/tqualifictn

INTO TABLE ser_tab

WHERE langu = sy-langu

AND txtmd in r_txtmd

AND datefrom LE sy-datum

AND dateto GE sy-datum.

Please note that the above method is case sensitive search. Even a single space in supplied value may create problem.

Regards,

Naren

ferry_lianto
Active Contributor
0 Kudos

Hi,

Sorry ... please try to remove CONDENSE statement.

*CONDENSE V_PATTERN NO-GAPS.

OR

*CONDENSE R_PATTERN-LOW NO-GAPS.

Also you may want to tranlate QL_TEXT to an upper and lower case using FM STRING_UPPER_LOWER_CASE.

Regards,

Ferry Lianto

ferry_lianto
Active Contributor
0 Kudos

Hi,

Please try this again.


RANGES: r_pattern FOR apqi-groupid.
 
CONCATENATE '*' ql_text '*' INTO r_pattern-low.
r_pattern-sign = 'I'.
r_pattern-option = 'CP'.
append r_pattern.
 
SELECT qualifictn txtmd
FROM /bi0/tqualifictn
INTO TABLE ser_tab
WHERE langu = sy-langu
      AND  txtmd IN r_pattern 
      AND datefrom LE sy-datum
      AND dateto GE sy-datum.

Regards,

Ferry Lianto

0 Kudos

hi Ferry

i try like that but its not working.

take a look maybe u can help.



MOVE ql_text TO v_pattern2.  "Upper case
  TRANSLATE ql_text TO UPPER CASE.

  TRANSLATE ql_text TO LOWER CASE.
  MOVE ql_text TO v_pattern3. "Lower case

  MOVE ql_text(1) TO f_letter.

  TRANSLATE f_letter TO UPPER CASE.

  MOVE f_letter TO ql_text(1). "for capital lattrs


  CALL FUNCTION 'SWA_STRING_TO_UPPERCASE'
    EXPORTING
      input_expression           = ql_text
      preserve_existing_capitals = ' '
    IMPORTING
      output_expression          = ql_text
    EXCEPTIONS
      expression_truncated       = 1
      OTHERS                     = 2.


*  CONCATENATE '%' ql_text '%'    INTO v_pattern . "Capital latters
**  CONDENSE v_pattern NO-GAPS.
*  CONCATENATE '%' v_pattern2 '%' INTO v_pattern2. "Upper case
**  CONDENSE v_pattern2 NO-GAPS.
*  CONCATENATE '%' v_pattern3 '%' INTO v_pattern3. "Lower case
**  CONDENSE v_pattern3 NO-GAPS.


  CONCATENATE '*' ql_text '*' INTO r_pattern-low. "Capital latters
  r_pattern-sign = 'I'.
  r_pattern-option = 'CP'.
  APPEND r_pattern.

  CONCATENATE '*' v_pattern2 '*' INTO r_pattern-low. "Upper case
  r_pattern-sign = 'I'.
  r_pattern-option = 'CP'.
  APPEND r_pattern.

  CONCATENATE '*' v_pattern3 '*' INTO r_pattern-low. "Lower case
  r_pattern-sign = 'I'.
  r_pattern-option = 'CP'.
  APPEND r_pattern.





  SELECT qualifictn txtmd
  FROM /bi0/tqualifictn
  INTO TABLE ser_tab
  WHERE langu = sy-langu
      AND  txtmd IN r_pattern
      AND datefrom LE sy-datum
      AND dateto GE sy-datum.


Best Regards

0 Kudos

hi Ferry

this is what i have in table r_pattern and still the subrc = 4.


1	I	CP	*Public health*
2	I	CP	*PUBLIC HEALTH*
3	I	CP	*public health*


Best regards

ferry_lianto
Active Contributor
0 Kudos

Hi,

Please try this .. it works fine for me.


RANGES: R_PATTERN FOR /BI0/TQUALIFICTN-TXTMD.
DATA: EXPRESSION LIKE SWAEXPDEF-EXPR.
                                                                        
MOVE QL_TEXT TO EXPRESSION.
                                                                        
CALL FUNCTION 'SWA_STRING_TO_UPPERCASE'
  EXPORTING
    INPUT_EXPRESSION           = EXPRESSION
    PRESERVE_EXISTING_CAPITALS = ' '
    CAPITALIZE_AFTER_SPACE     = 'X'
    LANGUAGE                   = SY-LANGU
  IMPORTING
    OUTPUT_EXPRESSION          = EXPRESSION
  EXCEPTIONS
    EXPRESSION_TRUNCATED       = 1
    OTHERS                     = 2.
                                                                        
CONCATENATE '*' EXPRESSION '*' INTO R_PATTERN-LOW.
R_PATTERN-SIGN = 'I'.
R_PATTERN-OPTION = 'CP'.
APPEND R_PATTERN.

SELECT QUALIFICTN TXTMD
FROM /BI0/TQUALIFICTN
INTO TABLE SER_TAB
WHERE LANGU = SY-LANGU
  AND TXTMD IN R_PATTERN
  AND DATEFROM LE SY-DATUM
  AND DATETO GE SY-DATUM. 

Regards,

Ferry Lianto

0 Kudos

hi Ferry

i think i now what is the problem

in the text i have the 2 words in capital latter's

like

<b>Team Management

Health System</b>

and when i do a search for words in table that in upper case like

<b>JAVA SCRIPT</b>

<i><b>i find it</b></i>

my question how i do search for two words that both are in capital letters?

Best Regards

0 Kudos

hi Ferry

i think that the best way to solve it is to take the string and divide it for to words and get all the possibility (capital ,upper...) and then concatenate them to one string'

but how i can separate the string for two words after the space?

Best Regards

ferry_lianto
Active Contributor
0 Kudos

Hi,

Interesting question ... please try this.


DATA: INPUT(25) VALUE 'Our Team Management'.
                                                                        
DATA: CURRENT_CHAR(1)  TYPE C,
      TOTAL_LEN        TYPE I,
      CURRENT_POSITION TYPE I.
                                                                        
DATA: FLAG(1).
                                                                        
WRITE: / INPUT(1).
TRANSLATE INPUT TO LOWER CASE.

TOTAL_LEN = STRLEN( INPUT ).
CURRENT_POSITION = 1.
                                                                        
WHILE CURRENT_POSITION < TOTAL_LEN.
  CURRENT_CHAR = INPUT+CURRENT_POSITION(1).
                                                                        
  IF FLAG = 'X'.
    CLEAR FLAG.
    TRANSLATE  CURRENT_CHAR TO UPPER CASE.
    WRITE: / CURRENT_CHAR.
  ENDIF.
                                                                        
  IF CURRENT_CHAR EQ SPACE.
    FLAG = 'X'.
  ENDIF.
                                                                        
  ADD 1 TO CURRENT_POSITION.
ENDWHILE.

Regards,

Ferry Lianto

0 Kudos

hi Ferry

Thanks u are Great!!! i understand your logic and solved the problem .

Thanks!!!

Best Regards