*&---------------------------------------------------------------------*
*& Report Z_DATA_TYPES
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT z_data_types.
* ---------------------------------------------------------------------*
*Syntax:
* TYPE-POOLS tpool.
* Example:
TYPE-POOLS abap.
DATA parameter_tab TYPE abap_func_parmbind_tab.
*-----------------------------------------------------------------------*
* -----------------------------------------------------------------------*
* DATA TYPES
*
* Syntax Forms
*
* 1. Use Predefined Types
*
* TYPES { {dtype[(len)] TYPE abap_type [DECIMALS dec]}
* | {dtype TYPE abap_type [LENGTH len] [DECIMALS dec]} }.
*Example 1:
*TYPES: text10 TYPE c LENGTH 10,
* text20 TYPE c LENGTH 20,
* result TYPE p LENGTH 8 DECIMALS 2.
*Example 2:
TYPES: text10(10) TYPE c,
text20(20) TYPE c,
result(8) TYPE p DECIMALS 2.
*-------------------------------------------------------------------------*
*Note: when we define data types or data objects, we can use ABAP key word as data types variables
*or data objects variables,which characteristics is different to other languages. But we should
*avoid use ABAP key word as variable name.
* For exaple.
TYPES: type TYPE c.
* DATA: TYPE TYPE C.
*-------------------------------------------------------------------------*
*-------------------------------------------------------------------------*
*2. Refer to Existing Types
*TYPES dtype { {TYPE [LINE OF] type}
* | {LIKE [LINE OF] dobj} }.
*Addition
*... LINE OF ...
*
*The optional addition LINE OF can be used if type is a table type or if dobj is an internal table.
*If this addition is used, dtype inherits the properties of the line type of the internal table.
*Example:
TYPE-POOLS cntl.
DATA: event_table TYPE cntl_simple_events,
event LIKE LINE OF event_table.
*-------------------------------------------------------------------------*
*-------------------------------------------------------------------------*
*3. Reference Types
*
* TYPES dtype { {TYPE REF TO type}
* | {LIKE REF TO dobj} }.
*Effect
*The addition REF TO specifies a data type for a reference variable.
*The entry behind REF TO specifies the static type of the reference variable.
*The static type restricts the object quantity to which a reference variable can refer.
*The dynamic type of a reference variable is the data type and the object class to
*which it refers. The static type is always more general or the same as the dynamic type
*(see also Assignments Between Reference Variables).
*-------------------------------------------------------------------------*
*Example:
INTERFACE i1.
ENDINTERFACE.
CLASS c1 DEFINITION.
PUBLIC SECTION.
INTERFACES i1.
ENDCLASS.
TYPES: iref TYPE REF TO i1,
cref TYPE REF TO c1,
dref TYPE REF TO iref.
*------------------------------------------------------------------------*
*4. Structured Types
* TYPES BEGIN OF struc_type.
* ...
* {TYPES dtype ...} | {INCLUDE {TYPE|STRUCTURE} ...}.
* ...
* TYPES END OF struc_type.
*Effect:
*A structured type struc_type is started by a TYPES statement with the addition
*BEGIN OF and must be ended with a TYPES statement with the addition END OF.
*Between these two TYPES statements, there can be any number of TYPES statements,
*in particular additional closed structure definitions, and the statements
*INCLUDE TYPE and INCLUDE STRUCTURE. A structured type cannot be created without at least one component.
*Example 1:
* Types: begin of struc_type,
* end of struc_type.
*-------------------------------------------------------------------------*
*Note: for this example, this is the deep structure.
*TYPES: BEGIN OF street_type,
* name TYPE c LENGTH 40,
* no TYPE c LENGTH 4,
* END OF street_type.
*
*TYPES: BEGIN OF address_type,
* name TYPE c LENGTH 30,
* street TYPE street_type,
* BEGIN OF city,
* zipcode TYPE n LENGTH 5,
* name TYPE c LENGTH 40,
* END OF city,
* END OF address_type.
*
*TYPES zipcode_type TYPE address_type-city-zipcode.
*--------Example 2:-------------------------------------------------------*
TYPE-pools: slis.
TYPES: BEGIN OF street_type,
streetname TYPE c LENGTH 40,
no TYPE c LENGTH 4,
END OF street_type.
TYPES: BEGIN OF city,
zipcode TYPE n LENGTH 5,
cityname TYPE c LENGTH 40,
END OF city.
TYPES BEGIN OF address_type.
TYPES:name1(10) TYPE C.
INCLUDE TYPE street_type.
INCLUDE TYPE city.
INCLUDE STRUCTURE FIELDINFO.
TYPES END OF address_type.
*If define zipcode_type as below line, it will occure error.
* TYPES zipcode_type TYPE address_type-city-zipcode.
TYPES zipcode_type TYPE address_type-zipcode.
*------ End of Example2----------------------------------------------------*
*--------------------------------------------------------------------------*
*5. Table Types
*TYPES dtype { {TYPE tabkind OF [REF TO] type}
* | {LIKE tabkind OF dobj} }
* [WITH key] [INITIAL SIZE n].
*TYPES - tabkind
*Syntax
*... { {[STANDARD] TABLE}
* | {SORTED TABLE}
* | {HASHED TABLE}
* | {ANY TABLE}
* | {INDEX TABLE} } ... .
*
* Note:
*The non-generic table types determine the internal administration and access type in the ABAP program for an internal table:
*
*Standard tables are managed system-internally by a table index.
*New rows are either attached to the table or added at certain positions.
*The table key or the index identify individual rows.
*
*Sorted tables are managed by a table index (like standard tables).
*The entries are listed in ascending order according to table key.
*
*Hashed tables are managed by a hash algorithm. There is no table index.
*The entries are not ordered in the memory. The position of a row is
*calculated by specifying a key using a hash function.
*
*The generic table types define a generic table type that can only be
*
*ANY TABLE includes all table types.
*INDEX TABLE includes all standard tables and sorted tables.
*
*TYPES - key
*
*Syntax
*... [UNIQUE | NON-UNIQUE] { {KEY comp1 comp2 ...}
* | {DEFAULT KEY} } ... .
*
*Definition of a table key in an internal table.
*
*You use UNIQUE and NON-UNIQUE to specify whether the table key is unique or not.
*For a table key specified with UNIQUE, a row with a certain key field content
*can only occur once in an internal table of this type.
*You can only use NON-UNIQUE for standard tables, you have to use UNIQUE for hashed tables, and both for sorted tables.
*---------------------------------------------------------------------------*
*---------------------------------------------------------------------------*
*6. Ranges Table Types
* TYPES dtype {TYPE RANGE OF type}|{LIKE RANGE OF dobj}
* [INITIAL SIZE n].
*This statement defines a table type for a ranges table, that is with the table type standard table,
*with a standard key, and a specially structured row type whose internal definition
*can be displayed as follows in ABAP syntax:
*
*TYPES: BEGIN OF linetype,
* sign TYPE c LENGTH 1,
* option TYPE c LENGTH 2,
* low {TYPE type}|{LIKE dobj},
* high {TYPE type}|{LIKE dobj},
* END OF linetype.
*----------------------------------------------------------------------------*
*----------------------------------------------------------------------------*
*INCLUDE TYPE
*Syntax
*
*INCLUDE { {TYPE struc_type} | {STRUCTURE struc} }
* [AS name [RENAMING WITH SUFFIX suffix]].
*In this example, the structure week is defined by repeated copying of the components
*in the structured type t_day. The components for week are all on one level and can be
*addressed as follows: week-work_mon, week-free_mon, week-work_tue, and so on. Alternatively,
*however, the following address method is also possible: week-monday-work, week-monday-free,
*week-tuesday-work, and so on.
*
*TYPES: BEGIN OF t_day,
* work TYPE c LENGTH 8,
* free TYPE c LENGTH 16,
* END OF t_day.
*
*DATA BEGIN OF week.
* INCLUDE TYPE t_day AS monday RENAMING WITH SUFFIX _mon.
* INCLUDE TYPE t_day AS tuesday RENAMING WITH SUFFIX _tue.
* INCLUDE TYPE t_day AS wednesday RENAMING WITH SUFFIX _wed.
*DATA END OF week.
ABAP DATA TYPES
最新推荐文章于 2024-07-15 09:56:20 发布