report demo_data_string.
* shifting strings by a given number of places
data: t1(10) type c value 'abcdefghij',
string1 like t1.
string1 = t1.
write string1.
shift string1.
write / string1.
string1 = t1.
shift string1 by 3 places left.
write / string1.
string1 = t1.
shift string1 by 3 places right.
write / string1.
string1 = t1.
shift string1 by 3 places circular.
write / string1.
skip.
uline.
* shifting up to a given string
data: t2(10) type c value 'abcdefghij',
string2 like t2,
str2(2) type c value 'ef'.
string2 = t2.
write string2.
shift string2 up to str2.
write / string2.
string2 = t2.
shift string2 up to str2 left.
write / string2.
string2 = t2.
shift string2 up to str2 right.
write / string2.
string2 = t2.
shift string2 up to str2 circular.
write / string2.
skip.
uline.
* shifting a string depending on the first or last sign
data: t3(14) type c value ' abcdefghij',
string3 like t3,
str3(6) type c value 'ghijkl'.
string3 = t3.
write string3.
shift string3 left deleting leading space.
write / string3.
string3 = t3.
shift string3 right deleting trailing str3.
write / string3.
skip.
uline.
* replacing values
data: t4(10) type c value 'abcdefghij',
string4 like t4,
str41(4) type c value 'cdef',
str42(4) type c value 'klmn',
str43(2) type c value 'kl',
str44(6) type c value 'klmnop',
len4 type i value 2.
string4 = t4.
write string4.
replace str41 with str42 into string4.
write / string4.
string4 = t4.
replace str41 with str42 into string4 length len4.
write / string4.
string4 = t4.
replace str41 with str43 into string4.
write / string4.
string4 = t4.
replace str41 with str44 into string4.
write / string4.
skip.
uline.
* translating signs
data: t5(10) type c value 'AbCdEfGhIj',
string5 like t5,
rule5(20) type c value 'AxbXCydYEzfZ'.
string5 = t5.
write string5.
translate string5 to upper case. "#EC SYNTCHAR
write / string5.
string5 = t5.
translate string5 to lower case. "#EC SYNTCHAR
write / string5.
string5 = t5.
translate string5 using rule5. "#EC SYNTCHAR
write / string5.
skip.
uline.
* overlaying strings
data: t6(10) type c value 'a c e g i ',
string6 like t6,
over6(10) type c value 'ABCDEFGHIJ',
str6(2) type c value 'ai'.
string6 = t6.
write string6.
write / over6.
overlay string6 with over6.
write / string6.
string6 = t6.
overlay string6 with over6 only str6.
write / string6.
skip.
uline.
*searching strings
data string7(30) type c value 'This is a little sentence.'.
write: / 'Searched', 'SY-SUBRC', 'SY-FDPOS'.
uline /1(26).
search string7 for 'X'.
write: / 'X', sy-subrc under 'SY-SUBRC',
sy-fdpos under 'SY-FDPOS'.
search string7 for 'itt '.
write: / 'itt ', sy-subrc under 'SY-SUBRC',
sy-fdpos under 'SY-FDPOS'.
search string7 for '.e .'.
write: / '.e .', sy-subrc under 'SY-SUBRC',
sy-fdpos under 'SY-FDPOS'.
search string7 for '*e'.
write: / '*e ', sy-subrc under 'SY-SUBRC',
sy-fdpos under 'SY-FDPOS'.
search string7 for 's*'.
write: / 's* ', sy-subrc under 'SY-SUBRC',
sy-fdpos under 'SY-FDPOS'.
skip.
uline.
*
data: string8(30) type c value 'This is a fast first example.',
pos8 type i,
off8 type i.
write / string8.
search string8 for 'ft' abbreviated.
write: / 'SY-FDPOS:', sy-fdpos.
pos8 = sy-fdpos + 2.
search string8 for 'ft' abbreviated starting at pos8 and mark.
write / string8.
write: / 'SY-FDPOS:', sy-fdpos.
off8 = pos8 + sy-fdpos - 1.
write: / 'Off:', off8.
skip.
uline.
* length of a string
data: int type i,
word1(20) type c value '12345',
word2(20) type c ,
word3(20) type c value ' 4 '.
int = strlen( word1 ). write int.
int = strlen( word2 ). write / int.
int = strlen( word3 ). write / int.
skip.
uline.
* condensing strings
data: string9(25) type c value ' one two three four',
len9 type i.
len9 = strlen( string9 ).
write: string9, '!'.
write: / 'Length: ', len9.
condense string9.
len9 = strlen( string9 ).
write: string9, '!'.
write: / 'Length: ', len9.
condense string9 no-gaps.
len9 = strlen( string9 ).
write: string9, '!'.
write: / 'Length: ', len9.
skip.
uline.
* concatenating strings
data: c1(10) type c value 'Sum',
c2(3) type c value 'mer',
c3(5) type c value 'holi ',
c4(10) type c value 'day',
c5(30) type c ,
sep(3) type c value ' - '.
concatenate c1 c2 c3 c4 into c5.
write c5.
concatenate c1 c2 c3 c4 into c5 separated by sep.
write / c5.
skip.
uline.
* splitting strings
data: string10(60) type c ,
p1(20) type c value '++++++++++++++++++++',
p2(20) type c value '++++++++++++++++++++',
p3(20) type c value '++++++++++++++++++++',
p4(20) type c value '++++++++++++++++++++',
del10(3) type c value '***'.
string10 = ' Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5'.
write string10.
split string10 at del10 into p1 p2 p3 p4.
write / p1.
write / p2.
write / p3.
write / p4.
skip.
uline.
* moving parts of strings
data: mc1(10) type c value 'ABCDEFGHIJ',
mc2(10) type c .
move mc1 to mc2 percentage 40.
write mc2.
move mc1 to mc2 percentage 40 right.
write / mc2.
分享到:
相关推荐
ABAP常用字符串操作收集整理 字符串连接 字符串分隔
讲解了ABAP SQL Functions for Strings的使用
1. 字符串连接 2.字符串分隔, split 一个 string 的部分到一个内表或一系列的变量
包括abap低于字符串的操作相关示例代码
abap处理字符串[参考].pdf
abap处理字符串[借鉴].pdf
ABAP 编程: ABAP ALV取消整数小数点后面的0
有安全性、快捷、方便等不同的方式来判断一个字符或者一个字符串是否为整数类型。
最全最易懂的SAP与ABAP字符的对应关系,MASTER DATA-主数据 Customer Master KNA1 Customer Basic Data KNB1 Customer Company Level Data客户的公司数据 KNVV Customer Sales Level Data 客户的销售数据 KNVP ...
SAP ABAP编程基础,适用于SAP ABAP变成初学者。
ABAP加密和解密
本程序自主开发,包括SELECT,UPDATE,DELETE,INSERT操作,SELECT 语句可以根据自定义的内表动态的输出ALV 列表,UPDATE DELETE INSERT 语句可以对数据库表进行操作. 切忌谨慎应用此程序对数据库的操作,以免造成数据...
sap abap 创建函数将阿拉伯金额数字变成人民币大写汉字,内涵具体实现代码
需求:现有ABAP长文本一条,根据其内容每132个字符就截取到内表中保存,请问什么方式合适? 实现: DATA : STR TYPE STRING. DATA : LENGTH TYPE I. STR = ‘132dsfaf456135asd1f5sda6f4s13246543ad31f32...
ABAP资料ABAP资料ABAP资料ABAP资料ABAP资料
ABAP 调用ABAP PROXY
ABAP流程处理的命令说明(stop,exit,return,check,reject)
ABAP_Excel_处理总结
此文件生成的秘钥字符串可保存到数据库中,不会出现各种特殊字符串导致数据库各种报错
abap tips abap tips abap tips abap tips abap tips