0
votes

It looks like a simple task, but how would you solve it? I don't get any solution right now.

ls_message-text = 'Pernr. 12345678 (Pete Peterson) is valid (06/2015).
append ls_message to lt_message.

ls_message-text = 'Pernr. 12345678 (Pete Peterson) is valid (07/2015).
append ls_message to lt_message.

This is the code I got, the thing is, this is the message I am showing in my application. The customer says that the 2 messages are the same. The second should be deleted.

How would you compare it to delete the line? The table might contain more then 2 lines and also with another text like "is not valid".

I can't extend the structure to have more fields for comparison, I can only use the string comparison on this one field. Are there string comparisons possible with a regex or something?

3
Is it possible to use a standard structure like BAPIRET2 where the messages (fixed components) are identified by keys and the variable parts are in separate fields? This would make stuff a lot easier.vwegert
I know :-) currently its not, I worked out a string comparison, its not beautiful this is why I asked myself if there are better solutions...dotchuZ
Have a look at Levenshtein distance.Bohemian

3 Answers

2
votes

Maybe you could solve your requirement using the Levenshtein distance . ABAP has a built-in function "distance" that gives you the number of operations to convert one string into another. Ex:

   DATA msg1 type string.
   DATA msg2 type string.

   msg1 = 'Levehnstein Distance 7/2015'.

   msg2 = 'Levehnstein Distance 6/2015'.

   data l_distance type i.

   l_distance = distance( val1 = msg1 val2 =  msg2 ).


   if l_distance lt 2 .
    "It's almost the same text
    endif.

In this case l_distance will be 1, because only one operation is necessary (replacing).

Hope this helps,

2
votes

Assuming you want to retain only one message for each unique Pernr. in lt_message, you can use regex to filter for the Pernr. and use that as "key". Now you can delete all but the first message of lt_message that matches this key.

Expand your regex if you want to keep only certain messages, e.g. only the "is valid" ones.

0
votes

have you tried looking to program DEMO_REGEX_TOY. Gives an idea on how to work with Regular expresion, that probably will save the problem