Sie sind auf Seite 1von 14

DATA - Simple Field Definition Variants: &&. DATA f. 2. DATA f(len). Variant 1 DATA f.

Extras: 1. ... TYPE type 2. ... LIKE f1 3. ... TYPE LINE OF itabtype 4. ... LIKE LINE OF itab 5. ... TYPE REF TO cif 6. ... TYPE REF TO DATA 7. ... TYPE REF TO type 8. ... VALUE lit 9. ... LENGTH n 10. ... DECIMALS n 11. ... READ-ONLY The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See New Naming Conventions. Effect The internal program field f is created with standard length. If you do not specify a reference type, the system creates a field with type C . A type name can be up to 30 characters long. The name may only consist of alphanumeric characters and the underscore character. It may not consist entirely of digits. Special characters such as German umlauts are not allowed. As well as these characters, certain special characters are used internall. However, these should not be used in application programs. SPACE is a reserved name, and cannot therefore be used. Furthermore, you should not use a field in a statement if it has the same name as one of the additions of the keyword (for example: PERFORM SUB USING CHANGING.). Recommendations for Type Names: 1. Always start the name with a letter. 2. Use the underscore to separate compound names (for example, NEW_PRODUCT. Additional help Variables Addition 1 ... TYPE type

Effect The field f is created with type type. For the type, you can specify either one of the predefined types listed below, a type defined using the TYPES statement, or a type created in the ABAP Dictionary. The standard length ( SL ) of a field depends on its type. Type Explanation SL Initial value

C Text (Character) 1 space N Numeric text 1 '00...0' D Date (YYYYMMDD) 8 '00000000' T Time (HHMMSS) 6 '000000' X Hexadecimal (HeX code) 1 X'00' I Integer 4 0 P Packed number 8 0 F Floating point number 8 0 STRING Character sequence (string) variable-length empty string XSTRING Byte sequence (X string) variable-length empty hexadecimal string Example DATA NUMBER TYPE I. DATA WA_SPFLI TYPE SPFLI. The field NUMBER is created with type I. You can now use it in the program. In particular, you can assign numeric values to the field and use it in calculations ( ABAP number types). The field WA_SPFLI is created using the type of the database table SPFLI from the ABAP Dictionary. This field is structured and can be used especially for working with data from database table SPFLI. Addition 2 ... LIKE f1 The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Cannot Use LIKE References to Dictionary Types. Effect Field f is created with the same field attribtues as the data object f1, which has already been declared. Any data object (field, parameter, structure...) is allowed as long as its type has been fully specified. f1 can be any ABAP Dictionary reference. Example DATA TABLE_INDEX LIKE SY-TABIX. The field TABLE_INDEX now has the same attributes as SY-TABIX (index field for internal tables). Note

You should use this addition whenever you can. If the type of a field to which you are referring changes, the ABAP runtime system updates all references automatically. It also stops the system from carrying out unnecessry (and maybe undesirable) type conversions. Addition 3 ... TYPE LINE OF itabtype Effect The specified type itabtype must have the type of an internal table. The system creates a data object with the same line type of the specified table. Example TYPES TAB_TYPE TYPE STANDARD TABLE OF I WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 10. DATA TAB_WA TYPE LINE OF TAB_TYPE. The data object TAB_WA now has the same attributes as a line of the table type TAB_TYPE, that is, type I. Addition 4 ... LIKE LINE OF itab The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Cannot Use LIKE References to Dictionary Types. Effect The data object itab must be an internal table with or without header line. The system creates a data object with the same line type as the specified table. Example DATA TAB TYPE STANDARD TABLE OF I WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 10. DATA TAB_WA LIKE LINE OF TAB. The data object TAB_WA now has the same attributes as a line of the table TAB , that is, type I. Addition 5 ... TYPE REF TO cif Effect Data object f is declared as reference variable within ABAP objects. cif is a class or an interface. Reference variables contain references (pointers) to objects. Reference variables whose types are defined with reference to a class can contain references to objects of this class. Reference variables whose types are defined with reference to an intterface can contain references to objects whose class implements the interface. Note Objects, i.e.instances of classes, are only addressed with their reference variables. To create

objects see CREATE OBJECT. Example INTERFACE i1. METHODS m1. ENDINTERFACE. CLASS c1 DEFINITION. PUBLIC SECTION. INTERFACES i1. ENDCLASS. CLASS c1 IMPLEMENTATION. METHOD i1~m1. ... ENDMETHOD. ENDCLASS. DATA: o1 TYPE REF TO c1, o2 TYPE REF TO c1, ir TYPE REF TO i1. START-OF-SELECTION. CREATE OBJECT o1. o2 = o1. ir = o1. Additional help Handling of Objects Addition 6 ... TYPE REF TO DATA Effect Declares the data object f as a generic data reference variable. Data reference variables of that kind can contain references (pointers) to data objects of any types. They can only be dereferenced using the statement ASSIGN . Example DATA: numref TYPE REF TO DATA, number TYPE I VALUE 123. FIELD-SYMBOLS: <fs> TYPE ANY. GET REFERENCE OF number INTO numref. ASSIGN numref->* TO <fs>. This example creates a reference to the data object number. It is then assigned to the field symbol <fs> using the dereferencing operator ->*. It is now possible to work with the field symbol in the normal way.

Addition 7 ... TYPE REF TO type Defining a typed data reference variable. Types you can use include elementary types, types defined using TYPES, or types created in the ABAP Dictionary. You can dereference completely typed data reference variables using the dereferencing operator ->* at any operand position. Example types: LNTYP type I. data: CNT type ref to I, LINE type ref to LNTYP, FLIGHT type ref to SFLIGHT. create data CNT. create data LINE. create data FLIGHT. CNT->* = 20. LINE->* = 110. FLIGHT->FLDATE = SY-DATUM. Addition 8 ... VALUE lit Effect Instead of the default initial value, the system assigns the literal lit to f, as its initial value. You can also declare a constant. Instead of using a literal, you can also use the IS INITIAL declaration. In this case, the field value is set to the initial value appropriate to its type. This form is particularly necessary when you use the CONSTANTSstatement, since you must always include the VALUE addition with this statement. Example DATA: NUMBER TYPE I VALUE 123, FLAG VALUE 'X', TABLE_INDEX LIKE SY-TABIX VALUE 45. The field NUMBER with type I is created, and does not have an initial value of 0, but 123; the new field FLAG with type C (length 1) contains the value 'X'; TABLE_INDEX has the value 45, since SY-TABIX is a numeric field. Note You cannot declare XSTRINGs, references and internal tables or structures containing internal tables after VALUE. Addition 9 ... LENGTH n Effect This addition is only allowed for the field types C , N , X, and P. The field f is created with the

length n. Addition 10 ... DECIMALS n Effect This addition is only necessary for field type P. When you calculate using this field or output it, it has n decimal places, where n is between 0 and 14. When you create a new program, "floating point arithmetic" is selected by default. If you deselect this attributes, the DECIMALS specification is only effective when you output the field, not when you use it in calculations. In this case, you must ensure that you have the correct number of decimal places by multiplying or dividing the field by the appropriate power of 10. (COMPUTE). You are recommended always to work with the fixed point arithmetic switched on. This ensures that intermediate results (division!) are calculated with the greatest possible accuracy (31 decimal places). To see whether fixed point P or floating point F is more suitable, see "ABAP number types" Addition 11 ... READ-ONLY Effect You can only use this addition in the public visibility section (PUBLIC SECTION ) of a class declaration (see CLASS) or in an interface definition (see INTERFACE). The READ-ONLY addition makes a public attribute, declared in a DATA statement, readable from outside the class, but only modifiable by methods of the class or its subclasses. Example CLASS C1 DEFINITION. PUBLIC SECTION. DATA A VALUE 'X' READ-ONLY. METHODS M. ENDCLASS. DATA O TYPE REF TO C1. CREATE OBJECT O. CALL METHOD O->M. WRITE O->A. CLASS C1 IMPLEMENTATION. METHOD M. A = 'Y'. ENDMETHOD. ENDCLASS. Attribute A of class C1 can only be read from outside the class. To change it, you need a method from the same class. Additional help

Classes Variant 2 DATA f(len). Extras: As in variant 1, except addition LENGTH . Effect The field f is created with length len. You can only use this variant for fields with type C , N , P, and X. Fields with a different type can only be created with their standard length (see the table under variant 1). The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Incorrect Length Entries in Declaration . The permitted length of a field depends on its type: Type Permitted length C 1 - 65535 N 1 - 65535 P 1 - 16 X 1 - 65535 Note The system can display one character or two decimal or hexadecimal digits per byte. In P fields, one character is reserved for the sign. This means that a P field with length 3 can contain up to 5 digits, but an X field with length 3 can contain 6. Both have output length 6.

DATA - Simple Field Definition Variants: &&. DATA f. 2. DATA f(len). Variant 1 DATA f.

Extras: 1. ... TYPE type 2. ... LIKE f1

3. ... TYPE LINE OF itabtype 4. ... LIKE LINE OF itab 5. ... TYPE REF TO cif 6. ... TYPE REF TO DATA 7. ... TYPE REF TO type 8. ... VALUE lit 9. ... LENGTH n 10. ... DECIMALS n 11. ... READ-ONLY The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See New Naming Conventions. Effect The internal program field f is created with standard length. If you do not specify a reference type, the system creates a field with type C . A type name can be up to 30 characters long. The name may only consist of alphanumeric characters and the underscore character. It may not consist entirely of digits. Special characters such as German umlauts are not allowed. As well as these characters, certain special characters are used internall. However, these should not be used in application programs. SPACE is a reserved name, and cannot therefore be used. Furthermore, you should not use a field in a statement if it has the same name as one of the additions of the keyword (for example: PERFORM SUB USING CHANGING.). Recommendations for Type Names: 1. Always start the name with a letter. 2. Use the underscore to separate compound names (for example, NEW_PRODUCT. Additional help Variables Addition 1 ... TYPE type Effect The field f is created with type type. For the type, you can specify either one of the predefined types listed below, a type defined using the TYPES statement, or a type created in the ABAP Dictionary. The standard length ( SL ) of a field depends on its type. Type C N D T X I P F Explanation SL Initial value

Text (Character) 1 space Numeric text 1 '00...0' Date (YYYYMMDD) 8 '00000000' Time (HHMMSS) 6 '000000' Hexadecimal (HeX code) 1 X'00' Integer 4 0 Packed number 8 0 Floating point number 8 0

STRING Character sequence (string) variable-length empty string XSTRING Byte sequence (X string) variable-length empty hexadecimal string Example DATA NUMBER TYPE I. DATA WA_SPFLI TYPE SPFLI. The field NUMBER is created with type I. You can now use it in the program. In particular, you can assign numeric values to the field and use it in calculations ( ABAP number types). The field WA_SPFLI is created using the type of the database table SPFLI from the ABAP Dictionary. This field is structured and can be used especially for working with data from database table SPFLI. Addition 2 ... LIKE f1 The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Cannot Use LIKE References to Dictionary Types. Effect Field f is created with the same field attribtues as the data object f1, which has already been declared. Any data object (field, parameter, structure...) is allowed as long as its type has been fully specified. f1 can be any ABAP Dictionary reference. Example DATA TABLE_INDEX LIKE SY-TABIX. The field TABLE_INDEX now has the same attributes as SY-TABIX (index field for internal tables). Note You should use this addition whenever you can. If the type of a field to which you are referring changes, the ABAP runtime system updates all references automatically. It also stops the system from carrying out unnecessry (and maybe undesirable) type conversions. Addition 3 ... TYPE LINE OF itabtype Effect The specified type itabtype must have the type of an internal table. The system creates a data object with the same line type of the specified table. Example TYPES TAB_TYPE TYPE STANDARD TABLE OF I WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 10. DATA TAB_WA TYPE LINE OF TAB_TYPE.

The data object TAB_WA now has the same attributes as a line of the table type TAB_TYPE, that is, type I. Addition 4 ... LIKE LINE OF itab The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Cannot Use LIKE References to Dictionary Types. Effect The data object itab must be an internal table with or without header line. The system creates a data object with the same line type as the specified table. Example DATA TAB TYPE STANDARD TABLE OF I WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 10. DATA TAB_WA LIKE LINE OF TAB. The data object TAB_WA now has the same attributes as a line of the table TAB , that is, type I. Addition 5 ... TYPE REF TO cif Effect Data object f is declared as reference variable within ABAP objects. cif is a class or an interface. Reference variables contain references (pointers) to objects. Reference variables whose types are defined with reference to a class can contain references to objects of this class. Reference variables whose types are defined with reference to an intterface can contain references to objects whose class implements the interface. Note Objects, i.e.instances of classes, are only addressed with their reference variables. To create objects see CREATE OBJECT. Example INTERFACE i1. METHODS m1. ENDINTERFACE. CLASS c1 DEFINITION. PUBLIC SECTION. INTERFACES i1. ENDCLASS. CLASS c1 IMPLEMENTATION. METHOD i1~m1. ... ENDMETHOD. ENDCLASS.

DATA: o1 TYPE REF TO c1, o2 TYPE REF TO c1, ir TYPE REF TO i1. START-OF-SELECTION. CREATE OBJECT o1. o2 = o1. ir = o1. Additional help Handling of Objects Addition 6 ... TYPE REF TO DATA Effect Declares the data object f as a generic data reference variable. Data reference variables of that kind can contain references (pointers) to data objects of any types. They can only be dereferenced using the statement ASSIGN . Example DATA: numref TYPE REF TO DATA, number TYPE I VALUE 123. FIELD-SYMBOLS: <fs> TYPE ANY. GET REFERENCE OF number INTO numref. ASSIGN numref->* TO <fs>. This example creates a reference to the data object number. It is then assigned to the field symbol <fs> using the dereferencing operator ->*. It is now possible to work with the field symbol in the normal way. Addition 7 ... TYPE REF TO type Defining a typed data reference variable. Types you can use include elementary types, types defined using TYPES, or types created in the ABAP Dictionary. You can dereference completely typed data reference variables using the dereferencing operator ->* at any operand position. Example types: LNTYP type I. data: CNT type ref to I, LINE type ref to LNTYP, FLIGHT type ref to SFLIGHT. create data CNT. create data LINE.

create data FLIGHT. CNT->* = 20. LINE->* = 110. FLIGHT->FLDATE = SY-DATUM. Addition 8 ... VALUE lit Effect Instead of the default initial value, the system assigns the literal lit to f, as its initial value. You can also declare a constant. Instead of using a literal, you can also use the IS INITIAL declaration. In this case, the field value is set to the initial value appropriate to its type. This form is particularly necessary when you use the CONSTANTSstatement, since you must always include the VALUE addition with this statement. Example DATA: NUMBER TYPE I VALUE 123, FLAG VALUE 'X', TABLE_INDEX LIKE SY-TABIX VALUE 45. The field NUMBER with type I is created, and does not have an initial value of 0, but 123; the new field FLAG with type C (length 1) contains the value 'X'; TABLE_INDEX has the value 45, since SY-TABIX is a numeric field. Note You cannot declare XSTRINGs, references and internal tables or structures containing internal tables after VALUE. Addition 9 ... LENGTH n Effect This addition is only allowed for the field types C , N , X, and P. The field f is created with the length n. Addition 10 ... DECIMALS n Effect This addition is only necessary for field type P. When you calculate using this field or output it, it has n decimal places, where n is between 0 and 14. When you create a new program, "floating point arithmetic" is selected by default. If you deselect this attributes, the DECIMALS specification is only effective when you output the field, not when you use it in calculations. In this case, you must ensure that you have the correct number of decimal places by multiplying or dividing the field by the appropriate power of 10. (COMPUTE). You are recommended always to work with the fixed point arithmetic switched on. This ensures that intermediate results (division!) are calculated with the greatest possible accuracy (31 decimal places).

To see whether fixed point P or floating point F is more suitable, see "ABAP number types" Addition 11 ... READ-ONLY Effect You can only use this addition in the public visibility section (PUBLIC SECTION ) of a class declaration (see CLASS) or in an interface definition (see INTERFACE). The READ-ONLY addition makes a public attribute, declared in a DATA statement, readable from outside the class, but only modifiable by methods of the class or its subclasses. Example CLASS C1 DEFINITION. PUBLIC SECTION. DATA A VALUE 'X' READ-ONLY. METHODS M. ENDCLASS. DATA O TYPE REF TO C1. CREATE OBJECT O. CALL METHOD O->M. WRITE O->A. CLASS C1 IMPLEMENTATION. METHOD M. A = 'Y'. ENDMETHOD. ENDCLASS. Attribute A of class C1 can only be read from outside the class. To change it, you need a method from the same class. Additional help Classes Variant 2 DATA f(len). Extras: As in variant 1, except addition LENGTH . Effect The field f is created with length len. You can only use this variant for fields with type C , N , P, and X. Fields with a different type can only be created with their standard length (see the table under variant 1). The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Incorrect Length Entries in Declaration .

The permitted length of a field depends on its type: Type Permitted length C 1 - 65535 N 1 - 65535 P 1 - 16 X 1 - 65535 Note The system can display one character or two decimal or hexadecimal digits per byte. In P fields, one character is reserved for the sign. This means that a P field with length 3 can contain up to 5 digits, but an X field with length 3 can contain 6. Both have output length 6.

Das könnte Ihnen auch gefallen