‎2013 Jul 15 4:43 PM
Hi Eperts,
Am expecting one result but its giving different output.
As per my analysis its caluclating internal format length(carrid,connid).
carrid, connid fields not using any conversion routines also.
Please refer the below screens to make better understanding.
data: value type i.
types: begin of ty_sflight,
carrid type s_carr_id, " length : 3 (internal Format length: 6 )
connid type s_conn_id, " length : 4 (internal Format length : 8 )
end of ty_sflight.
obj_ref = cl_abap_typedescr=>describe_by_value('TY_SFLIGHT' ).
WRITE: / 'Length :', obj_ref->length.
O/P : Length : 14
Actual Result : Length : 14
Expected Result : Length : 7
‎2013 Jul 15 8:24 PM
Unicode represents two bytes to represent one character. Hence the length would be double the number of characters. The length value returned is in bytes, not in character.
In SM59, take a Unicode test , you will get the result
Target is a unicode system (character size 2)
http://help.sap.com/saphelp_nw04/helpdata/en/3f/7ffb40ef74f923e10000000a155106/content.htm
So you will have to divide by 2 to get the number of characters.
WRITE: / 'Length :', obj_ref->length / 2.
Option 2.
Use CL_ABAP_ELEMDESCR with the attribute OUTPUT_LENGTH in order to get the number of characters.
descr_ref TYPE ref to cl_abap_elemdescr.
START-OF-SELECTION.
descr_ref ?= cl_abap_typedescr=>describe_by_data( TY_SFLIGHT).
* or describe_by_name or describe_by_value.
WRITE: / 'Length :', descr_ref->length .
Let me know if its coming correctly now.
‎2013 Jul 15 5:36 PM
You are pointing at two different fields. S_CONN_ID is the numc. S_CARR_ID is the Char.
Neal
‎2013 Jul 15 8:24 PM
Unicode represents two bytes to represent one character. Hence the length would be double the number of characters. The length value returned is in bytes, not in character.
In SM59, take a Unicode test , you will get the result
Target is a unicode system (character size 2)
http://help.sap.com/saphelp_nw04/helpdata/en/3f/7ffb40ef74f923e10000000a155106/content.htm
So you will have to divide by 2 to get the number of characters.
WRITE: / 'Length :', obj_ref->length / 2.
Option 2.
Use CL_ABAP_ELEMDESCR with the attribute OUTPUT_LENGTH in order to get the number of characters.
descr_ref TYPE ref to cl_abap_elemdescr.
START-OF-SELECTION.
descr_ref ?= cl_abap_typedescr=>describe_by_data( TY_SFLIGHT).
* or describe_by_name or describe_by_value.
WRITE: / 'Length :', descr_ref->length .
Let me know if its coming correctly now.