Sunday, December 28, 2008

ABAP Proper Case Regex

I need to pull full user names from ADRP for an audit report, but the case is all over the place. This piece of code converts a character string to proper case (first letter uppercase). I wanted to handle Mc and Mac too, but ABAP implements the Posix regex syntax, which has no support for back referencing. If anyone knows a regular expression to catch the first character after Mac then please post a response.

report zzzzzzzz.

data:
li_ofs type i,
lv_name(30).

lv_name = 'PETER CHAPMAN'.

write: / lv_name.

translate lv_name to lower case.
while sy-subrc = 0.
translate lv_name+li_ofs(1) to upper case.
find regex '\b[a-z]' in lv_name match offset li_ofs.
endwhile.

write: / lv_name.

1 comment:

Unknown said...

Did you find some kind of solution ?