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

Offset in String - Move

former_member194669
Active Contributor
0 Likes
52,638

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®

1 ACCEPTED SOLUTION
Read only

JozsefSzikszai
Active Contributor
0 Likes
14,817

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.

21 REPLIES 21
Read only

Former Member
0 Likes
14,817

Take a length of 4 string pass 'Test' to that temp string than concatenate it with your final string at right position?

Read only

JozsefSzikszai
Active Contributor
0 Likes
14,818

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.

Read only

ThomasZloch
Active Contributor
0 Likes
14,817

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

Read only

0 Likes
14,817

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®

Read only

0 Likes
14,817

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)

Read only

0 Likes
14,817

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®

Read only

0 Likes
14,817

Is there any chance to take temp variable for "TEST" and finally concatenate with v_string at desired position?

Read only

0 Likes
14,817

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.

Read only

0 Likes
14,817

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

Read only

0 Likes
14,817

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.

Read only

0 Likes
14,817

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

Read only

0 Likes
14,817

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®

Read only

0 Likes
14,817

Jamie,

I tried with REGEX its not worked properly.

Thanks

a®

Read only

JayChan
Active Participant
0 Likes
14,817

hi,

I also ran into the same problem about yours.

My system runs on ECC 5.0

please refer my post:

[|]

any idea would be appreciated.

Chan Chih-Chieh

Read only

Former Member
0 Likes
14,817

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.

Read only

naimesh_patel
Active Contributor
0 Likes
14,817

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

Read only

Former Member
0 Likes
14,817

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

Read only

Former Member
0 Likes
14,817

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

Read only

Former Member
0 Likes
14,817

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

Read only

Former Member
0 Likes
14,817

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

Read only

0 Likes
14,817

Micheal,

> move 'Test' to v_string.

>

This part will not work in my case.

Thanks

a®