Monday, April 27, 2009

Type Groups

Type groups were based on the include technique, and allowed you to store any type definitions globally in the Dictionary by defining them using TYPES statements. The definition of a type group is a fragment of ABAP code which you enter in the ABAP Editor. The first statement for the type group pool is always: TYPE-POOL pool.

After that, you define data types using the statement TYPES. It was also possible to define global constants using the CONSTANTS statement. All the names of these data types and constants must begin with the name of the type group and an underscore: pool_

In an ABAP program, you must declare a type group as follows before you can use it: TYPE-POOLS pool. This statement allows you to use all the data types and constants defined in the type group pool in your program. You can use several type groups in the same program.

Let the type group HKTST be created as follows in the ABAP Dictionary:

TYPE-POOL hktst.
TYPES: BEGIN OF hktst_typ1,
col1(10) TYPE c,
col2 TYPE i,
END OF hktst_typ1.

TYPES hktst_typ2 TYPE p DECIMALS 2.
CONSTANTS hktst_eleven TYPE i VALUE 11.

This type group defines two data types HKTST_TYP1 and HKTST_TYP2, as well as a constant HKTST_ELEVEN with the value 11.

Any ABAP program can use this definition with the TYPE-POOLS statement:

TYPE-POOLS hktst.
DATA: dat1 TYPE hktst_typ1,
dat2 TYPE hktst_typ2 VALUE '1.23'.
WRITE: dat2, / hktst_eleven.
The output is: 1.23, 11

The data types defined in the type group are used to declare data objects with the DATAstatement and the value of the constant is, as the output shows, known in the program

Example for type Group
*&---------------------------------------------------------------------*
*& Report ZBASU_TYPE_GROUP *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT ZBASU_TYPE_GROUP .
TYPE-POOLs: ZTYPE .
Tables: mara.

data: itab type table of ztype_basu with header line.
select-options: material for mara-matnr.

select * from mara into corresponding fields of table itab where matnr
in material.

write:/ ztype_a.
loop at itab.
write:/ itab-matnr,
itab-ersda,
itab-ernam.
endloop.

***************** Type Group defined DDIC
TYPE-POOL ZTYPE .

constants: ZTYPE_a type i value 10.
types: begin of ztype_basu,
matnr like mara-matnr,
ersda like mara-ersda,
ernam like mara-ernam,
end of ztype_basu.

No comments:

Post a Comment