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

FM or text function for initial capitals

Former Member
0 Kudos
365

Hi everyone.

I need to turn a sentence into initial capitals. In other words, if I get a string such as

"one thousand and forty dollars" I want a function that returns "One Thousand and Forty Dollars".

Can anyone help

Regards

Martin

1 ACCEPTED SOLUTION
Read only

former_member156446
Active Contributor
0 Kudos
340

Try this might help:

DATA: lv_string TYPE string VALUE 'one thousand and forty dollars',
      lv_temp1(30) TYPE c, lv_temp2(30) TYPE c.
DATA: lv_fin TYPE string.

lv_temp2 = lv_string.
DO.
  SPLIT lv_temp2 AT space INTO lv_temp1 lv_temp2.
  IF lv_temp1 IS INITIAL.
    EXIT.
  ENDIF.

  TRANSLATE lv_temp1+0(1) TO UPPER CASE.

  CONCATENATE lv_fin lv_temp1 INTO lv_fin SEPARATED BY space.
ENDDO.

4 REPLIES 4
Read only

Former Member
0 Kudos
340

i dont know if there is a FM that does exactly THAT, but i´d have ideas how to solve it manually.

first split this string into words, use the "SPLIT" statement for that.

loop at the table in which you splitted.

use offset (1) to just get the first character of every word (record in your split table)

then call FM 2054_TRANSLATE_2_UPPERCASE.

then concatenate your split values into one string again. ready.

Read only

Former Member
0 Kudos
340

you'll not get function for this i think, u can achieve this through custom coding, I found a code on sdn once, but i dont have right now, will give it in a short while,(abt 1 hr).

кu03B1ятu03B9к

Read only

former_member156446
Active Contributor
0 Kudos
341

Try this might help:

DATA: lv_string TYPE string VALUE 'one thousand and forty dollars',
      lv_temp1(30) TYPE c, lv_temp2(30) TYPE c.
DATA: lv_fin TYPE string.

lv_temp2 = lv_string.
DO.
  SPLIT lv_temp2 AT space INTO lv_temp1 lv_temp2.
  IF lv_temp1 IS INITIAL.
    EXIT.
  ENDIF.

  TRANSLATE lv_temp1+0(1) TO UPPER CASE.

  CONCATENATE lv_fin lv_temp1 INTO lv_fin SEPARATED BY space.
ENDDO.

Read only

Former Member
0 Kudos
340

Hi Martin,

you need to separte each word of the sting take it into the separete word..and try to use the TRANSLATE key word with PATTARN..

like below

DATA: text TYPE string.
text = `ADFDFDFD`.
TRANSLATE text USING 'Aasdfsd'.

write:text.   "ouptu will be Adfdfdfd

and do that for all your words in that string ...and merge into one your final sting...

other than this i think we don't have the option.

hope it helps...

Thanks!