Determine the number of characters which are allowed in a field?

别来无恙 提交于 2019-12-11 14:32:05

问题


The is a follow-up question of SAP RFC: nuc_length vs uc_length

With PyRFC I can get the func_description like this:

get_function_description(rfc_name)

Per field I can read uc_length and nuc_length.

How can I determine the number of unicode characters which I can put into the field if nuc_length=40 and uc_length=80?


回答1:


Unfortunately this is not possible, I think. From the given length in bytes you can only calculate a maximum number of characters which would fit into this field.

For unicode ABAP systems we know that SAP stores the character data in code pages 4102 / 4103 which is UTF-16 (big and little endian format). That means a character needs at least 2 bytes, i.e. the maximum length can be calculated as uc_length / 2 = 40 chars in your example. I don't think that SAP already uses any 4-byte character yet. However, this would be possible with code pages 4102 / 4103. Therefore it depends on which Unicode character you will put in the field, it might be that less than 40 characters could be stored in a field with uc_length=80.

This is even more difficult with non-Unicode ABAP systems. As long as you only use code page 1100 with English logon language, a character usually only needs 1 byte. But if for example, using Japanese and code page 8000, then text data can contain mixed US-ASCII characters and Japanese characters. That means the text field may contain both: 1-byte characters and 2-byte characters. And to make it even more difficult, even 3-byte characters exist for all non-unicode code pages including code page 1100. For example, there are some SAP specific character icons/symbols with this length. Hence, the nuc_length=40 field can contain 40 Unicode characters at the maximum, but also only 13 characters in the worst case. It depends on which code page is being used and which Unicode characters you are filling into the field.



来源:https://stackoverflow.com/questions/58203229/determine-the-number-of-characters-which-are-allowed-in-a-field

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!