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

runtime error in executing FM

Former Member
0 Likes
1,863

Hi,

I had created a FM which i s used to divide the string into 2 parts after specifying the length from where we want to divide and add highfen mark at that point in that string using concatenate function. The problem when i debug the code it is picking up the correct data and when the processing is done the run time error occurs in that FM.

HERE IT IS:-



Error analysis
    An exception occurred that is explained in detail below.
    The exception, which is assigned to class 'CX_SY_RANGE_OUT_OF_BOUNDS', was not
     caught in
    procedure "Z_STRING_LENGTH1" "(FUNCTION)", nor was it propagated by a RAISING
     clause.
    Since the caller of the procedure could not have anticipated that the
    exception would occur, the current program is terminated.
    The reason for the exception is:
    In the running program "SAPLZGROUP_FOR_555", part of a string was about to be
     accessed
    with an explicitly specified length.
    However, this length (20) exceeded the current length of the string
    (16).
    This kind of access is illegal.

plzz proivde me guidelines for solving this problem.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,603

Hi Ricx,

write this piece of code in the function module..... this will surely resolve your issue....

FUNCTION Z_STRING_LENGTH1.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(I_STRING) TYPE  STRING
*"     VALUE(LENGTH) TYPE  I
*"  EXPORTING
*"     VALUE(E_STRING) TYPE  STRING
*"----------------------------------------------------------------------
data: str1 type string,
      len type i,
      STRING3 type string.
 
str1 = I_STRING.
LEN = STRLEN( I_STRING ).
IF len < length.
	" write a code to raise exception for an invalid length...
	" as the length exceeds the length of the string.....
ELSE.
	concatenate   STR1+0(length) '-' str1+length  into STRING3.
	e_string = STRING3.
ENDIF.

Regards,

Siddarth

12 REPLIES 12
Read only

Sm1tje
Active Contributor
0 Likes
1,603

Reading the full text should make it quite obvious as to what is wrong with your code. Somewhere in your coding you are trying to access a field with an offset and lengt which exceed the actual length of that field.

example.

data: field1(20) type c. " Character type field with lenght 20.

data: field2(5) type c. " Character type field with lenght 5

move field1+16(5) to field2. " Move characters 17-21 to field2.

The last statement is not valid, since field1 only has a lenght of 20.

Edited by: Micky Oestreich on May 11, 2009 7:20 AM

Read only

Former Member
0 Likes
1,603

hi.

actually i have to use string insted of character i cannot in sert the length of the offset value.

this the code which i am using right now:-



FUNCTION Z_STRING_LENGTH1.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(I_STRING) TYPE  STRING
*"     VALUE(LENGTH) TYPE  I
*"  EXPORTING
*"     VALUE(E_STRING) TYPE  STRING
*"----------------------------------------------------------------------
data: str1 type string,
      len type i,
      aa type i,
      STRING1 type string,
      STRING2 type string,
      STRING3 type string.

str1 = I_STRING.
LEN = STRLEN( I_STRING ).
AA = LEN - LENGTH.
STRING1 = str1(length).
STRING2 = str1+LENGTH(aa).
concatenate   STRING1 '-' STRING2  into STRING3.

e_string = STRING3.

the importt parameters:-

I_STRING	TYPE STRING                                                                                
LENGTH	TYPE I

The export parameters :-
E_STRING	 TYPE STRING	                     

Edited by: ricx .s on May 11, 2009 7:24 AM

Read only

Sm1tje
Active Contributor
0 Likes
1,603

So what happens when you enter a string like : "this is text 1" and a length of say 50. This will give a dump since the lenght of the string is less than 50!!

Or am I overlooking something here?

The fact that it works in SE37 is probably because you know the exact length of the string you are entering and therefore you will not enter a lenght beyound the lenght of that string. So the program calling your function module is providing invalid data.

To overcome this, you can do a check a the beginning of your code or, maybe better, catch the exception a return the message to calling application.

Edited by: Micky Oestreich on May 11, 2009 7:39 AM

Read only

Former Member
0 Likes
1,603

hi,

see the functionality of this FM is when we we enter a string of any length say about 100 words and we want to have highfen value at the position 25,it will divide the rest of the string(26 th ownwards) in to string2. after that the concatenate function will be called and insertion of the highfen will be donr b/w them and it will be stored into STRING 3.

When i excute the FM in se37 it is working fine ,even in debug mode but when i use this FM it works for some but when last execution is ,it gives the runtime error.

i hope u got the understanding of my problem.

Read only

Sm1tje
Active Contributor
0 Likes
1,603

So you are calling this FM several times in your report. For a couple of calls it works just fine, but at a certain point if fails, correct?

Again, the only way this could occur (according to the exception class), is that the offset (in this case import parameter LENGHT) lies beyond the lenght of your string (I_STRING). I sent a sample of how to catch this error, maybe it will help you to determine the error.

I tried to simulate the error in SE37, and I get the same runtime error as you, when entering the following:

1. I_STRING = 'This is the text to be split".

2. LENGTH = 50.

Edited by: Micky Oestreich on May 11, 2009 7:50 AM

Read only

Former Member
0 Likes
1,603

Hi Rick,

The problem seems to e with the data type of the data that is paased o the FM. as far as the problem of adding a highfen between two parts of a same string goes you can always refer to the SPLIT statement.

Refer to the example below:

Data : name1 type string value 'SAPABAP'.

SPLIT name1 AT 'ABAP' INTO s1 s2.

CONCATENATE s1 s2 into s3 SEPARATED BY '-'.

Now thw variable s3 contains the string 'SAP-ABAP'.

Regards,

Arnab.

Read only

0 Likes
1,603

even i know,but i am asked to make the FM for it. thats why i have made it. is there any posssibilty to rectify the code?

when i am executing in the SE37 it is working fine. when i am calling in the program it is giving that runtime error.

Edited by: ricx .s on May 11, 2009 7:32 AM

Read only

0 Likes
1,603

The problem occurs, when you mention higher value for Length than the input String. So you've to give some validation to check the Length value.

Cheers\

Mahesh

Read only

former_member188827
Active Contributor
0 Likes
1,603

TRY THIS

DATA: str1 TYPE string,

len TYPE I,

aa TYPE I,

STRING1 TYPE string,

STRING2 TYPE string,

STRING3 TYPE string.

str1 = I_STRING.

LEN = STRLEN( I_STRING ).

AA = LEN - LENGTH.

if aa lt 0.

aa = 0.

endif.

IF LENGTH LE LEN.

STRING1 = str1(length).

ELSE.

STRING1 = str1(len).

ENDIF.

IF LENGTH LE LEN.

STRING2 = str1+LENGTH(aa).

ELSE.

STRING2 = str1+LEN(aa).

ENDIF.

CONCATENATE STRING1 '-' STRING2 INTO STRING3.

e_string = STRING3.

Read only

Sm1tje
Active Contributor
0 Likes
1,603

Just an example:


FUNCTION zz_mo_test1.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(I_STRING) TYPE  STRING
*"     REFERENCE(LENGTH) TYPE  I
*"  EXPORTING
*"     REFERENCE(E_STRING) TYPE  STRING
*"     REFERENCE(E_MESSAGE) TYPE  STRING
*"----------------------------------------------------------------------

  DATA: str1 TYPE string,
        len TYPE i,
        aa TYPE i,
        string1 TYPE string,
        string2 TYPE string,
        string3 TYPE string.

  DATA: lr_error TYPE REF TO cx_sy_range_out_of_bounds.

  TRY.
      str1 = i_string.
      len = STRLEN( i_string ).
      aa = len - length.
      string1 = str1(length).
      string2 = str1+length(aa).
      CONCATENATE   string1 '-' string2  INTO string3.

      e_string = string3.

    CATCH cx_sy_range_out_of_bounds INTO lr_error.
      e_message = lr_error->get_text( ).

  ENDTRY.

ENDFUNCTION.

Read only

Former Member
0 Likes
1,604

Hi Ricx,

write this piece of code in the function module..... this will surely resolve your issue....

FUNCTION Z_STRING_LENGTH1.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(I_STRING) TYPE  STRING
*"     VALUE(LENGTH) TYPE  I
*"  EXPORTING
*"     VALUE(E_STRING) TYPE  STRING
*"----------------------------------------------------------------------
data: str1 type string,
      len type i,
      STRING3 type string.
 
str1 = I_STRING.
LEN = STRLEN( I_STRING ).
IF len < length.
	" write a code to raise exception for an invalid length...
	" as the length exceeds the length of the string.....
ELSE.
	concatenate   STR1+0(length) '-' str1+length  into STRING3.
	e_string = STRING3.
ENDIF.

Regards,

Siddarth

Read only

Former Member
0 Likes
1,603

hi,

thanks for all your help it had solved my problem and i had rewards had been assigned for it.