DATA

From Abap2Java

Jump to: navigation, search

ABAP

The keyword DATA is used to declare a variable.

 DATA lv_my_variable  TYPE i.
 DATA lv_my_string    TYPE string VALUE 'Hello World'.
 DATA lv_my_character TYPE c LENGHT 4.
 lv_my_variable = 23.

Variants

DATA lv_my_1st_string TYPE string.
DATA ls_my_1st_structure TYPE my_structure_type.
DATA lt_my_1st_table TYPE my_table_type.
DATA lv_my_2nd_string LIKE lv_my_1st_string.
DATA ls_my_2nd_structure LIKE ls_my_1st_structure.
DATA lt_my_2nd_table LIKE lt_my_1st_table.
DATA lt_my_3rd_table TYPE TABLE OF my_structure_type. 
"my_structure_type must be defined in the Data Dictionary
DATA lt_my_4th_table TYPE TABLE OF any_database_table.
"any_database_table can be any database table in the Data Dictionary
DATA lt_my_5th_table LIKE TABLE OF ls_my_1st_structure.
DATA lt_my_6th_table LIKE TABLE OF ls_my_2nd_structure.
DATA ls_my_3rd_structure TYPE LINE OF my_table_type.
DATA ls_my_4th_structure LIKE LINE OF lt_my_4th_table.
DATA ls_my_5th_structure LIKE LINE OF lt_my_5th_table.
DATA lr_my_1st_object TYPE REF TO cl_any_class.
DATA lr_my_2nd_object TYPE REF TO cl_any_class.
DATA lr_my_1st_data_reference TYPE REF TO DATA.

See also:
Data Type, CONSTANTS, FIELD-SYMBOLS, TYPES, BEGIN END, PARAMETERS

Java

In Java, variables are defined without a specific keyword.

 int lv_my_variable;
 String lv_my_string = "Hello World";
 String lv_my_character;
 lv_my_variable = 23;

Variable definitions can have modifiers that define the visibility (public, protected, private) and other properties of the variable (final, abstract, static etc.).

There is no equivalent for the DATA...LIKE variant, where ABAP programmers can give a variable the same type than an existing variable.

DATA lv_my_2nd_string LIKE lv_my_1st_string. "not possible in Java

Also, there is no equivalent for the variants TYPE TABLE OF, LIKE TABLE OF, TYPE LINE OF, LIKE LINE OF, since there is no direct equivalent for the concept of internal tables in Java.

The variant TYPE REF TO does not need a special keywork in Java, since references to classes can be defined like any other variable.

short my_simple_variable; //defines a simple variable of the built-in type short
my_class my_object; //defines a reference variable to the class my_class

See also:
Data Type, attribute, modifier

Personal tools