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

convert letter case

Former Member
0 Likes
1,740

Hi,

I need to convert letter, example : UNITED KINGDOM into United Kingdom

what is your suggested method?

The best FM i can find is string_upper_lower_case but the result will be United kingdom, only the first letter is translated to capital.

Please help. Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,496

Hi,

Try this.


v_str = 'UNITED KINGDOM'.

Split v_str at space into itab.

Loop at itab.

Call your FM.

Concatenate new_str itab-str into new_str separated by space.

endloop.

Regards,

Bhupal

Hi,

I need to convert letter, example : UNITED KINGDOM into United Kingdom

what is your suggested method?

The best FM i can find is string_upper_lower_case but the result will be United kingdom, only the first letter is translated to capital.

Please help. Thanks.

9 REPLIES 9
Read only

Former Member
0 Likes
1,496

Hi,

Where did u maintain UNITED KINGDOM, there u can maintain United Kingdom.

Read only

Former Member
0 Likes
1,497

Hi,

Try this.


v_str = 'UNITED KINGDOM'.

Split v_str at space into itab.

Loop at itab.

Call your FM.

Concatenate new_str itab-str into new_str separated by space.

endloop.

Regards,

Bhupal

Read only

Former Member
0 Likes
1,496

HI.

check this link.

Regards.

Jay

Read only

Former Member
0 Likes
1,496

Hello,

You can use the FM SWA_STRING_TO_UPPERCASE to convert the string to a title case (initials of each word in capitals). Have a look at the below code:

SELECTION-SCREEN BEGIN OF BLOCK b1.

PARAMETERS: p_input TYPE swaexpdef-expr.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

DATA: v_output_string TYPE swaexpdef-expr.

WRITE: / 'The input string is: ', p_input.

CALL FUNCTION 'SWA_STRING_TO_UPPERCASE'

EXPORTING

input_expression = p_input

  • INPUT_STRING =

preserve_existing_capitals = ' '

capitalize_after_space = 'X'

IMPORTING

  • OUTPUT_STRING =

output_expression = v_output_string

EXCEPTIONS

expression_truncated = 1

OTHERS = 2.

IF sy-subrc EQ 0.

WRITE: 'The converted string in title case is: ', v_output_string.

ENDIF.

END-OF-SELECTION.

Regards,

Namrata

Read only

Former Member
0 Likes
1,496

Hello,

You can use the FM SWA_STRING_TO_UPPERCASE to convert the string to a title case (initials of each word in capitals). Have a look at the below code:

SELECTION-SCREEN BEGIN OF BLOCK b1.

PARAMETERS: p_input TYPE swaexpdef-expr.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

DATA: v_output_string TYPE swaexpdef-expr.

WRITE: / 'The input string is: ', p_input.

CALL FUNCTION 'SWA_STRING_TO_UPPERCASE'

EXPORTING

input_expression = p_input

  • INPUT_STRING =

preserve_existing_capitals = ' '

capitalize_after_space = 'X'

IMPORTING

  • OUTPUT_STRING =

output_expression = v_output_string

EXCEPTIONS

expression_truncated = 1

OTHERS = 2.

IF sy-subrc EQ 0.

WRITE: 'The converted string in title case is: ', v_output_string.

ENDIF.

END-OF-SELECTION.

Regards,

Namrata

Read only

former_member451655
Active Participant
0 Likes
1,496

hi ,

just Create a Z funciton module with the Below Code , its working Fine

Import Param:

STRING1

Export Param :

STRING

Exceptions

NOT_VALID

TOO_LONG

TOO_SMALL

----


Source Code----


DATA :

IT_TXTS TYPE TABLE OF STRING, "Tabel for data storing

WA_TXTS(100) TYPE C, "Getting each words

CP_TEXT TYPE STRING, "Copying text

NN_TEXT TYPE STRING. "Result text

*

CP_TEXT = STRING1.

SPLIT CP_TEXT AT SPACE INTO: TABLE IT_TXTS.

LOOP AT IT_TXTS INTO WA_TXTS.

PERFORM CHANGE_CASE USING WA_TXTS.

CONCATENATE NN_TEXT WA_TXTS INTO NN_TEXT SEPARATED BY SPACE.

ENDLOOP.

CONDENSE NN_TEXT.

*

CASE SY-SUBRC.

WHEN 0.

STRING = NN_TEXT.

EXIT.

WHEN 2.

RAISE NOT_VALID.

WHEN 3.

RAISE TOO_LONG.

WHEN 4.

RAISE TOO_SMALL.

ENDCASE.

Read only

0 Likes
1,496

Not sure why, but I get blank from the output.

this FM has obsoleted?

FM -> CALL FUNCTION 'SWA_STRING_TO_UPPERCASE'

Read only

0 Likes
1,496

This works:

REPORT ztest LINE-SIZE 80 MESSAGE-ID zc.

DATA: text TYPE string   VALUE 'UNITED KINGDOM'.

WRITE: / 'Before -', text.

CALL FUNCTION 'SWA_STRING_TO_UPPERCASE'
  EXPORTING
    input_string               = text
    preserve_existing_capitals = ' '
    capitalize_after_space     = 'X'
    language                   = sy-langu
  IMPORTING
    output_string              = text
  EXCEPTIONS
    expression_truncated       = 1
    OTHERS                     = 2.

WRITE: / 'After  -', text.

Output:

Before - UNITED KINGDOM
After  - United Kingdom

Rob

Edited by: Rob Burbank on Nov 27, 2008 11:42 AM

Read only

Former Member
0 Likes
1,496

HI,

I think this cannot be possible...sap either convert's to upper case or lower case but not as per your requirement. you need to develop your onw functionality for this.