Use of * in offset processing

Generally when we try to access a string greater than its length it gives  dump.

Example 1:

REPORT y_offset_process.

DATA:

w_char TYPE c,

w_string TYPE string.

w_string = sy-abcde.

w_char = w_string+26(1). 

When you execute this program you get a dump.This is due to w_string is length of 26 and you are trying to access 27th position.

To avoid Short Dump “Illegal access to a string (offset too large)”,

REPORT y_offset_process.

DATA:

w_char TYPE c,

w_string TYPE string.

w_string = sy-abcde.

w_char = w_string+26( * ) . " please delete spaces in ( ).

Example 2:

REPORT y_offset_process.

PARAMETER:

p_desc TYPE char100. " where p_desc is company code + description

DATA:

w_lenght TYPE i,

w_bukrs TYPE bukrs, " company code

w_description TYPE string. " company code description

w_bukrs = p_desc+0(4).

w_lenght = STRLEN( p_desc ).

w_lenght = w_lenght - 4.

w_description = p_desc+4(w_lenght).

WRITE:

w_description. 

You can reduce the code to

REPORT y_offset_process.

PARAMETER:

    p_desc TYPE char100.  " where p_desc is company code + description

DATA:

w_bukrs TYPE bukrs, " company code

w_description TYPE string. " company code description
\\

w_bukrs = p_desc+0(4).

w_description = p_desc+4( * ).  " please delete spaces in ( ) before and after *.

WRITE:

w_description.

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.