cancel
Showing results for 
Search instead for 
Did you mean: 

How to find Length of String

former_member720137
Active Participant
0 Kudos

Hi

how to find length of a string.. i have a requirement that user cannot add more than 9 digits in a string.. i am new to WD Abap..

Regards,

Puneet

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You can use STRLEN command for your requirement.

First read your input field using code wizard.

Then using STRLEN command you can find the length of the Input field.

For Example :

Here input is your input field.

data :    length type i.
 
length = strlen(input).

If length < 9.

raise error msg.

endif.

Edited by: Viji on Mar 26, 2008 11:30 AM

former_member720137
Active Participant
0 Kudos

Hi Viji

Actually i have to read a table and then validate the string length of all the colums. can u give some ex of that..

e.g : for calculating 12 colums string length i hv to define 12 variables.. or any other approach is there..

former_member189058
Active Contributor
0 Kudos

Hi Puneet...

The UI Element Input Field has a Property "LENGTH". In case you want to restrict the length of user input. Specify the length there.

Former Member
0 Kudos

Hi,

I think there is no another way to achieve your requirement.

Its a good way to restrict the field length.

Thanks.

former_member720137
Active Participant
0 Kudos

Hi Reema

I have set the length property of Input Field as '10' but still user is able to enter as many digits as he wants..

Regards

Puneet

former_member189058
Active Contributor
0 Kudos

Hi Puneet,

What is the data type of the context attribute that is bound to the input field. Use a data element of length 10. Length of data element of the attribte that is bound to the input field surely restricts the number of charcters that a user can enter.

Regards,

Reema.

Former Member
0 Kudos

HI Puneet,

1. Go to SE11 and create Data element with your specified length. Ex : ZTemp [ char length 10].

2. Then give the type of your attribute as ZTemp.

3. Set the length as 10 for the input field in Layout of your application.

So follow these procedure you can restrict user enteries at the input field.

Thanks.

former_member720137
Active Participant
0 Kudos

Hi

Data type of context attribute is String , there is no other way apart from creating this data element.

Former Member
0 Kudos

Hi,

With out Data element you cant achieve your requirement.

There is no possibilities avilable at the properties of Input field.

Thanks.

former_member189058
Active Contributor
0 Kudos

If you do not want to restrict field length at data element level, validate the input field some action. eg if you have a button on the view, in the Event handler of the action bound to the button, read the current element's static attributes and give an error message if length of particular atrrib is greater than 10.

But this will not restrict the user from entering a longer string. It will only validate the length after user has entered it .. on some action.

Data Element length restriction is best suited to restrict user input.

Regards,

Reema

Answers (0)