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: 

String Comparison

Former Member
0 Kudos

Hello Experts,

Is there any function module in ABAP to compare the two strings. Let us assume there are 2 string variables STR1 & STR2. If both variables doesn't have the same value then I need an exception.

Thanks in advance.

5 REPLIES 5

Former Member
0 Kudos

Hi Mohan,

Is there any specific reason for the use of function module for this small logic?

You can simply compare

IF str1 = str2.

....

ELSE.

RAISE exception.

ENDIF.

Thanks and Best Regards,

Vikas Bittera.

<b><REMOVED BY MODERATOR></b>

Message was edited by:

Alvaro Tejada Galindo

Former Member
0 Kudos

data : str1(20) type c,

str2(20) type c.

str1 = 'Hello'.

str2 = 'Hello1'.

if str1 = str2.

write : 'same'.

endif.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You don't need a function module.

  if str1 <> str2.
     message e001(00) with 'These are not the same'.
  endif.

or....

  if str1 <> str2.
     raise exception < >
  endif.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi Mohan,

Also, dont forget to translate to upper case, if you want case insensitive camparison.

TRANSLATE str1 TO UPPERCASE.

Thanks and Best Regards,

Vikas Bittera.

<b><REMOVED BY MODERATOR></b>

Message was edited by:

Alvaro Tejada Galindo

Former Member
0 Kudos

Hello,

Thanks for the responses. Yes, the reason for looking the Function Module is, in PPPI Message Recipe we can't compare strings with IF condition. That's why I am trying to find out the standard function module instead of writing custom function module.