Application Development 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: 

Offset in String - Move

former_member194669
Active Contributor
0 Kudos

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.

1 ACCEPTED SOLUTION

JozsefSzikszai
Active Contributor
0 Kudos

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

former_member181995
Active Contributor
0 Kudos

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

JozsefSzikszai
Active Contributor
0 Kudos

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.

ThomasZloch
Active Contributor
0 Kudos

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

0 Kudos

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)"

0 Kudos

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)

0 Kudos

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.

0 Kudos

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

0 Kudos

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.

0 Kudos

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

0 Kudos

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.

0 Kudos

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

0 Kudos

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

0 Kudos

Jamie,

I tried with REGEX its not worked properly.

Thanks

JayChan
Active Participant
0 Kudos

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

former_member188685
Active Contributor
0 Kudos

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.

naimesh_patel
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

former_member705122
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

Micheal,

> move 'Test' to v_string.

>

This part will not work in my case.

Thanks