Skip to Content
avatar image
Former Member

string functions to check if string contains charactets other than digits

We have a string as an input.

We need to check if it contains any characters other than digits ( ie. 0123456789) The other characters could be special characters, albhabets etc.

Please suggest any RFC / Logic to get this .

Rohit

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Oct 28, 2008 at 11:44 AM
    IF string CO '0123456789'.
    ==> only digits
    ELSE.
    ==> not just digits (could be space as well)
    ENDIF.
    Add comment
    10|10000 characters needed characters exceeded

    • if you know the solution better, than why ask at all?

      if you get different replies, why don't you try them and see if works or not?

      CA stands for contains any

      IF string CA '0123456789'

      it will be true if the string contains at least one digit

      IF string CA '0123456789'
      ==> the string contains at least one digit
      ELSE.
      ==> the string does NOT contain any digit (however could contain space or special characters)
      ENDIF.

      CO stands for contains only

      IF string CO '0123456789'

      it will be true if the string contains only digits

      IF string CO '0123456789'
      ==> the string contains only digits
      ELSE.
      ==> the string contains not only digits (could be no digits at all)
      ENDIF.

      ==> the string contains only

      </Spoonfeeding>

      PS: Thomas: Thanks for your support / Vielen Dank für die Unterstützung! 😊

  • avatar image
    Former Member
    Oct 28, 2008 at 11:41 AM

    if lv_str CA '0123456789'

    else.

    endif.

    use CA option in ur case..

    vijay

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 28, 2008 at 11:47 AM

    hi,

    compare that string with system field sy-abcde..

    ex:

    data : var type string.
    
    var = '84748291'.
    if var CA sy-abcde.
      write : 'Hello'.
    else.
      write : 'NO'.
    endif.
    .

    Rgds.,

    subash

    Add comment
    10|10000 characters needed characters exceeded