`
zjut_xiongfeng
  • 浏览: 271397 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

ABAP 字符串处理

阅读更多

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.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics