‎2008 Feb 18 12:40 PM
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.
‎2008 Feb 18 12:44 PM
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
‎2008 Feb 18 12:50 PM
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.
‎2008 Feb 18 12:59 PM
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
‎2008 Feb 18 1:04 PM
Hi
u can use offset.
var = ABCDEFGHIJ
var1 = var+0(2).
var2 = var+2(3).
var3 = var+4(5).