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

length specification

Former Member
0 Likes
443

Is there any way to get the length specified for an element.

say if i declare a variable in a global structure

data m type c length 3.

is there any way for me to prgramtically retrieve this length.

Moderator message: please search for information before posting.

Message was edited by: Thomas Zloch

1 REPLY 1
Read only

VitorBrevilieri
Explorer
0 Likes
375

You have to use RTTI.

ABAP gives you classes to handle it.

Try the following code:

=====================================

REPORT  ZVUB_RTTI_02.

DATA: my_var TYPE c LENGTH 15.

DATA: lr_descr TYPE REF TO CL_ABAP_TYPEDESCR.
DATA: li_length TYPE I.
CALL METHOD cl_abap_typedescr=>describe_by_data
   EXPORTING
     p_data      = my_var
   receiving
     p_descr_ref = lr_descr.
li_length = lr_descr->LENGTH.
 
WRITE: 'My Var length is ', li_length.

=====================================

This is it!

Faca na Caveira.