Application Development and Automation 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: 
Read only

field validation

Former Member
0 Likes
867

Hi all,

i have field of length 9 as declared below.

ID(9) TYPE N,

this i need to check if it consists more than 8 digits it has to throw an error. this field should contain only 8 digits it should not contain 9 digits,

this is one condition for validation and we are not suppose to change the declaration as ID(8) TYPE N.

please help with code sample.

regards,

reddy

6 REPLIES 6
Read only

Former Member
0 Likes
777

Hi,

You can pass the value into another variable of type string and then find length. and accordingly throw error if it is more than 8.

use strlen()

Thanks

Ankit

Read only

Former Member
0 Likes
777

Hi Reddy,

as far as I know, if variable is declared as ID(9) TYPE N, it always contains 9 digits.

E.g. after

ID = 123 is value of ID 000000123, because value is always shifted to right and other places are filled with zeroes. In such case, probably following test is sufficient for You:

IF ID(1) EQ '0'.
* First digit is zero, it means that whole number is shorter than 9 digits
ELSE.
* First digit is not zero, it means the number's length is 9 digits
ENDIF.

Regards,

Adrian

Read only

Former Member
0 Likes
777

data:ID(9) TYPE n,

l type i.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

input = id

IMPORTING

OUTPUT = id.

l = strlen( id ).

if l <= 8.

-

-

-

else.

-

-

-

endif.

Read only

Former Member
0 Likes
777

This is a numeric field, so the solution is simple.

DATA id(9) TYPE n.

id = 123456789.

IF id > 99999999.
  WRITE 'incorrect'.
ENDIF.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
777

data:len(9) type c.

len = d.

length = strlen( len ).

if length > 8.

error.

endif.

Read only

Former Member
0 Likes
777

Resolved