onlyforbopi
2/28/2017 - 8:48 AM

ABAP - DATA DECLARATION

ABAP - DATA DECLARATION

* Declare variable structure
ULINE.
WRITE / 'Declare variable structure: '.
DATA:      BEGIN OF myaddress2,
           name     TYPE c LENGTH 20 VALUE 'Fred Flintstone',
           street   TYPE c LENGTH 20 VALUE 'Cave Avenue',
           number   TYPE p           VALUE  11,
           postcode TYPE n LENGTH 5  VALUE  98765,
           city     TYPE c LENGTH 20 VALUE  'Bedrock',
           END OF myaddress2.

WRITE: / 'Call', myaddress2-name.
WRITE: / 'Call', myaddress2-street.
WRITE: / 'Call', myaddress2-number.
WRITE: / 'Call', myaddress2-postcode.
WRITE: / 'Call', myaddress2-city.
* CONSTANTS *

******************************************************************
* SIMPLE CONSTANTS 
		CONSTANTS <f> TYPE <type> VALUE <val>.
		
*EX..
		REPORT YR_SEP_12. 
		CONSTANTS PQR TYPE P DECIMALS 4 VALUE '1.2356'. 
		Write: / 'The value of PQR is:', PQR.

******************************************************************
* COMPLEX CONSTANTS * CONSTANT STRUCTURES
		BEGIN OF EMPLOYEE,  
		Name(25) TYPE C VALUE 'Management Team',  
		Organization(40) TYPE C VALUE 'Tutorials Point Ltd',  
		Place(10) TYPE C VALUE 'India',  
		END OF EMPLOYEE.

******************************************************************
* CONSTANT REFERENCES *
		CONSTANTS null_pointer TYPE REF TO object VALUE IS INITIAL.
DATA char_var(15) TYPE C VALUE 'SAP ABAP22222'.
DATA char_var2 TYPE C LENGTH 30 VALUE 'SAP ABAP LONG'.  
DATA integer_var TYPE I VALUE '13'.
DATA numtext_var(5) TYPE N VALUE '121212'.

* Packed variables allow the storage of decimals
DATA packed_var(10) TYPE P VALUE '5555555'.
DATA float_var TYPE F VALUE '1.333333'.
DATA date_var TYPE D VALUE '20161411'.
DATA time_var type T VALUE '1923'.


WRITE:  / 'Char var', char_var,
        / 'Char var', char_var2,
        / 'integer_var', integer_var,
        / 'Numerical text var', numtext_var,
        / 'Packed var', packed_var,
        / 'Float var', float_var,
        / 'Date var', date_var,
        / 'Time var', time_var.

* VARIABLE LENGTH VARIABLES
***** STRINGS
*****
DATA my_Char(5) VALUE 'Hello'.

WRITE: / 'String variable', my_Char.
1. declare_variables.abap        - Declare variables 
2. declare_variable_struct.abap  - Declare variable structures
3. declare_constants.abap        - Declare constants
4. declare_const_structures.abap - Declare constant structures
5. variable_types.abap           - Different variable declarations.