ABAP字符串常用操作

Process Internal DataByte String and Character String Processing
CONCATENATE 连接字符串 [SEPARATED BY 分割符]
find

SPLIT 拆分子串
------------------------------------------------------
取前八位
data a type c(30).
a = '88888888abcdefg'.
a = a(6). "取前6位
a = a+6(1). "取第7位
a = a+6 . "取第六位后的所有字符
-------------------------------------------------------
拆分
split XXX at into table XXX
SPLIT dobj AT sep INTO
{ {result1 result2 ...} | {TABLE result_tab} }
[IN {BYTE|CHARACTER} MODE].
--------------------------------------------------------
拼接
DATA NAME (30).
NAME(10) = ' Dr.',
NAME+10(10) = 'Michael',
NAME+20(10) = 'Hofmann'.
CONDENSE NAME.
WRITE NAME.
-------------------------------------------------------
去空格
CONDENSE
-------------------------------------------------------
查找
Search for all occurrences of the string "now" in a string literal using a WHILE loop. After every successful search, the search range is redefined to start after the found location. This enables you to find all occurrences of the search string even in releases before 7.0.
DATA: patt TYPE string VALUE `now`,
text TYPE string,
off TYPE i,
moff TYPE i,
mlen TYPE i.
off = 0.
WHILE sy-subrc = 0.
FIND patt IN SECTION OFFSET off OF
`Everybody knows this is nowhere`
MATCH OFFSET moff
MATCH LENGTH mlen.
IF sy-subrc = 0.
WRITE / moff.
off = moff + mlen.
ENDIF.
ENDWHILE.
------------------------------------------------------------
补零
数字前补零
用途:
在查语句中,'00006' 和 '6' 是不同的字符,
而SAP会自动将查询条件变量前面的零去掉。导致查询条件不正确,
这时候要用CONVERSION_EXIT_ALPHA_INPUT进行补零。
call function 'CONVERSION_EXIT_ALPHA_INTPUT'
exporting
input = &1
importing
output = &1.

注意:变量类型要与数据库字段类型一直,否则补零的位数不正确。
去零
数字前去零
用途:
在输出的时候,'00006' 和 '6' 是不同的字符,要求把前面的零去掉
这时候要用CONVERSION_EXIT_ALPHA_OUTPUT进行去零。
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = &1
importing
output = &1.

------------------------------------------------------------
字符串长度
strlen( char_var )
------------------------------------------------------------
回车符
A Virtual Characterstic is a normal Characterstic,The Only difference is the data will be Updated at the time of Query Execution.Just Create a Characterstic add this Char to the Cube.You need to write some ABAP Code to Update this Char.
You will find the Doumentation and Example in SMOD for Virtual Characterstics and Keyfigures.
for Documentation and Example.
Goto Tcode SMOD -> Enter Enhancement as RSR00002 ,Select the Radio button Documentation -> Click on Display
用sap的类CL_ABAP_CHAR_UTILITIES( TYPE-POOLS: abap.).
CL_ABAP_CHAR_UTILITIES中有字符常量:如:CR_LF,HORIZONTAL_TAB,NEWLINE等等.
-------------------------------------------------
是否全是数字
if aaa CO '01234567888889 '.
---------------------------------------------------
数学函数
ABAP 代码编辑器中 strlen F1。
ABAP - Keyword documentation
ABAP By Theme
Built-in Type, Data Objects, and Functions
Built-in Functions
Mathematical Functions
------------------------------------------------------------

Process Internal DataByte String and Character String Processing
CONCATENATE 连接字符串 [SEPARATED BY 分割符]
find

SPLIT 拆分子串
------------------------------------------------------
取前八位
data a type c(30).
a = '88888888abcdefg'.
a = a(6). "取前6位
a = a+6(1). "取第7位
a = a+6 . "取第六位后的所有字符
-------------------------------------------------------
拆分
split XXX at into table XXX
SPLIT dobj AT sep INTO
{ {result1 result2 ...} | {TABLE result_tab} }
[IN {BYTE|CHARACTER} MODE].
--------------------------------------------------------
拼接
DATA NAME (30).
NAME(10) = ' Dr.',
NAME+10(10) = 'Michael',
NAME+20(10) = 'Hofmann'.
CONDENSE NAME.
WRITE NAME.
-------------------------------------------------------
去空格
CONDENSE
-------------------------------------------------------
查找
Search for all occurrences of the string "now" in a string literal using a WHILE loop. After every successful search, the search range is redefined to start after the found location. This enables you to find all occurrences of the search string even in releases before 7.0.
DATA: patt TYPE string VALUE `now`,
text TYPE string,
off TYPE i,
moff TYPE i,
mlen TYPE i.
off = 0.
WHILE sy-subrc = 0.
FIND patt IN SECTION OFFSET off OF
`Everybody knows this is nowhere`
MATCH OFFSET moff
MATCH LENGTH mlen.
IF sy-subrc = 0.
WRITE / moff.
off = moff + mlen.
ENDIF.
ENDWHILE.
------------------------------------------------------------
补零
数字前补零
用途:
在查语句中,'00006' 和 '6' 是不同的字符,
而SAP会自动将查询条件变量前面的零去掉。导致查询条件不正确,
这时候要用CONVERSION_EXIT_ALPHA_INPUT进行补零。
注意:变量类型要与数据库字段类型一直,否则补零的位数不正确。
去零
数字前去零
用途:
在输出的时候,'00006' 和 '6' 是不同的字符,要求把前面的零去掉
这时候要用CONVERSION_EXIT_ALPHA_OUTPUT进行去零。

------------------------------------------------------------
字符串长度
strlen( char_var )
------------------------------------------------------------
回车符
A Virtual Characterstic is a normal Characterstic,The Only difference is the data will be Updated at the time of Query Execution.Just Create a Characterstic add this Char to the Cube.You need to write some ABAP Code to Update this Char.
You will find the Doumentation and Example in SMOD for Virtual Characterstics and Keyfigures.
for Documentation and Example.
Goto Tcode SMOD -> Enter Enhancement as RSR00002 ,Select the Radio button Documentation -> Click on Display
用sap的类CL_ABAP_CHAR_UTILITIES( TYPE-POOLS: abap.).
CL_ABAP_CHAR_UTILITIES中有字符常量:如:CR_LF,HORIZONTAL_TAB,NEWLINE等等.
-------------------------------------------------
是否全是数字
if aaa CO '01234567888889 '.
---------------------------------------------------
数学函数
ABAP 代码编辑器中 strlen F1。
ABAP - Keyword documentation
ABAP By Theme
Built-in Type, Data Objects, and Functions
Built-in Functions
Mathematical Functions
------------------------------------------------------------

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/190059/viewspace-476664/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/190059/viewspace-476664/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值