Application Development 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: 

cl_abap_structdescr=>describe_by_name gives wrong lengths...

aris_hidalgo
Contributor
0 Kudos
492

Hello Experts,

In my program I am getting the components of a structure in my program. But

I noticed during debugging that it gives out wrong length. For example, field1

of my structure has a data type of flag which means it is a CHAR with length 1 but

when I use the said method of cl_abap_structdescr my field1 has a length of 2 which

is giving me short dumps.

Below is my code:

 
TYPES: BEGIN OF gs_file_struct1,
        col1  TYPE flag,  "Indicator
        col2  TYPE flag,  "Transaction type
        col3  TYPE string,
        col4  TYPE string,
        col5  TYPE string,
        col6  TYPE string,
        col7  TYPE string,
        col8  TYPE string,
        col9  TYPE string,
        col10 TYPE string,
        col11 TYPE string,
        col12 TYPE string,
       END OF gs_file_struct1.

im_struct_name is 'GS_FILE_STRUCT1' passed to an parameter of a method.


*   Get components of structure
    lcl_sdescr ?= cl_abap_structdescr=>describe_by_name( im_struct_name ).
    lt_components[] = lcl_sdescr->components[].

*   Build fieldcatalog based from the components
    LOOP AT lt_components INTO lw_components.
      CLEAR lw_fieldcat.
      lw_fieldcat-fieldname = lw_components-name.
      lw_fieldcat-datatype  = lw_components-type_kind.
      lw_fieldcat-inttype   = lw_components-type_kind.
      lw_fieldcat-intlen    = lw_components-length.
      lw_fieldcat-decimals  = lw_components-decimals.

      APPEND lw_fieldcat TO lt_fieldcat.
      CLEAR lw_fieldcat.
    ENDLOOP.

Now, when I check the length of my COL1, it is shown as length 2 instead of 1!

1 ACCEPTED SOLUTION

former_member194669
Active Contributor
0 Kudos
174

Is you system is unicode ?

11 REPLIES 11

former_member194669
Active Contributor
0 Kudos
175

Is you system is unicode ?

0 Kudos
174

Hi,

How do I check? Currently we are running NW 7.01 so I guess this is unicode.

0 Kudos
174

login SAP and goto System--> status-> SAP system data box

0 Kudos
174

Yes, it is a unicode system.

0 Kudos
174

In Unicode

1. UTF-8 Encoding

  • This is a 8 bit encoding

  • It is a variable width multi-byte encoding

  • One Unicode character can be 1 bye, 2 bytes or 3 bytes

2. UTF-16 Encoding

  • This is the 16 bit encoding

  • One Unicode character is 2 bytes

For testing this remove the Unicode check box from attributes of the program and test

0 Kudos
174

Hi,

So is there anyway I can "prevent " this form happening?

0 Kudos
174

Hi,

When I remove the UNICODE CHECKS ACTIVE in the attributes it is giving me an error

0 Kudos
174

Check this


report zaRs
       no standard page heading line-size 255.

types: begin of gs_file_struct1,
        col1  type flag,  "Indicator
        col2  type flag,  "Transaction type
        col3  type string,
        col4  type string,
        col5  type string,
        col6  type string,
        col7  type string,
        col8  type string,
        col9  type string,
        col10 type string,
        col11 type string,
        col12 type string,
       end of gs_file_struct1.
data : gt_file_struct1 type standard table of gs_file_struct1 with header line.

data : lcl_sdescr  type ref to cl_abap_structdescr.
data : lt_components   type abap_compdescr_tab.
data : lw_components  type abap_compdescr.

*   Get components of structure
lcl_sdescr ?= cl_abap_structdescr=>describe_by_data( gt_file_struct1 ).
lt_components[] = lcl_sdescr->components[].

*   Build fieldcatalog based from the components
loop at lt_components into lw_components.
  break-point.  " Check here your value for field
endloop.

0 Kudos
174

Hi Ars,

It is giving me a dump.Anyway, is there a way to get the original length of my structure?

0 Kudos
174

I face the same "problem" and have the same question. Temporary I divide the type length by 2. Let`s see if somebody has any update. Otto

0 Kudos
174

Hi all,

isn't there an attribute like CL_ABAP_CHAR_UTILITIES=>CHARSIZE?

Look here: [Determining Field Properties |http://help.sap.com/saphelp_nw04/helpdata/en/79/c554acb3dc11d5993800508b6b8b11/frameset.htm]

Regards,

Clemens