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: 

Regarding basic data declaration

Former Member
0 Kudos

can anyone explain me what the following statement means and when we can use it.

DATA: A type ref to DATA.

Assing A ->* to <fs>.

As <fs> is a field symbol.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

DATA: A type ref to DATA.

FIELD-SYMBOLS: <fs> TYPE ANY.

Obj A is the reference variable for the class.

The object will not be created until you use CREATE DATA.

CREATE DATA dref TYPE sbook.

Assign A ->* to <fs>.

object A is of type sbook and the memory is allocated at runtime.

Assign statement is used to assign a field to field symbol

Regards.

3 REPLIES 3

Former Member
0 Kudos

hi naveen,

DATA ref { {TYPE REF TO type}

| {LIKE REF TO dobj} }

[VALUE IS INITIAL]

[READ-ONLY].

Effect

Using the REF TO addition, you declare a reference variable ref. The specification after REF TO specifies the static type of the reference variables. The static type limits the set of objects to which ref can point. The dynamic type of a reference variable is the data type or the class to which it currently points. The static type is always more general or the same as the dynamic type (see also conversion rule for reference variables).

Syntax and meaning of the additions TYPE and LIKE are completely the same as the definition of reference types in the section TYPES -REF TO, but here they serve to create a bound reference type.

As a start value, only IS INITIAL can be specified after the addition VALUE.

Note

Reference variables are opak - that is, you cannot directly access their content. A reference is made up of the address of an object and other management information.

Example

In this example, an object reference oref and two data references dref1 and dref2 are declared. Both data references are typed fully and can be dereferenced using the dereferencing operator ->* at operand positions.

CLASS c1 DEFINITION.

PUBLIC SECTION.

DATA a1 TYPE i VALUE 1.

ENDCLASS.

DATA: oref TYPE REF TO c1,

dref1 LIKE REF TO oref,

dref2 TYPE REF TO i.

CREATE OBJECT oref.

GET REFERENCE OF oref INTO dref1.

CREATE DATA dref2.

dref2->* = dref1->*->a1.

FIELD-SYMBOLS <fs> { typing | STRUCTURE struc DEFAULT dobj }.

The FIELD-SYMBOLS statement declares a field symbol <fs>. The naming conventions apply to the name fs. The angle brackets of the field symbols indicate the difference to data objects and are obligatory. You can declare field symbols in any procedure and in the global declaration section of an ABAP program, but not in the declaration section of a class or an interface. You can use a field symbol in any operand position in which it is visible and which match the typing defined using typing.

After its declaration, a field symbol is initial - that is, it does not reference a memory area. You have to assign a memory area to it (normally using the ASSIGN statement) before you can use it as an operand. Otherwise an exception will be triggered.

You can use the addition typing to type the field symbol. The syntax of typing is described under Syntax of Typing. The typing specifies which memory areas can be assigned to the field symbol (see Checking the Typing) and in which operand positions it can be used.

You can omit the addition typing outside of methods. In this case, the field symbol has the complete generic type any and is implicitly assigned the predefined constant space during the declaration.

... STRUCTURE struc DEFAULT dobj

Effect

If you specify the addition STRUCTURE instead of typing for a field symbol, and struc is a local program structure (a data object, not a data type) or a flat structure from the ABAP Dictionary, this structure is cast for the field symbol <fs>. You have to specify a data object dobj that is initially assigned to the field symbol.

The field symbol copies the technical attributes of structure struc as if it were completely typed. When you assign a data object using the addition DEFAULT, or later using ASSIGN, its complete data type is not checked in non- Unicode programs. Instead, the system merely checks whether it has at least the length of the structure and its alignment.

In Unicode programs, we differentiate between structured and elementary data objects. For a structured data object dobj, its Unicode fragment view has to match the one of struc. In the case of an elementary data object, the object must be character-type and flat, and struc must be purely character-type. The same applies to assignments of data objects to field symbols typed using STRUCTURE when using the ASSIGN statement.

Field symbols declared using the addition STRUCTURE are a mixture of typed field symbols and a utility for casting structured data types. You should use the additions TYPE or LIKE for the FIELD-SYMBOLS statement to type field symbols, while the addition CASTING of the ASSIGN statement is used for casting.

Example

The first example shows the obsolete usage of the addition STRUCTURE.

DATA wa1 TYPE c LENGTH 512.

FIELD-SYMBOLS <scarr1> STRUCTURE scarr DEFAULT wa1.

<scarr1>-carrid = '...'.

The second example shows the replacement of STRUCTURE with the additions TYPE and CASTING.

DATA wa2 TYPE c LENGTH 512.

FIELD-SYMBOLS <scarr2> TYPE scarr.

ASSIGN wa2 TO <scarr2> CASTING.

<scarr2>-carrid = '...'.

reward points if helpful,

shylaja

Former Member
0 Kudos

Check the key word help in the T.Code ABAPDOCU.

Regards.

Former Member
0 Kudos

hi,

DATA: A type ref to DATA.

FIELD-SYMBOLS: <fs> TYPE ANY.

Obj A is the reference variable for the class.

The object will not be created until you use CREATE DATA.

CREATE DATA dref TYPE sbook.

Assign A ->* to <fs>.

object A is of type sbook and the memory is allocated at runtime.

Assign statement is used to assign a field to field symbol

Regards.