Вы находитесь на странице: 1из 3

Data Reference:

Data References are pointers to Data Objects. They occur in ABAP as the contents of Data
Reference Variable.

We can Create New Data Objects Dynamically with The help of data references.

We can even create Reference To Existing data Objects Dynamically.

But We can Only DeReference a Data Reference using a Special Allignment To field
Symbol Only.

Reference Varibale:

Reference variables contains only references Actual values of reference variable are not
visible they are hidden.

Syntax:

We can create the data type of a data reference variable using:

TYPES <t_dref> TYPE REF TO DATA.

We can create a data reference variable either by referring to the above data type or using:

DATA <dref> TYPE REF TO DATA.

Reference variables are initial when you declare them. They do not point to an object. We
cannot Dereference an initial reference variable.

Creating Data Objects dynamically:

To create a data object dynamically during a program we need a data reference variable
<dref>.

Syntax:

CREATE DATA <dref> TYPE <type>|LIKE <obj>.

This statement creates a data object in the internal session of the current ABAP program.

the data reference in the data reference variable <dref> points to the object.

Now we created the Data Objects Dynamically.

We can Even Specify the Data Type Of Data object dynamically using
Syntax:

CREATE DATA <dref> TYPE (<name>).

Here, <name> is the name of a field that contains the name of the required data type.

Access Contents Using DeReference Of DataReferences:

We get contents of dataobjects where datareferences are pointing.

Syntax:

ASSIGN <dref>->* TO <FS> [CASTING ...].

This statement assigns datareference variable to field symbol.If the assignment is


successful, SY-SUBRC is set to zero.

If the data reference in <dref> is initial or invalid, we cannot dereference it. The field symbol
remains unchanged, and SY-SUBRC is set to 4.

Getting ReferencesTo DataObject:

Syntax:

GET REFERENCE OF <obj> INTO <dref>.

<obj> can be a statically-declared data object, or a field symbol pointing to any object
(including a dynamic object).

Example Program:

REPORT  zbr_datareference.
DATA: BEGIN OF student,
      name TYPE c LENGTH 6 VALUE 'SACHIN',
      rno TYPE i VALUE 10,
      END OF student.

DATA dref TYPE REF TO data.
*TYPES dref type ref to data.
CREATE DATA dref LIKE student.
FIELD-SYMBOLS <fs> STRUCTURE student DEFAULT %DUMMY%.
ASSIGN dref->* TO <fs> CASTING.
IF <fs> IS ASSIGNED.
  <fs>-name = 'SACHIN'.
  <fs>-rno = 21.
  WRITE: / <fs>-name, <fs>-rno.
ELSE.
  SKIP.
ENDIF.
FIELD-SYMBOLS <fs1> TYPE i.
DATA dref2 TYPE REF TO data.
GET REFERENCE OF <fs>-rno INTO dref2.
ASSIGN dref2->* TO <fs1> CASTING.
IF <fs1> IS ASSIGNED.
  WRITE: <fs1>.
ELSE.
  EXIT.
ENDIF.

OUTPUT:

07.10.2010 Practice on data references


1

--------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------

SACHIN 21 21

Вам также может понравиться