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: 

How to validate the field length

0 Kudos

Hi,

all plz help me

How to validate a field length. actually the requirement is

For EBELN field input length is 10 , but in EBELN input if i give less than 10 digits then it has to show error message.

is there any function module for this or code.

thanks.

3 REPLIES 3

Hi shaik johny,

If you want to check the field length you can use String function STRLEN(field_name). Better you can validate

the field before executing your code, i.e.,

i will show you below short example

DATA : a type I.

DATA : EBELN TYPE EKPO-EBELN.

IF STRLEN(EBELN) NE '10'.

PROCEED

ELSE.

RAISE ERROR MESSAGE

ENDIF.

"below you can follow another example for your more clarification.

For suppose your ebeln value is '0000000324'.

but you enter only '324' in your input parameter it is defenetly throws a error some times.

for avoiding this

UNPACK EBELN TO EBELN.

for writing the above code it will automatically adding the leading zero's.

Reward points if it is helpfull.

0 Kudos

Hi johny_695,

* If you want to validate field length use the the function Strlen( field_name ).

* In EBELN first you need to remove left leading zero, If you have any doubt please refer my logic.

*&---------------------------------------------------------------------*

REPORT ZFIELD_VALIDATION.

PARAMETERS P_EBELN TYPE EKKO-EBELN.
DATA : LV_LEN TYPE NUMC4.
AT SELECTION-SCREEN.

IF P_EBELN IS NOT INITIAL.

SHIFT P_EBELN LEFT DELETING LEADING '0'.

LV_LEN = STRLEN( P_EBELN ).

IF LV_LEN <> 10.
MESSAGE 'Purchasing Number Must 10 Digits' TYPE 'E'.
ELSE.

ENDIF.
ELSE.
MESSAGE 'Please Enter Purchasing Document Number' TYPE 'E'.
ENDIF.

Thankyou.

raymond_giuseppi
Active Contributor
0 Kudos

Look at definition of field EBELN, you will find that its domain uses conversion exit ALPHA.

Before generating an error message when you receive less (more?) than 10 characters (data not coming from SAP or poorly written program) you could always call the conversion module CONVERSION_EXIT_ALPHA_INPUT. This will frame numbers to the right by adding trailing zeroes or frame texts to the left by removing leading blanks.

Then, as already written, add some check with strlen( field ) = 10.