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

Programmatically determine the length of a variable

Former Member
0 Likes
575

Hi All,

I have a program that calls a subroutine multiple times.

There is a changing parameter on this subroutine e.g. f_value.

Sometimes when this subroutine is called the f_value value being passed in is based on CHAR60, other times CHAR40.

StrLen() does not do this becasue this gives me how many of the 40 or 60 characters are populated within the f_value field.

Within the subroutine I want to determine whether f_value is based on a CHAR40 or a CHAR60.

Is there a function that will allow me to determine this.

Many Thanks In Advance

David

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
535

hi,

Make use of <b>describe</b> field statement ...

describe field <fieldname> length v_len.

Regards,

Santosh<b></b>

Hi All,

I have a program that calls a subroutine multiple times.

There is a changing parameter on this subroutine e.g. f_value.

Sometimes when this subroutine is called the f_value value being passed in is based on CHAR60, other times CHAR40.

StrLen() does not do this becasue this gives me how many of the 40 or 60 characters are populated within the f_value field.

Within the subroutine I want to determine whether f_value is based on a CHAR40 or a CHAR60.

Is there a function that will allow me to determine this.

Many Thanks In Advance

David

3 REPLIES 3
Read only

suresh_datti
Active Contributor
0 Likes
535

you can use the DESCRIBE FIELD statement

~Suresh

Read only

Former Member
0 Likes
536

hi,

Make use of <b>describe</b> field statement ...

describe field <fieldname> length v_len.

Regards,

Santosh<b></b>

Read only

Former Member
0 Likes
535

Hi

Please check out the following code

DATA: ws_char TYPE char40.

DATA: descr_ref TYPE REF TO cl_abap_typedescr.

FIELD-SYMBOLS: <length> TYPE ANY.

descr_ref ?= cl_abap_tabledescr=>describe_by_data( ws_char ).

ASSIGN descr_ref->length TO <length>.