*******字串控制函式********
concatenate:實現字串合併
語法:concatenate f1...fn into g by h>
data: one(10) value
'hello',
two(10) value
'sap',
result1(10),
result2(10).
concatenate one two into result1 separated
by space.
concatenate one two into result2.
concatenate one two into one.
concatenate one two into two.
split:實現字串的拆分
語法1:split f at g into h1...hn
語法2:split f at g into
table itab
data: names(30) type
c value
'hello,sap',
names2 type string,
one(10) type c,
two(10) type c,
delimiter(1) value
','.
types: begin
of itab_type,
word(20),
end
of itab_type.
data: itab type
standard
table
of itab_type with
header line.
split names at delimiter into one two.
split
'one stop two stop three stop'
at 'stop'
into
table itab.
write: one.
shift:將字串整體或者子串進行轉移
語法1:shift c
語法2:shift c
by n places
語法3:shift c
up to c1
語法4:shift c
left deleting leading c1
語法5:shift c right deleting leading c1
data: str1(15) type
c value
' abcdefghij',
str2(15) type c,
str3(15) type c,
str4(15) type c,
str5(15) type c,
str6(15) type c,
three(3) type
c value
'def',
four(3) type
c value
'def',
m1(4) value
'abcd',
m2(6) value
'hij'.
str6 = str5 = str4 = str3 = str2 = str1.
shift str1.
shift str2 circular up
to three.
shift str3 right.
shift str4 circular.
shift str5 by
5 places.
shift str6 circular by
2 places.
shift str1 left deleting leading space.
shift str1 right deleting trailing m2.
if str1 eq
'abcdefg'.
write: 'eq'.
endif.
condense:重新整合分配字串
語法:condense c
.data: name(40).
name(10) = ' dr.'.
name+10(10) = 'michael'.
name+20(10) = 'hofmann'.
condense name.
if name eq
'dr.michael hofmann'.
write name.
endif.
translate:實現字串轉換
語法1:translate c
to upper case.
語法2:translate c
to lower case.
語法3:translate c
using c1
語法4:translate c
form
code
page g1...to code
page g2.
data: str1(3) type
c value
'abc',
str2(4) type
c value
'efgh'.
data: str(20) type
c value
'abcabcabcxabcf',
change(15) type
c value
'axbaybabzaczb'.
translate str using change.將str的字元和change字元逐一比較,
如果找到change中某個字元與之相等則用change中該字元後面的字元進行替換它
translate str1 to
upper case.
translate str2 to
lower case.
overlay:參考字串對空白字元進行填充
語法:overlay c1 with c2.
data: work(20) value
'th t h s ch ng d',
help(20) value
'grab a pattern'.
overlay
work
with help.
*執行結果:work = 'that has changed'
replace:字串按條件取代
語法:replace f with g into h.
data: str(10) value
'12345abcde'.
replace
'12345'
with
'56789'
into str.
write: ''.
abap 字串操作 ABAP 字串常用處理方法
split dobj at sep into 必須指定足夠目標字段。否則,用字段dobj的剩餘部分填充最後目標欄位幷包含分界符 或者使用內錶動態接收 data l str type string,l str1 type c,l str2 type c.data begin of lt str occ...
abap 字串處理
1 對字串的操作 1 shift 截斷字串 shift by places 作用 去掉字串的前n個位置的字元,如果n未指定,預設為1,如果指定的n小於等於0,則字串不變。如果n超出字串的長度,則字串變空,所以在做此操作的時候要注意n的指定。可以首先獲得該字串的長度,方法 len strlen c m...
ABAP 擷取字串(Start Routine)
需求 有主資料zplant,取自工廠描述的一部分,用 隔開,比如 工廠a 北京 zplant只需要 工廠a 怎麼解決呢 寫在start routine裡,data z res wa typematch result,z res tab typematch result tab,z data type...