根椐程序中实际的需要,内表有很多不同的定义及使用方式,下面对几种常见方式一一举例说明。

1.使用TYPE叙述(定义类型)
TYPES <t> <type> OCCURS <n>
  宣告一个阵列<t>,型态为<type>,长度为<n>
         Example:
                  TYPES A TYPE I OCCURS 10.
                  A是个10个元素的数值Internal Table
         Example:
                  TYPES: BEGIN OF LINE,
                         COL1 TYPE I,
                         COL3 TYPE I,
                         END OF LINE.
                  TYPES ITAB TYPE LINE OCCURS 10.
                 宣告一个Internal Table ITAB,总共有10个元素,其WORK AREA名称
                 为LINE
2.使用DATA叙述(定义变量)
若使用DATA叙述来宣告Internal Table,可分成要不要有HEADER LINE, HEADER LINE就是所谓的WORK AREA,用在资料的存取上.
DATA <f> <type> OCCURS <n> [WITH HEADER LINE]
3.直接宣告,不使用WORK AREA
DATA: BEGIN OF <f> OCCURS <n>,
              <component宣告>
            END OF <f>.
4.其它定义方法
(1) DATA : itab1 TYPE HASHED TABLE OF i WITH UNIQUE KEY table_line.
(2) DATA: ftab2 TYPE SORTED TABLE OF f WITH NON-UNIQUE KEY table_line.
注:In internal tables it is possible to address the complete table line in a key specification by using the pseudo component TABLE_LINE. This is useful especially for tables whose line type has no structure.eg:
DATA: BEGIN OF line,
          col1 TYPE i,
          col2 TYPE i,
       END OF line.
DATA itab LIKE SORTED TABLE OF line WITH UNIQUE KEY table_line.
   (3) DATA: BEGIN OF line,
         land(3) TYPE c,
         name(10) TYPE c,
         age TYPE i,
         weight TYPE p DECIMALS 2,
        END OF line.
DATA itab LIKE STANDARD TABLE OF line WITH NON-UNIQUE KEY land.
(3) DATA mytab1 LIKE STANDARD TABLE OF MARA WITH HEADER LINE.
DATA mytab2 LIKE MARA OCCURS 10 WITH HEADER LINE.
同样定义一个带表头行的内表,但mytab1是经过排序的,执行效率要高于mytab2
(4) DATA : itab LIKE STANDARD TABLE OF SPFLI,
  Wa LIKE LINE OF ITAB.

5. SELECT中内表的动态指定
   SELECT * INTO CORRESPONDING FIELDS OF TABLE itab
   FROM (g_tabname)
WHERE aufnr IN t_aufnr AND arbpl IN t_arbpl AND vbeln IN t_vbeln.

1. Standard tables have an internal linear index. The system can access records either by using the table index or the key. The response time for key access is proportional to the number of entries in the table. The key of a standard table is always non-unique.
2. Sorted tables are always saved sorted by the key. The system can access records either by using the table index or the key. The response time for key access is logarithmically proportional to the number of table entries, since the system uses a binary search .
Standard tables and sorted tables are known generically as index tables.
3. Hashed tables have no linear index. You can only access a hashed table using its key. The response time is independent of the number of table entries, and is constant, since the system access the table entries using a hash algorithm. The key of a hashed table must be unique. When you define the table, you must specify the key as UNIQUE.
posted on 2008-12-05 09:59  hyladmin  阅读(441)  评论(0)    收藏  举报