ABAP内表和工作区操作笔记(一)

*&---------------------------------------------------------------------*
*& Report Z_CH12_TABLES
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_ch12_tables.

TABLES:zemployees.

* 传统创建内表方式
DATA: BEGIN OF itab01 OCCURS 0,

        surname  LIKE zemployees-surname,
        dob      LIKE zemployees-dob,
        forename LIKE zemployees-forename,
        title    LIKE zemployees-title,
        los      TYPE i VALUE 3,
      END OF itab01.

* 1、分割工作区域创建内表
* Create an Internal Table with Separate Work Area
TYPES: BEGIN OF line01_typ,
         "eenum    LIKE zemployees-eenum,
         surname LIKE zemployees-surname,
         "forename LIKE zemployees-forename,
         title   LIKE zemployees-title,
         "dob      LIKE zemployees-dob,
         "city     LIKE zemployees-city,
       END OF line01_typ.

TYPES itab02_typ TYPE STANDARD TABLE OF line01_typ.

** 2、包含主键类型的表,多个主键,则用逗号隔开。
*TYPES itab03_typ TYPE SORTED TABLE OF line01_typ WITH UNIQUE KEY surname.

* 3、定义内表
DATA itab02 TYPE itab02_typ WITH HEADER LINE.
DATA itab03 TYPE itab02_typ.

DATA wa_itab02 TYPE line01_typ.

* 填充内表

SELECT surname title FROM zemployees
  INTO wa_itab02.
  APPEND wa_itab02 TO itab02.

ENDSELECT.

LOOP AT itab02.
  WRITE: / itab02-surname,itab02-title.
ENDLOOP.

ULINE.

SELECT * FROM zemployees.
  MOVE zemployees-surname TO itab01-surname.
  MOVE zemployees-forename TO itab01-forename.
  APPEND itab01.
  WRITE /: itab01-surname.
ENDSELECT.