‎2005 Dec 20 9:03 AM
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,
‎2005 Dec 20 10:14 AM
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
‎2005 Dec 20 9:12 AM
check the lenght cpt , what is the value you are getting .
in debug mode findout.
i think it is overflowing...
regards
vijay
‎2005 Dec 20 9:16 AM
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
‎2005 Dec 20 9:20 AM
Try using the function Module "STRING_UPPER_LOWER_CASE"
Thanks
Tharani
‎2005 Dec 20 10:14 AM
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
‎2005 Dec 20 10:24 AM
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
‎2005 Dec 20 10:38 AM
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.
‎2005 Dec 20 10:45 AM
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
‎2005 Dec 20 10:41 AM
"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
‎2005 Dec 20 10:47 AM
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
‎2005 Dec 20 11:43 AM
Hi,
Pls award points to any answers which have been helpful.
Regards,
Amit M.