2009 Aug 24 3:43 AM
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!
2009 Aug 24 4:45 AM
2009 Aug 24 4:45 AM
2009 Aug 24 4:50 AM
Hi,
How do I check? Currently we are running NW 7.01 so I guess this is unicode.
2009 Aug 24 4:53 AM
2009 Aug 24 4:58 AM
2009 Aug 24 5:04 AM
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
a®
2009 Aug 24 5:06 AM
2009 Aug 24 5:09 AM
Hi,
When I remove the UNICODE CHECKS ACTIVE in the attributes it is giving me an error
2009 Aug 24 5:25 AM
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.
a®
2009 Aug 24 7:08 AM
Hi Ars,
It is giving me a dump.Anyway, is there a way to get the original length of my structure?
2011 May 14 2:32 PM
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
2011 May 14 3:18 PM
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