CONCATENATE:合并字符串.

CONCATENATE f1 … fn INTO g [SEPARATED BY h].

 1 * CONCATENATE合并字符串
2 DATA: c1(10) TYPE c VALUE 'Sum',
3 c2(3) TYPE c VALUE 'mer',
4 c3(5) TYPE c VALUE 'holi ',
5 c4(10) TYPE c VALUE 'day',
6 c5(30) TYPE c ,
7 sep(3) TYPE c VALUE ' - '.
8 CONCATENATE c1 c2 c3 c4 INTO c5.
9 WRITE c5.
10 CONCATENATE c1 c2 c3 c4 INTO c5 SEPARATED BY sep.
11 WRITE / c5.

--------------------------------------------------------

输出结果:
Summerholiday
Sum - mer - holi - day

--------------------------------------------------------

SPLIT: 字符串拆分.

SPLIT f AT g INTO h1 … hn.

SPLIT f AT g INTO TABLE itable.

 1 * splitting strings
2 DATA: string10(60) TYPE c ,
3 p1(20) TYPE c VALUE '++++++++++++++++++++',
4 p2(20) TYPE c VALUE '++++++++++++++++++++',
5 p3(20) TYPE c VALUE '++++++++++++++++++++',
6 p4(20) TYPE c VALUE '++++++++++++++++++++',
7 del10(3) TYPE c VALUE '***'.
8 string10 = ' Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5'.
9 WRITE string10.
10 SPLIT string10 AT del10 INTO p1 p2 p3 p4.
11 WRITE / p1.
12 WRITE / p2.
13 WRITE / p3.
14 WRITE / p4.

--------------------------------------------------------

输出结果:

Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5

Part 1

Part 2

Part 3

Part 4 *** Part 5

--------------------------------------------------------

SHIFT:字符串整体或者字串进行转移.

如果SHIFT 操作的对象是 C类型, 则所有字节都会向前移动一位,最后一位用空格代替;

如果SHIFT操作的对象是String类型,则所有字符都会向前移动一位,最后一位删除;

SHIFT c <LEFT/RIGHT/CIRCULAR>.

SHIFT c BY n PLACES.

SHIFT c UP TO c1.

 1 * SHIFT c BY n PLACES 用法.
2 DATA: t1(10) TYPE c VALUE 'abcdefghij',
3 string1 LIKE t1.
4
5 string1 = t1.
6 WRITE string1.
7 SHIFT string1.
8 WRITE / string1.
9 string1 = t1.
10 SHIFT string1 BY 3 PLACES LEFT.
11 WRITE / string1.
12 string1 = t1.
13 SHIFT string1 BY 3 PLACES RIGHT.
14 WRITE / string1.
15 string1 = t1.
16 SHIFT string1 BY 3 PLACES CIRCULAR.
17 WRITE / string1.

--------------------------------------------------------

输出结果:

abcdefghij   “string1

bcdefghij

defghij

abcdefg

defghijabc

--------------------------------------------------------

 1 * SHIFT c UP TO c1
2 DATA: t2(10) TYPE c VALUE 'abcdefghij',
3 string2 LIKE t2,
4 str2(2) TYPE c VALUE 'ef'.
5
6 string2 = t2.
7 WRITE string2.
8 SHIFT string2 UP TO str2.
9 WRITE / string2.
10 string2 = t2.
11 SHIFT string2 UP TO str2 LEFT.
12 WRITE / string2.
13 string2 = t2.
14 SHIFT string2 UP TO str2 RIGHT.
15 WRITE / string2.
16 string2 = t2.
17 SHIFT string2 UP TO str2 CIRCULAR.
18 WRITE / string2.

--------------------------------------------------------

输出结果:

abcdefghij

efghij

efghij

abcdef

efghijabcd

--------------------------------------------------------

移除字符串左/右边的子字符串:

SHIFT c LEFT DELETEING LEADING c1.

SHIFT c RIGHT DELETEING TRAILING c1.

 1 * SHIFT c LEFT/RIGHT DELETEING LEADING c1
2 DATA: t3(14) TYPE c VALUE ' abcdefghij',
3 string3 LIKE t3,
4 str3(6) TYPE c VALUE 'ghijkl'.
5
6 string3 = t3.
7 WRITE string3.
8 SHIFT string3 LEFT DELETING LEADING space.
9 WRITE / string3.
10 string3 = t3.
11 SHIFT string3 RIGHT DELETING TRAILING str3.
12 WRITE / string3.

--------------------------------------------------------

输出结果:

abcdefghij

abcdefghij

abcdef

--------------------------------------------------------

CONDENSE:重新整合分配字符串.

CONDENSE c <NO-GAPS>.

 1 * condensing strings
2 DATA: string9(25) TYPE c VALUE ' one two three four',
3 len9 TYPE i.
4
5 len9 = strlen( string9 ).
6 WRITE: string9, '!'.
7 WRITE: / 'Length: ', len9.
8 CONDENSE string9.
9 len9 = strlen( string9 ).
10 WRITE: string9, '!'.
11 WRITE: / 'Length: ', len9.
12 CONDENSE string9 NO-GAPS.
13 len9 = strlen( string9 ).
14 WRITE: string9, '!'.
15 WRITE: / 'Length: ', len9.

--------------------------------------------------------

输出结果:

one  two   three    four !

Length:          25  one two three four        !

Length:          18  onetwothreefour           !

Length:          15

--------------------------------------------------------

TRANSLATE:实现字符串转换.

TRANSLATE c TO UPPER CASE.

TRANSLATE c TO LOWER CASE.

TRANSLATE c USING c1.

 1 * translating signs
2 DATA: t5(10) TYPE c VALUE 'AbCdEfGhIj',
3 string5 LIKE t5,
4 rule5(20) TYPE c VALUE 'AxbXCydYEzfZ'.
5
6 string5 = t5.
7 WRITE string5.
8 TRANSLATE string5 TO UPPER CASE. "#EC SYNTCHAR
9 WRITE / string5.
10 string5 = t5.
11 TRANSLATE string5 TO LOWER CASE. "#EC SYNTCHAR
12 WRITE / string5.
13 string5 = t5.
14 TRANSLATE string5 USING rule5. "#EC SYNTCHAR
15 WRITE / string5.

----------------------------------------------

输出结果:

AbCdEfGhIj

ABCDEFGHIJ

abcdefghij

xXyYzZGhIj

----------------------------------------------

TRANSLATE c … FROM CODE PAGE g1 … TO CODE PAGE g2.

OVERLAY:参考字符串对空白字符进行填充.

OVERLAY c with c1.

REPLACE:字符串按条件取代.

REPLACE f … WITH g … INTO h.

 1 * replacing values
2 DATA: t4(10) TYPE c VALUE 'abcdefghij',
3 string4 LIKE t4,
4 str41(4) TYPE c VALUE 'cdef',
5 str42(4) TYPE c VALUE 'klmn',
6 str43(2) TYPE c VALUE 'kl',
7 str44(6) TYPE c VALUE 'klmnop',
8 len4 TYPE i VALUE 2.
9
10 string4 = t4.
11 WRITE string4.
12 REPLACE str41 WITH str42 INTO string4.
13 WRITE / string4.
14 string4 = t4.
15 REPLACE str41 WITH str42 INTO string4 LENGTH len4.
16 WRITE / string4.
17 string4 = t4.
18 REPLACE str41 WITH str43 INTO string4.
19 WRITE / string4.
20 string4 = t4.
21 REPLACE str41 WITH str44 INTO string4.
22 WRITE / string4.

----------------------------------------------

输出结果:

abcdefghij

abklmnghij

abklmnefgh

abklghij

abklmnopgh

--------------------------------------------------------

SERACH:搜索指定字符串. 通过SY_SUBRC取值得到查询结果.

SERACH f FOR g.

[ABBREVIATED] : 从指定字符串中按顺序搜索相匹配字符串 abbreviated

[STARTING AT n1 ]:从字符串第n1个字符串开始搜索

[ENDING AT n2 ]:搜索到字符串第 n2个字符为止

[AND MARK]:从指定字符串中模糊搜索相匹配字符串

 1 *searching strings
2 DATA string7(30) TYPE c VALUE 'This is a little sentence.'.
3 WRITE: / 'Searched', 'SY-SUBRC', 'SY-FDPOS'.
4
5 ULINE /1(26).
6 SEARCH string7 FOR 'X'.
7 WRITE: / 'X', sy-subrc UNDER 'SY-SUBRC',
8 sy-fdpos UNDER 'SY-FDPOS'.
9 SEARCH string7 FOR 'itt '.
10 WRITE: / 'itt ', sy-subrc UNDER 'SY-SUBRC',
11 sy-fdpos UNDER 'SY-FDPOS'.
12 SEARCH string7 FOR '.e .'.
13 WRITE: / '.e .', sy-subrc UNDER 'SY-SUBRC',
14 sy-fdpos UNDER 'SY-FDPOS'.
15 SEARCH string7 FOR '*e'.
16 WRITE: / '*e ', sy-subrc UNDER 'SY-SUBRC',
17 sy-fdpos UNDER 'SY-FDPOS'.
18 SEARCH string7 FOR 's*'.
19 WRITE: / 's* ', sy-subrc UNDER 'SY-SUBRC',
20 sy-fdpos UNDER 'SY-FDPOS'.

----------------------------------------------

输出结果:

Searched SY-SUBRC SY-FDPOS

--------------------------------------------

X            4        0

itt           0       11

.e .          0       15

*e           0       10

s*           0       17

----------------------------------------------

 1 *
2 DATA: string8(30) TYPE c VALUE 'This is a fast first example.',
3 pos8 TYPE i,
4 off8 TYPE i.
5
6 WRITE / string8.
7 SEARCH string8 FOR 'ft' ABBREVIATED.
8 WRITE: / 'SY-FDPOS:', sy-fdpos.
9 pos8 = sy-fdpos + 2.
10 SEARCH string8 FOR 'ft' ABBREVIATED STARTING AT pos8 AND MARK.
11 WRITE / string8.
12 WRITE: / 'SY-FDPOS:', sy-fdpos.
13 off8 = pos8 + sy-fdpos - 1.
14 WRITE: / 'Off:', off8.

----------------------------------------------

输出结果:

This is a fast first example.

SY-FDPOS:    10

This is a fast FIRST example.

SY-FDPOS:     4

Off:         15

----------------------------------------------

SERACH itab FOR g.

[ABBREVIATED] : 从内表中按顺序逐行搜索相匹配字符串

[STARTING AT line1 ]:从字符串第n1个字符串开始搜索

[ENDING AT line2 ]:搜索最大范围到内表中具体某行

[AND MARK]:从内表中模糊搜索相匹配字符串

搜索内表与字符串操作一致:

PS:其中源码部分来自SAP官方文档。

ABAP 字符串函数的更多相关文章

  1. ABAP CDS - 字符串函数

    下表显示了ABAP CDS中CDS视图中字符串的潜在SQL函数,以及对参数的要求.函数的含义可以在字符串的SQL函数下找到. 函数 参数类型 返回类型 CONCAT(arg1, arg2) See b ...

  2. ThinkPHP 模板substr的截取字符串函数

    ThinkPHP 模板substr的截取字符串函数在Common/function.php加上以下代码 /** ** 截取中文字符串 **/ function msubstr($str, $start ...

  3. SQL字符串函数

    LEN() :计算字符串长度(字符的个数.)datalength();//计算字符串所占用的字节数,不属于字符串函数.测试varchar变量与nvarchar变量存储字符串a的区别.见备注1.LOWE ...

  4. Python3中的字符串函数学习总结

    这篇文章主要介绍了Python3中的字符串函数学习总结,本文讲解了格式化类方法.查找 & 替换类方法.拆分 & 组合类方法等内容,需要的朋友可以参考下. Sequence Types ...

  5. TSQL 字符串函数:截断和查找

    字符串截断函数是指:Stuff 和 SubString,字符串查找函数是:CharIndex 和 PatIndex 一,SubString 截取子串 最常用的字符串函数,用于截取特定长度的子串. SU ...

  6. c#编程基础之字符串函数

    c#常用的字符串函数 例一: 获取字符串的大小写函数 ToLower():得到字符串的小写形式 ToUpper():得到字符串的大写形式 注意: 字符串时不可变的,所以这些函数都不会直接改变字符串的内 ...

  7. SQLSERVER常见系统函数之字符串函数(一)

    好久没有写博客了,这段时间准备写一下字符串函数 QQ群: 499092562:欢迎交流 字符串函数: 1.LEN(需要获取长度的字符串) 返回:字符串的长度 示例: SELECT LEN('小搬运工很 ...

  8. python笔记-字符串函数总结

    字符串函数: chr() 数字转ASCII chr(96)="a" ord() ASCII转数字 ord("a")=96 isspace() 判断是否为空格 s ...

  9. Sql Server函数全解<一>字符串函数

    阅读目录 1.ASCII()函数 2.CHAR()函数 3.LEFT()函数 4.RIGHT()函数 5.LTRIM()函数 6.RTRIM()函数 7.STR()函数 8.字符串逆序的函数REVER ...

随机推荐

  1. 记一次http接口格式摸索

    有一个需求,需要用到内部通讯工具的一个ERP转发接口,虽然有接口文档,但是对中文的编码格式没有提示,中间几经周折,最后才想起来通过F12查看提供的测试接口发送请求时的数据格式来分析,经过解析中文只有被 ...

  2. jmeter解决登录token获取

    1.以百度登录为例 2.打开console 3.根据console结果设置公共的header在test plan 4.建立测试计划-test plan 5.正则表达式提取器,获取token 6.登录t ...

  3. Javascript学习笔记5 - 滑动Slides

    开始之前:http://docs.jquery.com/ 是jQuery文档的网站, https://jsfiddle.net/是js的在线验证工具 在html中,有这几个标签: javascript ...

  4. tkinter面板切换

  5. iOS基础知识之多态问题

    多态是基于继承而言的,例如自定义父类Person,子类Son,那么可能会出现如下情况: Person *p =[ [Son alloc]init]; 这种情况时,便是多态的使用.多态属于动态创建对象, ...

  6. spark 常用技巧总结

    解析url scala> import java.net.URLimport java.net.URL scala> val urlstr="http://www.baidu.c ...

  7. 数电——全减器分析(用74HC138设计提示)

    -1=1(即Di=1). Di=(Y1' * Y2' * Y4' * Y7')'可以得到74HC138来表示,(注意:Ai,Bi,Ci-1的各自位权对应A2,A1,A0) Ci同理可得.

  8. 2018年1月21日--2月4日 NAS

    二十号去比赛时,与同事闲聊时说起家庭服务器,后来搜到nas(网络附着存储器),找到freenas,突然觉得很有用,手机拍了大量的照片视频,存储在电脑,已经换过几次硬盘了,对于这些珍贵的资料,万一硬盘坏 ...

  9. 访问服务器时一直在转圈,等待localhost响应

    之后把zookeeper的服务器的防火墙关了,就有响应了.可能就是防火墙的问题.

  10. Linux sed 流编辑器

    sed是stream editor的简称,也就是流编辑器.盗用一张图片解释原理 命令格式: SYNPPSIS: sed [OPTION]… {script-only-if-no-other-scrip ...