cancel
Showing results for 
Search instead for 
Did you mean: 

Validation on String...

former_member720137
Active Participant
0 Kudos

Hi

I have a couple of questions guys..

How to check whether a string contains '$' or ',' in it in ABAP?

and how to check that the string contains only integer values ??

Thanks in advance.

Regards,

Puneet

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

U can use the following Condition,

IF string CA '$' .
....
....
ELSEIF string NA sy-abcde.
.....
.....
ENDIF.

Regards,

Padmam.

former_member720137
Active Participant
0 Kudos

Hi Padman

Thanks for such a quick reply.. but i have to check in a table..

how to do that..

Former Member
0 Kudos

Hi,

For Table U can use the Condition inside the Loop,

LOOP AT itab INTO wa.

IF wa-string CA '$' .

....

....

ELSEIF wa-string NA sy-abcde.

.....

.....

ENDIF.

ENDLOOP.

Regards,

Padmam.

Former Member
0 Kudos

Hi,

Try this Code,

data : begin of temp,
       a type char4,
       end of temp.
data wa like temp.
data itab like table of temp.

wa-a = '1234'.
append wa to itab.

wa-a = 'ab$d'.
append wa to itab.

       
loop at itab into wa.
if wa-a ca '$'.
write : / sy-tabix,'  ',wa-a,'Contain $ Symbol' .
elseif wa-a na sy-abcde.
write : / sy-tabix,'  ',wa-a,'Contains only Integer Values' .
endif.
endloop.

Regards,

Padmam.

Former Member
0 Kudos

HI

sy-abcde = ABCDEFGHIJKLMNOPQRSTUVWXYZ

so before using this, we have to convert whole string to upper case otherwise

if input string is 1234a, it will return interger according to your condition.

Regards

Saurabh Garg

Former Member
0 Kudos

Hello Saurabh,

You are right! But the UPPER case inconsistency is not the only mistake of using sy-abcde. What happens with all other symbols like <,{,],&,^ .....? Using sy-abcde treats them all as numeric values. The only numeric values are 0123456789. And those have to be used for a comparison!

Heinz

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello Puneet,

Try this:

data: w_string type string.

parameters p_in(72).

w_string = p_in.

if w_string CN '0123456789'.

write: / 'Not only integer in string', w_string.

else.

write: / 'Only integer in string', w_string.

endif.

For similar checks you can use these Language elements for Logical expressions:

CO, CN, CA, NA, CS, NS, CP, NP.

Have fun and success,

Heinz

Here is additional information for a check in a table (internal table): you should perform a loop run and remember all index fields where the check failed and save them in a seperate itab. If this index table is empty you can conclude that every check was fine.

Heinz

Edited by: Heinz on Mar 23, 2008 10:10 PM