Showing posts with label SAP. Show all posts
Showing posts with label SAP. Show all posts

Wednesday, March 18, 2009

SAP ABAP : Structure, Internal Table, Transparent Table

These confused me a lot. Finally, I wrote something to clear my doubts.

* Transparent Table: SAPLANE
* Internal Table: TY_PLANETYPES
* Structure: Z07_SAPLANE

*Possible ways of typing data object with structure, trans. table and internal table.

TABLES: SAPLANE. "=> Equivalent to DATA: SAPLANE TYPE SAPLANE. [Structure of SAPLANE with the name of SAPLANE]

DATA: t_1 TYPE SAPLANE, "=> Structure of SAPLANE.
t_2 TYPE LINE OF TY_PLANETYPES, "=> Structure of TY_PLANETYPES
t_3 TYPE TY_PLANETYPES, "=> Internal Table of TY_PlANETYPES
t_4 TYPE TABLE OF SAPLANE, "=> Internal Table of SAPLANE
t_5 TYPE TABLE OF TY_PLANETYPES, "=> Single Column Internal Table that listing Internal Table of TY_PLANETYPES.
t_9 LIKE LINE OF t_4, "=> Structure of SAPLANE.
t_10 LIKE LINE OF t_5, "=> Structure of TY_PLANETYPE.
t_12 TYPE TABLE OF SAPLANE WITH HEADER LINE, "=> t_12 is both a Structure and Internal Table. This is obsolete and please avoid using this. SAP OOP prohibited this syntax.
t_13 LIKE LINE OF t_12, "=> ABAP refer t_12 as Internal Table, and form a structure of SAPLANE.
t_14 TYPE Z07_SAPLANE, "=> Structure of Z07_SAPLANE
t_15 TYPE TABLE OF Z07_SAPLANE. "=> Internal Table with Z07_SAPLANE structure.

"t_6 TYPE LINE OF t_1. => SYNTAX ERROR: TYPE a data object with a data object?
"t_7 LIKE LINE OF TY_PLANETYPES. => SYNTAX ERROR: A data object must come after LIKE.
"t_8 LIKE LINE OF t_2. => SYNTAX ERROR: LINE OF a structure?
"t_11 TYPE LINE OF SAPLANE => SYNTAX ERROR: SAPLANE is not internal table. Can't use LINE OF.


Phew! Hopefully these covers everything.

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!