Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP Substring?

Former Member
0 Kudos

Hi,

I'm looking for a substring command in ABAP.

I have a string like this...

text = 'hello, how are you today'.

Here's my goal...

I want to separate my string at the 10th character into two strings (text1 and text2).

so the result would be

text1 has the value 'hello, how'

text2 has the value ' are you today'

of course, the characters in the string 'text' will vary.

Can anyone help?

Thanks.

Audrey

1 ACCEPTED SOLUTION

ssimsekler
Active Contributor

Hi Audrey

You can use offset and length additions.

DATA lv_str TYPE string .

lv_str = 'hello, how are you today' .
write:/ lv_str+7 ,
      / lv_str+7(3) ,
      / lv_str(7) .

The output should be:

how are you today
how
hello,

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

5 REPLIES 5

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Check out the following logic.



report zrich_0001 .


data: x(100) type c,
      y(100) type c,
      z(100) type c.

x = 'Hello, how are you doing?'.


y = x+0(10).
z = x+10(90).


write:/ y.
write:/ z.

Regards,

Rich Heilman

ssimsekler
Active Contributor

Hi Audrey

You can use offset and length additions.

DATA lv_str TYPE string .

lv_str = 'hello, how are you today' .
write:/ lv_str+7 ,
      / lv_str+7(3) ,
      / lv_str(7) .

The output should be:

how are you today
how
hello,

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

andreas_mann3
Active Contributor
0 Kudos

Ho Audrey,

or try this:

DATA text(80).
DATA: BEGIN OF tx,
text1(10),
text2(70),
END OF tx.

text = 'hello, how are you today'.
WRITE : / text.
ULINE.
MOVE text TO tx.
WRITE: / tx-text1.
WRITE: / tx-text2.

regards Andreas

Former Member
0 Kudos

Former Member
0 Kudos

Use Function module 'STRING_SPLIT_AT_POSITION'

Manoj