*types: begin of ty_stu,
- no(11) type c,
- name(20) type c,
- sex(10) type c,
- age type i,
- end of ty_stu.
- data:gt_itab type table of ty_stu,
wa_itab type ty_stu.
- wa_itab-no = '45679'.
- wa_itab-name = '张三'.
- wa_itab-sex = '女'.
- wa_itab-age = '18'.
- APPEND wa_itab to gt_itab.
- wa_itab-no = '42549'.
- wa_itab-name = '三合会'.
- wa_itab-sex = '女'.
- wa_itab-age = '19'.
- APPEND wa_itab to gt_itab.
- LOOP at gt_itab into wa_itab.
- WRITE:/ wa_itab-no,wa_itab-name,wa_itab-sex,wa_itab-age.
- ENDLOOP.
*先用types语句创建内表用到的数据类型
*再根据类型创建数据对象(内表)
*types:begin of ty_book,
- isbn(20) type c,
- bookname(20) type c,
- author(15) type c,
- publish(20) type c,
- price type p DECIMALS 2,
- END OF ty_book.
**ty_book是一个数据,gt_book是内表,可以存放多个ty_book结构的数据,内表是二维的。wa_book是工作区,可以1个ty_book结构的数据,工作区是二维的。
- data:gt_book TYPE TABLE OF ty_book,
wa_book type ty_book.
- wa_book-isbn = '9787508651040'.
- wa_book-bookname = 'Java程序设计'.
- wa_book-author = '谢膺白'.
- wa_book-publish = '清华大学出版社'.
- wa_book-price = '35.00'.
- APPEND wa_book to gt_book.
- wa_book-isbn = '9787508651040'.
- wa_book-bookname = '数据结构'.
- wa_book-author = '郑阿奇'.
- wa_book-publish = '电子工业出版社'.
- wa_book-price = '36.00'.
- APPEND wa_book to gt_book.
- wa_book-isbn = '9787508651040'.
- wa_book-bookname = 'C语言程序设计'.
- wa_book-author = '陈建医'.
- wa_book-publish = '清华大学出版社'.
- wa_book-price = '45.00'.
- APPEND wa_book to gt_book.
- wa_book-isbn = '9787508651040'.
- wa_book-bookname = '数据库设计原理与应用'.
- wa_book-author = '陈浩'.
- wa_book-publish = '清华大学出版社'.
- wa_book-price = '38.00'.
- APPEND wa_book to gt_book.
**向内表中插入数据。
- wa_book-isbn = '9787508651040'.
- wa_book-bookname = '网页设计与制作'.
- wa_book-author = '张伟明'.
- wa_book-publish = '人民邮电出版社'.
- wa_book-price = '48.00'.
- INSERT wa_book into gt_book index 4.
**遍历表中的数据
- LOOP at gt_book into wa_book.
- WRITE:/ wa_book-isbn,wa_book-bookname,wa_book-author,wa_book-publish,wa_book-price.
- endloop.
*TABLES:MARC.
*TYPES:BEGIN OF sy_marc,
- MATNR type MARC-MATNR,
- WERKS type MARC-WERKS,
- EKGRP type MARC-EKGRP,
- BESKZ type MARC-BESKZ,
*END OF sy_marc.
*data:gt_marc TYPE TABLE OF sy_marc,
wa_marc type sy_marc.
*SELECT
- MARC~MATNR
- MARC~WERKS
- MARC~EKGRP
- MARC~BESKZ
- INTO TABLE gt_marc
- FROM MARC
- WHERE MARC~WERKS = '1000'.
- LOOP AT gt_marc into wa_marc.
- write:/ wa_marc-MATNR,wa_marc-WERKS,wa_marc-EKGRP,wa_marc-BESKZ.
- ENDLOOP.
TYPES:BEGIN OF SY_SFLIGHT,
CARRID TYPE SFLIGHT-CARRID,
CONNID TYPE SFLIGHT-CONNID,
FLDATE TYPE SFLIGHT-FLDATE,
PRICE TYPE SFLIGHT-PRICE,
PLANETYPE TYPE SFLIGHT-PLANETYPE,
CURRENCY TYPE SFLIGHT-CURRENCY,
END OF SY_SFLIGHT.
DATA:GT_SFLIGHT TYPE TABLE OF SY_SFLIGHT,
WA_SFLIGHT TYPE SY_SFLIGHT.
SELECT
SFLIGHT~CARRID
SFLIGHT~CONNID
SFLIGHT~FLDATE
SFLIGHT~PRICE
SFLIGHT~PLANETYPE
SFLIGHT~CURRENCY
INTO TABLE GT_SFLIGHT
FROM SFLIGHT
WHERE SFLIGHT~CARRID = 'LH'.
LOOP AT GT_SFLIGHT INTO WA_SFLIGHT.
WRITE:/ WA_SFLIGHT-CARRID,WA_SFLIGHT-CONNID,WA_SFLIGHT-FLDATE,WA_SFLIGHT-PRICE,WA_SFLIGHT-PLANETYPE,WA_SFLIGHT-CURRENCY.
ENDLOOP.
*多表查询
TYPES:BEGIN OF SY_SFLIGHT_S_SPFLI,
CARRID TYPE SFLIGHT-CARRID,"航线代码
CONNID TYPE SFLIGHT-CONNID,"航班ID
FLDATE TYPE SFLIGHT-FLDATE,"航班日期
PRICE TYPE SFLIGHT-PRICE,"航空运费
PLANETYPE TYPE SFLIGHT-PLANETYPE,"飞机类型
CITYFROM TYPE SPFLI-CITYFROM,"(起飞城市)
CITYTO TYPE SPFLI-CITYTO,"(目标城市)
FLTIME TYPE SPFLI-FLTIME,"(航班时间)
END OF SY_SFLIGHT_S_SPFLI.
DATA:GT_SFLIGHT TYPE TABLE OF SY_SFLIGHT_S_SPFLI,
WA_SFLIGHT TYPE SY_SFLIGHT_S_SPFLI.
SELECT
SFLIGHT~CARRID
SFLIGHT~CONNID
SFLIGHT~FLDATE
SFLIGHT~PRICE
SFLIGHT~PLANETYPE
SPFLI~CITYFROM
SPFLI~CITYTO
SPFLI~FLTIME
FROM SFLIGHT INNER JOIN SPFLI ON SFLIGHT~CONNID = SPFLI~CONNID INTO CORRESPONDING FIELDS OF TABLE GT_SFLIGHT
WHERE SFLIGHT~PLANETYPE = 'DC-10-10'
and SFLIGHT~FLDATE between '20190228' and '20191220'.
LOOP AT GT_SFLIGHT INTO WA_SFLIGHT.
WRITE:/ WA_SFLIGHT-CARRID,WA_SFLIGHT-CONNID,WA_SFLIGHT-FLDATE,WA_SFLIGHT-PRICE,
WA_SFLIGHT-PLANETYPE.
ENDLOOP.