Check Length and Alpha Numeric Variable

*
* Program to Check Length and Alpha Numeric Variable
*
* Is there any simple way or FM to check the string contains other
* than alphanumeric(A-Z and 0-9) and give an error message.
*
* How to check the length size of a variable?
*
* Written by : SAP Basis, ABAP Programming and Other IMG Stuff
*                    http://www.erpgreat.com
*
REPORT ZCHECK_ALPHA_NUMERIC.

* Declare the variable

* For Length
data: serial_length type i.

* For Alpha numeric
data: str type string.
data: valid_characters type string.

* Fill in those valid characters you need to check
concatenate '0123456789' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'abcdefghijklmnopqrstuvwxyz' into valid_characters.

* User Input
parameters testchar(10) default '12345abc'.

* Get User Input
str = testchar.

* The Checks
if str co valid_characters.
   write: / str, 'Characters are OK'.
else.
   write: / str, 'Characters are NOT OK'.
endif.

* Check if length is equal to 10 characters
serial_length = strlen( str ).
if serial_length <> 10.
   write: / str, 'Not 10 Digit'.
endif.

*-- End Program

More ABAP Program

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

ABAP Tips
ABAP Forum for Discussion and Samples Program Codes for Abapers

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.