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

Abt String Operation.

Former Member
0 Likes
502

hi,

I have one string name source.

Which contain 'ABCDEFGHIJ'

Now,

I want to put first two character(AB) in one variable.

next three(CDE) in other variable

and

remaining into other variable.

How to do this.

What are the function available.

Is SUBSTRING function is available.

ITS URGENT.

4 REPLIES 4
Read only

Former Member
0 Likes
484

Hi,

Use SPLIT Command.

Below is an example for the same


data: begin of wa,
ch(30) type c,
end of wa.
data: itab like table of wa.
data: text type string value 'abcd | xyz | nhyu | adfsfs | fslfs | fjsflsfl |'.
SPLIT text AT '|' INTO TABLE itab.
loop at itab into wa.
write:/ wa-ch.
endloop.

Regards,

Chandru

Read only

Former Member
0 Likes
484

u can use the offset operater.

store the value in a variable(VALUE)

write:/ value+0(2). "AB

/ value+2(3). "CDE

/ value+5. "FGHIJ

SUBSTRING is not available in ABAP.

Regards,

Phani.

Read only

matt
Active Contributor
0 Likes
484

Is it a TYPE string or a TYPE fixed length character field. For a fixed length character string you can use:

TYPES: BEGIN OF my_type,
         first_bit  TYPE C LENGTH 2,
         second_bit TYPE C LENGTH 3,
         last_bit   TYPE C LENGTH 5,
       END OF my_type.

DATA: l_mytext TYPE my_type.

l_mytext = 'ABCDEFGHIJ'.

WRITE: / l_mytext-first_bit, l_mytext-second_bit, l_mytext-last_bit. 

This is better programming than the use of arbitary offsets. See this article on [Magic Numbers|http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Unnamed_numerical_constant] for the reasons why you should avoid the use of offsets.

matt

Read only

Former Member
0 Likes
484

Hi

u can use offset.

var = ABCDEFGHIJ

var1 = var+0(2).

var2 = var+2(3).

var3 = var+4(5).