课件说明sap培训全ibm tables_第1页
课件说明sap培训全ibm tables_第2页
课件说明sap培训全ibm tables_第3页
课件说明sap培训全ibm tables_第4页
课件说明sap培训全ibm tables_第5页
已阅读5页,还剩38页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Data Structure & Internal Tables | 3.07March-2005Data structures and Internal tables2March-2005Data Structure & Internal Tables | 3.07ObjectivesThe participants will be able to: Create a Structure in an ABAP Program Create an Internal Table in an ABAP program Populate an Internal Table with data Rea

2、d Database information into an Internal Table3March-2005Data Structure & Internal Tables | 3.07Address ListStructureData StructuresAddress ListInternal TableLNFNCityST.LNFNCityST.LNFNCityST.LNFNCityST.4March-2005Data Structure & Internal Tables | 3.07Declaring a Structure - Method #1 1REPORT YN1C000

3、8. 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 14 ADDRESS- CITY.15WRITE ADDRESS.1617Basic Syntax:DATA: BEGIN OF

4、. . . . . . . . . END OF . FlagID Name1 CityAddress StructureIs this statement necessary for the code?5March-2005Data Structure & Internal Tables | 3.07REPORT Yxxxxxxx.TYPES: BEGIN OF ADDR,FLAG,IDLIKE EMPLOYEE-ID,NAME1LIKE EMPLOYEE-NAME1,CITYLIKE EMPLOYEE-CITY, END OF ADDR.DATA: ADDRESS TYPE ADDR.MO

5、VE: X TO ADDRESS-FLAG,00001 TO ADDRESS-ID,Smith TO ADDRESS-NAME1,Philadelphia TO ADDRESS-CITY.WRITE ADDRESS.Declaring a Structure - Method #2Basic Syntax:TYPES: BEGIN OF , . . . , . . . , . . . , END OF .DATA: TYPE . FlagID Name1 CityAddress Structure6March-2005Data Structure & Internal Tables | 3.0

6、7Populating a Structure with Field-by-Field TransportREPORT Y170DM37.TABLES: EMPLOYEE.DATA: BEGIN OF ADDRESS, FLAG, ID LIKE EMPLOYEE-ID, NAME LIKE EMPLOYEE-NAME1, CITY LIKE EMPLOYEE-CITY, END OF ADDRESS.SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO ADDRESS. WRITE: / ADDRESS-FLAG, ADDRESS-ID

7、, ADDRESS-NAME, ADDRESS-CITY. CLEAR ADDRESS.ENDSELECT.EMPLOYEEAddressID Name1 City000000001 Electronics Inc. Waldorf MOVE-CORRESPONDING EMPLOYEE TO ADDRESS.Flag ID Name City000000001 WaldorfClear .7March-2005Data Structure & Internal Tables | 3.07DemonstrationDeclaring a structure and populating the

8、 structure with values inside a program.8March-2005Data Structure & Internal Tables | 3.07PracticeDeclaring a structure and populating the structure with values inside a program.9March-2005Data Structure & Internal Tables | 3.07Internal Table TypesStandardSortedHashed10March-2005Data Structure & Int

9、ernal Tables | 3.07REPORT Y170DM38.TABLES: EMPLOYEE.TYPES: BEGIN OF EMP,ID LIKE EMPLOYEE-ID,NAME1 LIKE 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 EMPLOYEE TO EMPTAB. APP

10、END EMPTAB.ENDSELECT.The TYPES statement defines the structure and data type for the internal table.The DATA statement with an INITIAL SIZE creates the actual internal table capable of storing data. Because of the WITH HEADER LINE addition, this internal table is created with a header line.Header Li

11、ne ID NAME1 COUNTRYCreating an Internal Table with Header Line11March-2005Data Structure & Internal Tables | 3.07Internal Table KeysImplicit KeyAll character fieldsExplicit KeyUser-definede.g. WITH UNIQUE/NON-UNIQUE KEY FIELD1 FIELD2 .12March-2005Data Structure & Internal Tables | 3.07Size of an Int

12、ernal Table13March-2005Data Structure & Internal Tables | 3.07APPEND SORTED BY .APPEND .Department Salary123456Department SalaryHeaderLoading an Internal Table with a Header LineR&D400,000PROD 7,800,000MKTG 1,000,000SALES 500,000HR 140,000IT 50,000R&D400,000MKTG 1,000,000SALES 500,000PROD 7,800,000I

13、T 50,000HR 140,00014March-2005Data Structure & Internal Tables | 3.07REPORT Y170DM42.TABLES: EMPLOYEE.TYPES: BEGIN OF EMP,COUNTRYLIKE EMPLOYEE-COUNTRY,IDLIKE EMPLOYEE-ID,SALARYLIKE EMPLOYEE-SALARY, END OF EMP.DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE.SELECT * FROM EMPL

14、OYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB SORTED BY SALARY.ENDSELECT.Loading an Internal Table with a Header LineMore than ten entries can be saved in the internal table.A maximum of ten entries can be saved in the internal table

15、. Any entries that exceed the top ten will be deleted.With both versions of the APPEND statement, memory space for ten records is allocated when the first record is written to the internal table.Example 1Example 2OR15March-2005Data Structure & Internal Tables | 3.07Internal Table with Header Line EM

16、PLOYEE COUNTRY ID FORMA NAME1 SORTL . . . ID NAME1COUNTRYHeader LineAB16March-2005Data Structure & Internal Tables | 3.07Internal Table with Header Line ID NAME1 COUNTRYEMPLOYEEUSA00000001CompanyBaker DistributorsBAKER. . . COUNTRY ID FORMA NAME1 SORTL . . .Header Line117March-2005Data Structure & I

17、nternal Tables | 3.07Internal Table with Header Line ID NAME1 COUNTRY00000001 Baker Distributors USAEMPLOYEEHeader Line21USA00000001CompanyBaker DistributorsBAKER. . . COUNTRY ID FORMA NAME1 SORTL . . .18March-2005Data Structure & Internal Tables | 3.07Internal Table with Header Line USA 00000001 Co

18、mpany Baker Distributors BAKER . . . ID NAME1 COUNTRY00000001Baker DistributorsUSA00000001 Baker DistributorsUSAEMPLOYEE COUNTRY ID FORMA NAME1 SORTL . . .Header Line2312310.This header line is attached to the body of the internal table.119March-2005Data Structure & Internal Tables | 3.07Internal Ta

19、ble with Header Line ID NAME1 COUNTRY00000001 Baker Distributors USA00000002 Diversified Indust.USA00000002 Diversified Indust. USAUSA 00000002 Company Diversified Indust. DIVERS . . .EMPLOYEE COUNTRY ID FORMA NAME1 SORTL . . .Header Line5612310.420March-2005Data Structure & Internal Tables | 3.07Cr

20、eating an Internal Table without a Header LineREPORT 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-CORRESPONDI

21、NG EMPLOYEE TO EMPTAB_WA. APPEND EMPTAB_WA TO EMPTAB.ENDSELECT. ID NAME1 COUNTRYAPPEND to .The TYPES statement defines the structure and data type for the internal table and its work areaWork AreaThe DATA statement with an INITIAL SIZE creates the actual internal table without a header line. The DAT

22、A statement without the INITIAL SIZE creates the work area for the internal table.21March-2005Data Structure & Internal Tables | 3.07Separate Internal Table Work AreaPerformance IssuesNested Internal TablesInternal Table without a Header Line WHY?22March-2005Data Structure & Internal Tables | 3.07In

23、ternal Table without a Header LineEMPLOYEE COUNTRY ID FORMA NAME1 SORTL . . .Work AreaAB ID NAME1 COUNTRY23March-2005Data Structure & Internal Tables | 3.07Internal Table without a Header Line ID NAME1 COUNTRY ID NAME1COUNTRY 00000001 Baker Distributors USA00000001 Baker Distributors USA USA 0000000

24、1 Company Baker Distributors BAKER . . .EMPLOYEE COUNTRY ID FORMA NAME1 SORT . . .Work Area12312310.This work area is not attached to the body of the internal table.24March-2005Data Structure & Internal Tables | 3.07Transferring ABAP Dictionary Table StructuresREPORT Y170DM41.TABLES: EMPLOYEE.DATA:

25、EMPTAB LIKE STANDARD TABLE OF EMPLOYEE INITIAL SIZE 10 WITH HEADER LINE.SELECT * FROM EMPLOYEE. MOVE EMPLOYEE TO EMPTAB. APPEND EMPTAB.ENDSELECT.The internal table EMPTAB will have the exact same structure as the dictionary table EMPLOYEE.Notice the MOVE statement instead of a MOVE-CORRESPONDING.25M

26、arch-2005Data Structure & Internal Tables | 3.07Automatic Field Conversion MOVE-CORRESPONDING or MOVE field to field Individual field type conversion MOVE Structure to structure Field to structure Structure to field Intermediate C type Followed by adoption of new types26March-2005Data Structure & In

27、ternal Tables | 3.07Mass Reading from Database Tables into Internal TablesREPORT Y170DM69.TABLES: EMPLOYEE.DATA: EMPTAB LIKE STANDARD TABLE EMPLOYEE INITIAL SIZE 10 WITH HEADER LINE.SELECT * FROM EMPLOYEE INTO TABLE EMPTAB WHERE COUNTRY = USA.SELECT * FROM . . .1. INTO TABLE .2. APPENDING TABLE .Not

28、ice no ENDSELECT is needed here because no loop processing occurs.27March-2005Data Structure & Internal Tables | 3.07Processing an Internal TableREPORT Y170DM45.TABLES: EMPLOYEE.TYPES: BEGIN OF EMP,COUNTRYLIKE EMPLOYEE-COUNTRY,NAME1LIKE EMPLOYEE-NAME1,SALESLIKE EMPLOYEE-SALES, END OF EMP.DATA: EMPTA

29、B TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE.SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB.ENDSELECT.LOOP AT EMPTAB WHERE COUNTRY BETWEEN A AND D. WRITE: / EMPTAB-COUNTRY, EMPTAB-NAME1, EMPTAB-SALES.ENDLOOP.IF SY-SUBRC NE 0. WRITE: / NO ENTRIES. ENDIF.

30、This LOOP AT statement allows for a logical expression in a WHERE clause to limit the processing of the internal table.If no internal table entries qualify under the logical expression, the statement within the loop is not executed and SY-SUBRC is set to 4.28March-2005Data Structure & Internal Table

31、s | 3.07System Field SY-TABIXREPORT Y170DM46.TABLES: EMPLOYEE.TYPES: BEGIN OF EMP,COUNTRYLIKE EMPLOYEE-COUNTRY,NAME1LIKE EMPLOYEE-NAME1, END OF EMP.DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE.PARAMETERS:START LIKE SY-TABIX DEFAULT 10,END LIKE SY-TABIX DEFAULT 20.SELECT *

32、 FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB.ENDSELECT.LOOP AT EMPTAB FROM START TO END. WRITE: / SY-TABIX, EMPTAB-COUNTRY, EMPTAB-NAME1.ENDLOOP.Screen outputSY-TABIX29March-2005Data Structure & Internal Tables | 3.07Accumulating Data within an Internal TableREPORT Y170DM43.T

33、ABLES: EMPLOYEE.TYPES: BEGIN OF EMP,COUNTRYLIKE EMPLOYEE-COUNTRY,SALESLIKE EMPLOYEE-SALES, END OF EMP.DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE.SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. COLLECT EMPTAB.ENDSELECT.LOOP AT EMPTAB. WRITE: / EMPTAB-COUNT

34、RY, EMPTAB-SALES.ENDLOOP.COLLECT .CountrySalesD400,000USA1,000,000GB500,000D7,800,000Header LineA371,065.00CH 45,305.00D 8,200,000.00F 0.00GB500,000.00NL577,000.00NO 234.00USA 1,000,000.00HK0.00Screen output30March-2005Data Structure & Internal Tables | 3.07Sorting an Internal TableREPORT Y170DM44.T

35、ABLES: EMPLOYEE.TYPES: BEGIN OF EMP,COUNTRYLIKE EMPLOYEE-COUNTRY,NAME1LIKE EMPLOYEE-NAME1,SALESLIKE EMPLOYEE-SALES, 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.ENDSELECT.SORT EMPTAB B

36、Y SALES DESCENDING.LOOP AT EMPTAB. WRITE: / ITAB-COUNTRY, ITAB-NAME1, ITAB-SALES.ENDLOOP.Sorting options:1)SORT - sorts the entries of the internal table in ascending order.2) SORT BY - sorts the table on one or more fields within the table.screen output31March-2005Data Structure & Internal Tables |

37、 3.07Control Level ProcessingAT FIRSTAT NEW AT END AT LAST32March-2005Data Structure & Internal Tables | 3.07REPORT Y170DM47.TABLES: EMPLOYEE.TYPES: BEGIN OF EMP, COUNTRY LIKE EMPLOYEE-COUNTRY, NAME1 LIKE EMPLOYEE-NAME1, END OF EMPTAB.DATA:EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADE

38、R LINE.SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB.ENDSELECT.READ TABLE .Reading a Single Table Entry33March-2005Data Structure & Internal Tables | 3.07Reading a Single Table Entry - OptionsREAD TABLE options:1) READ TABLE .2) READ TABLE WITH KEY = = .3) READ TABLE W

39、ITH TABLE KEY = . = .4) READ TABLE WITH KEY = .5) READ TABLE WITH KEY . . . BINARY SEARCH.6) READ TABLE INDEX .7) READ TABLE COMPARING . . . .8) READ TABLE COMPARING ALL FIELDS.9) READ TABLE TRANSPORTING . . . .10) READ TABLE TRANSPORTING NO FIELDS.34March-2005Data Structure & Internal Tables | 3.07

40、Maintaining Internal TablesSELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB.ENDSELECT.READ TABLE EMPTAB INDEX 1.MOVE ABC TO EMPTAB-NAME1.MODIFY EMPTAB INDEX SY-TABIX.IF SY-SUBRC NE 0.WRITE / Attempt to modify failed.ELSE.WRITE: / EMPTAB-COUNTRY, EMPTAB-NAME1.ENDIF.INSERT

41、EMPTAB INDEX 1.DELETE EMPTAB INDEX SY-TABIX.INSERT INDEX .MODIFY INDEX .DELETE INDEX .Check SY-SUBRC after every attempt to change an internal table entry. 35March-2005Data Structure & Internal Tables | 3.07Working with an Internal Table without a Header LineAPPEND TO .COLLECT INTO .INSERT INTO .MOD

42、IFY FROM .READ TABLE INTO .LOOP AT INTO .36March-2005Data Structure & Internal Tables | 3.07Deleting an Internal TableCLEAR Initialises the header line.Internal table lines remain unchanged.REFRESH Deletes all table lines.Storage space is not released.Paging is released.Header line remains unchanged

43、.FREE Deletes all table lines.Storage space is released.Header line remains unchanged37March-2005Data Structure & Internal Tables | 3.07Information about an Internal TableREPORT Y170DM49.TABLES: EMPLOYEE.TYPES: BEGIN OF EMP,COUNTRYLIKE EMPLOYEE-COUNTRY,NAME1LIKE EMPLOYEE-NAME1, END OF EMP.DATA:EMPTA

44、B TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE,LINE_COUNT TYPE I,INITIAL_COUNT TYPE I.SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB.ENDSELECT.DESCRIBE TABLE EMPTABLINES LINE_COUNTOCCURS INITIAL_COUNT.WRITE: / lines:, LINE_COUNT, / occurs:, INITIAL SIZE_C

45、OUNT. DESCRIBE TABLE LINES OCCURS .screen output38March-2005Data Structure & Internal Tables | 3.07REPORT Y170DM50.TABLES: EMPLOYEE.TYPES: BEGIN OF EMP,COUNTRYLIKE EMPLOYEE-COUNTRY,NAME1LIKE EMPLOYEE-NAME1,END OF EMP,DATA:EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE,SELECT * FR

46、OM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB.ENDSELECT.EDITOR-CALL FOR EMPTAB.CHECK SY-SUBRC EQ 0.LOOP AT EMPTAB WHERE NAME1 EQ Maurice Cheeks.WRITE: / EMPTAB-COUNTRY, EMPTAB-NAME1.ENDLOOP.IF SY-SUBRC NE 0. WRITE: / No records. ENDIF.Calling the SAP Table Editorscreen output39March-2005Data Structure & Internal Tables | 3.07DemonstrationDecla

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论