ABAP基础之结构与内表
定义结构
1 | DATA: GS_1 TYPE ZTPX001. TABLES: ZTPX001. DATA: BEGIN OF GS_2, ZNUMBER LIKE ZTPX001-ZNUMBER, ZNAME LIKE ZTPX001-ZNAME, END OF GS_2. DATA: BEGIN OF GS_3. DATA: ZX TYPE C. INCLUDE STRUCTURE ZVPX001. DATA: END OF GS_3. |
定义内表
1 | DATA: GT_1 LIKE GS_1 OCCURS 0 WITH HEADER LINE. DATA: GT_2 TYPE ZTPX001 OCCURS 0 WITH HEADER LINE. DATA: BEGIN OF GT_3 OCCURS 0, ZNUMBER LIKE ZTPX001-ZNUMBER, ZNAME LIKE ZTPX001-ZNAME, END OF GT_3. DATA: BEGIN OF GT_4 OCCURS 0. DATA: ZX TYPE C. INCLUDE STRUCTURE ZTPX001. DATA: END OF GT_4. |
操作内表一条记录
1 | DATA: WA LIKE GS_1. DATA: ITAB LIKE GS_1 OCCURS 0 WITH HEADER LINE. DATA: ITAB2 LIKE GS_1 OCCURS 0 WITH HEADER LINE. WA-ZNAME = 'Joe'. APPEND WA TO ITAB. CLEAR WA. WA-ZNAME = 'Jake'. INSERT WA INTO ITAB INDEX 1. CLEAR WA. READ TABLE ITAB INTO WA INDEX 2. CLEAR WA. WA-ZNAME = 'Tom'. MODIFY ITAB FROM WA INDEX 2. DELETE ITAB INDEX 1. |
操作内表多条记录
1 | LOOP AT ITAB INTO WA WHERE ZNAME = 'Tom'. WRITE: WA-ZNAME. ENDLOOP. INSERT LINES OF ITAB WHERE INTO ITAB2. DELETE ITAB WHERE ZNAME = 'Jake'. REFRESH ITAB. |
赋值
1 | 结构名-字段 = 值. MOVE 变量1 TO 变量2 MOVE-CORRESPONDING 结构1 TO 结构2 |