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

unicode error

Former Member
0 Likes
1,055

Hi,

I am getting unicode error : gt_ftp must be a character type (c.n,d,t ).

gt_ftp is a structure .

vl_len = STRLEN( gt_ftp ).

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,028

What vikranth said is correct ,

There is no SAP Defined variable to calculate teh length of Structure

Just check what values you require and add them.

Regards

Sas

9 REPLIES 9
Read only

Former Member
0 Likes
1,028

Can you show us the declaration of gt_ftp ? May be you will have to use specific fields to calculate the strlen instead of the whole structure

Vikranth

Read only

0 Likes
1,028

Hi,

what is the way , which type of fields need to be considered for finding length of structure

DATA: BEGIN OF gt_ftp OCCURS 0,

kunnr LIKE kna1-kunnr,

hx01(1) TYPE x ,

name1 LIKE kna1-name1,

hx06(1) TYPE x ,

hx25(1) TYPE x ,

END OF gt_ftp .

Read only

0 Likes
1,028

Hello,

Change the structure definition as below and try


DATA: BEGIN OF gt_ftp OCCURS 0,
kunnr LIKE kna1-kunnr,
hx01(1) TYPE c ,
name1 LIKE kna1-name1,
hx06(1) TYPE c ,

hx25(1) TYPE c ,
END OF gt_ftp .

and use cl_abap_char_utilities=>horizontal_tab or the corresponding attribute the hx* fields.

After changing all the fields to Type c, use the solution suggested by Marcin. That will place the whole structure value into the string after which you can calculate the length

Vikranth

Read only

0 Likes
1,028

what is the way , which type of fields need to be considered for finding length of structure

In your case you can't check character length of the components of this structure. This is because some of them are of type x not c . So basically you need to determine the internal length of the structure (meaning in bytes not in chars ). For this you can use the following


DATA: str_bytes TYPE i.

DATA: r_compdescr TYPE REF TO cl_abap_structdescr.

FIELD-SYMBOLS: <comp> TYPE abap_compdescr.

START-OF-SELECTION.
  r_compdescr ?= cl_abap_typedescr=>describe_by_data( gt_ftp ).

  LOOP AT r_compdescr->components ASSIGNING <comp>.
    ADD <comp>-length TO str_bytes.
  ENDLOOP.
  WRITE:'Structure has ', str_bytes, ' bytes'.

Regards

Marcin

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,028

Can we not use a DESCRIBE DISTANCE IN BYTE MODE instead ? Refer: [http://help.sap.com/abapdocu_70/en/ABAPDESCRIBE_DISTANCE.htm]

Read only

0 Likes
1,028

Sure we can, I was thinking of that initially, but the one above is just I like more as it provides additional information about our structure like components name, type etc.

Regards

Marcin

Read only

Former Member
0 Likes
1,029

What vikranth said is correct ,

There is no SAP Defined variable to calculate teh length of Structure

Just check what values you require and add them.

Regards

Sas

Read only

Former Member
0 Likes
1,028

Hi Ranjna,

STRLEN works only with character-type fields (C, N, D, T) and not with structure type fields. Check this link: [Finding Length of fields|;.

Instead, you could copy your structure into a STRING type variable and find the length using the STRLEN statement. Here is a short example:


concatenate gt_ftp-field1
            gt_ftp-field2
            gt_ftp-field3
      into gv_string.

lv_length = strlen( gv_string ).

Hope this helps! Do let me know if you need anything else!!

Cheers,

Shailesh.

Read only

MarcinPciak
Active Contributor
0 Likes
1,028

Assuming gt_ftp corresponds to a strucutre you can try this way



data: container(1000) type c.

call method CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_C
  exporting  IM_VALUE               = gt_ftp
  importing  EX_CONTAINER           = CONTAINER
  exceptions ILLEGAL_PARAMETER_TYPE = 1
             others                 = 2.

vl_len = STRLEN( CONTAINER ).

Regards

Marcin