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: 

Compare strings with spaces in between

siongchao_ng
Contributor
0 Kudos

Hi all,

I used this following select stament:

      wa_t001l_lgobe-sign = 'I'.
      wa_t001l_lgobe-option = 'CP'.
*      wa_t001l_lgobe-low = lv_ps
      CONCATENATE '*' lv_psloc '*' INTO wa_t001l_lgobe-low.
      APPEND wa_t001l_lgobe TO r_t001l_lgobe.

   SELECT SINGLE lgort
        FROM t001l
        INTO lv_lgort
        WHERE werks = p_werks
        AND   lgobe IN r_t001l_lgobe.

      IF sy-subrc = 0.
      ENDIF.

 

r_t001l_lgobe = *AA-  123*

The sy-subrc returns 4. The select stament cannot seems to find strings with spaces in between. Anyone knows what is wrong here?

1 ACCEPTED SOLUTION

siongchao_ng
Contributor
0 Kudos

Hi all,

Apparently, the problem lies with the string itself which contains non-breaking space.

That is why the SELECT statement cannot match with the string.

Have to replace all occurences of the special char with space.

call method cl_abap_conv_ince=>uccp

exporting

uccp =

   '000D'

receiving

char = lv_rep.

loop at r_t001l_lgobe into wa_t001l_lgobe.

  replace all occurances of wa_t001l_lgobe-low with ' '.

  replace all occurances of wa_t001l_lgobe-high with ' '.

  modify r_t001l_lgobe from wa_t001l_lgobe transporting low high.

clear wa_t001l_lgobe.

endloop.

7 REPLIES 7

former_member946717
Contributor
0 Kudos

Hi Siong,

Can you mention what lv_psloc contains?

Also you can write it as below:

SELECT LGORT

FROM T001L

INTO TABLE IT_LGORT

WHERE WERKS = P_WERKS.

IF SY-SUBRC EQ 0.

   SORT IT_LGORT BY LGORT.

   DELETE IT_LGORT WHERE LGORT NP '*LV_PSLOC*'.

ENDIF.

I think in ranges only EQ and BT works but not anything other than this. Also WERKS can contain many LGORT of pattern '*lv_psloc*' right? Why do you want to get it into a variable?

Hope this helps.

former_member282823
Active Participant
0 Kudos

Hi,

  Instead of * try using % in the concatenate statement..

Regards,

ramesh.

DirkAltmann
Active Participant
0 Kudos

Hi,

your code seems correct. Are you sure that the combination of werks and lgobe exist? Are take care that P_WERKS has an value?

Btw. SELECT SINGLE should be only used if you have the full table key in the WHERE clause. In your case the better alternative is:

SELECT LGORT

FROM T001L UP TO 1 ROWS

...

ENDSELECT.

Regards,

Dirk

former_member217544
Active Contributor
0 Kudos

Hi,

When you are using CP, what is the need of appending * to lv_psloc..

      wa_t001l_lgobe-sign = 'I'.
      wa_t001l_lgobe-option = 'CP'.
      wa_t001l_lgobe-low = lv_psloc should suffice.

or try with Like statment

concatenate '%' lv_psloc '%' into lv_psloc.

   SELECT SINGLE lgort
        FROM t001l
        INTO lv_lgort
        WHERE werks = p_werks
        AND   lgobe like lv_psloc.

      IF sy-subrc = 0.
      ENDIF.

Regards,

Swarna

uppu_narayan
Active Participant
0 Kudos

HI Siong,

     i checked your code on different table and it is working fine ..............check whether that record is present in database. try to check the value is same in database...

thanks and regards,

narayan

Former Member
0 Kudos

Hi,

As in where clause you have taken WERKS as parameter that is why it treating as mandatory field,

change it to select option with no intervals.

I think this would work in your case.

Reward points if Useful.

siongchao_ng
Contributor
0 Kudos

Hi all,

Apparently, the problem lies with the string itself which contains non-breaking space.

That is why the SELECT statement cannot match with the string.

Have to replace all occurences of the special char with space.

call method cl_abap_conv_ince=>uccp

exporting

uccp =

   '000D'

receiving

char = lv_rep.

loop at r_t001l_lgobe into wa_t001l_lgobe.

  replace all occurances of wa_t001l_lgobe-low with ' '.

  replace all occurances of wa_t001l_lgobe-high with ' '.

  modify r_t001l_lgobe from wa_t001l_lgobe transporting low high.

clear wa_t001l_lgobe.

endloop.