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

Validate serial patterns

Hi all!

I have this issue..

I have to validate serial patters if each character is Alphanumeric and numeric, for example:

Format1 > AAAANNAAANAA

Format2 > AAANNANAANAA

Format3 > AAANNANAANA

Format4 > AAANNNAAANAA

Format5 > NNNNNNNN

Format6 > AANNNNAAANAA

Taking as a example for the first one "AAAANNAAANAA" if I receive the value "ABCD12EFG3HI" should be ok

BUT! if I receive "ABCDQ2EFG3HI" (the number 1 changed for a "Q" it shout send an error

I was cheking the regex [:digit:][:alnum:] but I was not success.

Can you help me please?

Best Regards

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Feb 08, 2012 at 04:18 PM

    I am sure there would be more elegant way, but you can try like this:

    DATA: lv_pattern TYPE char20.
    DATA: lv_value TYPE char20.
    lv_pattern = 'AAAANNAAANAA'.
    lv_value   = 'ABCD12EFG3HI'.
    
    DATA: lv_len TYPE i.
    lv_len = STRLEN( lv_pattern ).
    DATA: lv_char TYPE char1.
    DATA: lv_val_char TYPE char1.
    DATA: lv_index TYPE i.
    DATA: mlen TYPE i.
    DATA: lv_regex TYPE string.
    DATA: lv_failed TYPE flag.
    DO lv_len TIMES.
      lv_char = lv_pattern+lv_index(1).
      lv_val_char = lv_value+lv_index(1).
      IF lv_char = 'A'.
        lv_regex = '[a-zA-Z]'.
      ELSEIF lv_char = 'N'.
        lv_regex = '[0-9]'.
      ENDIF.
      lv_index = lv_index + 1.
      FIND REGEX lv_regex IN lv_val_char
       MATCH LENGTH mlen.
      IF sy-subrc NE 0.
        WRITE: 'Error at position', lv_index,
               'expecting', lv_regex, 'but found otherwise'.
        lv_failed = 'X'.
        EXIT.
      ENDIF.
    ENDDO.
    IF lv_failed IS INITIAL.
      WRITE: 'Looks good'.
    ENDIF.
    

    Regards,

    Naimesh Patel

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 08, 2012 at 05:49 AM

    You say that the incoming serial no must be validated with all the patterns available ?

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Yep, it must to be validated, for example, if I receive this serial: ABCD12EFG3HI I have to validate that the first four positions are alphanumeric, the sixth and seventh are numeric eighth ninth and tenth alphanumeric, and so on, based on this pattern "AAAANNAAANAA"

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.