SAP ABAP字符和字符串变量隐式转换的一些规则
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.
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- MAC下 Centos7 下 免账号免密码便捷登录服务器的正确姿势 实践笔记
- AnimatedList 介绍及使用
- Flutter之SliverAppBar
- OpenGL ES 环境搭建
- Asp.Net Core 程序部署到Linux(centos)生产环境(一):普通部署
- Asp.Net Core 程序部署到Linux(centos)生产环境(二):docker部署
- docker-compose 安装jenkins的正确姿势 实践笔记
- windows安装nginx注册为服务的正确姿势 并设置开机自启 实践笔记
- windows navicat连接oracle11G 自用 实践笔记
- docker安装官方redis集群并集群连接测试 的正确姿势 自用 实践笔记
- Asp.net Core 使用Jenkins + Dockor 实现持续集成、自动化部署(一):Jenkins安装
- Centos7安装轻量级TCP转发工具rinetd注册为服务的正确姿势 并设置开机自启 实践笔记 自用
- Connection open error . Connection Timeout Expired. The timeout period elapsed during the post-login
- macbook-12-2015款 安装win10系统 自用 实践笔记
- OpenGL ES 之attribute