SAP 内表一

来源:互联网 发布:路亚竿淘宝 编辑:程序博客网 时间:2024/05/13 18:39

内表是SAP极其重要的概念,合理的使用可以提高效率。也许可以和DataSet或者DataStore类比。

 

内表定义

      inner table has three types:standard table,sorted table,hash table.it can be refrenced to existent object e.g. tables or structures.

 

也可以专门为当前form定义structure,然后再由该strucuture定义内表。任何时候注意reserved word。

 

工作区 work area

 

tables 定义

with header line

 

可以定义一个结构,由此结构分别定义一个内表和一个工作区。注意这里的关键字type而不是like

DATA: IT_VBRK TYPE TABLE OF LINE WITH HEADER LINE,
           WA_VBRK TYPE LINE.

 

 

*&---------------------------------------------------------------------*
*& Report  ZTEST1
*&
*&---------------------------------------------------------------------*
*&test for inner table
*
*&
*&---------------------------------------------------------------------*

REPORT  ZTEST1.

"TABLES VBRK.

TYPES:
  BEGIN OF LINE,
    VBELN TYPE VBRK-VBELN,
    FKDAT TYPE VBRK-FKDAT,
  END OF LINE.

"Inner table IT_VBRK has no header line,has one work area instead
"the definiton keyword here must be type not like
  DATA: IT_VBRK TYPE TABLE OF LINE WITH HEADER LINE,
        WA_VBRK TYPE LINE.

  "SELECT * FROM VBRK INTO CORRESPONDING FIELDS OF TABLE IT_VBRK UP TO 100 ROWS.

"When you  not specify the keyword table then it_vbrk will be treat as one work area
"after the keyword table ,it_vbrk treated as inner table - the right way
"if specify the column list then into table [inner table]
"if use * then into corresponding fields of table [inner table]
SELECT VBELN FKDAT FROM VBRK INTO TABLE IT_VBRK UP TO 100 ROWS.

 "LOOP AT IT_VBRK INTO WA_VBRK.
  " WRITE: / WA_VBRK-VBELN,WA_VBRK-FKDAT.
   "WRITE: / IT_VBRK-VBELN,IT_VBRK-FKDAT.
   "WRITE: / SY-INDEX.
 "ENDLOOP.
 
 " if not specify the workared explicitly  use headline instead
  LOOP AT IT_VBRK .
     WRITE: / IT_VBRK-VBELN,IT_VBRK-FKDAT.
   "WRITE: / SY-INDEX.
 ENDLOOP.

原创粉丝点击