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

Create data type string with restriction

Former Member
0 Likes
678

Hello,

There is a way to build string with restriction of length ,I know that basically string don't have

any restriction but i need to create data somehow type string with restriction of length like 10 , 20 ,100 etc

when i try to do create data lv_data type ('string') length 8.

i get dump since you cannot limit the string length but there is some workaround ?

Thanks,

Joy

1 ACCEPTED SOLUTION
Read only

SureshRa
Active Participant
0 Likes
636

You can try this


DATA weird_string TYPE REF TO DATA.
FIELD-SYMBOLS <fs_string> TYPE STRING.
CREATE DATA weird_string TYPE c LENGTH 8.
ASSIGN weird_string->* TO <fs_string>.
*Now <fs_string> is a limited (8 char) string ... weird !!

Regards

Suresh

5 REPLIES 5
Read only

Former Member
0 Likes
636

a string with a length is a char(length).

Read only

Former Member
0 Likes
636

Hi,

try with below declaration...

data lv_data(100) type c.

Ram.

Read only

SureshRa
Active Participant
0 Likes
637

You can try this


DATA weird_string TYPE REF TO DATA.
FIELD-SYMBOLS <fs_string> TYPE STRING.
CREATE DATA weird_string TYPE c LENGTH 8.
ASSIGN weird_string->* TO <fs_string>.
*Now <fs_string> is a limited (8 char) string ... weird !!

Regards

Suresh

Read only

matt
Active Contributor
0 Likes
636

Create an object class to emulate a limited length string, in SE24.

Read only

Former Member
0 Likes
636

Hello,

Why don't you try in this manner

PARAMETERS : p_name TYPE string.
DATA : len TYPE i.
len = strlen( p_name ).
IF len gt 8.
 MESSAGE 'String length exceeds 8 characters' TYPE 'E'.
ELSE.
...
(Your business logic...)
....
ENDIF.

Here in the above example, we are restricting the string length to 8 characters.