Skip to Content
avatar image
Former Member

how to make first character of an input field capitalized?

Hi all,

How to make an input field automatically capitalized after user enters a value? Thanks.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Jun 01, 2011 at 05:01 AM

    Hi,

    you can do this by using FM.. 'SWA_STRING_TO_UPPERCASE'

    DATA: OUTPUT TYPE STRING.
    CALL FUNCTION 'SWA_STRING_TO_UPPERCASE'
     EXPORTING
       INPUT_EXPRESSION                 = 'WEBDYNPRO'
    *   INPUT_STRING                     =
       PRESERVE_EXISTING_CAPITALS       = ''
       CAPITALIZE_AFTER_SPACE           = 'X'
       LANGUAGE                         = SY-LANGU
     IMPORTING
       OUTPUT_STRING                    = OUTPUT
    *   OUTPUT_EXPRESSION                =
     EXCEPTIONS
       EXPRESSION_TRUNCATED             = 1
      OTHERS                           = 2
              .
    IF sy-subrc  0.
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    OR

    You can do by using TRANSLATE Command, you need to use some logic.

    data : TEXT(10) type C.

    data : T type C.

    TEXT = kris'.

    move TEXT+0(1) to T.

    translate T to upper case.

    concatenate T TEXT+1(9) into TEXT.

    write : TEXT.

    Cheers,

    Kris.

    Edited by: kissnas on Jun 1, 2011 7:06 AM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 01, 2011 at 04:56 AM

    hi,

    it depends on the data element of the attribute to which you bind the input field.

    regards,

    sahai.s

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Siong,

      If you want to convert the first character in to the Uppercase you have to write a logic by your own. It is very simple.

      You can try out following code:

      data : in_str(50) value 'sample test'.

      data : itab(50) occurs 0 with header line.

      data : out_str(50).

      split in_str at space into table itab.

      loop at itab.

      translate itab+0(1) to upper case.

      concatenate out_str itab into out_str separated by space.

      endloop.

      write : / out_str.

      It will return the sample test as Sample Test. You can use this code in your application and can change the case of the context attribute

      Regards

      Abhinav