1. TYPES typ.

2. TYPES typ(len).

3. TYPES: BEGIN OF rectyp,

...

END OF rectyp.

1. ... TYPE typ1

2. ... LIKE f

3. ... TYPE typ1 OCCURS n

4. ... LIKE f OCCURS n

5. ... TYPE LINE OF itabtyp

6. ... LIKE LINE OF itab

7. ... DECIMALS n

The type name typ can be up to 30 characters long. Apart from the special characters '(', ')', '+', '.', ',', ':', '-', '<' and '>', you can use any characters. Numbers are allowed, but the name cannot consist of numbers alone.

Recommendations for type names:

Always use a letter as the first character.

Use the underscore as the link in multiple word names (e.g. NEW_PRODUCT ).

The length (SL) of the type typ is the same as the type typ1 .

Type Description Std len. Initial value

C Text (character) 1 Blank

N Numeric text 1 '00...0'

D Date (YYYYMMDD) 8 '00000000'

T Time (HHMMSS) 6 '000000'

X Hexadecimal 1 X'00'

I Whole number (integer) 4 0

P Packed number 8 0

F Floating point number 8 '0.0'

- TYPES NUMBER TYPE I.

This defines the type NUMBER NUMBER with the type I . It can then be used in the program.

While type P is used for money amount fields, you should use type I for number fields, index fields, position specifications, etc.

Apart from zero, type F allows you to display positive and negative numbers in the range from 1E-307 to 1E+307 with 15 decimal places. (The ABAP/4 processor uses the floating point operations of the relevant hardware and does not attempt to standardize them.) Floating point literals must be enclosed in quotation marks. The standard output length is 22.

Input in type F fields can be formatted differently:

Decimal number with or without sign, with or without decimal point.

In the form

Floating point arithmetic is fast on our hardware platforms. It is ideal when you require a large value range and can take rounding errors into account when making calculations. Such rounding errors can occur when converting from external (decimal) format to internal format (base 2 or 16) or vice-versa (see ABAP/4 number types ).

- TYPES TABLE_INDEX_TYP LIKE SY-TABIX.

The type TABLE_INDEX_TYP now points to the type of the field SY-TABIX (index for internal tables).

You fill and process an internal table with statements such as APPEND , READ TABLE , LOOP and SORT .

The OCCURS parameter n specifies how many table lines of storage is required. This storage reservation process does not happen until the first line is inserted in the table. The value n of the OCCURS specification has no effect on type checking, i.e. data objects which have types with different OCCURS specifications are type-compatible.

TYPES: TAB_TYPE TYPE I OCCURS 20.

DATA: TAB TYPE TAB_TYPE,

TAB_WA TYPE I.

TAB_WA = 1.

APPEND TAB_WA TO TAB.

TAB_WA = 2.

APPEND TAB_WA TO TAB.

The internal table TAB now consists of two table entries.

- DATA: BEGIN OF PERSON, NAME(20), AGE TYPE I, END OF PERSON. TYPES TYPE_PERSONS LIKE PERSON OCCURS 20. DATA PERSONS TYPE TYPE_PERSONS. PERSON-NAME = 'Michael'. PERSON-AGE = 25. APPEND PERSON TO PERSONS. PERSON-NAME = 'Gabriela'. PERSON-AGE = 22. APPEND PERSON TO PERSONS.

The internal table PERSONS now consists of two table entries.

- TYPES TAB_TYP TYPE I OCCURS 10. TYPES MY_TYPE TYPE LINE OF TAB_TYP.

- DATA TAB TYPE I OCCURS 10. TYPES MY_TYPE LIKE LINE OF TAB.

The type MY_TYPE now has the same attributes as the line type of the table TAB and thus has the type I .

Normally, the attribute for fixed point arithmetic is set with newly created programms. If you switch this attribute off, the DECIMALS -specification is taken into account on output, but not when making calculations. In this case, the programmer must take care that the decimal point is in the right place by multiplying or dividing (COMPUTE ) by the appropriate power of ten.

When making calculations, you should always have fixed point arithmetic switched on. Then, even intermediate results (division!) are calculated with the greatest possible accuracy (31 decimal places).

To decide whether the fixed point type P or the floating point type F is more suitable, see also "ABAP/4 number types ".

Similar to variant 1

This variant should only be used with the types C , N , P and X . Other types can only be created in the standard length (see table under effect of variant 1).

The permitted lengths depend on the type being pointed to:

Type Permitted lengths

C 1 - 65535

N 1 - 65535

P 1 - 16

X 1 - 65535

...

END OF rectyp.

- TYPES: BEGIN OF PERSON, NAME(20) TYPE C, AGE TYPE I, END OF PERSON.

Index

© SAP AG 1996