10-08-2008 3:33 PM
Hi,
I have this code
report zaRs no standard page heading
line-size 170
line-count 65(4).
data : v_string type string.
move 'Test' to v_string+2(4).
This code will syntax error.
"At the write position, you cannot use offset and length with fields of type "STRING" or "XSTRING"
But i need to use offset in string. Anyother way ?.
PS Please don't suggest to use CHAR instead of STRING.
a®
10-08-2008 3:37 PM
this is really not allowed for strings, but what about to do this way:
DATA : lv_help(6) TYPE c.
DATA : v_string TYPE string.
lv_help = v_string(2).
lv_help+2(4) = 'Test'.
MOVE lv_help TO v_string.
So the idea would be to use a character type help variable, reading out the actual vaue of the string (into the help) and adding your own one and filling back to the string from left to right.
10-08-2008 3:37 PM
Take a length of 4 string pass 'Test' to that temp string than concatenate it with your final string at right position?
10-08-2008 3:37 PM
this is really not allowed for strings, but what about to do this way:
DATA : lv_help(6) TYPE c.
DATA : v_string TYPE string.
lv_help = v_string(2).
lv_help+2(4) = 'Test'.
MOVE lv_help TO v_string.
So the idea would be to use a character type help variable, reading out the actual vaue of the string (into the help) and adding your own one and filling back to the string from left to right.
10-08-2008 3:43 PM
how about
CONCATENATE v_string(2) 'Test' v_string+6 INTO v_string.
Only works if v_string has a value already > length 6, otherwise "offset too large" dump.
Thomas
10-08-2008 3:51 PM
Eric,
I need a string instead of CHAR field
Thomas,
I tried as you suggested , but got system dump
"Illegal access to a string (offset too large)"
a®
10-08-2008 3:54 PM
the character variable would be only for temporary help, just check again the code I added (I did not include your string declaration, but that is a must, of course)
10-08-2008 3:59 PM
Eric/Naimesh,
I cannot declare a CHAR field, due data length will be decided only at runtime. I am working on Archieve link document for content server, sometimes length in thousands.
a®
10-08-2008 3:59 PM
Is there any chance to take temp variable for "TEST" and finally concatenate with v_string at desired position?
10-08-2008 4:02 PM
a char type can 65xxx (whatever) long. Is that not enough? If yes:
DATA : lv_help(65xxx) TYPE c.
DATA : lv_string TYPE c.
lv_help = lv_string.
lv_help+2(4) = 'Test'.
lv_string = lv_help.
if the string can be longer than 65xxx, you can still wrap it (there is a standard FM for wrapping text) into an internal table. The lines of the internal table would look like lv_help above.
10-08-2008 4:03 PM
Yes, as the others and I wrote, a string has to have a value of a certain length before you address an offset of it. Otherwise, no way to do what you want, I'm afraid.
A string's length is not known before it actually contains a value.
Thomas
10-08-2008 4:05 PM
the syntax error is not there , but Runtime error is coming
why can't you use LCHAR you can use upto 32000.
is your data bigger than 32000 chars.
data : v_string type string.
field-symbols: <fs> type any.
data: text(20).
assign v_string to <fs>.
<fs>+0(10) = 'Hello'.
write <fs>.
In the current program "ZTEST", write access to part of the
string "<FS>" should be possible.
This access is not possible.
Only read access to substrings is possible.
10-08-2008 4:14 PM
Hello,
Not sure if this will help, but here goes:
DATA : v_string TYPE string.
v_string = ' *'.
REPLACE FIRST OCCURRENCE OF SUBSTRING '*' IN v_string WITH 'Test'.
The Horst Keller ABAP Objects book has an example that may or may not work using regular expressions near the bottom of page 314. I'm not sure if the regex is correct in the code shown below (I get a syntax error in ECC 5.0 that REGEX is a reserved word), but it is based on the Keller book example:
DATA : v_string TYPE string.
v_string = ' *'.
REPLACE REGEX '(\d{4})' IN v_string WITH 'Test'.
Regards,
Jamie
10-08-2008 4:16 PM
you can still wrap it (there is a standard FM for wrapping text) into an internal table.
Eric,
You got work around way.
solved.
Here is solution.
1. call function 'SCMS_STRING_TO_FTEXT'
2. Change value in the output table coming out of above said fm
3. Convert back to string using fm SOTR_SERV_TABLE_TO_STRING
Thanks Eric, Thomas, Naimesh, Vijay, Naren, Amit & A
a®
10-08-2008 4:18 PM
01-05-2009 1:26 AM
10-08-2008 3:43 PM
I don't think you can use Offset on Strings. may be you can use LCHAR type and proceed if you want to use Long text.
10-08-2008 3:45 PM
We have to live with this helper variables.
Make sure you have some value in the V_STRING in the example provided by Eric. Otherwise it would give rutime error STRING_OFFSET_TOO_LARGE.
DATA : lv_help(6) TYPE c,
v_string type string.
v_string = '1111111'.
lv_help = v_string(2).
lv_help+2(4) = 'Test'.
MOVE lv_help TO v_string.
write: v_string.
Regards,
Naimesh Patel
10-08-2008 3:47 PM
Hi,
i agree with Eric...
check this
report zaRs no standard page heading
line-size 170
line-count 65(4).
data : v_string type string,
v_string1(6) type c.
move 'Test' to v_string1+2(4).
move v_string1 to v_string .
write: v_string.
Regards
A
Edited by: A on Oct 8, 2008 4:48 PM
10-08-2008 4:05 PM
Hi,
If the offset is always fixed..Then you can create a dummy structure..and move the values.
DATA : v_string TYPE string.
DATA: BEGIN OF wa,
dummy TYPE char2,
value TYPE char200,
END OF wa.
wa-value = 'test'.
v_string = wa.
WRITE: / v_string.
Thanks
Naren
10-08-2008 4:18 PM
check this...
REPORT zars NO STANDARD PAGE HEADING
LINE-SIZE 170
LINE-COUNT 65(4).
DATA : v_string TYPE string.
MOVE 'TEST' TO v_string .
SHIFT v_string BY 2 PLACES RIGHT.
WRITE: v_string.
Regards
Adil
10-08-2008 4:23 PM
Use SHIFT. When you shift right it expands the length of string types.
report zaRs no standard page heading
line-size 170
line-count 65(4).
data : v_string type string.
move 'Test' to v_string.
* v_string = 'Test'
shift v_string by 2 places right.
* v_string = ' Test'
Oops. Syed beat me to it. B)
Edited by: Michael Evershed on Oct 8, 2008 5:25 PM
10-08-2008 4:27 PM
Micheal,
> move 'Test' to v_string.
>
This part will not work in my case.
Thanks
a®