SAP ABAP SYNTAX FOR DATA PART ONE

Variants

1. DATA f.
2. DATA f(len).
3. DATA: BEGIN OF rec,
...
END OF rec.
4. DATA: BEGIN OF itab OCCURS n,
...

END OF itab.
5. DATA: BEGIN OF COMMON PART c,
...
END OF COMMON PART.

Effect

Defines global and local variables. Variables allow you to address declared data objects . They always have a particular data type. Data types and data objects are important components of the ABAP/4 type concept .

Variant 1

DATA f.

Additions


1. ... TYPE typ
2. ... LIKE f1
3. ... TYPE typ OCCURS n
4. ... LIKE f1 OCCURS n
5. ... TYPE LINE OF itabtyp
6. ... LIKE LINE OF itab
7. ... VALUE lit
8. ... DECIMALS n
9. ... WITH HEADER LINE

Effect

Creates the internal field f in its standard length. If you do not specify the type (using the addition TYPE ), a field of type C is assumed.

The field f can be up to 30 characters long. You can use any characters you like except the special characters '(' , ')' , '+' , '-' , ',' and ':' . Numeric characters are allowed but the field name may not consist of numbers alone.

SPACE is a reserved word and therefore cannot be used. Also, the field name cannot be the same as one of the additional parameters of the introductory key word (e.g. PERFORM SUB USING CHANGING. ).

Recommendations for field names:
Always use a letter as the first character.
Use the underscore to join together words which are part of the same name (e.g. NEW_PRODUCT ). The hyphen should not be used here, since it is reserved for the names of field string components .

Addition 1

... TYPE typ.

Effect

Creates a field f of the type typ . You can use either one of the predefined types listed below or one of your own types which you define withTYPES .
The standard length ( SL ) of the field depends on the type.
Type
Description
SL
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 no.
8
'0.0'




Example

 
DATA NUMBER TYPE I.

Creates the field NUMBER as type I . You can also use it in the program, particularly if you want to assign number values and perform calculations.

Notes

  • The data type I is the whole number type on which the hardware is based. Its value range is from -2**31 to 2**31-1 (from -2.147.483.648 to 2.147.483.647).
    You use type P for fields containing monetary amounts, but type I is more suitable for number fields, index fields, specifying positions and so forth.
You can use type F for positive and negative numbers other than zero in the range from 1E-307 to 1E+308 with a degree of accuracy up to 15 decimal places. (The ABAP/4 processor always uses the floating point operations of the hardware in question rather than standardizing them.) Floating point literals must be enclosed in quotation marks. The standard output length is 22.

Entries in type F fields may be formatted in any of the following ways:

As a decimal number with or without sign and with or without a decimal point.

In the form e, where you specify the mantissa as above and the exponent with or without a sign. (Examples of floating point literals: '1' , '-12.34567' , '-765E-04' , '1234E5' , '+12E+34' , '+12.3E-4' .

Since floating point arithmetic is fast on our hardware platforms, you should use it when you need a greater value range and you are able to tolerate rounding errors. Rounding errors may occur when converting the external (decimal) format to the corresponding internal format (base 2 or 16) or vice-versa (ABAP/4 number types ).


RELATED POST

SAP ABAP SYNTAX FOR CREATE

No comments :

Post a Comment