Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Validation for last 2 places in coding

Former Member
0 Kudos

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

10 REPLIES 10

Sandeep_Kumar
Advisor
Advisor
0 Kudos

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

0 Kudos

hello sandeep the value in g_pmkey+5(2) is blank

but i g_pnkey there is a value .

Can you please help me with ths

0 Kudos

But you are c hecking g_pmkey+5(2) and not g_pnkey.

Please paste ur code here.

0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

regards,

Advait

former_member182426
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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.

former_member194797
Active Contributor
0 Kudos

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

 CO '0123456789'. 

and NOT

 CA '0123456789'.