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

INITCAP

Former Member
0 Likes
927

Hello Experts,

How to make first letter of each word in string to capital letter and all others to lower case.

This can acheived using INITCAP keyword in other languages. How to do it in ABAP.

Regards,

Benu

4 REPLIES 4
Read only

Former Member
0 Likes
645

translate g_var+0(1) to upper case.

translate g_var+1 to lower case.

where g_var is the variable.

>report ZTEST15.

>DATA: A(10) VALUE 'AMIT'.

>TRANSLATE a+0(1) TO UPPER CASE.

>TRANSLATE A+1 TO LOWER CASE.

>WRITE: A.

Output

Amit

Edited by: Amit Gupta on Nov 8, 2008 2:29 PM

Read only

vinod_vemuru2
Active Contributor
0 Likes
645

Hi,

I don't thing there is some direct statement. But u can put in below simple logic.


DATA: l_count TYPE i,
      l_len TYPE i,
      l_name(30) TYPE c VALUE 'viNod kuMar veMuru'.

WRITE:/1 'Before change name is:', l_name.

l_len = strlen( l_name ).
CONDENSE l_name.
TRANSLATE l_name+0(1) TO UPPER CASE.

DO l_len TIMES.
  IF l_name+l_count(1) EQ space.
    ADD 1 TO l_count.
    TRANSLATE l_name+l_count(1) TO UPPER CASE.
    CONTINUE.
  ENDIF.

  ADD 1 TO l_count.
  TRANSLATE l_name+l_count(1) TO LOWER CASE.
ENDDO.

WRITE:/1 'After change name is:', l_name.


Thanks,

Vinod.

Small change in Logic;)

Read only

Former Member
0 Likes
645

Hi Benu,

Use the Function Module:


STRING_UPPER_LOWER_CASE

Thanks,

Chidanand

Read only

Former Member
0 Likes
645

Hai,

Use the keyword Translate

Data : txt(100) Value 'benu Mariantony '.

Data : Begin of itab occurs 0,

txt1(100),

End of itab.

Split txt At ' ' into table itab.

Clear txt.

Loop at itab.

Translate itab-txt1+0(1) to upper case.

Concatenate txt itab-txt1 into txt separated by ' '.

Endloop.

txt = txt+1.

Write : / txt.

[SAP Help|http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb33a5358411d1829f0000e829fbfe/frameset.htm]

Regards,

Harish