SAP ABAP SYNTAX FOR DATA PART FOUR

This is the continuation of Syntax for data part three .

Addition 7

... VALUE lit

Effect

The initial value of the field f is the literal lit instead of that defined in the table above. You can also specify a constant or even use IS INITIAL . In the latter case, the field is preset to the type-specific initial value. This form is particularly important in connection with the CONSTANTS statement which always requires you to use the addition VALUES .

Example

 
DATA NUMBER      TYPE I        VALUE 123,
     FLAG                      VALUE 'X',
     TABLE_INDEX LIKE SY-TABIX VALUE 45.
When created, the field NUMBER of type I contains 123 rather than the expected initial value of 0. The newly created field FLAG of type C (length 1) contains 'X' , while TABLE_INDEX contains 45, since the system field SY-TABIX is a numeric field.

Addition 8

... DECIMALS n

Effect

Only makes sense with field type P . When you perform calculations and on output, the field has n decimal decimal places, where n is a number between 0 and 14.

In the case of newly generated programs, you normally activate fixed point arithmetic in the attributes. If it is not set, the DECIMALS specification is taken into account on output, but not when performing calculations. This means that the programmer must take care of any decimal point calculations by multiplying or dividing by powers of ten.
Fixed point arithmetic should always be active when you are performing calculations, since this enables intermediate results (for division) to be calculated as accurately as possible (in this case, to 31 decimal places).
To decide whether you should use the fixed point type P or the floating point type F , see "ABAP/4 number types ".

Addition 9

... WITH HEADER LINE

Effect

You can only use this addition with table types. When you specify WITH HEADER LINE , you create a header line with the same name type as a table line in addition to the table.

With non-table operations , the name f refers to this header line. With table operations (e.g. APPEND ,
the name f refers to the table or the table and header line. The notation f[] always denotes the table. The result of this expression is a table without a header line and can be used as such.

Example

 
DATA:  BEGIN OF PERSON_TYPE,
         NAME(20),
         AGE TYPE I,
       END OF PERSON_TYPE.
DATA:  PERSONS LIKE PERSON_TYPE OCCURS 20 WITH HEADER LINE.
 
PERSON-NAME = 'Michael'.
PERSON-AGE  = 25.
APPEND PERSONS.
PERSON-NAME = 'Gabriela'
PERSON-AGE  = 22.
APPEND PERSONS.
* Delete header line
CLEAR PERSONS.
* Delete table
CLEAR PERSONS[].

No comments :

Post a Comment