Skip to Content
0
Jan 01, 2008 at 07:45 PM

cl_abap_typedescr=>describe_by_data->length reports double length !

614 Views

Hello everybody and I wish you all a very Happy New Year !

Here is my problem:

I have created a function module with the following interface:

*"----


""Local Interface:

*" IMPORTING

*" VALUE(I_NAME) TYPE RVARI_VNAM

*" VALUE(I_TYPE) TYPE RSSCR_KIND

*" TABLES

*" T_RANGE

*" EXCEPTIONS

*" VAR_NOT_FOUND

*" NO_DATA

*"----


This FM will be used to read any variant maintained in table TVARV and will return its values in a given range (through the tables parameter t_range). For example, the program ZTEST will call this FM with a range r_ktokd (defined as: ranges: r_ktokd for kna1-ktokd) and I_NAME will have the value, say, 'ZSD_ACC_GRP'.

In order to be able to handle any type of range object defined in a program, I am trying to dynamically realize the actual length of the type range (in our example, KTOKD has length 4), so that I know exactly how to handle the data from TVARVC and move them respectively to t_range-low, t_range-high etc fields.

Therefore, I use have written the following code to do this:

DATA: wa_tvarvc TYPE tvarvc,

descr_ref TYPE REF TO cl_abap_typedescr,

wl_field_len TYPE i,

wl_high TYPE i.

CLEAR: wa_tvarvc, t_range, t_range[].

descr_ref = cl_abap_typedescr=>describe_by_data( t_range ).

  • Calculate the low-high fields' length

wl_field_len = ( descr_ref->length - 3 ) / 2 .

as t_range-sign length = 1

t_range-option length = 2

t_range-low length = 4

t_range-high length = 4

the descr_ref->length should return 11 as the total length of the t_range structure. However, it returns 22 !! So, I have changed the code as follows:

wl_field_len = ( descr_ref->length - 6 ) / 4 .

Although it works now, can someone please explain me why this happens and if there is a more safe way to do this?

Thanks in advance and HAPPY CODING in 2008 !

George