SAP Tech Pro

SAP Technical Blog

How to Create Variables, Structures and Tables dynamically (Run time) using data objects

How to Create Variables, Structures and Tables dynamically (Run time) using data objects

Data objects are instances of data types and contain the concrete data that a program uses at runtime. This is done by specifying data objects in operand positions.

Generation and addressing of data objects

We differentiate between:

  • Named data objects, which are statically agreed with a data-defining statement and are addressed using a name. The typical data-defining statement is DATA. Named objects are generated at the start of the lifetime of a context (program, class, object, procedure) by the ABAP runtime environment, and exist for as long as their context exists.

 

Syntax for Creating Elementary Data Object :


DATA dref TYPE REF TO data.
FIELD-SYMBOLS <fs> TYPE any.

* type can be 'd' OR 'decfloat16' OR 'decfloat34' OR 'f' OR 'i'
*              OR 'string' OR 't' OR 'xstring'.
CREATE DATA dref TYPE (type).

* type is 'c' OR 'n' OR 'x'.
CREATE DATA dref TYPE (type) LENGTH len.

*if thetype if 'P'
CREATE DATA dref TYPE p LENGTH 10 DECIMALS 2.

ASSIGN dref->* TO <fs>.

Syntax for Creating Structured Data Object :


DATA dref TYPE REF TO data.
FIELD-SYMBOLS <wa> TYPE any.

CREATE DATA dref TYPE (dbtab). "dbtab can be any structure/table
        ASSIGN dref->* TO <wa>.

Syntax for Creating Tabled Data Object :


DATA dref TYPE REF TO data.
FIELD-SYMBOLS <table> TYPE ANY TABLE.

CREATE DATA dref TYPE STANDARD TABLE OF (dbtab)
                              WITH NON-UNIQUE DEFAULT KEY.
        ASSIGN dref->* TO <table> 

Add comment

Before Buying, Compare Prices at Topprice.in

Topprice.in