Sunday, March 15, 2009

SAP ABAP: Data Type Categories

I have no idea why this topic caused that much of problems to me, this is a basic topic and I shouldn't have much troubles with it. But somehow, I spent a very long time to understand it, may be that's the way to master the basic? Or I did it in stupid way? Who knows? Anyway, by hook or by crook, I have to get it clear in my mind.

ABAP has 3 categories of Data Types:
  1. Predefined Data Type / ABAP Standard Type / ABAP Type:
    • Complete ABAP standard types (Doesn't need to specify length)
      1. D - Date, YYYYMMDD, length 8 bytes, fixed.
      2. T - Time, HHMMSS, length 6 bytes, fixed.
      3. I - Integer, lenght 4 bytes, fixed.
        • = 32 bits = 10 digits and 1 +/- sign, MinMax value is +- 2,147,483,647.
      4. F - Floating point number (F), 8 bytes.
        • For scientific calculation purpose, it provides approximate value with rounding error.
        • should avoid using this for any business calculation.
      5. STRING - dynamic length character string.
      6. XSTRING - dynamic length byte sequence (HeXadecimal String).
    • Incomplete ABAP standard types (Length must be specified for the data objects)
      1. C - Character string
      2. N - Numerical Character
        • This guy is odd, he is character that detects and accepts only numeric (0-9) value from Left Hand Side. Pattern King!
      3. X - Byte Sequence (HeXadecimal String)
      4. P - Packed Number
        • This guy won't mess up with any rounding errors, because it's using fixed point arithmetic.
        • Use it for any business calculation.
        • But you have to specify the length and decimals for it.
        • Valid Length is from 1 to 16.
        • Valid Decimals ranged from 0 to 14. (Zero-decimals will convert it behave like Integral [auto round up and down])
  2. Local Type
    • Apparently, you define and declare the Data Type, and use it to type data objects within the program.
  3. Global Type
    • Obviously, you define your Data Type in ABAP Dictionary, and it can be used throughout the entire SAP system.
How you define Data Objects?
DATA: dataObject TYPE data type.

Example 1 with predefined data type:

DATA: lv_dataObjTYPE P LENGTH 5 DECIMALS 2.


Example 2 with local type:
Within your program,

TYPES: abc TYPE P LENGTH 5 DECIMALS 2.

DATA: lv_dataObj TYPE abc.


Example 3 with global type:
Go to ABAP Dictionary: Initial Screen with command SE11 and define your data type, for e.g. def.
In your program,

DATA: lv_dataObj TYPE def.

Please feel free to drop your comments!

No comments: