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: 

Structure fragmentation and field symbol

Former Member
0 Kudos

Hi,

Can someone help me understand how the below code works?

In the above code, it makes sense when the below statement throws an error as a result of structure fragmentation within unicode programs.


*lv_string = s1.

What I dont understand is how the data object <fs_x> can hold the contents of the structure 'S1'? The object <fs_x> is declared as type X which would make it 1 byte variable where as the structure S1 is more than 1 byte

Thanks,

Vikram.M

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

I think you have made a confusion between FIELD-SYMBOLS <fs_x> TYPE x which corresponds to a generic type X with undefined length (only set at runtime when the field symbol is assigned), and DATA lv_x TYPE x, which of course cannot be generic (because a data object must have a concrete type) and SAP has defined default lengths for all generic types (like C, P, N and X; and maybe decfloat, I don't remember).

9 REPLIES 9

Former Member
0 Kudos

Hello Vikram,

have you checked the output?

in your example s1 should be 'AZ 12 4444'

But it probably is not the same for <fs_x>

The thing is, field symbols are like pointers, they reference another element in memory. So what happens when the type of the reference is shorter than the referenced element, it should get be cut off.

Give it a try and print it.

regards

Markus

0 Kudos

It wouldn't cutoff. Below is the output.

0 Kudos

use:

WRITE: <fs_x>

field symbols that are to short won't cut off their originals!

edit: they don't do that as they can only change what they arereferencing, and that is only the shortened area and not the whole element

Message was edited by: Markus V

0 Kudos

Would you be kind enough to elaborate?

Sandra_Rossi
Active Contributor
0 Kudos

I think you have made a confusion between FIELD-SYMBOLS <fs_x> TYPE x which corresponds to a generic type X with undefined length (only set at runtime when the field symbol is assigned), and DATA lv_x TYPE x, which of course cannot be generic (because a data object must have a concrete type) and SAP has defined default lengths for all generic types (like C, P, N and X; and maybe decfloat, I don't remember).

0 Kudos

Sandra,

As far as I know, a generic type is referred with:

  • ANY
  • ANY TABLE
  • INDEX TABLE
  • DATA
  • OBJECT

When a data object is defined with type X, I thought it refers to a hex with 1 byte length.

Are you saying when a field symbols is defined with type X it becomes generic with undefined length? If yes, would you be able to point me to the corresponding SAP documentation?

Thanks,

Vikram.M

0 Kudos

When a data object is defined with type X, I thought it refers to a hex with 1 byte length.

FIELD-SYMBOLS are not data objects!

When defining data objects 'x' behaves are predefined type (http://help.sap.com/abapdocu_740/en/abenbuiltin_types_byte.htm)

When defining FIELD-SYMBOLS 'x' is generic type (http://help.sap.com/abapdocu_740/en/abenbuilt_in_types_generic.htm). Which Sandra has already pointed out!

BR, Suhas

PS - RT*M, most(almost) of the things are already documented there

0 Kudos

Thanks Sandra and Suhas for pointing me on the right direction.