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 Error dump in code

Former Member
0 Likes
2,192

HI guys,

I have a requirement in which when a space is given in string field (text) in table control and enter is pressed, then a special character should appear  in place of space. But in another field which is of Simulation it should appear as space i.e. the special character should be converted back to space in simulation field.

Now, I have written the below code and it works fine for the existing records in table. But when i make a new entry and in text field i enter something lets say "abcd" it gives me dump stating some offset error - "subfield accesses with an offset specification that is not smaller than the field length are not permitted."

Can you help me with this.

In code "lws_fzcoprsff" is the work area of table fzcoprsff

"lws_fzcoprsff-text1" is the text field.

    DATA : lw_count   TYPE  i,
               lw_char  TYPE c.
     lw_count = 1.
     lw_char = lws_fzcoprsff-text1(1).
     IF lws_fzcoprsff-text1 IS NOT INITIAL.
       DO.
         IF lws_fzcoprsff-text1+lw_count(1) EQ '#'.
           lws_fzcoprsff-text1+lw_count(1) = space.
         ELSEIF lws_fzcoprsff-text1+lw_count(1) EQ lw_char.
           EXIT.
         ENDIF.
         lw_count = lw_count + 1.
       ENDDO.
     ENDIF.

7 REPLIES 7
Read only

hendrik_brandes
Contributor
0 Likes
1,726

Hello Dharmin,

why do you not use the ABAP statement "REPLACE"?

Example:

REPLACE ALL OCCURRENCES OF '#' IN lws_fzcoprsff WITH space.

I think, the way, how you use the offset-options is not ideal:

lw_count(1) makes a string conversion and then takes the first character. When you use this in your context of

lws_fzcoprsff-text1+lw_count(1)

this leads to an error. For using offset, just take the integer-variable without length-operator.

Kind regards,

Hendrik

Read only

0 Likes
1,726

hey Hendrik,

I made changes,but now whats happening is ..for a new entry when i enter similar letters in text field for eg."aa_b" two 'a' nd then space nd 'b' its not showing special character over here..however if i enter like "abc_d" then it shows the special character after c. didn't get this. You have any idea why is it like this?

Read only

0 Likes
1,726

Hello Dharmin,

when I test your example, it works:

 

data:
  text type string value 'aa_b'.
replace all OCCURRENCES OF '_' in text with '#'.
write:/ text.

another Tip: Use regular expressions.

See my post in, where you find a similar requirement: http://scn.sap.com/thread/3255089

Kind regards,

Hendrik

Read only

0 Likes
1,726

hi dharmin,

can you provede some expected result for respective input, so it will be easy to help you

Shinaagam.

Read only

0 Likes
1,726

HIi Venkata,

Say i am entering text like "string". Now when i provide spaces in between like"str in g" and press enter then it shows text with special characters like "str#in#g" which its showing.

But when i enter similar texts together at the start like "aa ple" then its not showing special character over here. but if i write "ple aa" then it shows special character "ple#aa'. So am not unedrstanding why its not showing for similar letters "aa ple".

Regards,

Dharmin

Read only

0 Likes
1,726

Dharmin,

Dont understnad why it is showing like this  and why it is not showing for APPLE.

But anyway you can  use replace all occurance first using the space as hendrik is saying then you can condense the whole data ..now the 'APP LE'  will become 'APP#LE'   then after replace all occurance it will become 'APP LE'  and after condense it will become 'APPLE'... i think this way you can solve it into the code.

thanks,

Jo

Read only

0 Likes
1,726

HI JO,

well i tried replace command.. but it didn't work. instead i used this

     LOOP AT int_fzcoprsf INTO ws_zcoprsf WHERE opno = zcoprs-opno AND oopr = zcoprs-oopr AND oprs = zcoprs-oprs.
     lw_count = 1.
     lw_char = ws_zcoprsf-text1(1).
     lw_strlen = STRLEN( ws_zcoprsf-text1 ).
     IF ws_zcoprsf-text1 IS NOT INITIAL.
       WHILE lw_count LT lw_strlen.                              

  IF ws_zcoprsf-text1+lw_count(1) EQ space.
           ws_zcoprsf-text1+lw_count(1) = '#'.
         ELSEIF ws_zcoprsf-text1+lw_count(1) EQ lw_char.
           EXIT.
         ENDIF.
         lw_count = lw_count + 1.
       ENDWHILE.                                               

ENDIF.
     MODIFY int_fzcoprsf FROM ws_zcoprsf TRANSPORTING text1 simulation.
   ENDLOOP.

I used while loop.. so its working.

But am not understanding this behaviour of similar characters.. Moreover only when similar characters are written at first den its showing error.. i.e if "aab cd" if i write like this then it does not show d special charatcer like "aab#cd" instead it shows it as space only.. but if i write anywhere except the first place like "abb cd" then it shows d special char. "abb#cd"..! Wonder why its happening lke this.