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

Validation for last 2 places in coding

hi all , i have a field g_aufk-zz_pmf_key it is 7 char

i need to pass it to t_aufk if the last 2 char are numbers

so i wrote

IF g_aufk-zz_pmf_key+5(2) CA '0123456789'.

t_aufk = g_aufk-zz_pmf_key.

ELSE.

WRITE:/'error'.

ENDIF.

but when i see i debugging i can see the value in g_aufk-zz_pmf_key+5(2) is blank .

can anynody suggest me a better way ?

Regards

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • Posted on Oct 22, 2008 at 09:42 AM

    Hello ,

    The code you have written should work fine.

    The only reason i can see is that the last 2 fields are blank in g_aufk-zz_pmf_key . So it will not give any results. You need to check this.

    Rgds,

    sandeep

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Bhanu,

      You can use the below logic.

      Declare a variable of length 7 say namely ld_var.

      ld_var = g_aufk-zz_pmf_key

      Use FM CONVERSION_EXIT_ALPHA_INPUT on ld_var.

      IF ld_var+5(2) CA '0123456789'.

      t_aufk = g_aufk-zz_pmf_key.

      ELSE.

      WRITE:/'error'.

      ENDIF.

  • author's profile photo Former Member
    Former Member
    Posted on Oct 22, 2008 at 09:48 AM

    Hey Bhanu,

    According to your logic, even if one of the characters turns out to be a number, data will be passed to t_ausk, which I think is not according to your requirement. for eg: wot if last 2 characters are 'a2' ?

    Using your logic, data will be passed.

    Why don't you see for each character..

    ie,

    IF g_aufk-zz_pmf_key+5(1) CA '0123456789' and 
        g_aufk-zz_pmf_key+6(1) CA '0123456789'.
        t_aufk = g_aufk-zz_pmf_key.
    ELSE.
      WRITE:/'error'.
    ENDIF.
    

    cheers,

    Vishnu

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 22, 2008 at 09:49 AM

    Hello,

    It is working fine for me if not you can use this logic.

    I tested just now it is working fine.

    DATA: y_v_char TYPE char7 VALUE 'ABCDE89'.

    DATA: y_v_char1 TYPE char2.

    IF y_v_char+5(2) CA 'ABCDE89'.

    y_v_char1 = y_v_char+5(2).

    ELSE.

    WRITE:/'error'.

    ENDIF.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 22, 2008 at 09:53 AM

    Check if g_aufk-zz_pmf_key have any value and is not empty.

    regards,

    Advait

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 22, 2008 at 09:54 AM

    hi,

    i tried like this. it's getting value... just check it once...

    data: zz_pmf_key(7)  type c value 'abcde45'.
    data: t_aufk(2) type c.
    
    IF zz_pmf_key+5(2) CA '0123456789'.
    t_aufk = zz_pmf_key+5(2).
    *move zz_pmf_key+5(2) TO t_aufk.
    ELSE.
    WRITE:/'error'.
    ENDIF.

    Regards,

    Shankar.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 22, 2008 at 10:08 AM

    Hi,

    DATA : LEN TYPE I,

    IND1 TYPE I,

    IND2 TYPE I.

    LEN = STRLEN( G_AUFK-ZZ_PMF_KEY ).

    IND1 = LEN - 2.

    IND2 = LEN - 1.

    IF G_AUFK-ZZ_PMF_KEYIND1(1) CA '0123456789' AND G_AUFK-ZZ_PMF_KEYIND2(1) CA '0123456789'.

    T_AUFK = G_AUFK-ZZ_PMF_KEY.

    ELSE.

    WRITE:/'error'.

    ENDIF.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 22, 2008 at 12:36 PM

    If you want to check that BOTH characters are numbers, you must code

     CO '0123456789'. 

    and NOT

     CA '0123456789'. 

    Add a comment
    10|10000 characters needed characters exceeded

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.