BC430 ABAP Dictionary . . PARTICIPANT HANDBOOK INSTRUCTOR-LED TRAINING . Course Version: 15 Course Duration: 3 Day(s) e-book Duration: 16 Hours 5 Minutes Material Number: 50123960 SAP Copyrights and Trademarks © 2017 SAP SE or an SAP affiliate company. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company. SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/ copyright/index.epx for additional trademark information and notices. Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors. National product specifications may vary. These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or release any functionality mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions. Typographic Conventions American English is the standard used in this handbook. The following typographic conventions are also used. This information is displayed in the instructor’s presentation Demonstration Procedure Warning or Caution Hint Related or Additional Information Facilitated Discussion User interface control Example text Window title Example text © Copyright. All rights reserved. iii iv © Copyright. All rights reserved. Contents vii Course Overview 1 Unit 1: 2 9 Lesson: Describing the ABAP Dictionary Unit 2: 10 17 23 27 32 35 39 44 53 Unit 3: 120 123 126 135 146 149 Database Tables Lesson: Creating Transparent Tables Exercise 5: Create Tables in the ABAP Dictionary Lesson: Defining Cluster Tables and Pooled Tables Unit 4: 86 91 95 109 119 Data Types in the ABAP Dictionary Lesson: Creating Domains and Data Elements Exercise 1: Create Basic Data Types Lesson: Creating Flat Structures Exercise 2: Create Simple and Nested Structures Lesson: Creating Table Types and Deep Structures Exercise 3: Create Table Types Exercise 4: Create Deep Structures Lesson: Creating Type Groups 54 67 77 85 Introduction to the ABAP Dictionary Performance During Table Access Lesson: Creating Database Table Indexes Exercise 6: Create Table Indexes Lesson: Setting Up Table Buffering Exercise 7: Set Up Table Buffering Unit 5: Input Checks Lesson: Creating Fixed Values Exercise 8: Create Fixed Values Lesson: Defining Foreign Keys to Perform Input Checks Exercise 9: Perform Input Checks to Ensure Data Consistency Lesson: Creating Text Tables Exercise 10: Create a Text Table © Copyright. All rights reserved. v 159 Unit 6: 160 Lesson: Differentiating Between Active and Inactive Dictionary Objects 165 Exercise 11: Differentiate Between Active and Inactive Dictionary Objects Lesson: Identifying Dependencies with ABAP Dictionary Objects Exercise 12: Identify Dependencies with ABAP Dictionary Objects 169 173 179 Unit 7: 180 189 194 201 209 251 252 267 271 275 279 Table Changes Lesson: Performing a Table Conversion Exercise 13: Perform a Table Conversion Lesson: Enhancing Tables Using Append Structures Exercise 14: Add Enhancements to a Table Using an Append Structure Unit 8: 210 223 227 235 240 243 vi Dictionary Object Dependencies Views and Maintenance Views Lesson: Creating Database Views Exercise 15: Create a Database View Lesson: Creating Maintenance Views Exercise 16: Create a Maintenance View Lesson: Creating View Clusters Exercise 17: Create a View Cluster Unit 9: Search Helps Lesson: Creating Search Helps Exercise 18: Create Search Helps Lesson: Applying Advanced Search Help Techniques Exercise 19: Create Collective Search Helps Exercise 20: Create Append Search Helps © Copyright. All rights reserved. Course Overview TARGET AUDIENCE This course is intended for the following audiences: ● Application Consultant ● Data Consultant ● Development Consultant ● Industry / Business Analyst Consultant ● Technology Consultant ● Developer ● System Administrator © Copyright. All rights reserved. vii viii © Copyright. All rights reserved. UNIT 1 Introduction to the ABAP Dictionary Lesson 1 Describing the ABAP Dictionary 2 UNIT OBJECTIVES ● Describe the functions of the ABAP Dictionary © Copyright. All rights reserved. 1 Unit 1 Lesson 1 Describing the ABAP Dictionary LESSON OVERVIEW This lesson provides an overview of the functional scope of the ABAP Dictionary. Business Example As a developer, you must explain the main capabilities of the ABAP Dictionary to a colleague. For this reason, you require the following knowledge: ● An overview of the functions of the ABAP Dictionary in the SAP system ● An understanding of the different ways of defining data objects and data types ● An understanding of the services provided by the ABAP Dictionary ● An understanding of the relationship between the ABAP Dictionary and the tools provided by the development and runtime environment LESSON OBJECTIVES After completing this lesson, you will be able to: ● Describe the functions of the ABAP Dictionary Functional Overview of the ABAP Dictionary Figure 1: Function of the ABAP Dictionary 2 © Copyright. All rights reserved. Lesson: Describing the ABAP Dictionary The ABAP Dictionary enables all the type definitions used in the SAP system to be managed centrally. In the ABAP Dictionary, you can perform the following activities: ● Create user-defined types, such as data elements, structures, and table types, for use in ABAP programs or in interfaces of function modules, object methods, and so on. ● Create the database objects such as tables, indexes, and views in the ABAP Dictionary. ● Provides a number of services that support program development. For example, the ABAP Dictionary supports setting and releasing locks, defining an input help (F4 help), and attaching a field help (F1 help) to a screen field. Database Objects in the ABAP Dictionary Figure 2: Database Objects in the ABAP Dictionary In the ABAP Dictionary, you can perform the following functions: ● Define the tables and database views. The system creates these tables and views in the underlying database with the definition in ABAP Dictionary. Changes to the definition of a table or database view are also automatically made in the database. ● Define indexes in the ABAP Dictionary to speed up access to data in a table. The system also creates these indexes in the database when the table is activated. © Copyright. All rights reserved. 3 Unit 1: Introduction to the ABAP Dictionary Type Definitions in the ABAP Dictionary Figure 3: Type Definitions in the ABAP Dictionary Different type categories in the ABAP Dictionary are as follows: ● Data elements Data elements describe an elementary type by defining the data type, length, and decimal places. ● Structures Structures consist of components that can have any type. ● Table types Table types describe the structure of an internal table. Any complex user-defined type can be built from these basic types. For example, the data for an employee is stored in a structure called Employee with Name, Address, and Telephone as its components. The component Name is also a structure, with First name and Last name as its components. The First name and Last name components are elementary, since the type is defined by a data element. The type of component Address is a structure, whose components are also structures. A table type is used to define the Telephone component because an employee can have more than one telephone number. Types are used in ABAP programs at various places, for example, to define the types of interface parameters of function modules. 4 © Copyright. All rights reserved. Lesson: Describing the ABAP Dictionary Services of the ABAP Dictionary Figure 4: Services of the ABAP Dictionary The following ABAP Dictionary services support program development: ● Input helps for screen fields Input helps (F4 help) can be defined with search helps. ● Field help for screen fields Screen fields can be assigned a field help (F1 help) by creating documentation for the data element. ● Input check An input check ensures that the values entered are consistent and can be easily defined for screen fields using foreign keys. ● Set and release locks The ABAP Dictionary provides support when you set and release locks. To set and release locks, you must create lock objects in the ABAP Dictionary. The function modules for setting and releasing locks are automatically generated from these lock objects; these can then be linked into the application program. ● Data buffering Performance when accessing database data can be improved for database objects (tables, views, and so on) with data buffering. ● Logging Logging allows you to record changes to the table entries automatically. © Copyright. All rights reserved. 5 Unit 1: Introduction to the ABAP Dictionary Linking to the Development and Runtime Environment Figure 5: Linking to the Development and Runtime Environment The ABAP Dictionary is actively integrated in the development and runtime environments. Each change in the ABAP Dictionary takes immediate effect in the relevant ABAP programs and screens. The following examples explain the relationship between the ABAP Dictionary and the tools provided by the development and runtime environment: ● When a program or screen is executed, the ABAP Interpreter and the screen interpreter access the type definitions stored in the ABAP Dictionary. ● The ABAP tools and the Screen Painter use the information stored in the ABAP Dictionary to support you during program development. An example of this is the Get from Dictionary button in the Screen Painter, which you can use to place fields of a table or structure defined in the ABAP Dictionary on a screen. ● The database interface uses the information about tables or database views stored in the ABAP Dictionary to access the data of these objects. LESSON SUMMARY You should now be able to: ● 6 Describe the functions of the ABAP Dictionary © Copyright. All rights reserved. Unit 1 Learning Assessment 1. Screen fields can be assigned a field help (F1 help) by creating documentation for the data element. Determine whether this statement is true or false. X True X False 2. Which of the following type categories exist in the ABAP Dictionary? Choose the correct answers. X A Data elements X B Structures X C Indexes X D Table types 3. When creating the user interface in the _________________, fields from structures or tables defined in the Dictionary can be added to the screen using the Get from Dictionary function. Choose the correct answer. X A Function Modules X B ABAP Interpreter X C Screen Painter © Copyright. All rights reserved. 7 Unit 1 Learning Assessment - Answers 1. Screen fields can be assigned a field help (F1 help) by creating documentation for the data element. Determine whether this statement is true or false. X True X False 2. Which of the following type categories exist in the ABAP Dictionary? Choose the correct answers. X A Data elements X B Structures X C Indexes X D Table types 3. When creating the user interface in the _________________, fields from structures or tables defined in the Dictionary can be added to the screen using the Get from Dictionary function. Choose the correct answer. 8 X A Function Modules X B ABAP Interpreter X C Screen Painter © Copyright. All rights reserved. UNIT 2 Data Types in the ABAP Dictionary Lesson 1 Creating Domains and Data Elements Exercise 1: Create Basic Data Types 10 17 Lesson 2 Creating Flat Structures Exercise 2: Create Simple and Nested Structures 23 27 Lesson 3 Creating Table Types and Deep Structures Exercise 3: Create Table Types Exercise 4: Create Deep Structures 32 35 39 Lesson 4 Creating Type Groups 44 UNIT OBJECTIVES ● Create domains for data elements ● Create data elements ● Create simple and nested structures in the ABAP Dictionary ● Create table types in the ABAP Dictionary ● Create deep structures in the ABAP Dictionary ● Define type groups in the ABAP Dictionary © Copyright. All rights reserved. 9 Unit 2 Lesson 1 Creating Domains and Data Elements LESSON OVERVIEW This lesson explains how to create domains and use them in data elements. It also explains data elements how they are used as the basis for defining data objects in ABAP programs. Business Example You need to define simple and complex data types in the ABAP Dictionary, and to be able to use these data types in an ABAP program. For this reason, you require an understanding of the following: ● Data types ● Data elements ● Domains LESSON OBJECTIVES After completing this lesson, you will be able to: 10 ● Create domains for data elements ● Create data elements © Copyright. All rights reserved. Lesson: Creating Domains and Data Elements Overview of Data Types Figure 6: Data Dictionary: Initial Screen Cross-program (globally known) data types can be defined in the ABAP Dictionary. You can refer to these data types in every ABAP program in the SAP system with the TYPE addition for the corresponding ABAP statements. On the ABAP Dictionary: Initial Screen, in the Data Type field, you can find the following basic types: ● Data element ● Structure ● Table type © Copyright. All rights reserved. 11 Unit 2: Data Types in the ABAP Dictionary Data Types in the ABAP Dictionary Figure 7: Data Types in the ABAP Dictionary You can use the type definitions shown in the figure (with the exception of the domain) to define data objects in ABAP programs. The arrows show how the type definitions can be used together. Data elements use domains or integrated types to define their technical properties. However, an ABAP program cannot access domains to define data objects. A structure consists of components that can be elementary fields, tables, and also structures. The line type of a table type (ITAB) can be a structured type or an elementary type. Domains Domains manage the technical properties of data elements centrally. Domains cannot be used directly in programs, tables, and so on. A Domain comprises the settings formatand output characteristics . Format In the format specifications, you find the data type and the number of characters that can be entered in the dependent data object. If the format is numeric, you can also specify the number of decimal places. The data type must be chosen from a built-in list of data types. The following are the most frequently used data types: ● 12 CHAR (Character string) © Copyright. All rights reserved. Lesson: Creating Domains and Data Elements Fields of this type can have a maximum length of 255 characters in tables. To use longer character strings in tables, you have to choose the LCHR data type. In structures, there are no length restrictions regarding these fields. ● DATS (Date) The length for this data type is set to eight characters. You can define the output template with the user profile. ● DEC (Decimal) A DEC field can have a maximum of 31 characters. This field is the calculation or amount field with decimal point, +/- sign, and thousands separators. ● NUMC (Numeric) The length of NUMC field is restricted to a maximum of 255 characters. This character string can only contain numbers. Output Characteristics The maximum field length, including commas or decimal points, is specified for the input and output of values. This value is usually calculated automatically once the number of charactershas been assigned under Format . However, you can overwrite it later. The output format affects how screens and selection screens are displayed. The specifications from this area are used when a field is integrated in a screen. However, they can be modified in the Screen Painter. You can also define a conversion routine. This conversion routine changes the display format (for example, place leading zeros before a number) when the content of a screen field is converted from the display format to the SAP-internal format, and vice versa. The same conversion routines are executed by the system when you use the ABAP statement WRITE . Similarly, you can also use this conversion routine to override any unsuitable standard conversions. For certain data types, such as DEC, FLTP, QUAN, and CURR, the check box +/- sign is ready for entry. If this is activated, the first character of the field is reserved for the +/- sign on a screen. Accordingly, the system increases the output length by 1. For character-based data types, you should also determine whether lowercase letters are allowed. If this flag is not set, you can enter lowercase letters in the respective input fields; however, the lowercase letters are transformed into uppercase letters as soon as the user confirms the entry (for example, with the ENTER key). In addition, you can define valid value ranges that are used for input checks. © Copyright. All rights reserved. 13 Unit 2: Data Types in the ABAP Dictionary Data Elements Figure 8: Data Element Data elements define data types which can be used on screens, search helps, ABAP programs, and complex data types. Data elements contain both semantic and technical information about the data type. The technical properties for the data element are maintained on the Data Type tab page. SAP recommends using domains to specify the technical type of a data element. However, you can also define the data element using the same integrated types that are used to define the domains. As a special case, you can also create a data element as a reference type. The referenced type may be any type defined in the dictionary or a generic reference to types ANY, OBJECT, and DATA. A reference of the type ANY can point to both objects and data. The definition as a reference is the same as the type declaration in an ABAP program TYPES tr_dt TYPE REF TO data. The semantic information is maintained in the field labels. These field labels (short, medium, or long) can be displayed on screens or selection screens to explain the field content. You also have to specify maximum length for the respective field label. If you work for a company that operates globally, you can translate the field labels into other languages. (On the ABAP Dictionary: Initial Screen, choose Goto →Translation, or run the transaction code SE63.) When specifying the maximum length, remember that the same term in the field label might require more letters in another language. A search help (F4 key or input help) can be appended to a data element. The subject of search helps is discussed in greater detail later in this course. Search helps can be integrated at different levels. 14 © Copyright. All rights reserved. Lesson: Creating Domains and Data Elements Data Elements: Additional Options Additional options for data elements are as follows: ● Documentation You can create a text that describes the contents of the data element. This text is displayed for the F1 help in all screen fields that refer to this data element. ● Search help A search help (F4 key or input help) can be assigned to a data element. The subject of search helps is discussed in greater detail later in this course. Search helps can be integrated at different levels. ● Set/Get Parameter Assigning a SET/GET parameter to the data element saves the user from entering the same value several times. A field can be filled with default values from SAP memory. When you exit the screen, the system transfers the value into this parameter. If an input field based on the same data element exists on a subsequent screen, the system reads the value from the parameter and enters it in the screen field. The SET/GET parameters hold the value for each session. These values are not retained after the user has logged off. Note: The SET/GET parameters have nothing to do with the SAP GUI history (local data). ● Default component name You can assign a default component name to the data element. However, this is effective only if you use the data element as a component in Business Application Programming Interface (BAPI) structures. ● Change document The system logs changed field contents only if you set the Change document indicator for the data element. ● Input history The mechanism that the SAP GUI uses to handle the input history of a screen input field is switched off. ● Bi-directional options SET/GET Parameter In different applications, you may need to enter a particular value in several screens. Assigning a SET/GET parameter to the data element saves the user from entering the same value several times. When you exit the screen, the system transfers the value into this parameter. If an input field based on the same data element exists on a subsequent screen, the system reads the value from the parameter and enters it in the screen field. The SET/GET parameters hold the value for each session. These values are not retained after the user has logged off. The SET/GET parameters have nothing to do with the SAP GUI history (local data). You can also assign a default name to the data element. However, this is only effective if you use the © Copyright. All rights reserved. 15 Unit 2: Data Types in the ABAP Dictionary data element as a component in Business Application Programming Interface (BAPI) structures. Note: For more details about data elements, refer to the Online Manual (Information Icon button) from transaction SE11. 16 © Copyright. All rights reserved. Unit 2 Exercise 1 Create Basic Data Types Business Example As part of your development project, you want to create several global data types that can be accessed by other project members. Use the SAP system to create domains and several data elements. Then create an executable program that uses the data elements whose technical properties are defined by domains. Create Two Domains Create two domains so that you can use them later in data elements. 1. Execute the transaction SE11. 2. Create a domain with the name ZDO_10NUM_## on the initial screen of the ABAP Dictionary. Set the domain's properties so that it can contain 10-digit decimal numbers and allow negative values. Of these 10 digits, 2 digits should be reserved for the decimal places. 3. Save the domain as a local object and activate it. 4. On the ABAP Dictionary: Initial Screen, create a domain with the name ZDO_30CHAR_##. The domain can have a maximum of 30 text characters and lowercase letters should be permitted in the input fields. 5. Save the domain as a local object and activate it. Create Data Elements and Use the Defined Domains for Technical Properties 1. Start transaction SE11. 2. Create a data element ZLASTNAME## for the surname of a person and use a suitable domain. The data element can have maximum of 30 characters. 3. Create a data element (ZFIRSTNAME##) for the first name of a person and use the domain ZDO_30CHAR_##. 4. Create a data element (ZASSETS##) for assets and use the domain ZDO_10NUM_##. 5. Create a data element (ZLIABILITIES##) for liabilities and use the domain ZDO_10NUM_##. Create an Executable Program Using the Defined Data Elements Create an executable program which uses the data elements already defined. © Copyright. All rights reserved. 17 Unit 2: Data Types in the ABAP Dictionary 1. Create the executable program ZBC430_##_DATA_ELEMENTS without a TOP Include or copy from the template SAPBC430SDATA_ELEMENTS. 2. Create the following entry fields in the program with the ABAP command PARAMETERS. Parameter Data Type pa_fname ZFIRSTNAME## pa_lname ZLASTNAME## pa_activ ZASSETS## pa_liabs ZLIABILITIES## Calculate the assets minus liabilities and output all parameters as well as the calculation results in a list. 3. Execute the program. On the selection screen, enter the different values that you will output in a list. 18 © Copyright. All rights reserved. Unit 2 Solution 1 Create Basic Data Types Business Example As part of your development project, you want to create several global data types that can be accessed by other project members. Use the SAP system to create domains and several data elements. Then create an executable program that uses the data elements whose technical properties are defined by domains. Create Two Domains Create two domains so that you can use them later in data elements. 1. Execute the transaction SE11. 2. Create a domain with the name ZDO_10NUM_## on the initial screen of the ABAP Dictionary. Set the domain's properties so that it can contain 10-digit decimal numbers and allow negative values. Of these 10 digits, 2 digits should be reserved for the decimal places. a) On the ABAP Dictionary: Initial Screen, select the Domain radio button. b) Enter the name of the domain in the input field. c) Choose the Create button. d) Enter a meaningful description for the domain in the Short Descriptionfield. e) Enter the value DEC in the Data Type field. f) Enter the value 10 in the No. Characters field. g) Enter the value 2 in the Decimal Places field. h) Select the Sign checkbox. 3. Save the domain as a local object and activate it. a) Choose Save. b) Choose Local Object. c) Choose Check, then Activate. 4. On the ABAP Dictionary: Initial Screen, create a domain with the name ZDO_30CHAR_##. The domain can have a maximum of 30 text characters and lowercase letters should be permitted in the input fields. a) On the ABAP Dictionary: Initial Screen, select the Domain radio button. b) Enter the name of the domain in the input field. c) Choose the Create button. © Copyright. All rights reserved. 19 Unit 2: Data Types in the ABAP Dictionary d) Enter a meaningful description for the domain in the Short Descriptionfield. e) Using the Input Help, enter CHAR in the Data Type field. f) Enter 30 in the No. Characters field. g) Select the Lower Case checkbox. 5. Save the domain as a local object and activate it. a) Choose Save. b) Choose Local Object. c) Choose Check, then Activate. Create Data Elements and Use the Defined Domains for Technical Properties 1. Start transaction SE11. 2. Create a data element ZLASTNAME## for the surname of a person and use a suitable domain. The data element can have maximum of 30 characters. a) On the ABAP Dictionary: Initial Screen, select the Data Type radio button. b) Enter the name of the data type in the input field. c) Choose the Create button. d) In the dialog box, select the Data Element radio button and confirm the entry. e) Enter a meaningful description for the data element in the Short Descriptionfield. f) On the Data Type tab page, under Elementary Type, enter the domain that you created in the previous part of the exercise, ZDO_30CHAR_##. g) On the Field Label tab page, enter labels and the length of the labels to explain the fields. For example, short label Last, length 4 and long label Lastname, length 8. h) Save as a local object and activate. 3. Create a data element (ZFIRSTNAME##) for the first name of a person and use the domain ZDO_30CHAR_##. a) Proceed as described in step 2. 4. Create a data element (ZASSETS##) for assets and use the domain ZDO_10NUM_##. a) Proceed as described in step 2. 5. Create a data element (ZLIABILITIES##) for liabilities and use the domain ZDO_10NUM_##. a) Proceed as described in step 2. Create an Executable Program Using the Defined Data Elements Create an executable program which uses the data elements already defined. 1. Create the executable program ZBC430_##_DATA_ELEMENTS without a TOP Include or copy from the template SAPBC430SDATA_ELEMENTS. 20 © Copyright. All rights reserved. Lesson: Creating Domains and Data Elements a) To create the program, use transaction SE80. Select Program, then fill in the program name ZBC430_##_DATA_ELEMENTS and choose the icon . b) On the Create Program screen, choose Yes and Continue. c) Enter a title and save the program as a local object. 2. Create the following entry fields in the program with the ABAP command PARAMETERS. Parameter Data Type pa_fname ZFIRSTNAME## pa_lname ZLASTNAME## pa_activ ZASSETS## pa_liabs ZLIABILITIES## Calculate the assets minus liabilities and output all parameters as well as the calculation results in a list. a) Enter or copy the source code (provided at the end of this solution). Note: Replace ## with your group number and uncomment the source code. b) Activate the program. 3. Execute the program. On the selection screen, enter the different values that you will output in a list. a) Make sure that it is possible to enter uppercase and lowercase letters for names, in accordance with the definitions in the domains. In the two numeric fields, it must be possible to enter the decimal places and a minus sign. Source text excerpt: SAPBC430S_DATA_ELEMENTS REPORT sapbc430s_data_elements . *Replace ## by Your Group- Screennumber and uncomment *the ABAP-coding DATA: result PARAMETERS: pa_fname pa_lname pa_activ pa_liabs TYPE zassets##. TYPE TYPE TYPE TYPE zfirstname##, zlastname##, zassets##, zliabilities##. START-OF-SELECTION. NEW-LINE. WRITE: 'Client:', pa_fname, pa_lname. result = pa_activ - pa_liabs. NEW-LINE. WRITE: 'Finance:', pa_activ, pa_liabs, result. © Copyright. All rights reserved. 21 Unit 2: Data Types in the ABAP Dictionary LESSON SUMMARY You should now be able to: 22 ● Create domains for data elements ● Create data elements © Copyright. All rights reserved. Unit 2 Lesson 2 Creating Flat Structures LESSON OVERVIEW This lesson explains simple and nested structures in the ABAP Dictionary. It also covers how to define global types and constants using type groups. Business Example You need to define simple and nested structures in the ABAP Dictionary. You also need to define global types and constants using a type group. For this reason, you require an understanding of the following: ● How to define complex (nested or deep) structures ● How to define global types and constants with the help of a type pool and use them in ABAP programs LESSON OBJECTIVES After completing this lesson, you will be able to: ● Create simple and nested structures in the ABAP Dictionary Simple and Nested Structures Figure 9: Structures © Copyright. All rights reserved. 23 Unit 2: Data Types in the ABAP Dictionary A structure consists of components in the following forms: ● Data elements ● Integrated types ● Table types ● Definition of database tables and database views ● Other structure types When the fields of an actual two-dimensional object are integrated in a structure by including a view or DB tables, the data object that can be generated from this structure remains flat and is one-dimensional. A deep structure is always created when you use a table type to define a component. Although this component is then two-dimensional, the other components in the structure remain flat (one-dimensional). Using Simple Structures in ABAP Figure 10: Using Simple Structures in ABAP The simplest form of a structure is a list of fields typed with data elements. This form of a structure is called a flat structure. A data object based on this structure type is always onedimensional (as opposed to table-like, two-dimensional data objects). You address the individual elements (components) of the structure using the name of the structure, a hyphen, and the name of the components. 24 © Copyright. All rights reserved. Lesson: Creating Flat Structures Nested Structure Figure 11: Nested Structure You can include another structured object in the structure and assign it to a component. The component refers to the structured object and the new data object is described as a nested structure. © Copyright. All rights reserved. 25 Unit 2: Data Types in the ABAP Dictionary 26 © Copyright. All rights reserved. Unit 2 Exercise 2 Create Simple and Nested Structures Business Example To map complex data structures, you must build a complex structure for your project in the ABAP Dictionary. Create Simple Structures in the ABAP Dictionary and Use them in Programs 1. In the ABAP Dictionary, create a structure ZNAME## and include the following two components in the structure. Use the data elements that you created in the Create Basic Data Types exercise for typing. Component Component Type Typing Method FIRSTNAME ZFIRSTNAME## Types LASTNAME ZLASTNAME## Types 2. Create a structure ZADDRESS## and enter the following components: Component Component Type Typing Method STREET S_STREET Types NR S_NO Types ZIP POSTCODE Types CITY S_CITY Types Create Nested Structures in the ABAP Dictionary and Use them in Programs 1. Create a structure ZPERSON## in the ABAP Dictionary. 2. Add the structure ZADDRESS## as an include structure to the ZPERSON## structure. In addition, add the structure ZNAME## in the ZPERSON## structure as a nested structure under the component name NAME. Component Component Type Description .include ZADDRESS## Address structure NAME ZNAME## Refers to the name structure 3. Create the executable program ZBC430_##_STRUCT_NESTED without a TOP Include or copy from the template SAPBC430S_STRUCT_NESTED. © Copyright. All rights reserved. 27 Unit 2 Solution 2 Create Simple and Nested Structures Business Example To map complex data structures, you must build a complex structure for your project in the ABAP Dictionary. Create Simple Structures in the ABAP Dictionary and Use them in Programs 1. In the ABAP Dictionary, create a structure ZNAME## and include the following two components in the structure. Use the data elements that you created in the Create Basic Data Types exercise for typing. Component Component Type Typing Method FIRSTNAME ZFIRSTNAME## Types LASTNAME ZLASTNAME## Types a) Start transaction SE11. b) Enter the name of the structure in the Data type input field. c) Choose Create and select Structure in the modal dialog box. d) Provide a short description and enter the specified components. Save as a local object and activate it. Note: Ignore the warning message about the enhancement category. 2. Create a structure ZADDRESS## and enter the following components: Component Component Type Typing Method STREET S_STREET Types NR S_NO Types ZIP POSTCODE Types CITY S_CITY Types a) Proceed in the same way as you did in step 1. 28 © Copyright. All rights reserved. Lesson: Creating Flat Structures Create Nested Structures in the ABAP Dictionary and Use them in Programs 1. Create a structure ZPERSON## in the ABAP Dictionary. a) Proceed in the same way as you did the first task, steps 1 a-c. 2. Add the structure ZADDRESS## as an include structure to the ZPERSON## structure. In addition, add the structure ZNAME## in the ZPERSON## structure as a nested structure under the component name NAME. Component Component Type Description .include ZADDRESS## Address structure NAME ZNAME## Refers to the name structure a) To include the address, either choose Edit → Include → Insert and enter the structure name ZADDRESS##, or enter the keyword .INCLUDE in the Component TypeColumn. Caution: The period in front of the keyword is important. b) Add the second structure by entering the structure NAME under component and ZNAME## under Component Type. Choose Types as the Typing Method. c) Save as a local object and activate. 3. Create the executable program ZBC430_##_STRUCT_NESTED without a TOP Include or copy from the template SAPBC430S_STRUCT_NESTED. a) To create the program, use transaction SE80. Select Program, fill in program name and choose Enter. b) On the Create Program screen, choose Yes and Continue. c) Enter a title and save it as a local object. d) Enter the following source code. Note: Replace ## with your group number and uncomment the ABAP code. e) Activate the program. Source code excerpt: SAPBC430S_STRUCT_NESTED REPORT sapbc430s_struct_nested. *Replace ## by Your group- or screen number and *uncomment the ABAP-coding DATA wa_person TYPE zperson##. © Copyright. All rights reserved. 29 Unit 2: Data Types in the ABAP Dictionary START-OF-SELECTION. wa_person-name-firstname = 'Harry'. wa_person-name-lastname = 'Potter'. wa_person-street = 'Privet Drive'. wa_person-nr = '3'. wa_person-zip = 'GB-10889'. wa_person-city = 'London'. WRITE: / 30 wa_person-name-firstname , wa_person-name-lastname , wa_person-street , wa_person-nr , wa_person-zip , wa_person-city . © Copyright. All rights reserved. Lesson: Creating Flat Structures LESSON SUMMARY You should now be able to: ● Create simple and nested structures in the ABAP Dictionary © Copyright. All rights reserved. 31 Unit 2 Lesson 3 Creating Table Types and Deep Structures LESSON OVERVIEW This lesson describes the table types in the SAP system. Business Example As a developer, you need to create table types and deep structures in the SAP system. For this reason, you require and understanding of the following: ● How to define data types in the ABAP Dictionary ● How to define flat and complex structures LESSON OBJECTIVES After completing this lesson, you will be able to: ● Create table types in the ABAP Dictionary ● Create deep structures in the ABAP Dictionary Table Types Figure 12: Internal Tables Defined by a Table Type 32 © Copyright. All rights reserved. Lesson: Creating Table Types and Deep Structures A dictionary structure containing one or more fields using a table type is called a deep structure. You can define table types using an existing dictionary type. Database tables, structure definitions, views, data elements, direct type definitions, or existing table types can be used as line type. During runtime, if the ABAP program is referencing any data object using table types, the system will create a two-dimensional array in the main memory for each of these objects. Table Type Definition A table type is defined by the following: ● A line type that defines the structure and the data type attributes of a line in the internal table. ● Access mode, which determines how to manage and access the data. Possible access modes are standard table, sorted table, hashed table, index table, and not specified. ● Primary key definition and key category (Unique/Non-unique/Not specified). Hashed table is always unique, and sorted table can be unique, non-unique, or not specified. ● Secondary key (optional) Secondary keys can be hashed or sorted. A sorted secondary key can be unique or nonunique. To define a table type, go to the ABAP Dictionary (transaction SE11), enter the table type name, and fill in the definitions. Special Table Types Generic table types ● Generic table types are table types that define only some of the attributes of an internal table in the ABAP Dictionary and leave the others open. You use generic table types to define the types of generic table parameters in function modules and forms, and thus provide a degree of freedom for the arguments passed in the corresponding calls. A table type is generic in the following cases: ● - You have selected Index table or Not Specified as the access mode. - The key is not specified. - The key category is not specified. - Further secondary keys are permitted. Ranges table types A ranges table type is a special case. You use this table type to describe the structure of an internal table for administering complex areas, that is, the type of an internal ranges table in the ABAP program. You can use ranges tables, for example, in logical conditions (IN operators) in the SELECT, IF, WHILE, and CHECK statements, or to pass data to selection tables. The row type of a ranges table type has a fixed structure. The row type consists of the four components: SIGN (sign), OPTION (comparison operator), LOW (lower limit), and HIGH (upper limit), in this order. © Copyright. All rights reserved. 33 Unit 2: Data Types in the ABAP Dictionary The type of components LOW and HIGH are defined by an elementary associated type. You can define this by specifying a data element or by directly defining the data type, number of places, and number of decimal places. A ranges table type always has standard table access mode and a standard key that is non-unique. To define a table type, go to the ABAP Dictionary (transaction SE11), enter a table type name, and choose Edit → Define as ranges table type. 34 © Copyright. All rights reserved. Unit 2 Exercise 3 Create Table Types Business Example You need to read data from the table SFLIGHT and output the data to the screen. To do this, create a table type in the Dictionary, which you can use to define a suitable internal table in your ABAP program. 1. Create a table type ZIT_SFLIGHT## in the ABAP Dictionary. The table type should be based on the line type of the database table SFLIGHT and sorted according to the flight date FLDATE. 2. Create an ABAP program ZBC430_##_ITAB_SORTED or copy from the template SAPBC430S_ITAB_SORTED. In this program, create a structured data object wa_sflight of the type SFLIGHT as the work area, and an internal table on the basis of the table type just defined. From the SFLIGHT table, select the data of a carrier, for example, JL, in the work area and output this as an unsorted list. 3. Extend the program as follows. Insert a line (ABAP command ULINE) in the list. Retrieve the same data again, but this time use an array fetch in the SELECT command. Read the data from the database into the internal table of the type ZIT_SFLIGHT## and output the content of the table using the LOOP command in the same list. Compare the order of the data in both list excerpts. © Copyright. All rights reserved. 35 Unit 2 Solution 3 Create Table Types Business Example You need to read data from the table SFLIGHT and output the data to the screen. To do this, create a table type in the Dictionary, which you can use to define a suitable internal table in your ABAP program. 1. Create a table type ZIT_SFLIGHT## in the ABAP Dictionary. The table type should be based on the line type of the database table SFLIGHT and sorted according to the flight date FLDATE. a) Start transaction SE11. b) Select the required data type. c) Enter the name of the table, ZIT_SFLIGHT##, in the Data Type field. d) Choose Create. e) In the dialog box, select the Table Type radio button. f) Assign a short description and enter the name of the database table, SFLIGHT, in the line type field. g) Switch to the Initialization and Accesstab page and select Sorted Table as the access type. h) Switch to the Primary Key tab page and select Non-unique as the key type. i) On the Primary Key tab page, select the Key componentsradio button from Key definition. In the Key components pane, select CARRID and choose the Choose componentsbutton. j) Save as a local object and activate. 2. Create an ABAP program ZBC430_##_ITAB_SORTED or copy from the template SAPBC430S_ITAB_SORTED. In this program, create a structured data object wa_sflight of the type SFLIGHT as the work area, and an internal table on the basis of the table type just defined. From the SFLIGHT table, select the data of a carrier, for example, JL, in the work area and output this as an unsorted list. a) Use transaction SE80 to create the program and enter the source code below (first select block). Note: Replace ## with your group number and uncomment the ABAP code. b) Activate the program. 36 © Copyright. All rights reserved. Lesson: Creating Table Types and Deep Structures 3. Extend the program as follows. Insert a line (ABAP command ULINE) in the list. Retrieve the same data again, but this time use an array fetch in the SELECT command. Read the data from the database into the internal table of the type ZIT_SFLIGHT## and output the content of the table using the LOOP command in the same list. Compare the order of the data in both list excerpts. a) Use transaction SE80 to create the program and enter the following source code (second select block). Note: Replace ## with your group number and uncomment the ABAP code. b) Activate the program. SAPBC430S_ITAB_SORTED REPORT SAPBC430S_ITAB_SORTED. **Replace ## by Your group- or screennumber and **uncomment the ABAP-coding DATA it_flight TYPE zit_sflight##. DATA wa_sflight TYPE sflight. WRITE / 'Printout in tableorder of Database:'. * Array fetch SELECT * FROM sflight INTO wa_sflight WHERE carrid = 'JL'. WRITE: / wa_sflight-carrid, wa_sflight-connid, wa_sflight-fldate, wa_sflight-price, wa_sflight-currency, wa_sflight-planetype. ENDSELECT. ULINE. SELECT * FROM sflight INTO TABLE it_flight WHERE carrid = 'JL'. WRITE / 'Printout in tableorder of sorted ITAB:'. LOOP AT it_flight INTO wa_sflight. WRITE: / wa_sflight-carrid, wa_sflight-connid, wa_sflight-fldate, wa_sflight-price, wa_sflight-currency, wa_sflight-planetype. ENDLOOP. © Copyright. All rights reserved. 37 Unit 2: Data Types in the ABAP Dictionary Deep Structures Figure 13: Deep Structures in an ABAP program A deep structure contains at least one field with a table type. The component of this table has its own name with which it can be addressed in the same way as a normal internal table (LOOP AT..., INSERT... INTO TABLE, ...). An internal table, in turn, can have a deep structure as a line type. In this way, you can create multidimensional data types, since internal tables and structures can be inter-nested several times. Caution: Database tables can only include flat structures. 38 © Copyright. All rights reserved. Unit 2 Exercise 4 Create Deep Structures Business Example You expand the structure of the personal data for your project team to such an extent that you can incorporate a telephone list of any length for each employee. Create a deep structure by adding a table type field. Use this in an ABAP program. 1. Create a table type ZIT_PHONE_NUMBER## in the Dictionary. The table type should be based on the existing structure STR_PHONE. 2. Extend your existing structure ZPERSON## in the Dictionary. The new component should receive the name PHONE and be based on the table type ZIT_PHONE_NUMBER##. 3. Create an ABAP program ZBC430_##_STRUCT_DEEP. To do this, copy your solution for the program ZBC430_##_STRUCT_NESTED or the model template SAPBC430S_STRUCT_NESTED. Extend this program by adding one work area for a structured data object wa_phone of the type STR_PHONE using the data statement. 4. Extend the program as follows: Insert three telephone numbers in the structured data object wa_person and output this data in the same list using the LOOP command. © Copyright. All rights reserved. 39 Unit 2 Solution 4 Create Deep Structures Business Example You expand the structure of the personal data for your project team to such an extent that you can incorporate a telephone list of any length for each employee. Create a deep structure by adding a table type field. Use this in an ABAP program. 1. Create a table type ZIT_PHONE_NUMBER## in the Dictionary. The table type should be based on the existing structure STR_PHONE. a) Start transaction SE11. b) Select the data type. c) Enter ZIT_PHONE_NUMBER## in the input field. d) Choose Create. e) In the dialog box, select the Table Type radio button. f) Provide a short description and enter the name of the structure in the line type field. g) Switch to the Initialization and Accesstab page and select Standard Table as the access type. h) Switch to the Primary Key tab page and choose Non-unique as the key type. i) Choose Standard Key as a key definition. j) Save as a local object and activate. 2. Extend your existing structure ZPERSON## in the Dictionary. The new component should receive the name PHONE and be based on the table type ZIT_PHONE_NUMBER##. a) Enter a new component with the name Phone in your structure and specify the newly created table type as component type. Component Component Type Typing Method .include ZADDRESS## Types NAME ZNAME## Types PHONE ZIT_PHONE_NUMBER## Types b) Save as a local object and activate. Note: Ignore the warning message about the Enhancement Category. 40 © Copyright. All rights reserved. Lesson: Creating Table Types and Deep Structures 3. Create an ABAP program ZBC430_##_STRUCT_DEEP. To do this, copy your solution for the program ZBC430_##_STRUCT_NESTED or the model template SAPBC430S_STRUCT_NESTED. Extend this program by adding one work area for a structured data object wa_phone of the type STR_PHONE using the data statement. a) Use transaction SE80 to create/copy the program and enter the source code. Note: Replace ## with your group number and uncomment the ABAP code. b) Add the work area as follows: DATA wa_phone TYPE str_phone. 4. Extend the program as follows: Insert three telephone numbers in the structured data object wa_person and output this data in the same list using the LOOP command. a) See the source code excerpt from the model solution. b) Save the program as a local object and activate. SAPBC430S_STRUCT_DEEP REPORT sapbc430s_struct_deep. **1. Replace the ## with your group or screen number . **2. Activate the given code. DATA wa_person TYPE zperson##. DATA wa_phone TYPE str_phone. START-OF-SELECTION. *Fill deep structure with data wa_person-name-firstname = 'Harry'. wa_person-name-lastname = 'Potter'. wa_person-street = 'Privet Drive'. wa_person-nr = '3'. wa_person-zip = 'GB-10889'. wa_person-city = 'London'. wa_phone-p_type = 'P'. wa_phone-p_number = '+31-10-9938990'. INSERT wa_phone INTO TABLE wa_person-phone. wa_phone-p_type = 'F'. wa_phone-p_number = '+31-10-9938991'. INSERT wa_phone INTO TABLE wa_person-phone. wa_phone-p_type = 'M'. wa_phone-p_number = '+31-79-12211433'. INSERT wa_phone INTO TABLE wa_person-phone. *Write on List WRITE: / wa_person-name-firstname , wa_person-name-lastname , wa_person-street , © Copyright. All rights reserved. 41 Unit 2: Data Types in the ABAP Dictionary wa_person-nr , wa_person-zip , wa_person-city . WRITE: / 'Phone-Numbers:'. LOOP AT wa_person-phone INTO wa_phone. WRITE: AT 20 wa_phone-p_type, wa_phone-p_number. NEW-LINE. ENDLOOP. 42 © Copyright. All rights reserved. Lesson: Creating Table Types and Deep Structures LESSON SUMMARY You should now be able to: ● Create table types in the ABAP Dictionary ● Create deep structures in the ABAP Dictionary © Copyright. All rights reserved. 43 Unit 2 Lesson 4 Creating Type Groups LESSON OVERVIEW In this lesson, you will learn how to define global constants using type groups. LESSON OBJECTIVES After completing this lesson, you will be able to: ● Define type groups in the ABAP Dictionary Type Groups Figure 14: Type Group Type groups can be used to define your own global-complex data types, global constants, and macros. Type groups were introduced prior to release 4.5a, when complex data types were not supported. They are still being used by some ABAP programs but their use is no longer recommended. Instead of using type groups, you can use the options provided by Dictionary structures to define your own global, complex data types. You can also use constant classattributes provided by ABAP objects to define global constants. 44 © Copyright. All rights reserved. Lesson: Creating Type Groups The name of the type group can contain a maximum of five characters. In the type group, you can use the TYPES statement and the CONSTANTS statement, and you can also use the predefined ABAP types or global dictionary types. A type group is defined as a piece of ABAP code that you maintain either in the ABAP Dictionary (SE11) or in the ABAP Editor (SE38). The first statement in a type group is always TYPE-POOL <name>. This is followed by the data type definition with the TYPES statement, as described under local program data types. Moreover, you can declare cross-program constants using the CONSTANTS statement. All names of these data types and constants must begin with the name of the type group and an underscore, for example, zmytp_. In releases prior to NW AS 7.02, you have to declare the usage of a type group explicitly in your program. The ABAP statement is TYPE-POOLS <type group name>. This statement enables you to use all types and constants defined in that type group. You can use several type groups in the same program. LESSON SUMMARY You should now be able to: ● Define type groups in the ABAP Dictionary © Copyright. All rights reserved. 45 Unit 2: Data Types in the ABAP Dictionary 46 © Copyright. All rights reserved. Unit 2 Learning Assessment 1. ABAP Objects support the use of global constants in the form of constant class-attributes. Determine whether this statement is true or false. X True X False 2. Which of the following technical information can be found in a domain? Choose the correct answers. X A Data type X B Field length X C Output characteristics X D Field labels 3. Data elements are based on domains or built-in types. Determine whether this statement is true or false. X True X False 4. Field labels contain keywords of different lengths (short, medium, and long) which can be assigned to screen fields referencing definitions in the ABAP Dictionary. Which of the following dictionary definitions can be used to maintain these field labels? Choose the correct answer. X A Built-in type X B Data element X C Domain X D Type pool © Copyright. All rights reserved. 47 Unit 2: Learning Assessment 5. A structure can consist of components with the following types: data elements, integrated types, table types, database tables, views, or other existing structures. Determine whether this statement is true or false. X True X False 6. The simplest form of a structure is a list of fields typed with data elements. This always gives rise to a ______________ structure. Choose the correct answer. X A deep X B flat X C nested 7. Which of the following dictionary definitions can be used as line type for a table type in the Dictionary? Choose the correct answers. X A Database table X B Structure X C Domain X D Data element X E Type group 8. You can create a two-dimensional array in main memory by declaring an internal table in an ABAP program. Determine whether this statement is true or false. X True X False 9. A deep structure contains at least one table. Determine whether this statement is true or false. 48 X True X False © Copyright. All rights reserved. Unit 2: Learning Assessment 10. The name of a type group can contain a maximum of how many characters? Choose the correct answer. X A Ten X B Three X C Five 11. In a structure, you can include another structured object and assign it to a component. The component refers to the structured object and the new data object is described as a nested structure. Determine whether this statement is true or false. X True X False © Copyright. All rights reserved. 49 Unit 2 Learning Assessment - Answers 1. ABAP Objects support the use of global constants in the form of constant class-attributes. Determine whether this statement is true or false. X True X False 2. Which of the following technical information can be found in a domain? Choose the correct answers. X A Data type X B Field length X C Output characteristics X D Field labels 3. Data elements are based on domains or built-in types. Determine whether this statement is true or false. X True X False 4. Field labels contain keywords of different lengths (short, medium, and long) which can be assigned to screen fields referencing definitions in the ABAP Dictionary. Which of the following dictionary definitions can be used to maintain these field labels? Choose the correct answer. 50 X A Built-in type X B Data element X C Domain X D Type pool © Copyright. All rights reserved. Unit 2: Learning Assessment - Answers 5. A structure can consist of components with the following types: data elements, integrated types, table types, database tables, views, or other existing structures. Determine whether this statement is true or false. X True X False 6. The simplest form of a structure is a list of fields typed with data elements. This always gives rise to a ______________ structure. Choose the correct answer. X A deep X B flat X C nested 7. Which of the following dictionary definitions can be used as line type for a table type in the Dictionary? Choose the correct answers. X A Database table X B Structure X C Domain X D Data element X E Type group 8. You can create a two-dimensional array in main memory by declaring an internal table in an ABAP program. Determine whether this statement is true or false. X True X False 9. A deep structure contains at least one table. Determine whether this statement is true or false. X True X False © Copyright. All rights reserved. 51 Unit 2: Learning Assessment - Answers 10. The name of a type group can contain a maximum of how many characters? Choose the correct answer. X A Ten X B Three X C Five 11. In a structure, you can include another structured object and assign it to a component. The component refers to the structured object and the new data object is described as a nested structure. Determine whether this statement is true or false. 52 X True X False © Copyright. All rights reserved. UNIT 3 Database Tables Lesson 1 Creating Transparent Tables Exercise 5: Create Tables in the ABAP Dictionary 54 67 Lesson 2 Defining Cluster Tables and Pooled Tables 77 UNIT OBJECTIVES ● Create transparent tables ● Define INCLUDE structures ● Create tables in the ABAP Dictionary ● Define cluster tables and pooled tables © Copyright. All rights reserved. 53 Unit 3 Lesson 1 Creating Transparent Tables LESSON OVERVIEW This lesson describes transparent tables and INCLUDE structures. The lesson also explains how to define the technical settings for transparent tables. Business Example As a developer, you are asked to create additional tables to support the data model used in your company. For this reason, you require an understanding of the following: ● How to create tables ● The use of the two-level domain concept ● How to define the technical settings of a table ● How to create and use INCLUDE structures LESSON OBJECTIVES After completing this lesson, you will be able to: 54 ● Create transparent tables ● Define INCLUDE structures ● Create tables in the ABAP Dictionary © Copyright. All rights reserved. Lesson: Creating Transparent Tables Transparent Tables Figure 15: Tables and Fields The structure of the objects used in application development is mapped to tables in the database system. The attributes of these objects correspond to the fields of the table. A table consists of columns (fields) and rows (entries). The table has a name and different general attributes, such as delivery class and maintenance authorization. A field has a unique name and attributes; for example, a key field. A table has one or more key fields. The values of these key fields uniquely identify a table entry. These key fields collectively are called as a primary key. You must specify a reference table for fields containing a currency (data type CURR) or quantity (data type QUAN). A reference table must contain a field (reference field) with the format for currency keys (data type CUKY) or the format for units (data type UNIT). The field is only assigned to the reference field at program runtime. © Copyright. All rights reserved. 55 Unit 3: Database Tables Basic Objects of the ABAP Dictionary Figure 16: Basic Objects of the ABAP Dictionary The basic objects for defining data in the ABAP Dictionary are as follows: ● Tables A transparent table is used to define database tables on the database system. You can store business data in database tables. ● Domains A domain is used for the technical definition of a table field (for example, field type and length). It also describes the value range of a field by its data type and length. The value range can be limited by specifying fixed values. ● Data element A data element is used for the semantic definition, for example, a short description of a table field. A data element also describes the meaning of a domain in a certain business context. The data element primarily contains the field help (F1 documentation) and the field labels on the screen. A field is not an independent object. It is table-dependent. You can only maintain a field within a table. You can enter the data type and number of places directly for a field. No data element is required in this case. Instead, you can choose a predefined type to specify the data type and number of places. You can specify the technical attributes of a data element even without using a domain. To do so, you enter the built-in data type and the number of places directly. 56 © Copyright. All rights reserved. Lesson: Creating Transparent Tables Example of Two-Level Domain Concept Figure 17: Example of Two-Level Domain Concept The table SPFLI stores the flight schedule. Table fields AIRPFROM (departure airport) and AIRPTO (arrival airport) have the same domain S_AIRPID. Because both fields use the same domain and contain airport IDs, they have the same technical attributes. Both table fields have a different semantic meaning and use different data elements. Field AIRPFROM uses data element S_FROMAIRP and field AIRPTO uses data element S_TOAIRP. © Copyright. All rights reserved. 57 Unit 3: Database Tables Transparent Tables and Structures Figure 18: Transparent Tables and Structures A table is automatically created in the database when a transparent table is activated in the ABAP Dictionary. At this time, the database-independent description of the table in the ABAP Dictionary is translated into the language of the database system used. The database table has the same name as the table in the ABAP Dictionary. The fields also have the same name in both the database and the ABAP Dictionary. The system converts the data types in the ABAP Dictionary to the corresponding data types of the database system. The order of the fields in the ABAP Dictionary can differ from the order of the fields in the database. Therefore, you can insert new fields without having to convert the table. When you add a new field, the system adjusts the list of fields by changing the database catalog. This mechanism is called ALTER TABLE. ABAP programs can use a transparent table in the following ways: ● You can access the data contained in the table with OPEN SQL (or native SQL). ● You can use the transparent table as a structure type when defining variables (or more complex data types). You can also create a structured type in the ABAP Dictionary for which there is no corresponding object in the database. Such types are called structures. Structures can also define the types of variables. 58 © Copyright. All rights reserved. Lesson: Creating Transparent Tables INCLUDE Structures Figure 19: INCLUDE Structures The include mechanism exists to avoid redundant structure definitions. You can re-use structures by including them in other structures or tables. A table cannot be included in another table. Includes may contain other includes. Foreign keys defined in the INCLUDE structure are passed on to the including table. © Copyright. All rights reserved. 59 Unit 3: Database Tables Technical Settings for Transparent Tables Figure 20: Technical Settings: General Properties The technical settings determine the storage requirements and the access behavior of database tables. When you activate the table in the ABAP Dictionary, the system automatically creates the table in the database system. The technical settings define how the table is handled when it is created in the database system. The settings for the data class and size category determine the storage area to be selected and the expected table size. The settings for buffering define whether and how the table should be buffered. You can define whether changes to the table entries should be logged. 60 © Copyright. All rights reserved. Lesson: Creating Transparent Tables Table Fragmentation in the Database Figure 21: Table Fragmentation in the Database Tables that include transaction data can have large gaps in their allocated space due to fast growth or frequent data record changes, such as inserting or deleting the data records. This data fragmentation on the database server always leads to potential performance problems. Indexes can be fragmented too due to frequent or mass data record changes. Regular database maintenance and reorganization can help to solve some of these issues and this is usually handled by the system or database administrators. Note: Tablespace is a term used by Oracle. It is a storage area in the database. Fragmented Indexes Fragmented indexes can be defragmented by rebuilding with indexes. The database calculates the content and structure of the index again and creates the necessary space in one piece in the storage medium. While the index is being re-created by the database system, ABAP programs can still access the table content. Caution: If the index belongs to a large table (> 100.000 data records), the index rebuild process may take several minutes or even hours. While rebuilding the index, the index cannot be used for database access, which may lead to increased response time when reading table data (due to Full Table Scan). © Copyright. All rights reserved. 61 Unit 3: Database Tables Fragmented Tables To reduce the fragmentation of database tables, one of the possible solutions is to rebuild the tables. During the rebuild process, the SAP system creates a new table and transfers the data to this table. Afterwards the system deletes the old, fragmented table and replaces it with the new one. In case the table has been grown unexpectedly fast, you should check and adjust the size category in the technical settings before converting the table. Note: The rebuild or any table conversion should be carefully planned and executed by your system or database administrator. SAP does provide the database utility, which allows database objects derived from the ABAP Dictionary to be adjusted, deleted, or created. There are also other utilities or products from your database vendor or third party, which offer similar features. Refer to the Database Utility in the online help for more details. Caution: You cannot read or change the content of the table during the rebuild process. Depending on the table size, the process can last for several minutes or hours. In a productive environment, therefore, you should exercise care when executing the procedure. The conversion should take place at times when the load on the system is at a minimum, for example, at night. To minimize fragmentations, you must choose the correct data class and size category in the technical settings of the table. Data Class Figure 22: Data Class 62 © Copyright. All rights reserved. Lesson: Creating Transparent Tables The database system has different physical storage areas. The data class defines where the table resides within the database system. Note: Tablespace is a term used in the Oracle database. The most important data classes are as follows: ● Master data Master data is data that is seldom modified. An example of master data is the customer master data, which includes customer name, company address, and company details. ● Transaction data Transaction data is the data that is frequently modified. An example is the material stock of a warehouse, which can change after each purchase order. ● Organizational data Organizational data is the data you can define when you customize and install the system, and is seldom modified afterwards. The country keys are an example. ● System data System data is the data that the SAP system needs. The system configurations are an example. Size Category Figure 23: Size Category The size category describes the expected storage requirements for the table in the database. When the system creates a table in the database, it reserves an initial extent. The size of the © Copyright. All rights reserved. 63 Unit 3: Database Tables initial extent is identical for all size categories. If the table needs more space for data at a later time, further extents are added. These further extends have a fixed size that depends on the size category specified in the ABAP Dictionary. You can choose a size category from 0 to 4. Depending on the database system, each size category has a fixed extent size. Correctly assigning a size category ensures that you do not create a large number of small extents that may increase table fragmentation. At the same time, do not choose a size category that is too large and wastes storage space. Log Data Changes Figure 24: Log Data Changes You can use logging to record and store changes to the entries of a table. To activate logging, select the Log Data Changes checkbox in the technical settings. Selecting the flag in the ABAP Dictionary is not sufficient to trigger logging. Logging is only performed if it is enabled in the system profile parameter rec/client. Table 1: Settings for the Parameter rec/client Settings Description rec/client = ALL Log all clients rec/client = 000[...] Log specified clients only rec/client = OFF Logging is deactivated in this system The data modifications are logged independently of the update. You can display the logs with the Table History transaction (SCU3). 64 © Copyright. All rights reserved. Lesson: Creating Transparent Tables Caution: Logging decreases the overall system performance. Table logging results in additional database write access. The logging table is accessed by many different users, which may lead to lock situations and slow down system performance. Write Access Only with Java Using the indicator Write access only with Java, you can define that contents of the table may be changed only from within Java. If you implement changes (INSERT, UPDATE) to the table content through ABAP programs, there is no guarantee that this data can be read correctly from the Java side. If the data written by ABAP is ASCII data, it can be read from the Java side. Technical Settings: DB-Specific Properties Besides general properties, there is now a new tab called DB-Specific Propertiesunder Technical Settings, where you can change the storage type, depending on the database you use. Conceptually, a relational database table is a two-dimensional data structure, with cells organized in rows and columns. SAP NetWeaver 7.4 uses both the column and row store of SAP HANA. If you use the data dictionary to create a table for SAP HANA , it will be a table in column store by default, in which the database serializes all of the values of a column together, then the values of the next column, and so on. You can change this setting in SE11 under DB-Specific Properties. © Copyright. All rights reserved. 65 Unit 3: Database Tables 66 © Copyright. All rights reserved. Unit 3 Exercise 5 Create Tables in the ABAP Dictionary Business Example As a developer, you need to enhance the tables of the flight model with human resource management. This employee management enables the airlines to enter and evaluate data about their employees (for example, name, personnel number, salary, department, and so on) and about assignments within the organization (airline departments). You need to create tables for employee data and the airline departments. The table ZEMPLOY## (where ## is your group number) stores employee data, such as name, address, and salary. The ZDEPMENT## table contains the departments of the airline. Each department has a telephone and a fax number. Create Two Transparent Tables and Define Key Fields Create two transparent tables ZEMPLOY## and ZDEPMENT## and define their key fields. Data is maintained for three airlines. An airline has 20,000 employees and between 10 and 30 departments. Do not buffer or log the data. Note: You have to define the technical settings before you can activate the tables. 1. Create the table ZEMPLOY##, using the data in the following table: Field Data Element Domain CLIENT S_MANDT MANDT Client CARRIER S_CARR_ID S_CARR_ID Carrier EMP_NUM zempnum## zempnum## FIRST_NAME S_FNAME S_FNAME First name LAST_NAME S_LNAME S_LNAME Last name DEPARTMENT zdept## zdept## CHAR 4 Dept code AREA zarea## zarea## CHAR 1 Area SALARY zsalary## zsalary## CURR 10 deci- Salary mal 2 CURRENCY S_CURRCODE S_CURR © Copyright. All rights reserved. Data Type NUMC Length 10 Description Personnel number Currency 67 Unit 3: Database Tables 2. Create the table ZDEPMENT##, using the data in the following table: Field Data element Domain CLIENT S_MANDT MANDT Data Type Length Description Client CARRIER S_CARR_ID S_CARR_ID Airline DEPARTMENT zdept## zdept## CHAR 4 Dept code TELNR ztelnr S_PHONE CHAR 30 Telephone FAXNR zfaxnr S_PHONE CHAR 30 Fax 3. Document the Personnel numberand Department codefields. 4. Maintain the technical settings and then activate the table. If you have defined an amount field in the table, you must assign the corresponding currency field. Create a Structure with Two Columns Changes to ZEMPLOY## and ZDEPMENT## are critical, so we want to keep track of who made the changes and when. In order to do this, you need a structure with two columns: Last_changed_byand Changed_on. Note: Changes to tables ZEMPLOY## and ZDEPMENT## are critical and must be recorded. The ABAP program maintaining the data should automatically save information about the last user to change the table data. This can be done by appending fields for the personnel number of the last person to change the entry and the date of the last entry to tables ZEMPLOY## and ZDEPMENT##. In a real application, the above enhancement causes the standard table maintenance for the two tables to be deactivated. Your own maintenance transactions are instead created for the table in which the fields for change logging are filled internally by the program and not directly by the user. Creation of such transactions goes beyond the scope of this course. In this course, we therefore assume that all users (correctly) fill these fields in the standard table maintenance routine. 1. Create the structure ZCHANGE##. Create a new data element for the Last_changed_by field using the domain you used for the personnel number. Use S_CHDATE as the data element for the Changed_on field. 2. Insert ZCHANGE## as an include in the tables ZEMPLOY## and ZDEPMENT##. 3. Find out what actions have been carried out on the database. 4. Start the program BC430_CHECK in transaction SE38. 68 © Copyright. All rights reserved. Lesson: Creating Transparent Tables Note: The program BC430_CHECK checks whether your solutions are correct and fills the new tables ZEMPLOY## and ZDEPMENT## with the sample data needed for later exercises. © Copyright. All rights reserved. 69 Unit 3 Solution 5 Create Tables in the ABAP Dictionary Business Example As a developer, you need to enhance the tables of the flight model with human resource management. This employee management enables the airlines to enter and evaluate data about their employees (for example, name, personnel number, salary, department, and so on) and about assignments within the organization (airline departments). You need to create tables for employee data and the airline departments. The table ZEMPLOY## (where ## is your group number) stores employee data, such as name, address, and salary. The ZDEPMENT## table contains the departments of the airline. Each department has a telephone and a fax number. Create Two Transparent Tables and Define Key Fields Create two transparent tables ZEMPLOY## and ZDEPMENT## and define their key fields. Data is maintained for three airlines. An airline has 20,000 employees and between 10 and 30 departments. Do not buffer or log the data. Note: You have to define the technical settings before you can activate the tables. 1. Create the table ZEMPLOY##, using the data in the following table: 70 Field Data Element Domain Data Type CLIENT S_MANDT MANDT Client CARRIER S_CARR_ID S_CARR_ID Carrier EMP_NUM zempnum## zempnum## FIRST_NAME S_FNAME S_FNAME First name LAST_NAME S_LNAME S_LNAME Last name DEPARTMENT zdept## zdept## CHAR 4 Dept code AREA zarea## zarea## CHAR 1 Area SALARY zsalary## zsalary## CURR 10 deci- Salary mal 2 CURRENCY S_CURRCODE S_CURR NUMC Length 10 Description Personnel number Currency © Copyright. All rights reserved. Lesson: Creating Transparent Tables a) Select the Database table radio button and enter the table name ZEMPLOY## in the corresponding input field. Choose the Create button. Enter a short text in the maintenance screen for the table. b) Enter A as the delivery class and allow Table View Maintenance. c) Select the Fields tab to go to the maintenance screen for the field definitions. Enter the field names (they do not have to be in the customer namespace). d) For the fields Client, Carrier, First name, Surname, and Currency, enter the name of the data element as shown in the Data element column. Save your entries. e) Create your own data elements for the fields Personnel number, Department code, Area, and Salary. In the Field type column, enter a name (Z<object>##) for the data element. Select the name of the data element. The data element definition appears. f) Enter a short text (component of the F1 help). On the Field Label tab page, store the texts for the field labels. g) Assign the data element a technical description (domain). On the Definition tab page, select the Domain radio button and enter a name (Z<object>##) for your domain. If the domain is predefined, activate the data element and return (using F3) to the maintenance screen for the table fields. Otherwise, select the domain name. The domain definition appears. h) Enter the details in the respective fields, such as Short Description, Data Type, and Length. Activate the domain. i) Go back to the data element definition and activate your data element. j) Go back to the field definition. Start again with step e) until all the table fields are defined. Save your table. k) Define the Reference table and Reference field for the Salary field. Select the field name and enter the following in the next dialog box: Field Value Reference table ZEMPLOY## Reference field Currency l) In the Key column, select the checkboxes to define the key fields for the ZEMPLOY## table. The fields Client, Carrier, and Personnel numberuniquely identify an entry. They must, therefore, be marked as key fields. Note: The key fields Client, Carrier, and Personnel numbermust appear in this order at the beginning of the field list. m) Activate the ZEMPLOY## table. The maintenance screen for the technical settings appears automatically. © Copyright. All rights reserved. 71 Unit 3: Database Tables Note: Since the contents of table ZEMPLOY## do not change frequently, you must enter APPLO (master data) as the Data class. Because the expected number of records in the ZEMPLOY## table is 60,000, you must select the Size category 2. The table should not be buffered or logged. n) Save the technical settings. Go back to the maintenance screen of the table using F3. The table is activated. The technical settings you must select are as follows: Field Value Data class APPL0 (master data) Size category 2 Buffering Not allowed Logging No logging 2. Create the table ZDEPMENT##, using the data in the following table: Field Data element Domain CLIENT S_MANDT MANDT Data Type Length Description Client CARRIER S_CARR_ID S_CARR_ID Airline DEPARTMENT zdept## zdept## CHAR 4 Dept code TELNR ztelnr S_PHONE CHAR 30 Telephone FAXNR zfaxnr S_PHONE CHAR 30 Fax a) Select the Database table radio button and enter the table name ZDEPMENT## in the corresponding input field. Choose the Create button. Enter a short text in the maintenance screen for the table. b) Enter A as the delivery class and allow Table View Maintenance. c) Select the Fields tab page to go to the maintenance screen for field definitions. Enter the field names (they do not have to be in the customer namespace). d) For the fields Client and Carrier, enter the name of the data element as shown in the Data element column. Save your entries. e) For the fields Department code, Telephone number, and Fax number, you should create your own data elements. In the Field type column, enter a name (Z<object>##) for the data element. Select the name of the data element. The data element definition appears. f) Enter a short text (component of the F1 help). On the Field Label tab page, store the texts for the field labels. 72 © Copyright. All rights reserved. Lesson: Creating Transparent Tables g) You also have to assign the data element a technical description (domain). On the Definition tab page, select the Domain radio button and enter a name (Z<object>##) for your domain. Otherwise, select the domain name. The domain definition appears. Note: If the domain is predefined, activate the data element and return (using F3) to the maintenance screen for the table fields. h) Define the Short Description, Data Type (CHAR), and Field Length (30). Activate the domain. i) Go back one screen (using F3) to the data element definition and activate your data element. j) Save your table. k) In the Key column, select the checkboxes to define the key fields for the ZDEPMENT## table. The fields Client, Carrier, and Department codeuniquely identify an entry. They must, therefore, be marked as key fields. l) Activate the table and define the technical settings. Since the contents of table ZDEPMENT## do not change frequently, you must enter APPL0 (master data) as the Data class. Because the expected number of records in the ZDEPMENT## table is 90, you must select the Size category 0. The table should not be buffered or logged. The technical settings you need to select are as follows: Field Value Data class APPL0 (master data) Size category 0 Buffering Not allowed Logging No logging 3. Document the Personnel numberand Department codefields. a) Double-click the data element to go to the data element definition. Switch to Change Mode by choosing Display → Change. Choose Goto → Documentation. b) Enter a text for the fields and save your entries. 4. Maintain the technical settings and then activate the table. If you have defined an amount field in the table, you must assign the corresponding currency field. a) Choose Technical Settings. b) Enter the appropriate data class and size category. c) Save your changes and return to the field view for the table. d) You still must assign currency fields for amount fields such as Salary. To do this, select the Currency/Quantity Fieldstab page. e) Enter the name of the current table in the Reference table field. f) In the Reference field, enter the name of the field you have used for the currency. © Copyright. All rights reserved. 73 Unit 3: Database Tables Create a Structure with Two Columns Changes to ZEMPLOY## and ZDEPMENT## are critical, so we want to keep track of who made the changes and when. In order to do this, you need a structure with two columns: Last_changed_byand Changed_on. Note: Changes to tables ZEMPLOY## and ZDEPMENT## are critical and must be recorded. The ABAP program maintaining the data should automatically save information about the last user to change the table data. This can be done by appending fields for the personnel number of the last person to change the entry and the date of the last entry to tables ZEMPLOY## and ZDEPMENT##. In a real application, the above enhancement causes the standard table maintenance for the two tables to be deactivated. Your own maintenance transactions are instead created for the table in which the fields for change logging are filled internally by the program and not directly by the user. Creation of such transactions goes beyond the scope of this course. In this course, we therefore assume that all users (correctly) fill these fields in the standard table maintenance routine. 1. Create the structure ZCHANGE##. Create a new data element for the Last_changed_by field using the domain you used for the personnel number. Use S_CHDATE as the data element for the Changed_on field. a) On the initial screen of the ABAP Dictionary, select the Data type and enter ZCHANGE## in the corresponding field. Choose the Create button. b) Select the Structure radio button in the next dialog box. c) Enter the field names in the Component column and the corresponding data elements in the Component Typecolumn. Create your own data element for the first field. Use the domain you created for the personnel number in the ZEMPLOY## table. d) Create one field for the personnel number and another for the date of change. Use the data element S_CHDATE for the second field. e) Activate structure ZCHANGE##. 2. Insert ZCHANGE## as an include in the tables ZEMPLOY## and ZDEPMENT##. a) Go to the maintenance screen for table ZEMPLOY##. b) Choose New rows and position the cursor on the first new field. c) Choose Edit → Include → Insert. d) In the next dialog box, enter the name ZCHANGE## and choose Continue. e) Activate the ZEMPLOY## table. Make the same entries in order to insert the substructure ZCHANGE## in the ZDEPMENT## table. 3. Find out what actions have been carried out on the database. 74 © Copyright. All rights reserved. Lesson: Creating Transparent Tables a) Display the actions that were performed on the database by choosing Utilities → Activation log. Expand the activation log and you can see there is a structure change. DB is adjusted, and the SQL statements Drop/Create Table are executed. 4. Start the program BC430_CHECK in transaction SE38. Note: The program BC430_CHECK checks whether your solutions are correct and fills the new tables ZEMPLOY## and ZDEPMENT## with the sample data needed for later exercises. a) Start transaction SE38 and execute program BC430_CHECK. © Copyright. All rights reserved. 75 Unit 3: Database Tables LESSON SUMMARY You should now be able to: 76 ● Create transparent tables ● Define INCLUDE structures ● Create tables in the ABAP Dictionary © Copyright. All rights reserved. Unit 3 Lesson 2 Defining Cluster Tables and Pooled Tables LESSON OVERVIEW This lesson explains pooled and cluster tables. Business Example In the performance checks of some applications, you come across SELECT statements that access tables in the database other than those referred to in the respective ABAP source code. In the ABAP source code, the developer has used pooled and cluster tables. For this reason, you require an understanding of the following: ● Pooled tables ● Cluster tables LESSON OBJECTIVES After completing this lesson, you will be able to: ● Define cluster tables and pooled tables Cluster Tables and Pooled Tables Figure 25: Overview of the DB Table Types © Copyright. All rights reserved. 77 Unit 3: Database Tables In addition to transparent tables, where the definition in the ABAP Dictionary and the database are identical, there are pooled and cluster tables in the SAP system. Pooled and cluster tables are characterized by the fact that several tables logically defined in the ABAP Dictionary are combined in a physical database table (table pool or cluster). SAP uses the pool tables and cluster tables mostly for system-internal data. Business data should be stored in transparent tables. Cluster Tables Figure 26: Cluster Tables In cluster tables, you store functionally dependent data, which is divided among different tables, in one database table. Accordingly, the intersection of the key fields of the cluster tables form the key of the table cluster, known as the cluster key. The data dependent on one cluster key is stored in the VARDATA field of the table cluster. If the VARDATA field does not have the capacity to take on all the dependent data, the database interface creates an overflow record. The PAGNO field guarantees the uniqueness within the table cluster. The database interface compresses the content of the VARDATA field. Accordingly, the VARDATA field contains a description for decompressing its data. The TIMESTAMP and PAGELG fields contain administrative information. 78 © Copyright. All rights reserved. Lesson: Defining Cluster Tables and Pooled Tables Pooled Tables Figure 27: Pooled Tables A table pool, as opposed to a table cluster, stores data records from the tables defined in the ABAP Dictionary that are not dependent on one another. You would like to combine small SAP tables in one database table. In the example in the figure, you can see there are no common key fields between TABA and TABB. Despite this, the TABAB table pool stores the data records from TABA and TABB. The key for a data record of the TABAB table pool consists of both the TABNAME and VARKEY fields. The TABNAME field assumes the name of the pooled table. The VARKEY field consists of the concatenation of the key fields of the pooled table. For this reason, the key fields of a pooled table must be of the type C. The database interface stores the non-key fields of the pooled tables in an unstructured way, in the VARDATA field in compressed form. The DATALN field contains the length of the VARDATA field. In the pooled table, the technical settings are exactly the same as transparent table. The only addition is the Convert to transparent tableindicator. You can convert the pooled table into a transparent table with this indicator. © Copyright. All rights reserved. 79 Unit 3: Database Tables Advantages and Disadvantages of Pooled and Cluster Tables Figure 28: Advantages and Disadvantages of Pooled and Cluster Tables The primary advantage of pooled and cluster tables is that the data can be stored in compressed form in the database. This reduces the memory required as well as the network load. Combining tables into pooled tables or cluster tables results in fewer tables and fewer table fields (due to data compression). The result is that fewer different SQL statements need to be carried out. Because pooled and cluster tables are not stored as separate tables in the database, administration is simpler. With cluster tables, functionally dependent data is read together, which results in fewer database accesses. The main disadvantage is that database functionality is restricted. It is not possible for non-key fields to be created as an index. There are neither primary indices nor indices on a subset of the key fields. The use of database views or ABAP joins is also ruled out, as are table appends. You can access the data in pooled or cluster tables only by OPEN SQL (not Native SQL). For pooled tables, only the WHERE conditions for key fields are transferred to the database. In the case of cluster tables, only the WHERE conditions for the fields of the cluster key (subset of the key fields) are transferred. ORDER BY (or GROUP BY) clauses are not transferred for non-key fields. You need longer keys than semantically necessary for pooled tables. LESSON SUMMARY You should now be able to: ● 80 Define cluster tables and pooled tables © Copyright. All rights reserved. Unit 3 Learning Assessment 1. You cannot access the data contained in a pooled or cluster table with OPEN SQL. Determine whether this statement is true or false. X True X False 2. Which of the following ABAP dictionary objects stores data permanently in the database? Choose the correct answer. X A Tables X B Structure X C Data element X D Domain 3. The ______________ key is a combination of columns that uniquely identifies a data record. Choose the correct answer. X A secondary X B primary X C domain X D data 4. ________________ determine the storage requirements and the access behavior of database tables. Choose the correct answer. X A Internal table types X B Technical settings X C Foreign keys © Copyright. All rights reserved. 81 Unit 3: Learning Assessment 5. Master data is data that is seldom modified; for example, customer data, such as customer name, address, and so on. Determine whether this statement is true or false. X True X False 6. In cluster tables, you store functionally dependent data among different tables into the table cluster. The data dependent on the cluster key is stored in the _____________________ field of the table cluster. Choose the correct answer. X A cluster data X B vardata X C table data 7. A table pool, as opposed to table clusters, stores data records from tables that are not dependent on one another. Determine whether this statement is true or false. X True X False 8. The primary advantage of pooled and cluster tables is that the data can be stored in compressed form in the database. This reduces the memory required as well as the network load. Determine whether this statement is true or false. 82 X True X False © Copyright. All rights reserved. Unit 3 Learning Assessment - Answers 1. You cannot access the data contained in a pooled or cluster table with OPEN SQL. Determine whether this statement is true or false. X True X False 2. Which of the following ABAP dictionary objects stores data permanently in the database? Choose the correct answer. X A Tables X B Structure X C Data element X D Domain 3. The ______________ key is a combination of columns that uniquely identifies a data record. Choose the correct answer. X A secondary X B primary X C domain X D data © Copyright. All rights reserved. 83 Unit 3: Learning Assessment - Answers 4. ________________ determine the storage requirements and the access behavior of database tables. Choose the correct answer. X A Internal table types X B Technical settings X C Foreign keys 5. Master data is data that is seldom modified; for example, customer data, such as customer name, address, and so on. Determine whether this statement is true or false. X True X False 6. In cluster tables, you store functionally dependent data among different tables into the table cluster. The data dependent on the cluster key is stored in the _____________________ field of the table cluster. Choose the correct answer. X A cluster data X B vardata X C table data 7. A table pool, as opposed to table clusters, stores data records from tables that are not dependent on one another. Determine whether this statement is true or false. X True X False 8. The primary advantage of pooled and cluster tables is that the data can be stored in compressed form in the database. This reduces the memory required as well as the network load. Determine whether this statement is true or false. 84 X True X False © Copyright. All rights reserved. UNIT 4 Performance During Table Access Lesson 1 Creating Database Table Indexes Exercise 6: Create Table Indexes 86 91 Lesson 2 Setting Up Table Buffering Exercise 7: Set Up Table Buffering 95 109 UNIT OBJECTIVES ● Describe the use of database indexes ● Create database indexes in the ABAP Dictionary ● Apply the settings for table buffering ● Describe buffering types ● Set up table buffering © Copyright. All rights reserved. 85 Unit 4 Lesson 1 Creating Database Table Indexes LESSON OVERVIEW This lesson explains the structure and usage of database indexes. Business Example Some transactions contain select statements in their applications, which cause very long runtimes. You need to improve the performance without changing the program. For this reason, you require an understanding of the following: ● How to create indexes ● How to use indexes LESSON OBJECTIVES After completing this lesson, you will be able to: 86 ● Describe the use of database indexes ● Create database indexes in the ABAP Dictionary © Copyright. All rights reserved. Lesson: Creating Database Table Indexes Database Access Using Indexes Figure 29: Database Access Using Indexes You can create an index to speed up the selection of data records from a table. An index can be considered to be a copy of a database table reduced to certain fields. This copy stores the data in sorted form. Sorting the data enables fast access to the records of the table (for example, using a binary search). An index contains those fields of the database table which are relevant for database queries. The index also contains a pointer from the index entry to the corresponding table entry so that all the field contents can be read. The following points are important when indexes are created: ● An index should be as small as possible. Use only those fields that are frequently used in the WHERE clause of SELECT statements. Note: Note the index field order. The most frequently selected fields should be at the first positions in the index. Note the field order in the WHERE clause of SELECT statements. The field order should match the index field order. This ensures that the index is used properly by the database system. ● An index must contain significant fields only. A field is significant if it contains considerable data content that can help to identify a table row. ● Whenever you insert, update, or delete database content, the system must adjust all of the assigned indexes. This is time-consuming. Tables whose contents are frequently changed must not have too many indexes. © Copyright. All rights reserved. 87 Unit 4: Performance During Table Access ● Indexes on a table are as disjunct as possible. Database Indexes Figure 30: Access with Indexes The database optimizer decides which index on the table should be used by the database to access data records. Each database table has one primary index and an arbitrary number of secondary indexes and extension indexes. The differences between the different types of index are as follows: ● Primary index The primary index contains the key fields of the table. The primary index is always unique. When a table is activated for the first time, the system automatically creates the primary index. ● Secondary index Secondary indexes are useful if a large table is often accessed with a selection on fields other than the table's key fields. Most of the secondary indexes are non-unique but unique secondary indexes are also possible. ● Extension index An extension index is part of the Enhancement Framework. It is an extension of the standard. In the past, it was very common for customers to add their own secondary indexes to SAP tables. However, during upgrade, these customer-added indexes are deleted and need to be re-created in a system after the upgrade. Extension indexes are automatically copied over during upgrades and no modification adjustment takes place. 88 © Copyright. All rights reserved. Lesson: Creating Database Table Indexes Table indexes have a three-character ID. 0 is reserved for the primary index. Customers can create their own indexes on SAP tables. The IDs of customer indexes must begin with Y or Z. Steps to Create an Index Figure 31: Creating an Index The steps to create a secondary index and extension index are the same. Go to the ABAP Dictionary (SE11) and enter a table name. Choose the Indexes button, then the Create button, and select the index fields. When you create an index, you can choose between a non-unique index and a unique index. You can also specify whether it should be created on the database when it is activated. Some indexes only result in a gain in performance for certain database systems. You can, therefore, specify a list of database systems when you define an index. The index is then created on the specified database systems only when activated. Uses of unique indexes are as follows: ● ● The fields of a unique index identify each record in the table uniquely. When you insert or update table data, the system ensures that there are no duplicate entries in the database table. The performance improvements brought about by indexes strongly depend on the underlying database system. For this purpose, you can specify the database systems on which the index is created. © Copyright. All rights reserved. 89 Unit 4: Performance During Table Access 90 © Copyright. All rights reserved. Unit 4 Exercise 6 Create Table Indexes Business Example As part of their daily work, airline employees need quick access to the data contained in the employee administration tables. In this exercise, you will accelerate access to the data in these tables. The combination of first and last names is often used to access an employee’s HR data. Last name is used often (specified in the access) than the first name. An index must be created for this purpose. Create an Index for First and Last Names Create an index that supports access to the combination of first names and last names. Make sure that the index is created on the database. 1. Create an index for the ZEMPLOY## table. It has to contain the fields Client, Last name, and First name. Create an Index that Supports Business Areas Create an index for the employee table that supports selections via the business area. Make sure that this index is created only on the MAXDB and SQL Server database systems. Note: Using an index for the business areas might increase performance when accessing the employee data, for example, if all the pilots of an airline are frequently selected. When the performance was measured on different database systems, improvements were recorded only with MAXDB and SQL Server database systems. 1. Create an index for the table ZEMPLOY## using the fields Client, Carrier, and Area. 2. Create the new index only on the MAXDB and SQL Server database systems. © Copyright. All rights reserved. 91 Unit 4 Solution 6 Create Table Indexes Business Example As part of their daily work, airline employees need quick access to the data contained in the employee administration tables. In this exercise, you will accelerate access to the data in these tables. The combination of first and last names is often used to access an employee’s HR data. Last name is used often (specified in the access) than the first name. An index must be created for this purpose. Create an Index for First and Last Names Create an index that supports access to the combination of first names and last names. Make sure that the index is created on the database. 1. Create an index for the ZEMPLOY## table. It has to contain the fields Client, Last name, and First name. a) Run transaction SE11. Enter ZEMPLOY## in the Database table field and choose Display. b) On the Dictionary: Display Tablescreen, choose Indexes. c) In the Indices for Table ZEMPLOY##dialog box, choose Create → Create Index. d) In the dialog box, enter a three-character index ID NAM and choose Continue. e) Enter a short description in the maintenance screen of the index. f) Choose Table Fields. A list of all the fields in the table appears. g) Select the fields CLIENT, LAST_NAME, and FIRST_NAME and choose Copy. Arrange the fields in the order specified. Note: If the First name field comes before the Last name field, you have to change the order of the fields. Place the cursor on the line with the First name field and choose Cut. Then place the cursor on the first free line after the Last name field and choose Paste. h) Select the settings Non-unique index and Index on all database systems. 92 © Copyright. All rights reserved. Lesson: Creating Database Table Indexes Note: The index is certainly not unique, as there can be employees with the same first and last names. There is also no reason to create the index only on certain database systems. i) Activate the index. The index is automatically created on the database, which you can see under Status. Create an Index that Supports Business Areas Create an index for the employee table that supports selections via the business area. Make sure that this index is created only on the MAXDB and SQL Server database systems. Note: Using an index for the business areas might increase performance when accessing the employee data, for example, if all the pilots of an airline are frequently selected. When the performance was measured on different database systems, improvements were recorded only with MAXDB and SQL Server database systems. 1. Create an index for the table ZEMPLOY## using the fields Client, Carrier, and Area. a) Display the table ZEMPLOY## and choose the Indexes button. On the Indices for Table screen, choose Create, then choose Create index, and enter the name ARE. Note: This is not a unique index. The index is created on the database only if your training system is running on one of the selected database systems. 2. Create the new index only on the MAXDB and SQL Server database systems. a) Enter a short description and select the For selected database systemscheckbox. b) Choose the arrow icon in this line. Choose Selection list. Select the identifiers for the database systems ADA for Adabas and MSS for SQL Server from the list. c) Choose Continue. d) Choose the Table Fields button and select CLIENT, CARRIER, and AREA. Choose Continue. e) Activate the index. Hint: Do not run BC430_CHECK. You will perform a check of this exercise later at the end of the unit, together with other exercises. © Copyright. All rights reserved. 93 Unit 4: Performance During Table Access LESSON SUMMARY You should now be able to: 94 ● Describe the use of database indexes ● Create database indexes in the ABAP Dictionary © Copyright. All rights reserved. Unit 4 Lesson 2 Setting Up Table Buffering LESSON OVERVIEW This lesson explains how to improve database performance using table buffering. Business Example You need to evaluate the benefits of using buffers. For this reason, you require an understanding of the following: ● Buffer synchronization ● Table buffering LESSON OBJECTIVES After completing this lesson, you will be able to: ● Apply the settings for table buffering ● Describe buffering types ● Set up table buffering © Copyright. All rights reserved. 95 Unit 4: Performance During Table Access Table Buffering Figure 32: Data Access Using the Buffer Table buffering increases performance when the records of the table are read. The records of a buffered table are read directly from the local buffer of the application server on which the accessing transaction is running when the table is accessed. The table buffering eliminates time-consuming database accesses. The table access performance is improved by a factor of 10 to 100. The increase in speed depends on the structure of the table and on the exact system configuration. Buffering, therefore, can greatly increase system performance. Buffered table records are stored in the main memory of the application server. If the memory is exhausted, the system discards the table record that was accessed least recently. When you enter /$TAB in the command field, the system resets the table buffers on the corresponding application server. Only use this command if there are inconsistencies in the buffer. In large systems, it can take several hours to fill the buffers. The performance is reduced during this time. Buffering Types When a record of the table is accessed, the buffering type determines which records of the table are loaded into the buffer of the application server. The buffering types are as follows: ● Full buffering When a record of the table is accessed, all the records of the table are loaded into the buffer. 96 © Copyright. All rights reserved. Lesson: Setting Up Table Buffering ● Generic buffering When a record of the table is accessed, all the records whose left-justified part of the key are the same are loaded into the buffer. ● Single-record buffering Only the record that was accessed is loaded into the buffer. Full Buffering Figure 33: Full Buffering With full buffering, the table is either completely in the buffer or not at all. Whenever a record of the table is accessed, all of the table records are loaded into the buffer. When you decide whether to fully buffer a table, you must take the table size, the number of read accesses, and the number of write accesses into consideration. The smaller the table is, the more frequently it is read, and the less frequently it is written to, the better it is to fully buffer the table. Full buffering is also recommended for tables that have frequent accesses to records that do not exist. The buffer can quickly check if a record exists, as all the records of the table reside in the buffer. The data records are stored in the buffer sorted by table primary key. When you access the data with SELECT, only fields up to the last specified key field can be used for the access. For such accesses you should specify a left-justified part of the key that is as large as possible. For example, if the first key field is not defined, the entire table is scanned in the buffer. Under these circumstances, direct access to the database could be more efficient if a suitable secondary index exists. © Copyright. All rights reserved. 97 Unit 4: Performance During Table Access Generic Buffering Figure 34: Generic Buffering When one record of the table is accessed, all the records whose generic key fields agree with this record are loaded into the buffer. The generic key is a left-justified part of the primary table key. The generic key must be selected so that the generic areas are not too small, which would result in too many generic areas. Full buffering is preferred for the table that has few records for each generic area. If you choose a large generic key, too much data will be invalidated if there are changes to table entries, which would have a negative effect on the performance. A table can be generically buffered if only certain generic areas of the table are usually needed for processing. Client-dependent, fully buffered tables are automatically generically buffered. The client field is the generic key. This is based on the assumption that not all of the clients are actually used on one application server. Language-dependent tables are an example of generic buffering. The generic key includes all the key fields up to and including the language field. The generic areas are managed in the buffer as independent objects. The generic areas are managed in the same way as fully buffered tables. 98 © Copyright. All rights reserved. Lesson: Setting Up Table Buffering Single-Record Buffering Figure 35: Single-Record Buffering In single-record buffering, the records that are actually accessed with SELECT SINGLE are loaded into the buffer. Single-record buffering is recommended particularly for large tables in which only a few records are accessed repeatedly with SELECT SINGLE. All the accesses to the table that do not use SELECT SINGLE bypass the buffer and directly access the database. If you access a record that was not yet buffered using SELECT SINGLE, there is a database access to load the record. If the table does not contain a record with the specified key, this record is recorded in the buffer as non-existent. This prevents a further database access if you make another access with the same key. Differences between single-record buffering and the other buffering types are as follows: ● Single-record buffering saves storage space in the buffer compared to generic and full buffering. ● The overhead for buffer administration is higher than for generic or full buffering. ● Considerably more database accesses are necessary to load the records than for the other buffering types. You only need one database access to load a table with full buffering, but you need several database accesses with single-record buffering. Therefore, full buffering is generally preferable for small tables that are frequently accessed. © Copyright. All rights reserved. 99 Unit 4: Performance During Table Access Table Buffering Settings Figure 36: Table Buffering Settings To define table buffering, go to the ABAP Dictionary (transaction SE11), enter the table name, and choose Technical Settings. Choose the appropriate buffering option and buffering type. Alternatively, you can use transaction SE13. Buffer Synchronization Figure 37: Table Buffering The SAP system manages and synchronizes the buffers on the individual application servers. If an application program accesses data in a table, the database interfaces determine whether this data is located in the buffer of the application server. In this case, the data is read directly 100 © Copyright. All rights reserved. Lesson: Setting Up Table Buffering from the buffer. If the data is not in the buffer of the application server, it is read directly from the database and loaded into the buffer. Buffer Synchronization 1 Figure 38: Buffer Synchronization 1 As the buffers reside locally on the application servers, buffers must be synchronized after data has been modified in a buffered table. Synchronization takes place at fixed time intervals that can be set in the system profile. The corresponding parameter is rdisp/buffertime and it defines the length of the interval in seconds. The value must lie between 60 and 3600. We recommend a value between 60 and 240. Assume a system with two application servers. The following example shows how the local buffers of the system are synchronized: ● Starting situation Neither server has accessed the records of the table SCARR yet to fully buffer them. Therefore, the table does not yet reside in the local buffers of the two servers. ● Timepoint 1 A program running on Server 1 reads records from the table SCARR on the database. ● Timepoint 2 SCARR is fully loaded into the local buffer of Server 1. The local buffer of this server is now used for access from Server 1 to the data in the SCARR table. © Copyright. All rights reserved. 101 Unit 4: Performance During Table Access Buffer Synchronization 2 Figure 39: Buffer Synchronization 2 The next two timepoints of the buffer synchronization process are as follows: ● Timepoint 3 A program on Server 2 accesses records in the table. Since the table does not yet reside in the local buffer of Server 2, the records are read directly from the database. ● Timepoint 4 The SCARR table is loaded into the local buffer of Server 2. Therefore, Server 2 also uses its local buffer to access its data when it next reads the SCARR table. 102 © Copyright. All rights reserved. Lesson: Setting Up Table Buffering Buffer Synchronization 3 Figure 40: Buffer Synchronization 3 The next three timepoints of the buffer synchronization process are as follows: ● Timepoint 5 A program on Server 1 deletes records from the SCARR table and updates the database. ● Timepoint 6 Server 1 writes an entry in the synchronization table. ● Timepoint 7 Server 1 updates its local buffer. © Copyright. All rights reserved. 103 Unit 4: Performance During Table Access Buffer Synchronization 4 Figure 41: Buffer Synchronization 4 The next timepoint of the buffer synchronization process is as follows: ● Timepoint 8 A program on Server 2 accesses the deleted records. Since the SCARR table resides in its local buffer, the access uses this local buffer. Therefore, Server 2 finds the records although they no longer exist in the database table. If the same access were made from an application program to Server 1, this program would recognize that the records no longer exist. At this time, the behavior of an application program depends on the server on which it is running. 104 © Copyright. All rights reserved. Lesson: Setting Up Table Buffering Buffer Synchronization 5 Figure 42: Buffer Synchronization 5 The next two timepoints of the buffer synchronization process are as follows: ● Timepoint 9 The buffer synchronization refresh interval (as defined in the system profile) has elapsed. Both servers look in the synchronization table to see if another server has modified one of the tables in its local buffer in the meantime. ● Timepoint 10 Server 2 finds that the SCARR table has been modified by Server 1 in the meantime. Server 2 therefore invalidates the table in its local buffer. The next access from Server 2 to data in the SCARR table, therefore, uses the database. Server 1 does not have to invalidate the table in its buffer, as it is the only changer of the SCARR table itself. Server 1, therefore, uses its local buffer again the next time it accesses records in the SCARR table. © Copyright. All rights reserved. 105 Unit 4: Performance During Table Access Buffer Synchronization 6 Figure 43: Buffer Synchronization 6 The last two timepoints of the buffer synchronization process are as follows: ● Timepoint 11 Server 2 again accesses records in the SCARR table. Since SCARR is invalidated in the local buffer of Server 2, the access uses the database. ● Timepoint 12 The table is reloaded into the local buffer of Server 2. The information regarding the SCARR table is now consistent again on the servers and the database. Advantages and Disadvantages of Table Buffering Advantages and disadvantages of buffer synchronization are as follows: ● Advantage The load on the network is kept to a minimum. If the buffers were to be synchronized immediately after each modification, each server would have to inform all other servers about each modification to a buffered table through the network. This would have a negative effect on performance. ● Disadvantage The local buffers of the application servers can contain obsolete data between the moments of synchronization. 106 © Copyright. All rights reserved. Lesson: Setting Up Table Buffering Table Buffering: Summary ● Only those tables that are written very infrequently (read mostly), or those for which temporary inconsistencies are of no importance, may be buffered. ● Tables whose entries change frequently should not be buffered. Otherwise, there is constant invalidation and reloads from the database. Note: For more information about performance tuning using table buffering, refer to the course BC490: ABAP Performance Tuning. Decision Tree for Buffering Figure 44: Decision Tree for Buffering You should use the decision-making tree for buffering tables to help you in your system. © Copyright. All rights reserved. 107 Unit 4: Performance During Table Access 108 © Copyright. All rights reserved. Unit 4 Exercise 7 Set Up Table Buffering Business Example As part of their daily work, airline employees need quick access to the data contained in the employee administration tables. For this reason, access to the data in these tables should be accelerated. To set up a flight crew, you have to assign employees (pilots and stewards) to flights. You need to create a table in which the employees involved and their functions can be entered for each flight. Copy a Table to Another Table and Replace a Data Element 1. Copy the table SFLCREW to the table ZFLCREW##. Replace the existing data element for the employee number with your own data element. Maintain Settings for Buffering Maintain the settings for buffering the ZDEPMENT## and ZFLCREW## tables. These tables are accessed very frequently. Data records are read repeatedly from these tables. 1. Maintain the settings for buffering the ZDEPMENT## table in the Technical Settings. Note: Since the contents of table ZDEPMENT## are rarely changed but frequently read, it is advisable to buffer the table. 2. Maintain the settings for buffering the ZFLCREW## table in the Technical Settings. Note: The data in table ZFLCREW## is often read repeatedly and is rarely changed. Usually, only the data for one airline is needed on an application server. You should therefore buffer the table generically with the generic key Client and Airline Code. 3. Execute the program BC430_CHECK in transaction SE38. BC430_CHECK checks whether all your solutions in this unit are correct and fills the new table ZFLCREW## with the sample data needed for later exercises. © Copyright. All rights reserved. 109 Unit 4 Solution 7 Set Up Table Buffering Business Example As part of their daily work, airline employees need quick access to the data contained in the employee administration tables. For this reason, access to the data in these tables should be accelerated. To set up a flight crew, you have to assign employees (pilots and stewards) to flights. You need to create a table in which the employees involved and their functions can be entered for each flight. Copy a Table to Another Table and Replace a Data Element 1. Copy the table SFLCREW to the table ZFLCREW##. Replace the existing data element for the employee number with your own data element. a) On the initial screen of the ABAP Dictionary, enter SFLCREW in the Database table field. b) Choose Copy. c) In the dialog box, enter the name ZFLCREW## in the Table field at the bottom and choose Continue. Save as a local object. d) In Change Mode, go to the table maintenance screen and replace the data element SEMP_NUM with the data element you created for the employee number ZEMPNUM##. e) Activate the table. Maintain Settings for Buffering Maintain the settings for buffering the ZDEPMENT## and ZFLCREW## tables. These tables are accessed very frequently. Data records are read repeatedly from these tables. 1. Maintain the settings for buffering the ZDEPMENT## table in the Technical Settings. Note: Since the contents of table ZDEPMENT## are rarely changed but frequently read, it is advisable to buffer the table. a) Run transaction SE11, enter ZDEPMENT## in the Database table field and choose Change. b) On the Dictionary: Change Tablescreen, choose Technical Settings. 110 © Copyright. All rights reserved. Lesson: Setting Up Table Buffering Note: Alternatively, you can use transaction SE13 and choose Change. c) Select the Buffering switched onradio button. As the table is small and rarely changed, select the Fully buffered checkbox. d) Activate the technical settings for table ZDEPMENT#. 2. Maintain the settings for buffering the ZFLCREW## table in the Technical Settings. Note: The data in table ZFLCREW## is often read repeatedly and is rarely changed. Usually, only the data for one airline is needed on an application server. You should therefore buffer the table generically with the generic key Client and Airline Code. a) Run transaction SE11, enter ZFLCREW## in the Database table field and choose Change. b) On the Dictionary: Change Tablescreen, choose Technical Settings. Note: Alternatively, you can use transaction SE13 and choose Change. c) Select the Buffering switched onradio button. Select the Generic bufferingcheckbox and choose 2 as the number of generic key fields. d) Activate the technical settings for the table ZFLCREW##. 3. Execute the program BC430_CHECK in transaction SE38. BC430_CHECK checks whether all your solutions in this unit are correct and fills the new table ZFLCREW## with the sample data needed for later exercises. © Copyright. All rights reserved. 111 Unit 4: Performance During Table Access LESSON SUMMARY You should now be able to: 112 ● Apply the settings for table buffering ● Describe buffering types ● Set up table buffering © Copyright. All rights reserved. Unit 4 Learning Assessment 1. An index can be regarded as a copy of a database table reduced to certain fields. Determine whether this statement is true or false. X True X False 2. Which index is automatically created in the database when the table is activated for the first time? Choose the correct answer. X A Secondary index X B Primary index X C Extension index 3. If a large table is accessed so frequently that it is not possible to use the primary index, you should create secondary indexes for the table. Determine whether this statement is true or false. X True X False 4. The _____________ decides which table index is used by the database system to access data records. Choose the correct answer. X A database optimizer X B database table X C table buffers © Copyright. All rights reserved. 113 Unit 4: Learning Assessment 5. Table buffering increases performance when the records of the table are read. Determine whether this statement is true or false. X True X False 6. Generic buffering is recommended, particularly for large tables, in which only a few records are accessed repeatedly with SELECT SINGLE. Determine whether this statement is true or false. X True X False 7. With generic buffering, the generic key is a left-justified part of the primary key of the table. Determine whether this statement is true or false. X True X False 8. _____________ buffering is advisable for tables that have frequent access to records that do not exist. Choose the correct answer. X A Full X B Generic X C Single-record 9. Buffers reside locally on the application servers, and must be synchronized after data has been modified in a buffered table. Synchronization takes place at fixed time intervals and can be set in the system profile. Determine whether this statement is true or false. X True X False 10. Table indexes have a three-character ID and 0 is reserved for the primary index. Determine whether this statement is true or false. 114 X True X False © Copyright. All rights reserved. Unit 4 Learning Assessment - Answers 1. An index can be regarded as a copy of a database table reduced to certain fields. Determine whether this statement is true or false. X True X False 2. Which index is automatically created in the database when the table is activated for the first time? Choose the correct answer. X A Secondary index X B Primary index X C Extension index 3. If a large table is accessed so frequently that it is not possible to use the primary index, you should create secondary indexes for the table. Determine whether this statement is true or false. X True X False 4. The _____________ decides which table index is used by the database system to access data records. Choose the correct answer. X A database optimizer X B database table X C table buffers © Copyright. All rights reserved. 115 Unit 4: Learning Assessment - Answers 5. Table buffering increases performance when the records of the table are read. Determine whether this statement is true or false. X True X False 6. Generic buffering is recommended, particularly for large tables, in which only a few records are accessed repeatedly with SELECT SINGLE. Determine whether this statement is true or false. X True X False 7. With generic buffering, the generic key is a left-justified part of the primary key of the table. Determine whether this statement is true or false. X True X False 8. _____________ buffering is advisable for tables that have frequent access to records that do not exist. Choose the correct answer. X A Full X B Generic X C Single-record 9. Buffers reside locally on the application servers, and must be synchronized after data has been modified in a buffered table. Synchronization takes place at fixed time intervals and can be set in the system profile. Determine whether this statement is true or false. 116 X True X False © Copyright. All rights reserved. Unit 4: Learning Assessment - Answers 10. Table indexes have a three-character ID and 0 is reserved for the primary index. Determine whether this statement is true or false. X True X False © Copyright. All rights reserved. 117 Unit 4: Learning Assessment - Answers 118 © Copyright. All rights reserved. UNIT 5 Input Checks Lesson 1 Creating Fixed Values Exercise 8: Create Fixed Values 120 123 Lesson 2 Defining Foreign Keys to Perform Input Checks Exercise 9: Perform Input Checks to Ensure Data Consistency 126 135 Lesson 3 Creating Text Tables Exercise 10: Create a Text Table 146 149 UNIT OBJECTIVES ● Create fixed values for a domain ● Define foreign keys to ensure data consistency ● Create a text table © Copyright. All rights reserved. 119 Unit 5 Lesson 1 Creating Fixed Values LESSON OVERVIEW This lesson explains how to create and work with fixed values. Business Example When entering values in your application, further checks on the screens occur without additional ABAP coding. For this reason, you require an understanding of the following: ● How to create and use fixed values ● How to use foreign keys LESSON OBJECTIVES After completing this lesson, you will be able to: ● Create fixed values for a domain Fixed Values Figure 45: Fixed Values A domain describes the value range of a field by specifying its data type and field length. If only a limited set of values is allowed, these can be defined as fixed values. 120 © Copyright. All rights reserved. Lesson: Creating Fixed Values You can define the value range of the domain by specifying fixed values. Fixed values are used as value help (F4) and input validation for the fields on the screen. Fixed values can either be listed individually or defined as an interval. You can create appends for fixed values. A fixed value append is assigned to exactly one domain. A domain can have multiple fixed value appends. Fixed value appends are modification-free enhancements of the SAP standard. The system automatically copies over fixed value appends during upgrades. © Copyright. All rights reserved. 121 Unit 5: Input Checks 122 © Copyright. All rights reserved. Unit 5 Exercise 8 Create Fixed Values Business Example When you enter or change the employee master data, only valid areas should be allowed. The employees of the airlines are divided into administration personnel (A), flight personnel (F), and service personnel (S). They are assigned to activity areas A, F, or S accordingly. You need to enter the fixed values for administration personnel, flight personnel, and service personnel and activate your domain. 1. Maintain fixed values in the domain for the AREA field in ZEMPLOY##, using the data in the table below: Fixed value Short Description A Administration personnel F Flight personnel S Service personnel Hint: Do not run BC430_CHECK now. You will perform a check of this exercise at the end of the unit, together with other exercises. © Copyright. All rights reserved. 123 Unit 5 Solution 8 Create Fixed Values Business Example When you enter or change the employee master data, only valid areas should be allowed. The employees of the airlines are divided into administration personnel (A), flight personnel (F), and service personnel (S). They are assigned to activity areas A, F, or S accordingly. You need to enter the fixed values for administration personnel, flight personnel, and service personnel and activate your domain. 1. Maintain fixed values in the domain for the AREA field in ZEMPLOY##, using the data in the table below: Fixed value Short Description A Administration personnel F Flight personnel S Service personnel a) On the ABAP Dictionary: Initial Screen, select Database tables and enter the value ZEMPLOY## in the corresponding field. Choose Display. b) In the list of fields, go to the field AREA and double-click the data element ZAREA##. c) Choose the Display <-> Change button to change the domain. d) Choose the Value Range tab and enter the fixed values from the table. e) Activate the domain. f) Go back to the maintenance screen for the ZEMPLOY## table. g) Choose Utilities → Table Contents → Create Entries for table ZEMPLOY##. The input help of the AREA field should now function as intended. Hint: Do not run BC430_CHECK now. You will perform a check of this exercise at the end of the unit, together with other exercises. 124 © Copyright. All rights reserved. Lesson: Creating Fixed Values LESSON SUMMARY You should now be able to: ● Create fixed values for a domain © Copyright. All rights reserved. 125 Unit 5 Lesson 2 Defining Foreign Keys to Perform Input Checks LESSON OVERVIEW This lesson explains how to define and use foreign keys. This lesson also demonstrates how foreign keys ensure data consistency through input checks. Business Example You need to ensure consistency through input checks. For this reason, you require an understanding of the following: ● How to define and use foreign keys LESSON OBJECTIVES After completing this lesson, you will be able to: ● Define foreign keys to ensure data consistency Definition of Foreign Keys Figure 46: Inserting a Data Record A customer needs to book a flight with American Airlines. This flight with flight number 0017 is to be on November 22, 1997. The booking should be made at counter 8. Table SBOOK contains all the flight bookings of the airlines. Table SCOUNTER contains all the valid counters 126 © Copyright. All rights reserved. Lesson: Defining Foreign Keys to Perform Input Checks of the airlines. If an entry is made in field COUNTER of table SBOOK, the program must make sure that only valid counters can be entered. Violation of the Foreign Key Check Figure 47: Violation of the Foreign Key Check The flight cannot be booked because American Airlines (AA) does not have a counter 8. No data record is selected in table SCOUNTER for the entries in the example. The entry for table SBOOK is rejected. In the ABAP Dictionary, such relationships between two tables are called foreign keys and must be defined explicitly for the fields. Foreign keys are used to ensure that the data is consistent. Data that has been entered is checked against existing data to ensure that it is consistent. © Copyright. All rights reserved. 127 Unit 5: Input Checks Foreign Key Fields and Check Fields Figure 48: Foreign Key Fields and Check Fields For example, the foreign key table is table SBOOK and the check table is table SCOUNTER. The foreign key ensures that only valid counters of carriers can be assigned to a booking. Each counter is identified by the following key fields in the table SCOUNTER: ● CLIENT ● CARRID ● COUNTNUM To define the foreign key, these fields are assigned to the fields of the foreign key table (foreign key fields) with which the input to be checked is entered on the screen. MANDT, CARRID, and COUNTER are these fields of table SBOOK. The system accepts the entries if the key fields represent a valid counter. The foreign key is defined for field SBOOK-COUNTER. Therefore, the COUNTER field is called the check field for the foreign key. A foreign key is defined for field COUNTER, table SBOOK, resulting in the following field assignment: Table 2: Foreign Key Field Assignment 128 Check Table Foreign Key Table SCOUNTER-CLIENT SBOOK-MANDT SCOUNTER-CARRID SBOOK-CARRID SCOUNTER-COUNTNUM SBOOK-COUNTER © Copyright. All rights reserved. Lesson: Defining Foreign Keys to Perform Input Checks Foreign Key Requirements Figure 49: Data Consistency Through Foreign Keys A combination of fields in a table is called a foreign key, if this field combination is the primary key of another table. A foreign key links two tables. The check table is a table whose key fields are checked. This table is also called the referenced table. The field of the foreign key table to be checked is called the check field. Foreign keys are only checked by the system during screen input and screen value help. In contrast to that, ABAP programs are able to modify database table content ignoring foreign keys. For example, a new entry is to be made in table SPFLI (flight schedule). There is a check whether the airline carrier entered is stored in table SCARR (carrier) for field SPFLI-CARRID. The record is only copied to table SPFLI (foreign key table) if this is the case. A foreign key is defined for field SPFLI-CARRID (check field); for example, the checks are on this field. The corresponding check table is table SCARR with the primary key fields CLIENT and CARRID. © Copyright. All rights reserved. 129 Unit 5: Input Checks Foreign Key Definitions and Domains Figure 50: Foreign Key Definitions and Domains In the ABAP Dictionary, the same domain is required for the check field and referenced key field of the check table so that you do not compare fields with different data types and field lengths. Domain equality is essential. Different data elements can be used, but they must refer to the same domain. The requirement for domain equality is only valid for the check field. For all other foreign key fields, it is sufficient if the data type and the field length are equal. Nevertheless, you should strive for domain equality. In this case, the foreign key will remain consistent if the field length is changed because the corresponding fields are both changed. If the domains are different, the foreign key would be inconsistent if, for example, the field length were changed. 130 © Copyright. All rights reserved. Lesson: Defining Foreign Keys to Perform Input Checks Value Table Figure 51: Value Table If the domain of the check field has a value table, you can have the system make a proposal with the value table as a check table. In this case, a proposal is created for the field assignment in the foreign key. Specifying a value table does not automatically provide value help and input validation. To make the entire value help and validation functions available, you must also define an appropriate foreign key. The domain value table is simply used by the system to create automatic proposals for defining foreign keys. © Copyright. All rights reserved. 131 Unit 5: Input Checks The Relationship Between Check Table and Value Table Figure 52: The Relationship Between Check Table and Value Table If the reusability of the domains is also inserted at unsuitable places, the proposal may be unsuitable for the check table. In the example above, a primary key field exists in several tables that is based on the same domain as the check field. The system proposal is then the value table of the domain. Table 3: Value Table: System Proposal In the example of the foreign key definition for field SBOOK-AGENCYNUM, the system proposal is based on the value table SBUSPART in the domain definition, as follows: Field Assignment Check Table Foreign Key Table SBUSPART-MANDANT SBOOK-MANDT SBUSPART-BUSPARTNUM SBOOK-AGENCYNUM The SBUSPART table contains all the business partners of airline carriers. However, only agencies are allowed for field SBOOKAGENCYNUM. Therefore, the system proposal is incorrect. The right check table is table STRAVELAG. Table STRAVELAG is a subset of table SBUSPART, due to its foreign key definition on field AGENCYNUM. You must overwrite the system proposal with table STRAVELAG. If you do not know the correct check table, the system can help you by listing all the tables in question. The listed tables include all the tables that have a key field with domain S_ BUSPARNUM. 132 © Copyright. All rights reserved. Lesson: Defining Foreign Keys to Perform Input Checks Semantic Attributes Figure 53: Semantic Attributes The cardinality describes the foreign key relationship with regard to how many records of the check table are assigned to records of the foreign key table. The cardinality is always defined from the point of view of the check table. Types of Foreign Key Fields The type of the foreign key field defines whether the foreign key field identifies a table entry or not. Hence, the foreign key fields may or may not be defined as key fields. These foreign key fields may be defined as the key fields of a text table. The following settings exist for the type of foreign key fields: ● Not specified No information about the kind of foreign key fields can be given. ● No key fields/candidates The foreign key fields are neither primary key fields, nor do they uniquely identify a record of the foreign key table (key candidates). Therefore, the foreign key fields do not (partially) identify the foreign key table. ● Key fields/candidates The foreign key fields are either primary key fields of the foreign key table or they uniquely identify a record of the foreign key table (key candidates). Therefore, the foreign key fields (partially) identify the foreign key table. © Copyright. All rights reserved. 133 Unit 5: Input Checks ● Key fields of a text table The foreign key table is a text table of the check table. The key of the foreign key table is identical to the key of the text table, but has an additional language key field. This is a special case of the category Key fields/candidates. 134 © Copyright. All rights reserved. Unit 5 Exercise 9 Perform Input Checks to Ensure Data Consistency Business Example To ensure data consistency through input checks, foreign keys are used frequently. You need to be familiar with how to define suitable foreign keys in your tables using the ABAP Dictionary. Define Foreign Keys for Tables Define suitable foreign keys for the tables ZEMPLOY##, ZDEPMENT##, and ZFLCREW##. Use the tables of the flight model, tables T000 (client) and SCURX (currency code), as well as your tables, to define the foreign keys. To maintain the individual foreign keys, open the respective tables in maintenance mode. 1. Create a foreign key for the field ZEMPLOY##-CLIENT using T000 as the check table.. 2. Create a foreign key for the field ZEMPLOY##-CARRIERusing SCARR as the check table. Note: Since you are using the S_CARR_ID domain for the CARRIER field in ZEMPLOY##, you can use the value table SCARR for the foreign key definition. 3. Create a foreign key for the field ZEMPLOY##-DEPARTMENTusing ZDEPMENT## as the check table. Enter the value table ZDEPMENT## in the domain for the DEPARTMENT field and activate the domain. Note: To obtain a proposal for the foreign key definition, you need to add ZDEPMENT## as a value table in the domain of the DEPARTMENT field in ZEMPLOY##. This is not absolutely necessary for later foreign key definitions, but it makes the definition easier. 4. Create a foreign key for the fieldZEMPLOY##-CURRENCYusing SCURX as the check table. Note: Since you are using the S_CURR domain for the ZEMPLOY##-CURRENCY field, you can use the value table SCURX for the foreign key definition. © Copyright. All rights reserved. 135 Unit 5: Input Checks 5. Create a foreign key for the field ZDEPMENT##-CLIENTusing T000 as the check table. 6. Create the foreign key for the field ZDEPMENT## CARRIERusing SCARR as the check table. 7. Create a foreign key for the field ZFLCREW##-EMP_NUMusing ZEMPLOY## as the check table. 8. Maintain some data for the table ZEMPLOY## and test the effect of your foreign key relationships. Extend a Table and Define the Foreign Key Relationship Some employees of airline carriers work in travel agencies in order to sell flights for their companies. You need to extend table ZEMPLOY## to include a field that documents the travel agency where each employee works. Extend table ZEMPLOY## accordingly and define the foreign key relationship. Hint: The table containing the travel agencies is called STRAVELAG. 1. Create a new AGENCY field in your table ZEMPLOY##. 2. Define an appropriate foreign key for the new field. Extend a Table to Include One More Field Extend the ZDEPMENT## table by one field. Each department of an airline has a head of department. The assignment between the department and the head of the department should be mapped in the flight model. 1. Extend table ZDEPMENT## to include the DEPHEAD field. Note: In our model, the personnel number identifies a person. Therefore, the new field to be added to table ZDEPMENT## must contain personnel numbers. The field should also refer to the domain for personnel numbers, which is ZEMPNUM##. As the person to be managed in this case has a special role, you should create a new data element and not use the one already created for the personnel number. Use the two-step domain concept. 2. Define a suitable foreign key for this field using ZEMPLOY## as the check table. 136 © Copyright. All rights reserved. Lesson: Defining Foreign Keys to Perform Input Checks Hint: Do not run BC430_CHECK now. You will perform a check of this exercise at the end of the unit, together with other exercises. © Copyright. All rights reserved. 137 Unit 5 Solution 9 Perform Input Checks to Ensure Data Consistency Business Example To ensure data consistency through input checks, foreign keys are used frequently. You need to be familiar with how to define suitable foreign keys in your tables using the ABAP Dictionary. Define Foreign Keys for Tables Define suitable foreign keys for the tables ZEMPLOY##, ZDEPMENT##, and ZFLCREW##. Use the tables of the flight model, tables T000 (client) and SCURX (currency code), as well as your tables, to define the foreign keys. To maintain the individual foreign keys, open the respective tables in maintenance mode. 1. Create a foreign key for the field ZEMPLOY##-CLIENT using T000 as the check table.. a) Run transaction SE11, enter the database table name ZEMPLOY##, and choose Change. b) Select the CLIENT field in ZEMPLOY##. Choose the Foreign Keys button. Note: Since you are using the domain MANDT for the CLIENT field in ZEMPLOY##, the system proposes the value table T000 as the check table. c) Confirm and check the system proposal. The following fields of the check table T000 must be assigned: Check Table Field Foreign Key Table Foreign Key Field MANDT ZEMPLOY## CLIENT d) Enter a short text and define the semantic attributes as follows: Field Name Value Foreign key field type Key fields/candidates Cardinality 1:CN e) Choose Copy and save your table. 2. Create a foreign key for the field ZEMPLOY##-CARRIERusing SCARR as the check table. 138 © Copyright. All rights reserved. Lesson: Defining Foreign Keys to Perform Input Checks Note: Since you are using the S_CARR_ID domain for the CARRIER field in ZEMPLOY##, you can use the value table SCARR for the foreign key definition. a) Select the CARRIER field. Choose the Foreign Keys button. b) Confirm and check the system proposal. The following fields of the check table SCARR must be assigned: Check Table Field Foreign Key Table Foreign Key Field MANDT ZEMPLOY## CLIENT CARRID ZEMPLOY## CARRIER c) Enter a short text and determine the semantic attributes as follows: Field Name Value Foreign key field type Key fields/candidates Cardinality 1:CN d) Choose Copy and save your table. 3. Create a foreign key for the field ZEMPLOY##-DEPARTMENTusing ZDEPMENT## as the check table. Enter the value table ZDEPMENT## in the domain for the DEPARTMENT field and activate the domain. Note: To obtain a proposal for the foreign key definition, you need to add ZDEPMENT## as a value table in the domain of the DEPARTMENT field in ZEMPLOY##. This is not absolutely necessary for later foreign key definitions, but it makes the definition easier. a) To add ZDEPMENT## as a value table, select the column DEPARTMENT and forward navigate on the data element ZDEPT## into the domain. Select the Value Range tab and enter ZDEPMENT## into the Value Table field. b) Select the DEPARTMENT field in ZEMPLOY##. Choose the Foreign Keys button. Note: Since you are using the domain of the ZDEPMENT##-DEPARTMENTfield for the ZEMPLOY##-DEPARTMENTfield, you can use the value table ZDEPMENT## for the foreign key definition. c) Confirm and check the system proposal. In the check table ZDEPMENT##, the following fields must be assigned: © Copyright. All rights reserved. 139 Unit 5: Input Checks Check Table Field Foreign Key Table Foreign Key Field CLIENT ZEMPLOY## CLIENT CARRIER ZEMPLOY## CARRIER DEPARTMENT ZEMPLOY## DEPARTMENT d) Enter a short text and determine the semantic attributes, as follows: Field Name Value Foreign key field type Non key fields/candidates Cardinality 1:CN e) Save your foreign key. 4. Create a foreign key for the fieldZEMPLOY##-CURRENCYusing SCURX as the check table. Note: Since you are using the S_CURR domain for the ZEMPLOY##-CURRENCY field, you can use the value table SCURX for the foreign key definition. a) Select the ZEMPLOY##-CURRENCYfield. Choose the Foreign Keys button. b) Confirm and check the system proposal. The following fields of the check table SCURX must be assigned: Check Table Field Foreign Key Table Foreign Key Field CURRKEY ZEMPLOY## CURRENCY c) Enter a short text and define the semantic attributes as follows: Field Name Value Foreign key field type Non-key fields/candidates Cardinality 1:CN d) Save your foreign key. 5. Create a foreign key for the field ZDEPMENT##-CLIENTusing T000 as the check table. a) Use the same steps as above to create the foreign key definition. Confirm and check the system proposal. The check table is T000 and the check table field is MANDT. 6. Create the foreign key for the field ZDEPMENT## CARRIERusing SCARR as the check table. a) Use the same steps as above to create the foreign key definition. Confirm and check the system proposal. The check table is SCARR and the check table fields are MANDT and CARRID. 7. Create a foreign key for the field ZFLCREW##-EMP_NUMusing ZEMPLOY## as the check table. 140 © Copyright. All rights reserved. Lesson: Defining Foreign Keys to Perform Input Checks a) Select the EMP_NUM field in ZFLCREW##. Choose the Foreign Keys button. Note: The check table is the ZEMPLOY## table. If you have stored this as a value table in the domain for the employee number, a corresponding proposal is created. If not, you have to enter it yourself. b) If the Check Table field is empty, enter ZEMPLOY## and choose the Generate proposal button. c) Confirm and check the system proposal. d) Enter a short text and determine the semantic attributes as follows: Field Name Value Foreign key field type Key fields/candidates Cardinality 1:CN e) Choose Copy and activate your table. 8. Maintain some data for the table ZEMPLOY## and test the effect of your foreign key relationships. a) Open the table ZEMPLOY## in maintenance mode and choose Utilities → Table Contents → Create Entries. b) Enter data and check whether your foreign key functions correctly by testing it with some incorrect data, such as wrong carrier code, wrong currency code, and so forth. Extend a Table and Define the Foreign Key Relationship Some employees of airline carriers work in travel agencies in order to sell flights for their companies. You need to extend table ZEMPLOY## to include a field that documents the travel agency where each employee works. Extend table ZEMPLOY## accordingly and define the foreign key relationship. Hint: The table containing the travel agencies is called STRAVELAG. 1. Create a new AGENCY field in your table ZEMPLOY##. a) Open table ZEMPLOY## in maintenance mode. Go to the end of the table and insert AGENCY in the field. Note: In the definition of table STRAVELAG, you can see that a suitable data element is called S_AGNCYNUM. b) Assign the data element S_AGNCYNUM to your new field ZEMPLOY##-AGENCY. © Copyright. All rights reserved. 141 Unit 5: Input Checks 2. Define an appropriate foreign key for the new field. a) Select the AGENCY field and have the system make a proposal for the foreign key definition. b) Check the proposal. The check table is SBUSPART. This check table is not correct, as it contains all the business partners of carriers, rather than just agencies. c) The correct check table is STRAVELAG, which contains the agencies. Open the table definition of table STRAVELAG in a second window and compare the table definition with the foreign key definition. d) In the foreign key definition for ZEMPLOY##-AGENCY, overwrite the entry SBUSBART in the check table with STRAVELAG. e) The system recognizes the change in the check table and suggests that it create a proposal. Select the proposal. The following fields of the check table STRAVELAG must be assigned: Check Table Field Foreign Key Table Foreign Key Field MANDT ZEMPLOY## CLIENT AGENCYNUM ZEMPLOY## AGENCY f) Enter a short text and determine the semantic attributes, as follows: Field Name Value Foreign key field type Non-key fields/candidates Cardinality 1:CN g) Choose Copy. h) Activate the table. i) Open the table ZEMPLOYEE and choose Utilities → Table Contents → Create entries. Verify your foreign key. Extend a Table to Include One More Field Extend the ZDEPMENT## table by one field. Each department of an airline has a head of department. The assignment between the department and the head of the department should be mapped in the flight model. 1. Extend table ZDEPMENT## to include the DEPHEAD field. 142 © Copyright. All rights reserved. Lesson: Defining Foreign Keys to Perform Input Checks Note: In our model, the personnel number identifies a person. Therefore, the new field to be added to table ZDEPMENT## must contain personnel numbers. The field should also refer to the domain for personnel numbers, which is ZEMPNUM##. As the person to be managed in this case has a special role, you should create a new data element and not use the one already created for the personnel number. Use the two-step domain concept. a) Open the table ZDEPMENT## in Change mode. b) Go to the end of the table and enter the new field DEPHEAD and enter a name for the data element to be created in the Field type column, for example, ZDEPHEAD##. c) Save the table definition. d) Double-click the name of the new data element to be created. Confirm that you want to create a data element. e) Enter a short text for the data element. Enter ZEMPNUM## in the Domain field. f) On the Field Label tab page, enter some label texts. g) Activate the data element as a local object. Go back to the maintenance screen for the table ZDEPMENT##. h) Activate the table. 2. Define a suitable foreign key for this field using ZEMPLOY## as the check table. a) Select the field DEPHEAD and have the system make a proposal for the foreign key definition. Hint: If you have not entered a value table in your domain for employee numbers, you have to enter the check table manually. b) Check the proposal. Make sure the check table is your table, ZEMPLOY##. The following fields of the check table must be assigned: Check Table Field Foreign Key Table Foreign Key Field CLIENT ZDEPMENT## CLIENT CARRIER ZDEPMENT## CARRIER EMPNUM ZDEPMENT## DEPHEAD c) Enter a short text and determine the semantic attributes, as follows: Field Name Value Foreign key field type Non-key fields/candidates © Copyright. All rights reserved. 143 Unit 5: Input Checks Field Name Value Cardinality 1:CN d) Activate the table. e) Open table ZDEPMENT##, then choose Utilities → Table Contents → Create entries . Verify your foreign key. Hint: Do not run BC430_CHECK now. You will perform a check of this exercise at the end of the unit, together with other exercises. 144 © Copyright. All rights reserved. Lesson: Defining Foreign Keys to Perform Input Checks LESSON SUMMARY You should now be able to: ● Define foreign keys to ensure data consistency © Copyright. All rights reserved. 145 Unit 5 Lesson 3 Creating Text Tables LESSON OVERVIEW This lesson explains how to create and work with text tables. Business Example You need to work with text tables. For this reason, you require an understanding of the following: ● How to create a text table ● How to define a text foreign key LESSON OBJECTIVES After completing this lesson, you will be able to: ● Create a text table Text Tables Figure 54: Text Table 146 © Copyright. All rights reserved. Lesson: Creating Text Tables The table SMEAL contains the meals served to the passengers during a flight. The table SMEALT maintains the meal descriptions. The table SMEALT is the text table for table SMEAL. The key of SMEALT consists of the key of SMEAL and an additional language key field (a field with data type LANG). Table SMEALT can contain explanatory text in several languages for each key entry of SMEAL. To link the key entries with the text, the text table SMEALT must be linked with the table SMEAL using a foreign key. This is done by selecting the Key fields of a text tablecheckbox for the type of the foreign key fields. The foreign key relationship is defined from SMEALT to SMEAL. For each table, you can define one foreign key of type ‘text table’ only. This means that each table can have a maximum of one text table assigned to it. © Copyright. All rights reserved. 147 Unit 5: Input Checks 148 © Copyright. All rights reserved. Unit 5 Exercise 10 Create a Text Table Business Example We often work with text tables. These are tables that contain explanatory text in several languages for each key entry from another related table. To link the key entries with the text, you need to be familiar with how to create a foreign key for a text table. 1. Create a text table ZDEPMENTT## for the ZDEPMENT## table by copying the key fields of table ZDEPMENT##. Add two new fields for the language key and the description text (suggested names: LANGUAGE and DESCR). Note: The text table offers the department ID description in different languages for employees of the carrier in all countries. For the field definition, use the data elements SPRAS (data type LANG) and S_TEXT (data type CHAR, 40). 2. Define a foreign key of the DEPARTMENT field in the ZDEPMENTT## table. Note: The foreign keys for the CLIENT and CARRIER fields in the ZDEPMENTT## table have already been correctly defined because they were copied. 3. Define a foreign key of the LANGUAGE field in the ZDEPMENTT## table. Note: Since you are using the domain SPRAS for the field ZDEPMENTT##-Language, you can use value table T002 for the foreign key definition. 4. Run program BC430_CHECK in transaction SE38 to test all three exercises of this unit. © Copyright. All rights reserved. 149 Unit 5 Solution 10 Create a Text Table Business Example We often work with text tables. These are tables that contain explanatory text in several languages for each key entry from another related table. To link the key entries with the text, you need to be familiar with how to create a foreign key for a text table. 1. Create a text table ZDEPMENTT## for the ZDEPMENT## table by copying the key fields of table ZDEPMENT##. Add two new fields for the language key and the description text (suggested names: LANGUAGE and DESCR). Note: The text table offers the department ID description in different languages for employees of the carrier in all countries. For the field definition, use the data elements SPRAS (data type LANG) and S_TEXT (data type CHAR, 40). a) Copy table ZDEPMENT## to table ZDEPMENTT## using transaction SE11. Save it as a local object. b) Navigate to the field maintenance for tableZDEPMENTT##. Delete all the fields that are not key fields. Create the following new fields: Field Data Element Data Type LANGUAGE SPRAS LANG DESCR S_TEXT CHAR Length Short Description Language 40 Description Note: The field ZDEPMENTT##-LANGUAGE must be a key field. 2. Define a foreign key of the DEPARTMENT field in the ZDEPMENTT## table. Note: The foreign keys for the CLIENT and CARRIER fields in the ZDEPMENTT## table have already been correctly defined because they were copied. 150 © Copyright. All rights reserved. Lesson: Creating Text Tables a) Place the cursor on the DEPARTMENT field in the table ZDEPMENTT##. Choose the Foreign Keys button. Note: Since you are using the domain of field ZDEPMENT##-DEPARTMENTfor field ZDEPMENTT##-DEPARTMENT, you can use value table ZDEPMENT## for the foreign key definition. b) Have the system propose the foreign key definition. Check the proposal. The following fields of the check table ZDEPMENT## must be assigned: Check Table Field Foreign key table Foreign key field CLIENT ZDEPMENT## CLIENT CARRIER ZDEPMENT## CARRIER DEPARTMENT ZDEPMENT## DEPARTMENT c) Enter a short text and determine the semantic attributes as follows: Field Name Value Foreign key field type Key fields of a text table Cardinality 1:CN d) Choose Copy and save. 3. Define a foreign key of the LANGUAGE field in the ZDEPMENTT## table. Note: Since you are using the domain SPRAS for the field ZDEPMENTT##-Language, you can use value table T002 for the foreign key definition. a) Place the cursor on the field ZDEPMENTT##-Language. Choose the Foreign Keys button. b) Have the system make a proposal for the foreign key definition. Check the proposal. The following fields of check table T002 must be assigned: Check Table Field Foreign Key Table Foreign Key Field SPRAS ZDEPMENTT## LANGUAGE c) Enter a short text and define the semantic attributes as follows: Field Name Value Foreign key field type Key fields / candidates Cardinality 1:CN d) Choose Copy and save. © Copyright. All rights reserved. 151 Unit 5: Input Checks e) Activate the table. 4. Run program BC430_CHECK in transaction SE38 to test all three exercises of this unit. 152 © Copyright. All rights reserved. Lesson: Creating Text Tables LESSON SUMMARY You should now be able to: ● Create a text table © Copyright. All rights reserved. 153 Unit 5: Input Checks 154 © Copyright. All rights reserved. Unit 5 Learning Assessment 1. Validation of screen fields does not occur until a foreign key is defined or fixed values are provided in the domain definition. Determine whether this statement is true or false. X True X False 2. If you refer to a domain with a value table in a field and define a foreign key at field level, there is no check. Determine whether this statement is true or false. X True X False 3. A domain describes the general value range of a field by specifying its ___________ and field length. Choose the correct answer. X A fixed value X B data type X C field value range 4. ________________ are used to ensure that the data is consistent among tables. Choose the correct answer. X A Primary keys X B Foreign keys X C Secondary keys © Copyright. All rights reserved. 155 Unit 5: Learning Assessment 5. The field of the foreign key table to be checked is called the _______________. Choose the correct answer. X A check field X B referenced field X C foreign key 6. A user enters data in a screen field with a foreign key assigned. This entered data must be consistent with the key fields of the check table. Determine whether this statement is true or false. X True X False 7. A text table has all the key fields of the normal table along with an extra key, which is the language key field. Determine whether this statement is true or false. X True X False 8. Only one text table can be linked with a table. Determine whether this statement is true or false. 156 X True X False © Copyright. All rights reserved. Unit 5 Learning Assessment - Answers 1. Validation of screen fields does not occur until a foreign key is defined or fixed values are provided in the domain definition. Determine whether this statement is true or false. X True X False 2. If you refer to a domain with a value table in a field and define a foreign key at field level, there is no check. Determine whether this statement is true or false. X True X False 3. A domain describes the general value range of a field by specifying its ___________ and field length. Choose the correct answer. X A fixed value X B data type X C field value range 4. ________________ are used to ensure that the data is consistent among tables. Choose the correct answer. X A Primary keys X B Foreign keys X C Secondary keys © Copyright. All rights reserved. 157 Unit 5: Learning Assessment - Answers 5. The field of the foreign key table to be checked is called the _______________. Choose the correct answer. X A check field X B referenced field X C foreign key 6. A user enters data in a screen field with a foreign key assigned. This entered data must be consistent with the key fields of the check table. Determine whether this statement is true or false. X True X False 7. A text table has all the key fields of the normal table along with an extra key, which is the language key field. Determine whether this statement is true or false. X True X False 8. Only one text table can be linked with a table. Determine whether this statement is true or false. 158 X True X False © Copyright. All rights reserved. UNIT 6 Dictionary Object Dependencies Lesson 1 Differentiating Between Active and Inactive Dictionary Objects Exercise 11: Differentiate Between Active and Inactive Dictionary Objects 160 165 Lesson 2 Identifying Dependencies with ABAP Dictionary Objects Exercise 12: Identify Dependencies with ABAP Dictionary Objects 169 173 UNIT OBJECTIVES ● Differentiate between active and inactive Dictionary objects ● Identify the usages of Dictionary objects using the where-used list © Copyright. All rights reserved. 159 Unit 6 Lesson 1 Differentiating Between Active and Inactive Dictionary Objects LESSON OVERVIEW This lesson enables you to distinguish between active and inactive Dictionary objects. Business Example Certain dependencies between Dictionary objects become effective when objects are changed. For example, if you change a technical domain, one or more database tables may have to be converted (can be very time-consuming). For this reason, you require an understanding of the following: ● Active and inactive versions ● Runtime objects ● The where-used list LESSON OBJECTIVES After completing this lesson, you will be able to: ● 160 Differentiate between active and inactive Dictionary objects © Copyright. All rights reserved. Lesson: Differentiating Between Active and Inactive Dictionary Objects Active and Inactive Dictionary Objects Figure 55: Active and Inactive Versions During development, you sometimes need to change an (active) object that is already used by the system. Such changes are supported in the ABAP Dictionary by separating the active and inactive versions. The basic difference between the active and inactive version is as follows: ● Active version The active version of an ABAP Dictionary object is the version that the components of the runtime environment (for example, ABAP processor, database interface) access. This version is not initially changed. ● Inactive version When you change an active object, the system creates an inactive version that can be saved without checking. It has no effect on the runtime system. At the end of the development process, the inactive version can be made the active version. This is done by activation. The inactive version of the object is first checked for consistency. If it is consistent, the inactive version replaces the active one. From this point on, the runtime system uses the new active version. © Copyright. All rights reserved. 161 Unit 6: Dictionary Object Dependencies Note: When existing dictionary objects used by other objects are activated, most of the dependencies in question are respected. The used objects can be activated only if the dependent objects can be activated. The following example demonstrates the activation process. An active structure contains three fields. A field is added to this structure in the ABAP Dictionary. After this action, there is an active version with three fields and an inactive version with four fields. During activation, the active version is overwritten with the inactive version. As a result, the inactive version becomes the active version. After the activation, the active version has four fields. Hint: If a long runtime is expected in an activation because of a large number of dependent objects, you must choose Activating Objectsin the background for the object. Such a long runtime is expected, for example, when a domain that is used in many tables is to be activated. Mass Activation You can use mass activation to activate a large set of objects simultaneously (for example, after importing data). The mass activation is automatically called when a transport request is imported into a system. The mass activation gets a list of ABAP Dictionary objects. All objects in the list are then activated in one action. The mass activation program has two advantages over activating objects one at a time: If dependent tables are affected by changes to different domains or data elements, they have to be reactivated only once. Related objects, for example, a domain and its associated value table, can be activated together. If you are activating objects individually, you need to activate each of the objects separately and in the correct sequence. For example, before activating a table, you must activate all domains and data elements to which the table fields refer. 162 © Copyright. All rights reserved. Lesson: Differentiating Between Active and Inactive Dictionary Objects Runtime Objects Figure 56: Runtime Objects When an object in ABAP Dictionary is activated, a runtime object is usually created and an activation log that can be consulted if errors occur. The runtime object can be displayed and checked in the ABAP Dictionary by choosing Utilities → Runtime Object. The information about a structure (or table) is distributed in the ABAP Dictionary in domains, data elements, and the structure definition. The runtime object combines this information into a structure in a form that is optimized for access from ABAP programs. The runtime object is generated automatically when you activate a structure. The runtime objects of the structures are buffered so that the ABAP runtime system can quickly access this information. The runtime objects contain the following information: ● Information about the overall structure, for example, number of fields. ● Information about individual structure fields, such as field name, position of the field in the structure, data type, length, number of decimal places, reference field, reference table, check table, conversion routine, and so on. ● Information required by the database interface to access the table data, such as client dependence, buffering, key fields, and so on. Runtime objects are created for all ABAP Dictionary objects that can be used as types in ABAP programs. These runtime objects are data elements, table types, views, structures, and tables. © Copyright. All rights reserved. 163 Unit 6: Dictionary Object Dependencies Note: If existing dictionary objects used to define database tables are changed, it may be necessary to convert these tables. This can be a very lengthy process for tables with a large number of rows. Furthermore, foreign keys in the converted tables can become inconsistent. A where-used list should be created before dictionary objects such as data elements or domains are changed. When an object is activated in the ABAP Dictionary, the time stamp of the runtime object and the time stamp of all programs and screens that use this object are adjusted. 164 © Copyright. All rights reserved. Unit 6 Exercise 11 Differentiate Between Active and Inactive Dictionary Objects Business Example The information about the logging of changes for tables ZEMPLOY## and ZDEPMENT## must be made more detailed. In addition to the person who made the last change and the date of this change, you also want to record the time of the last change. For this, you need to extend the tables to include an additional field. 1. Ensure that a suitable field for the change log is inserted in the tables ZEMPLOY## and ZDEPMENT## with the minimum of effort. Use the name CHANGED_ON for this new field and type it with data element S_TIME. Note: The fields for the change log can be found in the include structure ZCHANGE##. The new field should therefore be inserted in this structure. The field is automatically inserted in the tables ZEMPLOY## and ZDEPMENT## using the include mechanism. 2. Make sure that the field is included in the tables ZEMPLOY## and ZDEPMENT##. Check the activation log of the tables and structures involved. 3. Run program BC430_CHECK to test your exercise. © Copyright. All rights reserved. 165 Unit 6 Solution 11 Differentiate Between Active and Inactive Dictionary Objects Business Example The information about the logging of changes for tables ZEMPLOY## and ZDEPMENT## must be made more detailed. In addition to the person who made the last change and the date of this change, you also want to record the time of the last change. For this, you need to extend the tables to include an additional field. 1. Ensure that a suitable field for the change log is inserted in the tables ZEMPLOY## and ZDEPMENT## with the minimum of effort. Use the name CHANGED_ON for this new field and type it with data element S_TIME. Note: The fields for the change log can be found in the include structure ZCHANGE##. The new field should therefore be inserted in this structure. The field is automatically inserted in the tables ZEMPLOY## and ZDEPMENT## using the include mechanism. a) On the ABAP Dictionary: Initial Screen, choose Database table and enter ZEMPLOY##. Choose the Display button. b) Choose Utilities → Table Contents → Create Entries. You can see the active version of this table at runtime. c) Repeat steps a) and b) for the table ZDEPMENT##. d) On the ABAP Dictionary: Initial Screen, choose Data type and enter ZCHANGE## in the corresponding field. Choose the Change button. e) Choose the Components tab page. In the Component column, enter the name CHANGED_ON for the new field and in the Component Typecolumn, enter the data element S_TIME. f) Save the structure. g) On the ABAP Dictionary: Initial Screen, choose Database table and enter ZEMPLOY##. Choose the Display button. See the include ZCHANGE##: ii does not contain the new field. h) On the ABAP Dictionary: Initial Screen, choose Data type and enter ZCHANGE## in the corresponding field. Choose the Change button. i) Activate the structure. 166 © Copyright. All rights reserved. Lesson: Differentiating Between Active and Inactive Dictionary Objects 2. Make sure that the field is included in the tables ZEMPLOY## and ZDEPMENT##. Check the activation log of the tables and structures involved. a) Choose Utilities → Activation Log to find the activation log for the structure. In the activation log, you can see that the tables ZEMPLOY## and ZDEPMENT## are activated as dependent objects and were extended to include the new field. b) Open the definition of the table ZEMPLOY## or the table ZDEPMENT## in Display mode. c) Choose Utilities → Table Contents → Create Entries. You can see that the table was extended to include the corresponding field. 3. Run program BC430_CHECK to test your exercise. a) In the Command field, enter /oSA38 to run ABAP Program Execution in a new session. b) Enter BC430_CHECK in the corresponding field. c) Choose Execute. d) Choose Unit 6, exercise 11. © Copyright. All rights reserved. 167 Unit 6: Dictionary Object Dependencies LESSON SUMMARY You should now be able to: ● 168 Differentiate between active and inactive Dictionary objects © Copyright. All rights reserved. Unit 6 Lesson 2 Identifying Dependencies with ABAP Dictionary Objects LESSON OVERVIEW This lesson describes the mechanism for handling the dependent objects in the ABAP Dictionary. This lesson also explains the Repository Information System and the where-used list for ABAP Dictionary objects. Business Example You need to find out which objects actually refer to your object, such as data elements, structure components, and table fields. For this reason, you require an understanding of the following: ● How to use the where-used list for ABAP Dictionary objects ● How to use the Repository Information System for ABAP Dictionary objects LESSON OBJECTIVES After completing this lesson, you will be able to: ● Identify the usages of Dictionary objects using the where-used list © Copyright. All rights reserved. 169 Unit 6: Dictionary Object Dependencies The Where-Used List Figure 57: Where-Used List If an object that is already active is modified, this can affect other objects that use it directly or indirectly. Objects that use another object either directly or indirectly are called dependent objects. Some changes might require adjustments to the runtime objects of these dependent objects. Others might make the dependent object inconsistent. When an object is activated, the dependent objects are determined and activated (if necessary). The active versions of the dependent objects are activated again in this case. In particular, new and inactive versions of objects using the changed object are not changed. When you change the data type of a domain and activate the domain, for example, all the data elements, structures, and tables that refer to this domain are also activated automatically. This ensures that all affected runtime objects are adjusted in line with the changed type information. If an ABAP Dictionary object has a database table as a dependent object, the database object and runtime object of the table may have to be adjusted when the ABAP Dictionary object is activated. Changing an ABAP Dictionary object may also affect its dependent objects. Before making a critical change, such as changing the data type or deleting a field, you should define the set of objects affected in order to estimate the implications of the planned action. For each ABAP Dictionary Object there exists a where-used list that you can use to find all the objects that refer to this object. You can call the where-used list from the maintenance transaction for the object. 170 © Copyright. All rights reserved. Lesson: Identifying Dependencies with ABAP Dictionary Objects You can find direct and indirect usages of an ABAP Dictionary object with the where-used list. You then must define the usage object types that need to be included in the search, for example, all structures and tables using a data element. You can also search for usages that are not ABAP Dictionary objects, for example, all the programs that use a specific table. The search can also be limited by package or user namespace. If an object is likely to be used by a large number of objects, you can perform the search in the background. The Repository Information System Figure 58: The Repository Information System ABAP Dictionary The Repository Information System ABAP Dictionary is part of the general Repository Information System. It helps you search for ABAP Dictionary objects and their users. The where-used list for Repository objects can be called from the information system. The information system also enables you to search for objects by their attributes. In addition to the object-specific search criteria (for example, buffering type for tables), you can search for all objects by package, short description, or author and date of last change. The object lists created by the Repository Information System are fully integrated in the ABAP Workbench. The object lists allow you to navigate directly to the maintenance transactions for the objects found. © Copyright. All rights reserved. 171 Unit 6: Dictionary Object Dependencies 172 © Copyright. All rights reserved. Unit 6 Exercise 12 Identify Dependencies with ABAP Dictionary Objects Business Example To explore dependencies with ABAP Dictionary Objects, you need to use the Repository Information System. 1. Use the Repository Information System to find out the following: all domains with fixed values whose names begin with Z, all table fields that use data element S_FNAME, and all tables of the flight model (package SAPBC_DATAMODEL) with delivery class A. 2. Determine all the programs that use the table SFLIGHT. 3. Determine the names of the data elements created by your neighbors. Hint: You can determine your neighbor’s data elements either through a string search using the name (if your neighbors adhered to the given naming convention) or with Last changed by. It might be useful if you restrict the selection with the last changed by date (the last change should be no earlier than the beginning of the course) at least in the first case (naming convention). 4. Execute the program BC430_CHECK in transaction SE38 to check whether your solutions are correct. © Copyright. All rights reserved. 173 Unit 6 Solution 12 Identify Dependencies with ABAP Dictionary Objects Business Example To explore dependencies with ABAP Dictionary Objects, you need to use the Repository Information System. 1. Use the Repository Information System to find out the following: all domains with fixed values whose names begin with Z, all table fields that use data element S_FNAME, and all tables of the flight model (package SAPBC_DATAMODEL) with delivery class A. a) On the ABAP Dictionary: Initial Screen, choose Environment → Repository Information System. Expand the ABAP Dictionary node. b) Choose Domains under ABAP Dictionary in the Repository Information System tree. c) In the selection screen, enter Z* in the Domain field. d) Choose Edit → All Selections. e) In the enhanced selection screen, select the Only domains with fixed valuescheckbox. Choose Execute to generate the required list. f) Go back to the initial screen of the Repository Information System and expand the Fields node. Select Table Fields. g) Choose Edit → All Selections and enter S_FNAME in the Data element field. Choose Execute to generate the required list. h) Go back to the initial screen of the Repository Information System. The ABAP Dictionary node is still expanded. Select Database Tables. i) Enter the package SAPBC_DATAMODEL on the Selection screen. j) Choose Edit → All Selections and, using the input help, enter the delivery class A. Choose Execute to generate the required list. 2. Determine all the programs that use the table SFLIGHT. a) Go to the initial screen of the ABAP Dictionary. Choose Database table and enter SFLIGHT in the corresponding field. Choose the Where-Used List button. b) The usage in programs is flagged in the dialog box. Choose Execute to generate the required list. Choose Yes in the Use of a Table dialog box. 3. Determine the names of the data elements created by your neighbors. 174 © Copyright. All rights reserved. Lesson: Identifying Dependencies with ABAP Dictionary Objects Hint: You can determine your neighbor’s data elements either through a string search using the name (if your neighbors adhered to the given naming convention) or with Last changed by. It might be useful if you restrict the selection with the last changed by date (the last change should be no earlier than the beginning of the course) at least in the first case (naming convention). a) On the ABAP Dictionary: Initial Screen, choose Environment → Repository Information System. b) Expand the ABAP Dictionary node and choose Data Elements. c) Choose Edit → All Selections and search for Last changed by. Note: If you have two groups of neighbors, you have to use Multiple selection. 4. Execute the program BC430_CHECK in transaction SE38 to check whether your solutions are correct. a) Start transaction SE38. b) In the Program field, enter BC430_CHECK. c) Choose Execute. d) In the Text table for deptfield, enter ZDEPMENTT##. e) In the Domain for area field, enter ZAREA##. f) Chose Execute. © Copyright. All rights reserved. 175 Unit 6: Dictionary Object Dependencies LESSON SUMMARY You should now be able to: ● 176 Identify the usages of Dictionary objects using the where-used list © Copyright. All rights reserved. Unit 6 Learning Assessment 1. The ______________ version of an ABAP Dictionary object is the version that the components of the runtime environment (for example, ABAP processor, database interface) access. Choose the correct answer. X A passive X B active X C inactive 2. The runtime object of a table contains further information needed by the database interface for accessing the table data, such as client dependence, buffering, key fields, and so on. Determine whether this statement is true or false. X True X False 3. The ______________ for Repository objects can be called from the information system. Choose the correct answer. X A data elements X B where-used list X C buffering type of tables 4. When an object that is already active is modified, it can affect other objects that use it directly or indirectly. The affected objects are called ______________. Choose the correct answer. X A dependent objects X B database objects X C Repository objects © Copyright. All rights reserved. 177 Unit 6 Learning Assessment - Answers 1. The ______________ version of an ABAP Dictionary object is the version that the components of the runtime environment (for example, ABAP processor, database interface) access. Choose the correct answer. X A passive X B active X C inactive 2. The runtime object of a table contains further information needed by the database interface for accessing the table data, such as client dependence, buffering, key fields, and so on. Determine whether this statement is true or false. X True X False 3. The ______________ for Repository objects can be called from the information system. Choose the correct answer. X A data elements X B where-used list X C buffering type of tables 4. When an object that is already active is modified, it can affect other objects that use it directly or indirectly. The affected objects are called ______________. Choose the correct answer. 178 X A dependent objects X B database objects X C Repository objects © Copyright. All rights reserved. UNIT 7 Table Changes Lesson 1 Performing a Table Conversion Exercise 13: Perform a Table Conversion 180 189 Lesson 2 Enhancing Tables Using Append Structures Exercise 14: Add Enhancements to a Table Using an Append Structure 194 201 UNIT OBJECTIVES ● Describe the effect of table changes ● Convert transparent tables ● Correct conversion errors ● Add enhancements to tables using append structures © Copyright. All rights reserved. 179 Unit 7 Lesson 1 Performing a Table Conversion LESSON OVERVIEW This lesson explains how to perform table conversions and handle conversion errors. Business Example The data structures of an application must be adjusted in line with new business requirements. For this reason, you require an understanding of the following: ● How to change existing database tables LESSON OBJECTIVES After completing this lesson, you will be able to: 180 ● Describe the effect of table changes ● Convert transparent tables ● Correct conversion errors © Copyright. All rights reserved. Lesson: Performing a Table Conversion Changes to Database Tables Figure 59: Changes to Tables ABAP programs can only access a database table correctly if the runtime object of the table is consistent with the structure of the table in the database. Each time the table is changed in the ABAP Dictionary, the system checks during the activation (when the runtime object is updated) whether it has to adjust the database object to the changed ABAP Dictionary definition of the table. The database structure does not have to be changed for certain changes to the ABAP Dictionary. For example, you do not have to change the database structure when the order of the fields (except key fields) in the ABAP Dictionary is changed. In this case, the changed structure is activated in the ABAP Dictionary and the database structure remains unchanged. © Copyright. All rights reserved. 181 Unit 7: Table Changes Structure Adjustment in the ABAP Dictionary Figure 60: Structure Adjustment in the ABAP Dictionary The database table can be adjusted to the changed definition in the ABAP Dictionary by doing one of the following: ● Deleting the database table and creating it again. The table in the database is deleted, the inactive table is activated in the ABAP Dictionary, and the table is created again in the database. The existing data in the table is lost. ● Changing the database catalog ALTER TABLE. The definition of the table in the database is simply changed. The existing data is retained. However, indexes of the table may have to be built again. ● Converting the table. This is the most time-consuming way of adjusting a database table. If the table does not contain any data, it is deleted from the database and created again with its new structure. If data exists in the table, the system attempts to adjust the structure with ALTER TABLE. If the database system used is not able to do so, the structure is adjusted by converting the table. Conversion is the most resource-intensive method of adjusting structures. However, structural changes involving changes to the database catalog can also result in costly internal data reorganizations in some database systems. You must not adjust the database structure during production. All applications that access the table must be deactivated during the structural adjustment. Since the table data is not consistent during the structural adjustment (in particular during conversion), programs may behave incorrectly when they access this data. 182 © Copyright. All rights reserved. Lesson: Performing a Table Conversion The Table Conversion Process Figure 61: Conversion Process 1 The procedure actually used by the system in a particular case depends on the following: ● Type of structural change ● Database system used ● Whether or not data already exists in the table The following example illustrates the steps carried out by the system during a conversion: In the figure The Table Conversion Process, the table TAB was changed in the ABAP Dictionary. The length of field 3 was reduced from 60 to 30 places. As a result, the ABAP Dictionary has an active (field 3 with a length of 60 places) and an inactive (field 3 with a length of 30 places) version of the table. The table in the database corresponds to the active version in the ABAP Dictionary, which means that field 3 currently has 60 places in the database. A secondary index with the ID A11, which was also created in the database, is defined for the table in the ABAP Dictionary. The table already contains data. © Copyright. All rights reserved. 183 Unit 7: Table Changes Conversion Process 2 Figure 62: Conversion Process 2 The following steps are illustrated in figure “Conversion Process 2”: ● Step 1 The table is locked to prevent further structure changes. If the conversion terminates due to an error, the table remains locked. Before the conversion is completed correctly, this lock mechanism prevents any further structure changes which may lead to loss of data. Moreover, all views dependent on the table are inactivated and therefore blocked. ● Step 2 The database table TAB is renamed QCMTAB. The new name of the table is defined by the prefix QCM and the original table name TAB. If a table named QCMTAB already exists in the database (for example, from a previous conversion attempt), this table is deleted before the table is renamed. During the renaming, all secondary indexes of the table are deleted. 184 © Copyright. All rights reserved. Lesson: Performing a Table Conversion Conversion Process 3 Figure 63: Conversion Process 3 The following steps are illustrated in figure “Conversion process 3”: ● Step 3 The inactive version of table TAB is activated in the ABAP Dictionary. The table is created in the database as table QCM8TAB with the new structure and a primary index. After this step, the database contains the following tables: - Table QCMTAB with the old structure. This table contains the business data. - Table QCM8TAB with the new structure. This table is empty. Caution: The table does not exist in the database with its original name during conversion. As the programs that access this table cannot be executed, make sure that no applications access the table to be converted during conversion. © Copyright. All rights reserved. 185 Unit 7: Table Changes Conversion Process 4 Figure 64: Conversion Process 4 The following steps are illustrated in figure “Conversion process 4”: ● Step 4 The data is loaded back from table QCMTAB to table QCM8TAB. The conversion is done using statement MOVE-CORRESPONDING. Both tables contain the data after this step. If you reduce the size of the fields, for example, the extra places are truncated when you reload the data. Since the data is in both tables QCM8TAB and QCMTAB during the conversion, there are greater storage requirements. Before converting large tables, therefore, you should check whether sufficient space is available in the corresponding tablespace. A database commit is performed after 16 MB when you copy the data from table QCMTAB to table QCM8TAB. A conversion process therefore needs 16 MB of resources in the rollback segment. The existing database lock is released with the Commit and then requested again before the next data area to be converted is edited. When you reduce the size of keys, only one record can be reloaded if there are several records whose key cannot be distinguished. It is not possible to say which record this will be. In this case, you should clean up the data in the table before converting it. 186 © Copyright. All rights reserved. Lesson: Performing a Table Conversion Conversion Process 5 Figure 65: Conversion Process 5 The following steps are illustrated in figure “Conversion process 5”: ● Step 5 Table QCMTAB is deleted if all records could be copied from table QCMTAB into table QCM8TAB. If duplicate records appeared in table QCM8TAB, for example, because the key of table TAB was shortened, the system keeps table QCMTAB for safety reasons. ● Step 6 Table QCM8TAB is renamed to TAB. The secondary indexes defined in the ABAP Dictionary for the table are created again. The views on the table that we deactivated in the first step of the conversion are reactivated in the database. ● Step 7 The lock set at the beginning of the conversion is removed. If the conversion aborts, the table stays locked and the system writes a reset log. Each successful step of the conversion is recorded in this reset log. The restart log is deleted, together with the lock, when the conversion has been completed. If the conversion aborts, you can find the place where the conversion terminated in the reset log (the last step to be executed). You must clean up terminated conversions or problems can occur with programs that access this table. You must find out why the conversion terminated (for example, overflow of the corresponding tablespace) and correct it. You must then continue the terminated conversion. © Copyright. All rights reserved. 187 Unit 7: Table Changes 188 © Copyright. All rights reserved. Unit 7 Exercise 13 Perform a Table Conversion Business Example After some organizational changes at the airlines, the original employee management design is no longer appropriate. The design of table ZFLCREW## is no longer correct. The field for the employee role during the flight is too long. 1. Shorten a field in the ZFLCREW## table by creating a new data element ZROLE## and replacing the existing data element with the new one. Reduce the length of field ROLE to 15 characters. Note: Create a new data element ZROLE## and replace the existing data element with the new one. When you define data element ZROLE##, do not use a domain. Instead, enter the data type and length directly in the definition of the data element. Then activate the table. 2. Display the activation log. The system reminds you that shortening the field makes it necessary to convert the table ZFLCREW##. Perform the conversion with the Database Utility. © Copyright. All rights reserved. 189 Unit 7 Solution 13 Perform a Table Conversion Business Example After some organizational changes at the airlines, the original employee management design is no longer appropriate. The design of table ZFLCREW## is no longer correct. The field for the employee role during the flight is too long. 1. Shorten a field in the ZFLCREW## table by creating a new data element ZROLE## and replacing the existing data element with the new one. Reduce the length of field ROLE to 15 characters. Note: Create a new data element ZROLE## and replace the existing data element with the new one. When you define data element ZROLE##, do not use a domain. Instead, enter the data type and length directly in the definition of the data element. Then activate the table. a) On the ABAP Dictionary: Initial Screen, enter the ZFLCREW## as the database table and choose Change. b) Overwrite the data element SEMP_ROLE in the Field type column with ZROLE##, the name of your data element. Save the changes. c) Double-click the data element ZROLE##. In the Create Data Elementdialog box, choose Yes. d) In the data element maintenance screen, enter a short description. e) Choose the Data Type tab, then choose the Predefined Typeradio button. Enter CHAR in the Data Type field, 15 in the Length field, and 0 in the Decimal Places field. f) On the Field Label tab page, enter some text for the data element. g) Activate the data element. 2. Display the activation log. The system reminds you that shortening the field makes it necessary to convert the table ZFLCREW##. Perform the conversion with the Database Utility. a) Navigate back to the maintenance screen for the table ZFLCREW##. b) Choose Utilities → Database Object → Database Utility. c) Select the Activate and adjust databasebutton. In the dialog box, choose Yes. 190 © Copyright. All rights reserved. Lesson: Performing a Table Conversion Conversion Errors Figure 66: Possible Problems During Conversions As the data exists in both the original and temporary tables during conversion, the storage requirements increase. If the tablespace overflows when you reload the data from the temporary table, the conversion terminates. In this case, you must extend the tablespace and start the conversion in the database utility again. If the client field is removed from a client-specific table, it is no longer possible to distinguish the new key of records from different clients. If deleting a client field has resulted in records having the same key, only one of these records can be reloaded into the table. The order in which the records are reloaded to the table determines which record this is. You cannot be sure that the reloaded records come from only one client. In such a case, you must clean up the table before the conversion. If you shorten the key of a table (for example, when you remove a key field or shorten the field length of key fields), this may result in duplicate records with the same key. When you reload the data from the temporary table, only one of these duplicate records can be loaded back to the table. It is not possible to predict which record is loaded back to the table. If you want to copy certain records, you have to clean up the table before the conversion. During a conversion, the data is copied back to the database table from the temporary table with the ABAP statement MOVE-CORRESPONDING. This means that only those type changes that can be executed with MOVE-CORRESPONDING are allowed. All other type changes cause the conversion to be terminated when the data is loaded back to the original table. In this case, you have to recreate the old state prior to conversion. Using database tools, you have to delete the table, change the name of the QCM table to its old name, reconstruct the runtime object in the database utility, set the table structure in the ABAP Dictionary back to its old state, and then activate the table. When a pooled or cluster table is converted, the system creates the QCM table in the database as a transparent table and the data from the pooled or cluster table is copied to it. There is an upper limit for the number of fields in a database table, depending on the database system used. It is not possible to convert pooled and cluster tables if the number of fields in the pooled or cluster table exceeds the maximum number of fields possible in a database table. © Copyright. All rights reserved. 191 Unit 7: Table Changes Resuming Terminated Conversions Figure 67: Resuming Terminated Conversions If a conversion terminates, the lock entry for the table set in step 1 of the conversion process is retained. The table cannot be edited anymore with the maintenance tools of ABAP Dictionary (Transaction SE11). A terminated conversion can be analyzed with the database utility (transaction SE14) and then resumed. The database utility provides an analysis tool that you can use to find the cause of the error and the current state of all the tables involved in the conversion. You can usually find the precise reason for the termination in the object log. If the object log does not provide any information about the cause of the error, you have to analyze the System Log (transaction SM21) or the ABAP Dump Analysis (transaction ST22). If a conversion terminates, the following options are displayed as buttons in the database utility: ● Continue adjustment After correcting the error, you can resume the conversion where it terminated with the Continue adjustmentbutton. ● Unlock table The Unlock table button deletes only the existing lock entry for the table. You should never choose Unlock table for a terminated conversion if the data exists only in the temporary table, for example, if the conversion terminated in Step 3 or 4. 192 © Copyright. All rights reserved. Lesson: Performing a Table Conversion LESSON SUMMARY You should now be able to: ● Describe the effect of table changes ● Convert transparent tables ● Correct conversion errors © Copyright. All rights reserved. 193 Unit 7 Lesson 2 Enhancing Tables Using Append Structures LESSON OVERVIEW This lesson describes a table using append structures. Business Example You need to add customer fields to standard SAP tables by means of append structures without modifications. For this reason, you require an understanding of the following: ● How to enhance tables using append structures LESSON OBJECTIVES After completing this lesson, you will be able to: ● Add enhancements to tables using append structures Enhancement of SAP Standard Tables Figure 68: Append Structures 1 194 © Copyright. All rights reserved. Lesson: Enhancing Tables Using Append Structures Append structures allow you to append fields to standard SAP tables and structures without modifying the table definition. An append structure is a structure that is assigned to exactly one table. There can be several append structures for a table. When a table is activated, all the active append structures for the table are found and their fields are appended to the table. If an append structure is created or changed, the table to which it is assigned is also activated. Like all structures, an append structure defines a type that can be used in ABAP programs. As of Release 4.6C, you can define foreign keys for fields that already exist in the table using an append structure. Search helps can also be attached to fields that already exist in the table. Hint: If you copy a transparent table in the ABAP Dictionary to which an append structure has been added, the fields of the append structure are converted to normal table fields. Append Structures 2 Figure 69: Append Structures 2 Customers create append structures in their namespace. The append structures are thus protected against overwriting during an upgrade. The new versions of the standard tables are imported during the upgrade. When the standard tables are activated, the fields contained in the active append structures are appended to the © Copyright. All rights reserved. 195 Unit 7: Table Changes new standard tables. When append structures are added to a table, you do not have to manually adjust the customer modifications to the new SAP version of the table (transaction SPDD) during the upgrade. As the order of the fields in the ABAP Dictionary can differ from the order on the database, a conversion is not necessary when you add an append structure or insert fields in an existing append structure. The structure is adjusted when the database catalog is adjusted (ALTER TABLE). When you activate a structure in the ABAP Dictionary, the definition of the table is changed and the new field is appended to the database table. Append Structures 3 Figure 70: Append Structures 3 The new version of the standard SAP table is activated and the new field is appended to the database table. 196 © Copyright. All rights reserved. Lesson: Enhancing Tables Using Append Structures Caution: Note the following restrictions regarding append structures: ● No append structures may be created for pooled and cluster tables. ● Tables containing a long field (data type LCHR or LRAW) cannot be extended with appends structures. This extension is not possible because long fields have to be the last field of the table. ● The fields in the append structure must be in the customer namespace beginning with YY or ZZ. Using the customer namespace prevents name conflicts with future table fields delivered by SAP. ● If, as a partner, you have your own reserved namespace, it is recommended that you choose the names for your append structures from your namespace. Enhancement of Tables Figure 71: Enhancement of Tables Structures and tables that have been defined by SAP in the ABAP Dictionary can be enhanced by the customer in the following ways: ● Customizing includes © Copyright. All rights reserved. 197 Unit 7: Table Changes With this variant, certain places within a standard structure or table are reserved by SAP for customer enhancements. The Customizing environment supports customers using these Customizing includes. Using appends ● With this variant, any fields without previous reservation are appended to the end of structures or tables. Caution: Enhancements using append structures may cause the following problems: ● Structure enhancements affect not only the enhanced structure itself, but also all dependent structures that use the enhanced structure as an include or substructure. However, when the enhanced structure is included in a dependent structure, this can lead to fields in the dependent structure being displaced. This is the case, for example, when the include appears in the middle of the dependent structure. The field displacement can prevent ABAP programs from reading the structure correctly. ● In programs with de-activated Unicode checks, structure enhancements can lead to syntax and runtime errors. These errors are generally found in type checks and in connection with deep structures. ● In programs with activated Unicode checks, structure enhancements additionally affect value assignments, operand checks, and accesses with offset and length. For example, numerical or deep components are inserted into a purely character-like structure. Enhancements may also cause some issues because the fragment view is changed, and checks in assignments and comparisons that are based on this are affected as a result. Enhancement Categories Table 4: Enhancement Categories Structures and tables in the ABAP dictionary are classified under Extras → Enhancement category. The following table shows the various enhancement categories: 198 Level Category Meaning 1 Not classified The structure does not have an enhancement category 2 Not enhanceable The structure cannot be enhanced 3 Enhanceable and characterlike All structure components and their enhancements must be character-like © Copyright. All rights reserved. Lesson: Enhancing Tables Using Append Structures Level Category Meaning 4 Enhanceable and characterlike or numerical The structure and its enhancement cannot contain any deep data types 5 Freely extendable The structure and its enhancements may contain components whose data type is optional The elementary types C, D, N, and T are described as character-like, the elementary types F, I, and P as numerical, and the elementary type X as hexadecimal. The deep types STRING and XSTRING are not supported. With structures and tables with includes or substructures, the enhancement categories of the Includes and substructures cannot be larger than those of the initial structure. For example, if the initial structure contains an Include of level 4, levels 2 and 3 are not permitted for the initial structure. Structure enhancements in the Dictionary can also have an effect on internal structures in ABAP programs if Dictionary structures in the source text are used as type, include, or substructure. These dependencies are considered implicitly in the ABAP program check. These dependencies also relate to non-classified structures that contain enhanceable includes or substructures. © Copyright. All rights reserved. 199 Unit 7: Table Changes 200 © Copyright. All rights reserved. Unit 7 Exercise 14 Add Enhancements to a Table Using an Append Structure Business Example Employees with management or maintenance functions have their workplace at an airport. These employees are assigned a telephone number and office location. Record this information in the database table ZEMPLOY##. You need to create an append structure for the table ZEMPLOY##. This table is automatically adjusted when you activate the append structure. The new fields are appended to the existing fields on the database. 1. Create an append structure for table ZEMPLOY## containing the following information: Field Data Element ZZAIRPORT S_AIRPORT ZZBUREAUNO S_BUREAUNO ZZTELNO S_TELNO Note: The field names in an append structure must be in the customer namespace for fields. This means that the field names must begin with ZZ or YY. 2. Run program BC430_CHECK to test your exercise. © Copyright. All rights reserved. 201 Unit 7 Solution 14 Add Enhancements to a Table Using an Append Structure Business Example Employees with management or maintenance functions have their workplace at an airport. These employees are assigned a telephone number and office location. Record this information in the database table ZEMPLOY##. You need to create an append structure for the table ZEMPLOY##. This table is automatically adjusted when you activate the append structure. The new fields are appended to the existing fields on the database. 1. Create an append structure for table ZEMPLOY## containing the following information: Field Data Element ZZAIRPORT S_AIRPORT ZZBUREAUNO S_BUREAUNO ZZTELNO S_TELNO Note: The field names in an append structure must be in the customer namespace for fields. This means that the field names must begin with ZZ or YY. a) Open the table ZEMPLOY## in Change mode. b) Choose Goto → Append Structure. c) In the dialog box, enter the required name for the append structure. It must satisfy the usual naming conventions. Choose Continue. d) The system displays the maintenance screen for the append structure. You maintain the append structure in the same way as you maintain a structure. e) Enter a short text and insert the fields ZZAIRPORT, ZZBUREAUNO, and ZZTELNO with the specified data elements. f) Activate the append structure. Choose Utilities → Activation Log to display the activation log. g) The table ZEMPLOY## is automatically adjusted when you activate the append structure. The new fields are appended to the existing fields on the database. 2. Run program BC430_CHECK to test your exercise. 202 © Copyright. All rights reserved. Lesson: Enhancing Tables Using Append Structures a) In the Command field, enter /oSA38 – to run ABAP Program Execution in a new session. b) Enter BC430_CHECK in the corresponding field. c) Choose Execute. d) Choose Unit 7, exercise 13-14. © Copyright. All rights reserved. 203 Unit 7: Table Changes LESSON SUMMARY You should now be able to: ● 204 Add enhancements to tables using append structures © Copyright. All rights reserved. Unit 7 Learning Assessment 1. Correct access by ABAP programs to a database table is not possible if the runtime object of the table is inconsistent with the structure of the table in the database. Determine whether this statement is true or false. X True X False 2. During the conversion process, the data is reloaded from table QCMTAB to table QCM8TAB with ______________. Choose the correct answer. X A ALTER TABLE X B MOVE-CORRESPONDING X C SELECT 3. If a conversion terminates, the following options are displayed as buttons in the database utility: Choose the correct answers. X A Continue Adjustment X B Unlock Table X C Discard Adjustment X D Reset Table 4. Identify the ways in which customers can enhance the structures and tables that have been defined by SAP in the ABAP Dictionary. Choose the correct answers. X A Using Customizing Includes X B Using append structures X C Using internal tables © Copyright. All rights reserved. 205 Unit 7 Learning Assessment - Answers 1. Correct access by ABAP programs to a database table is not possible if the runtime object of the table is inconsistent with the structure of the table in the database. Determine whether this statement is true or false. X True X False 2. During the conversion process, the data is reloaded from table QCMTAB to table QCM8TAB with ______________. Choose the correct answer. X A ALTER TABLE X B MOVE-CORRESPONDING X C SELECT 3. If a conversion terminates, the following options are displayed as buttons in the database utility: Choose the correct answers. 206 X A Continue Adjustment X B Unlock Table X C Discard Adjustment X D Reset Table © Copyright. All rights reserved. Unit 7: Learning Assessment - Answers 4. Identify the ways in which customers can enhance the structures and tables that have been defined by SAP in the ABAP Dictionary. Choose the correct answers. X A Using Customizing Includes X B Using append structures X C Using internal tables © Copyright. All rights reserved. 207 Unit 7: Learning Assessment - Answers 208 © Copyright. All rights reserved. UNIT 8 Views and Maintenance Views Lesson 1 Creating Database Views Exercise 15: Create a Database View 210 223 Lesson 2 Creating Maintenance Views Exercise 16: Create a Maintenance View 227 235 Lesson 3 Creating View Clusters Exercise 17: Create a View Cluster 240 243 UNIT OBJECTIVES ● Describe database views ● Define database views ● Describe maintenance views ● Create maintenance views ● Identify when to use maintenance views ● Define complex maintenance dialogs © Copyright. All rights reserved. 209 Unit 8 Lesson 1 Creating Database Views LESSON OVERVIEW This lesson explains how to define and create database views. Business Example To simplify the ABAP coding of your applications, you should create database views as an overview or as a combination of tables. For this reason, you require an understanding of the following: ● How to define database views ● How to create a database join ● How to recognize the difference between an inner join and an outer join ● How to create a simple and complex maintenance view LESSON OBJECTIVES After completing this lesson, you will be able to: ● Describe database views ● Define database views Database Views Figure 72: Database Views 210 © Copyright. All rights reserved. Lesson: Creating Database Views Data for an application object is often distributed across several database tables. Database systems provide you with a way of defining application-specific views of data in multiple tables. These are called views. Data from several tables can be combined in a meaningful way using a view (join). You can also hide information that is not important (projection) and display only those data records that satisfy certain conditions (selection). The data of a view can be displayed exactly like the data of a table in extended table maintenance. Structure of a View – Cross-Product as Starting Situation Figure 73: Structure of a View – Cross-Product as Starting Situation The structure of a view and selection of the data using this view are illustrated in the following example. The two tables used here are SCARR and SFLIGHT. The table SCARR contains two entries and the table SFLIGHT contains four entries. The tables are appended to one another. This results in a cross-product of both tables, in which each SCARR table record is combined with each SFLIGHT table record. © Copyright. All rights reserved. 211 Unit 8: Views and Maintenance Views Structure of a View – Join Condition Figure 74: Structure of a View – Join Condition Usually, the entire cross-product is not a good selection. Therefore, it is often necessary to limit the cross-product with a join condition. The join condition describes how the records in the two tables are related. In the example shown in the figure, the CARRID field for SCARR is compared with the CARRID field for SFLIGHT. The join condition used to limit the cross-product is SCARR-CARRID = SFLIGHT-CARRID. With this join condition, all the records whose entry in Field 1 (T1~CARRID) is not identical to the entry in Field 3 (T2~CARRID) are removed from the cross-product. As a result, the column for Field 3 (T2~CARRID) in the view is unnecessary. 212 © Copyright. All rights reserved. Lesson: Creating Database Views Structure of a View – Field Selection (Projection) Figure 75: Structure of a View – Field Selection (Projection) Often some of the fields of the tables involved in a view are of no interest. You can explicitly define the set of fields to be excluded from the view (projection). In the example shown in the figure, the PLANETYPE field is not important and can, therefore, be hidden. © Copyright. All rights reserved. 213 Unit 8: Views and Maintenance Views Structure of a View – Selection Condition Figure 76: Structure of a View – Selection Condition The set of records that can be displayed with the view can be further restricted with a selection condition. In the example shown in the figure, only records that have the value DL in the CARRID field can be displayed with the view. Therefore, a selection condition can be formulated with fields included in the view, and fields which are not contained in the view. 214 © Copyright. All rights reserved. Lesson: Creating Database Views Database View Definition Figure 77: Example Tables of a Database View Definition To explain how the tables are linked to views, the figure shows an example. Sometimes, travel agencies have to check which customer is booked on which flights. The corresponding data is distributed across several tables. Table 5: Tables used as an Example of a Database View Definition Table Description SCUSTOM Customer data, such as the customer number, name, and address SBOOK Booking data, such as the airline, flight number, and passenger (customer number) SPFLI Flight data, such as the city of departure and city of arrival You have to create a view of the tables SCUSTOM, SBOOK, and SPFLI to obtain the booking data. You can determine all the bookings in table SBOOK for a customer number (ID) for the customer number in table SCUSTOM. Using the carrier ID (CARRID) and the flight number (CONNID), the flight information can be read from table SPFLI for a booking that is found. In this example, the join conditions are as follows: ● SBOOK-MANDT = SCUSTOM-MANDT ● SCUSTOM-ID = SBOOK-CUSTOMID © Copyright. All rights reserved. 215 Unit 8: Views and Maintenance Views ● SPFLI-MANDT = SBOOK-MANDT ● SPFLI-CARRID = SBOOK-CARRID ● SPFLI-CONNID = SBOOK-CONNID Structure of the View Figure 78: Structure of the View You can see the bookings for a particular customer by selecting the corresponding records for keys MANDT and CUSTOMID in table SBOOK. For each booking in table SBOOK, you can obtain additional flight data using table SPFLI. To obtain this flight data, you can select the corresponding record using the keys MANDT, CARRID, and CONNID from table SPFLI. You can display only the customer bookings that were not canceled using the view with the selection condition SBOOK-CANCELED <> X. The join conditions can also be derived from the existing foreign key relationships. Copying the join conditions from the existing foreign keys is supported in the maintenance transaction. The field names of the underlying table fields are used as field names in the view. However, you can also choose a different field name. You need to choose a different field name if two fields with the same name are to be copied to the view from different tables. In this case, you must choose a different name for one of the two fields in the view. 216 © Copyright. All rights reserved. Lesson: Creating Database Views Data Selection with Views Figure 79: Data Selection with Views You can also formulate the join condition directly in OPEN SQL. You obtain the same result when using an inner Join. SELECT C~CARRID C~CARRNAME P~CONNID P~CITYFROM P~CITYTO F~FLDATE F~SEATSMAX F~SEATSOCC INTO TABLE ITAB_FLIGHTS FROM ( SCARR AS C INNER JOIN SPFLI AS P ON C~CARRID = P~CARRID ) INNER JOIN SFLIGHT AS F ON F~CARRID = P~CARRID AND F~CONNID = P~CONNID WHERE CITYFROM IN SO_CITYF AND CITYTO IN SO_CITYT AND SEATSOCC < F~SEATSMAX ORDER BY C~CARRID P~CONNID F~FLDATE. Note that the performance of OPEN SQL joins is not as good as the performance of statically defined database views. A view defined in the ABAP Dictionary is a data type that can be used in ABAP programs, in the same way as other ABAP Dictionary data types. © Copyright. All rights reserved. 217 Unit 8: Views and Maintenance Views Inner and Outer Join Figure 80: Inner and Outer Join The set of data that can be selected with a view depends on whether the view implements an inner join or an outer join. With an inner join, you only receive those records that have an entry in all the tables included in the view. With an outer join, the records that do not have a corresponding entry in some of the tables included in the view are also selected. Therefore, the result set of an inner join can be a subset of the result set of an outer join. Database views implement an inner join. You only obtain the records that have an entry in all the tables included in the view. Maintenance views implement an outer join. 218 © Copyright. All rights reserved. Lesson: Creating Database Views Note: As of SAP NetWeaver 7.4, a new repository object type called External View is available in the ABAP Dictionary. External Views can be created in an ABAP System using SAP HANA as the primary database, and represent an SAP HANA view on the ABAP side. In other words, an External View is a proxy in the ABAP Dictionary for an SAP HANA view. The External View’s definition and usage is explained in the course ABAP Programming for SAP HANA. External views can be created only using the ABAP Development Tools (ADT) and only if the current database is an SAP HANA database. When an external view is activated, an alias with the name of the view is created on the SAP HANA database that points to the SAP HANA view. The names of the view fields of the external view can be defined differently from the names of the view fields of the SAP HANA view. The runtime object of the external view accesses the alias on the SAP HANA database. This performs a mapping of HANA-specific data types to predefined types in ABAP Dictionary. External views can be displayed in the ABAP Dictionary tool in the SAP GUI-based ABAP Workbench, but they cannot be edited. Database Views Figure 81: Database Views A database view is defined in the ABAP Dictionary and automatically created in the database during activation. Accesses to a database view are passed directly to the database from the database interface. The database software performs the data selection. The data in ABAP programs can be accessed with both OPEN SQL and NATIVE SQL. © Copyright. All rights reserved. 219 Unit 8: Views and Maintenance Views If the definition of a database view is changed in the ABAP Dictionary, the view created in the database must be adjusted to this change. As a view does not contain any data, this adjustment is made by deleting the old view definition and creating the view again in the ABAP Dictionary with its new definition. The maintenance status defines whether you can only read with the view or whether you can also write with it. If a database view was defined with more than one table, you can only read with this view. The data read with a database view can be buffered. View data is buffered in the same way as with tables. The technical settings of a database view control whether the view data may be buffered and how this should be done. The same settings (buffering types) can be used here as for table buffering. The buffered view data is invalidated when the data in one of the base tables of the view changes. Selection with a database view is faster than access to individual tables. When selecting with views, you must also ensure that there are suitable indexes on the tables contained in the view. Dynamic Attachment of Table Fields in Database Views Figure 82: Dynamic Attachment of Table Fields in Database Views You can include entire tables in database views. In this case, all the fields of the included table become fields of the view (whereby you can explicitly exclude certain fields). If new fields are included in the table or existing fields are deleted, the view is automatically adjusted to this change. A new or deleted field is therefore automatically included in the view or deleted from it. If an append structure is added to a table included in a view, the fields added with the append structure are automatically included in the view. To include a table in a view, you must enter the character “*” in the field View field in the view maintenance, the name of the table to be included in the field Table, and the character “*” again in the field Field name. 220 © Copyright. All rights reserved. Lesson: Creating Database Views If you do not want to insert a field of the included table in the view, you must enter a “-” in the View field, the name of the included table in the Table field, and the name of the field to be excluded in the Field name field. By using an append view, you can include fields of the base tables of a database view in the view without modifications. Using an append view is similar to enhancing a table with an append structure. An append view is assigned to one database view. More than one append view can be created for one database view. © Copyright. All rights reserved. 221 Unit 8: Views and Maintenance Views 222 © Copyright. All rights reserved. Unit 8 Exercise 15 Create a Database View Business Example The data for an employee is distributed across several tables (according to the relational data model). However, for some tasks, a complete view of this data is needed. In this exercise, the corresponding views are implemented by creating database views. The flight personnel (all pilots and stewards) must be selected when a flight crew is set up. Not all the data in the table ZEMPLOY## may be displayed when this data is accessed, for example, the employee setting up the teams must not see the salary of the crew members. The telephone number of the employee’s department should be shown in case there are any questions. You need to create views, define join conditions, and buffer database views. 1. Create a suitable database view ZEMPFLY## that satisfies the requirements. The following information about an employee should be displayed: ● Client ● Airline ● Personnel number ● First name ● Last name ● Telephone number of the department ● Department code Note: The view should permit a view of the data in the tables ZEMPLOY## and ZDEPMENT##. The view should display data about employees (from table ZEMPLOY##) and departments (from table ZDEPMENT##). 2. Copy the fields from the tables into the view. 3. Make sure that only flight personnel can be selected with the view. On the Selection conditions tab page, define this restriction. 4. Buffer the view. You probably will have to (frequently) access the data using the view. Therefore, the selected data should be buffered to increase performance. On the technical settings screen, select the Full Buffering checkbox. © Copyright. All rights reserved. 223 Unit 8 Solution 15 Create a Database View Business Example The data for an employee is distributed across several tables (according to the relational data model). However, for some tasks, a complete view of this data is needed. In this exercise, the corresponding views are implemented by creating database views. The flight personnel (all pilots and stewards) must be selected when a flight crew is set up. Not all the data in the table ZEMPLOY## may be displayed when this data is accessed, for example, the employee setting up the teams must not see the salary of the crew members. The telephone number of the employee’s department should be shown in case there are any questions. You need to create views, define join conditions, and buffer database views. 1. Create a suitable database view ZEMPFLY## that satisfies the requirements. The following information about an employee should be displayed: ● Client ● Airline ● Personnel number ● First name ● Last name ● Telephone number of the department ● Department code Note: The view should permit a view of the data in the tables ZEMPLOY## and ZDEPMENT##. The view should display data about employees (from table ZEMPLOY##) and departments (from table ZDEPMENT##). a) In the ABAP Dictionary: Initial Screen, choose the View object type, enter the object name ZEMPFLY##, and choose Create. b) In the Choose View Typedialog box, select the Database view radio button. c) Choose the Continue button. d) Enter a short text in the Short Descriptionfield and enter table ZEMPLOY## in the Tables field. 224 © Copyright. All rights reserved. Lesson: Creating Database Views e) Choose the Relationships button. All the foreign key relationships of the table ZEMPLOY## to other tables are listed. Mark the relationship to table ZDEPMENT## and choose the Copy button. The join conditions are copied from the foreign key. f) In a second SAP GUI window, display the foreign key between the two tables and notice the relationship between the foreign key and the join conditions. 2. Copy the fields from the tables into the view. a) Choose the View fields tab. b) Choose the Table Fields button. In the next dialog box, mark the table ZEMPLOY## and select the Choose button. c) All the fields of the table ZEMPLOY## are listed. Mark the fields Client, Airline, Personnel number, First name, and Last name. Choose the Copy button. The fields are now inserted in the view. d) Choose the Table Fields button again. In the dialog box, choose table ZDEPMENT## and insert the fields Department telephoneand Department codein the view, as described above. e) Choose the Selection conditionstab. 3. Make sure that only flight personnel can be selected with the view. On the Selection conditions tab page, define this restriction. a) The restriction based on whether an employee belongs to the flight personnel is contained in field Area in the ZEMPLOY## table. Enter the table names and fields in the columns Table and Field name. b) As flight personnel are identified by the value F in the AREA field, enter “EQ” in the column Operator and ‘F’ in the column Compar. Value. 4. Buffer the view. You probably will have to (frequently) access the data using the view. Therefore, the selected data should be buffered to increase performance. On the technical settings screen, select the Full Buffering checkbox. a) Choose Goto → Technical settings.The maintenance screen for the technical settings of the view appears. With the exception of some attributes that are meaningless for views and are therefore not displayed, the screen is similar to the corresponding maintenance screen for tables. b) Select the Buffering activatedradio button. c) Select the Fully buffered checkbox. d) Save the technical settings and return to the View Maintenance screen. e) Activate the view. © Copyright. All rights reserved. 225 Unit 8: Views and Maintenance Views LESSON SUMMARY You should now be able to: 226 ● Describe database views ● Define database views © Copyright. All rights reserved. Unit 8 Lesson 2 Creating Maintenance Views LESSON OVERVIEW This lesson describes the maintenance views and explains when to use them. Business Example You need to define maintenance views. For this reason, you require an understanding of the following: ● How to create maintenance views ● How to use maintenance views LESSON OBJECTIVES After completing this lesson, you will be able to: ● Describe maintenance views ● Create maintenance views ● Identify when to use maintenance views © Copyright. All rights reserved. 227 Unit 8: Views and Maintenance Views Maintenance Views Figure 83: Collecting Data with Generated Maintenance Masks Data that is distributed across more than one table forms a logical unit, called an application object. The technical implementation of the application object, such as the distribution of the data across several tables, is not relevant for the end user. You can easily maintain application objects by using a maintenance view. The data is automatically distributed across the underlying database tables. All the tables used in a maintenance view must be linked with a foreign key. The join conditions are always derived from the foreign key in the maintenance view. You cannot enter the join conditions directly as in a database view. A maintenance user interface with which the data of the view can be displayed, changed, and created must be generated from the definition of a maintenance view in the ABAP Dictionary. The maintenance status determines which accesses to the data of the underlying tables are possible with the maintenance view. When the maintenance user interface is created, function modules that distribute the data maintained with the view of the underlying tables are generated automatically. The maintenance user interface is generated with the transaction Generate Table Maintenance Dialog (transaction SE54) or from within ABAP Dictionary by choosing Utilities → Table Maintenance Generator. 228 © Copyright. All rights reserved. Lesson: Creating Maintenance Views Maintenance Dialog for a Maintenance View Figure 84: Maintenance Dialog for a Maintenance View In a one-step maintenance dialog, the data of the table rows is represented as a table control. The key fields have a gray background and are not intended for changes. The function fields have a white background and can be changed. In a two-step maintenance dialog, double-click a table line to present the selected data record in a clear form. © Copyright. All rights reserved. 229 Unit 8: Views and Maintenance Views Maintenance View Creation Figure 85: Define Maintenance View 1 When creating a maintenance view, consider the following points: ● Select Maintenance View as the View Type. ● Place all the key fields of primary table in the View Definition. ● Include the client field for client-dependent tables or views. However, the client field is not displayed in the maintenance view. Note: Do not copy the language fields for text tables as secondary tables. During maintenance, the logon language is automatically provided in the text tables ● First define the key fields, then define the function fields. The function fields and the key fields cannot be in a mixed order. Each field can have one of the following maintenance attributes: ● R (read only) A field flagged R is not ready for input by the user on the screen. When a new data record is created, it must be filled automatically in the background. ● H (hidden) A field flagged H is not displayed on the screen. 230 © Copyright. All rights reserved. Lesson: Creating Maintenance Views When a new data record is saved, the system writes R and H fields to the database like all other fields. ● S (subset) A field flagged S restricts the work area. The system only shows data records for which this subset field has the specified value. This restriction of the work area remains effective when you create new data records. Fields of a referred table cannot be maintained and have the maintenance attribute R. You can assign a maintenance attribute P to individual fields in the maintenance view definition in the Dictionary (transaction code SE11). Creation of a Maintenance View Figure 86: Define Maintenance View 2 Enter an explanatory short text in the short description field. Steps for Creating a Maintenance View The following steps are used to create a maintenance view: ● Copy tables Specify the primary table of the view on the Tables tab page or Join Conditions under Tables. Only those tables can be included in the maintenance view that are connected to the primary table (indirectly) by a foreign key. If necessary, include other tables in the view. You can only include tables in a maintenance view that are connected to one another through foreign keys. Position the cursor on the primary table and choose Relationships. All existing foreign key relationships of the © Copyright. All rights reserved. 231 Unit 8: Views and Maintenance Views primary table are displayed. Select the desired foreign key and choose Copy. The secondary table involved in the foreign key is copied in the view. The join conditions (foreign key relationship and join condition) derived from the foreign keys are displayed. You can also include tables that are connected to one of the previously copied secondary tables via a foreign key. Position the cursor on the secondary table and activate Relationships. The foreign key relationships for which a maintenance view is not appropriate are displayed at the end of the list under the heading “Relationships with unsuitable cardinality”. ● Copy the View Fields On the View field tab page, select the fields that you want to copy to the view. Activate Table fields. All the tables contained in the view are displayed in a dialog box. When you select a table, the fields of the table are displayed in a dialog box. You can remove fields by highlighting these in the first column and choosing Copy. All the key fields of the primary table must be included in a maintenance view. In addition, all the key fields of secondary tables that are not involved in the foreign key (that is, they are not connected via a join condition to a key field already included in the view) must be included in the view. This ensures that the records inserted via a maintenance view can be written correctly in the tables contained in the view. ● Selection Conditions On the Selection Conditionstab page, formulate (optional) restrictions for the data records that can be displayed with the view (see Maintain selection condition of the view). The selection conditions define which data records can be selected with the view. Note: You can use maintenance view variants in maintenance views. Maintenance view variants are partial views of generated maintenance dialogs. For example, a maintenance view variant restricts the maintenance dialog on which it is based to a smaller number of maintainable fields, or uses a more restrictive database selection than the initial dialog. The maintenance view variant has no maintenance dialog of its own. It uses the maintenance dialog on which it is based, including the maintenance screens and all its checks. Caution: In data maintenance, the maintenance view selection conditions and, following those, the maintenance view variant selection conditions apply. The maintenance view selection conditions apply only if they were generated in the maintenance dialog. If, for example, the selection conditions are put in the ABAP/4 Dictionary later and the maintenance dialog was not regenerated, these selection conditions do not apply in the maintenance view variant. ● Maintenance Status On the Maintenance Statustab page, define the maintenance status of the view. The maintenance status determines how you can access the view data via standard view maintenance (SM30). 232 © Copyright. All rights reserved. Lesson: Creating Maintenance Views ● Activate A log is written during activation, which you can display by choosing Utilities → Activation log. If errors or warnings occurred when the view is activated, the activation log is displayed automatically. Generate Maintenance Dialog Figure 87: Generate a Maintenance Dialog You can generate maintenance modules and maintenance interfaces from the view definition, which take care of the distribution of the data entered by the view to the basis tables of the view. You reach the generation environment for maintenance views by one of the following methods: ● In the ABAP Dictionary (transaction code SE11), choose Utilities → Table Maintenance Generator. ● In the SAP Easy Access menu, choose Tools → ABAP Workbench → Development → Other Tools → Generate Table Maintenance Dialog. ● Call transaction SE54 directly. On the initial screen of the Generate Table Maintenance Dialog transaction, perform the following steps: ● Enter the name of the table or the view on which the maintenance dialog is to be based. ● Select Generated Objects. © Copyright. All rights reserved. 233 Unit 8: Views and Maintenance Views ● Choose the Create/Change button. Parameters Specified in the Definition of the Maintenance Dialog In the definition of the maintenance dialog, you must specify the following parameters: ● Function group You define the function group in which components of the maintenance dialog are generated. If necessary, create a new function group. ● Authorization group You specify which users are authorized to maintain the tables/view contents via the authorization group. ● Maintenance type You define whether the dialog consists of one or two steps via the maintenance type. Onestep dialogs consist only of one overview screen that contains all fields. With two-step dialogs, only the key fields and text fields with a length of more than 20 characters are displayed in the overview screen. The complete list of fields is offered in the detailed screen. ● Maintenance screens Here you specify the internal number of every maintenance screen. When you choose the Find Screen Numbersbutton, the system proposes available screen numbers. ● Recording routine With recording routine, you specify whether and how tables/view contents maintained with a dialog can be included in a transport. Once you have entered all of the values, generation of the maintenance dialog is started. If this process runs without any errors, the dialog can be used immediately to maintain the tables/ view contents. To do this, start transaction SM30 and enter the table or view, for which you have generated the maintenance dialog, in the Table/View field. Activate the Maintenance button. 234 © Copyright. All rights reserved. Unit 8 Exercise 16 Create a Maintenance View Business Example You need to create a simple maintenance dialog for your database tables to generate test data quickly in your project. You need to create a maintenance view with the name ZPARTNER##, with which you can easily maintain new business partners. Note: The business partners are entered in the table SBUSPART. A business partner can be either a flight customer or a travel agency. If it is a travel agency, there will be a corresponding entry in the table STRAVELAG. The view should permit you to maintain the tables SBUSPART and STRAVELAG at once. Include all the necessary fields of the tables in the view. You want to maintain the data in tables SBUSPART and STRAVELAG together in the maintenance view. To enter a new partner directly, you must first enter it in the table SBUSPART. Only then can you enter the corresponding data in the table STRAVELAG (because of the existing foreign key check between SBUSPART and STRAVELAG). 1. Create a maintenance view named ZPARTNER##. 2. Include the fields of both tables in the view. 3. Generate a maintenance dialog for the view. Use the following parameters: Field Name Value Function group ZZBC430## Authorization group SUNI Maintenance type one-step Overview screen 100 4. Enter the data for a new travel agency using extended table maintenance. © Copyright. All rights reserved. 235 Unit 8 Solution 16 Create a Maintenance View Business Example You need to create a simple maintenance dialog for your database tables to generate test data quickly in your project. You need to create a maintenance view with the name ZPARTNER##, with which you can easily maintain new business partners. Note: The business partners are entered in the table SBUSPART. A business partner can be either a flight customer or a travel agency. If it is a travel agency, there will be a corresponding entry in the table STRAVELAG. The view should permit you to maintain the tables SBUSPART and STRAVELAG at once. Include all the necessary fields of the tables in the view. You want to maintain the data in tables SBUSPART and STRAVELAG together in the maintenance view. To enter a new partner directly, you must first enter it in the table SBUSPART. Only then can you enter the corresponding data in the table STRAVELAG (because of the existing foreign key check between SBUSPART and STRAVELAG). 1. Create a maintenance view named ZPARTNER##. a) In the ABAP Dictionary, create the view ZPARTNER##. Choose Maintenance view as the view type. b) Enter the SBUSPART table in the Tables field. The key fields of this table are automatically included in the view as fields. c) Place the cursor in the Tables field on the SBUSPART entry. Choose the Relationships button. d) A dialog box appears listing all the existing foreign key relationships between the table SBUSPART and other tables. e) In the dialog box, select the foreign key relationship for the STRAVELAG table and choose Copy. f) The join conditions are created from the foreign key. The join conditions have the following form: SBUSPART-MANDANT = STRAVELAG-MANDT SBUSPART-BUSPARTNUM = STRAVELAG-AGENCYNUM 2. Include the fields of both tables in the view. 236 © Copyright. All rights reserved. Lesson: Creating Maintenance Views a) On the View fields tab page, choose the Table fields button and select the table SBUSPART. A list of all the fields of the table appears. Choose the Select all button and then the Copy button. b) Include all the fields of the STRAVELAG table, with the exception of the fields MANDT and AGENCYNUM in the view in the same way. These fields are linked to the corresponding fields of the table SBUSPART, with the join conditions, and therefore should not appear in the view. c) Activate the view. 3. Generate a maintenance dialog for the view. Use the following parameters: Field Name Value Function group ZZBC430## Authorization group SUNI Maintenance type one-step Overview screen 100 a) Choose Utilities → Table Maintenance Generator. b) On the next screen, enter the Authorization group, Function group, and Maintenance type as listed in the table. Select 0100 as the maintenance screen number of the overview screen. c) Choose Create. When prompted for packages for the function group and the generated maintenance objects, choose Local Object. 4. Enter the data for a new travel agency using extended table maintenance. a) Choose System → Services → Table maintenance → Extended Table maintenance → Enter View Name → Maintain. b) Enter the data for a new travel agency. c) With the Data Browser (in the Environment menu of the initial screen of the ABAP Dictionary), verify that the data for the new travel agency has been written to the tables SBUSPART and STRAVELAG. © Copyright. All rights reserved. 237 Unit 8: Views and Maintenance Views Advantages and Disadvantages of Maintenance Dialogs Figure 88: Advantages and Disadvantages of Maintenance Dialogs Generated maintenance dialogs should not be used regularly by a large number of users. These dialogs are intended to enable a limited number of users to quickly and easily maintain customizing tables and customer tables containing small to medium volumes of data. 238 © Copyright. All rights reserved. Lesson: Creating Maintenance Views LESSON SUMMARY You should now be able to: ● Describe maintenance views ● Create maintenance views ● Identify when to use maintenance views © Copyright. All rights reserved. 239 Unit 8 Lesson 3 Creating View Clusters LESSON OVERVIEW This lesson describes view clusters of maintenance views. Business Example You need to define complex maintenance dialogs. For this reason, you require an understanding of the following: ● How to create view clusters ● How to define complex maintenance dialogs LESSON OBJECTIVES After completing this lesson, you will be able to: ● Define complex maintenance dialogs View Clusters Figure 89: View Clusters and Maintenance Views 240 © Copyright. All rights reserved. Lesson: Creating View Clusters If you have generated multiple maintenance dialogs for views, you can combine these to a view cluster. A view cluster is a group of maintenance dialogs combined in one maintenance unit for business or technical reasons. While maintenance views can be used to maintain only database tables that have a 1:1 relationship with one another (with the exception of language-dependent text tables), you can use view clusters to maintain database tables that have an N:M relationship with one another. Also, maintenance views can be combined into a view cluster without a key or sub key dependency. The navigation within the view cluster is generally oriented towards the hierarchy of the tables or views underlying the individual dialogs. Master - Detail - Relationships, even those over several levels, are especially suitable for a view cluster. A view cluster consists of one or more root dialogs. A maximum of 14 maintenance dialogs can be combined in a view cluster. Each maintenance dialog can be either a one-step dialog or a two-step dialog. Before creating a view cluster, you must first generate maintenance dialogs for each individual maintenance view. You can then combine these dialogs in a view cluster. Use transaction SM34 to maintain the data in a view cluster. Advantages The advantages of view clusters are as follows: Advantages of View Clusters ● Navigation In a view cluster, you can comfortably navigate between the individual maintenance dialogs. Easy navigation simplifies the maintenance of the data in a view cluster. ● Consistency The view cluster ensures data consistency when deleting, copying, saving, retrieving, and manually transporting data. Therefore, when deleting an entry in a higher-level view, it automatically ensures that all dependent entries in lower-level views are also deleted. © Copyright. All rights reserved. 241 Unit 8: Views and Maintenance Views 242 © Copyright. All rights reserved. Unit 8 Exercise 17 Create a View Cluster Business Example You want to bundle maintenance dialogs in a view cluster. Generate multiple maintenance dialogs for dependent database tables. Combine these maintenance dialogs in a view cluster. In this exercise, use the table from the flight data model again. You need to copy these tables, including their entire content, to the customer namespace. 1. Copy the tables SCARR, SPFLI, and SFLIGHT to the customer namespace with your group number ZCARR##, ZPFLI##, and ZFLIGHT##. Maintain the foreign keys appropriately in the new tables. 2. Copy the content of the original tables to the newly created tables using a report. 3. Create a two-step maintenance dialog (for example, screen numbers 100 and 110) for every table copied. 4. Create a view cluster with the name ZPC_FLIGHT##. 5. Enter a meaningful short description in the header. 6. Change to the Object structureand enter the following new entries: View/Table Short Description Predecessor Dep Pos ZCARR## Carriers ZCARR## R 1 ZPFLI## Flight connections ZCARR## S 2 ZFLIGHT## Flights of the connection ZPFLI## S 3 7. Generate the field dependencies for every entry in the list. 8. Activate the view cluster. 9. Create an entry for a new airline, set up two flight connections and two flights for each flight connection. © Copyright. All rights reserved. 243 Unit 8 Solution 17 Create a View Cluster Business Example You want to bundle maintenance dialogs in a view cluster. Generate multiple maintenance dialogs for dependent database tables. Combine these maintenance dialogs in a view cluster. In this exercise, use the table from the flight data model again. You need to copy these tables, including their entire content, to the customer namespace. 1. Copy the tables SCARR, SPFLI, and SFLIGHT to the customer namespace with your group number ZCARR##, ZPFLI##, and ZFLIGHT##. Maintain the foreign keys appropriately in the new tables. a) Copy and activate the tables using transaction SE11. Adjust the foreign key relationships ZPFLI## (CARRID →ZCARR##) and ZFLIGHT## (CARRID →ZCARR##, CONNID →ZPFLI##). 2. Copy the content of the original tables to the newly created tables using a report. a) See the source code of the model solution. You can also find and copy the respective report in the system. REPORT SAPBC430S_FILL_CLUSTER_TAB. DATA wa_scarr TYPE scarr. DATA wa_spfli TYPE spfli. DATA wa_flight TYPE sflight. DATA my_error TYPE i VALUE 0. START-OF-SELECTION. * Replace ## by Your user-number DELETE FROM zcarr##. DELETE FROM zpfli##. DELETE FROM zflight##. SELECT * FROM scarr INTO wa_scarr. INSERT INTO zcarr## VALUES wa_scarr. ENDSELECT. IF sy-subrc = 0. SELECT * FROM spfli INTO wa_spfli. INSERT INTO zpfli## VALUES wa_spfli. ENDSELECT. IF sy-subrc = 0. 244 © Copyright. All rights reserved. Lesson: Creating View Clusters SELECT * FROM sflight INTO wa_flight. INSERT INTO zflight## VALUES wa_flight. ENDSELECT. IF sy-subrc <> 0. my_error = 1. ENDIF. ELSE. my_error = 2. ENDIF. ELSE. my_error = 3. ENDIF. IF my_error = 0. WRITE / 'Data transport successfully finished'. ELSE. WRITE: / 'ERROR:', my_error. ENDIF. 3. Create a two-step maintenance dialog (for example, screen numbers 100 and 110) for every table copied. a) There are two ways of displaying the relevant screen in transaction SE54: ● ● In SE11, enter the table name and choose Utilities → Table maintenance generator to go to the generation environment for the table. Run transaction SE54 and enter the respective table. Select Generated objectand choose the Create or Change button. b) On the Maintenance Generatorscreen, enter the authorization group SUNI and specify the respective table names with the prefix ZFP_## as the function group. c) Select the Two Step radio button as the maintenance type. Select the numbers 0100 and 0110 as the maintenance screen numbers of the overview screen and single screen. d) Choose the Create button. The package of the function group and the generated maintenance objects are prompted. In both cases, choose Local object. e) Repeat this with all copied tables. 4. Create a view cluster with the name ZPC_FLIGHT##. a) Run the transaction code SE54. On the initial screen, choose Edit View Cluster to access the screen for editing or creating a view cluster. b) Enter the name of the cluster in the View cluster field. c) Choose the Create or Change button. d) Ignore the message “No changes please (data belong to SAP)”. As long as you stay in the customer namespace (Z* or Y*), this message is meaningless. 5. Enter a meaningful short description in the header. 6. Change to the Object structureand enter the following new entries: View/Table Short Description Predecessor Dep Pos ZCARR## Carriers ZCARR## R 1 © Copyright. All rights reserved. 245 Unit 8: Views and Maintenance Views View/Table Short Description Predecessor Dep Pos ZPFLI## Flight connections ZCARR## S 2 ZFLIGHT## Flights of the connection ZPFLI## S 3 a) In the navigation window, double-click Dialog structure on the Object structurenode. b) Choose the New entries button. c) Enter the values respectively in the table. d) Select the ZCARR## table as the initial object through the START column. 7. Generate the field dependencies for every entry in the list. a) Select every line of the object structure and generate the field dependencies with the Field dependencybutton. 8. Activate the view cluster. a) Double-click the dialog for the header entry and choose the Activate button. 9. Create an entry for a new airline, set up two flight connections and two flights for each flight connection. a) Run the transaction code SM34. b) Enter the name of your view cluster in the input field and choose the Maintain button. c) Create the new entries, beginning with ZCARR##. Note: You can navigate on the left-hand side of the screen and enter or change the data on the right-hand side. d) Fill in data and save your entries. e) Repeat the same steps for ZPFLI## and ZFLIGHT## and enter the flight and the flight connection data. Note: For number screens, you can use 200 and 210 for ZPFLI##, and for the table ZFLIGHT##, you can use screen numbers 300 and 310 for the twostep maintenance dialog. f) Run the transaction code SM34 to display the new data. 246 © Copyright. All rights reserved. Lesson: Creating View Clusters LESSON SUMMARY You should now be able to: ● Define complex maintenance dialogs © Copyright. All rights reserved. 247 Unit 8: Views and Maintenance Views 248 © Copyright. All rights reserved. Unit 8 Learning Assessment 1. In a database view, a _____ condition can be formulated with fields included in the view, and fields that are not contained in the view. Choose the correct answer. X A selection X B table X C projection 2. A ____________ is defined in the ABAP Dictionary and automatically created on the database during activation. Choose the correct answer. X A view cluster X B database view X C field name 3. When you create a maintenance view, the key fields must be defined before the function fields. Determine whether this statement is true or false. X True X False 4. A view cluster consists of one or more _________________ views. Choose the correct answer. X A database X B maintenance X C help © Copyright. All rights reserved. 249 Unit 8 Learning Assessment - Answers 1. In a database view, a _____ condition can be formulated with fields included in the view, and fields that are not contained in the view. Choose the correct answer. X A selection X B table X C projection 2. A ____________ is defined in the ABAP Dictionary and automatically created on the database during activation. Choose the correct answer. X A view cluster X B database view X C field name 3. When you create a maintenance view, the key fields must be defined before the function fields. Determine whether this statement is true or false. X True X False 4. A view cluster consists of one or more _________________ views. Choose the correct answer. 250 X A database X B maintenance X C help © Copyright. All rights reserved. UNIT 9 Search Helps Lesson 1 Creating Search Helps Exercise 18: Create Search Helps 252 267 Lesson 2 Applying Advanced Search Help Techniques Exercise 19: Create Collective Search Helps Exercise 20: Create Append Search Helps 271 275 279 UNIT OBJECTIVES ● Describe the input help process ● Create elementary search helps ● Create collective search helps ● Create append search helps to enhance search helps ● Implement search help exits © Copyright. All rights reserved. 251 Unit 9 Lesson 1 Creating Search Helps LESSON OVERVIEW This lesson describes the input help process and elementary search helps. Business Example You need to create dialog boxes that provide users with simple input help. LESSON OBJECTIVES After completing this lesson, you will be able to: ● Describe the input help process ● Create elementary search helps The Input Help Process Figure 90: SAP Standard Function – Input Help The input help (F4) is a standard function of the SAP system that allows the user to display a list of possible values for a screen field. A value can be directly copied to an input field by selecting it from the list. Fields that have input help are shown in the SAP system by the input help key to the right of the field. This key appears as soon as the cursor is positioned on the corresponding screen field. The help can be started either by selecting the input help key or with function key F4. 252 © Copyright. All rights reserved. Lesson: Creating Search Helps If the number of possible entries for a field is very large, you can limit the set of values displayed by entering further restrictions. The possible entries are displayed with further useful information about the values shown. This feature is especially useful if the field requires the entry of a formal key. As the input help is a standard function, it looks and behaves the same throughout the entire SAP system. The development environment, therefore, provides tools for attaching a standardized input help to a screen field. The precise description of the input help for a field is usually defined by its semantics. For this reason, the input help for a field is normally defined in the ABAP Dictionary. Input Help Requirements Figure 91: Input Help Requirements The following requirements must be met by the input help of a screen field (search field): ● Information (about the context) known to the system must be taken into consideration in the input help. This includes entries the user already made in the current input template as well as information obtained in previous dialog steps. Normally, the input help uses the context to limit the set of possible values. ● The input help must determine the values that can be offered to the user for selection. The data to be displayed as supplementary information in the list of possible values must also be determined. When the possible values are determined, the restrictions resulting from the context and from further search conditions specified by the user must also be taken into consideration. ● The input help must hold a dialog with the user. This dialog always contains the presentation of the possible values (with supplementary information) in list form and the © Copyright. All rights reserved. 253 Unit 9: Search Helps possibility to select a value from this list. A search template in which the user can define conditions for the values to be displayed is also sometimes required. ● If the user selects a value, the input help must return the value to the search field. The input template often contains more fields (often only display fields) containing further explanatory information about the search field. The input help should also update the contents of these fields in this case. Elementary Search Helps Figure 92: ABAP Dictionary Object Search Help The ABAP Dictionary object search help is used to describe an input help. The definition of a search help contains the information the system needs to satisfy the described requirements. An elementary search help defines the standard flow of an input help. You can define the following components of this flow in the search help: ● Where the data displayed in the hit list must come from (selection method). Which enhanced options are to be provided for the search method (type-ahead and full text search). ● What information must be displayed in the dialog box for value selection and in the hit list (search help parameters). ● Which field contents can be taken into account for hit list selections and which values in the hit list can be returned to the screen fields (search help parameters). ● Which dialog steps must be executed in the input help (dialog behavior). The interface of the search help controls the data transfer from the input template to the input help and back. The interface defines the context data to be used and the data to be returned to the input template when a value is selected. 254 © Copyright. All rights reserved. Lesson: Creating Search Helps The internal behavior of the search help describes the value help process itself. This includes the selection method with which the values to be displayed are determined, as well as the dialog behavior describing the interaction with the user. As with a function module, a search help distinguishes between the interface with which it exchanges data with other software components and the internal behavior (for function modules, the latter is defined by the source text). Like the editor for function modules, the editor for search helps also enables you to test an object. You can test the behavior of a search help without attaching it to a screen field. Selection Method of a Search Help Figure 93: Selection Method of a Search Help The possible values displayed for a field by the input help are determined at runtime by a selection from the database. When a search help is defined, you must define the database object from which the data should be selected by specifying a table or a view as the selection method. Use a view as the selection method if the data about the possible values that is relevant for the input help is distributed across several tables. If all of this data is contained in one table or in the corresponding text table, you can use the table as the selection method. The system automatically ensures that the text of the text table in the user’s logon language is used. If a view that combines the data that is relevant for an input help is not available, you must create it in the ABAP Dictionary. Maintenance views may not be used as the selection method for search helps. Normally, a database view is used. However, you should note that database views (in the SAP system) are always created with an inner join. As a result, only those values that have an entry in each of © Copyright. All rights reserved. 255 Unit 9: Search Helps the tables involved are offered in the input help. Sometimes the values should be determined with an outer join. In this case you should choose a help view as the selection method. If the selection method of a search help is client-dependent, the possible values are only selected in the logon client of the user. The search help must not contain any parameters for the clients. Description of the Dialog Behavior Figure 94: Description of the Dialog Behavior The possible values are presented in a list within a dialog box so that the user can select the required entry. This is called the hit list dialog box. If the possible values are formal keys, further information should also be displayed. If the hit list is very large, the user can define further restrictions for the attributes of the entry. Restricting the set of data in this way both increases the clarity of the list and reduces the load on the system. Additional conditions can be entered in a further dialog box. It is called the dialog box for value restriction. The dialog type of a search help defines whether the dialog box for value restriction is displayed before the hit list is built. You must define the characteristics that appear on either (or both) of the dialog boxes as parameters in the search help. You can use all the fields of the selection method (with the exception of the client field) and the non-key fields of your text table as parameters. You define which parameters appear in which dialog box (in what order) by specifying the parameters’ positions in the two dialog boxes. You can thus use different parameters (or different orders) in the two dialog boxes. The types of search help parameters have to be defined with data elements. These define the display in the two dialog boxes. If nothing else is defined, a parameter uses the data element of the corresponding field of the selection method. 256 © Copyright. All rights reserved. Lesson: Creating Search Helps Interface of a Search Help Figure 95: Interface of a Search Help When you define a parameter of a search help, you must also define whether it is used to copy data to the input help (IMPORT parameter) or return data from the input help (EXPORT parameter). The IMPORT and EXPORT parameters of a search help together make up the interface of the search help. The parameters of a search help can be compared with the parameters of a function module. You can also define interface parameters that do not appear in either the hit list dialog or the dialog box for value restricting. This is useful, for example, when screen fields that do not appear on either of the two dialog boxes are to be updated when you select a value. The location from which the IMPORT parameters of a search help get their values and the screen fields in which the contents of the EXPORT parameters of the search help are returned are defined in the search help attachment. The search field is a special case. Its contents are only used in the input help if it is a search string (that is, if it contains a * or a +) and the parameter linked with the search field is an IMPORT parameter. Parameters that only contain additional information about the search field should not be defined as IMPORT parameters as the user must otherwise empty the corresponding screen fields every time a new value can be defined with the input help. Search Functionality Enhancements You can enhance the functionality of a search help object to display possible search results and further values beneath the search field while you type. This assists the user who is © Copyright. All rights reserved. 257 Unit 9: Search Helps searching for the desired entry. In addition, you can define an error-tolerant value for fuzzy searches to specify the deviation of the relevant results. Note: In transaction SDSH_CONFIG, you can deactivate the enhanced options systemwide by deselecting the Use proposal search for input fieldcheckbox. This requires the standard authorization 02 (Change) of the authorization object S_DEVELOP. A magnifying glass icon indicates input fields that are assigned a search help with enabled enhanced options. In transaction SE11, you can select the enhanced options for each elementary search help. Depending on the enhanced options selected and the capabilities of the database, the following search methods are provided: ● Type-ahead search Input fields using this search help are enabled for the proposal search (that is, a magnifying glass will be shown). The user’s search term is automatically completed or possible proposals of the search result are displayed in a drop-down box. You can select matching database entries while typing without calling the traditional input help dialog. This feature uses the standard pattern-based logic of the search help infrastructure and is therefore available on all databases. ● Full text search If the Multi-column Full Text Searchcheckbox is selected and the relevant database system supports it, a full text search is also performed on the selection methods. In contrast to the pattern-based logic, the system searches for the search string in all columns that are marked as searchable. The full text search can be executed in an errortolerant way. For more details, see the table Enhanced Options. To provide an enhanced search help, consider the following prerequisites: ● SAP GUI version 7.30 for Windows Patch Level 5, recommended Patch Level 6. ● SAP NetWeaver 7.4 SP06. ● Fuzzy search is currently supported for SAP HANA databases on ABAP systems only. Restrictions for Enhanced Search Help Options Type-ahead and full text searches are currently supported for SAP GUI screens on Windows only. Other UI technologies, such as Web Dynpro, are currently not supported. For more information, see SAP Note 1861491. 258 © Copyright. All rights reserved. Lesson: Creating Search Helps Table 6: Enhanced Options Option Relevant Search Description Method Proposal Search for Input Fields Type-ahead This option defines that a search help object is capable of running a type-ahead call. The search results are displayed in a list generated on the basis of the modeled LPos parameters. The values of the parameter that belongs to the input field are always displayed in the first column of the drop-down box, irrespective of the LPos value. All other parameters follow in accordance with their LPos value. If only this field is set, or if the Multi-column Full Text Search option is not supported by the database used by the system, the search is executed solely on the column of the database that belongs to the field or the assigned search help parameter. Additional selection conditions for other columns of the table(s) or view are considered as follows: ● If these selection conditions are modeled as additional IMPORT parameters in the search help. ● If values are stored in the user interface or as default values in the search help and if they can be matched to the IMPORT parameters. The drop-down box of an entry or search field displays 10 search results by default. Test this search help object for its runtime behavior before you activate this option for search help objects that contain exits with complex selection conditions or that implement long-running operations. Moreover, ensure that an existing search help exit does not call SAP GUI-specific logic (such as call own dialogs) on its own. Multi-column Full Text Search (Database-Specific) Full text search The system performs a full text multi-column search in addition to the standard pattern-based search. The results of both searches are combined and returned in their order of relevance with respect to the search query. You can select this option only if the Proposal Search for Input Fields option is selected and the selection methods support full text search. This applies to tables and text tables as well as standard and projection views. Other variants are not supported. The corresponding columns must be marked as IMPORT or SPos parameters. © Copyright. All rights reserved. 259 Unit 9: Search Helps Option Relevant Search Description Method Accuracy Value Fuzzy search for Error-tolerant Full Text Search The error-tolerant value determines the variation bandwidth of the displayed search results. Therefore, spelling mistakes can also be considered. This value ranges between 0 and 1. A score of 0 means the search query and the search result have nothing in common, while 1 means a complete match. Therefore more variations display when the value is lower. The error-tolerant value can only be applied to the multi-column full text search. Usage of Search Helps Figure 96: Usage of Search Helps A search help describes the flow of an input help. The search help can only take effect using a mechanism that attaches the search help to this field. This mechanism is called the search help attachment for the field. Attaching a search help to a field has an effect on the field’s behavior. It is therefore considered to be part of the field definition. The semantic and technical attributes of a screen field (type, length, field help, and so on) are not defined directly when the input template is defined. On the contrary, only a reference to an ABAP Dictionary field (usually with the same name) is specified in the Screen Painter. The screen field takes on the attributes of this field from the ABAP Dictionary. The same principle is also used to define the input help of a screen field. The search help is thus attached to the ABAP Dictionary field and not to the screen field. 260 © Copyright. All rights reserved. Lesson: Creating Search Helps In the search help attachment, the interface parameters of the search help and the screen fields providing data for the input help or getting data from the input help are assigned to one another. The search field must be assigned to an EXPORT parameter of the search help at this time. This parameter should also be an IMPORT parameter so that the user can take advantage of search patterns that have already been entered. Fields that do not have a search help attachment can also have an input help since further mechanisms (for example, fixed values for domains) are also used for the input help. Search Help Attachment in the ABAP Dictionary Figure 97: Search Help Attachment in the ABAP Dictionary A search help can be attached to ABAP Dictionary objects in one of the following ways: ● A search help can be attached directly to a field in a structure or table. The definition of this assignment is similar to that of a foreign key. You have to define an assignment (between the interface parameters of the search help and the fields of the structure) for which the system makes a proposal. ● If a field has a check table, its contents are automatically offered as possible values in the input help. The key fields of the check table are displayed. If a check table has a text table, its first character-like, non-key field is displayed. If you are not satisfied with the described standard display of the data of the check table, you can assign a search help to the check table. This search help is used for all the fields that have this table as a check table. You have to define an assignment between the interface of the search help and the key of the check table. ● The semantics of a field and its possible values are defined by its data element. You can, therefore, assign a search help to a data element. The search help is then available for all the fields that refer to this data element. In the assignment, you must define an EXPORT parameter of the search help for the data transfer. © Copyright. All rights reserved. 261 Unit 9: Search Helps Attaching a search help to a check table (or a data element) can result in a high degree of reusability. However, there are restrictions on passing further values through the interface of the search help. Overview – Mechanisms for the Input Help Figure 98: Overview – Mechanisms for the Input Help To offer a meaningful input help for as many screen fields as possible, the SAP system uses a number of mechanisms. If there is more than one such mechanism available for a field, the one that is furthest left or at the top of the above hierarchy is used. In addition to the options described for defining the input help of a field in the ABAP Dictionary, you can also define it in the screen field. The disadvantage, however, is that there is no automatic reuse. By using the POV screen event (PROCESS ON VALUE-REQUEST), you can program the input help of a field yourself. You can adjust the design of the help to the standard help using the function modules F4IF_FIELD_VALUE_REQUEST or F4IF_INT_TABLE_VALUE_REQUEST. However, you should check to see if the part of the input help that you programmed yourself should be implemented as a search help exit instead. You can also attach a search help to a screen field in the Screen Painter. There are some functional restrictions on this kind of attachment as compared to attachments in the Dictionary. You should no longer use the input checks defined directly in the flow logic of the screen, from which also input helps are derived. In the context menu of the hit list, the Technical info function is offered. It can be used to find out which of the specified mechanisms is being used. 262 © Copyright. All rights reserved. Lesson: Creating Search Helps Performance of the Input Help Figure 99: Performance of the Input Help A large amount of data sometimes has to be searched in the selections for an input help. This means that the user might have to wait a long time for the possible entries to be displayed, and can also result in a significant increase in the load on the system. When defining a search help, you must check whether you can take measures to optimize the access behavior for the selection method. This is especially true if the selection uses a view and, therefore, more than one database table. If the possible number of hit list entries is very large, you can restrict the hit list with conditions. Restricting the hit list with conditions also increases the readability of the hit list. The additional conditions can directly result from the context, or can be entered in the dialog box for value restriction by the user. The performance of the input help can frequently be significantly improved by creating an index on the fields used to formulate the restrictions. If the number of entries in the selection method is relatively small, you must always check whether the selection method can be buffered. © Copyright. All rights reserved. 263 Unit 9: Search Helps View as Selection Method of a Search Help Figure 100: View as Selection Method of a Search Help If the selection method for a search help is a database view, the input help displays only the records for which there are entries in all the tables involved in the view (inner join). The set of possible entries is sometimes described by the entries in a primary table for which additional optional information is added from further secondary tables. This view of the data can be implemented with a help view in the SAP system. The same outer join logic is used for help views as for maintenance views. A help view is defined in the same way as a maintenance view. Help views can only be used as selection methods in search helps. Since the SAP system cannot pass the selection on a help view directly to the database, it has to generate its own access routines. The database view should therefore be used as selection method in preference to the help view. Selection using a table and text table corresponds to selection using a virtual help view. Therefore, an extra virtual help view should not be created in this case. There is an exception to this rule, where the table contains a field with the same name as a non-key field in the text table. If this field in the text table is required in the search help, you have to create a help view for the two tables because the field in the search help cannot be accessed directly. It is customary to start the name of help views with the prefix H_. Views beginning with the prefixes H_Y or H_Z, therefore, are in the customer namespace. 264 © Copyright. All rights reserved. Lesson: Creating Search Helps Alternative Displays of the Input Help Figure 101: Alternative Displays of the Input Help The SAP system provides the following presentation forms for the input help: ● List box ● Control (amodal) ● Dialog (modal) The list box does not provide for any further selection conditions and no further columns are displayed in the hit list. However, the list box is the most user-friendly input help for clear, one-column lists. The application developer decides whether to offer a field as a list box and stores this information in the Screen Painter for the corresponding field. When the user calls the list box, the data to be displayed is obtained with the input help mechanism stored in the ABAP Dictionary or Screen Painter for the field. Note: You can obtain more information on using the list box in the course BC410 Programming User Dialogs. Alternatively, you can display fields that are not offered as a list box with a modeless control or with a modal dialog implemented with SAP screen technology. By choosing Help → Settings, each user can define the variant they prefer. This presentation form is then used for all input helps for this user. The system administrator can define the default value. The control is particularly useful if more than one field is to be filled sequentially with the same input help (for example, in a table control). The Hold list function starts the control from the modal help. © Copyright. All rights reserved. 265 Unit 9: Search Helps 266 © Copyright. All rights reserved. Unit 9 Exercise 18 Create Search Helps Business Example Many management tasks require that you search for employee data. The appropriate search options for these tasks need to be provided. You need to create a simple search help for an input field. 1. Open the ZDEPMENT## table in Display mode. Choose Utilities → Table Contents → Create Entries. An input template appears, in which you can create new entries for the table ZDEPMENT## (for example, new departments). The head of the new department should also be defined here. Make this entry in the DEPHEAD field. Maintenance of this field should be supported with an input help that displays the (personnel number of the) employee. Verify that the field already has an input help. Find out which input help mechanism is used here. The objective is to make the input help for check table ZEMPLOY## more user-friendly. You will check this later by calling the input help again. To do so, create an elementary search help ZEMPLOY##_ESH1. The following attributes should appear in the specified order in the hit list: ● Airline ● First name ● Last name ● Personnel number Because of the large number of employees, you should offer the user the possibility to restrict the values displayed by specifying the first and/or last names of the required person before displaying the hit list. Bear in mind that the last name is used more frequently as a restriction than the first name. If the user has specified an airline before calling the input help, the input help should take the airline into consideration. The hit list of the input help should show the airlines employees only. Otherwise, the airline screen field should be filled automatically when the user selects the employee in the input help. Test your search help. 2. Attach the search help ZEMPLOY##_ESH1 to the table ZEMPLOY## to enable a search on the DEPHEAD field. Return to the input template in which you can create new entries for table ZDEPMENT##. Open the input help for the Department head field and check whether your efforts have been successful. © Copyright. All rights reserved. 267 Unit 9 Solution 18 Create Search Helps Business Example Many management tasks require that you search for employee data. The appropriate search options for these tasks need to be provided. You need to create a simple search help for an input field. 1. Open the ZDEPMENT## table in Display mode. Choose Utilities → Table Contents → Create Entries. An input template appears, in which you can create new entries for the table ZDEPMENT## (for example, new departments). The head of the new department should also be defined here. Make this entry in the DEPHEAD field. Maintenance of this field should be supported with an input help that displays the (personnel number of the) employee. Verify that the field already has an input help. Find out which input help mechanism is used here. The objective is to make the input help for check table ZEMPLOY## more user-friendly. You will check this later by calling the input help again. To do so, create an elementary search help ZEMPLOY##_ESH1. The following attributes should appear in the specified order in the hit list: ● Airline ● First name ● Last name ● Personnel number Because of the large number of employees, you should offer the user the possibility to restrict the values displayed by specifying the first and/or last names of the required person before displaying the hit list. Bear in mind that the last name is used more frequently as a restriction than the first name. If the user has specified an airline before calling the input help, the input help should take the airline into consideration. The hit list of the input help should show the airlines employees only. Otherwise, the airline screen field should be filled automatically when the user selects the employee in the input help. Test your search help. a) On the ABAP Dictionary: Initial Screen, choose Search help and enter ZEMPLOY##_ESH1 in the corresponding field. b) Choose Create. In the dialog box, confirm that you want to create an elementary search help. c) Enter a short text for your search help. 268 © Copyright. All rights reserved. Lesson: Creating Search Helps d) The search help should support the search for employees. These are managed in table ZEMPLOY##. You must select this table (or a view for this table) as the selection method. The table is sufficient for this exercise. Enter it in the Selection methodfield. e) To obtain the required behavior, choose the dialog type Dialog with value restriction. f) Choose the search help parameters using the input help. You should retain the hit list with the possible search help parameters by selecting Keep, since you do not have to call the help again in this case. Select the Airline, First name Last name, and Personnel number fields as the parameters. g) Mark all parameters as EXPORT parameters (column EXP). Mark the attribute to be searched for (for example, Personnel number) and the hierarchically higher airline as IMPORT parameters (column IMP). This ensures that a corresponding entry in the input template is taken into consideration (as described in the exercise). h) Define the hit list by specifying the corresponding position numbers (for example 1, 2, 3, 4, 5) in the column LPos. i) Define the dialog box for restricting values by specifying position numbers in the column SPos. You should enter positive numbers in these columns for parameters First name and Last name, where the value of Last name should be less than that of First name. j) Activate your search help. The search help is not yet effective for the field ZDEPMENT##-DEPHEAD. However, you can try out the search help immediately with the Test function button. 2. Attach the search help ZEMPLOY##_ESH1 to the table ZEMPLOY## to enable a search on the DEPHEAD field. Return to the input template in which you can create new entries for table ZDEPMENT##. Open the input help for the Department head field and check whether your efforts have been successful. a) Go to Change mode in the maintenance screen for the table. Choose Extras → Search help for table. In the dialog box, enter the name of search help ZEMPLOY##_ESH1. Choose Continue . b) The proposal created by the system for assigning the search help parameters to the key fields of the table is probably correct. Check this and copy the definition. c) Activate the table ZEMPLOY##. d) Choose Utilities → Table Contents → Create Entries for the table ZDEPMENT## again. The input help for the field DEPHEAD should now function correctly. © Copyright. All rights reserved. 269 Unit 9: Search Helps LESSON SUMMARY You should now be able to: 270 ● Describe the input help process ● Create elementary search helps © Copyright. All rights reserved. Unit 9 Lesson 2 Applying Advanced Search Help Techniques LESSON OVERVIEW This lesson explains how to apply advanced search help techniques. Business Example You need to enhance a collective search help using an append search help without modifications. You also need to implement search help exits. For this reason, you require an understanding of the following: ● Collective search helps ● Append search helps ● Search help exits LESSON OBJECTIVES After completing this lesson, you will be able to: ● Create collective search helps ● Create append search helps to enhance search helps ● Implement search help exits Collective Search Helps Figure 102: Alternative Search Paths In the relational data model, entities are usually represented by formal keys. In real life, however, these entities are often identified by one or more of their attributes. For example, © Copyright. All rights reserved. 271 Unit 9: Search Helps the key for a person is the personnel number. A person will generally describe another person by his or her name and possibly address. The attributes used to identify an entity can differ from one user to the next and from situation to situation. A user wants to use these attributes in an input help to define a value for a field that requires that a formal key be entered. For this reason, you need search paths that permit access to the data using non-key fields. Several different search paths should be possible for one field. A search path for a field can be implemented using a search help. To describe an input help with more than one alternative search path, a set of search helps can be combined into a collective search help in the SAP system. Collective and Elementary Search Helps Figure 103: Collective Search Helps and Elementary Search Helps In contrast to elementary search helps, the search helps that combine several search paths are called collective search helps. Collective search helps are sometimes used to map the distribution of the possible entries for a field among several (disjunct) datasets. Like an elementary search help, a collective search help has an interface of IMPORT and EXPORT parameters with which it exchanges data. Using this interface, the collective search help can be attached to fields, tables, and data elements exactly like an elementary search help. Only one search help can be attached to a field, table, or data element. The assignment of several search paths is therefore done by assigning a collective search help. In a collective search help the components for describing the dialog behavior and data selection are missing. In their stead, the included search helps are listed. For each inclusion, there is an assignment of the parameters of the collective search help to the interface parameters of the included search help. 272 © Copyright. All rights reserved. Lesson: Applying Advanced Search Help Techniques A search help can also be included in several collective search helps and, at the same time, be attached to fields, tables, and data elements. A collective search help can also be included in another collective search help. When you use a collective search help, you are offered the elementary search helps contained in the collective search help as parallel tab pages. If you repeatedly use a collective search help, the tab page that was last used is automatically active. This is because most users always use the same search path. Note: To enable an input field with a collective search help for type-ahead, you must enable the Proposal Search for Input Fieldsoption for at least one of the assigned elementary search help objects. If you call a collective search help with more than two elementary search helps that are type-ahead-enabled, the system considers the configuration of the first elementary search help for its behavior. You can change the order of sequence either statically (in transaction SE11) or dynamically (in a search help exit). © Copyright. All rights reserved. 273 Unit 9: Search Helps 274 © Copyright. All rights reserved. Unit 9 Exercise 19 Create Collective Search Helps Business Example You need to create a collective search help to facilitate access to the employee data from the database systems. 1. Create a collective search help with several search paths. First make the following preparations: ● Copy the search help SAREA to your new search help ZEMPLOY##_AREA. ● Change the parameters, selection method table, and data elements in your copy so that it references the names used in your table instead of the original table. ● Check and activate the search help. ● Copy the search help SDEPT to your new search help ZEMPLOY##_DEPT. Change it accordingly and activate it (as above). Copy the search help ZEMPLOY##_DEPT to ZEMPLOY##_CSH and convert the new copy to a collective search help. Include the search helps ZEMPLOY##_ESH1, ZEMPLOY##_AREA, and ZEMPLOY##_DEPT as components of the new collective search help. Replace the elementary search help for check table ZEMPLOY## with your new collective search help and check whether your efforts have been successful © Copyright. All rights reserved. 275 Unit 9 Solution 19 Create Collective Search Helps Business Example You need to create a collective search help to facilitate access to the employee data from the database systems. 1. Create a collective search help with several search paths. First make the following preparations: ● Copy the search help SAREA to your new search help ZEMPLOY##_AREA. ● Change the parameters, selection method table, and data elements in your copy so that it references the names used in your table instead of the original table. ● Check and activate the search help. ● Copy the search help SDEPT to your new search help ZEMPLOY##_DEPT. Change it accordingly and activate it (as above). Copy the search help ZEMPLOY##_DEPT to ZEMPLOY##_CSH and convert the new copy to a collective search help. Include the search helps ZEMPLOY##_ESH1, ZEMPLOY##_AREA, and ZEMPLOY##_DEPT as components of the new collective search help. Replace the elementary search help for check table ZEMPLOY## with your new collective search help and check whether your efforts have been successful a) On the ABAP Dictionary: Initial Screen, enter SAREA in the search help Name field and choose Copy. Change the search help name to ZEMPLOY##_AREA and choose Continue. Choose the Change for the new search help. b) Change the selection method table to ZEMPLOY##. Change parameter names to match the fields of the table by selecting the parameter with the input help. This also corrects the data element reference. Correct other specifications as needed, perform a syntax check on the definition, and activate the search help. c) Repeat steps a) and b) to create the search help ZEMPLOY##_DEPT using the SDEPT template. d) Copy the search help ZEMPLOY##_DEPT to ZEMPLOY##_CSH. On the Maintain Search Help screen, choose Edit → Change Search Help Type. e) Change the Search Help Type and confirm the change. f) Insert an import parameter for the Area. This must refer to the data element that you used for the ZEMPLOY##-AREA. g) Select the Included Search Helpstab. Enter the search help as ZEMPLOY##_ESH1. 276 © Copyright. All rights reserved. Lesson: Applying Advanced Search Help Techniques h) Position the cursor on the search help just entered. Choose Parameter assignment. The system generates a proposal for the assignment. i) Check and then copy the proposal. j) Include the search helps ZEMPLOY##_AREA and ZEMPLOY##_DEPT. k) Activate the search help ZEMPLOY##_CSH. l) Open the table ZEMPLOY## in maintenance mode to change the search help for the table. In the menu, choose Extras → Search help for tableand change the search help name to ZEMPLOY##_CSH. The system generates a proposal. Check and copy the proposal. Activate the table ZEMPLOY##. m) Open the table ZDEPMENT## in Display mode. In the menu, choose Utilities → Table Contents → Create Entries. Go to the Department Head field and test the search help. You can see that the input help is still functioning and that a collective search help is now available. © Copyright. All rights reserved. 277 Unit 9: Search Helps Append Search Helps Figure 104: Append Search Helps The set of search paths that are meaningful for an object largely depends on the particular circumstances of the SAP customer. Customers would often like to enhance the standard SAP collective search helps with their own elementary search helps. Release 4.6 provides an append technique that enables collective search helps to be enhanced without modifications. An append search help is a collective search help that is assigned to another collective search help (its appending object) and that enhances it with the search helps it includes. The append search help uses the interface of its appending objects. The append search help is in the customer namespace. Normally, the search helps included in the append search help are also created by the customer and are in the customer namespace. However, the required elementary search help might already be provided by SAP, in which case, customers only have to add it to their own append search helps. Append search helps are used by SAP to improve component separation. Some SAP collective search helps therefore already have one or more append search helps in the standard search help. Customer enhancements should always be made by creating a separate append search help. SAP collective search helps often contain elementary search helps that are not required by all customers. The search helps you do not need can be hidden using an append search help. For this purpose, the corresponding search help must be included in the append search help and the hidden flag must be set. 278 © Copyright. All rights reserved. Unit 9 Exercise 20 Create Append Search Helps Business Example Your business requirements have changed and impact the process of searching for employees. The search path with which employees can be found by their department is not currently required. You need to enhance search helps using append search helps. Since you want to make the changes without modifying existing objects, you have to create an append search help for collective search help ZEMPLOY##_CSH. The append should include search help ZEMPLOY##_DEPT as a hidden search help. 1. Change the input help used for field ZDEPMENT##-DEPARTMENT_HEADaccordingly without actually modifying search help ZEMPLOY##_CSH (or a table that is involved). Do this by creating an append search help for ZEMPLOY##_CSH. The append should include search help ZEMPLOY##_DEPT as a hidden search help. Check whether your efforts have been successful. © Copyright. All rights reserved. 279 Unit 9 Solution 20 Create Append Search Helps Business Example Your business requirements have changed and impact the process of searching for employees. The search path with which employees can be found by their department is not currently required. You need to enhance search helps using append search helps. Since you want to make the changes without modifying existing objects, you have to create an append search help for collective search help ZEMPLOY##_CSH. The append should include search help ZEMPLOY##_DEPT as a hidden search help. 1. Change the input help used for field ZDEPMENT##-DEPARTMENT_HEADaccordingly without actually modifying search help ZEMPLOY##_CSH (or a table that is involved). Do this by creating an append search help for ZEMPLOY##_CSH. The append should include search help ZEMPLOY##_DEPT as a hidden search help. Check whether your efforts have been successful. a) Open search help ZEMPLOY##_CSH in display mode. Choose Goto → Append search helps. b) A name for the append search help is proposed in the next dialog box. You can copy this name. c) Enter a short description for the append search help. d) Select the Included Search Helpstab. e) Enter ZEMPLOY##_DEPT in the list of included search helps. Select the checkbox under the Hidden column for the entry. f) Position the cursor on the name of search help ZEMPLOY##_DEPT. Choose Parameter assignment. In the next dialog box, confirm that you want to create a proposal for the parameter assignment. g) The parameter assignment proposed by the system is probably correct. Check this and copy the assignment. h) Activate your append search help. i) You can check whether your efforts have been successful by calling the input help for field ZDEPMENT##-DEPHEAD. 280 © Copyright. All rights reserved. Lesson: Applying Advanced Search Help Techniques Search Help Exits Figure 105: Deviation from Standard – Search Help Exit A search help is an object that describes an input help within the system-wide standard. In some cases, the special semantics of a field require that you deviate from this standard with regard to certain details. This can be implemented with a search help exit. A search help exit is a function module with a standardized interface. The function module F4IF_SHLP_EXIT_EXAMPLE can be used as a template. If a search help has such a search help exit, the search help exit is called prior to each single step of the process. The administrative data of the help processor is passed through the interface. The search help exit can manipulate this data. The administration data also includes the information about the next step to be executed. The search help exit can now execute either preparatory actions for this step or the step itself (for example a data selection that cannot be implemented with a SELECT on a table or view). In the second case, the search help exit also changes the information about the next step to be executed. Some function modules that can be used as search help exits or to manipulate the administration data in search help exits are already defined with the prefix F4UT_. Search help exits should only be used for exceptions. Using search help exits encourages non-standard solutions and makes it more difficult to maintain the input help. © Copyright. All rights reserved. 281 Unit 9: Search Helps Hint: Search help exit F4UT_OPTIMIZE_COLWIDTH adjusts the column width in the hit list to the contents of the column. Use this search help exit when the columns of the hit list have to be made wide for extreme cases (for example, name fields), but they contain much smaller values. Further Options for Search Helps Figure 106: Further Options for Search Helps A parameter can be preassigned a value by allocating a default value. The parameter is always given this value unless it is an IMPORT parameter that is linked to a field on the screen, its module pool, or to a parameter of the including collective search help. The possible default values for search help parameters are as follows: ● Literals ● System fields ● GET parameters You can use a default value to formulate a simple selection condition for a field of the selection method. You can assign a single letter or a digit as a hot key to an elementary search help. If this elementary search help is used in a screen field for the input help, and if this field has the short cut =<hot key>.<SEL1>.<SEL2>, this elementary search help is processed when the input help is called. <SEL1>, <SEL2> is used as the field contents for the dialog box for restricting values (with an * added at the end) and the hit list is then displayed immediately. 282 © Copyright. All rights reserved. Lesson: Applying Advanced Search Help Techniques Individual search help inclusions can be hidden in a collective search help. You can thus deactivate individual search paths that are not wanted in a system. They should normally be hidden in an append search help, as this can be done without modification. Parameters of an elementary search help can be marked as pure display fields in the dialog box for restricting values. In general, IMPORT parameters that are assigned read-only fields on the screen are displayed as changeable in the dialog box. © Copyright. All rights reserved. 283 Unit 9: Search Helps LESSON SUMMARY You should now be able to: 284 ● Create collective search helps ● Create append search helps to enhance search helps ● Implement search help exits © Copyright. All rights reserved. Unit 9 Learning Assessment 1. What are the different ways of obtaining input help for a field? Choose the correct answers. X A A search help can be attached directly to a field of a structure or table X B If a field has a check table, its contents are automatically offered as possible values in the input help X C The values in the database will be automatically output directly X D The possible values are defined by its data element 2. In every search help at least one an __________ parameter must be defined for the data transfer. Choose the correct answer. X A EXPORT X B IMPORT 3. The search helps that combine several search paths are called _____________ . Choose the correct answer. X A collective search helps X B hidden search helps X C elementary search helps 4. SAP collective search helps often contain elementary search helps that are not required by all customers. The search helps you do not need can be hidden using _____________ . Choose the correct answer. X A Hidden search helps X B Append search helps X C Collective search helps © Copyright. All rights reserved. 285 Unit 9: Learning Assessment 5. Existing function modules with the prefix F4UT_ can be used to implement search help exits. Determine whether this statement is true or false. 286 X True X False © Copyright. All rights reserved. Unit 9 Learning Assessment - Answers 1. What are the different ways of obtaining input help for a field? Choose the correct answers. X A A search help can be attached directly to a field of a structure or table X B If a field has a check table, its contents are automatically offered as possible values in the input help X C The values in the database will be automatically output directly X D The possible values are defined by its data element 2. In every search help at least one an __________ parameter must be defined for the data transfer. Choose the correct answer. X A EXPORT X B IMPORT 3. The search helps that combine several search paths are called _____________ . Choose the correct answer. X A collective search helps X B hidden search helps X C elementary search helps 4. SAP collective search helps often contain elementary search helps that are not required by all customers. The search helps you do not need can be hidden using _____________ . Choose the correct answer. X A Hidden search helps X B Append search helps X C Collective search helps © Copyright. All rights reserved. 287 Unit 9: Learning Assessment - Answers 5. Existing function modules with the prefix F4UT_ can be used to implement search help exits. Determine whether this statement is true or false. 288 X True X False © Copyright. All rights reserved.