Skip to Content
author's profile photo Former Member
Former Member

Get first char in string that is not A,B,C ....0-9

Hi everybody,

assuming I have strings like

45a46SSSS5646&544

jksdKJLKJL#POIPOIPOI

098FHGF*ksdlasködla

How can i find the first position (sy-fdpos) where a special character occurs?

Regards

Mario

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Jan 10, 2014 at 11:59 AM

    Try regular expression:

    [^a-zA-Z0-9]

    😊

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 10, 2014 at 12:46 PM

    Hello Mario,

    if you want to avoid working with regeular expressions you can do the following:

    The output will be &.

    If you want to avoid coding all letters you can fill your overlay-pattern using sy-abcde.

    Greets

    Stefan


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 10, 2014 at 12:57 PM

    A simple check string CO 'ABC....Z0123456789' will set sy-fdpos, but you are allowed to play with regex in a FIND statement of course.

    DATA: BEGIN OF alphanum,
             abc TYPE sy-abcde,
             num TYPE c LENGTH 40 VALUE '0123456789',
           END OF alphanum.
     LOAD-OF-PROGRAM.
       alphanum-abc = sy-abcde.
     * SELECTION SCREEN
       PARAMETERS: text TYPE text80.
     AT SELECTION-SCREEN ON text.
       IF text CO  alphanum. " Convert to uppercase if required
       ENDIF   MESSAGE s002(sy) WITH sy-fdpos.
    

    Regards,

    Raymond

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2014 at 12:26 PM

    Try this:

    DATA: lv_char,

    lv_count type i value '0',

    lv_pos type i.

    lv_string = '45a46SSSS5646&544'.

    Do.

    lv_char = lv_string+lv_count(1).

    lv_count = lv_count + 1.

    IF lv_char CO '0123456789' OR

    lv_char CO SYABCDE.

    * Do nothing

    ELSE.

    lv_pos = lv_count.

    Exit.

    ENDIF.

    ENDDO.

    Cheers,

    Prakash

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Sure Prakash, but since you posted a correction with more issues than originally I could'nt resist to clarify... 😊 I personnaly think (wish) that a code posted over here (as a solution proposal) should be 100% accurate...(or in case of doubt should just be posted as a pseudo-code) But...I dream I know 🤯

      I remember a teacher of mine (in the years compilation was costing a lot) telling me twenty times a day: "Remember, read your syntax again carefully before compiling, you only have 3 shots!" 😊 I guess that's why I cant support bugs anywhere anymore! 🤣

      Anyway be willing to help worths a thousand bugs! Tx mate 😉

      Cheers,

      Manu.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.