ABAP Data Types and Constants

Data Type describes the technical characteristics of a Variable of that type. Data type is just the blue print of a variable.

Predefined ABAP Types

Data Type Description Default Length Default Value
C Character 1 ‘ ‘
N Numeric 1 0
D Date 8 00000000
T Time 6 000000
X Hexa Decimal 1 X’0′
I Integer 4 0
P Packed 8 0
F Float 8 0

User defined data types
Use TYPES keyword to define the data types.

TYPES: name(10) TYPE c,
       length   TYPE p DECIMALS 2,
       counter  TYPE i,
       id(5)    TYPE n.

Structured data types

Structured data type is grouping of several simple data types under one name.

Use the keywords BEGIN OF and END OF to create a structured data type.

TYPES: BEGIN OF student,
        id(5)     TYPE n,
        name(10)  TYPE c,
        dob       TYPE d,
        place(10) TYPE c,
        END OF student.

Constants

Constants are used to store a value under a name. We must specify the value when we declare a constant and the value cannot be changed later in the program.

Use CONSTANTS keyword to declare a constant.

CONSTANTS: pi  TYPE p DECIMALS 2 VALUE '3.14',
           yes TYPE c VALUE 'X'.

28 Comments

  1. Excellent post. It is seriously improve to us. Its offer us a great many interest and satisfaction. Its chance are so great and hitting style so speedy. Its really a great write-up. It offers me a lot of pleasure and interest.

  2. I just want to say I am just newbie to blogging and truly enjoyed your web site. Probably I’m likely to bookmark your site . You amazingly come with wonderful well written articles. Many thanks for revealing your blog site.

  3. Hey, you used to write fantastic articles, but the last few posts have been kinda boring… I miss your tremendous posts. Past several posts are just a little bit out of track!

  4. Hey There. I found your blog using msn. This is a very well written article. I’ll make sure to bookmark it and return to read more of your useful info. Thanks for the post. I’ll certainly comeback.

  5. Simply desire to say your article is as amazing. The clearness in your post is just great and i could assume you are an expert on this subject. Fine with your permission allow me to grab your RSS feed to keep updated with forthcoming post. Thanks a million and please keep up the gratifying work.

  6. I am often to blogging and i really respect your content. The article has actually peaks my interest. I am going to bookmark your site and hold checking for new information.

  7. its really easy to understand things from here for newbie Abaper but If the output of given user defined data types also shown here,it will be a great help as i am not able to understand the structured data type ,how it look like.

  8. Your blog is very nice. I have gone through the entire material. Really appreciating your effort. I would like to add one small point to this tutorial. While declaring constants it is not mandatory to specify the value and the value can be changed during our program. At any point of time it contains one value.

  9. X Hexa Decimal 1 X’0′
    I checked in ABAP and found that a Hexadecimal variable was able to store 2 hex characters.
    For example,
    TYPES: HexValue type X.
    DATA: value type HexValue.

    value = ‘FF’.
    WRITE value.

    It is printing ‘FF’. So does that mean the length of a Hexadecimal variable is 2?

  10. Additional Info :
    Difference between float and packed.
    packed – rounds the decimal value to the next whole integer.
    89.88 becomes 90.

    float – holds the exact value assigned to it.
    89.88 remains 8.9879999999999995E+1

  11. can u elaborate more aout user defined data types ,
    coz as per java we array structures union as userdefined data types,
    so in ABAP do we have similar data types

Comments are closed.