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

Upper case and lower case

Former Member
0 Likes
4,209

Hi,

i've a little problem with string, i want to upper case the first caracter of my string and the remainder i want to lower case it, can you tell me the best way for this ?

I tested this :

FORM format_first_name CHANGING p_vorna.

DATA : wa1 TYPE c,

wa(255) type c,

cpt TYPE i.

wa1 = p_vorna(1).

wa = p_vorna.

DESCRIBE FIELD p_vorna LENGTH cpt IN CHARACTER MODE.

TRANSLATE wa1 TO UPPER CASE.

TRANSLATE wa TO LOWER CASE.

WRITE p_vorna+1(cpt) to wa.

But on the last line (WRITE...) program dump.

Regards,

1 ACCEPTED SOLUTION
Read only

andreas_mann3
Active Contributor
0 Likes
2,340

Hi,

i think you mean this:

DATA : wa1 TYPE c,
wa(255) type c,
cpt TYPE i.

parameters p_vorna(50) lower case default 'andreas'.


wa1 = p_vorna(1).
wa = p_vorna.

cpt = strlen( p_vorna ).

TRANSLATE wa1 TO UPPER CASE.

TRANSLATE wa TO LOWER CASE.
WRITE wa1 to wa(1).

write wa.

Andreas

10 REPLIES 10
Read only

Former Member
0 Likes
2,340

check the lenght cpt , what is the value you are getting .

in debug mode findout.

i think it is overflowing...

regards

vijay

Read only

christian_wohlfahrt
Active Contributor
0 Likes
2,340

Hi!

I would use

concatenate wa1 wa into p_vorna.

to make the result.

But you can also write something, if you like - just that you should use

write p_vorna+1(cpt-1) to wa.

You have to subtract your offset from the whole length (before, not inside the write).

Regards,

Christian

Read only

Former Member
0 Likes
2,340

Try using the function Module "STRING_UPPER_LOWER_CASE"

Thanks

Tharani

Read only

andreas_mann3
Active Contributor
0 Likes
2,341

Hi,

i think you mean this:

DATA : wa1 TYPE c,
wa(255) type c,
cpt TYPE i.

parameters p_vorna(50) lower case default 'andreas'.


wa1 = p_vorna(1).
wa = p_vorna.

cpt = strlen( p_vorna ).

TRANSLATE wa1 TO UPPER CASE.

TRANSLATE wa TO LOWER CASE.
WRITE wa1 to wa(1).

write wa.

Andreas

Read only

Former Member
0 Likes
2,340

Hi tafkap,

1. what i understood u want

Title Case

functionality (as in microsoft word)

2. amit sap hello how are u

should be

Amit Sap Hello How Are U

3. SWA_STRING_TO_UPPERCASE

Use the above FM

It works fantastic.

[ Especially note the functionality of

the paramter

CAPITALIZE_AFTER_SPACE

]

[ It can be used to convert all first characer words to uppper

or only the VERY FIRST ONE

]

4. Sample Code (Just copy paste)

REPORT abc .

DATA : v type string.

DATA : s TYPE string.

v = 'amit sap hello how are u'.

CALL FUNCTION 'SWA_STRING_TO_UPPERCASE'

EXPORTING

  • INPUT_EXPRESSION =

input_string = v

  • PRESERVE_EXISTING_CAPITALS = 'X'

  • CAPITALIZE_AFTER_SPACE = 'X'

  • LANGUAGE = SY-LANGU

IMPORTING

output_string = s

  • OUTPUT_EXPRESSION =

EXCEPTIONS

expression_truncated = 1

OTHERS = 2

.

WRITE 😕 v.

WRITE 😕 s.

I hope it helps.

Regards,

Amit M.

Message was edited by: Amit Mittal

Read only

Former Member
0 Likes
2,340

FORM format_first_name CHANGING p_vorna.

DATA : wa1 TYPE c,

wa(255) type c,

cpt TYPE i.

break-point.

wa1 = vorna(1).

cpt = strlen( vorna ).

if cpt > 1.

wa = vorna+1(cpt).

TRANSLATE wa TO LOWER CASE.

endif.

TRANSLATE wa1 TO UPPER CASE.

concatenate wa1

wa into wa.

write 😕 wa.

endform.

Read only

0 Likes
2,340

hi,

describe field P_vorna length cpt in character mode.

will give you the defined length of variable P_VORNA not the total no of characters in that variable.

(example : p_vorna(255) type c value 'abcd'.

if you use DESCRIBE FOR P_VORNA, will return 255 to CNT

& STRLEN( P_VORNA ) gives you 4.)

so use STRLEN to findout the length of the P_VORNA & then use offset to seperate 1 & remaining characters then use TRANSLATE.

i hope this gives you clear idea.

regards,

srikanth

added example for DESCRIBE FIELD

Read only

Former Member
0 Likes
2,340

"input contains the string having value

data itab type string occurs 0 with header line.

data ch.

split input at delm into table itab.

clear output.

loop at itab.

ch = itab.

shift itab left.

translate ch to upper case.

translate itab to lower case.

concatenate ch itab into itab.

concatenate output itab into output separated by delm.

IF OUTPUT(1) EQ DELM.

SHIFT OUTPUT LEFT.

ENDIF.

endloop.

try this

Read only

0 Likes
2,340

Try this.

types:begin of st,

text(35),

end of st.

data:itab type table of st,

wa type st.

split string at space into itab.

clear string.

loop at it into wa.

translate wa(1) to uppercase.

concatenate string wa into string separated by space.

endloop.

Now string will be of the Title case format.

Regards

Binoo

Read only

Former Member
0 Likes
2,340

Hi,

Pls award points to any answers which have been helpful.

Regards,

Amit M.