*定义结构ty_sales
TYPES:BEGIN OF ty_sales,
customerid(3) TYPE n,
productid(3) TYPE n,
orderid(3) TYPE n,
customername(10) TYPE c,
amount TYPE i,
END OF ty_sales.
*定义内表和工作区
DATA: it_sales TYPE STANDARD TABLE OF ty_sales WITH KEY customerid productid orderid.
DATA wa_sales TYPE ty_sales.
*添加数据
*插入数据
wa_sales-customerid = ‘001‘.
wa_sales-productid = ‘001‘.
wa_sales-orderid = ‘001‘.
wa_sales-customername = ‘Apple‘.
wa_sales-amount = 10.
APPEND wa_sales TO it_sales.
wa_sales-customerid = ‘003‘.
wa_sales-productid = ‘002‘.
wa_sales-orderid = ‘001‘.
wa_sales-customername = ‘Microsoft‘.
wa_sales-amount = 10.
APPEND wa_sales TO it_sales.
wa_sales-customerid = ‘002‘.
wa_sales-productid = ‘002‘.
wa_sales-orderid = ‘001‘.
wa_sales-customername = ‘Google‘.
wa_sales-amount = 10.
APPEND wa_sales TO it_sales.
wa_sales-customerid = ‘003‘.
wa_sales-productid = ‘001‘.
wa_sales-orderid = ‘001‘.
wa_sales-customername = ‘Google‘.
wa_sales-amount = 10.
APPEND wa_sales TO it_sales.
*将公司代码为001的订单 公司名称改为Apple2
LOOP AT it_sales INTO wa_sales WHERE customerid = ‘001‘.
wa_sales-customername = ‘Apple2‘.
MODIFY it_sales FROM wa_sales.
ENDLOOP.
*将数据输出屏幕
LOOP AT it_sales INTO wa_sales.
WRITE: / wa_sales-customerid,wa_sales-productid,wa_sales-orderid,wa_sales-customername,wa_sales-amount.
ENDLOOP.