One new colleague in my team asked me that some code does not work as he expected. The confuse could be summarized into following source code:
DATA: lv_i TYPE int4 VALUE 1,
lv_s TYPE string,
lv_s2 TYPE string VALUE '1',
lv_ss TYPE sstring,
lv_s3 TYPE char18.
lv_s = lv_i.
lv_ss = lv_i.
lv_s3 = lv_i.
WRITE:/ strlen( lv_s ).
WRITE:/ strlen( lv_s2 ).
WRITE:/ strlen( lv_ss ).
WRITE:/ strlen( lv_s3 ).
Can you get the correct answer without hesitation?
The answer is: 2, 1, 19, 17, which confuses my colleague a lot. The reason for first result 2: According to ABAP help, when an integer value is converted to a string value, a blank character is automatically inserted to the last place and this space is also taken into consideration for result length.
In debugger we can observe this space in Hexadecimal value view so this is the reason why we get 2 and 1 for first two strlen.
For the third and fourth test, the variables with char type are used to store the converted value.
According to ABAP help, the blank is padded on the left, which could be observed below:
Although we can still observe the existence of trailing space character in debugger, why for these two variables, the last character is not considered by strlen?
Again the answer is in help, simply because char data object with fixed length will ignore it but String type will count.
So my suggestion to my new colleagues when they meet with “weird” behavior in ABAP: always check with ABAP help first.
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关推荐
1. 字符串连接 2.字符串分隔, split 一个 string 的部分到一个内表或一系列的变量
资源名称:sap abap开发从入门到精通 内容简介: 《SAP ABAP开发从入门到精通》以应用实例的形式,讲解了SAPABAP开发的相关知识点,详细介绍了SAPABAP开发者必须掌握的包与变更传输系统(CTS)、数据类型、数据库...
从实例学sap abap编程,从实例学sap abap编程,从实例学sap abap编程
最全最易懂的SAP与ABAP字符的对应关系,MASTER DATA-主数据 Customer Master KNA1 Customer Basic Data KNB1 Customer Company Level Data客户的公司数据 KNVV Customer Sales Level Data 客户的销售数据 KNVP ...
SAP ABAP 数据库操作,快速学会ABAP!
《SAP ABAP开发技术详解(实例篇)(第二版) [1] 》除了对对SAP ABAP开发所需的常用技术(SAP报表、批量导入、对话程序、函数)做了详尽的介绍,包括基本报表、交互式报表、复杂报表、ALV(SAP List Viewer)报表、...
SAP ABAP开发学习——第9课:ALV2(视频教程) 1.SAP ABAP开发入门学习 2.含视频教程学习、PPT、作业 3.视频非常清晰
ABAP开发从入门到精通_高清自学版 SAP+ABAP开发从入门到精通 SAP开发自学必读 SAP SAP开发自学入门到精通完整版HANA开发
《SAP ABAP开发从入门到精通》以应用实例的形式,讲解了SAP ABAP开发的相关知识点,详细介绍了SAP ABAP开发者必须掌握的包与变更传输系统(CTS)、数据类型、数据库、模块化程序、内表、调试、ABAP数据字典、锁对象...
sap abap经典中文帮助 sap abap经典中文帮助
[SAP ABAP开发技术总结]ALV详解(Fuction ALV 和OO ALV) 图文并茂,详细介绍了Fuction ALV 和OO ALV的相关开发 [SAP ABAP开发技术总结]ALV详解:Function ALV(一) [SAP ABAP开发技术总结]ALV详解:Function ALV...
SAP ABAP开发学习——第19课:实战讲解(视频教程) 1.SAP ABAP开发入门学习 2.含视频教程学习、PPT、作业 3.视频非常清晰
sap abap程序 举例大全 包含所以ABAP开发程序类型
SAp abap 非常清晰的abap学习资料
SAP ABAP 代码备份下载到本地程序代码
SAP ABAP程序性能调优介绍.pptx
全面介绍SAP ABAP语言编程与开发(SAP官方文档)
SAP ABAP 常用T-CODE SAP ABAP
sap-abap
网上收集整理的SAP abap PA 试题2,还有部分资料