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

Find symbol in string

Former Member
0 Likes
2,570

HI ALL ,

assume i have field like 99.999.99 or fields like 99,99 or fileds

like 99.99,99 or 99,99.99 ,how can i know that the fields

are with symbols (, or .) and separate between them and filed like 9999 that

dont have any symbol on it .

I try with FIND REGEX `(.)(,)` IN lv_val. but

it dont fetch fiels like 99.999.99 .

Regards

Alex

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,130

Is this what you are looking for ?

REPORT  z_test LINE-SIZE 255.

DATA: num(30) VALUE '999.999.999,999'.

DATA: v_strlen TYPE i,
      v_index TYPE i VALUE 0,
      v_temp TYPE c VALUE '',
      output TYPE string VALUE ''.

v_strlen = STRLEN( num ).

DO v_strlen TIMES.
  CASE num+v_index(1).
    WHEN '1'. v_temp = 'X'.
    WHEN '2'. v_temp = 'X'.
    WHEN '3'. v_temp = 'X'.
    WHEN '4'. v_temp = 'X'.
    WHEN '5'. v_temp = 'X'.
    WHEN '6'. v_temp = 'X'.
    WHEN '7'. v_temp = 'X'.
    WHEN '8'. v_temp = 'X'.
    WHEN '9'. v_temp = 'X'.
    WHEN '0'. v_temp = 'X'.
    WHEN OTHERS.
      IF v_temp = 'X'.
        CONCATENATE output '-' INTO output.
        CLEAR v_temp.
      ENDIF.
      CONCATENATE output num+v_index(1) INTO output.
  ENDCASE.
  v_index = v_index + 1.
ENDDO.
WRITE : / output.

16 REPLIES 16
Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
2,130

Try SPLIT and then concatenate in new string.

Read only

Former Member
0 Likes
2,130

You can use Replace all occurances with space and then condense.

Thanks,

Anmol.

Read only

0 Likes
2,130

yes it should work with a CONDENSE NO-GAPS.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,130

Hi,

If its always numeric then you can go like this. Seperate the string where non numeric characters are found. In your case comma and dot are always non numeric. Also could you please explain it bit more clear. Is your requirement to find if there is a separator or what is the separator ?

Read only

0 Likes
2,130

HI Keshav ,

The fields can come as dec or quan

and i need to know if the field contain the follwing template .

(.-.) 99.99.99
(,-,) 99,99,99
(,-.) 99,99.99
(.-,) 99.99,99
(,-,-.) 99,99,99.00
(.-.-,) 99.99.99,00

what is the best way to do that ?

Regards

Alex

Read only

0 Likes
2,130

OK then put the value into a string and check if

w_string CP '999999*'

Read only

0 Likes
2,130

HI François Henrotte

The string can be diffrent now it 999.999 and it can be also any nubmer like 11,11 etc

i need to find if tstring lv_val contain the following patterns

(.-.) 99.99.99
(,-,) 99,99,99
(,-.) 99,99.99
(.-,) 99.99,99
(,-,-.) 99,99,99.00
(.-.-,) 99.99.99,00

Regards

Alex

Read only

0 Likes
2,130

I am not sure whenthere this is what you meant


data:str type string.
data:temp type string.


str = '99,99,99.00'.
replace all occurrences of regex '[:\d:]' in str with ` `.
replace all occurrences of ` ` in str with '-'.
condense str.
write str.

or spli it into internal table then concatenate the symbols with -.

Read only

0 Likes
2,130

Hi Alex,

Please try inputting single validations for the REGEX. Instead of checking for "," & '.' at the same time, take a multi step approach. Use IF conditions; like if the the field does not have commas then check if it has dots. Also, if you can use constants in your code, you can make good enough use of the syntax. Declare constants for the values "," & "." .

Example:

CONSTANTS: C_COMMA TYPE C VALUE ',' ,
           C_DOT   TYPE C VALUE '.' .

DATA: result_tab TYPE match_result_tab.

Use the constants in the code as shown below.

FIND ALL OCCURRENCES OF REGEX C_COMMA IN "FIELDNAME" RESULTS result_tab.

FIND ALL OCCURRENCES OF REGEX C_COMMA IN "FIELDNAME" RESULTS result_tab.

Please try as aforesaid and post back if you need help.

Best Regards,

Chaitanya

Edited by: cn chaitanya on Dec 28, 2010 8:58 PM

Read only

0 Likes
2,130

if you're looking for patterns, you could try something like this:


parameters: lv_val type string.

if lv_val CP '*.*.*'.
    if lv_val CP '*.*.*,*'.
      write /: `Contains pattern '*.*.*,*'`.
    else.
      write /: `Contains pattern '*.*.*'`.
    endif.

    ELSEIF lv_val CP '*.*,*'.
      write /: `Contains pattern '*.*,*'`.
endif.

if lv_val CP '*,*,*'.
    if lv_val CP '*,*,*.*'.
      write /: `Contains pattern '*,*,*.*'`.
    else.
      write /: `Contains pattern '*,*,*'`.
    endif.

    ELSEIF lv_val CP '*,*.*'.
      write /: `Contains pattern '*,*.*'`.
endif.

Read only

0 Likes
2,130

Hi,

You can do like this way.

data: w1(10) value '99,999.99',

w2(10) value '9999',

s(2) value '.,'.

if w1 ca s .

write 'found'.

else.

write: 'not found'.

endif.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,130

You need not go for any regex pattern for this. This is determined by the decimal notation in user profile.

You can get it from table USR01, field DCPFM passing the username to field BNAME.

Possible values are X,Y , SPACE.

If its blank then thousand separator is dot and decimal separator is comma

if its X then thousand separator is comma and decimal separator is dot

Read only

0 Likes
2,130

HI Keshav.T

Yes i know how to do it like that but i need to do it with coding

assume the field value is type string and i want to find if it contain one of the pattern in my previos post

Thanks

Alex

Read only

0 Likes
2,130

What do you mean by coding ?

Is it like the string might comtain the pattern opposite to the values maintained in the user profile ?

Read only

Former Member
0 Likes
2,131

Is this what you are looking for ?

REPORT  z_test LINE-SIZE 255.

DATA: num(30) VALUE '999.999.999,999'.

DATA: v_strlen TYPE i,
      v_index TYPE i VALUE 0,
      v_temp TYPE c VALUE '',
      output TYPE string VALUE ''.

v_strlen = STRLEN( num ).

DO v_strlen TIMES.
  CASE num+v_index(1).
    WHEN '1'. v_temp = 'X'.
    WHEN '2'. v_temp = 'X'.
    WHEN '3'. v_temp = 'X'.
    WHEN '4'. v_temp = 'X'.
    WHEN '5'. v_temp = 'X'.
    WHEN '6'. v_temp = 'X'.
    WHEN '7'. v_temp = 'X'.
    WHEN '8'. v_temp = 'X'.
    WHEN '9'. v_temp = 'X'.
    WHEN '0'. v_temp = 'X'.
    WHEN OTHERS.
      IF v_temp = 'X'.
        CONCATENATE output '-' INTO output.
        CLEAR v_temp.
      ENDIF.
      CONCATENATE output num+v_index(1) INTO output.
  ENDCASE.
  v_index = v_index + 1.
ENDDO.
WRITE : / output.

Read only

Former Member
0 Likes
2,130

You can use the SEARCH

Constants : c_minus(1) type c value '-'.

Eg:- SEARCH text FOR c_minus