《11.ABAP数据结构.ppt》由会员分享,可在线阅读,更多相关《11.ABAP数据结构.ppt(33页珍藏版)》请在第壹文秘上搜索。
1、Address ListAddress ListAddress ListAddress List 1REPORT YN1C0008. 2 3TABLES: TABNA. 4DATA:BEGIN OF ADDRESS, 5FLAGTYPE C, 6IDLIKE TABNA-ID, 7NAME1LIKE TABNA-NAME1, 8CITYLIKE TABNA-CITY, 9END OF ADDRESS.10MOVEXTO ADDRESS-FLAG.11MOVE0001TO ADDRESS-ID.12MOVESmithTO ADDRESS-NAME1.13MOVEPhiladelphia TO A
2、DDRESS-CITY.1415WRITE ADDRESS.1617181920212223基本语法基本语法:DATA: BEGIN OF DATA: BEGIN OF . . . 1 . . . . . . 2 . . . . . . . . . END OF END OF . . FlagFlagID ID Name1 Name1 City CityAddress Address 结构结构REPORT Yxxxxxxx.TYPES: BEGIN OF ADDR,FLAG,IDLIKE EMPLOYEE-ID,NAME1LIKE EMPLOYEE-NAME1,CITYLIKE EMPLOYE
3、E-CITY, END OF ADDR.DATA: ADDRESS TYPE ADDR.MOVE: X TO ADDRESS-FLAG,00001 TO ADDRESS-ID,Smith TO ADDRESS-NAME1,Philadelphia TO ADDRESS-CITY.WRITE ADDRESS.基本语法基本语法:TYPES: BEGIN OF TYPES: BEGIN OF ,1, . . . ,1 . . . , . . . ,2 . . . , . . . , . . . , END OF END OF .1.DATA: DATA: TYPE 2 TYPE .1. FlagID
4、 Name1 CityAddress 结构结构REPORT Y170DM37.TABLES: EMPLOYEE.DATA: BEGIN OF ADDRESS,FLAG,IDLIKE EMPLOYEE-ID,NAMELIKE EMPLOYEE-NAME1,CITYLIKE EMPLOYEE-CITY, END OF ADDRESS.SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO ADDRESS. WRITE: / ADDRESS-FLAG, ADDRESS-ID, ADDRESS-NAME, ADDRESS-CITY. CLEAR A
5、DDRESS.ENDSELECT.EMPLOYEEEMPLOYEEAddressAddressID ID Name1 Name1 City City000000001 Electronics Inc. Waldorf 000000001 Electronics Inc. Waldorf MOVE-CORRESPONDING EMPLOYEE MOVE-CORRESPONDING EMPLOYEE TO ADDRESS. TO ADDRESS.FlagFlag ID ID Name Name City City000000001000000001 Waldorf WaldorfClear .Cl
6、ear . 标准内表标准内表 排序内表排序内表 HashedHashed内表内表REPORT Y170DM38.TABLES: EMPLOYEE.TYPES: BEGIN OF EMP,IDLIKE EMPLOYEE-ID,NAME1LIKE EMPLOYEE-NAME1,COUNTRY LIKE EMPLOYEE-COUNTRY, END OF EMP.DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE.SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLO
7、YEE TO EMPTAB. APPEND EMPTAB.ENDSELECT.TYPES TYPES 语句定义内表的结构和数语句定义内表的结构和数据类型据类型INITIAL SIZE INITIAL SIZE 语句指定了内表的存语句指定了内表的存储数量储数量, HEADER LINE , HEADER LINE 语句指定内语句指定内表带有一个标题行表带有一个标题行标题行标题行 ID NAME1 COUNTRYID NAME1 COUNTRY 默认关键字默认关键字所有的字符类型所有的字符类型 指定关键字指定关键字用户指定用户指定例如例如. . WITH UNIQUE/NON-UNIQUE KEY
8、 WITH UNIQUE/NON-UNIQUE KEY 字段字段1 1 字段字段2 .2 .APPEND APPEND SORTED BY SORTED BY . .APPEND APPEND . .DepartmentDepartment Salary Salary1 12 23 34 45 56 6DepartmentDepartment Salary Salary标题行标题行R&D 400,000R&D 400,000PROD PROD 7,800,0007,800,000MKTG MKTG 1,000,0001,000,000SALES SALES 500,000500,000HR H
9、R 140,000140,000IT IT 50,00050,000R&D 400,000R&D 400,000MKTG 1,000,000MKTG 1,000,000SALES 500,000SALES 500,000PROD 7,800,000PROD 7,800,000IT 50,000IT 50,000HR 140,000HR 140,000REPORT Y170DM42.TABLES: EMPLOYEE.TYPES: BEGIN OF EMP,COUNTRY LIKE EMPLOYEE-COUNTRY,IDLIKE EMPLOYEE-ID,SALARYLIKE EMPLOYEE-SA
10、LARY, END OF EMP.DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE.SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB SORTED BY SALARY.ENDSELECT.多于多于10 10条的记录也可以保存条的记录也可以保存多于多于10 10条的记录将被删除条的记录将被删除
11、两种两种 APPENDAPPEND语句的表达方式语句的表达方式,最最初都会分配初都会分配10 10条记录的存储空条记录的存储空间间Example 1Example 1Example 2Example 2 COUNTRY ID FORMA NAME1 SORTL . . .COUNTRY ID FORMA NAME1 SORTL . . . ID NAME1 COUNTRYID NAME1 COUNTRY标题行标题行A AB B ID NAME1ID NAME1 COUNTRY COUNTRYUSAUSA0000000100000001CompanyCompanyBaker Distributo
12、rsBaker DistributorsBAKERBAKER. . . . . COUNTRY ID FORMA NAME1 SORTL . . .COUNTRY ID FORMA NAME1 SORTL . . .标题行标题行1 1 ID NAME1ID NAME1 COUNTRY COUNTRY00000001 Baker Distributors USA00000001 Baker Distributors USA 标题行标题行2 21 1USAUSA0000000100000001CompanyCompanyBaker DistributorsBaker DistributorsBAK
13、ERBAKER. . . . . COUNTRY ID FORMA NAME1 SORTL . . .COUNTRY ID FORMA NAME1 SORTL . . . USA 00000001 Company Baker Distributors BAKER . . .USA 00000001 Company Baker Distributors BAKER . . . ID NAME1ID NAME1 COUNTRY COUNTRY0000000100000001Baker DistributorsBaker DistributorsUSAUSA0000000100000001Baker
14、 DistributorsBaker DistributorsUSAUSA COUNTRY ID FORMA NAME1 SORTL . . .COUNTRY ID FORMA NAME1 SORTL . . .标题行标题行2 23 31 12 23 310 10.标题行的数据标题行的数据被赋给内表中被赋给内表中的记录的记录1 1 ID NAME1ID NAME1 COUNTRY COUNTRY0000000100000001 Baker Distributors Baker Distributors USA USA00000002 00000002 Diversified Indust.Di
15、versified Indust.USAUSA0000000200000002 Diversified Indust. Diversified Indust. USA USAUSA USA 00000002 Company Diversified Indust. 00000002 Company Diversified Indust. DIVERS . . . DIVERS . . . COUNTRY ID FORMA NAME1 SORTL . . .COUNTRY ID FORMA NAME1 SORTL . . .Header LineHeader Line5 56 61 12 23 3
16、10 10.4 4REPORT Y170DM40.TABLES: EMPLOYEE.TYPES: BEGIN OF EMP,IDLIKE EMPLOYEE-ID,NAME1LIKE EMPLOYEE-NAME1,COUNTRYLIKE EMPLOYEE-COUNTRY, END OF EMP.DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10, EMPTAB_WA TYPE EMP.SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB_WA. APPEND EMPTAB_WA TO EMPTAB.ENDSELECT. ID NAME1 COUNTRYID NAME1 COUNTRYAPPEND to .APPEND to .TYPESTYPES语句为内表和它的工作区语句为内表和它的工作区域定义了结构和数据类型域定义了结构和数据类型工作区域工作区域 DATA DATA语句定义了一个内表和一语句定义了一个内表和一个工作区域个工作区域分离内表工作区域分离内表工作区