ABAP RAWSTRING(XSTRING) 类型
用F1查看的时候,这里是这样说的:
The types RAWSTRING and STRING have a variable length. A maximum length for these types can be specified, but has no upper limit.
The type SSTRING is available as of release 6.10 and it has a variable length. Its maximum length must be specified and is limited to 255. The advantage of this type compared with CHAR, is that it is assigned to the ABAP type string.
效果如下:
用几个例子说明一下
例子1:
DATA str TYPE sSTRING. DATA str1 TYPE string. DATA str2 TYPE xstring."这个就是rawstring类型 DATA STR3 TYPE STRING. str = '好好学习'. str1 = str. str2 = str. WRITE :/ 'str1:',str1. ULINE. WRITE :/ 'str2:',str2. ULINE. STR3 = STR2. WRITE :/ 'str3:',STR3. ULINE.
结果:
结论1:xstring不支持中文
例子二:
DATA str TYPE sSTRING. DATA str1 TYPE string. DATA str2 TYPE xstring."这个就是rawstring类型 DATA STR3 TYPE STRING. str = 'ABCDEFGH'. str1 = str. str2 = str. WRITE :/ 'str1:',str1. ULINE. WRITE :/ 'str2:',str2. ULINE. STR3 = STR2. WRITE :/ 'str3:',STR3. ULINE.
结果:
结论2:xstring支持6个字母
例子3:
DATA str TYPE sSTRING. DATA str1 TYPE string. DATA str2 TYPE xstring."这个就是rawstring类型 DATA STR3 TYPE STRING. str = 'abcd'. str1 = str. str2 = str. WRITE :/ 'str1:',str1. ULINE. WRITE :/ 'str2:',str2. ULINE. STR3 = STR2. WRITE :/ 'str3:',STR3. ULINE.
结果:
结论3:Xstring不支持小写字母
例子4:
DATA str TYPE sSTRING. DATA str1 TYPE string. DATA str2 TYPE xstring."这个就是rawstring类型 DATA STR3 TYPE STRING. str = 'AaBbCc'. str1 = str. str2 = str. WRITE :/ 'str1:',str1. ULINE. WRITE :/ 'str2:',str2. ULINE. STR3 = STR2. WRITE :/ 'str3:',STR3. ULINE.
结果:
结论4:当xstring一旦遇到不支持的,立刻停止,还有,大家要注意后面的0
例子5:
DATA str TYPE sSTRING. DATA str1 TYPE string. DATA str2 TYPE xstring."这个就是rawstring类型 DATA STR3 TYPE STRING. str = 'ABC'. str1 = str. str2 = str. WRITE :/ 'str1:',str1. ULINE. WRITE :/ 'str2:',str2. ULINE. STR3 = STR2. WRITE :/ 'str3:',STR3. ULINE.
结果:
结论5:如果xstring的变量,没有到6个字母的时候,都会后面补0
补充一个
结论6:我这里的str3都是用到str2的值,没经过处理,直接交给str3.
就是说,当一个xstring变量不支持的值,赋值给它的时候,它会取到自己能读取的部分,而且就算最后想还原,也不可能了。
所以,用xstring是一个很好的通信加密协议!!!!好好利用吧!!
本帖转自 http://hi.baidu.com/zzp0805/item/38a3f4f40194c527753c4c14