ABAP DATA TYPES

*&---------------------------------------------------------------------*
*& 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(10TYPE c,
       text20(20TYPE c,
       result(8TYPE 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.
 TYPEStype 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.
TYPESBEGIN OF street_type,
         streetname TYPE c LENGTH 40,
         no   TYPE c LENGTH 4,
       END OF street_type.

TYPESBEGIN OF city,
          zipcode TYPE n LENGTH 5,
          cityname    TYPE c LENGTH 40,
         END OF city.

TYPES BEGIN OF address_type.
TYPES:name1(10TYPE 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值