Application Development and Automation 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: 
Read only

How to get substring from a string?

Former Member
0 Likes
24,118

For example, there is a string:

C-REVF-00003 0010 Development

how the program get the value '0010'?

1 ACCEPTED SOLUTION
Read only

Former Member
8,345

hi,

substring = string+offset(no of chars).

string = 'C-REVF-00003 0010'.

substring = string+14(4).

check this.

data : text(30) value 'C-REVF-00003 0010 ',

text1(10),

text2(10).

split text at space into text1 text2.

write : / text2.

regards

shiba dutta

8 REPLIES 8
Read only

Former Member
0 Likes
8,345

use split command and seperated by spaces..

Read only

Former Member
8,346

hi,

substring = string+offset(no of chars).

string = 'C-REVF-00003 0010'.

substring = string+14(4).

check this.

Read only

0 Likes
8,345

if the string = 'C-REVF-00000003 0010'.

substring = string+14(4) doesn't work.

Read only

0 Likes
8,345
hi James,

 try this

REPORT ychatest MESSAGE-ID zz..

DATA : v_str(25) VALUE 'C-REVF-00003 0010',
       v_str1(4).

SEARCH v_str FOR '0010'.
IF sy-subrc EQ 0.
  v_str1 = v_str+sy-fdpos(4).
ENDIF.

WRITE : v_str1
Read only

Former Member
0 Likes
8,345

Hi,

Use SHIFT <string> BY <n> PLACES LEFT command.

Regards,

Padmam.

Read only

Former Member
0 Likes
8,345

u can use offset lengths.

text = '10001000101'.

v_text = text+9(3) = 101.

Regards

Peram

Read only

Former Member
0 Likes
8,345

data : text(30) value 'C-REVF-00003 0010 ',

text1(10),

text2(10).

split text at space into text1 text2.

write : / text2.

regards

shiba dutta

Read only

Former Member
0 Likes
8,345

Hi,

Use Split command.

Syntax

SPLIT <c> AT <del> INTO <c1>... <cn> INTO TABLE <itab>.

Searches the field <c> for the character <del> and places the partial fields before and after <del>

into the target fields <c1> … <cn>, or into a new line of the internal table <itab>.

Ex.

DATA: STRING(60),

P1(20) VALUE '++++++++++++++++++++',

P2(20) VALUE '++++++++++++++++++++',

P3(20) VALUE '++++++++++++++++++++',

P4(20) VALUE '++++++++++++++++++++',

DEL(3) VALUE '***'.

STRING = ' Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5'.

WRITE STRING.

SPLIT STRING AT DEL INTO P1 P2 P3 P4.

WRITE / P1.

WRITE / P2.

WRITE / P3.

WRITE / P4.

The output appears as follows:

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

Part 1

Part 2

Part 3

Part 4 *** Part 5

Regards,

Bhaskar