Skip to Content
0
Feb 01, 2008 at 09:53 AM

Assign statement with field offset overflow not set sy-subrc ne 0

228 Views

on HELP of ABAP statement ASSIGN it is mentioned that if assign was not successfull sy-subrc is set <> 0 and if successfull sy-subrc is set to 0. Unfortunately this is not always true.

If you use string offset together with ASSIGN statament beware that if your offset points outside your source variable physical length, the sy-subrc is still 0, but target field-symbol is not assigned. If you continue processing and refer to such field-symbol you'll get a runtime error GETWA_NOT_ASSIGNED_RANGE.

The importance here is that with older versions of R/3 (4.6c fore example) no short dump was raised. Or to be honest I don't know if the reason is in Unicode behaviour or differences in kernel versions. My recent observations are from a Unicode system of NW04s.

Does anybody understand why SAP had made ASSIGN to work this way, so that sy-subrc is not raised even if ASSIGN was not successfull. It worked in such way in older systems too, so nothing new except no dump was raised in previous versions.

Here is a sample code so that you can understand better.

REPORT ZZZTEST_ASSIGN.

data: fld(10) type c,

off(2) type i.

field-symbols: <fs1> type any,

<fs2> type any,

<fs3> type any.

*

fld = 'ABCD'.

off = 3.

assign fld+off(1) to <fs1>. "points to D

  • sy-subrc is set to 0

if sy-subrc = 0.

write: / <fs1>.

endif.

off = 5.

assign fld+off(1) to <fs2>. "points outside current field content

  • sy-subrc is still 0, because offset not yet overflow

  • physical field length, even if offset is beyond current field lenght

if sy-subrc = 0.

write: / <fs2>. "will cause a runtime error

endif.

********************************************************************

  • Next is the important part and reason for this SDN thread message*

********************************************************************

off = 11. "outside physical boundary of source field

assign fld+off(1) to <fs3>. "points outside field phys. length

  • You would think sy-subrc is set <> 0, but it is still 0!

  • But physical field length is now overridden, and field-symbol

  • is NOT assigned

if sy-subrc = 0.

write: / <fs3>. "will cause a runtime error

endif.

This thread was not marked as question, but feel free to comment or advice how to avoid runtime error (for other SDN members facing the problem).

br: Kimmo