SAP ABAP - Elementary Data Types, Initial Values, Syntax & Properties.
In ABAP, we have 8 elementary data types to declare data types:
CHARACTER TEXT(C):
- Lenght: 1 - 65535.
- Default Length: 1.
- Initial Value: Blank.
- Default Values for the character based data types has to be a text enclosed in single quotes.
- Character fields (Type C) are left-justified and can be truncated or filled with blanks from the right.
- Character fields can also be used as alphanumeric fields.
Example:
DATA: option TYPE c.
DATA: name(30).
DATA: subject(20) TYPE c.
DATA: title(10) VALUE 'Mr.'.
DATA: name(30) TYPE c VALUE 'Sachin Tendulkar '.
DATA: name TYPE char30. " This statement will allow name variable to hold upto 30 characters.
NUMERIC TEXT (N):
- Length: 1 - 65535.
- Default Length: 1.
- Initial Value: '0....0'.
- Numeric text variables hold unsigned positive integers.
- This data type should be used for numeric fields that will not be calculated like Roll number, Employee number.
- We can use it for variables that hold a numeric extracted from a character data type.
- Long character field in which only numbers can be entered.
- Default Values for the numeric based data types has to be a text enclosed in single quotes.
- Numeric Fields are left-justified.
Example:
DATA: rollno(8) TYPE n.
DATA: empno(12) TYPE n VALUE '1234567890'.
DATE TYPE (D):
- Default Length: 8 (Fixed).
- Valid Values: 0-9.
- Initial Value: '00000000'.
- The current date is available in the system field sy-datum.
- Value for date variable always stored internally as YYYYMMDD.
Example:
DATA: date TYPE D VALUE '20110101'.
TIME TYPE (T):
- Default Length: 6 (Fixed).
- Valid Values: 0-9.
- Initial Value: 000000.
- The current time is available in the system field sy-uzeit.
- Value for date variable always stored internally as HHMMSS.
Example:
DATA: time TYPE T VALUE '063015'.
INTEGER TYPE (I):
- Length: 4 Bytes (Fixed).
- Initial Value: 0.
- Use integers for variables that will be involved in simple computations or when no decimal points are required.
- This data type stores a binary number with a range of values from -2147483648 to +
2147483647.
- Variables such as counters, indexes, positions, or offsets are good examples.
- Default Values for the integer based data types has to be a text enclosed in single quotes.
- Integer types are right-justified.
Example:
DATA: number TYPE i.
DATA: profit TYPE i VALUE '10'.
PACKED DECIMAL TYPE (P):
- Length: 1 - 16 Bytes.
- Default Length: 8 Bytes.
- Initial Value: 0.
- Amount or counter field (packed; implementation depends on hardware platform).
- Data Type 'P' length between 1-16 (default 8) and decimals length between 0-31.
- With this data type, two digits are stored in a single byte and the last half byte is used to store the sign.
- Recommended for commercial calculations.
- Packed type i.e. Type 'P' are right-justified.
Example:
* Defines a variable 'FACTOR' capable of holding 4 digits (plus a sign).
DATA: factor(2) TYPE p DECIMALS 2.
* Defines a variable 'AVG' capable of holding 15 digits because the default length for type p is 8.
DATA: avg TYPE p.
DATA: mean(8) TYPE p DECIMALS 2 VALUE '1.50'.
FLOATING-POINT TYPE (F):
- Max Length: 8 Bytes.
- Default Length: 8 Bytes.
- Initial Value: 0.0
- Floating-point variables are always approximate.
- They can be used for calculations requiring very large values or many decimal places.
- Floating-Point type i.e. Type 'F' are right-justified.
- Recommended for mathematical/scientific calculations.
ALSO READ:
- Type Conversion ( Char To Curr Type).
- Type Conversion ( Curr To Char Type).
- ELEMENTARY DATA TYPES - Initial Values, Syntax & Properties.
- FIELD SYMBOLS - Introduction, Syntax & Examples.
- PARAMETERS - Introduction, Syntax & Examples.
- SELECT-OPTIONS - Introduction, Syntax & Examples.
- SELECTION-SCREEN - Introduction, Syntax & Examples.
- SSCRFIELDS - The Screen Fields Table.
- ...Back To Index On Report Programming.
Your suggestions and comments are welcome in this section.
Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.
CHARACTER TEXT(C):
- Lenght: 1 - 65535.
- Default Length: 1.
- Initial Value: Blank.
- Default Values for the character based data types has to be a text enclosed in single quotes.
- Character fields (Type C) are left-justified and can be truncated or filled with blanks from the right.
- Character fields can also be used as alphanumeric fields.
Example:
DATA: option TYPE c.
DATA: name(30).
DATA: subject(20) TYPE c.
DATA: title(10) VALUE 'Mr.'.
DATA: name(30) TYPE c VALUE 'Sachin Tendulkar '.
DATA: name TYPE char30. " This statement will allow name variable to hold upto 30 characters.
NUMERIC TEXT (N):
- Length: 1 - 65535.
- Default Length: 1.
- Initial Value: '0....0'.
- Numeric text variables hold unsigned positive integers.
- This data type should be used for numeric fields that will not be calculated like Roll number, Employee number.
- We can use it for variables that hold a numeric extracted from a character data type.
- Long character field in which only numbers can be entered.
- Default Values for the numeric based data types has to be a text enclosed in single quotes.
- Numeric Fields are left-justified.
Example:
DATA: rollno(8) TYPE n.
DATA: empno(12) TYPE n VALUE '1234567890'.
DATE TYPE (D):
- Default Length: 8 (Fixed).
- Valid Values: 0-9.
- Initial Value: '00000000'.
- The current date is available in the system field sy-datum.
- Value for date variable always stored internally as YYYYMMDD.
Example:
DATA: date TYPE D VALUE '20110101'.
TIME TYPE (T):
- Default Length: 6 (Fixed).
- Valid Values: 0-9.
- Initial Value: 000000.
- The current time is available in the system field sy-uzeit.
- Value for date variable always stored internally as HHMMSS.
Example:
DATA: time TYPE T VALUE '063015'.
INTEGER TYPE (I):
- Length: 4 Bytes (Fixed).
- Initial Value: 0.
- Use integers for variables that will be involved in simple computations or when no decimal points are required.
- This data type stores a binary number with a range of values from -2147483648 to +
2147483647.
- Variables such as counters, indexes, positions, or offsets are good examples.
- Default Values for the integer based data types has to be a text enclosed in single quotes.
- Integer types are right-justified.
Example:
DATA: number TYPE i.
DATA: profit TYPE i VALUE '10'.
PACKED DECIMAL TYPE (P):
- Length: 1 - 16 Bytes.
- Default Length: 8 Bytes.
- Initial Value: 0.
- Amount or counter field (packed; implementation depends on hardware platform).
- Data Type 'P' length between 1-16 (default 8) and decimals length between 0-31.
- With this data type, two digits are stored in a single byte and the last half byte is used to store the sign.
- Recommended for commercial calculations.
- Packed type i.e. Type 'P' are right-justified.
Example:
* Defines a variable 'FACTOR' capable of holding 4 digits (plus a sign).
DATA: factor(2) TYPE p DECIMALS 2.
* Defines a variable 'AVG' capable of holding 15 digits because the default length for type p is 8.
DATA: avg TYPE p.
DATA: mean(8) TYPE p DECIMALS 2 VALUE '1.50'.
FLOATING-POINT TYPE (F):
- Max Length: 8 Bytes.
- Default Length: 8 Bytes.
- Initial Value: 0.0
- Floating-point variables are always approximate.
- They can be used for calculations requiring very large values or many decimal places.
- Floating-Point type i.e. Type 'F' are right-justified.
- Recommended for mathematical/scientific calculations.
ALSO READ:
- Type Conversion ( Char To Curr Type).
- Type Conversion ( Curr To Char Type).
- ELEMENTARY DATA TYPES - Initial Values, Syntax & Properties.
- FIELD SYMBOLS - Introduction, Syntax & Examples.
- PARAMETERS - Introduction, Syntax & Examples.
- SELECT-OPTIONS - Introduction, Syntax & Examples.
- SELECTION-SCREEN - Introduction, Syntax & Examples.
- SSCRFIELDS - The Screen Fields Table.
- ...Back To Index On Report Programming.
Your suggestions and comments are welcome in this section.
Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.