TAW12 ABAP Workbench Concepts part II
.
.
PARTICIPANT HANDBOOK INSTRUCTOR-LED TRAINING . Course Version: 15 Course Duration: 5 Day(s) Material Number: 50129723
SAP Copyrights and Trademarks
© 2015 SAP SE. 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. The information contained herein may be changed without prior notice. Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors. ●
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.
●
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.
●
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.
●
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries.
●
Oracle is a registered trademark of Oracle Corporation
●
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
●
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc.
●
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology.
●
●
Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape.
●
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP BusinessObjects Explorer, StreamWork, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE in Germany and other countries.
●
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects Software Ltd. Business Objects is an SAP company.
●
Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere, and other Sybase products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Sybase, Inc. Sybase is an SAP company.
All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP SE and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group 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.
© Copyright. All rights reserved.
iii
iv
© Copyright. All rights reserved.
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.
v
VLC About This Handbook
About This Handbook This handbook provides you with basic information for attending your virtual live classroom session. Adobe Connect Support Information Web and audio support is available by: ●
Pressing *0 from within the audio-conferencing
●
Calling the support hotline numbers listed below
●
Emailing the PGi support hotline below
Global PGi Support Hotline for SAP Education (24/7) Tel: +1 800-368-1945 Tel: +1 719-234-7915 Note: After dialing in, press option 2 for technical support. You will then be presented with two options – press 1 for Audio support, or press 2 for Web support. Email:
[email protected] Setting up your Learning Environment Ideally you want to be in a private room when participating in a synchronous (live) event. In reality, you may not be able to arrange that. Here are some tips for maximizing your learning environment: ●
Create an inspirational office/studio to work in
●
Use a comfortable chair
●
Use well designed and functional computer peripherals
●
Keep a log or journal of notes and ideas you can use for future sessions
Before your online class: ● Tell co-workers you will be in class (send e-mail) ●
Post a sign indicating when you will be free again (when class is over)
●
Use a headset instead of your computer speakers to minimize disruption of others
●
Ignore people who try to get your attention
●
Turn off the ringers / alerts on telephone, pager, and cell phone
●
Turn off e-mail and instant message alerts
●
Remove other distractions lying on your desktop
●
Keep a glass of water at your desk
Teleconferencing ground rules: Use the mute button or press *6
●
●
vi
Do not place call on hold
© Copyright. All rights reserved.
●
Use the "Raise hand" icon in the Attendee List: My Status to indicate you want to ask a question
●
Identify yourself before speaking, when not called on
●
Charge the batteries for your cordless handset
●
If possible use a land line instead of your cell phone
Minimum Hardware Requirements ●
●
●
PC with 1.4 GHz processor or higher (Windows) or 1.83 GHz process or higher (Mac OS). Minimum processor required for screen sharing. You may be asked to share your screen during hands-on exercise portions of the class. 17 inch or larger monitor is recommended, set at 1024 X 768. Larger monitor and 1024 X 768 setting will make presentation and system screens easier to read. Phone with Headset/Microphone or Speakerphone feature – to maximize student listening and comfort during presentation and demonstration portions of the course.
Software Requirement A complete list of supported Operating Systems, browsers and additional requirements for Adobe® Acrobat® Connect™ can be found at: www.adobe.com/products/acrobatconnectpro/systemreqs Sample Email to Notify Others You Are in a Virtual Class This is a sample of an email you can send to your colleagues and manager when you are taking an online course. Dear colleagues, Today I will be participating in an online class from my desk. I will be online from approximately 9:30 a.m. to 5:30 a.m. EST. I would appreciate it if you would not disturb me during this time. If you have an immediate question, please contact Joe Smith at extension 123. If it can wait until after 11:00 a.m., please send me an email and I will follow up with you before the end of the business day. I appreciate your consideration. Best regards, Getting the Most Out of Your Session Session Guidelines ●
Turn off email, phones, instant messaging tools, and clear other distractions away from your training area.
●
Participate and prepare to be called on by name.
●
Use the “Raise Hand” icon if you have an immediate question or comment.
●
Be patient waiting for a response to your chat messages.
●
If you leave the program, please use the “Step Away” status icon in the Attendee List pod to let your instructor know when you leave and remember to clear it when you return.
© Copyright. All rights reserved.
vii
viii
© Copyright. All rights reserved.
Contents xiii
Course Overview
1
Unit 1:
2 7 19
Lesson: Adjusting SAP Standard Software Lesson: Describing Classic Enhancement Types Unit 2:
20
Unit 3:
38 46 57 62 65 70 77 87
Unit 4:
158 163 171
Classic Business Add-Ins Lesson: Describing an ABAP Objects Interface Lesson: Describing Classic Business Add-Ins (BAdIs) Lesson: Explaining Additional Details of Business Add-Ins (BAdIs)
Unit 5:
106 109 115 119 123 127 131 137 143 157
Customer Exits Lesson: Describing Enhancement Projects Lesson: Enhancing Programs Using Program Exits Exercise 2: Implement a Customer Exit – Program Exit Lesson: Enhancing Menus Using Menu Exits Exercise 3: Implement a Customer Exit – Menu Exit Lesson: Enhancing Screens Using Screen Exits Exercise 4: Implement a Customer Exit – Screen Exit
88 91 97 105
Enhancement of Dictionary Elements Lesson: Enhancing Tables Using Append Structures and Customizing Includes Exercise 1: Enhance a Table Using an Append Structure Lesson: Enhancing Texts of Data Elements
25 29 37
Adjustment of SAP Standard Software
New Business Add-Ins Lesson: Describing the Change from Classic BAdIs to New BAdIs Lesson: Using New Business Add-In (BAdI) Program Exits Exercise 5: Implement New BAdI Program Exits Lesson: Using New Business Add-In (BAdI) Menu Exits Exercise 6: Implement a New BAdI Menu Exit Lesson: Using New Business Add-In (BAdI) Screen Exits Exercise 7: Implement New BAdI Screen Exits Lesson: Using New Business Add-Ins (BAdIs) Exercise 8: Define a New BAdI
Unit 6:
Explicit Enhancement Options Lesson: Describing the Enhancement Framework Lesson: Using Explicit Enhancements Exercise 9: Use Explicit Enhancements
© Copyright. All rights reserved.
ix
179
Unit 7:
180 182 185
Lesson: Explaining Implicit Enhancements Lesson: Implementing Implicit Enhancements in Function Modules Exercise 10: Use Implicit Enhancements of an SAP Function Module
191 195 201 205 210 213
Lesson: Implementing Implicit Enhancements in Global SAP Classes Exercise 11: Enhance a Global SAP Class Lesson: Using Other Implicit Enhancements Exercise 12: Enhance SAP Structures and SAP Subroutines Lesson: Using Composite Enhancements Exercise 13: Create a Composite Enhancement Implementation
225
Unit 8:
226 235 243 250 254 261
273
Unit 9:
274 278 283 289 291 298 301 307 315
326 332 338 341
Introduction to Web Dynpro Lesson: Outlining the Benefits of Web Dynpro Lesson: Displaying Web Dynpro Component Architecture Exercise 17: Create a Simple Web Dynpro Lesson: Navigating Between Views Exercise 18: Set Up Navigation Between Views Lesson: Creating View Assemblies Exercise 19: Create View Assemblies Lesson: Identifying Web Dynpro Entities and Relationships
Unit 10:
316 325
Modifications of the SAP Standard Application Lesson: Modifying SAP Standard Software Lesson: Modifying Applications using the Modification Assistant Exercise 14: Implement Modifications Lesson: Implementing User Exits Lesson: Adjusting Modifications Exercise 15: Perform Modification Adjustment with Transaction SPDD Exercise 16: Perform Modification Adjustment with Transaction SPAU
265
x
Implicit Enhancements
Web Dynpro Controllers Lesson: Outlining Controller Types and Entities
Unit 11:
Web Dynpro Context Lesson: Creating Context Nodes Lesson: Setting Context Node Properties Lesson: Sharing Data Between Controllers with Context Mapping Exercise 20: Define, Map, and Bind Data to the Context
© Copyright. All rights reserved.
349
Unit 12:
Web Dynpro User Interface
350 365 371
Lesson: Defining the View Layout Exercise 21: Arrange UI Elements with Layout Managers Lesson: Controlling UI Element Behavior with Data Binding
379 389
Lesson: Using Composite UI Elements Exercise 22: Display Tables with the Service Wizard
403
Unit 13:
Controller and Context Programming
404 414 423
Lesson: Outlining Controller Methods and Attributes Lesson: Accessing the Context at Runtime with Controller Methods Exercise 23: Access the Context at Runtime
428 435 442 445
Lesson: Adding New Elements to a Context Node Exercise 24: Display Mass Data Using Tables Lesson: Implementing Supply Functions Exercise 25: Implement Supply Functions
© Copyright. All rights reserved.
xi
xii
© Copyright. All rights reserved.
Course Overview
TARGET AUDIENCE This course is intended for the following audiences: ●
Developer
●
Development Consultant
© Copyright. All rights reserved.
xiii
xiv
© Copyright. All rights reserved.
UNIT 1
Adjustment of SAP Standard Software
Lesson 1 Adjusting SAP Standard Software
2
Lesson 2 Describing Classic Enhancement Types
7
UNIT OBJECTIVES ●
Describe the options for adjusting the SAP standard system
●
Describe the enhancement types
© Copyright. All rights reserved.
1
Unit 1 Lesson 1 Adjusting SAP Standard Software
LESSON OVERVIEW This lesson provides an overview of the options available for modifying your SAP system, and outlines the guidelines that enable you to decide which option to use. Business Example You need to know the options available for modifying and enhancing your SAP system. For this reason, you require the following knowledge: ●
●
An understanding of the different levels at which you can make changes to the standard system delivered by SAP An understanding of the most suitable method for changing the standard system
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Describe the options for adjusting the SAP standard system
Overview of Options for Changing SAP Standard Application
Figure 1: Overview Diagram – Changing the SAP Standard
You can adapt SAP standard software by using any of the following techniques:
2
© Copyright. All rights reserved.
Lesson: Adjusting SAP Standard Software
●
Personalization
●
Modification
●
Enhancement
Change Levels
Figure 2: Change Levels
There are different approaches and techniques which can be used to adapt an ABAP-based system as follows: ●
Customizing Using Customizing, you can configure specific business processes and functions for your system based on the Implementation Guide (IMG).
●
Personalization Personalization includes techniques which do not require development, but which allow field and screen properties to be adapted and simplified, as well as the creation of userspecific menus.
●
Modification Modification involves directly changing SAP repository objects in the customer system. If SAP delivers a changed version of the modified object, modification adjustment is required . The modification procedure is supported through the use of the Modification Assistant.
●
Enhancement Enhancements allow you to adapt SAP repository objects without the need to modify them. Various enhancement techniques exist..
●
Customer Development Customer development involves the creation of new repository objects (unique to the customer) in the customer namespace.
© Copyright. All rights reserved.
3
Unit 1: Adjustment of SAP Standard Software
Customer developments, enhancements, and modifications are performed by using the tools available in the ABAP Workbench. Procedure for Deciding How to make Changes
Figure 3: Procedure for Deciding How to make Changes
If Customizing or personalization does not fulfill your requirements, you can either start a development project or use a Complementary Software Program (CSP). A list of CSPs that are certified by SAP is available in the SAP Service Marketplace under the alias / softwarepartner. Custom development may be required if the SAP standard system doesn't already provide the functionality which is needed. However, if a similar SAP function exists, try to include it in your development project by either enhancing or modifying it, by using a user exit, or by copying the appropriate SAP program. Modifications should be a last resort as they can cause problems when you upgrade or import a support package. After an upgrade, you must compare the new versions of SAP objects with the modified versions that you previously created. If necessary, you must also adjust the new versions to incorporate the adjustments you made to the previous versions. Make modifications only in the following situations:
4
●
Customizing or personalization do not fulfill your requirements.
●
A suitable enhancement option is not available.
●
Copying the SAP object to the customer namespace cannot be considered as an option.
© Copyright. All rights reserved.
Lesson: Adjusting SAP Standard Software
Customizing
Figure 4: Customizing
If a company has decided to implement an SAP System, they must adapt the software to meet their business requirements. The term Customizing refers to the process of system configuration during which the members of the project team make the required system settings. Customizing activities are performed through the Implementation Guide (IMG). Customizing provides the following functions: ●
A roadmap as a structure plan for implementing and enhancing the SAP System
●
Tools for making and documenting system settings
●
Recommendations for system settings
●
Customizing projects as a means for controlling the management, editing and analysis processes of the implementation
Personalization Examples of how Personalization is Achieved ●
●
Screen field properties can be controlled using: -
Variant transactions
-
SET/GET parameters
-
User-dependent or client-dependent table control settings
Personalized menus -
Role-based menus
© Copyright. All rights reserved.
5
Unit 1: Adjustment of SAP Standard Software
-
Favorites
-
Shortcuts on your desktop
Personalization can help accelerate and simplify the processing of business scenarios by users. With personalization, individual application transactions can be adjusted to meet the business needs of your company as a whole, or the needs of specific user groups in your company. All unnecessary information and functions found in the transaction can be deactivated. Using personalization, you can simplify an application without the need for development using the ABAP Workbench. There are several techniques which can be used to control screen field properties to define default values for specific screen fields. You can also suppress individual fields, table control columns in a particular transaction, or a whole screen. Personalized menus, such as role-based menus, favorites, and shortcuts on the desktop, allow you to adjust menus to reflect the needs of different user groups in your company. LESSON SUMMARY You should now be able to: ●
6
Describe the options for adjusting the SAP standard system
© Copyright. All rights reserved.
Unit 1 Lesson 2 Describing Classic Enhancement Types
LESSON OVERVIEW This lesson describes the available enhancement types and their uses. Business Example To work in the SAP system, you will need to learn several enhancement techniques. For this reason, you require the following knowledge: ●
An understanding of the available enhancement types and their uses
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Describe the enhancement types
Change Levels Using the ABAP Workbench
Figure 5: Change Levels Using the ABAP Workbench
If SAP standard applications do not meet your requirements, there are different approaches which can be taken to solve the problem using the ABAP Workbench: ●
Modification
●
Enhancement
© Copyright. All rights reserved.
7
Unit 1: Adjustment of SAP Standard Software
●
Customer development
Modifications are changes made to SAP objects in customer systems. They can be: ●
●
Executed with the help of user exits (these are subroutines reserved for customers within objects in the SAP namespace) 'Hard-coded' at various points within SAP Repository objects
Customer developments are programs developed by the customer that may or may not call SAP repository objects. For example, customers can create programs that call SAP function modules. With enhancements, the roles are reversed. SAP programs call repository objects that you, as a customer, have created or changed. For example, you can implement a function module exit that is called by an SAP program. Enhancements can be made to different types of repository object as follows: ●
In ABAP programs by using program exits
●
In a GUI status by using menu exits
●
On screens, by using screen exits to insert a subscreen in an area that SAP provides
●
In ABAP Dictionary tables or structures by using table enhancements
Table Enhancements
Figure 6: Table Enhancements
You can enhance SAP tables and structures by adding additional fields using the following options: ●
Append structures
●
Customizing Includes (CI)
Both techniques allow you to attach fields to a table without modifying the table.
8
© Copyright. All rights reserved.
Lesson: Describing Classic Enhancement Types
An append structure is a structure you assign to exactly one table. There can be several append structures for a table. During activation, the system searches for all active append structures for that table and attaches them to the table. Table Enhancements - Role of SAP and the Customer
Figure 7: Table Enhancements - Role of SAP and the Customer
Append structures allow you to attach fields to a table without actually modifying the table. Therefore, SAP developers do not have to plan table enhancements using append structures. An append structure can only belong to one table. In contrast, Customizing Includes allow you to use the same structure in multiple tables. The include statement must already exist in the SAP table or structure, and therefore Customizing Includes require planning by SAP developers. Append structures and Customizing Includes are not the only dictionary enhancement possibilities. Text enhancements are available to allow some properties of data elements to be enhanced, an extension index can be created for a standard SAP table and fixed value appends allow you to create additional fixed values for an SAP domain.
Program Enhancements
Figure 8: Program Enhancements – How They Work
A program enhancement (sometimes called a program exit) is a link between an SAP program and customer source code. Customers can use these program enhancements to
© Copyright. All rights reserved.
9
Unit 1: Adjustment of SAP Standard Software
implement additional or alternative functions in SAP source code without making modifications. Implementation Techniques for Program Exits
Figure 9: Implementation Techniques for Program Exits
The figure Implementation Techniques for Program Exits shows the various implementation techniques for program exits that are available in SAP NetWeaver 7.0. Classic Program Enhancements – SAP and Customer
Figure 10: Classic Program Enhancements – SAP and Customer
Program enhancements allow you to create additional program logic for an SAP application program. SAP currently provides the techniques outlined in the figure.
10
© Copyright. All rights reserved.
Lesson: Describing Classic Enhancement Types
Menu Enhancements
Figure 11: Implementation Techniques for Menu Exits
Menu enhancements permit you to add additional menu entries to an SAP standard menu. Menu enhancements are provided using the following enhancement technologies: ●
Customer exits
●
Business Add-Ins (classic and new)
The additional menu options are merged into the GUI status - they can be identified through a special function code starting with a '+'. When the menu enhancement is implemented, you can define the text for the new menu option. Menu enhancements are always provided along with a program enhancement, which you can implement to code the logic which will be executed when the new menu entry is chosen.
© Copyright. All rights reserved.
11
Unit 1: Adjustment of SAP Standard Software
Screen Enhancements
Figure 12: Screen Enhancements
A screen exit provides the option to include additional screen elements on an SAP screen without the need for a modification. You can add both SAP standard fields or Customer append fields (from an Append structure) to the screen. To provide screen exits, the SAP developer must perform the following tasks:
12
●
Define the subscreen areas.
●
Program the corresponding calls in the flow logic.
●
Provide the framework for the data transport.
●
Include the screen exit in an enhancement (either a Customer Exit or a Business Add-In).
●
Maintain the documentation.
© Copyright. All rights reserved.
Lesson: Describing Classic Enhancement Types
Origin of the Implementation Techniques
Figure 13: Origin of the Implementation Techniques
The figure shows the enhancement technologies which SAP have used over time, and the reasons for their introduction. You cannot have more than one active implementation of menu exits and screen exits. However, program exits, which are provided using the Business Transaction Event and BAdI technology sometimes allow multiple implementations. In this case, a program exit may have several active implementations that are processed in succession at runtime.
© Copyright. All rights reserved.
13
Unit 1: Adjustment of SAP Standard Software
Program Exits - Multiple Implementations
Figure 14: Program Exits - Multiple Implementations
The figure shows the runtime architecture when a program exit has multiple implementations. New Enhancement Options Offered Through the Enhancement Framework as of SAP NetWeaver 7.0 ●
Implicit enhancement points and options
●
Explicit enhancement points
●
Explicit enhancement sections
●
New BAdls
As of SAP NetWeaver 7.0, SAP revised the BAdI technology to improve performance. In the future, enhancements will be provided using the new BAdI technology. However, the system still has some BAdIs that you can implement using classic BAdI technology.
14
© Copyright. All rights reserved.
Lesson: Describing Classic Enhancement Types
Enhancement Points
Figure 15: Overview – Enhancement Points
Enhancement points are points in SAP programs, function modules, and methods in which customers can add additional logic in the form of source code without making any modifications. Implicit enhancement points are points in SAP programs where enhancements are possible, but where SAP Development have not explicitly provided them, whereas explicit enhancement points are enhancement points provided by SAP Development. Overview – Enhancement Options Enhancement options allow customers to define the following without making modifications: ●
Additional (optional) interface parameters in SAP function modules and SAP methods
●
Additional attributes and methods in SAP classes
●
Preparation and post-processing functions for global SAP methods
●
Replacements for global SAP methods
Enhancement options are implicitly available and customers can use them to enhance SAP class definitions and interfaces of SAP function modules and methods.
Hint: Implicit enhancement points and options also exist in SAP objects that were developed before SAP NetWeaver 7.0.
© Copyright. All rights reserved.
15
Unit 1: Adjustment of SAP Standard Software
Modifications
Figure 16: Modifications of SAP Standard Applications
Any direct change that you make to an object that SAP has delivered is known as a modification. After an upgrade, you must compare the new versions of SAP objects with the modified versions that you created previously. As of Release 4.5A, the Modification Assistant has been available to assist when you perform a modification. The modification adjustment process has also been overhauled. LESSON SUMMARY You should now be able to: ●
16
Describe the enhancement types
© Copyright. All rights reserved.
Unit 1 Learning Assessment
1. Which of the following techniques used to adapt SAP standard software involve the use of the ABAP Workbench? Choose the correct answers. X
A Customization
X
B Personalization
X
C Enhancements
X
D Modifications
2. Which of the following enhancement technologies offer menu exits? Choose the correct answers. X
A Customer Exits
X
B Business Transaction Events
X
C Business Add-Ins
X
D Explicit Enhancements
© Copyright. All rights reserved.
17
Unit 1 Learning Assessment - Answers
1. Which of the following techniques used to adapt SAP standard software involve the use of the ABAP Workbench? Choose the correct answers. X
A Customization
X
B Personalization
X
C Enhancements
X
D Modifications
2. Which of the following enhancement technologies offer menu exits? Choose the correct answers.
18
X
A Customer Exits
X
B Business Transaction Events
X
C Business Add-Ins
X
D Explicit Enhancements
© Copyright. All rights reserved.
UNIT 2
Enhancement of Dictionary Elements
Lesson 1 Enhancing Tables Using Append Structures and Customizing Includes Exercise 1: Enhance a Table Using an Append Structure
20 25
Lesson 2 Enhancing Texts of Data Elements
29
UNIT OBJECTIVES ●
Enhance tables by using append structures
●
Enhance tables by using Customizing Includes
●
Enhance texts of data elements
© Copyright. All rights reserved.
19
Unit 2 Lesson 1 Enhancing Tables Using Append Structures and Customizing Includes
LESSON OVERVIEW This lesson explains how to enhance tables by using append structures and Customizing Includes. Business Example You would like to add fields to SAP tables without performing a modification. For this reason, you require the following knowledge: ●
How to enhance tables by using append structures
●
How to enhance tables by using Customizing Includes
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Enhance tables by using append structures
●
Enhance tables by using Customizing Includes
Table Enhancements
Figure 17: Enhancements to the ABAP Dictionary – Overview Diagram
20
© Copyright. All rights reserved.
Lesson: Enhancing Tables Using Append Structures and Customizing Includes
You can add extra fields to an SAP table, without modifying the table, using append structures and Customizing Includes. Options for Adding Extra Fields to SAP Tables There are two ways to add extra fields to an SAP table without modification. ●
Append Structure -
●
Customers can create an append structure for an SAP table (without the need for SAP preparation).
-
Multiple append structures can be used in a single SAP table.
-
Append structures can also be used like normal structures as types in programs.
Customizing Include -
Customizing includes are already integrated into SAP tables by SAP.
-
Customers add the desired additional fields to the Customizing include.
-
Customizing includes often go hand-in-hand with program exits and screen exits for the processing of any additional fields added.
If the SAP application developer has an idea in advance that one of the tables or structures delivered by SAP needs to have customer-specific fields added to it, the developer will include a Customizing include in the table to allow these fields to be added. The same Customizing Include can occur in multiple tables and structures. This ensures consistency throughout these tables and structures, whenever the Include is used (if fields are added). No errors will occur if Customizing Includes provided by SAP are not implemented.
Append Structures
Figure 18: Append Structures
Append structures allow you to append fields to a table without actually having to modify the table itself.
© Copyright. All rights reserved.
21
Unit 2: Enhancement of Dictionary Elements
An append structure may only be assigned to a single table. A table may, however, have several append structures attached to it. Whenever a table is activated, the system searches for all active append structures for that table and attaches them to the table. If an append structure is created or changed and then activated, the table to which it is assigned is also activated. All of the changes made to the append structure take effect in the table as well. You can use the fields in append structures in ABAP programs in the same way as any other field in the table. If you copy a table that has an append structure attached to it, the fields in the append structure become normal fields in the target table. Append Structures at Upgrade
Figure 19: Append Structures at Upgrade
Creating append structures in the customer namespace protects them from being overwritten during a system upgrade. New versions of standard tables may be imported during upgrades. The fields contained in active append structures are then appended to the new standard tables when these new standard tables are activated for the first time. The field sequence in the ABAP Dictionary can differ from the field sequence in the database. Therefore, no conversion of the database table is necessary when adding an append structure or inserting fields into an existing one. All necessary structure adjustment is taken care of automatically by adjusting the database catalog (ALTER TABLE). The table definition is changed when it is activated in the ABAP Dictionary and the new field is appended to the database table. Important Considerations When Using Append Structures Pay attention to the following points when using append structures: ●
22
SAP tables and structures are sometimes classified using an Enhancement Category in order to prevent issues arising from Unicode checks in the system. The fields of a Customizing include or an append structure must respect this classification. The possible Enhancement Categories are as follows:
© Copyright. All rights reserved.
Lesson: Enhancing Tables Using Append Structures and Customizing Includes
●
●
●
Enhancement Category
Description
Not classified
The table has no enhancement category
Cannot be enhanced
The table cannot be enhanced
Can be enhanced (character-type)
All table components and their enhancements must be character-type
Can be enhanced (character-type or numeric-type)
The structure and its enhancement cannot contain deep data types
Can be enhanced in any way
The structure and its enhancement can contain components with any data type
You cannot create append structures for pool and cluster tables. If a table contains a long field (either of the LCHR or LRAW data type), you cannot expand the table using an append structure. This is because long fields of this kind must always be the last field in their respective tables. You cannot add any fields from an append structure after the long fields. If you use an append structure to expand an SAP table, the field names in your append structure must be in the customer namespace, that is, they must begin with either YY or ZZ. This prevents naming conflicts with any new fields that SAP may insert in the future.
© Copyright. All rights reserved.
23
Unit 2: Enhancement of Dictionary Elements
24
© Copyright. All rights reserved.
Unit 2 Exercise 1 Enhance a Table Using an Append Structure
Business Example You work as a computer specialist for a large travel agency. Your fellow employees use transaction BC425_## to display flight information when helping customers. They would like more information about the flight, including the pilot’s name or the main meal. The flight data is stored in the SFLIGHT## table. You need to add two columns to this table without actually modifying it. Enhance the table using an append structure. 1. In the ABAP Dictionary, display table SFLIGHT##. 2. Create an append structure ZASFLIGHT## for the SFLIGHT## table (where ## is your group number). 3. Give the append structure the short description: Additional flight details. Add the fields using the data in the following table: Component
Typing Method
Component Type
YYPILOT
Types
S_PILNAME
YYMEAL
Types
S_MEAL
4. Set the Enhancement Category of the append structure to state that additional fields should not be added. 5. Activate the append structure and verify the additional fields are now part of SFLIGHT##.
© Copyright. All rights reserved.
25
Unit 2 Solution 1 Enhance a Table Using an Append Structure
Business Example You work as a computer specialist for a large travel agency. Your fellow employees use transaction BC425_## to display flight information when helping customers. They would like more information about the flight, including the pilot’s name or the main meal. The flight data is stored in the SFLIGHT## table. You need to add two columns to this table without actually modifying it. Enhance the table using an append structure. 1. In the ABAP Dictionary, display table SFLIGHT##. a) Call the ABAP Dictionary by using transaction SE11. Alternatively, in the Object Navigator, choose Edit object → Edit Dictionary objects. b) In the Database table field, enter SFLIGHT## as the table name and choose Display. 2. Create an append structure ZASFLIGHT## for the SFLIGHT## table (where ## is your group number). a) Choose Goto → Append Structure or its corresponding push button. b) In the Create Append Structure for SFLIGHT## dialog box, in the Append Name field, enter ZASFLIGHT## . 3. Give the append structure the short description: Additional flight details. Add the fields using the data in the following table: Component
Typing Method
Component Type
YYPILOT
Types
S_PILNAME
YYMEAL
Types
S_MEAL
a) Include the fields from the table. b) Assign the append structure to your package and transport request when prompted. 4. Set the Enhancement Category of the append structure to state that additional fields should not be added. a) Choose Extras → Enhancement category. b) Choose the Cannot Be Enhanced radio button. 5. Activate the append structure and verify the additional fields are now part of SFLIGHT##. a) Activate the append structure. If an error occurs, you can find the details in the activation log.
26
© Copyright. All rights reserved.
Lesson: Enhancing Tables Using Append Structures and Customizing Includes
Customizing Includes
Figure 20: Customizing Includes
Customizing Includes are part of the customer namespace. The names of all Customizing includes begin with CI_. This naming convention ensures that the nonexistent Customizing includes do not lead to errors. The SAP standard software does not deliver any code for Customizing includes. You create Customizing Includes by using special Customizing transactions. Some are already part of SAP enhancements, and you can create them by using Project Management (transaction CMOD). The Customizing Include field names must lie in the customer namespace, just like field names in append structures. The rules for adding fields to database tables using Customizing includes are the same as the rules for append structures
© Copyright. All rights reserved.
27
Unit 2: Enhancement of Dictionary Elements
LESSON SUMMARY You should now be able to:
28
●
Enhance tables by using append structures
●
Enhance tables by using Customizing Includes
© Copyright. All rights reserved.
Unit 2 Lesson 2 Enhancing Texts of Data Elements
LESSON OVERVIEW This lesson shows how to overwrite texts delivered with SAP data elements with customerspecific texts. Business Example You would like to adapt field labels and documentation for SAP data elements with customerspecific texts. For this reason, you require the following knowledge: ●
How to change field labels and documentation for SAP data elements without carrying out a modification
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Enhance texts of data elements
Text Enhancements
Figure 21: Text Enhancements – Overview
Text enhancements comprise customer-specific field labels and customer documentation for SAP data elements. If a text enhancement has been implemented by a customer, it will apply in all SAP applications that use the particular data element. They are global enhancements.
© Copyright. All rights reserved.
29
Unit 2: Enhancement of Dictionary Elements
SAP Field Label Enhancements
Figure 22: Overwriting SAP Field Labels
SAP application programmers define field labels in different lengths and a short description for each data element. Customers can overwrite the field label texts with customer-specific texts. You can provide new field labels for screen fields which are based on the data element in this way. Prerequisites for Overwriting an SAP Field Label
Figure 23: Prerequisites for Overwriting an SAP Field Label
You can overwrite field labels for only those screen fields for which the developer of the screen has not assigned their own specific description. In such cases, the Dict. Modified attribute of the screen field has the value F.
30
© Copyright. All rights reserved.
Lesson: Enhancing Texts of Data Elements
Table 1: Possible Values of the Dict. Modified Attribute for a Screen Field Value
Function
SPACE
Field label that best fits the field length
1
Short field label
2
Medium field label
3
Long field label
4
Field label for header
V
Variable text transfer from the dictionary (as SPACE)
F
Fixed (no text transfer from the dictionary)
Overwriting SAP Field Labels – Steps
Figure 24: Overwriting SAP Field Labels – Steps
The figure shows the procedure to overwrite SAP field labels.
© Copyright. All rights reserved.
31
Unit 2: Enhancement of Dictionary Elements
Restoration of Customer Field Labels
Figure 25: Overwritten Texts in Upgrades
If SAP has redelivered existing field labels as part of an upgrade to a new release or you import new corrections, you need to restore your customer field labels. If you want to retain your own field labels from the previous release, choose the menu option that restores customer field labels. SAP recommends that you always restore your field labels after a release upgrade. Restoration of SAP Field Labels
Figure 26: Restoring SAP Field Labels
To undo field label changes, choose the Restore SAP Version menu option.
32
© Copyright. All rights reserved.
Lesson: Enhancing Texts of Data Elements
When you choose this option, the restoration is performed by a program which runs in the background. This program checks all the data elements that you have edited and restores their field labels, if necessary.
Note: All field labels will be restored - you cannot perform this action for a specific data element. For central field labels such as data elements BUKRS, MANDT, and so on, start the restoration when the contents of the tables that use BUKRS and MANDT are not being changed.
Enhanced Documentation for Data Elements
Figure 27: Enhanced Documentation for Data Elements
When you enhance the data element documentation, you can include the original SAP documentation as well as your own. In this case, when a user presses F1 in the corresponding screen field, the system displays the SAP documentation as well as the customer-specific documentation. If you want to revert to the original SAP documentation, delete your own documentation.
© Copyright. All rights reserved.
33
Unit 2: Enhancement of Dictionary Elements
Creation of Customer Documentation
Figure 28: Creating Customer Documentation
When you choose the menu path that is shown in the figure, a dialog box opens in which you have to choose between the options Original Text and Template. Select the Original text option to add additional text to the SAP documentation. Select the Template option to create customer-specific documentation without including the text of the SAP documentation. LESSON SUMMARY You should now be able to: ●
34
Enhance texts of data elements
© Copyright. All rights reserved.
Unit 2 Learning Assessment
1. Which of the following are characteristics of append structures? Choose the correct answers. X
A You can use multiple append structures with a single SAP table.
X
B You can use append structures as normal structures in programs.
X
C You can use one append structure in multiple tables.
X
D Customers can create an append structure for an SAP table without SAP preparation.
2. Which of the following are characteristics of Customizing Includes? Choose the correct answers. X
A Customizing Includes are already integrated into SAP tables by SAP.
X
B Customizing Includes may be linked with source code or screen exits provided by SAP for processing or displaying the fields of the table.
X
C Customizing Includes can be used in pool and cluster tables.
X
D Customizing Includes ensure consistency throughout the tables and structures affected.
© Copyright. All rights reserved.
35
Unit 2 Learning Assessment - Answers
1. Which of the following are characteristics of append structures? Choose the correct answers. X
A You can use multiple append structures with a single SAP table.
X
B You can use append structures as normal structures in programs.
X
C You can use one append structure in multiple tables.
X
D Customers can create an append structure for an SAP table without SAP preparation.
2. Which of the following are characteristics of Customizing Includes? Choose the correct answers.
36
X
A Customizing Includes are already integrated into SAP tables by SAP.
X
B Customizing Includes may be linked with source code or screen exits provided by SAP for processing or displaying the fields of the table.
X
C Customizing Includes can be used in pool and cluster tables.
X
D Customizing Includes ensure consistency throughout the tables and structures affected.
© Copyright. All rights reserved.
UNIT 3
Customer Exits
Lesson 1 Describing Enhancement Projects
38
Lesson 2 Enhancing Programs Using Program Exits Exercise 2: Implement a Customer Exit – Program Exit
46 57
Lesson 3 Enhancing Menus Using Menu Exits Exercise 3: Implement a Customer Exit – Menu Exit
62 65
Lesson 4 Enhancing Screens Using Screen Exits Exercise 4: Implement a Customer Exit – Screen Exit
70 77
UNIT OBJECTIVES ●
Describe enhancement projects
●
Create enhancement projects
●
Enhance code using program exits
●
Implement exit function groups
●
Enhance menus using menu exits
●
Enhance screens using screen exits
© Copyright. All rights reserved.
37
Unit 3 Lesson 1 Describing Enhancement Projects
LESSON OVERVIEW This lesson explains the fundamental aspects of enhancement projects, which you must use to implement existing customer exits. Business Example You would like to learn about the principle of an enhancement project in the customer exit environment. For this reason, you require the following knowledge: ●
An understanding of how to create, activate, and deactivate an enhancement project
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Describe enhancement projects
●
Create enhancement projects
SAP Application Enhancements
Figure 29: SAP Application Enhancements
Application enhancements are provided by SAP to allow customers to enhance their application functions. SAP preplans customer exits, which generally consist of several components. Application enhancements are inactive when delivered, and the customer uses and activates them, when needed. The characteristics of an application enhancement are as follows:
38
© Copyright. All rights reserved.
Lesson: Describing Enhancement Projects
●
Each enhancement provides you with a set of preplanned, precisely defined functions.
●
The interface for these functions is clearly defined.
●
Customers do not need in-depth knowledge of how to implement SAP applications.
●
Customers do not need to adjust enhancements during an upgrade if SAP have developed new functions.
Customer Enhancement Projects
Figure 30: Customer Enhancement Projects
SAP application programmers create SAP enhancements for program exits, menu exits, and screen exits. For this purpose, the system provides a management function (transaction code SMOD). A catalog containing an overview of existing SAP enhancements is provided to customers. They can then combine the SAP enhancements that they want to implement into an enhancement project using transaction CMOD. Enhancements and Enhancement Projects
Figure 31: Enhancements and Enhancement Projects
SAP enhancements are made up of component parts. These components include program exits, menu exits, and screen exits. A specific component can be assigned to only one SAP
© Copyright. All rights reserved.
39
Unit 3: Customer Exits
enhancement. This ensures that SAP enhancements are unique. SAP combines related components that belong together into one specific enhancement. Customer enhancement projects consist of SAP enhancements. You can use a SAP enhancement in only one single customer enhancement project. This ensures that the customer project is unique. The customer has to edit all enhancements that are to be activated together within one enhancement project. Customer Exits – Enhancement Management
Figure 32: The SAP Enhancement Creation Procedure
The following steps list the procedure used by SAP to create an enhancement: 1. SAP application programmers plan possible enhancements in an application and define the necessary components. 2. The application programmer combines these components in SAP enhancements. 3. The programmers document their enhancements in the best possible manner, so that customers can implement the enhancements without having to analyze the program source code or the screen source code.
40
© Copyright. All rights reserved.
Lesson: Describing Enhancement Projects
Procedure at the Customer’s Site
Figure 33: Procedure at the Customer’s Site
The general procedure for customers to use and implement enhancements is as follows: 1. Create an enhancement project. 2. Choose the SAP enhancements that you want to use. 3. Edit the individual components using the Project Management function. 4. Document the entire enhancement project. 5. Activate the enhancement project. This activates all of the project’s component parts.
© Copyright. All rights reserved.
41
Unit 3: Customer Exits
Customer Enhancement Projects
Figure 34: Creating a Customer Enhancement Project
To create a customer enhancement project, perform the following steps: 1. Run the transaction code CMOD to start the Project Management function. 2. Name your enhancement project. SAP recommends that you devise a naming convention for all of your projects. For example, you can include the transaction code or module pool name which you are enhancing in the project name. The project name uniquely identifies the enhancements in the system. 3. Go to the project attributes and enter a short text that describes the enhancement project. The remaining attributes are defaulted automatically (status, name, and time stamp) for recording creation and change details.
42
© Copyright. All rights reserved.
Lesson: Describing Enhancement Projects
Assignment of SAP Enhancements to Customer Projects
Figure 35: Assignment of SAP Enhancements to Customer Projects
Once the customer project has been created, you must then assign the relevant SAP enhancements to it. Enter the names of the SAP enhancements you want to use on the appropriate screen in transaction CMOD. The search function gives you a catalog-like overview of existing SAP enhancements. From there, you can select your desired enhancements. Editing the Enhancement Components
Figure 36: Editing the Enhancement Components
Once you have assigned the enhancement to the customer project, the components of the enhancement can be edited. When editing the components, you will branch to different tools, depending on the type of components. If it is a function module you will use the Function Builder, if it is a menu option, a
© Copyright. All rights reserved.
43
Unit 3: Customer Exits
dialog box will be displayed where you can make the necessary settings, and if it is a subscreen for a screen exit, you will use the Screen Painter. Activation of Enhancement Projects
Figure 37: Activating Enhancement Projects
Once you have made the necessary changes and settings to the enhancement components, the enhancement project must be activated. Activation affects all of the components of the project. After successful activation, the project has the status active. During activation, the system regenerates all programs, screens, and menus that contain components that belong to the project. (Note that the system will regenerate programs at the time of execution.) After activation, users will see the effect of the enhancements in the standard SAP application functions. The Deactivate function allows you to reset the status of an active enhancement project to inactive. This can be particularly useful if the effects in the SAP standard application are not as you expected. Transporting Enhancement Projects
Figure 38: Transporting Enhancement Projects
44
© Copyright. All rights reserved.
Lesson: Describing Enhancement Projects
Whenever you create an enhancement project, you have to assign it to a change request. Each of the related Repository objects, such as programs, subscreens, menu exits, and so on, should be assigned to the same change request. By doing this, the entire enhancement project and all of its components can then be transported at the same time. LESSON SUMMARY You should now be able to: ●
Describe enhancement projects
●
Create enhancement projects
© Copyright. All rights reserved.
45
Unit 3 Lesson 2 Enhancing Programs Using Program Exits
LESSON OVERVIEW This lesson explains how a program exit works, and how to implement a program exit which has been provided by SAP through a customer exit. It also outlines the possible uses of a program exit. Business Example You need to find program exits that are provided through customer exits and use them to enhance SAP standard applications. For this reason, you require the following knowledge: ●
An understanding of how to find program exits
●
An understanding of how to use program exits to enhance SAP standard code
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Enhance code using program exits
●
Implement exit function groups
Program Exits
Figure 39: Program Exit Overview
Program exits allow customers to implement additional logic in SAP standard applications. SAP programmers define where program exits are called in the standard application and what data can be transferred between the program and the program exit. In customer exits, these program exits are provided in the form of special function modules. SAP programmers create
46
© Copyright. All rights reserved.
Lesson: Enhancing Programs Using Program Exits
these exit function modules, which are complete with short text, interface, and documentation. The documentation for the function modules describes the intended purpose of each program exit. It is the job of the customer to write the source code for the function modules in the Function Builder. If any screens, text elements or additional Include programs are needed, they must be created in the same function group as the exit function module. Once you have implemented the exit function module, you must activate the code, but also the enhancement project (of which the function module is a component) - only then will your ABAP code be processed when the SAP standard application is executed. Program exits have no effect until the enhancement project is activated. Program Exits – Architecture
Figure 40: Program Exits – Architecture
The figure shows the flow of a program that provides an enhancement in the form of a program exit. The exit function module is called at a predefined point in the source code, decided by the SAP application developer. Within the function module, the customer code has to be inserted into a special include program.
© Copyright. All rights reserved.
47
Unit 3: Customer Exits
Program Exits – Syntax
Figure 41: Program Exits – Syntax
In the application, SAP developers call the exit function module using the ABAP statement CALL CUSTOMER-FUNCTION ‘NNN’, where ‘NNN’ is a three-digit number. They also create the corresponding function module and the function group. The function modules always belong to special function groups whose names begin with X. The exit function modules follow a naming convention: EXIT__
_ The CALL CUSTOMER-FUNCTION statement is executed only if the enhancement project is activated. If the same function module is called several times, the activation is valid for all calls.
Program Exit Search
Figure 42: Program Exit Search
48
© Copyright. All rights reserved.
Lesson: Enhancing Programs Using Program Exits
The most frequently asked question concerning enhancements is “How can you determine whether an application program offers a program exit?” This question is relevant regardless of the enhancement technology used for the program exit. You can use the following techniques to determine whether an application program offers a program exit: ●
Search in the source code of the application program When running a transaction, from the menu, choose System → Status. Double-click the program name to navigate to the source code. Use the Find button to search for the string CALL CUSTOMER-FUNCTION globally in the program.
●
Use global search tools On the right-hand side of the graphic, you can see global search tools which can be used to search for suitable enhancements. If you are using the Repository Information System to find suitable enhancements, you can restrict the search by the package which the enhancement belongs to, by its technical name, and also by its description.
Implementing Program Exits
Figure 43: Implementing Program Exits
The figure shows how to implement a program exit by navigating to the Include program in the exit function module. To Implement Program Exits The steps to implement program exits are as follows: 1. Go to transaction CMOD. 2. From the initial screen of CMOD, select the Components radio button and then Change to navigate to the enhancement components. (If you are no longer on the initial screen, there is a button labelled Components on the toolbar which you can choose instead).
© Copyright. All rights reserved.
49
Unit 3: Customer Exits
3. On the Components screen, there will be an entry for Function exit. Double-click the function module name listed next to it to navigate to the Function Builder, and go straight to the Source Code tab. Note: Do not change the function module, particularly the interface. The function module contains an INCLUDE statement for an include program that you create in the customer namespace. 4. Double-click the include program name which is used in the source code. This creates and opens the Include program in the editor, where you can enter the source code.
Normal Function Group Structure
Figure 44: Normal Function Group Structure
When you implement a function exit, the logic could be very simple, and you may only need to add code to the special include program. However, if you need to implement something more complex, you may need to define additional data objects, create subroutines and so on to use in your implementation. This will require you to use other parts of the Function Group which the function exit function module belongs to (this function group is sometimes known as an X function group). To use an X function group, you first need to understand how a normal function group is organized. A function group consists of a main program (of type function group) and include programs. Special naming conventions are used for the different Include programs, which are intended for different types of code. Some of the Include names are simply proposals and some cannot be changed. The TOP Include stores global data declarations and is generated automatically when a function group is created. Function modules are stored in Includes with sequential numbering. The Includes, in turn, are all stored in one special include ending with UXX.
50
© Copyright. All rights reserved.
Lesson: Enhancing Programs Using Program Exits
Note: Although you are free to choose the names of the Includes for all other function group subobjects (subroutines, PBO and PAI modules, event blocks, and so on), it is advisable to accept the proposed names. Interaction between SAP application program and the Exit Function Group
Figure 45: Exit Function Group
Exit Function Groups are created by an SAP developer especially for customer exits. These exit function groups consist of Include programs that begin with either LX or ZX. A customer can only edit include programs whose names start with a Z, because these are in the customer namespace. You cannot add further function modules to an exit function group. The Include programs ZXAAAUNN (where NN is a number) contain the customer's source code for the function modules of a function module exit.
© Copyright. All rights reserved.
51
Unit 3: Customer Exits
Global Data of an Exit Function Group
Figure 46: Global Data of an Exit Function Group
In exit function groups, the SAP developer can declare global data to be used elsewhere in the function group in the Include program LXAAATAP. When implementing a customer exit, if you need to declare additional global data, you must do so in the include program ZXAAATOP. The include program LXAAATOP also contains the FUNCTION-POOL statement, which may not be changed. This means that you cannot specify a default message class at the end of this statement, instead if you are going to issue messages in your function exit code, you will have to specify the message class directly in the MESSAGE statement itself. Additional Custom Processing Blocks
Figure 47: Additional Custom Processing Blocks
The Include program where you add your code is technically between the FUNCTIONENDFUNCTION in the ZXAAAUNN Include program. This means that event blocks,
52
© Copyright. All rights reserved.
Lesson: Enhancing Programs Using Program Exits
subroutines (FORM-ENDFORM), or modules (MODULE-ENDMODULE) are not permitted within this Include (that is, within the FUNCTION-ENDFUNCTION block). You need to create them in separate Includes. It is also important to note that any data declarations made in the include ZXAAAUNN using the DATA statement are only valid locally in this function module. The SAP developer will sometimes make a proposal for the source code to use in the function exit. If this is the case, the sample code will be found in the Include LXAAFNN, where 'NN' is the internal number for the function module in the LXAAAUXX Include. There will be a Sample Code button in transaction SMOD for any enhancement where this proposal exists. You can copy the source code from this Include to your customer Include program ZXAAAUNN. If necessary, you can create your own text symbols for the function group. Other SAP Objects in an Exit Function Group
Figure 48: Other SAP Objects in an Exit Function Group
SAP application programmers can provide you with default subroutines in the Include LXAAAF01. Table 2: Additional Includes Containing Specific Subobjects The following table lists the additional Includes that contain specific subobjects: Includes
Specific subobjects
LX...F01
Subroutines delivered by SAP
LX...E01
The event blocks belonging to the X function group
LX...O01
Process Before Output (PBO) modules for the screens to be delivered
LX...I01
The corresponding Process After Input (PAI) modules
© Copyright. All rights reserved.
53
Unit 3: Customer Exits
Customer Objects in an Exit Function Group
Figure 49: Customer Objects in an Exit Function Group
Code for custom subroutines, modules, and event blocks within an X function group must be created in separate Include programs that, in turn, are included in the Include program ZXAAAZZZ. Table 3: Naming Convention for Additional Includes Additional includes must adhere to the following naming convention:
54
Includes
Specific subobjects
ZXAAAFNN
Subroutines
ZXAAAONN
PBO modules
ZXAAAINN
PAI modules
ZXAAAENN
Events
© Copyright. All rights reserved.
Lesson: Enhancing Programs Using Program Exits
Customer Screens
Figure 50: Customer Screens
If you want to call a screen in your function exit implementation, the CALL SCREEN statement can be used, and the screen itself will need to be created in the exit function group, along with its flow logic. Create the related include programs for the PBO and PAI modules in the include program ZXAAAZZZ. Use forward navigation (double-clicking the relevant screen or module name) to create your screens and modules. Your screens will belong to the X function group (program SAPLXAAA). PBO and PAI modules are coded in Includes ZXAAAONN and ZXAAAINN, which again need to be included within ZXAAAZZZ.
Interaction Between SAP Application Program and the Exit Function Group
Figure 51: Interaction Between SAP Application Program and the Exit Function Group
© Copyright. All rights reserved.
55
Unit 3: Customer Exits
The figure summarizes the interaction between the SAP application program and the exit function module and function group.
56
© Copyright. All rights reserved.
Unit 3 Exercise 2 Implement a Customer Exit – Program Exit
Business Example Your co-workers have asked you to alter transaction BC425_## so that when they try to display the details of a flight with a date in the past, a warning message appears. Adjust the program so that a warning message appears when you select a flight for a date in the past. Do not modify the SAP program, instead check to see if it is possible to implement an enhancement using a program exit. Check Whether a Suitable Enhancement is Available in the Transaction Check whether it is possible to enhance the transaction. 1. Did the SAP developer provide a customer exit for the given transaction that you can use to add the required functionality? 2. What is the name of its corresponding enhancement? Choose the enhancement with which you can implement a supplementary check when you leave the first screen of the transaction. Implement the Enhancement and Check Results Create an enhancement project, implement the enhancement, and check your results. 1. Create an enhancement project named TG##CUS1, and include the enhancement you found in the previous task. 2. Program the following check in the exit module: Determine whether the date entered is before the current date. If this is the case, issue an appropriate warning. To do this, use message 011 from message class BC425. 3. Check your results.
© Copyright. All rights reserved.
57
Unit 3 Solution 2 Implement a Customer Exit – Program Exit
Business Example Your co-workers have asked you to alter transaction BC425_## so that when they try to display the details of a flight with a date in the past, a warning message appears. Adjust the program so that a warning message appears when you select a flight for a date in the past. Do not modify the SAP program, instead check to see if it is possible to implement an enhancement using a program exit. Check Whether a Suitable Enhancement is Available in the Transaction Check whether it is possible to enhance the transaction. 1. Did the SAP developer provide a customer exit for the given transaction that you can use to add the required functionality? a) Run transaction BC425_##. b) Choose System → Status. You can see the name of the corresponding program SAPBC425_FLIGHT##. c) Double-click on the program to navigate to the code. 2. What is the name of its corresponding enhancement? Choose the enhancement with which you can implement a supplementary check when you leave the first screen of the transaction. a) Choose
(Find).
b) In the Find field, enter CALL CUSTOMER-FUNCTION. c) Select the In Main program radio button. d) Choose Continue. e) In the results list, choose the first CALL CUSTOMER-FUNCTION. The call is in a PAI module called CUST_CHECK. f) Double-click the module name to navigate to the flow logic of the screen in which it is called. The module is called in the PAI flow logic of screen 100, which is the screen where the flight date field is displayed. This customer exit would therefore be suitable to implement the necessary check. g) Double-click on the number after the CALL CUSTOMER-FUNCTION (it should be 001 in this case). Note the full function module name. (It will be EXIT_SAPBC425_FLIGHT##_001.) h) Go back.
58
© Copyright. All rights reserved.
Lesson: Enhancing Programs Using Program Exits
i) To find the name of the enhancement which the exit function module belongs to, go to transaction SMOD (SAP Enhancements). j) Use the input help (F4) for the Enhancement field. k) In the Repository Information System: Find Exits dialog box, choose All Selections. l) In the Component Name field, enter the full function module name. m) Choose Execute. The name of the enhancement will be displayed. The name of the enhancement is SBC##E01. Note: Alternatively, the Repository Information System can be used to search for enhancements where the technical name of the component contains the program name — in this example, you could for EXIT_SAPBC425_FLIGHT##_*.
Implement the Enhancement and Check Results Create an enhancement project, implement the enhancement, and check your results. 1. Create an enhancement project named TG##CUS1, and include the enhancement you found in the previous task. a) Choose Tools → ABAP Workbench → Utilities → Enhancements → Project management. (Or execute transaction CMOD — Project Management of SAP Enhancements.) b) In the Project field, enter TG##CUS1 and choose Create. c) Add a short description. d) Save the project and assign it your package and transport request. 2. Program the following check in the exit module: Determine whether the date entered is before the current date. If this is the case, issue an appropriate warning. To do this, use message 011 from message class BC425. a) In your project, choose Enhancement assignments. b) Include enhancement SBC##E01 that you found in your project. c) Save your project. d) Choose Components. e) Double-click the function module name. The function will open in the Function Builder. f) Do not enter your code directly in the function module, instead double-click on the Include program name (ZXBCG425##U01). g) A warning message displays, so choose Enter to continue. h) When asked if the include program should be created, choose Yes. i) Assign to your package and transport request.
© Copyright. All rights reserved.
59
Unit 3: Customer Exits
j) When the Include program has been created, enter the following code: IF flight–fldate < sy–datum. MESSAGE w011(bc425) WITH sy–datum. ENDIF. k) Activate the include. l) Go back to Project management and activate your enhancement project. 3. Check your results. a) Run transaction BC425_##. b) Enter a flight date which is before the current date and press ENTER. The warning message appears.
60
© Copyright. All rights reserved.
Lesson: Enhancing Programs Using Program Exits
LESSON SUMMARY You should now be able to: ●
Enhance code using program exits
●
Implement exit function groups
© Copyright. All rights reserved.
61
Unit 3 Lesson 3 Enhancing Menus Using Menu Exits
LESSON OVERVIEW This lesson explains how menu exits are implemented. Business Example You need to find and implement menu exits that are provided through customer exits. For this reason, you require the following knowledge: ●
An understanding of how menu exits that are provided through customer exits work
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Enhance menus using menu exits
Menu Exits
Figure 52: Menu Exits Overview
Menu exits allow you to attach additional custom functions to menu options in SAP menus. For this purpose, SAP developer reserve certain menu options in the GUI status. You can specify the menu text for these additional custom menu options if you implement the associated menu exit. The menu options become visible in the SAP menu only after you implement the associated menu exit and then activate it. When the user chooses the corresponding menu option, the SAP application calls a related program exit which must be implemented to include their customer-specific functions.
62
© Copyright. All rights reserved.
Lesson: Enhancing Menus Using Menu Exits
Menu Exit Requirements
Figure 53: Menu Exit Requirements
To provide menu exits, SAP application programmers must add function codes which begin with a plus (+) sign to the relevant menu in the GUI status. These function codes are inactive and will not appear in the menu unless the menu exit has been implemented and activated. Menu Exits and Program Exits
Figure 54: Menu Exits and Program Exits
As well as adding the special function code (starting with a + ) to the menu in the GUI status, the SAP developer will also provide a program exit in the associated program, which will be executed if a user chooses the function code.
© Copyright. All rights reserved.
63
Unit 3: Customer Exits
Implementing Menu Exits
Figure 55: Implementing Menu Exits
You can implement menu exits using the transaction CMOD, for Project Management. On the Components screen, the menu text can be assigned by double-clicking on the Menu Exit entry. A dialog box is displayed where you can maintain the menu text in the Function text field. Of course the associated function exit must also be implemented with the logic to be executed when a user chooses the new menu entry. This has already been described in the previous section.
64
© Copyright. All rights reserved.
Unit 3 Exercise 3 Implement a Customer Exit – Menu Exit
Business Example The new warning messages in transaction BC425_## help your colleagues to avoid selecting flights from the past. However, they want more. They want you to create a link from this transaction to display a list of bookings for the flight they have chosen. A suitable executable program (SAPBC425_BOOKING_##) already exists to display the bookings, but at the moment the users have to run this program independently and enter details of the flight on the selection screen. Implement an enhancement with a menu exit in combination with a program exit to allow users to navigate to the bookings list from the flight transaction. Analyze the Transaction to Determine if a Suitable Enhancement Exists Examine transaction BC425_##. Is it possible to call the program using a menu entry in the transaction? 1. Did the SAP developer implement a customer exit that you can use to add the required functionality for the given transaction? 2. What is the name of the corresponding enhancement? Choose the enhancement with which you can implement a menu enhancement. Implement the Menu and Program Exit Create an enhancement project and implement the enhancement, then check your results. 1. Create an enhancement project called TG##CUS2 and include the enhancement that you found in the previous task. 2. Edit the components of the enhancement you found. Maintain the menu text Display Flight Bookings for the menu exit. Make sure that when the menu entry is chosen, program SAPBC425_BOOKING_## is called. The user must be able to return to the flight details from the bookings list. Transfer the chosen flight data to the selection screen of the program to be called. To do this, use the data that is available to you in the program exit. 3. Activate the project, then check your results.
© Copyright. All rights reserved.
65
Unit 3 Solution 3 Implement a Customer Exit – Menu Exit
Business Example The new warning messages in transaction BC425_## help your colleagues to avoid selecting flights from the past. However, they want more. They want you to create a link from this transaction to display a list of bookings for the flight they have chosen. A suitable executable program (SAPBC425_BOOKING_##) already exists to display the bookings, but at the moment the users have to run this program independently and enter details of the flight on the selection screen. Implement an enhancement with a menu exit in combination with a program exit to allow users to navigate to the bookings list from the flight transaction. Analyze the Transaction to Determine if a Suitable Enhancement Exists Examine transaction BC425_##. Is it possible to call the program using a menu entry in the transaction? 1. Did the SAP developer implement a customer exit that you can use to add the required functionality for the given transaction? a) Run transaction BC425_## b) From the menu, choose System → Status. c) Double-click the program name to navigate to the code. d) Chose Find. e) In the Find field, enter CALL CUSTOMER-FUNCTION. f) Select the In Main Program radio button g) Choose Continue. h) In the results list, click the second CALL CUSTOMER-FUNCTION. The call is in a PAI module which evaluates the function code chosen by the user on the screen, and will only be executed if this function has the code +EXT. All menu exit function codes start with +, so this exit is suitable for the task. i) Double-click the number after the CALL CUSTOMER-FUNCTION (it should be 002 in this case). j) Note the full function module name (it will be EXIT_SAPBC425_FLIGHT##_002). k) To find the name of the enhancement which the exit function module belongs to, go to transaction SMOD. l) Use the input help (F4) for the Enhancement field.
66
© Copyright. All rights reserved.
Lesson: Enhancing Menus Using Menu Exits
m) Choose Information System. n) In the Repository Information System: Find Exits dialog box, choose
All Selections.
o) Enter the full function module name in the Component Name field. p) Choose Execute. 2. What is the name of the corresponding enhancement? Choose the enhancement with which you can implement a menu enhancement. a) The name of the enhancement is SBC##E02. Implement the Menu and Program Exit Create an enhancement project and implement the enhancement, then check your results. 1. Create an enhancement project called TG##CUS2 and include the enhancement that you found in the previous task. a) Choose Tools → ABAP Workbench → Utilities → Enhancements → Project management. (Or execute transaction CMOD). b) Enter TG##CUS2 in the Project field and choose Create. c) Enter a short description for your project. d) Choose Save. e) Assign the project to your package and transport request. 2. Edit the components of the enhancement you found. Maintain the menu text Display Flight Bookings for the menu exit. Make sure that when the menu entry is chosen, program SAPBC425_BOOKING_## is called. The user must be able to return to the flight details from the bookings list. Transfer the chosen flight data to the selection screen of the program to be called. To do this, use the data that is available to you in the program exit. a) In your project, choose Enhancement Assignment and choose Change. b) In the Enhancement column, enter SBC##E02 (this is the enhancement that you found in task one). c) Choose Save. d) Choose Components. e) Double-click Menu Exit. f) In the Function Text field enter the menu text, then choose Copy. g) Assign to your transport request. h) On the Change TG##CUS2 screen, double-click Function exit. The function module will open in the Function Builder. i) Do not enter your code directly in the function module, instead double-click on the Include program name (ZXBC425G##U02). j) A warning message will be displayed, press ENTER to continue. k) When prompted, choose Yes to create the Include program.
© Copyright. All rights reserved.
67
Unit 3: Customer Exits
l) Assign the program to your package and transport request. m) When the Include program has been created, enter the following code: SUBMIT SAPBC425_BOOKING_## WITH so_car = flight–carrid WITH so_con = flight–connid WITH so_fld = flight–fldate AND RETURN. n) Choose
(Activate).
o) In the Inactive Objects dialog box, choose
(Select All).
p) Activate the enhancement project. 3. Activate the project, then check your results. a) Run transaction BC425_##. b) Use the input help to choose an airline carrier, flight connection code and a flight date (make sure to choose a date in the future). c) Choose Display. d) Choose Goto → Display Flight Bookings. (This is the new menu entry that you created using the menu exit.) e) Verify that the bookings displayed in the list correspond to the flight you chose. f) Choose the Back button to return to the transaction.
68
© Copyright. All rights reserved.
Lesson: Enhancing Menus Using Menu Exits
LESSON SUMMARY You should now be able to: ●
Enhance menus using menu exits
© Copyright. All rights reserved.
69
Unit 3 Lesson 4 Enhancing Screens Using Screen Exits
LESSON OVERVIEW This lesson explains how to find a screen exit that is implemented using a customer exit. Business Example You need to find and use screen exits that are available in the SAP standard system. For this reason, you require the following knowledge: ●
An understanding of how to find and use screen exits that are implemented using customer exits
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Enhance screens using screen exits
Screen Exits
Figure 56: Screen Exits Overview
Screen exits allow you to use reserved sections of a main screen (which are technically subscreen areas) to display additional information or allow the user to enter additional data. To create these additional input and output fields, you must create a customer subscreen, which will then be embedded in the subscreen area provided by the SAP developer.
70
© Copyright. All rights reserved.
Lesson: Enhancing Screens Using Screen Exits
Overview - Normal Subscreens
Figure 57: Normal Subscreens
Subscreens are rectangular areas on a screen that are reserved for displaying additional screens at runtime. Another screen (of type subscreen) can be displayed in each subscreen area at runtime. A Normal Subscreen Call
Figure 58: Slide 1
The subscreen to be embedded in the subscreen area is determined at the Process Before Output (PBO) event. The general syntax for calling a normal subscreen is as follows: CALL SUBSCREEN INCLUDING represents the main program to which the subscreen belongs, and represents the subscreen number.
© Copyright. All rights reserved.
71
Unit 3: Customer Exits
For each subscreen, the Process After Input (PAI) and Process Before Output (PBO) events are processed, as in regular screens. The sequence of “CALL SUBSCREEN” calls in the flow logic of the main screen determines the sequence in which the system processes the flow logic of individual subscreens. Remember the following points about regular subscreens: ●
The function code can only be processed via the main screen.
●
A subscreen may not have a named OK_CODE field.
●
You cannot define GUI statuses for subscreens.
●
You cannot control what the next screen will be in the flow logic of the subscreen (again this is done in the main screen).
Screen Exits Definition
Figure 59: Customer subscreen embedded in SAP screen
An SAP developer may create several subscreen areas on a main screen, reserved for subscreens. However, these subscreen areas may not all be reserved for a screen exit. If a subscreen area has been reserved for a screen exit, the subscreen is called during the flow control of the main screen with the CALL CUSTOMER-SUBSCREEN statement. The name of the subscreen area is defined without apostrophes.The function group to which the subscreen belongs is defined statically in apostrophes. However, the screen number can be supplied using a variable. If no implementation exists for a screen exit, the standard screen will be displayed without a subscreen in the subscreen area. The system processes the screen exit only after you have created a corresponding subscreen in an enhancement project and have activated this project.
72
© Copyright. All rights reserved.
Lesson: Enhancing Screens Using Screen Exits
Like menu exits, you create subscreens for screen exits in X function groups. Normally, these function groups also include program exits to allow additional logic relating to the subscreen to be coded. Call of a Customer Subscreen
Figure 60: Call of a Customer Subscreen
Customer subscreens are included in the subscreen area that the SAP developer defined when the CALL CUSTOMER-SUBSCREEN INCLUDING statement is processed in the PBO flow logic of the main screen. At this point, the system also processes all modules called during the PBO event of the subscreen. The PAI event of a subscreen is processed when the screen calls the subscreen during its PAI event.
© Copyright. All rights reserved.
73
Unit 3: Customer Exits
Transport of Data to Subscreens
Figure 61: Transport of Data to Subscreens
The X function group that contains your subscreen does not have direct access to the global data of the calling program. For this reason, when SAP developers create a screen exit, they will also create a program exit, and call it in a PBO module of the main screen in the SAP application to allow the data to be passed to the exit function group and therefore the subscreen. The corresponding exit function modules are in the same X function group in which you must create the customer subscreen. Transport of Data from Subscreens
Figure 62: Transport of Data from Subscreens
74
© Copyright. All rights reserved.
Lesson: Enhancing Screens Using Screen Exits
If data is to be transported back to the SAP application from the customer subscreen, the SAP developer will also create a second program exit to allow the data to be returned. This second program exit would be called in a PAI module of the main screen so the relevant data can be returned to the SAP application from the exit function group. Note: If the SAP developer did not intend for data to be passed back from the subscreen, this second program exit might not be available. Implementing a Screen Exit
Figure 63: Implementing a Screen Exit
The Project Management transaction CMOD is used to implement screen exits. In the Components screen of the project in CMOD, the screen exit will be displayed with the following elements: ●
The name of the calling program
●
The four-digit screen number for the main screen
●
The name of the subscreen area, followed by the name of the main program of the exit function group and the number of the subscreen
© Copyright. All rights reserved.
75
Unit 3: Customer Exits
Creating and Editing the Subscreen
Figure 64: Creating and Editing the Subscreen
You can create the customer subscreen using forward navigation (i.e. double-clicking on it) from the Components screen in transaction CMOD. When creating the subscreen, ensure that the screen type is Subscreen. The rules described earlier in this unit about what you can and cannot edit in the exit function group apply here too.
76
© Copyright. All rights reserved.
Unit 3 Exercise 4 Implement a Customer Exit – Screen Exit
Business Example Your users ask for a further improvement to transaction BC425_##. They would like additional data to be displayed for the chosen flight. You accept this new challenge from your coworkers and try to solve the problem without modification of the transaction. Specifically, you start looking for a way to add several new fields to the second screen of this transaction (screen number 200). Check Whether a Suitable Screen Exit is Available Check screen 200 of transaction BC425_## to see if there are available options to place additional fields on the screen 1. Is there a screen exit for enhancing the screen? 2. If this is the case, what is the name of the corresponding enhancement? Implement the Enhancement Implement the enhancement to add three fields to the screen. To do this, create a new project in transaction CMOD called TG##CUS3, include the enhancement which you found in the first task, and implement the relevant components. 1. Add three fields to the screen. The following should appear: ●
Pilot’s name (SFLIGHT##-YYPILOT)
●
Meal (SFLIGHT##-YYMEAL)
●
The number of free places on the current flight (to be calculated as SFLIGHT##SEATSMAX - SFLIGHT##-SEATSOCC.
Test the Program 1. Execute transaction BC425_## and check your results.
© Copyright. All rights reserved.
77
Unit 3 Solution 4 Implement a Customer Exit – Screen Exit
Business Example Your users ask for a further improvement to transaction BC425_##. They would like additional data to be displayed for the chosen flight. You accept this new challenge from your coworkers and try to solve the problem without modification of the transaction. Specifically, you start looking for a way to add several new fields to the second screen of this transaction (screen number 200). Check Whether a Suitable Screen Exit is Available Check screen 200 of transaction BC425_## to see if there are available options to place additional fields on the screen 1. Is there a screen exit for enhancing the screen? a) Run transaction BC425_##. b) Use the input help to choose an airline carrier, flight connection code and a flight date (make sure to choose a date in the future). c) Choose
(Display).
d) From the menu, choose System → Status. e) Double-click the screen number 200 to navigate to the code for the screen. f) Open the Flow Logic tab page. g) Examine the flow logic of the screen for and look for the statement CALL CUSTOMER– SUBSCREEN. You will see that screen 200 of transaction BC425_## offers a screen exit. 2. If this is the case, what is the name of the corresponding enhancement? a) Double-click the PBO module name (DATA_FOR_SUBSCREEN) which is called just before the CALL CUSTOMER-SUBSCREEN statement in the flow logic. (Just before a screen exit is called, there will be a program exit to allow data to be passed from the program to the subscreen.) b) Double-click the number after the CALL CUSTOMER-FUNCTION (it is 003 in this case). c) Note the full function module name (it is EXIT_SAPBC425_FLIGHT##_003). d) Go to transaction SMOD to find the name of the enhancement to which the exit function module belongs. e) Use the input help (f4) for the Enhancement field. f) Choose Information Systems.
78
© Copyright. All rights reserved.
Lesson: Enhancing Screens Using Screen Exits
g) In the Repository Information System: Find Exits dialog box, choose
(All Selections).
h) In the Component Name field, enter the full function module name. i) Choose (Execute). The name of the enhancement is SBC##E03. Implement the Enhancement Implement the enhancement to add three fields to the screen. To do this, create a new project in transaction CMOD called TG##CUS3, include the enhancement which you found in the first task, and implement the relevant components. 1. Add three fields to the screen. The following should appear: ●
Pilot’s name (SFLIGHT##-YYPILOT)
●
Meal (SFLIGHT##-YYMEAL)
●
The number of free places on the current flight (to be calculated as SFLIGHT##SEATSMAX - SFLIGHT##-SEATSOCC.
a) Choose Tools → ABAP Workbench → Utilities → Enhancements → Project management. (Or execute transaction CMOD. b) Enter TG##CUS3 in the Project field and choose Create. c) Enter a short description for your project. d) Choose Save. e) Assign the project to your package and transport request. f) In your project, choose Enhancement Assignments. g) Enter the enhancement that you found in the previous step (SBC##E03). h) Choose Save. i) Choose Components. j) Double-click Screen exit. The Screen Painter will open. k) In the Information dialog box, choose Continue. l) On the Attributes tab page, give the screen a short description. m) In the Screen Type screen area, select the Subscreen radio button. One of the fields to be added to the screen needs to be calculated. You will need to define a variable for this calculation in the Top Include of the function group to which the screen belongs. In addition to this, since the other fields are from SFLIGHT##, a corresponding TABLES structure will also need to be defined, to allow the data transfer between the screen fields and the program. n) Choose Save. o) From the menu, choose Utilities → Display Object List to display the function group. p) In the Object Name screen area, open the Includes folder.
© Copyright. All rights reserved.
79
Unit 3: Customer Exits
q) Double-click the include named ZX........TOP. r) Choose Yes to create the include. s) Assign to your package and transport request. t) If the Different original and logon languages dialog box appears, choose Maint in orig. lang. u) Choose Yes to create the include. Alternatively, right-click the include name and choose Create. v) Save it and assign it to your package and transport request. w) Open the Flow Logic tab page. x) Add the following code: TABLES: sflight##. DATA: seatsfree TYPE s_seatsocc. y) Activate the TOP include. z) In the Object name screen area expand the Screens node. aa) Double-click screen 500 to open the Screen Painter again. ab) Choose Layout to open the Graphical Screen Painter. ac) Choose Dictionary/Program Fields. ad) In the Table/Field Name field, enter SFLIGHT##. Then choose Get from Dictionary. ae) Select the fields YYPILOT and YYMEAL, then choose Continue. af) Position the fields to the top left-hand corner of the screen, then use the left-mouse button to drop them into place. ag) Choose Dictionary/Program Fields. ah) Choose Get from Program. ai) Select SEATSFREE, and repeat as above to position the field directly under the two fields you have already added to the screen. aj) You can also add a Text field with a suitable label in front of the new added input field (for example Free Seats). Note: It will also make sense to mark the new input fields as Output only (since all other fields displayed on this screen are output only too). This can be done by changing the Attributes of each new input field created ak) Choose Activate to activate the screen, then close the Graphical Screen Painter. al) Choose Back several times to return to transaction CMOD. am) Double-click the function module name. The function module will open in the Function Builder.
80
© Copyright. All rights reserved.
Lesson: Enhancing Screens Using Screen Exits
an) Do not enter your code directly in the function module, instead double-click on the Include program name (ZXBC425G##U01). ao) A warning message is displayed, choose Enter to continue. ap) Choose Yes to create the include program. aq) Assign the program to your package and transport request. ar) Enter the following code: MOVE-CORRESPONDING flight TO sflight##. seatsfree = flight-seatsmax – flight-seatsocc. as) Activate your code. at) Choose Back and activate your enhancement project. Green traffic lights will indicate that everything is now active. Test the Program 1. Execute transaction BC425_## and check your results. a) Run transaction BC425_##. b) Use the input help to choose an airline carrier, flight connection code and a flight date (make sure to choose a date in the future). c) Choose (Display). The additional fields should be displayed on the screen.
© Copyright. All rights reserved.
81
Unit 3: Customer Exits
LESSON SUMMARY You should now be able to: ●
82
Enhance screens using screen exits
© Copyright. All rights reserved.
Unit 3 Learning Assessment
1. Which of the following steps are required in the procedure to create an SAP enhancement? Choose the correct answers. X
A Define necessary components
X
B Assign components to SAP enhancements
X
C Document the enhancement project
X
D Activate the enhancement project
2. Which of the following steps are required in the procedure to create a customer enhancement project? Choose the correct answers. X
A Start project management
X
B Name your enhancement project
X
C Transport the project
X
D Enter a short text description in the project attributes
3. Which of the following includes contains the events belonging to the X function group? Choose the correct answer. X
A LX...F01
X
B LX...E01
X
C LX...O01
X
D LX...I01
© Copyright. All rights reserved.
83
Unit 3: Learning Assessment
4. Screen exits allow you to make use of reserved sections of a main screen. These reserved sections are called ____________. Choose the correct answer.
84
X
A Normal screens
X
B Subscreen areas
X
C Program screens
X
D Classical screens
© Copyright. All rights reserved.
Unit 3 Learning Assessment - Answers
1. Which of the following steps are required in the procedure to create an SAP enhancement? Choose the correct answers. X
A Define necessary components
X
B Assign components to SAP enhancements
X
C Document the enhancement project
X
D Activate the enhancement project
2. Which of the following steps are required in the procedure to create a customer enhancement project? Choose the correct answers. X
A Start project management
X
B Name your enhancement project
X
C Transport the project
X
D Enter a short text description in the project attributes
3. Which of the following includes contains the events belonging to the X function group? Choose the correct answer. X
A LX...F01
X
B LX...E01
X
C LX...O01
X
D LX...I01
© Copyright. All rights reserved.
85
Unit 3: Learning Assessment - Answers
4. Screen exits allow you to make use of reserved sections of a main screen. These reserved sections are called ____________. Choose the correct answer.
86
X
A Normal screens
X
B Subscreen areas
X
C Program screens
X
D Classical screens
© Copyright. All rights reserved.
UNIT 4
Classic Business Add-Ins
Lesson 1 Describing an ABAP Objects Interface
88
Lesson 2 Describing Classic Business Add-Ins (BAdIs)
91
Lesson 3 Explaining Additional Details of Business Add-Ins (BAdIs)
97
UNIT OBJECTIVES ●
Describe an ABAP Objects interface
●
Describe classic Business Add-Ins (BAdIs)
●
Explain additional details of BAdIs
© Copyright. All rights reserved.
87
Unit 4 Lesson 1 Describing an ABAP Objects Interface
LESSON OVERVIEW This lesson summarizes the basics of object-oriented programming which are necessary to understand Business Add-Ins. Business Example You want to add new functions to a flight maintenance transaction. To minimize the adjustment effort during the next upgrade, you want the implementation to contain as few modifications as possible. In particular, you want to use BAdIs provided by SAP. For this reason, you require the following knowledge: ●
An understanding of the ABAP Objects interface
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Describe an ABAP Objects interface
ABAP Objects – Interfaces
Figure 65: Classes and Objects
Business Add-Ins are an object-oriented enhancement technique. It is therefore useful to have a basic understanding of object-oriented concepts and terminology, when working with BAdIs. The basic approach of object-oriented programming is to think in terms of objects. The technical description of an object is provided by its class and the object is an instance of a class. Each object exists only during the lifetime of the program. A class consists not only of object-dependent attributes and methods, but also components, which are valid in general and have no special dependence on a concrete object. These components are called static components (static attributes and static methods).
88
© Copyright. All rights reserved.
Lesson: Describing an ABAP Objects Interface
Interfaces
Figure 66: Interfaces
An interface is a collection of formally defined methods without any coding. This means that the names of the methods are defined and their signatures, but there is no implementation of the method in the interface. An interface can be integrated into a class, which is then known as the implementing class of the interface. In the class, you can implement all interface methods with their class-specific implementation. If there are several implementing classes, each one will have its own class-specific coding for the method, even though there is only one definition of the method in the interface. Reference Variables
Figure 67: Reference Variables
Instances of classes (objects) are created at runtime, and therefore have no name. This means you have to access an instance through its reference variable (pointer), which refers to the instance. You must define a reference variable in the declaration block of a program with the additional specification TYPE REF TO . To create an object of the class, use the defined reference variable. The reference variable then refers ("points") to this object. You can then call instance methods of the object by using the reference variable as a prefix. To call class methods, you do not need an object because the class components are independent of any object of this class. Here the class name is used as a prefix to call a class method.
© Copyright. All rights reserved.
89
Unit 4: Classic Business Add-Ins
Interface Reference Variables
Figure 68: Interface Reference Variables
There is no way to instantiate an interface because interfaces do not have any coding. Therefore, you cannot use the statement CREATE OBJECT using a reference variable which is typed with reference to an interface. The implementation of an interface is provided by a class, which is hierarchically below the interface. A reference variable which is typed with reference to an interface can, therefore, point to an instance of the implementing class. Interface references can only be used to call the interface components of an object of the implementing class. The code which is executed depends on the implementing class. If you have several implementing classes for an interface, the same method can be called for objects of these different classes, but a different implementation will be executed for each object. LESSON SUMMARY You should now be able to: ●
90
Describe an ABAP Objects interface
© Copyright. All rights reserved.
Unit 4 Lesson 2 Describing Classic Business Add-Ins (BAdIs)
LESSON OVERVIEW This lesson describes the architecture of classic Business Add-Ins (BAdIs). It also describes how to find BAdIs. Business Example You need to enhance SAP software by using classic BAdIs delivered in the standard SAP system. For this reason, you require the following knowledge: ●
How to search for available BAdIs in SAP programs
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Describe classic Business Add-Ins (BAdIs)
Classic Business Add-Ins
Figure 69: BAdIs - Architecture
One of the reasons that SAP introduced BAdIs was to take into account changes which have occurred in the software delivery process over the years. The lower section of the figure explains how BAdIs function. An SAP application program provides the enhancement option. This requires at least one interface and a BAdI adapter class that implements it.
© Copyright. All rights reserved.
91
Unit 4: Classic Business Add-Ins
The interface is implemented by the user who wishes to use the BAdI. The strength of this concept lies in its reusability: a BAdI can be implemented many times, even by parties further towards the end of the software delivery chain. Business Add-Ins also enable each party in the software delivery chain to offer enhancements. BAdIs – Components
Figure 70: BAdIs – Components
A BAdI contains the components of an enhancement. BAdI Components ● Program enhancements The interface for program enhancements are defined in the form of interface methods in a BAdI. The SAP program calls the interface methods of the generated BAdI class. ●
Menu enhancements Function codes can be defined in a BAdI. These menu options are available in the GUI definition and made visible when the BAdI is implemented.
●
Screen enhancements You can define and implement screen enhancements in a BAdI.
92
© Copyright. All rights reserved.
Lesson: Describing Classic Business Add-Ins (BAdIs)
Definition and Implementation of Classic BAdIs
Figure 71: Definition and Implementation of Classic BAdIs
The components which must be created when a BAdI is defined are as follows: Interface
●
●
Generated class (the BAdI adaptor class) that implements the interface
The generated class (BAdI adaptor class) performs the following tasks: ● Filtering If implementations are created for a filter-dependent BAdI, the BAdI adapter class ensures that only the relevant implementations are called. ●
Control The BAdI adapter class calls the active implementations.
© Copyright. All rights reserved.
93
Unit 4: Classic Business Add-Ins
BAdIs – Flow of a Program Exit
Figure 72: BAdIs – Flow of a Program Exit
The figure shows the process flow of a program that contains a BAdI call. A reference variable must be declared that refers to the BAdI interface in the declaration section. An object reference (the instance of the BAdI adapter class) is generated in the first step by calling the method GET_INSTANCE of the service class CL_EXITHANDLER. This object is then used to call the program enhancement method(s). In the second step, the interface method of the BAdI class is called. In here, all active implementations of the BAdI are determined, and then the implemented methods are called.
94
© Copyright. All rights reserved.
Lesson: Describing Classic Business Add-Ins (BAdIs)
BAdIs – Call Syntax in SAP Programs
Figure 73: BAdIs – Call Syntax in SAP Programs
The figure shows the syntax with which an application calls a BAdI. The numbered circles correspond to the calls from the previous figure.
BAdI Search
Figure 74: Finding a BAdI
You can search for BAdIs in the following ways: ●
You can search in an application program for the string CL_EXITHANDLER. If a BAdI is called from the program, the GET_INSTANCE method of this class will be called.
© Copyright. All rights reserved.
95
Unit 4: Classic Business Add-Ins
-
●
●
You can then access the BAdI definition using forward navigation. The definition also contains documentation and a guide for implementing the BAdI.
To perform a general search for BAdIs, you can use the application hierarchy to restrict the components in which you want to search. Start the Repository Information System and choose Enhancements → Business Add-Ins to start the relevant search program. You can also search for BAdIs by using the entries in the relevant Customizing component.
LESSON SUMMARY You should now be able to: ●
96
Describe classic Business Add-Ins (BAdIs)
© Copyright. All rights reserved.
Unit 4 Lesson 3 Explaining Additional Details of Business AddIns (BAdIs)
LESSON OVERVIEW This lesson explains advanced details of Business Add-Ins (BAdIs). Business Example You have to add new functions to a flight maintenance transaction in the SAP standard system. To minimize the effort during the next upgrade, you want to use BAdIs provided by SAP. For this reason, you require the following knowledge: ●
An understanding of extendable filter types
●
An understanding of default and sample code
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Explain additional details of BAdIs
Extendable Filter Types
Figure 75: Extendable Filter Types – Prerequisites
Business Add-Ins may be implemented on the basis of a filter value, for example, a country code. If this is the case, the Filter-dependent checkbox in the BAdI definition will be selected, and a data element will be referenced as the filter type.
© Copyright. All rights reserved.
97
Unit 4: Classic Business Add-Ins
Whenever the SAP application program is executed, different implementations are executed, depending on the filter value. You can also specify generic filter values for the implementation of a BAdI. You can use the asterisk symbol to represent any part of a filter value. If the filter is labelled as 'Enhanceable', then an implementation can be created for filter values which are not already in the value table for the domain. When you save the implementation, the system adds these filter values to the value table. When you delete the implementation or the entire BAdI, the system removes the values from the value table. The same situation applies to the text tables. The assignment of the extendable attribute is subject to several restrictions. The domain to which the data element filter type refers must have the following properties: ●
●
●
The domain is linked to a cross-client value table. The value table has exactly one key field, which has the data element of the filter type as its field type. The domain has a text table with two key fields. A key field has the filter type as its field type, and a key field as a language field. To mark a field as a text field, the field must exist in a table that contains TEXT or TXT as a partial string. In the ABAP Dictionary, the text table must be assigned to the value table. The delivery class of both tables must be E or S.
If you want to implement a filter-dependent Business Add-In, you will need an implementation for each filter value that is relevant. Multiple filter values can use the same implementation, however. To implement a filter-dependent BAdI, proceed as follows: ●
●
98
Create an implementation by referring to the corresponding Business Add-In definition. Assign a filter value for the implementation, or choose F4 and select a value from the list of possible entries displayed. (It is possible to define multiple filter values for each implementation).
●
Implement the BAdI method(s) as usual.
●
Activate your implementations.
© Copyright. All rights reserved.
Lesson: Explaining Additional Details of Business Add-Ins (BAdIs)
Default and Sample Code
Figure 76: Default Implementation
A default implementation is executed when no other active implementation of a BAdI exists. The developer who defines the BAdI can create a default implementation. If a developer creates a default implementation for a BAdI definition, it can be found under the menu Goto → Default code. The system automatically generates a class with a predefined name. You then implement the methods with the required default behavior. The developer who defines the BAdI can also create a sample implementation, which acts as a template that can be used when the BAdI methods are implemented. If a developer creates a sample implementation for a BAdI definition, it can be found under the menu Goto → Sample Code. A developer who creates an implementation for the BAdI can view and use the sample code as a template.
© Copyright. All rights reserved.
99
Unit 4: Classic Business Add-Ins
Comparison with Other Enhancement Techniques
Figure 77: Comparison with Other Enhancement Techniques
BAdIs are a logical evolution of the older enhancement techniques. They have an administration layer like customer exits, along with the availability of various types of enhancement component. The idea of making BAdIs reusable was adopted from Business Transaction Events. The implementation of BAdIs involves an object-oriented approach.
Naming Conventions ●
BAdI definition -
OR Z OR /../ (Choose any; comply with namespace)
●
Interface -
IF_EX_ OR ZIF_EX_ OR /../IF_EX_ (Comply with namespace)
●
Methods -
●
Choose any name
Generated BAdI class (adapter class) -
CL_EX_ OR ZCL_EX_ OR /../CL_EX_ (Not changeable)
Naming Conventions (BAdI Implementations) ●
BAdI implementation -
100
OR Z OR /../
© Copyright. All rights reserved.
Lesson: Explaining Additional Details of Business Add-Ins (BAdIs)
(Choose any; comply with namespace) ●
Implementing class -
CL_IM_ OR ZCL_IM_ OR /../CL_IM_ (Choose any; comply with namespace)
LESSON SUMMARY You should now be able to: ●
Explain additional details of BAdIs
© Copyright. All rights reserved.
101
Unit 4: Classic Business Add-Ins
102
© Copyright. All rights reserved.
Unit 4 Learning Assessment
1. Which of the following components can be part of a Business Add-In (BAdI)? Choose the correct answers. X
A Program enhancements
X
B Screen enhancements
X
C Text enhancements
X
D Menu enhancements
2. If you want to implement a filter-dependent Business Add-In, you will need an implementation for each filter value that is relevant. Determine whether this statement is true or false. X
True
X
False
© Copyright. All rights reserved.
103
Unit 4 Learning Assessment - Answers
1. Which of the following components can be part of a Business Add-In (BAdI)? Choose the correct answers. X
A Program enhancements
X
B Screen enhancements
X
C Text enhancements
X
D Menu enhancements
Correct. Program enhancements, screen enhancements, and menu enhancements are parts of Business Add-In. 2. If you want to implement a filter-dependent Business Add-In, you will need an implementation for each filter value that is relevant. Determine whether this statement is true or false.
104
X
True
X
False
© Copyright. All rights reserved.
UNIT 5
New Business Add-Ins
Lesson 1 Describing the Change from Classic BAdIs to New BAdIs
106
Lesson 2 Using New Business Add-In (BAdI) Program Exits Exercise 5: Implement New BAdI Program Exits
109 115
Lesson 3 Using New Business Add-In (BAdI) Menu Exits Exercise 6: Implement a New BAdI Menu Exit
119 123
Lesson 4 Using New Business Add-In (BAdI) Screen Exits Exercise 7: Implement New BAdI Screen Exits
127 131
Lesson 5 Using New Business Add-Ins (BAdIs) Exercise 8: Define a New BAdI
137 143
UNIT OBJECTIVES ●
Explain the Integration of BAdIs into the Enhancement Framework
●
Implement New BAdI Program Exits
●
Implement New BAdI Menu Exits
●
Implement New BAdI Screen Exits
●
Define New BAdIs
© Copyright. All rights reserved.
105
Unit 5 Lesson 1 Describing the Change from Classic BAdIs to New BAdIs
LESSON OVERVIEW This lesson describes how to use implicit enhancements in SAP function modules. Business Example You have found an SAP standard function module whose behavior you want to change, without making modifications. For this reason, you require the following knowledge: ●
●
An understanding of the implicit enhancement points and implicit enhancement options available in SAP function modules An understanding of how to use the implicit enhancements of an SAP function module
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Explain the Integration of BAdIs into the Enhancement Framework
New BAdI Technology
Figure 78: Overview — Changing the SAP Standard
106
© Copyright. All rights reserved.
Lesson: Describing the Change from Classic BAdIs to New BAdIs
As of SAP NetWeaver 7.0, SAP intends to use the new BAdI technology to provide future enhancements. Classic BAdIs, discussed earlier in the course, have existed since SAP R/3 4.6 and provide a modern enhancement technology. Reasons Why SAP Introduced New BAdI Technology ●
To improve performance.
●
To implement additional functions -
-
●
Enhanced filter concept Option to inherit attributes from sample implementation classes (selective method redefinition)
To integrate into the new Enhancement Framework (together with enhancement points and enhancement sections)
The Enhancement Framework available as of SAP NetWeaver 7.0 manages new BAdIs, together with enhancement options, points, and sections. Overview of BAdIs in the Enhancement Framework
Figure 79: Overview of BAdIs in the Enhancement Framework
Unlike classic BAdIs, new BAdIs always belong to, and are managed by, enhancement spots. Although SAP will only create new BAdIs going forward, there are still enhancements provided by classic BAdIs.
© Copyright. All rights reserved.
107
Unit 5: New Business Add-Ins
Comparison of Classic BAdIs with New BAdIs
Figure 80: Comparison of Classic BAdIs with New BAdIs
The new BAdI concept takes advantage of SAP's extensive experience in offering customers different ways to enhance the standard SAP system. New BAdIs offer some major improvements over classic BAdIs such as better performance. The new BAdIs are integrated in the kernel and are switchable. The move from the classic to new BAdI technology had the following main goals: ●
●
BAdI performance is considerably enhanced by integrating BAdIs in the ABAP programming language through the new language elements GET BADI and CALL BADI. New BAdIs provide considerably more flexibility in the conversion of predefined enhancement options through new properties such as contexts and more filtering options than classic BAdIs. The new ABAP language elements and their additions ensure that these additional options can be easily used in ABAP programs.
LESSON SUMMARY You should now be able to: ●
108
Explain the Integration of BAdIs into the Enhancement Framework
© Copyright. All rights reserved.
Unit 5 Lesson 2 Using New Business Add-In (BAdI) Program Exits
LESSON OVERVIEW This lesson describes the implementation and use of new Business Add-In (BAdI) program exits. Business Example As a developer, you need to understand the architecture and the syntax of the new BAdI program exits so that you can implement them. For this reason you require the following knowledge: ●
An understanding of the architecture of new BAdI program exits
●
An understanding of the new BAdI program exit syntax
●
An understanding of how to search for new BAdI program exits
●
An understanding of how to implement new BAdI program exits
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Implement New BAdI Program Exits
© Copyright. All rights reserved.
109
Unit 5: New Business Add-Ins
Architecture of New BAdI Program Exits
Figure 81: New BAdI Program Exits – Architecture
The figure shows the architecture of a program exit that is provided using the new BAdI technology. The new BAdI technology works in a similar way to classic BAdIs. However, BAdI adapter classes are no longer created, which means the SAP application program does not need to instantiate them. Instead, at program runtime, the system generates a BAdI handle in the kernel, which performs the same function as the adapter class and calls the available implementation methods more efficiently.
110
© Copyright. All rights reserved.
Lesson: Using New Business Add-In (BAdI) Program Exits
New BAdI Program Exit Call Syntax
Figure 82: New BAdI Program Exit – Call Syntax in the SAP Program
The figure shows the syntax in an SAP program which calls a new BAdI. In contrast to the classic BAdI technology, the reference variable is typed directly to the BAdI, rather than the BAdI interface. The SAP program generates the BAdI handle using the GET BADI statement. If no active implementation of the BAdI is found, the cx_badi_not_implemented exception is triggered. The SAP program branches to the relevant implementations when the bridging method is called (CALL BADI). If an initial handle reference is used for the CALL BADI statement (for example, because GET BADI was not successful), exception cx_badi_initial_reference is triggered. Knowing the syntax required in the SAP program allows you to perform a program-related search for new BAdIs. To perform a free search for BAdIs or enhancement spots (remember, new BAdIs always belong to an enhancement spot), use transaction SE84. To list BAdIs or enhancement spots for a specific application, use transaction SE81, followed by transaction SE84. To Search for New BAdI Program Exits To search for new BAdI program exits, perform the following steps: 1. Perform a global search in the program you wish to enhance for GET BADI or CALL BADI. 2. Double-click the reference variable used in the GET BADI or CALL BADI statement to navigate to the variable definition. 3. Double-click the BAdI name to navigate to the display for the corresponding enhancement spot.
© Copyright. All rights reserved.
111
Unit 5: New Business Add-Ins
Note: It may also be necessary to perform the search in any function modules and methods called in the SAP program. Alternatively, you can debug the SAP application, and set a Debugger breakpoint for the GET BADI statement. If the Debugger stops at the statement, you can then analyze the code and determine the reference variable and therefore the BAdI name.
Implementation of New BAdI Program Exits
Figure 83: Enhancement Spot with BAdI Definition
The figure shows you an enhancement spot with a (new) BAdI definition. To use a BAdI, you must create an enhancement implementation for the higher-level enhancement spot, and then you must create a BAdI implementation for each BAdI you want to use in the enhancement spot.
112
© Copyright. All rights reserved.
Lesson: Using New Business Add-In (BAdI) Program Exits
Enhancement Spot Implementation with BAdI Implementation
Figure 84: Enhancement Spot Implementation with BAdI Implementation
The figure shows you an enhancement spot implementation with a (new) BAdI implementation. Two Types of BAdI Implementation ●
A BAdI definition can be linked to a fallback class
●
A BAdI implementation can be defined as the default implementation
Behaviour at Runtime ●
All non-default implementations are executed.
●
The default implementation is only called if no other implementation is executed.
●
The fallback class is used if nothing has been executed.
To implement New BAdI Program Exits The steps to create a BAdI implementation are as follows: 1. Display the corresponding enhancement spot. 2. Choose Implement Enhancement Spot and create the enhancement implementation. 3. Specify a name for the enhancement implementation, the BAdI implementation, and the Implementing Class. (If there is a Sample Class for the BAdI, you can choose to inherit from it or copy it.) 4. In the Navigation area for the BadI, double-click implementing class, then, double-click the method(s) to implement or adjust them.
© Copyright. All rights reserved.
113
Unit 5: New Business Add-Ins
5. Activate the method and all other related objects, including the enhancement implementation.
Filter-Dependent BAdIs
Figure 85: Filter-Dependent BAdIs
The figure illustrates the concept of filter-dependent BAdIs. As described in an earlier lesson, some classic BAdIs were filter-dependent, but the functionality has been enhanced in new BAdIs. Filter-dependent BAdIs now allow the following: Numeric filters
●
●
●
114
Implementations with not only single filter values, but also filter conditions using the operators <>, >, <. >=, <=, CP and NP Multiple filters for one BAdI implementation
© Copyright. All rights reserved.
Unit 5 Exercise 5 Implement New BAdI Program Exits
Business Example You have been asked to make changes to an SAP standard program. You want to search in the program to determine if there is a new BAdI program exit you can implement to enhance the code. 1. You want to add additional columns to the list output of SAP program BC425_##_NBD_PX (where ## stands for your group number) without making modifications. Find out if the SAP program contains a new BAdI program exit for this purpose. 2. If applicable, use the BAdI program exit that you found to add any additional columns of your choice to the program output. Name the components as follows: ●
Enhancement implementation (spot implementation) as ZBC425_##_PXBADI_SPOT
●
BAdI implementation as ZBC425_##_NBD_PX
●
Implementation class as ZCL_BC425_##_NBD_PX
© Copyright. All rights reserved.
115
Unit 5 Solution 5 Implement New BAdI Program Exits
Business Example You have been asked to make changes to an SAP standard program. You want to search in the program to determine if there is a new BAdI program exit you can implement to enhance the code. 1. You want to add additional columns to the list output of SAP program BC425_##_NBD_PX (where ## stands for your group number) without making modifications. Find out if the SAP program contains a new BAdI program exit for this purpose. a) Open program BC425_##_NBD_PX in the Object Navigator (transaction SE80). b) Perform a global search in the program for GET BADI and CALL BADI. c) Double-click the reference variable in either of these statements (R_EXIT) to navigate to the variable definition. d) Double-click the BAdI name which is used to type the reference variable (here BC425_##_PX_BADI) to navigate to the display for the corresponding enhancement spot. 2. If applicable, use the BAdI program exit that you found to add any additional columns of your choice to the program output. Name the components as follows: ●
Enhancement implementation (spot implementation) as ZBC425_##_PXBADI_SPOT
●
BAdI implementation as ZBC425_##_NBD_PX
●
Implementation class as ZCL_BC425_##_NBD_PX
a) Choose Implement Enhancement Spot (F6). b) In the Create Enhancement Implementation dialog box, enter ZBC425_##_PXBADI_SPOT in the Enhancement Implementation field, and also enter a short description, then choose Enter. c) When prompted, assign to your package ZBC425_## and your transport request. d) In the Create BAdI Implementation dialog box, enter ZBC425_##_NBD_PX in the BAdI Implementation field, enter a short description, enter ZCL_BC425_##_NBD_PX in the Implementing Class field, and enter BC425_##_PX_BADI in the BAdI Definition field, then choose Continue. e) In the Create Implementation Class dialog box, select the example class CL_EXAMPLE_BC425_##_PX_BADI, then choose Copy Sample Class. f) Assign to your package and your transport request.
116
© Copyright. All rights reserved.
Lesson: Using New Business Add-In (BAdI) Program Exits
g) Choose the arrow under your BAdI implementation name to expand, and then doubleclick on Implementing Class. h) Double-click on the method IF_EX_BC425_##_PX_BADI~WRITE_ADDITIONAL_COLS to open the Editor. i) As you copied the sample class, there will already be the code below inside the method, but if you would like to change it (for example to output different fields), you can enter your code now. METHOD if_ex_bc425_##_px_badi~write_additional_cols. WRITE: i_wa_spfli-distance, i_wa_spfli-distid. ENDMETHOD. j) Activate the method, and then your Enhancement Implementation. k) Return to the program BC425_##_NBD_PX and test it. l) Verify that the additional columns are displayed in the output.
© Copyright. All rights reserved.
117
Unit 5: New Business Add-Ins
LESSON SUMMARY You should now be able to: ●
118
Implement New BAdI Program Exits
© Copyright. All rights reserved.
Unit 5 Lesson 3 Using New Business Add-In (BAdI) Menu Exits
LESSON OVERVIEW This lesson describes the implementation and use of new Business Add-In (BAdI) menu exits. Business Example As a developer, you need to understand the architecture and the syntax of the new BAdI menu exits so you can implement them to add new menu entries to SAP standard menus. For this reason, you require the following knowledge: ●
An understanding of the principle and architecture of BAdI menu exits
●
An understanding of the syntax of BAdI menu exits
●
An understanding of how to find and implement a new BAdI menu exit
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Implement New BAdI Menu Exits
Architecture of New BAdI Menu Exits
Figure 86: BAdI Menu Exits – Principle
© Copyright. All rights reserved.
119
Unit 5: New Business Add-Ins
The figure shows the principle of a menu exit that has been provided by SAP using the new BAdI technology. Exits of this type can have only one active implementation. Menu exits provide customers with the option to implement additional menu entries on SAP screens, which trigger custom code. Architecture and Details of New BAdI Menu Exits
Figure 87: New BAdI Menu Exits – Architecture and Details
In the relevant GUI status the developer of the SAP screen prepares a menu option, which is not yet visible, with a special function code — always begins with a + (plus sign).You will also find a BAdI program exit related to this function code in the Process After Input (PAI) flow logic of the screen in question, the program exit can be used to implement the logic linked to the menu option. When a customer implements a BAdI of this type, they do not just specify the text for the additional menu option. They must also implement the BAdI program exit with the coding that will be executed when the user chooses the menu entry. When the BAdI menu exit is implemented, and the implementation has been activated, the entry in the SAP menu is activated and will be visible. If the user chooses the menu entry, the custom logic is processed.
120
© Copyright. All rights reserved.
Lesson: Using New Business Add-In (BAdI) Menu Exits
New BAdI Menu Exit Call Syntax
Figure 88: New BAdI Menu Exit Call Syntax
The figure shows the call syntax in the corresponding SAP program. It is identical to the call syntax for program exits. Here, the call will specifically be in a PAI module and will be executed when the user choose the special function code that represents the menu exit (starting with a + sign).
© Copyright. All rights reserved.
121
Unit 5: New Business Add-Ins
Implementation of New BAdI Menu Exits
Figure 89: BAdI Menu Exits – Implementation
The figure shows an example of a BAdI menu exit implementation. The menu text that the user sees in the menu has been maintained. The implementation of the program exit can also be maintained under Implementing Class, as with an ordinary new BAdI program exit.
122
© Copyright. All rights reserved.
Unit 5 Exercise 6 Implement a New BAdI Menu Exit
Business Example As a developer, you have been asked to make changes to a menu on an SAP standard screen. You want to search in the program to determine if there is a BAdI menu exit you can implement to provide an extra entry in the menu, which when chosen by the user will jump to a program displaying the flight bookings of the chosen customer. 1. The SAP program BC425_##_NBD_MX (where ## stands for the group number) shows the required customer master record on a screen after you enter a customer ID. From the customer display screen, you want to provide an additional menu entry to list the flight bookings of the customer. Find out if a BAdI menu exit exists for this menu entry. 2. If applicable, use the menu exit that you found to call the BC425_CUSTOMER_BOOKINGS program to display the relevant flight bookings of the displayed customer chosen on the selection screen. This program has a selection screen parameter named CUSTOMID which can be filled with a customer ID, and which will be used to determine the list of bookings. Name the components as follows: ●
Enhancement implementation (spot implementation) as ZBC425_##_MXBADI_SPOT
●
BAdI implementation as ZBC425_##_NBD_MX
●
Implementation class as ZCL_BC425_##_NBD_MX
© Copyright. All rights reserved.
123
Unit 5 Solution 6 Implement a New BAdI Menu Exit
Business Example As a developer, you have been asked to make changes to a menu on an SAP standard screen. You want to search in the program to determine if there is a BAdI menu exit you can implement to provide an extra entry in the menu, which when chosen by the user will jump to a program displaying the flight bookings of the chosen customer. 1. The SAP program BC425_##_NBD_MX (where ## stands for the group number) shows the required customer master record on a screen after you enter a customer ID. From the customer display screen, you want to provide an additional menu entry to list the flight bookings of the customer. Find out if a BAdI menu exit exists for this menu entry. a) In transaction SE80, open program BC425_##_NBD_MX. b) To check whether any menus have a menu exit, in the Object Name area, expand the GUI Status folder. c) Double-click the GUI Status used in the program (named S_100) to open it. d) Expand the Menu Bar screen area. e) Double-click each menu until you find an entry starting with +. There should be an entry +EXT in the Goto menu. f) Choose
(Previous Object) return to the ABAP source code.
g) Choose
(Find).
h) In the Find/replace dialog box, in the Find field, enter CALL BADI. i) Select the In main program radio button, then choose Continue to start the search. One occurrence of the CALL BADI statement is found. j) In the results list, double-click the CALL BADI statement to navigate to the code. It is used in the PAI module USER_COMMAND_0100, when the function code chosen by the user is +EXT. This is the program exit which is used with the menu exit. k) In the CALL BADI command, double-click the specified reference variable r_exit to navigate to its definition. l) Double-click the BAdI name BC425_##_MX_BADI used for the type assignment to navigate to the display of the corresponding enhancement spot to which the BAdI belongs. 2. If applicable, use the menu exit that you found to call the BC425_CUSTOMER_BOOKINGS program to display the relevant flight bookings of the displayed customer chosen on the selection screen. This program has a selection screen parameter named CUSTOMID which can be filled with a customer ID, and which will be used to determine the list of bookings.
124
© Copyright. All rights reserved.
Lesson: Using New Business Add-In (BAdI) Menu Exits
Name the components as follows: ●
Enhancement implementation (spot implementation) as ZBC425_##_MXBADI_SPOT
●
BAdI implementation as ZBC425_##_NBD_MX
●
Implementation class as ZCL_BC425_##_NBD_MX
a) Choose Create BAdI Implementation. b) In the Create Enhancement Implementation dialog box, enter ZBC425_##_MXBADI_SPOT as the implementation name, and a suitable description, then choose Creation of Enhancement. c) Assign your implementation to your package and transport request. d) In the Create BAdI Implementation dialog box, enter ZBC425_##_NBD_MX as the BAdI Implementation name, a suitable description, and then ZCL_BC425_##_NBD_MX as the name of the implementing class, then choose Continue. e) Assign your implementation to your package and transport request. f) Expand the node for the BAdI implementation. g) Double-click Menu Enhancements. h) Ensure you are in edit mode, then enter Display Customer Bookings in the Function Text field. i) Double-click Implementing Class. j) Double-click method IF_EX_BC425_##_MX_BADI~SHOW_ADDITIONAL_CUSTOMER_DATA. k) Choose Yes to save the enhancement. l) Choose
(Display<->Change).
m) Add the following code: SUBMIT BC425_CUSTOMER_BOOKINGS WITH customid = im_customid AND RETURN. n) Choose
(Activate) to activate the method implementation.
o) In the Inactive Objects dialog box, choose
(Select All)
p) Choose Continue. q) Choose
(Previous Object).
r) Choose
(Activate) to activate the enhancement implementation.
s) Return to transaction SE80 and test the program again by choosing Processing) (or F8)
(Direct
t) Use the input help on the selection screen to choose a customer, then choose Execute. u) Verify that the new menu entry is available under the Goto menu, and that the customer bookings are displayed when this option is chosen.
© Copyright. All rights reserved.
125
Unit 5: New Business Add-Ins
LESSON SUMMARY You should now be able to: ●
126
Implement New BAdI Menu Exits
© Copyright. All rights reserved.
Unit 5 Lesson 4 Using New Business Add-In (BAdI) Screen Exits
LESSON OVERVIEW This lesson describes the implementation and use of new Business Add-In (BAdI) screen exits. Business Example As a developer, you need to understand the architecture and the syntax of new BAdI screen exits, so you can add more fields to an SAP standard screen. For this reason, you require the following knowledge: ●
An understanding of the principle, architecture, and syntax of BAdI screen exits
●
An understanding of how to implement new BAdI screen exits
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Implement New BAdI Screen Exits
Architecture and Syntax of New BAdI Screen Exits
Figure 90: New BAdI Screen Exits – Principle
© Copyright. All rights reserved.
127
Unit 5: New Business Add-Ins
The figure shows the principle of a screen exit that SAP created using the new BAdI technology. Similar to menu exits, there can be only one active implementation of a screen exit. Screen exits provide customers with the option to display additional fields or other screen elements on an SAP screen, without making modifications. For example, you can use screen exits to display fields from a customer Append structure, relating to the data already displayed on the screen. The SAP screen developer reserves a subscreen area into which a customer subscreen can be embedded. The customer subscreen must be defined in a customer function group and it must contain the additional fields to be displayed. In the corresponding customer implementation of the BAdI, the reference to the subscreen is specified and this subscreen is determined and used in the PBO (Process Before Output) of the SAP screen. New BAdI Screen Exits – Architecture and Call Syntax
Figure 91: New BAdI Screen Exits – Architecture and Call Syntax
To ensure that the customer subscreen displays the correct data, the data is transferred in the PBO of the SAP screen (by calling the corresponding bridging method) to the customer's implementation of the BAdI method. This implementation of the BAdI method must ensure the transfer of the data to the global data of the function group, which in turn is used to provide the data for the subscreen fields. Therefore, in the customer function group, in addition to the subscreen itself, it is necessary to create a corresponding TABLES structure (in the TOP Include) for the data exchange, and a corresponding function module that will be called in the customer implementation of the BAdI method. If the screen has input fields (that is, it allows the user to change data), you must implement another BAdI method in such a way that it calls another function module of the customer function group. This allows the BAdI method to obtain data transferred from the subscreen to the TABLES structure, and export it to the caller of the method. The SAP program calls this
128
© Copyright. All rights reserved.
Lesson: Using New Business Add-In (BAdI) Screen Exits
BAdI method in the PAI flow logic of its screen (using the bridging method) to receive the data from the subscreen and process it.
Implementation of New BAdI Screen Exits
Figure 92: New BAdI Screen Exits – Implementation
The figure shows an implementation of a new BAdI screen exit. To Search for and Use BAdI Screen Exits 1. On the SAP standard screen, search for a subscreen area (optional pre-search). 2. In the SAP standard program, search for the GET BADI command. You will also find the method GET_PROG_AND_DYNP_FOR_SUBSCR of class CL_ENH_BADI_RUNTIME_FUNCTIONS, which tells you that there is a BAdI screen exit available. 3. Double-click the reference variable used in the GET BADI statement to navigate to the definition of the reference variable. 4. To navigate to the enhancement spot to which the BAdI belongs, double-click the BAdI used to type the reference variable. 5. Read the BAdI documentation and perform the subsequent steps for the BAdI implementation. 6. Create the function group, including the subscreen, the TABLES structure (in the TOP include), and the corresponding function modules. 7. Create an implementation for the enhancement spot and for the BAdI. 8. In the BAdI implementation, implement the available program exits (the PUT and GET methods).
© Copyright. All rights reserved.
129
Unit 5: New Business Add-Ins
9. In the BAdI implementation, double-click the available screen exit to implement it. 10. Specify the subscreen and the main program of the function group. The name of the main program is the name of the function group with the prefix SAPL. 11. Activate all objects.
130
© Copyright. All rights reserved.
Unit 5 Exercise 7 Implement New BAdI Screen Exits
Business Example You have been asked to make changes to an SAP standard screen. You want to search in the program to determine if there is a BAdI screen exit you can implement to add extra fields to this screen. 1. After the user chooses an airline carrier on the initial screen, SAP program BC425_##_NBD_SX (where ## stands for your group number) shows details of the specified airline on a second screen. You also want to display the local currency of the airline there. Find out if a BAdI screen exit exists for this purpose. 2. Create an enhancement implementation for the BAdI you found in step 1. Make the necessary settings to display the field SCARR-CURRCODE, with the correct data, underneath the existing fields on the second screen of the transaction. Name your components as follows: ●
Enhancement implementation (spot implementation) as ZBC425_##_SXBADI_SPOT
●
BAdI implementation as ZBC425_##_NBD_SX
●
Implementation class as ZCL_BC425_##_NBD_SX
●
Function Group for subscreen as ZSCREEN_EXIT_##
3. Once you have created the enhancement implementation, test the program again to verify the changes.
© Copyright. All rights reserved.
131
Unit 5 Solution 7 Implement New BAdI Screen Exits
Business Example You have been asked to make changes to an SAP standard screen. You want to search in the program to determine if there is a BAdI screen exit you can implement to add extra fields to this screen. 1. After the user chooses an airline carrier on the initial screen, SAP program BC425_##_NBD_SX (where ## stands for your group number) shows details of the specified airline on a second screen. You also want to display the local currency of the airline there. Find out if a BAdI screen exit exists for this purpose. a) In transaction SE80, open program BC425_##_NBD_SX. b) In the Object Name panel, expand the Screen folder. c) Double-click screen 0100 to open it in the Screen Painter. d) On the SAP standard screen, search for a subscreen area by choosing the Element list tab page. You will see that there is a subscreen area on the screen called SUB. e) Choose
(Previous Object) to return to the ABAP program.
f) Choose
(Find).
g) In the Find field, enter GET_PROG_AND_DYNP_FOR_SUBSCR. h) Select the In main program radio button. i) Choose Continue to start the search. j) Double-click on the result to navigate to the statement. Finding this indicates that there is a BAdI screen exit available. k) Repeat the above steps to search for the statement GET BADI. l) To navigate to the enhancement spot to which the BAdI belongs, double-click the BAdI bc425_##_sx_badi which is used to type the reference variable. m) Choose BAdI-Dokumentation to read the BAdI documentation 2. Create an enhancement implementation for the BAdI you found in step 1. Make the necessary settings to display the field SCARR-CURRCODE, with the correct data, underneath the existing fields on the second screen of the transaction. Name your components as follows: ●
132
Enhancement implementation (spot implementation) as ZBC425_##_SXBADI_SPOT
© Copyright. All rights reserved.
Lesson: Using New Business Add-In (BAdI) Screen Exits
●
BAdI implementation as ZBC425_##_NBD_SX
●
Implementation class as ZCL_BC425_##_NBD_SX
●
Function Group for subscreen as ZSCREEN_EXIT_##
a) On the Attributes tab page, choose
(Create BAdI Implementation).
b) In the Create Enhancement Implementation dialog box, in the Enhancement Name field, enter ZBC425_##_SXBADI_SPOT. c) In the Short Text field, enter a suitable description, then choose Enhancement).
(Creation of
d) Assign the implementation to your package and transport request. e) In the Create BAdI Implementation dialog box, enter the following information: Field
Value
BAdI Implementation
ZBC425_##_NBD_SX
Description
Add a suitable description.
Implementing Class
ZCL_BC425_##_NBD_SX
f) Choose Continue. g) Assign the BAdI implementation to your package and transport request. h) In a separate session, open transaction SE80 and choose Function Group from the dropdown list. i) Enter the function group nameZSCREEN_EXIT_## in the field underneath, and press ENTER to create the function group. j) In the Create Function Group dialog box, choose Yes. k) In the Create Function Group dialog box, in the Short text field, enter a suitable description for the function group, then choose Save. l) Assign the function group to your package and transport request. m) Right-click on the function group and choose Create → Screen. n) In the Create Screen dialog box, in the Screen number field, enter 900 , then choose Continue. The Screen Painter opens. o) On the Attributes tab page , enter a suitable short description, then select the Subscreen radio button. p) On the toolbar, choose Layout. The Graphical Screen Painter opens. q) Choose (Dictionary / Program Fields Window). r) In the Screen Painter: Dict./Program Fields dialog box, in the Table/Field Name field, enter SCARR then choose Get from Dictionary.
© Copyright. All rights reserved.
133
Unit 5: New Business Add-Ins
s) Select the entry for SCARR-CURRCODE, then choose Continue. t) Position the field to the top left-hand corner of the screen, then use your left mousebutton to drop it. u) Choose Flow Logic to return to the screen painter and close the Graphical Screen Painter. v) In the Object Name area, expand the Includes folder. w) Double-click LZBC425_SX_FGTOP to open the TOP include program. x) In the Exit Screen Painter dialog box, choose Yes. y) Add the following code under the FUNCTION-POOL statement: TABLES scarr. z) Right-click on the function group and choose Create → Function Module. aa) In the Exit Editor dialog box, choose Yes. ab) In the Create Function Module dialog box, in the Function Module name field, enter Z_BC425_PUT_DATA_## and in the Short Text field, enter a suitable description. ac) Choose Save. The Function Builder opens. ad) On the Import tab page, create a parameter with the following values: Parameter
Typing
Associated Type
IM_SCARR
TYPE
SCARR
ae) Open the Source code tab page and enter the following code: FUNCTION Z_BC425_PUT_DATA_##. *"------------------------------------------------------------------*"*"Local Interface: *" IMPORTING *" REFERENCE(IM_SCARR) TYPE SCARR *"------------------------------------------------------------------scarr = im_scarr. ENDFUNCTION. af) Choose
(Activate).
ag) In the Inactive Objects dialog box, choose
(Select All).
ah) Choose Continue. The function group is created. ai) Now you have created the function group, switch back to the other session where you created the BAdI implementation. aj) In the BAdI implementations area, expand the node, then double-click Implementing Class. ak) Double-click the method that is displayed to the right to implement the code.
134
© Copyright. All rights reserved.
Lesson: Using New Business Add-In (BAdI) Screen Exits
al) In the Create Method Implementation dialog box, choose Yes. am) Choose
(Display<->Change).
an) Enter the following code: Implementation of BAdI method PUT_DATA: method IF_EX_BC425_##_SX_BADI~PUT_DATA. CALL FUNCTION 'Z_BC425_PUT_DATA_##' EXPORTING IM_SCARR = im_wa_scarr. endmethod. ao) Choose
(Activate).
ap) In the Inactive Objects dialog box, choose Continue. aq) Choose
(Previous Object) to return the BAdI implementation.
ar) Double-click Screen Enhancements. as) Choose
(Display<->Change).
at) In the Program field, enter SAPLZSCREEN_EXIT_##. au) In the Subscreen field, enter 900. av) Choose aw) Choose
(Activate) to activate the enhancement implementation. (Back) twice to return to the ABAP program.
3. Once you have created the enhancement implementation, test the program again to verify the changes. a) Choose
(Direct Processing) to execute the program.
b) On the selection screen, choose an airline carrier, then choose Execute. The carrier details are displayed, along with the additional field added using the screen exit.
© Copyright. All rights reserved.
135
Unit 5: New Business Add-Ins
LESSON SUMMARY You should now be able to: ●
136
Implement New BAdI Screen Exits
© Copyright. All rights reserved.
Unit 5 Lesson 5 Using New Business Add-Ins (BAdIs)
LESSON OVERVIEW In this lesson, you will learn how to define a new Business Add-In (BAdI). LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Define New BAdIs
Definition of New BAdIs
Figure 93: Defining an Enhancement Spot for a New BAdI
To define a new BAdI, the BAdI Builder, transaction SE18 , is used ( Tools → ABAP Workbench → Utilities → Business Add-Ins → Definition ). New BAdI's are managed in enhancement spots, so before you can create a new BAdI you must first create an enhancement spot.
© Copyright. All rights reserved.
137
Unit 5: New Business Add-Ins
Defining New BAdIs
Figure 94: Defining New BAdIs
As a next step, you create the BAdI definition inside the Enhancement Spot. Defining the BAdI Interface
Figure 95: Defining the BAdI Interface
Double-click Interface on the left of the screen to define the BAdI Interface. When you do this, you enter the name you wish to give to your interface on the right of the screen, and then select Change to navigate to the Class Builder. Once in the Class Builder, you must define the interface methods with their signature.
138
© Copyright. All rights reserved.
Lesson: Using New Business Add-Ins (BAdIs)
Syntax of a New BAdI Call
Figure 96: Syntax in Program
Activate the interface, then return to the BAdI Builder and activate the Enhancement Spot. The next step is to define the “jump points” in the coding of your application program. To obtain the BAdI handle the statement GET BADI should be used. To call the BAdI implementation(s), use the CALL BADI statement. The BAdI reference must be defined using a DATA statement TYPE REF TO . Creating BAdI Subobjects
Figure 97: Creating BAdI Subobjects
BAdI's with filters, menu exits or screen exits have additional settings which must be made. A filter consists of a filter name and a data type (for example, integer (type i) or string)
© Copyright. All rights reserved.
139
Unit 5: New Business Add-Ins
If the BAdI is to provide a menu exit, it must not have any filters, must not be defined for multiple use, and must not be assigned to a switch. It may contain methods that are independent of the actual menu exit. If a BAdI is to provide a screen exit, it must have an Instance Creation Mode of ‘Reusing Instantiation’, cannot be defined for multiple use. It can contain BAdI methods that can be used to fill or evaluate the screen fields of the respective subscreens. Other properties that can be assigned to a BAdI include an optional fallback BAdI implementation class. This option is used if no BAdI implementation with suitable filter conditions and no standard implementation is found. Instance Creation Mode – Newly Creating Instantiation
Figure 98: Instance Creation Mode – Newly Creating Instantiation
One property of BAdIs which is worth analyzing further is the Instance Creation mode. This property controls the instantiation of the object plug-ins during execution of the statement GET BADI. Choosing the correct setting can hugely improve performance. The option Newly Creating Instantiation means that for each BAdI handle a new instance of the implementing class is generated.
140
© Copyright. All rights reserved.
Lesson: Using New Business Add-Ins (BAdIs)
Instance Creation Mode – Reusing Instantiation
Figure 99: Instance Creation Mode – Reusing Instantiation
An instance creation mode of ‘Reusing Instantiation’ means that an existing instance of the BAdI implementation class is used again (within the same internal session). Instance Creation Mode – Context-Specific Instantiation
Figure 100: Instance Creation Mode – Context-Specific Instantiation
The final option, Context-Specific Instantiation, means that at runtime, for an instance of a ‘Context class’, the same instance of the implementation class will always be used. This means that with context-dependent BAdIs, you must define an object reference variable for an instance of the Context class. The Context class can be any class which includes the interface IF_BADI_CONTEXT. In the GET BADI statement, the CONTEXT addition is used and the reference to the BAdI context object must be supplied. Within one internal session, only one object plug-in is
© Copyright. All rights reserved.
141
Unit 5: New Business Add-Ins
created for each context and implementing class. Each time there is another GET BADI with the same context, it is reused. As a result, within an internal session for the same BAdI context object, the same object plugins are always used. Such object plug-ins are singletons as far as their BAdI implementation class and a BAdI context object are concerned.
Note: The Method cl_badi_report_context=>get_instance can be used as a generic context generator. Use of a Context-Dependent BAdI The following example illustrates the use of a context-dependent BAdI badi_ctx_badi: DATA: bd TYPE REF TO badi_ctx_badi, ctx TYPE REF TO cl_badi_report_context. ctx = cl_badi_report=>get_instance( repid = sy-repid ). GET BADI bd CONTEXT ctx. The reference variable ctx references an instance of the context class that is unique for the current program. In this context a BAdI object is requested. If the same code fragment is executed in other programs in the same internal session, different instances of the BAdI implementation classes are always associated with the BAdI object. The class cl_badi_report_context allows you to bind object plug-ins to compilation units. The methods of these object plug-ins can be called anywhere in the internal session by using the combinations of GET BADI and CALL BADI shown above. The state is kept in this connection, which means that the same instances are always called for the same compilation units.
142
© Copyright. All rights reserved.
Unit 5 Exercise 8 Define a New BAdI
Business Example You want to define enhancements in your own programs for downstream software layers. You have already created a program which displays a list of flight connections, but now you want to provide a Business Add-In to allow customers to enhance the program in such a way that when a row in the list is double-clicked, an additional detail list can be displayed. You would also like to create a default implementation which will be used if the customer does not create their own Template Program SAPBC425_BADI_TEMPLATE 1. Copy the Program SAPBC425_BADI_TEMPLATE to a program named ZBC425_BADI_## (where ## is your group number). Assign your program to your package and transport request 2. Create an enhancement spot named ZBC425_ES_##, and then define a new BAdI named ZBC425_NB_## (where ## is your group number).. 3. Create an interface ZIF_BC425_INT _ ## with one method named FLIGHT_ADD_DATA. The method should contain the parameters in the table. Table 4: Parameter
Type
Typing
Associated Type
is_spfli
IMPORTING
TYPE
SPFLI
ir_grid
IMPORTING
TYPE REF TO
CL_GUI_ALV_GRID
The IS_SPFLI parameter allows the flight connection information to be passed to the method, and the IR_GRID parameter is for the reference to the ALV grid. Once created, the interface should be assigned to your BAdI definition. 4. Change the program to allow a detail list to display a BAdI implementation to be executed when a user double-clicks a line in the ALV grid. To do this, add the GET BADI statement to obtain the BAdI Handle, and then the CALL BADI statement to call the method FLIGHT_ADD_DATA. 5. Create a default implementation for the BAdI, using ZENH_DFLT_## as the name for the enhancement spot implementation, and ZBADI_DFLT_## for the BAdI implementation. Name the class ZCL_BC425_DFLT_##. Implement the method FLIGHT_ADD_DATA so that data is read from database table SCARR for the carrier of the connection the user double-clicked, and displayed in the ALV grid. (Replace ## with your group number.)
© Copyright. All rights reserved.
143
Unit 5: New Business Add-Ins
Note: There will be only one row in the ALV grid for the default implementation. 6. Define another enhancement spot implementation ZENH_## , with BAdI implementation ZBADI_## and a class named ZCL_BC425 _##. In this implementation, the flights for the chosen connection should be output in the ALV grid (retrieved from database table SFLIGHT##), overriding the default implementation.
144
© Copyright. All rights reserved.
Unit 5 Solution 8 Define a New BAdI
Business Example You want to define enhancements in your own programs for downstream software layers. You have already created a program which displays a list of flight connections, but now you want to provide a Business Add-In to allow customers to enhance the program in such a way that when a row in the list is double-clicked, an additional detail list can be displayed. You would also like to create a default implementation which will be used if the customer does not create their own Template Program SAPBC425_BADI_TEMPLATE 1. Copy the Program SAPBC425_BADI_TEMPLATE to a program named ZBC425_BADI_## (where ## is your group number). Assign your program to your package and transport request a) Open transaction SE80. b) Select Program from the list and enter the original program name: SAPBC425_BADI_TEMPLATE. c) Press ENTER. d) In the Object Name screen area, right-click the program name and choose Copy. e) In the Copy Program SAPBC425_BADI_TEMPLATE dialog box, in the Target program field, enter the name of the new program: ZBC425_BADI_##. f) Choose Copy. g) In the Copy Program SAPBC425_BADI_TEMPLATE to ZBC425_BADI_## dialog box, you are asked what parts of the program you want to copy. Choose (Select all). h) Choose Copy. i) Assign the program to your package and transport request. 2. Create an enhancement spot named ZBC425_ES_##, and then define a new BAdI named ZBC425_NB_## (where ## is your group number).. a) Go to transaction SE18. b) In the Enhancement Spot field, enter ZBC425_ES_## and choose Create. The Create Enhancement Spot dialog box will appear. c) In the Short Text field, enter a suitable description and choose Continue. d) Assign the Enhancement Spot to your package and transport request.
© Copyright. All rights reserved.
145
Unit 5: New Business Add-Ins
e) Open the Enh. Spot Element Definitions tab page and choose The Create BAdI Definition dialog appears.
(Create BAdI).
f) Enter the new BAdI name ZBC425_NB_## and a short description. Choose Enter. 3. Create an interface ZIF_BC425_INT _ ## with one method named FLIGHT_ADD_DATA. The method should contain the parameters in the table. Table 4: Parameter
Type
Typing
Associated Type
is_spfli
IMPORTING
TYPE
SPFLI
ir_grid
IMPORTING
TYPE REF TO
CL_GUI_ALV_GRID
The IS_SPFLI parameter allows the flight connection information to be passed to the method, and the IR_GRID parameter is for the reference to the ALV grid. Once created, the interface should be assigned to your BAdI definition. a) On the Enhancement Spot ZB425_ES_## Change screen, in the BAdI Definitions panel, expand the BAdI node. b) Double-click Interface. c) In the Interface field, enter ZIF_BC425_INT_## and press ENTER. d) Choose Activate. e) In the Inactive Objects dialog box, choose
(Select All).
f) In the Class/Interface ZB425_ES_## dialog box, choose Yes to create the interface. g) Assign the interface to your package and transport request. h) In the Edit Enhancement Spot dialog box, choose Yes to save the enhancement spot. i) On the Class Builder screen, in the Method column, enter FLIGHT_ADD_DATA. j) In the Level column, enter 0 (Instance Method). k) In the Description column, enter a short description. l) Put the cursor on the method name and choose Parameter. m) Enter the parameter using the data in the table. n) Press ENTER. o) Choose
(Activate).
p) Int he Inactive Objects dialog box, choose
(Select All).
q) Choose Continue. r) Choose Back three times to return to the BAdI Builder Initial Screen for Definitions screen. 4. Change the program to allow a detail list to display a BAdI implementation to be executed when a user double-clicks a line in the ALV grid. To do this, add the GET BADI statement to
146
© Copyright. All rights reserved.
Lesson: Using New Business Add-Ins (BAdIs)
obtain the BAdI Handle, and then the CALL BADI statement to call the method FLIGHT_ADD_DATA. a) In transaction SE80, open program ZBC425_BADI_##. b) Choose
(Find).
c) In the Find field, enter Data Definition. d) Select the In main program radio button. e) Choose Continue. f) In the global search results, double-click the result. g) In the Data Definition section of the program, you will see a comment *** << NEW CODING HERE: Define BAdI reference >>. h) Choose
(Display<->Change).
i) To define the reference variable for your BAdI, enter the following code: DATA: r_exit TYPE REF TO ZBC425_NB_##. j) Choose Save. k) Choose
(Find).
l) In the Find field, enter MODULE alv_grid. m) Select the In main program radio button. n) Choose Continue. o) In the global search results, double-click the result. p) In the PBO Module alv_grid section of the program, you will see a comment *** << NEW CODING HERE: Get BAdI Handle >>. . q) Choose
(Display<->Change).
r) To obtain the BAdI handle, enter the following code: TRY. GET BADI r_exit. CATCH cx_badi_not_implemented. ENDTRY. s) Choose Save. t) Choose
(Find).
u) In the Find field, enter CLASS lcl_event_handler IMPLEMENTATION.. v) Select the In main program radio button. w) Choose Continue. x) In the global search results, double-click the result. y) In the CLASS lcl_event_handler IMPLEMENTATION section of the program, you will see a comment *** << NEW CODING HERE: Call BAdI Method>>. .
© Copyright. All rights reserved.
147
Unit 5: New Business Add-Ins
z) Choose
(Display<->Change).
aa) To call the BAdI method, enter the following code: TRY.
CALL BADI r_exit->flight_add_data exporting is_spfli = gs_spfli ir_grid = gr_grid. CATCH cx_badi_initial_reference. ENDTRY. ab) Choose
(Activate).
ac) In the Inactive Objects dialog box, choose
(Select All).
ad) Choose Continue. 5. Create a default implementation for the BAdI, using ZENH_DFLT_## as the name for the enhancement spot implementation, and ZBADI_DFLT_## for the BAdI implementation. Name the class ZCL_BC425_DFLT_##. Implement the method FLIGHT_ADD_DATA so that data is read from database table SCARR for the carrier of the connection the user double-clicked, and displayed in the ALV grid. (Replace ## with your group number.) Note: There will be only one row in the ALV grid for the default implementation. a) Go to transaction SE18. b) The Enhancement Spot name should still be displayed, so choose Change. c) Open the Enhancem. Implementations tab page. d) On the toolbar at the top of the screen, choose
(Implement Enhancement Spot).
e) In the Create Enhancement Implementation dialog box, in the Enhancement Implementation field, enter ZENH_DFLT_##. f) In the Short Text field, enter a description and then choose Continue. g) Assign the implementation to your package and transport request. h) In the Create BAdI Implementation dialog box, enter the following information: BAdI Implementation
Implementation Class
BAdI Definition
ZENH_DFLT_##
ZCL_BC425_DFL_##
ZBC425_NB_##
i) Choose Continue. j) Assign the BAdI implementation to your package and transport request. The Enhancement Implementation screen appears. k) Select the Default Implementation checkbox. l) Expand the BAdI Implementation. m) Double-click Implementing Class. The default class appears with the interface method FLIGHT_ADD_DATA.
148
© Copyright. All rights reserved.
Lesson: Using New Business Add-Ins (BAdIs)
n) Double-click the method FLIGHT_ADD_DATA. o) On the Create Method Implementation dialog box, choose Yes. p) On the Edit Enhancement Implementation dialog box, choose Yes to save the Enhancement Implementation. The editor appears. q) Enter the following code: METHOD zif_bc425_##~FLIGHT_ADD_DATA. DATA: lt_scarr type table of scarr. SELECT * FROM SCARR INTO TABLE lt_scarr WHERE carrid = is_spfli-carrid. ir_grid->set_table_for_first_display( EXPORTING i_structure_name = 'SCARR' CHANGING it_outtab = lt_scarr ). ENDMETHOD. r) Choose
(Activate).
s) In the dialog box, choose
(Select All).
t) Choose Continue. u) Go back to the Enhancement Implementation screen. v) Go back to SE80. Choose (Direct Processing) to run program ZBC425_BADI_##. The default implementation is executed when you double-click on a row in the ALV. 6. Define another enhancement spot implementation ZENH_## , with BAdI implementation ZBADI_## and a class named ZCL_BC425 _##. In this implementation, the flights for the chosen connection should be output in the ALV grid (retrieved from database table SFLIGHT##), overriding the default implementation. a) Go to transaction SE18. Your Enhancement Spot name should still be displayed. b) From the menu, choose Enhancement Implementation → Create. c) In the Create Enhancement Implementation dialog box, in the Enhancem. Implementation field, enter ZENH_##. d) In the Short Text field, enter a suitable description. e) Choose Continue. f) Assign the implementation to your package and transport request. g) Enter ZBADI_## in the BAdI Implementation, ZCL_BC425_## in the Implementation Class, choose your BAdI definition and then choose Continue. Save it to your transport. The Enhancement Implementation screen will display. h) On the Enhancement Implementation screen, expand the arrow next to your BAdI Implementation to see the Implementing class. i) Double-click the Implementing class node. The class displays with the interface method FLIGHT_ADD_DATA.
© Copyright. All rights reserved.
149
Unit 5: New Business Add-Ins
j) Double-click FLIGHT_ADD_DATA. k) On the Create Method Implementation dialog box, choose Yes. l) On the Edit Enhancement Implementation dialog box, choose Yes to save the enhancement implementation. The FLIGHT_ADD_DATA method will display in the editor. m) Add the following code: METHOD ZIF_BC425_##~FLIGHT_ADD_DATA. DATA lt_sflight TYPE TABLE OF sflight##. SELECT * FROM sflight## INTO TABLE lt_sflight WHERE carrid = is_spfli-carrid AND connid = is_spfli-connid. ir_grid->set_table_for_first_display( EXPORTING i_structure_name = 'SFLIGHT' CHANGING it_outtab = lt_sflight ). ENDMETHOD. n) Choose
(Activate).
o) In the dialog box, choose
(Select All).
p) Choose Continue. q) Go back to the Enhancement Implementation screen. r) Go back to SE80. Choose (Direct Processing) to run program ZBC425_BADI_##. The new implementation is executed when you double-click on a row in the ALV.
150
© Copyright. All rights reserved.
Lesson: Using New Business Add-Ins (BAdIs)
LESSON SUMMARY You should now be able to: ●
Define New BAdIs
© Copyright. All rights reserved.
151
Unit 5: New Business Add-Ins
152
© Copyright. All rights reserved.
Unit 5 Learning Assessment
1. The new Business Add-In (BAdI) technology has been developed to ____________. Choose the correct answers. X
A Improve performance
X
B Implement additional functions
X
C Improve scalability
X
D Integrate into the new Enhancement Framework
2. New Business Add-Ins (BAdIs) always belong to enhancement spots and are managed by these spots. Determine whether this statement is true or false. X
True
X
False
3. For each Business Add-In (BAdI) that you want to use in an enhancement spot, you need to create a BAdI implementation. Determine whether this statement is true or false. X
True
X
False
4. Screen exits provide customers with the option to display additional fields or screen elements on an SAP screen. Determine whether this statement is true or false. X
True
X
False
© Copyright. All rights reserved.
153
Unit 5 Learning Assessment - Answers
1. The new Business Add-In (BAdI) technology has been developed to ____________. Choose the correct answers. X
A Improve performance
X
B Implement additional functions
X
C Improve scalability
X
D Integrate into the new Enhancement Framework
Correct. The new Business Add-In (BAdI) technology has been developed to improve performance, additional functions and to integrate into the new Enhancement Framework. 2. New Business Add-Ins (BAdIs) always belong to enhancement spots and are managed by these spots. Determine whether this statement is true or false. X
True
X
False
Correct. New Business Add-Ins (BAdI) always belong to the enhancement spots and are managed by these spots. 3. For each Business Add-In (BAdI) that you want to use in an enhancement spot, you need to create a BAdI implementation. Determine whether this statement is true or false. X
True
X
False
Correct. To use a BAdI, you must create an enhancement implementation that is an implementation of the higher-level enhancement spot. You must create a BAdI implementation for each BAdI you want to use in the enhancement spot.
154
© Copyright. All rights reserved.
Unit 5: Learning Assessment - Answers
4. Screen exits provide customers with the option to display additional fields or screen elements on an SAP screen. Determine whether this statement is true or false. X
True
X
False
Correct. Screen exits provide customers with the option to display additional fields or other screen elements on an SAP screen, without making modifications. For example, you can use the screen exits to display fields from a customer Append structure, relating to the data already displayed on the screen.
© Copyright. All rights reserved.
155
Unit 5: Learning Assessment - Answers
156
© Copyright. All rights reserved.
UNIT 6
Explicit Enhancement Options
Lesson 1 Describing the Enhancement Framework
158
Lesson 2 Using Explicit Enhancements Exercise 9: Use Explicit Enhancements
163 171
UNIT OBJECTIVES ●
Describe the enhancement options available in the Enhancement Framework
●
Describe Enhancement Spots
●
Use explicit enhancements
© Copyright. All rights reserved.
157
Unit 6 Lesson 1 Describing the Enhancement Framework
LESSON OVERVIEW This lesson describes the enhancement options, which are available in the Enhancement Framework and also describes the purpose of enhancement spots. Business Example You want to use the new enhancement options in the Enhancement Framework to enhance your SAP functions without making modifications. For this reason, you require the following knowledge: ●
An understanding of the enhancements available in the Enhancement Framework
●
An understanding of enhancement spots
●
An understanding of how to get information about an enhancement spot
LESSON OBJECTIVES After completing this lesson, you will be able to:
158
●
Describe the enhancement options available in the Enhancement Framework
●
Describe Enhancement Spots
© Copyright. All rights reserved.
Lesson: Describing the Enhancement Framework
Enhancements in the Enhancement Framework
Figure 101: Overview — Changing the SAP Standard
In SAP NetWeaver 7.0, some new enhancement techniques were provided through the Enhancement Framework: enhancement points, enhancement options and enhancement sections. Unlike earlier enhancement technologies, implicit enhancements do not require any preparation by SAP developers, they are implicitly available at certain places in SAP standard objects. The new Business Add-In (BAdI) technology was described in an earlier unit.
© Copyright. All rights reserved.
159
Unit 6: Explicit Enhancement Options
Explicit Enhancements as Part of the Enhancement Framework
Figure 102: Overview_of_BAdIs_in_the_Enhancement_Framework_Image.ppt
Explicit enhancements, like new BAdIs which were discussed in the previous unit, are managed using Enhancement Spots.
Enhancement Spots
Figure 103: Information on an Enhancement Spot
The figure illustrates how explicit enhancement points, explicit enhancement sections, and BAdIs that have been created using the new technology are grouped together and managed using enhancement spots.
160
© Copyright. All rights reserved.
Lesson: Describing the Enhancement Framework
Composite enhancement spots can comprise both simple enhancement spots and other composite enhancement spots. These spots serve to semantically bundle enhancements. Enhancement Spots and Enhancement Implementations
Figure 104: Enhancement Spots and Enhancement Implementations
This figure illustrates composite enhancement spots and composite enhancement implementations. SAP offers enhancement points and sections within enhancement spots. Enhancement spots can be combined by SAP into composite enhancement spots. This combination of enhancement spots into composite enhancement spots provides a better structure for the global search of enhancement spots. Customers can use enhancement points and sections by creating an enhancement implementation for the related enhancement spot. Normally, customers implement all enhancement points or sections of one enhancement spot in one enhancement implementation. The enhanced elements are numbered automatically. Customers also have the option to combine their enhancement implementations into a composite enhancement implementation. This combination of enhancement implementations into composite enhancement implementations makes it easier to find them later. However, you do not need to create composite enhancement implementations for composite enhancement spots.
To Search for an Enhancement Spot It is not possible to perform a global search for explicit enhancement points and sections; however, it is possible to search for the enhancement spots to which they belong. In general, the name of a spot that contains all of the explicit enhancements of a program is usually ES_. To search for an enhancement spot, perform the following steps: 1. Start the Repository Information System (transaction SE84). 2. Choose Enhancements → Enhancement Spots.
© Copyright. All rights reserved.
161
Unit 6: Explicit Enhancement Options
3. Specify the search criteria for the enhancement spots you are looking for and execute to display a list of results. (For example, you could search by package, or application component.) 4. Pick one of the results to display. You will see a list of enhancement points and sections of this spot. 5. On the Enhancement Implementations tab page, you can see any existing enhancement implementations of the spot. Choose the enhancement implementation that you want to display. 6. The result shows all enhancement implementation elements related to the enhancement implementation name. 7. Choose Source to see the implementation code at the bottom of the screen. Choose Editor to display the source code of the enhancement in-place in the program. Note: You can also use the enhancement browser (transaction SPAU_ENH) to show enhancement spots and their implementations. The functionality is the same as in the Repository Information System.
LESSON SUMMARY You should now be able to:
162
●
Describe the enhancement options available in the Enhancement Framework
●
Describe Enhancement Spots
© Copyright. All rights reserved.
Unit 6 Lesson 2 Using Explicit Enhancements
LESSON OVERVIEW This lesson provides an overview of explicit enhancement points and sections. Business Example As a developer you have noticed some explicit enhancement options and points in a standard program which you have been asked to change. You do not want to modify the program, and so you would like to know how to make use of the explicit enhancements available. For this reason, you require the following knowledge: 1. An understanding of explicit enhancement points and sections 2. An understanding of the risks of multiple implementations of explicit enhancement sections and points 3. How to use explicit enhancements LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Use explicit enhancements
Explicit Enhancement Points and Sections
Figure 105: Explicit Enhancement Points and Sections
The figure shows how to identify explicit enhancement points and enhancement sections in an SAP program. Explicit enhancement points are provided by SAP and allow you to enhance SAP source code by inserting your own logic, without making modifications. You can identify explicit enhancement points by searching for the ENHANCEMENT-POINT syntax. Enhancement
© Copyright. All rights reserved.
163
Unit 6: Explicit Enhancement Options
points can either be static (to allow additional data declarations) or dynamic (to allow additional executable code). An enhancement section is an option provided by SAP that allows you to replace an SAP source code section without making modifications. You can identify an enhancement section by searching for the ENHANCEMENT-SECTION and END-ENHANCEMENT-SECTION syntax. Explicit enhancement points and sections are stored inside enhancement spots. Use of Explicit Enhancements
Figure 106: Use of Explicit Enhancements
If there are multiple active implementations for an enhancement point, it is not possible to know in which order they will be executed. For an enhancement section, only one active implementation can be executed. If there are several active implementations, there is no runtime error, only a syntax warning. Enhancement Mode
Figure 107: Enhancement Mode
To use explicit enhancement points and enhancement sections, you must create an enhancement implementation (this is an implementation of the higher-level enhancement spot).
164
© Copyright. All rights reserved.
Lesson: Using Explicit Enhancements
Hint: Enhancement implementations are performed on a separate software layer (in the same way as modifications performed using the Modification Assistant). You cannot see them directly in the Debugger. When you reach the enhancement point or section in the Debugger, choose
(Single Step) to enter the
enhancement implementation Defining your own Explicit Enhancements
Figure 108: Defining your own Explicit Enhancements
If you, for example, as a partner want to offer your own explicit enhancement points or sections, you must do this in change mode in your program. Do not program them manually, instead you must create them using the special menu options available. Defining your own Explicit Enhancements: Framework Program
Figure 109: Defining your own Explicit Enhancements: Framework Program
© Copyright. All rights reserved.
165
Unit 6: Explicit Enhancement Options
If you offer your own explicit enhancements, note the possible additions to the ENHANCEMENT statements. The STATIC addition is intended for enhancement points or sections which are for enhancing data declarations. Without the STATIC addition, the enhancement is intended for enhancing executable code. One Include program can of course be used in many programs. Enhancement implementations for an explicit enhancement are always program-specific, even when the explicit enhancement is defined in an Include program. Should the implementation however by called for ALL programs, which the Include program is linked to, the definition of the explicit enhancement must have the addition INCLUDE BOUND. Without the INCLUDE BOUND addition, a source code enhancement is assigned to exactly one compilation unit. If the ENHANCEMENT-POINT statement is listed in an include program without this addition, a compilation unit must be assigned to it in the Enhancement Builder.
Note: ●
●
One include program cannot have both include-bound and non-include-bound enhancements at the same time. This also applies if an include program incorporates other include programs. In an include program that is integrated in the same program more than once, only include-bound source code enhancements are permitted.
To Create an Implementation for an Explicit Enhancement To use explicit enhancement points and sections, create an enhancement implementation (an implementation of the higher-level enhancement spot). 1. Display the SAP object (program, function module, method). 2. Search for the required enhancement point or section. 3. Choose
(Enhance).
4. Position your cursor on the enhancement spot which you want to create the implementation for, then choose Create Enhancement Implementation . 5. Specify the name of the enhancement implementation (comply with customer namespace Y* or Z*). 6. Enter the source code between ENHANCEMENT......ENDENHANCEMENT. 7. Choose
166
(Activate Enhancements).
© Copyright. All rights reserved.
Lesson: Using Explicit Enhancements
Risks of Multiple Implementations of Explicit Enhancement Sections
Figure 110: Multiple Implementations for an enhancement section
It is possible that more than one enhancement implementation may have been created and activated for an enhancement section. However, only one implementation for an enhancement section can be executed at runtime. To control which specific implementation is executed in this case, it is necessary to use the Switch Framework. In the case where more than one active implementation exists, you need to resolve the conflict by creating a conflict switch. In the absence of this switch, you cannot know which implementation will be executed at runtime.
© Copyright. All rights reserved.
167
Unit 6: Explicit Enhancement Options
Conflict in Enhancement Section – Example 1
Figure 111: Conflict in Enhancement Section – Example 1
The figure shows a conflict situation where multiple active implementations exist for an enhancement section. Here a conflict switch would be required to control which implementation is to be executed. Without the conflict switch, you cannot know whether implementation 1 or implementation 2 will be used at runtime.
Risks of Multiple Implementations for Explicit Enhancement Points
Figure 112: Multiple Implementations of Enhancement Points
It is possible to have one or more implementations for an enhancement point, belonging to different enhancement implementations. For example, in the figure, Point D has two implementations: enhancement implementation 1 and enhancement implementation 2.
168
© Copyright. All rights reserved.
Lesson: Using Explicit Enhancements
The issue is that you cannot know for certain the order in which the implementations will be executed An enhancement point of one spot can be assigned to many enhancement implementations, and one enhancement implementation can be used for enhancement points of one or more spots (m to n relation). Multiple Implementations of an Enhancement Point - Risk
Figure 113: Multiple Implementations of an Enhancement Point - Risk
Since the sequence in which the implementations are executed is not predefined, you must avoid any dependencies or conflicts in the logic, for example where different implementations change the value of the same variable.
© Copyright. All rights reserved.
169
Unit 6: Explicit Enhancement Options
170
© Copyright. All rights reserved.
Unit 6 Exercise 9 Use Explicit Enhancements
Business Example The report which you worked on in an earlier exercise, which allows users to choose a day of the week on the selection screen needs further enhancements. Although the users can now choose any day of the week, Saturday and Sunday are still treated as invalid days. Enhance the program so that they are treated in the same way as other days of the week. 1. Analyze the source code of program BC425_##_EPS (where ## is for your group number). 2. Use the explicit enhancement point BC425_##_EP1 to react to the user entering 6 and 7 on the selection screen in the same way that the SAP standard code reacts to the values 1 to 5. Name the enhancement implementation to be created ZBC425_##_EPS. 3. Use the explicit enhancement section BC425_##_ES1 to output the corresponding text in the list (that is, using the WRITE statement) instead of issuing a user message. 4. Test the program and verify that your enhancements work as expected.
© Copyright. All rights reserved.
171
Unit 6 Solution 9 Use Explicit Enhancements
Business Example The report which you worked on in an earlier exercise, which allows users to choose a day of the week on the selection screen needs further enhancements. Although the users can now choose any day of the week, Saturday and Sunday are still treated as invalid days. Enhance the program so that they are treated in the same way as other days of the week. 1. Analyze the source code of program BC425_##_EPS (where ## is for your group number). a) In transaction SE80, select Program from the dropdown list, enter the program name and choose (Display). b) In the Object Name list, double-click BC425_##_EPS. 2. Use the explicit enhancement point BC425_##_EP1 to react to the user entering 6 and 7 on the selection screen in the same way that the SAP standard code reacts to the values 1 to 5. Name the enhancement implementation to be created ZBC425_##_EPS. a) Choose
(Enhance).
b) Put your cursor on the enhancement point (BC425_##_EP1), and choose (Create Enhancement Implementation). c) In the Create Enhancement Implementation dialog box, in the Enhancement Implementation field, enter ZBC425_##_EPS and enter a short description, then choose Enter. d) Assign your implementation to your package and transport request. e) Enter your code between ENHANCEMENT and ENDENHANCEMENT as shown below: *$*$-Start: BC425_##_EP1------------------------$*$* ENHANCEMENT 1
ZBC425_##_EPS.
CASE weekday. WHEN '6'. WRITE 'Saturday'. EXIT. WHEN '7'. WRITE 'Sunday'. EXIT. ENDCASE. ENDENHANCEMENT. *$*$-End: BC425_##_EP1------------------------$*$* 3. Use the explicit enhancement section BC425_##_ES1 to output the corresponding text in the list (that is, using the WRITE statement) instead of issuing a user message.
172
© Copyright. All rights reserved.
Lesson: Using Explicit Enhancements
a) Put your cursor on the enhancement section (BC425_##_ES1), and choose (Create Enhancement Implementation). b) Enter your code between ENHANCEMENT and ENDENHANCEMENT as shown below: *$*$-Start: BC425_##_ES1----------------------$*$* ENHANCEMENT 2 ZBC425_##_EPS. WRITE:/ 'Invalid weekday input'. ENDENHANCEMENT. *$*$-End: BC425_##_ES1----------------------$*$*
Full model solution program after exercise: *-------------------------------------------------------------* * This program translates the name of a weekday into English. * *-------------------------------------------------------------* REPORT BC425_##_EPS. PARAMETERS weekday TYPE s_weekday_00. START-OF-SELECTION. CASE weekday. WHEN '1'. WRITE 'Monday'. EXIT. WHEN '2'. WRITE 'Tuesday'. EXIT. WHEN '3'. WRITE 'Wednesday'. EXIT. WHEN '4'. WRITE 'Thursday'. EXIT. WHEN '5'. WRITE 'Friday'. EXIT. ENDCASE. ENHANCEMENT-POINT BC425_##_EP1 SPOTS BC425_##_ESPOT1. *$*$-Start: BC425_##_EP1----------------------$*$* ENHANCEMENT 1 ZBC425_##_EPS. "active version CASE weekday. WHEN '6'. WRITE 'Saturday'. EXIT. WHEN '7'. WRITE 'Sunday'. EXIT. ENDCASE. ENDENHANCEMENT. *$*$-End: BC425_##_EP1------------------------$*$* ENHANCEMENT-SECTION BC425_##_ES1 SPOTS BC425_##_ESPOT1. MESSAGE 'Invalid weekday input' TYPE 'I'. END-ENHANCEMENT-SECTION. *$*$-Start: BC425_##_ES1------------------------$*$*
© Copyright. All rights reserved.
173
Unit 6: Explicit Enhancement Options
ENHANCEMENT 2 ZBC425_##_EPS. "active version WRITE:/ 'Invalid weekday input'. ENDENHANCEMENT. *$*$-End: BC425_00_ES1------------------------$*$* c) On the Inactive Objects screen, choose
(Select All) and then choose Continue.
4. Test the program and verify that your enhancements work as expected. a) Choose
(Direct processing) (or F8) to test the program.
b) On the selection screen, enter 6 in the Weekday field. c) Choose Execute. d) Verify that the text Saturday is displayed in the list. e) Go back to the selection screen. f) On the selection screen, enter 8 in the Weekday field. g) Choose Execute. h) Verify that 'Invalid weekday input' is displayed in the list.
174
© Copyright. All rights reserved.
Lesson: Using Explicit Enhancements
LESSON SUMMARY You should now be able to: ●
Use explicit enhancements
© Copyright. All rights reserved.
175
Unit 6: Explicit Enhancement Options
176
© Copyright. All rights reserved.
Unit 6 Learning Assessment
1. Customers can use enhancement points or sections by creating an enhancement implementation for the related ______________. Choose the correct answer. X
A Implicit enhancement section
X
B Explicit enhancement point
X
C Enhancement spot
2. What is the syntax used to identify an explicit enhancement point? Choose the correct answer. X
A ENHANCEMENT-SECTION
X
B ENHANCEMENT-POINT
X
C END-ENHANCEMENT SECTION
3. It is possible to have more than one implementation for an enhancement point, each one belonging to different enhancement implementations. Determine whether this statement is true or false. X
True
X
False
4. Explicit enhancement points and sections are stored inside a ___________. Choose the correct answer. X
A Conflict-dissolution or switch
X
B Enhancement spot
X
C Enhancement implementation
© Copyright. All rights reserved.
177
Unit 6 Learning Assessment - Answers
1. Customers can use enhancement points or sections by creating an enhancement implementation for the related ______________. Choose the correct answer. X
A Implicit enhancement section
X
B Explicit enhancement point
X
C Enhancement spot
Correct. Customers can use enhancement points or sections by creating an enhancement implementation of the related enhancement spot. 2. What is the syntax used to identify an explicit enhancement point? Choose the correct answer. X
A ENHANCEMENT-SECTION
X
B ENHANCEMENT-POINT
X
C END-ENHANCEMENT SECTION
3. It is possible to have more than one implementation for an enhancement point, each one belonging to different enhancement implementations. Determine whether this statement is true or false. X
True
X
False
4. Explicit enhancement points and sections are stored inside a ___________. Choose the correct answer.
178
X
A Conflict-dissolution or switch
X
B Enhancement spot
X
C Enhancement implementation
© Copyright. All rights reserved.
UNIT 7
Implicit Enhancements
Lesson 1 Explaining Implicit Enhancements
180
Lesson 2 Implementing Implicit Enhancements in Function Modules Exercise 10: Use Implicit Enhancements of an SAP Function Module
182 185
Lesson 3 Implementing Implicit Enhancements in Global SAP Classes Exercise 11: Enhance a Global SAP Class
191 195
Lesson 4 Using Other Implicit Enhancements Exercise 12: Enhance SAP Structures and SAP Subroutines
201 205
Lesson 5 Using Composite Enhancements Exercise 13: Create a Composite Enhancement Implementation
210 213
UNIT OBJECTIVES ●
Describe implicit enhancements
●
Use Implicit Enhancements in SAP function modules
●
Use implicit enhancements in global SAP classes
●
Use implicit enhancements in local SAP classes
●
Use implicit enhancements in SAP programs
●
Use Implicit Enhancements in existing enhancement implementations
●
Use composite enhancements
© Copyright. All rights reserved.
179
Unit 7 Lesson 1 Explaining Implicit Enhancements
LESSON OVERVIEW This lesson describes the implicit enhancement points and enhancement options that are available in SAP standard applications. Business Example You want to enhance SAP standard applications without making modifications, however, there are no explicit enhancements available for this purpose. For this reason, you require the following knowledge: ●
An understanding of implicit enhancement points
●
An understanding of implicit enhancement options
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Describe implicit enhancements
Implicit Enhancement Points
Figure 114: Overview of Implicit Enhancement Points
Implicit enhancement points provide you with the option to insert additional source code at certain points in SAP programs, function modules, and methods, without making modifications and without explicit preparation by SAP developers. Note: Even though the possibility to create implicit enhancement implementations has only been available since SAP NetWeaver 7.0, you can enhance repository objects which were created in earlier releases
180
© Copyright. All rights reserved.
Lesson: Explaining Implicit Enhancements
Showing Implicit Enhancement Points In The Source Code
Figure 115: Showing Implicit Enhancement Points In The Source Code
To create an implementation for an implicit enhancement point, you must first show where they are in the code. Once you have done this, the implementation can be created by putting your cursor on the implicit enhancement in question, and then choosing Create Enhancement Implementation. The figure illustrates this using the example of a subroutine. The implicit enhancement points are indicated by the black arrows in the status column, and the rows of double-quotes in the source code.
Implicit Enhancement Options SAP provides options to create the following without making modifications: ●
Additional (optional) interface parameters in SAP function modules and SAP methods
●
Additional attributes and methods in SAP classes
●
Preparation and postprocessing functions for global SAP methods
●
Replacements for global SAP methods
The Enhancement Framework also allows you to enhance the interfaces of SAP function modules and methods (that is create additional parameters), and to add new attributes and methods in SAP classes, as well as creating pre, post or overwrite exits for existing SAP methods. To use implicit enhancement points and options, you must create an enhancement implementation. LESSON SUMMARY You should now be able to: ●
Describe implicit enhancements
© Copyright. All rights reserved.
181
Unit 7 Lesson 2 Implementing Implicit Enhancements in Function Modules
LESSON OVERVIEW This lesson describes how to use implicit enhancements in SAP function modules. Business Example You have found an SAP standard function module whose behavior you want to change, without making modifications. For this reason, you require the following knowledge: ●
●
An understanding of the implicit enhancement points and implicit enhancement options available in SAP function modules An understanding of how to use the implicit enhancements of an SAP function module
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Use Implicit Enhancements in SAP function modules
Implicit Enhancement Points and Options in SAP Function Modules To use implicit enhancement points and options in an SAP function module, you need to create an enhancement implementation. Available Implicit Enhancements The following implicit enhancements are available for SAP function modules: ●
Implicit enhancement options -
●
Additional optional parameters can be added to the function module interface. (The parameters can be IMPORTING, EXPORTING, CHANGING or TABLES parameters, but additional EXCEPTIONS cannot be defined.)
Implicit enhancement points -
An enhancement implementation can be created to allow you to add logic at the beginning or end of the function module source code.
In order to use the implicit enhancement option to create additional parameters for a SAP function module, it is necessary to switch to Enhancement mode. This is done by using the usual button on the toolbar, and you will then be asked to create an enhancement implementation. Once this has been done, you will be able to define the new parameters with a suitable type under the appropriate tab page in the Function Builder.
182
© Copyright. All rights reserved.
Lesson: Implementing Implicit Enhancements in Function Modules
Note: Once you have activated the enhancement implementation, its name will be displayed against each of the new parameters, so that it is easy to distinguish between standard parameters and those created using an enhancement. Usually, if additional parameters have been added, the developer will also want to enhance the function module source code too. To do this, under the Source Code tab, in enhancement mode, it is necessary to use the appropriate menu entry to show where the available implicit enhancement points are located. (This will be at the beginning and end of the function module). An enhancement implementation can then be created and the necessary code added.
Note: If you use the Pattern functionality in the ABAP Editor to insert a function module call in your code, and that function module has been enhanced to include additional parameters, these new parameters will be included in the template call (but since they must always be optional, they will be commented).
© Copyright. All rights reserved.
183
Unit 7: Implicit Enhancements
184
© Copyright. All rights reserved.
Unit 7 Exercise 10 Use Implicit Enhancements of an SAP Function Module
Business Example You currently use a function module in some of your applications which calculates a gross price. In certain situations, you need to apply a discount to the price, and would therefore like to use the implicit enhancement options and points available to enhance the function module without making modifications. 1. Familiarize yourself with the way in which SAP function module BC425_##_CALC_PRICE works. The function module calculates the gross price for the imported net price and returns it through the EXPORT parameter. 2. Without making modifications, define an additional (optional) IMPORT parameter named im_discount (type I) that can be used to transfer a discount (in %) to the function module. Name your enhancement implementation ZBC425_##_CALC_PRICE_INTERFACE (where ## stands for your group number). Define an EXPORT parameter named ex_discprice (type BC425_PRICE) that the function module can use to return the discounted gross price. Save your enhancements. 3. Enhance the source code of the function module to use the IMPORT parameter im_discprice to calculate the discounted price and put the result into the EXPORT parameter ex_discprice. Name your enhancement implementation ZBC425_##_CALC_PRICE_SOURCE. 4. Copy program BC425_IEP_FM_TEMPLATE to target program ZBC425_##_IEP_FM. In the copied program, call the enhanced function module to ensure that it returns the discounted gross price in addition to the standard gross price. (The user input option for discount has already been implemented using the selection screen parameter Discount.) The program must output the two gross prices. 5. Test the program.
© Copyright. All rights reserved.
185
Unit 7 Solution 10 Use Implicit Enhancements of an SAP Function Module
Business Example You currently use a function module in some of your applications which calculates a gross price. In certain situations, you need to apply a discount to the price, and would therefore like to use the implicit enhancement options and points available to enhance the function module without making modifications. 1. Familiarize yourself with the way in which SAP function module BC425_##_CALC_PRICE works. The function module calculates the gross price for the imported net price and returns it through the EXPORT parameter. a) In transaction SE37, in the Function Module field enter BC425_##_CALC_PRICE. b) Choose Display. c) Analyze the information on each tab page. 2. Without making modifications, define an additional (optional) IMPORT parameter named im_discount (type I) that can be used to transfer a discount (in %) to the function module. Name your enhancement implementation ZBC425_##_CALC_PRICE_INTERFACE (where ## stands for your group number). Define an EXPORT parameter named ex_discprice (type BC425_PRICE) that the function module can use to return the discounted gross price. Save your enhancements. a) Choose the Import tab page, and then choose
(Enhance).
b) In the Select or Enhance Enhancement Implementation dialog box, choose Enhancement Implementation).
(Create
c) In the Create Enhancement Implementation dialog box, enter the following information: Field
Value
Enhancement Implementation
ZBC425_##_CALC_PRICE_INTERFACE
Short Text
Add a suitable description
d) Choose Continue. e) Assign the object to you package and transport request. f) On the Import tab page enter a new parameter with the following information:
186
© Copyright. All rights reserved.
Lesson: Implementing Implicit Enhancements in Function Modules
Parameter Name
Typing
Associated Type
Optional
Short Text
IM_DISCOUNT
Type
I
Selected
Discount
g) Open the Export tab page and enter a new parameter with the following information: Parameter Name
Typing
Associated Type
Short Text
EX_DISCPRICE
Type
BC425_PRICE
Discount Gross Price
h) Save your changes. 3. Enhance the source code of the function module to use the IMPORT parameter im_discprice to calculate the discounted price and put the result into the EXPORT parameter ex_discprice. Name your enhancement implementation ZBC425_##_CALC_PRICE_SOURCE. a) Display the source code of the function module. b) Choose
(Display <-> Change).
c) Choose
(Enhance).
d) Choose Edit → Enhancement Operations → Show Implicit Enhancement Options to display the implicit enhancement options. e) Put your cursor on one of the implicit enhancement points (it doesn't matter which one), and choose
(Create Enhancement Implementation).
f) In the Choose Enhancement Mode dialog box, choose Code. g) In the Select or Enhance Enhancement Implementation dialog box, choose Enhancement Implementation).
(Create
h) In the Create Enhancement Implementation dialog box, enter the following information: Field
Value
Enhancement Implementation
ZBC425_##_CALC_PRICE_SOURCE
Short Text
Add a suitable description
i) Choose Continue. j) Assign the object to your package and transport request. k) Insert the source code, as shown below: FUNCTION BC425_##_CALC_PRICE. *"------------------------------*"*"Lokale Schnittstelle: *" IMPORTING *" REFERENCE(IM_NETPRICE) TYPE BC425_PRICE *" EXPORTING *" REFERENCE(EX_FULLPRICE) TYPE BC425_PRICE
© Copyright. All rights reserved.
187
Unit 7: Implicit Enhancements
*"------------------------------ex_fullprice
=
im_netprice * 119 / 100 .
""""""$"$\SE:(1) Function Module BC425_##_CALC_PRICE, End *$*$-Start: (1)-------------------------------$*$* ENHANCEMENT 1 ZBC425_##_CALC_PRICE_SOURCE. "active version ex_discprice = ex_fullprice - ex_fullprice * ( im_discount / 100 ). ENDENHANCEMENT. *$*$-End: (1)-------------------------------$*$* ENDFUNCTION. l) Choose Save. m) In the function module editor, choose
(Activate Enhancement).
4. Copy program BC425_IEP_FM_TEMPLATE to target program ZBC425_##_IEP_FM. In the copied program, call the enhanced function module to ensure that it returns the discounted gross price in addition to the standard gross price. (The user input option for discount has already been implemented using the selection screen parameter Discount.) The program must output the two gross prices. a) Go to transaction SE80. b) Display program BC425_IEP_FM_TEMPLATE c) In the Object Name area, right-click on the program name and choose Copy. d) In the Copy Program BC425_IEP_FM_TEMPLATE dialog box, in the Target program field, enter ZBC425_##_IEP_FM. e) Choose Copy. REPORT
ZBC425_##_IEP_FM.
PARAMETERS: netprice discount DATA: fullprice discprice
TYPE bc425_price, TYPE i.
TYPE bc425_price, TYPE bc425_price.
* Calling the enhanced function module CALL FUNCTION 'BC425_##_CALC_PRICE' EXPORTING IM_NETPRICE = netprice IM_DISCOUNT = discount IMPORTING EX_FULLPRICE = fullprice EX_DISCPRICE = discprice . WRITE: / 'Full price :', 18 fullprice, / 'Discount price :', 18 discprice. f) In the Copy Program BC425_IEP_FM_TEMPLATE to ZBC425_##_IEP_FM dialog box, choose (Select All). g) Choose Copy. h) Assign the program to your package and transport request. i) n the Object Name area, right-click on the program name and choose Change.
188
© Copyright. All rights reserved.
Lesson: Implementing Implicit Enhancements in Function Modules
j) Update the code as follows: REPORT
zbc425_##_iep_fm.
PARAMETERS: netprice discount DATA: fullprice discprice
TYPE bc425_price, TYPE i.
TYPE bc425_price, TYPE bc425_price.
* Calling the enhanced function module CALL FUNCTION 'BC425_##_CALC_PRICE' EXPORTING IM_NETPRICE = netprice IM_DISCOUNT = discount IMPORTING EX_FULLPRICE = fullprice EX_DISCPRICE = discprice . WRITE: / 'Full price :', 18 fullprice, / 'Discount price :', 18 discprice. k) Activate the code. 5. Test the program. a) Choose
(Direct Processing).
b) On the selection screen, enter the following data: Field
Value
Net Price
100
Discount in %
17
c) Choose Execute. You can also debug the program to show exactly what happens.
© Copyright. All rights reserved.
189
Unit 7: Implicit Enhancements
LESSON SUMMARY You should now be able to: ●
190
Use Implicit Enhancements in SAP function modules
© Copyright. All rights reserved.
Unit 7 Lesson 3 Implementing Implicit Enhancements in Global SAP Classes
LESSON OVERVIEW This lesson describes how to use implicit enhancements in global SAP classes. Business Example You have found an SAP standard global class whose behavior you want to change, without making modifications. For this reason, you require the following knowledge: ●
An understanding of the implicit enhancement points and options in SAP classes
●
An understanding of pre-methods, post-methods, and overwrite methods
●
An understanding of when to use implicit source code enhancements instead of pre- and post-methods
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Use implicit enhancements in global SAP classes
Implicit Enhancement Points and Options in SAP Classes ●
Implicit enhancement options -
-
-
●
Adding optional parameters (importing, exporting, changing but no returning parameters and exceptions) to method interfaces Defining additional attributes and methods (public, protected, private) Defining a pre-method or a post-method for an SAP method (alternatively, defining an overwrite method)
Implicit enhancement points -
-
Adding additional logic (possibly using additional interface parameters, methods, or attributes) Implementing additional methods
To enhance the interface of global SAP methods or define additional attributes or methods for global SAP classes, proceed as follows: 1. Display the class in the Class Builder. 2. Choose Class → Enhance and create an enhancement implementation. 3. Define new attributes, new methods, and new parameters for existing methods.
© Copyright. All rights reserved.
191
Unit 7: Implicit Enhancements
4. To branch to the method editor so you can add the code, double-click the name of any additional methods you have created. 5. Choose
(Activate Enhancements).
The newly added interface parameters must always be optional, and they can then be used in any source code enhancements of the corresponding method. Any new attributes or methods can also be used in the source code enhancements of methods of the same global class.
Pre-Methods, Post-Methods, and Overwrite Methods These methods are automatically called before, after, or instead of the SAP method which they are linked to. When an overwrite method is created, it is not possible to have pre or post methods for the same original method. The chain pre-method → methodxyz → post-method can be interrupted at runtime (that is, parts are not executed) under the following circumstances: ●
●
If an exception is raised within the pre-method, the method xyz and the post-method are not executed. If an exception is thrown in the method xyz, the post-method is not executed.
When pre-, post-, and overwrite methods are created, the system generates a local class named lcl_ for the enhancement . This local class is attached to the end of the local class implementation section in the original class (as an implementation of the predefined enhancement option). You can access the components of the original class within the local class lcl_ through the object reference CORE_OBJECT. The local class lcl_ can implement the following interfaces: ●
IPR_ for pre-methods
●
IPO_ for post-methods
●
IOW_ for overwrite methods
Restrictions of Pre-, Post-, and Overwrite Methods The parameters of pre-methods, post-methods, and overwrite methods are similar to the parameters of the original method, but the following restrictions exist: ●
●
Pre-methods do not have export parameters. Post-methods do not have EXPORT parameters; the EXPORT parameters of the original SAP method become CHANGING parameters in the post-method.
●
The returning parameter of a functional method becomes a changing parameter.
●
Overwrite methods have the same signature as the original method.
●
You cannot change the parameter definitions of pre, post, and overwrite methods.
Defining a Pre-Method, Post-Method, or Overwrite Method The following are the steps to define a pre-, post-, or overwrite method for a method of a global SAP class:
192
© Copyright. All rights reserved.
Lesson: Implementing Implicit Enhancements in Global SAP Classes
1. Display the class in the Class Builder. 2. Choose Class → Enhance to create an enhancement implementation. 3. Use the cursor to mark the required SAP method. 4. Choose Edit → Enhancement Operations and then choose Insert Pre-Method, Insert PostMethod, or Add Overwrite Method. 5. Choose the pushbutton in the Pre-/Post-/Overwrite-Exit column to implement the corresponding method. To access components of the global class in the method, you have to use the reference variable core_object, which is filled in the local constructor. 6. Save the method. 7. Choose the Activate Enhancements pushbutton. For each SAP method, you can define a pre-method and post-method. As an alternative, you can create an overwrite method that replaces the SAP method. Advantages of Pre-Methods and Post-Methods Over Implicit Source Code Enhancements ●
●
●
Higher abstraction level due to a separate address space Less adjustment effort than source code enhancements during upgrade (only necessary when parameters are changed) All pre- and post-methods are stored in a local enhancement class which has its own attributes to exchange data between methods
© Copyright. All rights reserved.
193
Unit 7: Implicit Enhancements
194
© Copyright. All rights reserved.
Unit 7 Exercise 11 Enhance a Global SAP Class
Business Example You need to enhance a global SAP standard class to provide additional functionality. Template Class CL_BC425_CUSTOMER_## Enhance the SAP standard class CL_BC425_CUSTOMER _ ## by adding additional Attributes and methods. Also enhance the existing methods of the class, so that the additional attributes you have defined are processed. Use a POST-exit for a standard method. 1. Display and analyze the SAP standard class CL_BC425_CUSTOMER_## in the Class Builder. Use implicit enhancements to add the private Instance attributes MV_CITY (for the customer city) and MV_BIRTHDAY (for the customer birthday). Use a suitable field from SCUSTOM for the type of MV_CITY, and for MV_BIRTHDAY, use the type BC425_BDAY. 2. Define a private static functional method named GET_CITY to obtain the city, with an import parameter for the customer ID, and a returning parameter for the city. Implement the method so that the customer city is retrieved from database table SCUSTOM, using the customer ID supplied for the import parameter. Fill the returning parameter with the city. 3. The instance constructor requires an additional import parameter for the birthday. Fill the attribute MV_BIRTHDAY in the implementation of the instance constructor, using this new parameter. The customer city should also be derived and populated here by calling the GET_CITY method created in the previous step. 4. Define a POST exit for the method DISPLAY. In the exit, the Address details and birthday should be output. Make sure that the POST exit can access the private attributes of the class. 5. Test your results in the Class Builder.
© Copyright. All rights reserved.
195
Unit 7 Solution 11 Enhance a Global SAP Class
Business Example You need to enhance a global SAP standard class to provide additional functionality. Template Class CL_BC425_CUSTOMER_## Enhance the SAP standard class CL_BC425_CUSTOMER _ ## by adding additional Attributes and methods. Also enhance the existing methods of the class, so that the additional attributes you have defined are processed. Use a POST-exit for a standard method. 1. Display and analyze the SAP standard class CL_BC425_CUSTOMER_## in the Class Builder. Use implicit enhancements to add the private Instance attributes MV_CITY (for the customer city) and MV_BIRTHDAY (for the customer birthday). Use a suitable field from SCUSTOM for the type of MV_CITY, and for MV_BIRTHDAY, use the type BC425_BDAY. a) In transaction SE80. b) Choose Class/ Interface from the dropdown box and enter CL_BC425_CUSTOMER_##. c) Double-click the class name in the Object Name navigation area on the left to open the class. d) Open the Attributes tab page. e) Choose
(Enhance).
f) In the Create Enhancement Implementation dialog box, in the Enhancement Implementation field,enter ZBC425_CLASS_IMP_ENH_## . g) In the Short Text field enter a suitable description , then choose Enhancement).
(Creation of
h) When prompted, assign the implementation to your package and transport request. i) Add the following attributes to the class: Attribute
Level
Visibility
Associated Type
Description
MV_CITY
Instance
Private
SCUSTOM-CITY Customer City
MV_BIRTHDAY
Instance
Private
BC425_BDAY
Customer Birthday
2. Define a private static functional method named GET_CITY to obtain the city, with an import parameter for the customer ID, and a returning parameter for the city. Implement
196
© Copyright. All rights reserved.
Lesson: Implementing Implicit Enhancements in Global SAP Classes
the method so that the customer city is retrieved from database table SCUSTOM, using the customer ID supplied for the import parameter. Fill the returning parameter with the city. a) Open the Methods tab page. b) Define the method with the following properties: Method
Level
Visibility
Description
GET_CITY
Instance
Public
Get customer city
c) Place your cursor on the GET_CITY method name. d) Choose Parameter. e) Maintain the method parameters as follows: Parameter
Type
Pass By Value
Associated Type
IV_ID
Importing
N/A
SCUSTOM-ID
RE_CITY
Returning
Selected
SCUSTOM-CITY
f) Choose Back to methods and double-click on the method GET_CITY to navigate to the code. g) Implement the code as follows: METHOD GET_CITY . SELECT SINGLE city FROM scustom INTO re_city WHERE id = iv_id. IF sy-subrc <> 0. CLEAR re_city. ENDIF. ENDMETHOD. h) Choose
(Activate Enhancements).
i) Choose Continue. j) Choose Builder.
(Previous Object) to return from the method implementation to the Class
k) Choose
(Back to Methods) to return to the list of methods on the Methods tab page.
3. The instance constructor requires an additional import parameter for the birthday. Fill the attribute MV_BIRTHDAY in the implementation of the instance constructor, using this new parameter. The customer city should also be derived and populated here by calling the GET_CITY method created in the previous step. a) Place your cursor on the CONSTRUCTOR method name. b) Choose Parameter. c) Maintain the additional method parameter as follows:
© Copyright. All rights reserved.
197
Unit 7: Implicit Enhancements
Parameter
Associated Type
IV_BIRTHDAY
BC425_BDAY
d) Choose Back to methods and double-click on the method CONSTRUCTOR to navigate to the code. e) Choose Yes when prompted to save the enhancement. f) Choose
(Enhance).
g) From the menu, choose Edit → Enhancement Operations → Show Implicit Enhancement Options. h) Put your cursor on the second implicit enhancement (indicated by the row of doublequotes). i) Choose
(Create Enhancement Implementation).
j) In the Choose Enhancement Mode dialog box, choose Code. k) In the Create Enhancement Implementation dialog box, in the Enhancement Implementation field, enter ZBC425_SOURCE_ENH_##. l) In the Short Text field, enter a suitable description then choose Enhancement).
(Creation of
m) Assign to your package and transport request. n) Implement the code as follows: ENHANCEMENT 1 ZBC425_SOURCE_ENH_##. * Fill the birthday attribute mv_birthday = iv_birthday.
"inactive version
* Call GET_CITY to fill the city attribute mv_city = me->get_city( mv_id ). ENDENHANCEMENT. o) Choose
(Activate Enhancements).
p) Choose Continue. q) Choose Builder.
(Previous Object) to return from the method implementation to the Class
r) Choose
(Back to Methods) to return to the list of methods on the Methods tab page.
4. Define a POST exit for the method DISPLAY. In the exit, the Address details and birthday should be output. Make sure that the POST exit can access the private attributes of the class. a) Put your cursor on the DISPLAY method name. b) From the menu, choose Edit → Enhancement Operations → Insert Post-Method. c) In the Type of Access to Original Class dialog box, choose Yes.
198
© Copyright. All rights reserved.
Lesson: Implementing Implicit Enhancements in Global SAP Classes
d) Choose Navigation to PostExit which appears in the PostExit column on the same row as the method. e) Choose Yes to save the changes to the enhancement object. f) Add the code to the method IPO_ZBC425_CLASS_IMP_ENH_##~DISPLAY as follows: WRITE:/ 'Birthday:', core_object->mv_birthday. WRITE:/ 'City:', core_object->mv_city. g) Choose
(Activate).
h) Choose Continue. 5. Test your results in the Class Builder. a) Choose
(Previous Object) to return to the Class Builder.
b) Choose
(In Test Environment).
c) On the Create Instance of Class CL_BC425_CUSTOMER_##: Constructor Parameters screen, enter the following: Parameter
Value
IV_ID
00000001
IV_BIRTHDAY
01011980
d) Choose Instance. e) Choose Execute Method next to the DISPLAY method. f) Verify that the correct information is displayed at the top of the screen.
© Copyright. All rights reserved.
199
Unit 7: Implicit Enhancements
LESSON SUMMARY You should now be able to: ●
200
Use implicit enhancements in global SAP classes
© Copyright. All rights reserved.
Unit 7 Lesson 4 Using Other Implicit Enhancements
LESSON OVERVIEW This lesson explains which implicit enhancement points and options are available in local SAP classes, SAP structure definitions, and SAP subroutines. Business Example You want to know what other implicit enhancement options are available in SAP standard programs. For this reason, you require the following knowledge: ●
An understanding of implicit enhancement points and options in local SAP classes
●
An understanding of how to enhance SAP structures and SAP subroutines
●
An understanding of how to use implicit enhancement points within existing enhancement implementations
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Use implicit enhancements in local SAP classes
●
Use implicit enhancements in SAP programs
●
Use Implicit Enhancements in existing enhancement implementations
Implicit Enhancement Points and Options in Local SAP Classes Local SAP Class: Implicit Enhancements Options and Points ●
Implicit Enhancements Options: -
-
●
Adding optional parameters (importing, exporting, and changing, but no returning parameters and exceptions) to method interfaces Defining additional attributes and methods (public, protected, and private)
Implicit Enhancements Points: -
-
At the beginning and end of methods to add logic, possibly using additional interface parameters, attributes, or methods) At the end of the IMPLEMENTATION block (to implement any additional methods)
To use implicit enhancement points and options in local SAP classes, create an enhancement implementation.
© Copyright. All rights reserved.
201
Unit 7: Implicit Enhancements
To Enhance a Local SAP Class The following are the steps to enhance a local class: 1. Display the source code of the local class. 2. Choose
(Enhance).
3. Choose Edit → Enhancement Operations → Show Implicit Enhancement Options to show the implicit enhancement options. 4. In the editor, use the context menu of one of the implicit enhancement options or displayed points to create an enhancement implementation. Hint: You have to scroll to the right-hand side of the editor to see what implicit enhancements are displayed. If you create an enhancement implementation for the public section, make sure to choose the correct implicit enhancement. Do not write PUBLIC SECTION in the enhancement implementation. Proceed in the same way for all other enhancement possibilities.
Note: For the enhancement of a method interface, the introductory additions IMPORTING, EXPORTING, and CHANGING are not to be specified, even if they are missing from the original method declaration. 5. Insert the source code. 6. Choose
(Activate Enhancements).
Implicit Enhancement Points in Structure Declarations, Subroutines, and Include Programs Other Enhancement Points ●
At the end of a structure (type) declaration (before “END OF …”) (to include additional fields)
●
At the beginning and end of subroutines (to add more functionality)
●
At the end of includes (to implement additional functions and subroutines)
Hint: Implicit enhancement points and sections are not available for SAP Basis objects.
202
© Copyright. All rights reserved.
Lesson: Using Other Implicit Enhancements
What Has to be Done after an Upgrade? Enhancement implementations are performed without modifications. However, if the enhanced programs are newly released in an upgrade, you have to make an adjustment to “return” the enhancement implementations back to the program. This will be discussed in the unit Adjustment of Enhancement Implementations. To Use Other Implicit Enhancement Points 1. Display the source code of the corresponding SAP object. 2. Choose the
(Enhance ).
3. Choose Edit → Enhancement Operations → Show Implicit Enhancement Options. 4. In the editor, use the context menu of one of the implicit enhancement points displayed to create an enhancement implementation. 5. Insert the source code. 6. Choose the Activate Enhancements pushbutton. Note: When you enhance a structure (type) declaration (before “END OF ...”) you must use the syntax DATA: TYPE , TYPE . Without the DATA statement and the period at the end, a syntax error will occur.
© Copyright. All rights reserved.
203
Unit 7: Implicit Enhancements
204
© Copyright. All rights reserved.
Unit 7 Exercise 12 Enhance SAP Structures and SAP Subroutines
Business Example Your users have asked if a SAP standard report, which displays details of flight connections, can be changed to output two additional pieces of information. Use suitable implicit enhancement points to make the necessary changes. 1. Analyze the source code of program BC425_##_IEP_STRFORM (where ## stands for your group number). 2. Use the corresponding implicit enhancement point to add the distance and distid fields to the structure definition wa_conn (flight distance and unit, type assignment using the SPFLI fields of the same name). Name your enhancement implementation ZBC425_##_IEP_STRFORM. 3. In the subroutine display_conn, the formal parameter f_conn now contains the two additional fields distance and distid due to its type assignment using wa_conn. Use the corresponding implicit enhancement point in the subroutine to output these fields. 4. Activate the enhancements and test the program.
© Copyright. All rights reserved.
205
Unit 7 Solution 12 Enhance SAP Structures and SAP Subroutines
Business Example Your users have asked if a SAP standard report, which displays details of flight connections, can be changed to output two additional pieces of information. Use suitable implicit enhancement points to make the necessary changes. 1. Analyze the source code of program BC425_##_IEP_STRFORM (where ## stands for your group number). a) Display program BC425_##_IEP_STRFORM in the Object Navigator (transaction SE80) and analyze the code. 2. Use the corresponding implicit enhancement point to add the distance and distid fields to the structure definition wa_conn (flight distance and unit, type assignment using the SPFLI fields of the same name). Name your enhancement implementation ZBC425_##_IEP_STRFORM. a) Choose
(Enhance).
b) From the menu, choose Edit → Enhancement Operations → Show Implicit Enhancement Options. c) Position your cursor on the option at the end of the structure definition. d) Choose
(Create Enhancement Implementation).
e) In the Create Enhancement Implementation dialog box, enter ZBC425_##_IEP_STRFORM in the Enhancement Implementation field, a suitable description in the Short text field, then choose Creation of Implementation. f) Assign the implementation to your package and transport request. g) Add the code as shown below: DATA: BEGIN OF wa_conn, carrid TYPE spfli-carrid, connid TYPE spfli-connid, cityfrom TYPE spfli-cityfrom, cityto TYPE spfli-cityto, """"""""""$"$\SE:(1) Struct. WA_CONN, End *$*$-Start: (1)------------------$*$* ENHANCEMENT 1 ZBC425_##_IEP_STRFORM. "active version """""""""""""""""""""""""""""""" DATA: distance TYPE spfli-distance, distid TYPE spfli-distid. """""""""""""""""""""""""""""""" ENDENHANCEMENT. *$*$-End: (1)------------------$*$* END OF wa_conn.
206
© Copyright. All rights reserved.
Lesson: Using Other Implicit Enhancements
3. In the subroutine display_conn, the formal parameter f_conn now contains the two additional fields distance and distid due to its type assignment using wa_conn. Use the corresponding implicit enhancement point in the subroutine to output these fields. a) Put your cursor on the implicit enhancement point at the end of the subroutine. b) Choose
(Create Enhancement Implementation).
c) In the Choose Enhancement Mode dialog box, choose Code. d) Add the code as shown below: FORM display_conn
USING f_conn LIKE wa_conn.
WRITE: / f_conn-carrid, f_conn-connid, f_conn-cityfrom, f_conn-cityto. """""""""""""""""""""""""""""""""""" *$*$-Start: (2)---------------------$*$* ENHANCEMENT 2 ZBC425_##_IEP_STRFORM. "active version WRITE: f_conn-distance, f_conn-distid. ENDENHANCEMENT. *$*$-End: (2)---------------------$*$* ENDFORM. 4. Activate the enhancements and test the program. a) Choose
(Activate Enhancements).
b) Test the program by choosing
(Direct Processing)(or F8).
c) In the Airline field on the Selection Screen, enter AA. d) Verify that the additional fields are displayed in the report.
© Copyright. All rights reserved.
207
Unit 7: Implicit Enhancements
Implicit Enhancements in Existing Enhancement Implementations
Figure 116: Implicit Enhancements in Existing Enhancement Implementations
As of SAP NetWeaver 7.02, implicit enhancement points are now available within existing Enhancement implementations. To use them, you should proceed in the same way as for other implicit enhancement points. Choose Edit → Enhancement Operations → Show Implicit Enhancement Options. The implicit enhancement points are offered at the beginning and at the end of the existing implementation.
208
© Copyright. All rights reserved.
Lesson: Using Other Implicit Enhancements
LESSON SUMMARY You should now be able to: ●
Use implicit enhancements in local SAP classes
●
Use implicit enhancements in SAP programs
●
Use Implicit Enhancements in existing enhancement implementations
© Copyright. All rights reserved.
209
Unit 7 Lesson 5 Using Composite Enhancements
LESSON OVERVIEW In this lesson, you will create a Composite Enhancement Implementation. LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Use composite enhancements
Composite Enhancements
Figure 117: Composite Enhancement Spots
Enhancement Spots are Repository objects which contain one or more enhancements (either explicit enhancements or new BAdIs). Composite enhancement spots are used to semantically group simple enhancement spots. They contain one or more simple enhancement spots or one or more composite enhancement spots of the relevant type as described in the figure. Composite enhancement spots are therefore used to combine simple enhancement spots into meaningful units.
210
© Copyright. All rights reserved.
Lesson: Using Composite Enhancements
Example — Composite Enhancement Spot
Figure 118: Example — Composite Enhancement Spot
In the figure Example — Composite Enhancement Spot, you can see an example of a composite enhancement spot, ESC_CK_ECP, which is made up of 6 simple enhancement spots. Composite Enhancement Implementations
Figure 119: Composite Enhancement Implementations
Enhancement implementations are repository objects that serve as containers for enhancement implementation elements. If you want to use an explicit enhancement point, explicit enhancement section, new BAdI or an implicit enhancement provided by SAP, you must create an enhancement implementation. A simple enhancement implementation can contain one or more enhancement implementation elements which relate to elements of the same enhancement spot. However, if you create an implementation for something which belongs to a different enhancement spot, or you create an implementation for an implicit enhancement, you will be prompted to create a NEW enhancement implementation. If you wish to group these enhancement implementations together, a composite enhancement implementation is required. Composite enhancement implementations are used for the semantic grouping of simple enhancement implementations. A composite enhancement implementation contains either
© Copyright. All rights reserved.
211
Unit 7: Implicit Enhancements
one or more simple enhancement implementations or one or more composite enhancement implementations of the relevant type. Example — Composite Enhancement Implementation
Figure 120: Example — Composite Enhancement Implementation
The figure Example - Composite Enhancement Implementation shows an example of a composite enhancement implementation, which contains two simple enhancement implementations. It is important to understand that there is no need to create a composite enhancement implementation, even if the enhancements which you are using belong to an enhancement spot which itself is part of a composite enhancement spot. Conversely, you can create a composite enhancement implementation for enhancements which belong to simple enhancement spots which do NOT belong to a composite enhancement spot. An example of when a composite enhancement implementation would be advisable follows: You may need to use the implicit enhancements available in a function module – to create extra parameters and then enhance the source code. This function module is perhaps called in a standard SAP program, inside an enhancement section. You wish to call the enhanced function module in the standard program, and therefore create an enhancement implementation to replace the code in the enhancement section. Since the implicit enhancement implementation in the function module and the explicit enhancement in the program are clearly related, a composite enhancement implementation can be created to link them together. Enhancement Spots are repository objects which contain one or more enhancements.
212
© Copyright. All rights reserved.
Unit 7 Exercise 13 Create a Composite Enhancement Implementation
Business Example You need to enhance a standard function module to include additional parameters and the related logic in the source code. This function module is called in a standard ABAP program, which you will also need to enhance to use the additional parameters of the function module. Since the enhancements you will make are logically related, you decide to use a Composite Enhancement Implementation to group the enhancements together. Enhance the Function Module 1. Display function module BC425_DISCOUNT_## in the Function Builder, then switch to Enhancement mode. 2. Create an enhancement implementation named ZBC425_ENH1_COMP_##, and assign it to a composite enhancement implementation named ZBC425_COMP_##. 3. Maintain the following additional parameters for the function module: Parameter
Typing
Associated Type
IM_ALTER_DISCOUNT
Type
I
EX_ALTER_PRICE
Type
BC425_PRICE
4. Display the source code of the function module, and then switch to enhancement mode. Use the implicit enhancement at the end of the function module to calculate the alternative price using the alternative discount rate passed into the function module. When prompted, create a second enhancement implementation named ZBC425_ENH2_COMP_##, and assign it to your composite enhancement implementation ZBC425_COMP_##. 5. Activate your enhancements. Enhance the ABAP Program 1. In transaction SE80, display program BC425_COMP_##, then switch to Enhancement mode. 2. Use the explicit enhancement point in the program to add an additional selection screen parameter named PA_DISC of TYPE I, and an additional variable named GV_ALTER_DISC of TYPE bc425_price. Create an enhancement implementation named ZBC425_ENH3_COMP_##, and assign it to your Composite Enhancement implementation ZBC425_COMP_##.
© Copyright. All rights reserved.
213
Unit 7: Implicit Enhancements
3. Use the explicit enhancement section in the program to replace the call of the function module BC425_DISCOUNT_## with only the standard parameters, to a call of the same function module but using the new optional parameters. Pass in the discount rate entered by the user in your selection screen parameter PA_DISC, and use the new variable GV_ALTER_DISC to hold the alternative discounted price which is exported by the function module. 4. Use the implicit enhancement at the end of the subroutine OUTPUT_DISCOUNT to output the value of the variable GV_ALTER_DISC. 5. Activate your enhancements. 6. Test the program and verify the results. Analyze the Composite Enhancement Implementation 1. Display the composite enhancement implementation ZBC425_COMP_##. 2. Verify that all of the simple enhancement implementation are listed.
214
© Copyright. All rights reserved.
Unit 7 Solution 13 Create a Composite Enhancement Implementation
Business Example You need to enhance a standard function module to include additional parameters and the related logic in the source code. This function module is called in a standard ABAP program, which you will also need to enhance to use the additional parameters of the function module. Since the enhancements you will make are logically related, you decide to use a Composite Enhancement Implementation to group the enhancements together. Enhance the Function Module 1. Display function module BC425_DISCOUNT_## in the Function Builder, then switch to Enhancement mode. a) Open transaction SE37. b) In the Function Module field, enter BC425_DISCOUNT_##, then choose Display. c) Open the Import tab page. d) Choose
(Enhance).
2. Create an enhancement implementation named ZBC425_ENH1_COMP_##, and assign it to a composite enhancement implementation named ZBC425_COMP_##. a) In the Create Enhancement Implementation dialog box, enter the following information: Field
Value
Enhancement Implementation
ZBC425_ENH1_COMP_##
Short Text
Enter a suitable description
Composite Enhancement Implementation ZBC425_COMP_## b) Choose Create Composite Implementation. c) In the Create Composite Enhancement Implementation dialog box, in the Description field, enter a suitable description, then choose Continue. d) Assign the composite enhancement implementation to your package and transport request. You are returned to the Create Enhancement Implementation dialog box. e) Choose Creation of Enhancement. f) Assign your enhancement implementation to your package and transport request.
© Copyright. All rights reserved.
215
Unit 7: Implicit Enhancements
3. Maintain the following additional parameters for the function module: Parameter
Typing
Associated Type
IM_ALTER_DISCOUNT
Type
I
EX_ALTER_PRICE
Type
BC425_PRICE
a) On the Import tab page, create the new importing parameter using the details in the table. b) Open the Export tab page, and add the new exporting parameter using the details in the table. c) Choose Activate Enhancements. d) On the Inactive Objects, choose
(Select All).
e) Choose Continue. 4. Display the source code of the function module, and then switch to enhancement mode. Use the implicit enhancement at the end of the function module to calculate the alternative price using the alternative discount rate passed into the function module. When prompted, create a second enhancement implementation named ZBC425_ENH2_COMP_##, and assign it to your composite enhancement implementation ZBC425_COMP_##. a) Choose
(Display<->Change).
(You must go back to Display mode, before trying to enhance the source code.) b) Open the Source Code tab page. c) Choose
(Enhance).
d) From the menu, choose Edit → Enhancement Operations → Show Implicit Enhancement Options. e) Position your cursor on the implicit enhancement option at the end of the function module, then choose (Create Enhancement Implementation). f) In the Choose Enhancement Mode dialog box, choose Code. g) In the Create Enhancement Implementation dialog box, enter the following: Field
Value
Enhancement Implementation
ZBC425_ENH2_COMP_##
Short text
Enter a suitable description
Composite Enhancement Implementation ZBC425_COMP_## h) Choose Creation of Enhancement. i) Assign your enhancement implementation to your package and transport request. j) Enter the following code between ENHANCEMENT and ENDENHANCEMENT: ex_alter_price = im_price - ( ( im_price * im_alter_discount ) / 100 ). 5. Activate your enhancements.
216
© Copyright. All rights reserved.
Lesson: Using Composite Enhancements
a) Choose
(Activate).
b) On the Inactive Objects, choose
(Select All).
c) Choose Continue. Enhance the ABAP Program 1. In transaction SE80, display program BC425_COMP_##, then switch to Enhancement mode. a) Go to transaction SE80. b) Open program BC425_COMP_## in display mode. c) Choose
(Enhance).
2. Use the explicit enhancement point in the program to add an additional selection screen parameter named PA_DISC of TYPE I, and an additional variable named GV_ALTER_DISC of TYPE bc425_price. Create an enhancement implementation named ZBC425_ENH3_COMP_##, and assign it to your Composite Enhancement implementation ZBC425_COMP_##. a) Position your cursor on the enhancement point EP1, then choose Create Enhancement Implementation. b) In the Create Enhancement Implementation dialog box, enter the following: Field
Value
Enhancement Implementation
ZBC425_ENH3_COMP_##
Short text
Enter a suitable description
Composite Enhancement Implementation ZBC425_COMP_## c) Choose Creation of Enhancement. d) Assign your enhancement implementation to your package and transport request. e) Enter the following code between ENHANCEMENT and ENDENHANCEMENT: PARAMETERS pa_disc TYPE i. DATA gv_alter_disc TYPE bc425_price. 3. Use the explicit enhancement section in the program to replace the call of the function module BC425_DISCOUNT_## with only the standard parameters, to a call of the same function module but using the new optional parameters. Pass in the discount rate entered by the user in your selection screen parameter PA_DISC, and use the new variable GV_ALTER_DISC to hold the alternative discounted price which is exported by the function module. a) Position your cursor on the enhancement section EH1, then choose Create Enhancement Implementation. b) Delete the code between the new ENHANCEMENT 2….. and ENDENHANCEMENT. c) Position your cursor between ENHANCEMENT 2….. and ENDENHANCEMENT. d) Choose Pattern.
© Copyright. All rights reserved.
217
Unit 7: Implicit Enhancements
e) In the CALL FUNCTION field, enter BC425_DISCOUNT_##, then choose Continue. The function call will be inserted, along with the new optional parameters. f) Supply the appropriate variables for each parameter in the function call, as shown below: CALL FUNCTION 'BC425_DISCOUNT_##' EXPORTING im_price = pa_price IM_ALTER_DISCOUNT = pa_disc IMPORTING EX_DISCOUNT_PRICE = gv_discount_price EX_ALTER_PRICE = gv_alter_disc. 4. Use the implicit enhancement at the end of the subroutine OUTPUT_DISCOUNT to output the value of the variable GV_ALTER_DISC. a) In the menu, choose Edit → Enhancement Operations → Show Implicit Enhancement Options. b) Position your cursor on the implicit enhancement option just before the ENDFORM signifying the end of the subroutine. c) Choose Create Enhancement Implementation. d) In the Choose Enhancement Mode dialog box, choose Code. e) Add the following code between the ENHANCEMENT 3…. ENDENHANCEMENT: WRITE:/ 'Price with', pa_disc, '% discount:', gv_alter_disc. 5. Activate your enhancements. a) Choose
(Activate).
6. Test the program and verify the results. a) Choose
(Direct Processing).
b) On the selection screen, enter the following data: Field
Value
Price
100
PA_DISC
50
c) Choose Execute. d) Verify that the additional information is displayed in the list. Analyze the Composite Enhancement Implementation 1. Display the composite enhancement implementation ZBC425_COMP_##. a) Go to transaction SE20. b) Select the Compos. Enh. Implementation radio button. c) Enter ZBC425_COMP_## in the corresponding field. d) Choose Display. e) Verify that all of the simple enhancement implementation are listed 2. Verify that all of the simple enhancement implementation are listed.
218
© Copyright. All rights reserved.
Lesson: Using Composite Enhancements
a) On the Enh. Implementations tab page, ensure all of the simple enhancement implementations are listed. b) Double-click on each enhancement implementation to navigate to the details.
© Copyright. All rights reserved.
219
Unit 7: Implicit Enhancements
LESSON SUMMARY You should now be able to: ●
220
Use composite enhancements
© Copyright. All rights reserved.
Unit 7 Learning Assessment
1. An implicit enhancement point provides you with the option to insert additional source code at certain points in SAP source code. Determine whether this statement is true or false. X
True
X
False
2. The Enhancement Framework allows you to enhance methods in SAP classes. Determine whether this statement is true or false. X
True
X
False
3. To use implicit enhancement points and options, you need to create an ___________. Choose the correct answer. X
A Explicit enhancement point
X
B Enhancement implementation
X
C Explicit enhancement section
4. Overwrite methods replace the implementation of the original method. Determine whether this statement is true or false. X
True
X
False
5. Identify the implicit enhancements available in local SAP classes. Choose the correct answers. X
A At the beginning and end of each method.
X
B At the end of the implementation block.
X
C Option to create additional importing parameters.
© Copyright. All rights reserved.
221
Unit 7: Learning Assessment
6. Enhancement Spots are repository objects which contain one or more enhancements Determine whether this statement is true or false.
222
X
True
X
False
© Copyright. All rights reserved.
Unit 7 Learning Assessment - Answers
1. An implicit enhancement point provides you with the option to insert additional source code at certain points in SAP source code. Determine whether this statement is true or false. X
True
X
False
2. The Enhancement Framework allows you to enhance methods in SAP classes. Determine whether this statement is true or false. X
True
X
False
3. To use implicit enhancement points and options, you need to create an ___________. Choose the correct answer. X
A Explicit enhancement point
X
B Enhancement implementation
X
C Explicit enhancement section
Correct. To use implicit enhancement points and options in an SAP function module, you need to create an enhancement implementation. 4. Overwrite methods replace the implementation of the original method. Determine whether this statement is true or false. X
True
X
False
© Copyright. All rights reserved.
223
Unit 7: Learning Assessment - Answers
5. Identify the implicit enhancements available in local SAP classes. Choose the correct answers. X
A At the beginning and end of each method.
X
B At the end of the implementation block.
X
C Option to create additional importing parameters.
Correct. The implicit enhancement option available in local SAP class is adding importing parameter. 6. Enhancement Spots are repository objects which contain one or more enhancements Determine whether this statement is true or false.
224
X
True
X
False
© Copyright. All rights reserved.
UNIT 8
Modifications of the SAP Standard Application
Lesson 1 Modifying SAP Standard Software
226
Lesson 2 Modifying Applications using the Modification Assistant Exercise 14: Implement Modifications
235 243
Lesson 3 Implementing User Exits
250
Lesson 4 Adjusting Modifications Exercise 15: Perform Modification Adjustment with Transaction SPDD Exercise 16: Perform Modification Adjustment with Transaction SPAU
254 261 265
UNIT OBJECTIVES ●
Implement modifications
●
Implement modifications using the Modification Assistant
●
Implement modifications using user exits
●
Adjust modifications
© Copyright. All rights reserved.
225
Unit 8 Lesson 1 Modifying SAP Standard Software
LESSON OVERVIEW LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Implement modifications
Modifications – Overview
Figure 121: Modifications – Overview Diagram
The figure Modifications – Overview Diagram shows where modifications fit with the topics covered in this course.
226
© Copyright. All rights reserved.
Lesson: Modifying SAP Standard Software
Repository Objects - Originals and Copies
Figure 122: Repository Objects - Originals and Copies
A repository object is original in only one system. In the case of objects delivered by SAP, the original system belongs to SAP. In customer systems, these objects are only available as copies. This applies to your development system and all other systems that follow on from it. If you create your own applications and repository objects, the objects that you create are original in your development system. You assign your developments to a change request of the type Development/Correction. When released, this change request can be used to transport objects from the development system to subsequent systems. Corrections and Repairs
Figure 123: Corrections and Repairs
Changes to an original repository object are called corrections. Corrections are also recorded in a change request. The tasks of the change request are of the type Development/Correction.
© Copyright. All rights reserved.
227
Unit 8: Modifications of the SAP Standard Application
If you change a copy (an object outside of its own original system), the change is recorded in a task of the type Repair. Changes to SAP objects are called modifications. If a customer object needs to be changed (for example, as a consequence of an emergency in the production system), the change should always be made in the original system (that is the development system) to ensure that all systems remain consistent. The change can then be transported to subsequent systems in the landscape. However, you cannot do the same with SAP objects, because they are not original in any of your systems. You should only modify SAP repository objects if the modifications you want to make are really necessary.
Note: A good background knowledge of the application structure and flow is an essential prerequisite for deciding what kind of modifications to make, and how to design them. Modifications and Upgrades
Figure 124: Modifications and Upgrades
When you upgrade your system or apply a Support Package, conflicts can occur with modified objects. Conflicts occur when you have changed any SAP object and SAP also delivers a new version of it, which then becomes active in the repository. If you want to keep the changes you previously made, you must perform a modification adjustment for these objects. If you have many modified SAP objects, the modification adjustment can be very time consuming.
228
© Copyright. All rights reserved.
Lesson: Modifying SAP Standard Software
To ensure consistency between your development system and subsequent systems, you should only perform modification adjustments in your development system. The adjusted objects can then be transported into other systems in the landscape.
Modification Implementation
Figure 125: Registering Modifications in SSCR
The developer who will change the SAP standard objects must register those changes using SAP Software Change Registration (SSCR). For example, if changes are to be made to SAP source code, or manual changes will be made to ABAP Dictionary objects, each object to be changed must be registered. Registering the object will result in an access key being generated, which is needed when applying the changes to the object. (Matchcodes, database indexes, buffer settings, customer objects, patches, and objects, whose changes are based on automatic generation — for example, in Customizing — do not need to be registered.) If you change the object again later, the system will not ask for the registration key again. After you register an object, the system stores the related key locally and copies it automatically for later changes, regardless of which developer is making the change.These keys remain valid, even after a release upgrade. Benefits of SSCR ● Quick error resolution and high availability of modified systems SAP logs all the objects you changed. Based on this information, SAP’s first-level customer service can locate and fix problems quicker. This increases the availability of your ERP system. ●
Dependable operation Registering your modifications prevents unintended modification. This, in turn, promotes the dependable operation of your ERP software.
●
Simplification of upgrades Upgrades become easier due to the smaller number of modifications.
© Copyright. All rights reserved.
229
Unit 8: Modifications of the SAP Standard Application
Carrying out a Registered Modification
Figure 126: Carrying out a Registered Modification
If you want to change an SAP repository object, you must provide the following information when you make the change in the ABAP Workbench: ●
SSCR key
●
Change request
The figure shows the point at which the system will request the SSCR key. If you continue to change the object, you will see some dialog boxes displaying warning messages, which you must confirm to continue. At this point, you can still cancel the action without repairing the object. The system will then prompt you to assign the changes to a change request similar to those for your own objects. The system adds this object automatically to a repair task. The assignment to the change request has the following implications: ●
Change lock After the task has been assigned, only its owner can change the object.
●
Import lock The object cannot be overwritten by an import (upgrade or Support Package).
●
Version creation The system generates a new version of the object.
230
© Copyright. All rights reserved.
Lesson: Modifying SAP Standard Software
Post-Modification Steps
Figure 127: When the Modification is finished
After completing the development, the programmer releases the task. At this point, they should also document the changes made. The change lock and import lock are transferred to the change request to which the task belongs. If the developer confirms the repair, the import lock passes to the change request. If the developer does not confirm the repair when releasing the task, the import lock remains in place. Only the developer can release this lock. After completing the project, you release the change request. This removes all the object locks for the change request. This applies to both the change and import locks. When you release the change request, the system copies the objects from the database and stores them in a directory at operating system level. The system administrator then imports them into subsequent systems. After importing the modifications into the quality system, the developer should check the import log of the request.
© Copyright. All rights reserved.
231
Unit 8: Modifications of the SAP Standard Application
Versions
Figure 128: Versions
When you release a change request, a complete version of all objects contained inside it is written to the version database. If you transport the repository object again later, the current object becomes a complete copy. The system stores the differences between the old and the new object in the version database as a backwards delta. When you assign a repository object to a task, the system checks whether the current version matches the complete copy in the version database. If not, the system creates a complete copy. The system also initiates this process the first time you change an object, because SAP does not deliver versions of repository objects. The versions of a repository object provide the basis for modification adjustment. To support adjustment, the system stores information on whether SAP or the customer created the version. Critical Success Factors for Modifications
Figure 129: Critical Success Factors for Modifications
232
© Copyright. All rights reserved.
Lesson: Modifying SAP Standard Software
When performing modifications, it is best to encapsulate customer source code in modularization units instead of inserting it directly into the SAP source code (for example, by using customer function module calls in program source code, or customer subscreen calls for additional screen fields).
Note: Be careful to use narrow interfaces when you encapsulate customer-specific functions, in order to ensure good data control. More Critical Success Factors for Modifications Additional guidelines for performing modifications are as follows: ●
●
●
●
●
Use standardized in line documentation (supported by the Modification Assistant). Do not delete any SAP source code. Instead, comment it out (supported by the Modification Assistant). Keep a modification logbook (using the modification log from SE95 as a basis, for example). Do not modify any central Basis Dictionary objects (unless directed to by an SAP Note or the SAP Hotline). Release all requests that contain repairs before upgrade/support package installation.
SAP recommends that you define a company-wide standard for managing source code documentation for modifications. You also need to maintain a list of all the modifications (a modification log) in your system. Any modifications that you make to ABAP Dictionary objects that belong to SAP Basis components, such as the ABAP Workbench, are lost at upgrade. These objects revert to their initial form, and the system does not offer any adjustment help. This can lead to the loss of the content of certain tables. Before an upgrade/Support Package import, you have to release all requests that contain repairs.
© Copyright. All rights reserved.
233
Unit 8: Modifications of the SAP Standard Application
Modification Logs
Figure 130: Example of a Modification Log
SAP recommends that you maintain a record of all the modifications that have been made to your system. This includes all the changes that you have made to repository objects in the SAP namespace. At the very least, you should record the following information: ●
Object type, such as program, screen, GUI status, and so on
●
Object name
●
Routine (if applicable)
●
Subject area (according to process design blueprint or technical design)
●
Change request number for the repair
●
Change date
●
Changed by
●
Preliminary correction-Yes or No
●
SAP Note number, valid until Release X.Y (if applicable).
●
Estimated time to restore the modification during an adjustment
LESSON SUMMARY You should now be able to: ●
234
Implement modifications
© Copyright. All rights reserved.
Unit 8 Lesson 2 Modifying Applications using the Modification Assistant
LESSON OVERVIEW This lesson explains how the Modification Assistant and the Modification Browser work, and how to use these tools. Business Example You would like to use the Modification Assistant to make changes in an orderly manner to ensure that you can display an exact list of changes at a later stage, and make it easier to carry out modification adjustment. For this reason, you require the following knowledge: ●
An understanding of how to implement modifications using the Modification Assistant
●
An understanding of how the Modification Assistant works
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Implement modifications using the Modification Assistant
The Modification Assistant The aim of the Modification Assistant is to make modification easier. Previously, modifications were only recorded at the include program level. Now, a finer granularity is available and the system records modifications at the subroutine or module level. This is because the modifications are registered in a different layer. As a result, you can reset modifications more easily because the original version is not changed. Aims of the Modification Assistant ●
Making modification adjustments easier
●
Recording of changes at a more detailed level
●
Recording of changes in a separate layer, making the reset of modifications easier
© Copyright. All rights reserved.
235
Unit 8: Modifications of the SAP Standard Application
Modification Assistant – How it Works
Figure 131: Modification Assistant – How it Works
As just explained, the Modification Assistant records changes in a separate layer. This means that the original source code of the object does not change. The system does not adopt any modifications until the load is generated. When the load is generated, the system creates the executable object from both the original SAP program and the modifications. Modification Adjustments – Then and Now Table 5: Changes Due to the Modification Assistant THEN Granularity: Include program Modification adjustment: Line by line Each modification had to be included in the new SAP version manually (cut and paste)
NOW Granularity: Module (for example, subroutine) Modification adjustment: At module level
Previously, if you modified an include program for which SAP provided a new version in an upgrade, a modification adjustment was necessary. You had to perform the modification adjustment line by line, and the system did not provide much support. The Modification Assistant changes this situation. The granularity of the change recording has been refined. For example, if you modify only a subroutine, the rest of the include program remains unchanged. If SAP delivers a new version of the include program, the system checks if there is also a new version of the subroutine. If this is not the case, the system incorporates your changes into the new version automatically.
236
© Copyright. All rights reserved.
Lesson: Modifying Applications using the Modification Assistant
Modification Assistant – Software Layers
Figure 132: Modification Assistant – Software Layers
The original version of each software layer consists of the originals from the previous layer and the current modifications. Modification Assistant – Tools Supported Table 6: Tools Supported by the Modification Assistant Tool
Use of Modification Assistant
ABAP Editor
Modification mode
Screen Painter
Layout Flow logic
Menu Painter Text Elements Class Builder Function Builder
Adding function modules Compatible interface enhancements
ABAP Dictionary
Append structures are registered Data elements: field labels can be changed
Documentation
Substituting documentation objects
In the ABAP Editor, you can use modification mode to change the source code. Only a restricted range of functions is available in this mode. You can add, replace, or comment out source code; all controlled by the Modification Assistant. The Modification Assistant records changes to many different ABAP development objects. These include changes to the layout and flow logic in the Screen Painter, changes in the Menu Painter and text elements, and the addition of new function modules to an existing function
© Copyright. All rights reserved.
237
Unit 8: Modifications of the SAP Standard Application
group. To avoid conflicts when upgrading, table appends are also logged by the Modification Assistant. Modification Assistant – Prerequisites
Figure 133: Modification Assistant – Prerequisites
If you change an SAP object, you must provide the following information: ●
SAP Software Change Registration (SSCR) key
●
Change request
If it is switched on, the changes to the object will be under the control of the Modification Assistant. Only restricted functions are available in the editor. You can switch the Modification Assistant on or off for the entire system using the profile parameter eu/controlled_modification. However, SAP recommends that you always work with the Modification Assistant. (This is the default setting.) You can also switch off the Modification Assistant for a single repository object. Once again, this is not recommended as the changes will not be recorded to the same fine granularity level that is used in the Modification Assistant Modification Assistant Functions
Figure 134: Modification Assistant Functions
238
© Copyright. All rights reserved.
Lesson: Modifying Applications using the Modification Assistant
In modification mode, you cannot use all the normal functions of the tool you are working with. However, you can access them using the appropriate pushbuttons. As an example, the possible functions in the ABAP Editor are as follows: ●
Insert When you choose this function, the system generates two comment lines, between which you can enter your source code.
●
Replace When you position the cursor on a line and choose Replace, the system comments out the corresponding line and another line appears in which you can enter the code. If you want to replace several lines, mark them as a block first.
●
Delete By selecting a line or block of source code, and then choosing the Delete function, the lines will be commented out.
●
Undo modifications Choose this function to undo the selected modification that has been made to an object.
●
Display modification overview Choose this function to display an overview of all the modifications that belong to this object.
Modification Assistant – ABAP Editor Example
Figure 135: Modification Assistant – ABAP Editor Example
The figure shows the results of choosing the different functions using the Modification Assistant. The Modification Assistant automatically generates a framework of comment lines that describe the action. The comment also contains the number of the change request to which you assign the change, and an internal administration number.
© Copyright. All rights reserved.
239
Unit 8: Modifications of the SAP Standard Application
Modification Overview
Figure 136: Modification Overview
The Modification Overview button provides an overview of the modifications made in the current program. The display is divided according to the various modularization units. This corresponds to the structure used by the Modification Assistant to record the modifications. Restoration of the Original
Figure 137: Restoration of the Original
To undo a modification, place the cursor on it and choose Undo.
240
© Copyright. All rights reserved.
Lesson: Modifying Applications using the Modification Assistant
The system deletes the record for this modification. You cannot restore this record. Modification Browser
Figure 138: Modification Browser
The Modification Browser (transaction SE95) provides an overview of all of the modified objects in the system. The Modification Browser differentiates between modifications that you made using the Modification Assistant and modifications that you made without it. On the initial screen of the Modification Browser, you can restrict the selection according to various criteria. This allows you to find modifications easily, for example all modifications last changed by a certain user. The Modification Browser displays the list in tree form. The objects are arranged in the following manner: ●
Modification type (with or without Assistant)
●
Object type (PROG, DOMA, DTEL, TABL, ...)
In addition to the simple display functions, you can also use the Modification Browser to undo entire groups of modifications. To do this, select the desired subtree, and choose Reset to Original.
© Copyright. All rights reserved.
241
Unit 8: Modifications of the SAP Standard Application
242
© Copyright. All rights reserved.
Unit 8 Exercise 14 Implement Modifications
Business Example In supporting the SAP systems in your environment, you are required to modify some standard SAP repository objects to fulfill the requirements of the business. You need to use the Modification Assistant to implement these modifications.
Note: For this exercise, you will need to assign the changes which you make to a different transport request than the one which you have been using for other exercises in the course. The request will have the description Change request for exercise 20 - Implement Modifications. Please ask your instructor if you are not sure which transport request to use. Modify a Standard SAP Program 1. In the training system, find out the following details about program ADM325X## (replace ## with your group number). Which package does this program belong to? Which SAP system is the original system? 2. Using the Modification Assistant, modify program ADM325X## by adding the field AS4USER to the list of fields which the data retrieved from database table E070 is to be sorted by in line 38 of the source code as follows: ORDER BY STRKORR AS4USER TRKORR 3. Save and activate the program and assign it to the transport request created by your instructor for this exercise. Note: You will use a different transport request to the one you have been using in other exercises. 4. Check the Object Directory Entry for program ADM325X## and verify whether the Repair Flag is set. 5. Release your task. Note: Do not release your change request at this point.
© Copyright. All rights reserved.
243
Unit 8: Modifications of the SAP Standard Application
Modify an SAP Table 1. In the ABAP Dictionary, modify table ADM325X## by adding the following additional field (replace ## with group number). Field
Data Element
ZZBIRTHPLACE
GBORT
Note: Although technically additional fields can be added using an Append Structure, make sure that you modify the table directly, as in a later exercise you will explore the impact of modifications to Dictionary objects. 2. Activate the changes to table ADM325X## and assign them to the same transport request used in the previous task of this exercise. Note: You will be asked to assign the changes to a new task, since you have released the task you used earlier. 3. Add an entry to the table ADM325X## using the information in the table. Field (Technical Name)
Value
Reserve (PERSNR)
1234##
Description (NAME)
BC425 Group ##
Description (ANSCHRIFT)
BC425 Group ##
Number (GEBJAHR)
2014
Telephone no. (TELNO)
01234 567890
Birthplace (ZZBIRTHPLACE)
Frankfurt
4. Release your task and the transport request to which it belongst.
244
© Copyright. All rights reserved.
Unit 8 Solution 14 Implement Modifications
Business Example In supporting the SAP systems in your environment, you are required to modify some standard SAP repository objects to fulfill the requirements of the business. You need to use the Modification Assistant to implement these modifications.
Note: For this exercise, you will need to assign the changes which you make to a different transport request than the one which you have been using for other exercises in the course. The request will have the description Change request for exercise 20 - Implement Modifications. Please ask your instructor if you are not sure which transport request to use. Modify a Standard SAP Program 1. In the training system, find out the following details about program ADM325X## (replace ## with your group number). Which package does this program belong to? Which SAP system is the original system? a) Open transaction SE80. b) Select Program from the dropdown list and enter the program name ADM325X## (replace ## with your group number). c) Choose
(Display).
d) From the Menu, choose Goto → Object Directory Entry. The Display Object Directory Entry dialog box displays the package and the original system. The package for this object is ADM325 and the original system is KQG (this is the SAP system). e) Choose Continue to close the dialog box. 2. Using the Modification Assistant, modify program ADM325X## by adding the field AS4USER to the list of fields which the data retrieved from database table E070 is to be sorted by in line 38 of the source code as follows: ORDER BY STRKORR AS4USER TRKORR a) Make sure the program ADM325X## is still open in transaction SE80, and choose Change. b) An Information message will be displayed warning you about making repairs in foreign namespaces. Choose Continue.
© Copyright. All rights reserved.
245
Unit 8: Modifications of the SAP Standard Application
c) If the Modification Assistant dialog box appears, read the information and choose Continue. The ABAP Editor: Modify Report screen is displayed. d) On the ABAP Editor: Modify Report screen, position your cursor on Line 38 and choose Replace. e) Modify the code as follows: *{ *\ *}
REPLACE &$&$&$&$ ORDER BY STRKORR TRKORR. ORDER BY STRKORR AS4USER TRKORR. REPLACE
1
3. Save and activate the program and assign it to the transport request created by your instructor for this exercise. Note: You will use a different transport request to the one you have been using in other exercises. a) Choose Save. b) In the Prompt for Workbench request dialog box, use the input help to find the transport request which your instructor created for this exercise. If you are unsure which one to use, check with your instructor. c) Choose Continue. d) If the Create Task dialog box displays, choose Continue. e) Choose
(Activate). Note: Since the original system for this program is SAP, this type of change is referred to as a repair.
4. Check the Object Directory Entry for program ADM325X## and verify whether the Repair Flag is set. a) From the menu, choose Goto → Object Directory Entry. b) On the Display Object Directory Entry dialog box, choose (Object Attributes) to view all attributes and verify the value of the Repair Flag checkbox. Choose Continue 5. Release your task. Note: Do not release your change request at this point. a) In transaction SE80, choose Transport Organizer. b) Locate the transport request which you assigned your changes to, then expand the arrow to show all tasks belonging to this request.
246
© Copyright. All rights reserved.
Lesson: Modifying Applications using the Modification Assistant
c) Right-click your task number (which will be displayed next to your user ID BC425-## and labelled Repair) and choose Release. d) Do not release the top-level transport request yet.
Modify an SAP Table 1. In the ABAP Dictionary, modify table ADM325X## by adding the following additional field (replace ## with group number). Field
Data Element
ZZBIRTHPLACE
GBORT
Note: Although technically additional fields can be added using an Append Structure, make sure that you modify the table directly, as in a later exercise you will explore the impact of modifications to Dictionary objects. a) Go to transaction SE11. b) In the Database table field, enter ADM325X##. c) On the ABAP Dictionary: Initial Screen, choose
(Display <->Change).
d) An information message will be displayed warning you about making repairs in foreign namespaces. Choose Continue. e) In the Customer Modification: Different Original and Logon Languages dialog box, choose Maint. in logon lang.. f) On the Dictionary: Change Table screen, enter a suitable short description. g) Add a new field by entering the data from the table above on a blank line, then press ENTER. 2. Activate the changes to table ADM325X## and assign them to the same transport request used in the previous task of this exercise. Note: You will be asked to assign the changes to a new task, since you have released the task you used earlier. a) On the Dictionary: Change Table screen, activate the table by choosing
(Activate).
b) When prompted, assign the change to the same transport request that you used for the SAP program ADM325X##. c) When the Create Task dialog box is displayed, choose Continue to confirm the creation of a new task.
© Copyright. All rights reserved.
247
Unit 8: Modifications of the SAP Standard Application
Note: Once activated, the table status will be displayed as Active. 3. Add an entry to the table ADM325X## using the information in the table. Field (Technical Name)
Value
Reserve (PERSNR)
1234##
Description (NAME)
BC425 Group ##
Description (ANSCHRIFT)
BC425 Group ##
Number (GEBJAHR)
2014
Telephone no. (TELNO)
01234 567890
Birthplace (ZZBIRTHPLACE)
Frankfurt
a) On the Dictionary: Change Table screen, add a new table entry by choosing Utilities → Table Contents → Create Entries. b) In the Table Insert screen, add the data from the table. c) Choose the Save button to save your entries. 4. Release your task and the transport request to which it belongst. a) In SE80, choose Transport Organizer. b) Locate the transport request which you assigned your changes to, then expand the arrow to show all tasks belonging to this request. c) Right-click your task number (which will be displayed against your BC425-## user ID and labelled as a Repair) and choose Release. d) Right-click the top-level transport request and choose Release.
248
© Copyright. All rights reserved.
Lesson: Modifying Applications using the Modification Assistant
LESSON SUMMARY You should now be able to: ●
Implement modifications using the Modification Assistant
© Copyright. All rights reserved.
249
Unit 8 Lesson 3 Implementing User Exits
LESSON OVERVIEW This lesson explains how user exits work, and how you can find and use them to enhance SAP applications. Business Example You need to find user exits in the system and use them to enhance SAP software. For this reason, you require the following knowledge: ●
●
An understanding of user exits An understanding of how to find user exits in the system and use them to enhance SAP software
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Implement modifications using user exits
User Exits
Figure 139: User Exits – Structure of a Module Pool
SAP standard dialog transactions are based on ABAP programs with the Module Pool program type. A module pool is organized as a collection of include programs. This is a good approach for making the program easier to understand. The organization is similar to that of function groups.
250
© Copyright. All rights reserved.
Lesson: Implementing User Exits
The main program contains the include statements for all the include programs that belong to the module pool. SAP developers sometimes provided special Include programs in certain Module Pools. These special include programs contain the user exits which customers can implement. These special include programs are not technically different to the other include programs used in the module pool. They are only delivered once, and are intended for the implementation of the user exits - these implementations will not be overwritten by SAP. User Exits – Implementation
Figure 140: User Exits – Implementation
User exits are a type of enhancement that was originally developed for the Sales and Distribution (SD) component in SAP. The original purpose of user exits was to allow the user to avoid modification adjustment. Technically, using a user exit is a modification because it requires you to change objects in the SAP namespace. As described above, SAP developers create a special include program in a module pool. These include programs contain one or more subroutines that use the naming convention USEREXIT_. The calls of these subroutines have already been implemented by SAP within the standard application. The customer can therefore implement the subroutine and control what happens at the point when these subroutines are called. Usually, global variables are used. After delivering them, SAP never alters the Include programs which contain the user exit subroutines. If new user exits have to be delivered in a new release, they are placed in a new include program.
© Copyright. All rights reserved.
251
Unit 8: Modifications of the SAP Standard Application
User Exits – Example
Figure 141: User Exits – Example
User exits are empty subroutines that are provided by the SAP developers. You can fill them with your source code. Sometimes the SAP developer leaves some commented sample code in the user exit which can indicate the type of logic you can put there. As already described, the user exit subroutines are located in special Include programs. The last two characters of the Include program name indicate that it is for customer use and contains user exits. Example: Program SAPMV45A Include MV45AFZB This naming convention guarantees that SAP developers will not change this include in the future. Therefore, includes of this nature are never listed in modification adjustments.
252
© Copyright. All rights reserved.
Lesson: Implementing User Exits
User Exits – Search
Figure 142: User Exits – Search
You can find a list of all user exits in the SAP Reference Implementation Guide. Here, you can also find documentation explaining why SAP developers have created a particular user exit. LESSON SUMMARY You should now be able to: ●
Implement modifications using user exits
© Copyright. All rights reserved.
253
Unit 8 Lesson 4 Adjusting Modifications
LESSON OVERVIEW This lesson explains how to implement a modification adjustment. Business Example You need to carry out a modification adjustment after an upgrade or the application of a Support Package to your SAP system. For this reason, you require the following knowledge: ●
An understanding of the steps taken during a modification adjustment
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Adjust modifications
Modification Adjustment
Figure 143: Objects for Adjustment
The set of objects for adjustment is derived from the set of new objects delivered by SAP in a new release. This is compared with the set of modified objects. The intersection of the two is the set of objects that you must adjust when your SAP system is upgraded or a Support Package is imported.
254
© Copyright. All rights reserved.
Lesson: Adjusting Modifications
Modification Adjustment – SPDD and SPAU
Figure 144: Modification Adjustment – SPDD and SPAU
During modification adjustment, you can compare the old and new versions of ABAP repository objects using transactions SPDD and SPAU. Transaction SPDD is for comparison and adjustment of ABAP Dictionary objects, whereas transaction SPAU is used for the adjustment of other kinds of repository object. It is not necessary to call transaction SPDD during modification adjustment in the following cases:: ●
●
You did not make any changes to SAP standard objects in the Dictionary. You have only added customer dictionary objects to your system. You must adjust only SAP objects that you changed using this transaction.
You use transaction SPAU to adjust all other ABAP Repository objects. In the case of an update/upgrade, you have a maximum of 14 days to execute transaction SPAU without a key check (SAP Software Change Registration) for the objects that you changed. This guarantees that all actual adjustment work takes place only in your development system. Transaction SPAU first identifies the objects you modified and then ascertains the modified objects for which a new version was imported during the current upgrade. Modification adjustment allows you to transfer the modifications you have made in your system to your new system release.
© Copyright. All rights reserved.
255
Unit 8: Modifications of the SAP Standard Application
Modification Adjustment – Objects
Figure 145: Modification Adjustment – Objects
You use transaction SPDD to adjust ABAP Dictionary objects during modification adjustment. You can adjust the following types of ABAP Dictionary object: ●
Domains
●
Data elements
●
Tables (this includes structures, transparent tables, pooled, and cluster tables, together with their technical settings)
You adjust these object types directly after the Dictionary object import and before the main import. At this point in time, the system has not yet generated the new versions of the ABAP Dictionary objects. To ensure that no data is lost, it is important that you make any customer modifications to domains, data elements, or tables before you generate them. Changes to other ABAP Dictionary objects, such as lock objects, or views, cannot result in the loss of data. Therefore, you need to adjust these ABAP Dictionary objects using transaction SPAU after the main import and object generation have been completed. Transaction SPAU is used to adjust the following object types:
256
●
ABAP programs
●
Interfaces (menus)
●
Screens
●
Search helps
●
Views
●
Lock objects
© Copyright. All rights reserved.
Lesson: Adjusting Modifications
Transport of Adjustments Between Systems
Figure 146: Transport of Adjustments Between Systems
During modification adjustment, two separate transport requests are used when you process the objects: one for the SPDD adjustment and one for the SPAU adjustment. These change requests are then transported into the subsequent SAP systems in your landscape which you want to adjust. This guarantees that all actual adjustment work takes place only in your development system. To automatically transfer modifications to a subsequent SAP system when you have completed modification adjustment, use the Select for Transport function in SPDD or SPAU.
Note: For this process to be effective, it is important that all the systems involved have identical system landscapes. You can guarantee this by first making modifications in your development system, and then transporting them to subsequent systems before you upgrade the development system. You can also guarantee that all of your systems have an identical system landscape by creating your development system, before the upgrade, as a copy of your production system and then refraining from modifying the production system again.
© Copyright. All rights reserved.
257
Unit 8: Modifications of the SAP Standard Application
Modification Adjustment – Introduction
Figure 147: Modification Adjustment – Introduction
When you start modification adjustment using transaction SPAU, you can restrict the list of modifications to be displayed by making appropriate entries on the selection screen. You can decide whether you want to display all objects that need to be adjusted or only those that the system is yet to process. You can further restrict the selection of objects by using the following criteria: ●
Last changed by
●
Package
●
Request numbers/Task numbers
When you choose Execute, a list of the objects to be adjusted is displayed. The list is organized according to the following criteria:
258
●
With or without Modification Assistant
●
Object type
© Copyright. All rights reserved.
Lesson: Adjusting Modifications
Modification Adjustment Icons
Figure 148: Modification Adjustment Icons
The icons displayed in front of the individual objects that need adjustment show how they can be adjusted as follows: ●
Automatically The system could not find any conflicts. You can automatically adopt changes by choosing the appropriate icon or menu option.
●
Semi-automatically The relevant tools can be used to support you in adjusting the objects. For example, when you adjust a program, the Split Screen Editor is displayed, so you can make the changes there.
●
Manually You must process your modifications without any special support from the system. In this case, you can jump directly into the relevant tool.
Once adjustment has been performed, adjusted objects can be identified by a green tick. If you want to use the new SAP standard version, use Reset to Original, so that you do not have any adjustment work in the future.
© Copyright. All rights reserved.
259
Unit 8: Modifications of the SAP Standard Application
260
© Copyright. All rights reserved.
Unit 8 Exercise 15 Perform Modification Adjustment with Transaction SPDD
Business Example Most companies apply support packages on a regular basis to keep their SAP systems up to date. During the import of these support packages, the system checks the affected SAP repository objects to see if modification adjustments are required. As a developer, you need to know how to perform modification adjustments when needed using transaction SPDD.
Note: Your instructor has imported a support package before this exercise. The SAP tables and programs that you modified in the previous exercise Implement Modifications will cause some issues during the import and in this exercise you need to perform modification adjustments to fix these issues. Do not start this exercise until your instructor has imported the support package. Adjust Dictionary Objects Using Transaction SPDD 1. Perform modification adjustment on your table ADM325X## using transaction SPDD. Accept SAP’s proposal to create an Append Structure for the ZZBIRTHPLACE field. Assign your settings to the SPDD transport request provided by your instructor and release your task at the end.
© Copyright. All rights reserved.
261
Unit 8 Solution 15 Perform Modification Adjustment with Transaction SPDD
Business Example Most companies apply support packages on a regular basis to keep their SAP systems up to date. During the import of these support packages, the system checks the affected SAP repository objects to see if modification adjustments are required. As a developer, you need to know how to perform modification adjustments when needed using transaction SPDD.
Note: Your instructor has imported a support package before this exercise. The SAP tables and programs that you modified in the previous exercise Implement Modifications will cause some issues during the import and in this exercise you need to perform modification adjustments to fix these issues. Do not start this exercise until your instructor has imported the support package. Adjust Dictionary Objects Using Transaction SPDD 1. Perform modification adjustment on your table ADM325X## using transaction SPDD. Accept SAP’s proposal to create an Append Structure for the ZZBIRTHPLACE field. Assign your settings to the SPDD transport request provided by your instructor and release your task at the end. a) In client 800 of your training system, go to transaction SPDD. b) On the Modification Adjustment Dictionary: Object Selection screen, under the Selections area, in the Last changed by field, enter your user ID (BC425-##) and choose Execute. c) To display the objects requiring adjustment in the Modification Adjustment Dictionary screen, select the node Without Modification Assistant and choose (Expand Subtree). d) You should see the table that you modified in the previous exercise with a yellow traffic light. To check what the yellow status means, choose (Color Legend). Choose Continue to close the window. e) On the Modification Adjustment Dictionary screen, select the yellow traffic light icon for object ADM325X##. f) On the Adjustment for Table: Phase 1 screen, choose Accept Proposal.
262
© Copyright. All rights reserved.
Lesson: Adjusting Modifications
Note: The proposal is to keep the columns delivered by SAP and move your customer fields into a new append structure. The append structure is not a modification, but rather an enhancement. After the adjustment, your customer fields are in the append structure so the table can be reset. g) On the Append for table dialog box, accept the name of the Append Structure and choose Continue. h) On the Create Object Directory Entry dialog box, enter your package name in the Package field and choose Save. i) On the Prompt for transportable Workbench request screen, assign the modification to the transport request created by the instructor for SPDD adjustment. If you are not sure what transport request to use, ask your instructor. All participants must use the same transport request. j) If the Log display screen appears with warnings about the enhancement category for the append structure, choose
(Back).
k) On the Adjustment for Table : Phase 2 dialog box, chooseBack. l) On the Information dialog box, choose Continue. m) On the Reset to Original dialog box, choose Yes. n) On the Information dialog box, choose Continue. o) Assign your settings to the SPDD transport request (again, ask your instructor if you are not sure which transport request to use). p) In the Create Task dialog box, choose Continue. Note: The object ADM325X## now contains your previous modification (the ZZBIRTHPLACE field) in an append structure. q) To release your task, go to transaction SE80 and choose Transport Organizer. r) Find the transport request which you just assigned your adjustments to. Release all tasks assigned to your user ID by right-clicking and choosing Release. Note: Do not release the top-level transport request.
© Copyright. All rights reserved.
263
Unit 8: Modifications of the SAP Standard Application
264
© Copyright. All rights reserved.
Unit 8 Exercise 16 Perform Modification Adjustment with Transaction SPAU
Business Example Most companies apply support packages on a regular basis to keep their SAP systems up to date. During the import of the support packages, the system checks the SAP repository objects to see if modifications adjustments are required. As a developer, you need know how to perform the modification adjustments when needed using transaction SPAU.
Note: Do not start this exercise until your instructor has completed the corresponding demonstration and tells you that they have completed all necessary preparation steps. Your instructor will have imported a support package before this exercise. The SAP programs that you have modified in an earlier exercise will require adjustment during the import. 1. Perform modification adjustment on the SAP program ADM325X## using transaction SPAU and choose the option Reset to original object. Assign your object to the transport request provided by the instructor and release your task at the end.
© Copyright. All rights reserved.
265
Unit 8 Solution 16 Perform Modification Adjustment with Transaction SPAU
Business Example Most companies apply support packages on a regular basis to keep their SAP systems up to date. During the import of the support packages, the system checks the SAP repository objects to see if modifications adjustments are required. As a developer, you need know how to perform the modification adjustments when needed using transaction SPAU.
Note: Do not start this exercise until your instructor has completed the corresponding demonstration and tells you that they have completed all necessary preparation steps. Your instructor will have imported a support package before this exercise. The SAP programs that you have modified in an earlier exercise will require adjustment during the import. 1. Perform modification adjustment on the SAP program ADM325X## using transaction SPAU and choose the option Reset to original object. Assign your object to the transport request provided by the instructor and release your task at the end. a) In client 800 of your training system, go to transaction SPAU. b) On the Modification Adjustment: Object Selection screen, in the Last changed by field under the Selections area, enter your user ID and choose Execute. c) Put your cursor on the With Modification Assistant node and select (Expand Subtree). You will see the program that you modified in the exercise Implement Modifications listed, with a green traffic light d) For an explanation of the status on the object, choose
(Color Legend).
e) On the Modification Adjustment screen, position your cursor on the object (ADM325X##) and choose Modifications → Reset to Original f) In the Reset object dialog box, choose Continue. g) In the Information dialog box, choose Continue. h) On the Prompt for transportable Workbench request dialog box, assign the settings to the transport request created by your instructor for the SPAU adjustments. If you are not sure which transport request to choose, ask your instructor. Choose Continue. i) If you are prompted to create a new task for the request, choose Continue.
266
© Copyright. All rights reserved.
Lesson: Adjusting Modifications
j) On the Set Processor/Status dialog box, select the Completed checkbox for all entries. k) Choose Copy. The Modification Adjustment screen displays, and the program will now be displayed with the Original has been restored icon l) To release your task, go to transaction SE80 and choose Transport Organizer. m) Find the SPAU transport request which you just assigned your settings to. Release all tasks assigned to your user ID by right-clicking and choosing Release. Note: Do not release the transport request.
© Copyright. All rights reserved.
267
Unit 8: Modifications of the SAP Standard Application
LESSON SUMMARY You should now be able to: ●
268
Adjust modifications
© Copyright. All rights reserved.
Unit 8 Learning Assessment
1. What are some of the benefits of SSCR (SAP Software Change Registration) for registering modifications? Choose the correct answers. X
A Quick error resolution
X
B Simplification of upgrades
X
C Dependable operation
X
D SSCR key given to an object, needs to be given again and again for each modification
2. Which of the following tools are supported by the Modification Assistant? Choose the correct answers. X
A ABAP Editor
X
B Screen Painter
X
C Menu Builder
X
D ABAP Dictionary
3. Which of the following are reasons why SAP provided user exits? Choose the correct answers. X
A Provide enhancements for Sales and Distribution applications.
X
B Provide enhancements to prevent modifications.
X
C Enable multiple independent implementations.
X
D Ensure smooth upgrades.
© Copyright. All rights reserved.
269
Unit 8: Learning Assessment
4. During modification adjustment, which transactions can you use to compare the old and new versions of ABAP Repository objects? Choose the correct answers.
270
X
A SPDD
X
B SSCR
X
C SPAU
© Copyright. All rights reserved.
Unit 8 Learning Assessment - Answers
1. What are some of the benefits of SSCR (SAP Software Change Registration) for registering modifications? Choose the correct answers. X
A Quick error resolution
X
B Simplification of upgrades
X
C Dependable operation
X
D SSCR key given to an object, needs to be given again and again for each modification
2. Which of the following tools are supported by the Modification Assistant? Choose the correct answers. X
A ABAP Editor
X
B Screen Painter
X
C Menu Builder
X
D ABAP Dictionary
3. Which of the following are reasons why SAP provided user exits? Choose the correct answers. X
A Provide enhancements for Sales and Distribution applications.
X
B Provide enhancements to prevent modifications.
X
C Enable multiple independent implementations.
X
D Ensure smooth upgrades.
© Copyright. All rights reserved.
271
Unit 8: Learning Assessment - Answers
4. During modification adjustment, which transactions can you use to compare the old and new versions of ABAP Repository objects? Choose the correct answers.
272
X
A SPDD
X
B SSCR
X
C SPAU
© Copyright. All rights reserved.
UNIT 9
Introduction to Web Dynpro
Lesson 1 Outlining the Benefits of Web Dynpro
274
Lesson 2 Displaying Web Dynpro Component Architecture Exercise 17: Create a Simple Web Dynpro
278 283
Lesson 3 Navigating Between Views Exercise 18: Set Up Navigation Between Views
289 291
Lesson 4 Creating View Assemblies Exercise 19: Create View Assemblies
298 301
Lesson 5 Identifying Web Dynpro Entities and Relationships
307
UNIT OBJECTIVES ●
Describe the programming approach of Web Dynpro
●
Identify the benefits of the metadata approach of Web Dynpro
●
Explain the main elements of Web Dynpro
●
Explain the context and data transport
●
Set up navigation between views
●
Create view assemblies
●
Differentiate between internally and externally visible Web Dynpro entities
© Copyright. All rights reserved.
273
Unit 9 Lesson 1 Outlining the Benefits of Web Dynpro
LESSON OVERVIEW This lesson describes the programming approach of Web Dynpro and the benefits of the metadata approach of Web Dynpro. Business Example You want to find a technology that is best suited to developing ABAP based Web applications. The requirements for your projects are high speed, low cost, and standardized UI elements. You have heard that Web Dynpro ABAP is a good candidate. Therefore, you want to get an initial overview of Web Dynpro functionality. For this reason, you require the following knowledge: ●
●
An understanding of the programming approach that is used to create Web Dynpro applications An understanding of the benefits of the metadata approach of Web Dynpro
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Describe the programming approach of Web Dynpro
●
Identify the benefits of the metadata approach of Web Dynpro
Introduction to Web Dynpro SAP’s Web Dynpro for Java and ABAP is a revolutionary step in the development of Webbased UIs. Unlike any other design paradigm used by SAP, it represents a quantum leap in the development of Web-based Enterprise Resource Planning (ERP) applications. Web Dynpro applications are built using declarative programming techniques based on the Model View Controller (MVC) paradigm. That is, you specify which UI elements you want on the client and where these elements get their data from. You also define the possible navigation paths declaratively in your application. A standard runtime framework generates all the code to create the UI automatically, relieving you of the repetitive coding tasks involved in writing HTML and making it interactive with JavaScript. Web Dynpro ABAP has been available since SAP NetWeaver Application Server 7.0. To develop the entities of a Web Dynpro application, the O bject Navigator (transaction code SE80 ) has been enhanced. Web Dynpro is designed to support structured development. The software modularization units are Web Dynpro components, which can be combined to create complex applications.
274
© Copyright. All rights reserved.
Lesson: Outlining the Benefits of Web Dynpro
Meta Model Declarations and Custom Coding – Comparison
Figure 149: Meta Model Declarations Versus Custom Coding
A Web Dynpro application is developed using a declarative programming approach. In the ABAP Workbench, there are special tools that allow you to build an abstract representation of an application in the form of a Web Dynpro meta model. The necessary source code is then generated automatically and conforms to a standard architecture known as the Web Dynpro framework. The Web Dynpro framework allows you to place the custom source code at predefined positions within the generated code. All Web Dynpro applications are constructed from the same basic units. However, by using custom coding, the standard framework can be extended to supply any required business function. Not all implementation decisions are made at design time. It is possible to implement a Web Dynpro application in which the UI is defined at runtime. This enables you to write highly flexible applications without the need to write any HTML or JavaScript coding.
© Copyright. All rights reserved.
275
Unit 9: Introduction to Web Dynpro
Application Scenarios with Web Dynpro
Figure 150: Examples of Application Scenarios with Web Dynpro
The figure shows that Web Dynpro applications can access various data sources. A Web Dynpro ABAP application can address all kinds of reuse components directly. ●
Methods of global classes defined in your system.
●
Function modules defined in your system or (through RFC) in back-end system.
●
Web services through a Web service client object.
Caution: Do not place a SELECT statement in your controller methods directly because this leads to a mixing between flow logic and business logic. Model objects are not yet supported in Web Dynpro ABAP. The best way to have reusable entities encapsulating business logic is to create global ABAP classes containing the source code. You can develop UI-free (faceless) Web Dynpro components, where only the non visual parts of the component can be accessed by other Web Dynpro components through component reuse.
276
© Copyright. All rights reserved.
Lesson: Outlining the Benefits of Web Dynpro
Benefits of Web Dynpro
Figure 151: Web Dynpro Benefits
The main goal of Web Dynpro is to enable application developers to create powerful web applications with minimal effort, using descriptive tools in a structured design process. The Web Dynpro Philosophy According to the Web Dynpro philosophy, it is better to have fewer lines of hand written code. Web Dynpro pursues its philosophy in the following ways: ● Web Dynpro uses a declarative meta model for defining UIs. The development environment generates the required source code from this abstract definition. You can also manipulate the UI from the source code, which is necessary to implement dynamic changes that are not known at design time. ●
●
Web Dynpro provides technical features, such as support for internationalization, flickerfree interaction, and a clean separation of the business logic and the UI. This separation is achieved through a modified implementation of the MVC design paradigm. Web Dynpro provides wizards that support the definition of forms and tables in the UI and source code in the controller methods. Using these wizards reduces the development effort significantly.
Because the repetitive tasks of UI coding have been eliminated, the developer can focus more on the flow of business data through the application. LESSON SUMMARY You should now be able to: ●
Describe the programming approach of Web Dynpro
●
Identify the benefits of the metadata approach of Web Dynpro
© Copyright. All rights reserved.
277
Unit 9 Lesson 2 Displaying Web Dynpro Component Architecture
LESSON OVERVIEW This lesson explains the Web Dynpro architecture and its main elements. This lesson also describes how data transport works in Web Dynpro. Business Example You need to structure complex Web applications, nest large application sections, and develop reusable entities for your project. For this reason, you require the following knowledge: ●
An understanding of Web Dynpro components
●
An understanding of the context and data transport
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Explain the main elements of Web Dynpro
●
Explain the context and data transport
Web Dynpro Component
Figure 152: Web Dynpro Component
Web Dynpro components are containers for other entities related to a UI and a Web Dynpro program.
278
© Copyright. All rights reserved.
Lesson: Displaying Web Dynpro Component Architecture
Entities related to the UI are windows and views. The layout of a view is the rectangular part of a page displayed by the client, for example, a browser. The view contains UI elements, such as input fields and buttons. The complete page sent to the client can be set up by only one view, but can also be a combination of multiple views. The possible combinations of views and the flow between the views are defined in a window. A window can contain any number of views. A view can be embedded in any number of windows. The Web Dynpro source code is located in Web Dynpro controllers. Global variables of controllers are defined as controller attributes. Global data related to the UI (displayed by elements on the UI or used to manipulate the UI element properties) is stored in a hierarchical storage area called the context. Addressing the Web Dynpro Components Web Dynpro components can be addressed in the following ways: ● By using a Web Dynpro application, you can link a Web Dynpro component to a URL, which you can call from a web browser or another Web Dynpro client. ●
●
When reusing a Web Dynpro component as a subcomponent, you can combine the visual interface of a Web Dynpro component with the visual entities of the main component to form the UI. When reusing a Web Dynpro component as a subcomponent, the main component can access all methods and the data defined in the programming interface.
Context and Data Binding
Figure 153: Context and Data Transport
Connecting the values of UI elements that allow user input to the context attributes of the corresponding controller is called data binding. By using data binding, you can establish an automatic data transport between the UI elements and the context attributes. Referencing the variables defined in a Web Dynpro controller from other Web Dynpro controllers is called context mapping. Context mapping allows you to share common data between different controllers, so copying this data between controller contexts is not necessary.
© Copyright. All rights reserved.
279
Unit 9: Introduction to Web Dynpro
Combining these two concepts, data transport between UI elements located in various views can be defined in a purely declarative way. Context Mapping
Figure 154: Data Sharing Using Context Mapping
Context mapping allows a context node in one controller to be supplied automatically with data from a corresponding context node in another controller. This is the primary mechanism for sharing data between controllers. The prerequisites for establishing a mapping relationship are as follows: ● A node must exist in the context of the controller acting as the mapping origin. This node may also have child nodes or attributes. ●
●
280
The mapping origin controller must not be a view controller. The controller containing the mapped node must declare the use of the mapping origin controller as a used controller.
© Copyright. All rights reserved.
Lesson: Displaying Web Dynpro Component Architecture
Data Binding
Figure 155: Putting Data on the Screen – Data Binding
Data binding is the means by which data is automatically transported to and from a UI element in its layout. You may not bind the UI elements to the context nodes or attributes defined in another controller. UI elements are private to the view controller in which they are declared. The Data Binding Process The data binding process separates the UI element object from the application code in the view controller. Therefore, to manipulate UI element properties, the application code in the view controller needs only to manipulate the values of the context nodes, and the attributes to which the UI elements are bound. The Web Dynpro framework then performs the following tasks: It transports data from the context attribute to the UI element during the screen rendering process.
●
●
It repopulates the context attribute from the UI element after data has been entered and the next server round trip is initiated. The values entered are automatically converted and checked for type conformity. If an error occurs, an appropriate message is displayed.
Data binding is a powerful tool because not only can the value of a UI element be bound to a context attribute, but the properties of a UI element can also be bound, for example, visibility. This means that UI element properties can be manipulated from the view controller by acting on the context attributes.
© Copyright. All rights reserved.
281
Unit 9: Introduction to Web Dynpro
282
© Copyright. All rights reserved.
Unit 9 Exercise 17 Create a Simple Web Dynpro
Business Example Develop a Web Dynpro application. Start by creating the Web Dynpro entities that are mandatory for an application that displays a page with a simple text field. Template: N/A Solution: NET310_INTR_S Create a Web Dynpro component with a window embedding a single view, define a simple UI element on the view layout, and edit its properties. Create a Package Create a package that will contain all the repository objects you are going to develop. 1. Create package ZNET310_## . Assign application component BC-WD-ABA and the software component HOME to your package. Create a Web Dynpro Component Create a Web Dynpro component with a window embedding a single view. 1. Create a Web Dynpro component ZNET310_INTR_## with a window MAIN_WINDOW embedding a single view MAIN_VIEW . 2. What other Web Dynpro entities are displayed in the object tree of the ABAP Workbench after you have created the Web Dynpro component?
Create a UI Element that Displays Text in the Layout of the View Create a simple TEXTVIEW UI element that displays an arbitrary text in the layout of the view MAIN_VIEW . 1. Create a simple UI element ( TEXTVIEW ) of type TextView in the layout of the view MAIN_VIEW , and edit its properties. 2. Maintain the text to be displayed in the TEXTVIEW UI element. You may want to change some other properties of the element and see the result on the layout preview. 3. Activate the Web Dynpro component. Create a Web Dynpro Application to Access your Web Dynpro Component Create a Web Dynpro application to access your Web Dynpro component. Start the application. 1. Create a Web Dynpro application (suggested name: ZNET310_INTR_## ) that accesses the only existing window of your Web Dynpro component.
© Copyright. All rights reserved.
283
Unit 9: Introduction to Web Dynpro
2. Test the Web Dynpro application.
284
© Copyright. All rights reserved.
Unit 9 Solution 17 Create a Simple Web Dynpro
Business Example Develop a Web Dynpro application. Start by creating the Web Dynpro entities that are mandatory for an application that displays a page with a simple text field. Template: N/A Solution: NET310_INTR_S Create a Web Dynpro component with a window embedding a single view, define a simple UI element on the view layout, and edit its properties. Create a Package Create a package that will contain all the repository objects you are going to develop. 1. Create package ZNET310_## . Assign application component BC-WD-ABA and the software component HOME to your package. a) On the SAP Easy Access ABAP Workbench screen, choose Tools → ABAP Workbench → Overview → Object Navigator . You can also use transaction code SE80. b) On the Object Navigator screen, create package ZNET310_## . c) In the Create Package dialog box by selecting Package from the drop-down menu, typing the package name and pressing Enter. d) On the Create Pack. dialog box, choose Yes . e) Enter the following data: Field Name
Value
Package
ZNET310_##
Short Description
Web Dynpro Pack
Application Component
BC-WD-ABA
Software Component
HOME
f) Choose the Continue button. g) On the Prompt for transportable Workbench request dialog box, choose the request created by your instructor and choose Continue . h) On the Create Task dialog box, choose Continue . Create a Web Dynpro Component Create a Web Dynpro component with a window embedding a single view.
© Copyright. All rights reserved.
285
Unit 9: Introduction to Web Dynpro
1. Create a Web Dynpro component ZNET310_INTR_## with a window MAIN_WINDOW embedding a single view MAIN_VIEW . a) In the context menu (right-click) of the package ZNET310_## , choose Create → Web Dynpro → Web Dynpro Component (Interface). b) In the Web Dynpro: Component/Create Interface dialog box, enter the following data: Field Name
Value
Name
ZNET310_INTR_##
Description
Web Dynpro Component
Type
Web Dynpro Component
Window Name
Main_Window
View Name
Main_View
c) Choose Continue . d) In the Create Object Directory Entry dialog box choose the package you just created. Save your selection. e) On the Prompt for transportable Workbench request dialog box, choose the request created by your instructor and choose Continue . 2. What other Web Dynpro entities are displayed in the object tree of the ABAP Workbench after you have created the Web Dynpro component? The other Web Dynpro entities that are displayed in the object tree of the ABAP Workbench after you have created the Web Dynpro component are: a component controller, an interface controller, an interface view for the window, and a global interface ZIWCI_NET310_INTR_##. Create a UI Element that Displays Text in the Layout of the View Create a simple TEXTVIEW UI element that displays an arbitrary text in the layout of the view MAIN_VIEW . 1. Create a simple UI element ( TEXTVIEW ) of type TextView in the layout of the view MAIN_VIEW , and edit its properties. a) In the object tree of the component ZNET310_INTR_## , open the View folder, then double-click MAIN_VIEW . b) If the view is in display mode, on the Web Dynpro Explorer toolbar, choose Display<-> Change . On the Layout tab page, right click ROOTUIELEMENTCONTAINER , and choose Insert Element . c) In the Create Element dialog box, enter TEXTVIEW as the element Name and set the element Typ to TextView . d) Choose Continue . 2. Maintain the text to be displayed in the TEXTVIEW UI element. You may want to change some other properties of the element and see the result on the layout preview. a) In the UI element hierarchy, choose the TEXTVIEW UI element.
286
© Copyright. All rights reserved.
Lesson: Displaying Web Dynpro Component Architecture
b) In the properties list, enter any text in the text field. c) You can change other properties if desired. d) Choose Save . 3. Activate the Web Dynpro component. a) Double-click the Web Dynpro component ZNET310_INTR_## , then right-click ZNET310_INTR and choose Activate. b) In the Inactive Objects for NET310-## dialog box, you find that the inactive parts of your component are selected. c) Choose Save . Create a Web Dynpro Application to Access your Web Dynpro Component Create a Web Dynpro application to access your Web Dynpro component. Start the application. 1. Create a Web Dynpro application (suggested name: ZNET310_INTR_## ) that accesses the only existing window of your Web Dynpro component. a) In the context menu of the Web Dynpro component ZNET310_INTR_## , choose Create → Web Dynpro Application. b) In the Create Web Dynpro Application dialog box, enter the following data: Field Name
Value
Application
ZNET310_INTR_##
Description
WD Application
c) Choose Continue. d) Save your entry. e) If you see a Create Administration Service window, deselect Administration Service and choose Apply . f) On the Web Dynpro Explorer: Create Web Dynpro Application screen, choose Save. g) On the Prompt for transportable Workbench request window, choose Continue. 2. Test the Web Dynpro application. a) Right-click the Web Dynpro application ZNET310_INTR_## and choose Test to open a browser window and start the application.
© Copyright. All rights reserved.
287
Unit 9: Introduction to Web Dynpro
LESSON SUMMARY You should now be able to:
288
●
Explain the main elements of Web Dynpro
●
Explain the context and data transport
© Copyright. All rights reserved.
Unit 9 Lesson 3 Navigating Between Views
LESSON OVERVIEW This lesson explains the principle of navigation and the ways to navigate between views. Business Example You want to understand how navigation between views works in Web Dynpro, so you can create an application where the user moves from one page to another by pushing buttons. For this reason you need the following knowledge: ●
An understanding of navigation between views
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Set up navigation between views
Principles of Navigation
Figure 156: Navigation Principle
Navigation between views is triggered by firing outbound plugs. Firing an outbound plug raises a navigation event. Navigation events are special asynchronous events that are placed into a navigation queue. Multiple outbound plugs can be fired from one view, which ones are used determines the next UI. The navigation queue is processed at certain points of time in the Web Dynpro processing phase. Until this time, the navigation stack can be extended by firing additional outbound plugs, or the complete navigation stack can be deleted. Outbound
© Copyright. All rights reserved.
289
Unit 9: Introduction to Web Dynpro
plugs are named according to the action that caused the navigation away from the current view. Inbound and Outbound Plugs
Figure 157: Navigation Between Views
Inbound plugs have special event handler methods that subscribe to the navigation events raised when outbound plugs are fired. Inbound plug methods are called only when the navigation queue is processed. This only takes place after the views in the current view assembly have fired their outbound plugs and no validation errors occur that can cancel navigation. Inbound plugs should be named according to the reason the view is displayed. Outbound and inbound plugs are joined together using navigation links. Linking an inbound plug to an outbound plug means registering the inbound plug event handler method to the navigation event that is called by firing an outbound plug. Navigation links are defined in a window. Outbound plugs and event handler methods related to the inbound plug can have parameters, allowing you to pass data between the views. An action is used to link a client-side event to an event handler method (automatically defined with the action) in the corresponding view controller.
290
© Copyright. All rights reserved.
Unit 9 Exercise 18 Set Up Navigation Between Views
Business Example You want to develop a Web Dynpro application with more than one view. To do this, you define buttons on the layouts of each view to allow the user to navigate between the views. Template: N/A Solution: NET310_CTRL_S Define buttons and implement navigation between Web Dynpro views. Create a Web Dynpro Component Create a Web Dynpro component containing a window and two views. 1. Create Web Dynpro component ZNET310_CTRL_## with a window, MAIN_WINDOW, and a view, INPUT_VIEW. Perform this step as in the exercise, Create a Simple Web Dynpro. 2. Create an additional view (OUTPUT_VIEW) inside your component and embed this view into the MAIN_WINDOW. Create Outbound Plug and Inbound Plug Create an outbound plug and inbound plug for each view. Define two navigation links between the two views, each link going from the outbound plug of one view to the inbound plug of the other view. 1. For your first view (INPUT_VIEW), create an outbound plug (OUT_DETAILS) and inbound plug (IN_DEFAULT). 2. What are the new parts created in the view controller by completing the previous step (refer to the various tab pages of the view)?
3. For the OUTPUT_VIEW, create the outbound plug OUT_BACK and the inbound plug IN_DEFAULT. 4. Edit your window. Define a navigation link from the outbound plug (OUT_DETAILS) of INPUT_VIEW to the inbound plug (IN_DEFAULT) of OUTPUT_VIEW. 5. Define a navigation link from the outbound plug (OUT_BACK) of OUTPUT_VIEW to the inbound plug (IN_DEFAULT) of INPUT_VIEW.
Define a Button on each View Define a button on each of the two views and make sure that the outbound plug of the respective view is fired when the user presses the button.
© Copyright. All rights reserved.
291
Unit 9: Introduction to Web Dynpro
1. Create a simple UI element of type, BUTTON, with the name, BUT_DETAILS, on the layout of view, INPUT_VIEW. Maintain the text to be displayed on the button. 2. Create an action for the button with the name, DISPLAY_DETAILS. Assign this action to the BUT_DETAILS button. If the user chooses this button, the outbound plug OUT_DETAILS is fired. 3. What are the new parts created in the view controller by the previous step (refer to the various tab pages of the view)?
4. Create a button in the view OUTPUT_VIEW with the name BUT_BACK. Set the text to be displayed on the button and assign an action with the name BACK to the property onAction. Make sure that the outbound plug OUT_BACK is fired when the user chooses the button. Activate your Component Create an application to access your component and start the application. 1. Activate your component and all contained component entities. 2. Create a Web Dynpro application for your component. Start the application.
292
© Copyright. All rights reserved.
Unit 9 Solution 18 Set Up Navigation Between Views
Business Example You want to develop a Web Dynpro application with more than one view. To do this, you define buttons on the layouts of each view to allow the user to navigate between the views. Template: N/A Solution: NET310_CTRL_S Define buttons and implement navigation between Web Dynpro views. Create a Web Dynpro Component Create a Web Dynpro component containing a window and two views. 1. Create Web Dynpro component ZNET310_CTRL_## with a window, MAIN_WINDOW, and a view, INPUT_VIEW. Perform this step as in the exercise, Create a Simple Web Dynpro. a) In the Web Dynpro: Component/Create Interface dialog box, enter the following data: Field Name
Value
Name
ZNET310_CTRL_##
Description
WD Component
Type
Web Dynpro Component
Window Name
MAIN_WINDOW
View Name
INPUT_VIEW
2. Create an additional view (OUTPUT_VIEW) inside your component and embed this view into the MAIN_WINDOW. a) Right-click the component ZNET310_CTRL_##, choose Create → View. b) In the Create View dialog box, enter the following data: Field Name
Value
Component
ZNET310_CTRL_##
View
OUTPUT_VIEW
Description
Output_View
c) Choose Continue. d) Save your entry.
© Copyright. All rights reserved.
293
Unit 9: Introduction to Web Dynpro
e) In the object tree of component ZNET310_CTRL_##, choose Windows, and doubleclick MAIN_WINDOW. f) In the overview screen of the MAIN_WINDOW, ensure that the window structure is displayed hierarchically (if it is not, choose the Switch Window Editor View button ). g) From the object tree of the ABAP workbench, expand Views and drag OUTPUT_VIEW of the component ZNET310_CTRL_## onto the root node of MAIN_WINDOW in the Window Structure panel. h) Save your entries. Create Outbound Plug and Inbound Plug Create an outbound plug and inbound plug for each view. Define two navigation links between the two views, each link going from the outbound plug of one view to the inbound plug of the other view. 1. For your first view (INPUT_VIEW), create an outbound plug (OUT_DETAILS) and inbound plug (IN_DEFAULT). a) In the object tree of the component ZNET310_CTRL_##, choose Views and doubleclick INPUT_VIEW. b) In the overview screen of the INPUT_VIEW, choose the Outbound Plugs tab page and enter the following data: Field Name
Value
Plug Name
OUT_DETAILS
Description
outward
c) Choose the Inbound Plugs tab page and enter the following data: Field Name
Value
Plug Name
IN_DEFAULT
Description
inward
d) Save your entries. 2. What are the new parts created in the view controller by completing the previous step (refer to the various tab pages of the view)? The event handler method "HANDLEIN_DEFAULT” (empty) is the new part that is created in the view controller by completing the previous step. 3. For the OUTPUT_VIEW, create the outbound plug OUT_BACK and the inbound plug IN_DEFAULT. a) Perform this step as in step 1. b) Save your entries. 4. Edit your window. Define a navigation link from the outbound plug (OUT_DETAILS) of INPUT_VIEW to the inbound plug (IN_DEFAULT) of OUTPUT_VIEW.
294
© Copyright. All rights reserved.
Lesson: Navigating Between Views
a) In the object tree of the component ZNET310_CTRL_##, choose Windows and doubleclick MAIN_WINDOW. b) In the overview screen of MAIN_WINDOW, choose the Window tab page and expand all nodes of the window structure. c) Ensure that the window structure is displayed hierarchically (if it is not, choose the Switch Window Editor View button). d) Drag the outbound plug OUT_DETAILS of INPUT_VIEW onto the inbound plug IN_DEFAULT of OUTPUT_VIEW. e) On the Web Dynpro: Choose Destination for Navigation window, choose Continue. 5. Define a navigation link from the outbound plug (OUT_BACK) of OUTPUT_VIEW to the inbound plug (IN_DEFAULT) of INPUT_VIEW. a) Perform this as described in the previous step. b) Choose Save.
Define a Button on each View Define a button on each of the two views and make sure that the outbound plug of the respective view is fired when the user presses the button. 1. Create a simple UI element of type, BUTTON, with the name, BUT_DETAILS, on the layout of view, INPUT_VIEW. Maintain the text to be displayed on the button. a) In the object tree of the component ZNET310_CTRL_##, expand the Views folder, double-click the view INPUT_VIEW, and choose the Layout tab page. b) On the Layout tab page, right-click ROOTUIELEMENTCONTAINER, and choose Insert Element. c) In the Create Element dialog box, enter the following data: Field Name
Value
ID
BUT_DETAILS
Typ
Button
d) Choose Continue. e) In the properties area, go to property, Text, and enter the text to be displayed in the Value column. 2. Create an action for the button with the name, DISPLAY_DETAILS. Assign this action to the BUT_DETAILS button. If the user chooses this button, the outbound plug OUT_DETAILS is fired. a) Go to property onAction of the button and choose the Create button in the Binding column. b) In the Create Action dialog box, enter the following data: Field
Value
Action
DISPLAY_DETAILS
Description
Action for input view
© Copyright. All rights reserved.
295
Unit 9: Introduction to Web Dynpro
Field
Value
Outbound Plug
OUT_DETAILS
c) Choose Continue. d) Save your entries. 3. What are the new parts created in the view controller by the previous step (refer to the various tab pages of the view)? The action DISPLAY_DETAILS and the event handler method ONACTIONDISPLAY_DETAILS (with coding to fire the outbound plug) are the new parts created in the view controller by the previous step. 4. Create a button in the view OUTPUT_VIEW with the name BUT_BACK. Set the text to be displayed on the button and assign an action with the name BACK to the property onAction. Make sure that the outbound plug OUT_BACK is fired when the user chooses the button. a) Perform this as done in the previous steps, using a description of Action for output view in the Create Action dialog box. Activate your Component Create an application to access your component and start the application. 1. Activate your component and all contained component entities. a) Double-click ZNET310_CTRL_## to select it, then right-click the component and choose the Activate button. b) Choose Save. 2. Create a Web Dynpro application for your component. Start the application. a) In the context menu of the component (right-click) ZNET310_CTRL_##, choose Create → Web Dynpro Application. b) In the Create Web Dynpro Application dialog box, enter the following data: Field Name
Value
Application
znet310_ctrl_##
Description
WD application
c) Choose Continue. d) Save your entries. On the Create Administration Service dialog box, deselect Administration Service and choose Continue. e) On the Create Object Directory Entry dialog box, choose Save. f) On the Prompt for transportable Workbench request dialog box, choose Continue. g) To start the application in a browser window, in the context menu of the Web Dynpro application ZNET310_CTRL_##, choose the Test button.
296
© Copyright. All rights reserved.
Lesson: Navigating Between Views
LESSON SUMMARY You should now be able to: ●
Set up navigation between views
© Copyright. All rights reserved.
297
Unit 9 Lesson 4 Creating View Assemblies
LESSON OVERVIEW This lesson shows you how to use view assemblies. Business Example You need to create windows and nested views, embed a view in a view controller, and learn how to use view assemblies. For this reason, you require the following knowledge: ●
An understanding of view assemblies
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Create view assemblies
View Assemblies
Figure 158: Windows and Nested Views
Windows and Views ●
●
●
298
A window is the set of all possible views that can make up a visible screen. A window defines which views are displayed in what combination and how the view combination changes by firing outbound plugs. A view can have container areas defined by the ViewContainerUIElement. This allows nesting of views within a window.
© Copyright. All rights reserved.
Lesson: Creating View Assemblies
●
A ViewContainerUIElement can only display one view at a time.
When you create a window, remember the following points: You must embed all the possible views that can exist in the visual interface of the component in the window.
●
●
●
To display multiple views in parallel, define the layout and position of these views in a special view containing ViewContainerUIElements in its layout. This container view is embedded in the window and all the possible views for this view container area are embedded (nested embedding) inside each area, which is defined by a ViewContainerUIElement. One default view is displayed at startup for each ViewContainerUIElement. Define the navigation links between the different views.
Only one view is displayed in the view container area at a time. To replace the contents of a view container area, define the navigation links between views. View container areas can be blanked out by embedding the view EMPTYVIEW (automatically created with the component), whose inbound plug responds to an appropriate navigation event. View Assembly
Figure 159: View Assembly
Outbound plugs are the triggers that cause a view container area to contain a particular view. For window definitions in which multiple views are embedded in view container areas, many permutations of views are possible. Exactly what is displayed depends on the navigation links that the user follows. The subset of views visible at any time is known as a view assembly. Navigation causes either specific views within a view container area to be replaced, or it can cause entire view combinations within the window to be replaced.
© Copyright. All rights reserved.
299
Unit 9: Introduction to Web Dynpro
300
© Copyright. All rights reserved.
Unit 9 Exercise 19 Create View Assemblies
Business Example You need to develop a single-screen Web Dynpro application. Combine multiple views to define the page displayed to the user. In addition, firing outbound plugs should replace one or multiple views being part of the view assembly. Template: NET310_CTRL_S Solution: NET310_CTRL_S_OPT After completing this exercise, you will be able to display more than one view in parallel. Make a Copy of your Web Dynpro Component Copy your solution from the previous exercise or the template component. 1. Copy your solution from the previous exercise (ZNET310_CTRL_##) or the Web Dynpro component NET310_CTRL_S to the new component, ZNET310_CTRL_##_OPT. Define a Container Area Define a container area in the layout of INPUT_VIEW. 1. Define a UI element (VC) of the type VIEWCONTAINERUIELEMENT in the layout of the view INPUT_VIEW. Define a View Assembly Embed views in a new window and define the navigation. 1. Define a new window with the name SECOND_WINDOW. 2. Embed INPUT_VIEW in the new window. 3. Embed the view EMPTYVIEW in the container area. 4. Embed the view, OUTPUT_VIEW, in the container area, VC. 5. Define the navigation. Activate the Component Define a new Web Dynpro application to access the new window of your application. Start the new application. 1. Activate your component and all its entities. 2. Create a Web Dynpro application for your component.
© Copyright. All rights reserved.
301
Unit 9 Solution 19 Create View Assemblies
Business Example You need to develop a single-screen Web Dynpro application. Combine multiple views to define the page displayed to the user. In addition, firing outbound plugs should replace one or multiple views being part of the view assembly. Template: NET310_CTRL_S Solution: NET310_CTRL_S_OPT After completing this exercise, you will be able to display more than one view in parallel. Make a Copy of your Web Dynpro Component Copy your solution from the previous exercise or the template component. 1. Copy your solution from the previous exercise (ZNET310_CTRL_##) or the Web Dynpro component NET310_CTRL_S to the new component, ZNET310_CTRL_##_OPT. a) To copy your solution from the previous exercise, choose the Other Object SE80.
button in
b) In the Object Selection dialog box, choose the Enhanced Options radio button. c) Choose the Web Objects tab page, select the Web Dynpro Comp./Intf. radio button, and enter ZNET310_CTRL_## in the Web Dynpro Comp./Intf. field. d) Choose the Copy
button.
e) In the Copy Web Dynpro component dialog box, enter ZNET310_CTRL_##_OPT in the Name of Copy field. f) Choose Continue. g) In the Create Object Directory Entry dialog box, choose the Save button. h) In the Prompt for transportable Workbench request dialog box, choose Continue. Define a Container Area Define a container area in the layout of INPUT_VIEW. 1. Define a UI element (VC) of the type VIEWCONTAINERUIELEMENT in the layout of the view INPUT_VIEW. a) In SE80, choose Web Dynpro Comp. / Intf. and enter the name of your new Web Dynpro ZNET310_CTRL_##_OPT, then choose the Display button. b) On the Display Package screen, choose ZNET310_CTRL_##_OPT → Views, and double-click INPUT_VIEW. c) Choose the Layout tab.
302
© Copyright. All rights reserved.
Lesson: Creating View Assemblies
d) In the context menu of ROOTUIELEMENTCONTAINER, choose Insert Element. e) In the Create Element dialog box, enter the following data: Field Name
Value
ID
VC
Typ
ViewContainerUIElement
f) Choose Continue. g) Save your entries. Define a View Assembly Embed views in a new window and define the navigation. 1. Define a new window with the name SECOND_WINDOW. a) In the context menu of the component ZNET310_CTRL_##_OPT, choose Create → Window. b) In the Web Dynpro: Create Window dialog box, enter SECOND_WINDOW in the Window field. c) Choose Continue. 2. Embed INPUT_VIEW in the new window. a) Open the Window tab page and expand the node SECOND_WINDOW. b) Ensure that the window structure is displayed hierarchically. If it is not, choose the Switch Window Editor View
button.
c) In the Object list for the component expand ZNET310_CTRL_##_OPT → Views. d) Drag INPUT_VIEW to the root node SECOND_WINDOW, which is displayed under the Window tab page. e) Save your entries. 3. Embed the view EMPTYVIEW in the container area. a) On the Web Dynpro Builder: Change Window for ZNET310_CTRL_##_OPT screen, under the Window tab page, expand the node, SECOND_WINDOW, then expand the node, INPUT_VIEW. b) In the context menu of the view container area VC, choose Embed View. c) In the Web Dynpro: Embed a View dialog box, enter the following data: Field Name
Value
View to Be Embedded
EMPTYVIEW
Component of View
ZNET310_CTRL_##_OPT
d) Choose Continue. 4. Embed the view, OUTPUT_VIEW, in the container area, VC. a) In the context menu of the view container area VC, choose Embed View.
© Copyright. All rights reserved.
303
Unit 9: Introduction to Web Dynpro
b) In the Web Dynpro: Embed a View dialog box, enter the following data: Field Name
Value
View to Be Embedded
OUTPUT_VIEW
Component of View
ZNET310_CTRL_##_OPT
c) Choose Continue. 5. Define the navigation. a) On the Web Dynpro Builder: Change Window for ZNET310_CTRL_##_OPT screen, ensure the node SECOND_WINDOW, and all nodes within it, are fully expanded. Drag the outbound plug of INPUT_VIEW, which is OUT_DETAILS, and drop it on the inbound plug of OUTPUT_VIEW, which is IN_DEFAULT. Choose Continue. b) Drag the outbound plug of OUTPUT_VIEW, which is OUT_BACK, to the inbound plug of EMPTYVIEW, which is SHOWEMPTYVIEW. Choose Continue. c) On the Web Dynpro Builder: Change Window for ZNET310_CTRL_##_OPT screen, choose the Save button. Activate the Component Define a new Web Dynpro application to access the new window of your application. Start the new application. 1. Activate your component and all its entities. a) Double-click the component ZNET310_CTRL_##_OPT to select it. b) In the context menu of the component ZNET310_CTRL_##_OPT, choose Activate. c) In the Inactive Objects for NET310-## dialog box, choose Continue. 2. Create a Web Dynpro application for your component. a) In the context menu of the component ZNET310_CTRL_##_OPT, choose Create → Web Dynpro Application. b) In the Create Web Dynpro Application dialog box, enter ZNET310_CTRL_##_OPT in the Application field. c) Choose Continue. Hint: If you have already created a Web Dynpro Application for your component, you will need to explicitly choose the application name when you create subsequent applications. d) Define the application properties. On the Properties tab page, enter the following data using the corresponding value help:
304
Field Name
Value
Interface View
SECOND_WINDOW
© Copyright. All rights reserved.
Lesson: Creating View Assemblies
Field Name
Value
Plug Name
DEFAULT
e) Choose the Save button. f) On the Create Administration Service dialog box, deselect the Administration Service, and choose Continue. g) In the Create Object Directory Entry dialog box, choose the Save button again. h) In the Prompt for transportable Workbench request dialog box, choose Continue. i) On the Web Dynpro Explorer: Change Web Dynpro Application screen, choose the Test button
© Copyright. All rights reserved.
. A browser window opens and the application starts.
305
Unit 9: Introduction to Web Dynpro
LESSON SUMMARY You should now be able to: ●
306
Create view assemblies
© Copyright. All rights reserved.
Unit 9 Lesson 5 Identifying Web Dynpro Entities and Relationships
LESSON OVERVIEW This lesson explains the Model View Controller (MVC) design paradigm and the internal and external visibility of the Web Dynpro entities. It also shows you how to create a custom controller and view the component interface. Business Example You want to explore the Web Dynpro architecture to determine which Web Dynpro entities are internally and externally visible. For this reason, you require the following knowledge: ●
●
An understanding of the Web Dynpro entities that are only visible inside the Web Dynpro An understanding of the Web Dynpro entities that form part of the Web Dynpro Component Interface
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Differentiate between internally and externally visible Web Dynpro entities
Model View Controller
Figure 160: Model View Controller
SAP’s Web Dynpro is built on the foundation of the MVC design paradigm. MVC was invented by the Norwegian software designer Trygve Reenskaug while working at Xerox PARC in the
© Copyright. All rights reserved.
307
Unit 9: Introduction to Web Dynpro
late 1970s. The first implementation of this design paradigm was with the release of the Smalltalk-80 programming language. MVC was a revolutionary design paradigm because it was the first to describe software components in terms of the functional responsibilities that each must fulfill and message protocols to which each component must respond. SAP modified and extended the original MVC specification to create the Web Dynpro toolset.
Internal Visibility Versus External Visibility
Figure 161: Internally-Visible Web Dynpro Entities (1)
The architecture of a Web Dynpro component can be divided into two parts – external and internal visibility. The horizontal dashed line in the figure separates the entities that are visible outside the component from those that are only visible within the component. The internally visible parts can be further divided into visual entities and programming entities. Visual entities are related to the UI. They are generated by the Web Dynpro framework and passed to the client. The internally visible entities consist of windows and views. A view consists of a view layout and the corresponding view controller. The view controller can contain navigation plugs, methods, and a context. A window embeds one or more views and has a corresponding window controller. A window controller can contain navigation plugs, methods, and a context. Each view can be embedded in multiple windows. The outbound plug of a window can be connected to any inbound plug of embedded views and the outbound plug of a view can be connected to any inbound plug of the embedding window. However, navigation between windows of the same component is not possible.
308
© Copyright. All rights reserved.
Lesson: Identifying Web Dynpro Entities and Relationships
Internally Visible Web Dynpro Entities – Component Controller
Figure 162: Internally Visible Web Dynpro Entities (2)
The component controller works as a component-wide controller. Program logic related only to a certain view, for example, checking user input, is coded in the related view controller. Usage declarations between the controllers allow you to access the context data, the public attributes, and the methods of the declared controller (used controller). A view controller cannot be declared as a used controller for other controllers because this violates good programming practice (MVC programming paradigm). Business logic should not be part of the Web Dynpro component, but should be defined outside the component to ensure high reusability. To encapsulate the related source code, you should preferably use global ABAP classes. Internally Visible Web Dynpro Entities – Custom Controllers
Figure 163: Internally Visible Web Dynpro Entities (3)
© Copyright. All rights reserved.
309
Unit 9: Introduction to Web Dynpro
Custom controllers are optional controllers defined by the developer. These controllers are used to modularize component content. For example, custom controllers can act as local controllers for some views, or they can be used to encapsulate the logic related to a certain model class (business logic). The use of custom controllers allows you to reduce the content of the component controller by populating subfunctions. Externally Visible Web Dynpro Entities
Figure 164: Externally Visible Web Dynpro Entities
If a Web Dynpro component (parent component) needs access to another Web Dynpro component (child component), the parent component can declare the use of the child component. A specific component usage instance is created and the parent component accesses the functions of the child component through its component interface controller. Interface Controllers and Views The only parts of a Web Dynpro component that are externally visible are the interface controller and the interface view. A Web Dynpro component interface consists of the following parts: ● Interface controller All Web Dynpro components have only one interface controller. Through the interface controller, data, methods, and event handlers can be made accessible to other components. ●
Interface views Interface views represent the visual interface of a Web Dynpro component. There is a oneto-one relationship between a window and an interface view. Each time a window is defined, a related interface view is automatically generated, which makes the window accessible from outside the component. The interface view only exposes those inbound and outbound plugs to the component user that have the interface property checked. Methods and context data of the window are not accessible through the related interface view.
310
© Copyright. All rights reserved.
Lesson: Identifying Web Dynpro Entities and Relationships
If a component has no views, there is no need to have windows. In this case, the component does not implement an interface view. Components without any visual interface are called faceless components. Web Dynpro Application
Figure 165: Web Dynpro Application
A Web Dynpro application is the entry point into a Web Dynpro component and is the only Web Dynpro entity that can be addressed through a URL. There is often a one-to-one relationship between an interface view and an application. In the same way that the functions in an ABAP module pool are accessed by defining multiple transaction codes, the functions of a single Web Dynpro component can be accessed by defining multiple applications. Each application addresses a different interface view and/or a different inbound plug of the interface view. To define a Web Dynpro application, specify the following elements: The component to be instantiated. It is then known as the root component.
●
●
●
The interface view of the root component to be used. The default view in this interface view defines the default view assembly. The inbound plug that acts as an entry point for the nominated interface view (this inbound plug must be of type Startup).
LESSON SUMMARY You should now be able to: ●
Differentiate between internally and externally visible Web Dynpro entities
© Copyright. All rights reserved.
311
Unit 9: Introduction to Web Dynpro
312
© Copyright. All rights reserved.
Unit 9 Learning Assessment
1.
Match the item in the first column to the corresponding item in the second column. Meta Model Declarations
Good tool support
Meta Model Declarations
Common application design
2. How does Web Dynpro pursue its philosophy, to have fewer lines of hand written code?
3. Multiple views can be displayed in the view container area at a time. Determine whether this statement is true or false. X
True
X
False
4. Which of the following statements are true? Choose the correct answers. X
A The outbound plug of a window can be connected to any inbound plug of embedded views
X
B Each view can be embedded in multiple windows.
X
C The outbound plug of a view can be connected to any inbound plug of the embedding window.
X
D Navigation between windows of the same component is possible.
© Copyright. All rights reserved.
313
Unit 9 Learning Assessment - Answers
1.
Match the item in the first column to the corresponding item in the second column. Meta Model Declarations
Common application design
Meta Model Declarations
Good tool support
2. How does Web Dynpro pursue its philosophy, to have fewer lines of hand written code? Web Dynpro uses a declarative meta model for defining UIs. The development environment generates the required source code from this abstract definition. Web Dynpro provides technical features, such as support for internationalization, flicker-free interaction, and a clean separation of the business logic and the UI. This separation is achieved through a modified implementation of the MVC design paradigm. Web Dynpro also provides wizards that support the definition of forms and tables in the UI and source code in the controller methods significantly reducing the development effort. 3. Multiple views can be displayed in the view container area at a time. Determine whether this statement is true or false. X
True
X
False
4. Which of the following statements are true? Choose the correct answers. X
A The outbound plug of a window can be connected to any inbound plug of embedded views
X
B Each view can be embedded in multiple windows.
X
C The outbound plug of a view can be connected to any inbound plug of the embedding window.
X
D Navigation between windows of the same component is possible.
That's incorrect. Navigation between windows of the same component is not possible.
314
© Copyright. All rights reserved.
UNIT 10
Web Dynpro Controllers
Lesson 1 Outlining Controller Types and Entities
316
UNIT OBJECTIVES ●
Differentiate the controller types
●
Outline the structure of component and custom controllers
●
Outline the structure of view and window controllers
© Copyright. All rights reserved.
315
Unit 10 Lesson 1 Outlining Controller Types and Entities
LESSON OVERVIEW This lesson provides an overview of the various controller types and entities that form the integral part of a Web Dynpro component. Business Example You need to implement the flow logic of your Web Dynpro applications. This will involve implementing event handlers, inbound plug methods, and reaction to client side events, all of which live inside controllers. For this reason, you require the following knowledge: ●
An understanding of the contents of a Web Dynpro controller
●
An understanding of the function of each controller entity
●
An understanding of the differences between the component controller, custom controllers, view controllers, and window controllers
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Differentiate the controller types
●
Outline the structure of component and custom controllers
●
Outline the structure of view and window controllers
Controller Types The different types of controllers that may be found in a Web Dynpro component are as follows:
316
Controller Types
Description
Component controller
There is only one component controller in each Web Dynpro component. This is a global controller, visible to all other controllers. The component controller drives the functionality of the entire component. This controller has no visual interface.
© Copyright. All rights reserved.
Lesson: Outlining Controller Types and Entities
Controller Types
Description
Custom controllers
Custom controllers are optional. They are defined at design time and can be used to encapsulate subfunctions of the component controller. Multiple custom controllers can be defined in a component. The Web Dynpro framework automatically instantiates the custom controllers and the instantiation order is undefined. Therefore, the coding in a custom controller should not depend on the existence of any other custom controller.
Configuration controllers
This is a special custom controller. It is only necessary if the corresponding component implements special configuration and personalization functions. Only one configuration controller may exist in any component. Any controller can access the configuration controller, but the configuration controller cannot access any other controller.
View controllers
Each view consists of the layout part and one view controller. This controller handles the view-specific flow logic, for example, checking user input, and handling user actions.
Window controllers
Each window has exactly one window controller. You can use this controller to handle the data passed through the inbound plugs when it is reused as a child controller. You can call the methods of this controller from the inbound plug methods of the window.
At runtime, all controller instances are singletons with respect to their parent components. This is also true for view controllers and, therefore, embedding a view in a view assembly more than once is not allowed. The context and the methods defined in a controller are private unless another controller explicitly declares the usage of this controller. However, a view controller cannot be declared as a used controller, which means that the context data and the methods of a view controller are always private. Controller Instance Lifetime Web Dynpro is a stateful technology. The lifetime of controller instances is not limited to the time used to process the program code and to process the user interface (UI). The following list describes the lifetimes of the different controller instances, depending on the controller type: ● Component controller The lifetime of the component controller is the lifetime of the component. When you start a Web Dynpro application, the component controller is instantiated by the Web Dynpro runtime.
© Copyright. All rights reserved.
317
Unit 10: Web Dynpro Controllers
●
Custom controllers The instantiation of a custom controller is delayed until the first method of the controller is called. Custom controller instances cannot be deleted explicitly.
●
Configuration controllers A configuration controller is instantiated as the first controller of the component. It lives as long as the component lives.
●
View controllers The instantiation of a view controller is delayed until the first method of the controller is called. The developer can control the lifetime of a view controller through the view properties. To delete the view instance with the component, the developer selects the framework controlled option. To delete the view instance as soon as the view no longer belongs to the view assembly, the developer selects the when visible option.
●
Window controllers The instantiation of a window controller is delayed until the first method of this controller is called. This is done by starting a Web Dynpro application, by embedding the related interface view in the parent component's window, or by displaying the window in a dialog box. Window controller instances cannot be deleted explicitly.
Common Controller Entities
Figure 166: Constituents of all Controllers
Each controller has its own context. The root node of the context already exists. All other nodes and attributes are defined statically or by dynamically at runtime in the source code. For all controllers, the Web Dynpro framework calls certain methods in a predefined order. These are called hook methods. Different hook methods are available depending on the controller type. All controller types contain at least two hook methods, which are processed only once during the lifetime of the controller instance, at the following events:
318
© Copyright. All rights reserved.
Lesson: Outlining Controller Types and Entities
●
When a controller instance is created (wddoinit( ))
●
When a controller instance is deleted (wddoexit( ))
Additional methods can be defined on the Methods tab page. Attributes that are not bound to any UI element property are declared on the Attributes tab page. After they have been declared, the attributes are visible in all the methods of this controller. There are two predefined attributes, which are used to access the functionality of the controller ( WD_THIS ) and the context ( WD_CONTEXT ). Information Sharing Among Controllers To share information between different controllers, one controller must declare the use of another controller. This can be done on the Properties tab page of the controller that needs to access another controller. This type of data sharing is used for creating a mapped context node or for accessing the user-defined methods and public attributes of another controller. You may not specify the name of a view controller as a used controller because this violates good model view controller (MVC) design principles. A view controller should be written in such a way that it is responsible for nothing more than the display of data and user interaction. A view controller is not responsible for generating the data it displays; that is the role of a custom controller. The methods from all controllers enable you to access business logic, such as function modules, BAPIs, or methods in helper classes.
Special Entities of Component/Custom Controllers
Figure 167: Component and Custom Controllers – Special Entities
For the component controller and custom controllers, events can be defined with the parameters of your choice. Any method of any other controller, including view and window controllers, can register to these events if this method is defined as an event handler method.
© Copyright. All rights reserved.
319
Unit 10: Web Dynpro Controllers
These events are typically used to invoke processing in a view controller after processing in the component controller has been completed. This can be done when a method in the view controller subscribes to an event raised by the component controller. Using your design-phase declarations, the Web Dynpro framework automatically performs the definition, triggering, and handling subscription to such events for you. You also have the additional option of dynamic event subscription at runtime.
Caution: If two or more methods subscribe to the same event, the order in which they are executed is undefined. The component controller has the following additional hook methods: ● wddobeforenavigation( ) ●
wddopostprocessing( )
●
wddoapplicationstatechange( )
Methods, context elements, and events can be marked as part of the interface. These elements are then exposed to other components through the interface controller.
Special Entities of View Controllers
Figure 168: Special Entities of View Controllers
A view controller is a visual building block of a Web Dynpro component and it is designed to handle all aspects of data display and user interaction. To enable the navigation between different Web Dynpro view controllers, special navigation events and navigation event handlers, called navigation plugs, have been created. Firing an outbound plug raises a navigation event.
320
© Copyright. All rights reserved.
Lesson: Outlining Controller Types and Entities
Using the generic name < Outbound plug > for an outbound plug, its declaration causes a method named FIRE__PLG to be generated in the component view's controller. This method is only visible to the Web Dynpro framework. An inbound plug is a navigation event handler that can be registered to a navigation request. Using the generic name for an inbound plug, its declaration causes a method named HANDLE_PLG to be generated in the view controller. A static registration of an inbound plug to the navigation event raised by an outbound plug is called a navigation link. Navigation links are not part of a view but are defined in a window embedding the view. Therefore, event registration can be defined differently in different windows. Special Hook Methods An action links a client-side event (for example, choosing a pushbutton in a browser) to an event handler method defined in the corresponding view controller. When you define an action with the name < Action >, an event handler method ( ONACTION ) is automatically generated. If a view has to be replaced as a result of a client event, the related outbound plug can be fired in this action event handler method. View controllers include the following special hook methods: ● wddobeforeaction( ) ●
wddoafteraction( )
●
wddomodifyview( )
●
wddooncontextmenu( )
In addition to the standard attributes that exist in all controllers ( WD_THIS and WD_CONTEXT ), a view controller has a reference to the component controller of its component, WD_COMP_CONTROLLER . This reference can be used to access functions of the component controller, for example, to call methods declared there.
Hint: The attribute WD_COMP_CONTROLLER only exists, if the usage of the component controller is declared.
© Copyright. All rights reserved.
321
Unit 10: Web Dynpro Controllers
Special Entities of Window Controllers
Figure 169: Window Controller Architecture
Window controllers are similar to view controllers but, unlike view controllers, they don’t have a UI (view layout). All views that are to be displayed when using a Web Dynpro application have to be embedded in the window that is referred to by the application or the calling component. The Web Dynpro window embeds all views to be displayed. If defined statically, the navigation links defining the possible view assemblies are embedded in the Web Dynpro window. Each Web Dynpro window contains outbound plugs and inbound plugs, just like views. You can use the plugs to set up cross-component navigation. To expose the plugs to the component interface, select the Interface property for each plug. These plugs are then part of the related interface view. If the usage of the component controller is declared, the window controller contains the additional attribute WD_COMP_CONTROLLER , allowing access to the component controller functionality. Windows controllers include the following special hook methods: wddoonopen( )
●
●
wddoonclose( )
LESSON SUMMARY You should now be able to:
322
●
Differentiate the controller types
●
Outline the structure of component and custom controllers
●
Outline the structure of view and window controllers
© Copyright. All rights reserved.
Unit 10 Learning Assessment
1. The context and the methods defined in a controller are private unless another controller explicitly declares the usage of this controller. Determine whether this statement is true or false. X
True
X
False
2. Which of the following hook methods exist in a Component Controller? Choose the correct answers. X
A wddobeforenavigation( )
X
B wddopostprocessing( )
X
C wddoonopen( )
X
D wddoapplicationstatechange( )
© Copyright. All rights reserved.
323
Unit 10 Learning Assessment - Answers
1. The context and the methods defined in a controller are private unless another controller explicitly declares the usage of this controller. Determine whether this statement is true or false. X
True
X
False
2. Which of the following hook methods exist in a Component Controller? Choose the correct answers.
324
X
A wddobeforenavigation( )
X
B wddopostprocessing( )
X
C wddoonopen( )
X
D wddoapplicationstatechange( )
© Copyright. All rights reserved.
UNIT 11
Web Dynpro Context
Lesson 1 Creating Context Nodes
326
Lesson 2 Setting Context Node Properties
332
Lesson 3 Sharing Data Between Controllers with Context Mapping Exercise 20: Define, Map, and Bind Data to the Context
338 341
UNIT OBJECTIVES ●
Create a context node with attributes
●
Explain the cardinality property
●
Set the singleton property of a context node
●
Define internal context mapping
© Copyright. All rights reserved.
325
Unit 11 Lesson 1 Creating Context Nodes
LESSON OVERVIEW This lesson explains the context. It also describes how to define nodes and attributes in the context. Business Example You have created your first Web Dynpro component with views and windows embedding the views. You have created a Web Dynpro application to access your Web Dynpro component from the browser. You want your application to display data from a back-end system. Therefore, you need to define variables that can be bound to UI elements and that can be easily exchanged between different controllers. These variables are defined in the controller context, so you want to learn about how to define this hierarchical data storage structure. For this reason, you require the following knowledge: ●
An understanding of nodes and attributes in a controller’s context
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Create a context node with attributes
The Context Structure
Figure 170: The Context
326
© Copyright. All rights reserved.
Lesson: Creating Context Nodes
Every Web Dynpro controller has exactly one hierarchical data storage structure, known as the context. The data held in the context exists only for the life span of the controller. Once the controller instance has been terminated, all data held within its context is lost. The structure, that is, the metadata of the context, is typically defined at design time. However, at runtime you can modify the contents of the context, and can also dynamically modify the structure. Process of Changing the Context
Figure 171: Changing the Context (1)
The figure shows the different steps of changing the context nodes and attributes using different options in the application screens. Process of Changing the Context Editor View
Figure 172: Changing the Context (2)
Unless declared otherwise, all runtime data in a controller’s context is private to that component.
© Copyright. All rights reserved.
327
Unit 11: Web Dynpro Context
You can make the information held in the context of the component controller or of a custom controller easily accessible to the context of another controller (view or custom) by using a technique known as context mapping. Using this technique, two or more controllers can access the same runtime data. Context mapping is the primary mechanism for sharing data between controllers within a single component.
Note: It is not possible for a view controller to share its context data. New Context Nodes and Attributes – Creation
Figure 173: Creating New Context Nodes and Attributes
All controller contexts are constructed from a hierarchical arrangement of entities known as nodes and attributes. A context always has a parent node known as the context root node. This context root node has fixed properties and it cannot be deleted. A context node is the main abstraction class used for runtime data storage within the Web Dynpro framework. Context nodes are arranged hierarchically. The node may have attributes or other nodes as child nodes.
Hint: For simplicity reasons, the term node is used in the following ways: ●
●
328
When referring to design time, the term node describes an element defined in the context of a controller. When referring to runtime, the term node is used to describe an object (instance) derived from the metadata. A more correct term would be node object or node instance.
© Copyright. All rights reserved.
Lesson: Creating Context Nodes
All the child entities of a node are aggregated into a unit known as an element. A node can be thought of as a collection of such elements in the same way as a table is a collection of rows.
Caution: The name of a context node must be unique within the complete structure of a controller’s context. A context attribute is an entity within the context that is not permitted to have children. A context attribute cannot exist without being the child of some parent node, be it the context root node itself or some other node. If a collection of structured data objects is to be stored in a controller context at runtime, a context node is defined to store the collection. Each structured data set is stored in an element. The reference to each element is stored in the node collection. The data structure is derived from the context attributes defined as subelements of the node. Context Node Properties
Figure 174: Context Nodes and Context Attributes at Runtime (1)
The figure shows the node object creation at runtime and the context root at design time.
© Copyright. All rights reserved.
329
Unit 11: Web Dynpro Context
Context Attributes Related to the Context Root
Figure 175: Context Nodes and Context Attributes at Runtime (2)
A structure is generated at runtime for the context attributes related to the context root. The reference to this structure is stored in the attribute STATIC_ATTRIBUTES of the element. Context Nodes and Context Attributes at Runtime
Figure 176: Context Nodes and Context Attributes at Runtime (3)
330
© Copyright. All rights reserved.
Lesson: Creating Context Nodes
A node object is created automatically for each subnode of the context root. The references are stored in the attribute CHILD_NODES of the context root element. LESSON SUMMARY You should now be able to: ●
Create a context node with attributes
© Copyright. All rights reserved.
331
Unit 11 Lesson 2 Setting Context Node Properties
LESSON OVERVIEW This lesson explains various properties of a context node. Business Example You want to build the Component Controller context for your Web Dynpro component, with the necessary nodes and attributes to hold the data required for your Web Dynpro application. You need to set the properties of these nodes correctly so that the right amount of data can be held at runtime, amongst other. For this reason, you require the following knowledge: ●
An understanding of the Cardinality property of context nodes
●
An understanding of the Singleton property of context nodes
LESSON OBJECTIVES After completing this lesson, you will be able to:
332
●
Explain the cardinality property
●
Set the singleton property of a context node
© Copyright. All rights reserved.
Lesson: Setting Context Node Properties
Cardinality
Figure 177: Context Structure at Runtime – Cardinality Property (1)
Many node properties set at design time determine memory allocation (for example, the dimension of the data array to be stored) at runtime. It is therefore essential to understand the properties of nodes. At design time, you create the metadata structure within which the runtime data is stored. All context nodes are collections and, therefore, it is possible that multiple element references are stored by a context node at runtime. Every context node has a property known as cardinality . Cardinality describes the maximum and minimum number of elements that the node collection may hold at runtime. All nodes contain an element collection, even if the maximum number of elements within the collection is limited to one. The possible cardinality values (specified as ..) and the element permissions depending upon the cardinality values are as follows: Table 7: Possible Cardinality Values and Permissions Cardinality Values
Description
0..1
Zero or one element permitted
0..n
Zero or more elements permitted
1..1
Exactly one element permitted
1..n
One or more elements permitted
© Copyright. All rights reserved.
333
Unit 11: Web Dynpro Context
At runtime, the context root node is instantiated automatically. The reference to this node is provided by the framework through the controller attribute WD_CONTEXT. You cannot alter the properties of the context root node. Because the cardinality is 1..1 , the root node always contains exactly one element. Context Nodes – Cardinality All context nodes, defined as direct children of the context root node (independent nodes), are instantiated automatically when accessed the first time (programmatically or because node data is to be displayed on the UI). If the cardinality of a node equals 1..1 or 1..n , the element with index 1 is created automatically when the node is instantiated. All other elements are instantiated programmatically. A node cannot exist if the collection of the parent node object is empty (elements related to the parent node do not exist). This means that the existence of nodes that are not defined as direct children of the context root node (dependent nodes) is not guaranteed. The following are the scenarios that can cause the application to dump due to cardinality violations: ● Deleting the default element of a node with cardinality 1..1 or 1..n. ●
Adding a second element to a node with cardinality 0..1 or 1..1.
Context Structure at Runtime – Cardinality Property
Figure 178: Context Structure at Runtime – Cardinality Property (2)
The figure shows that the structure of the context at runtime is not the flat, two-dimensional hierarchy it is at design time. At runtime, the context consists of multiple dependent objects. This can be compared to an internal table in ABAP at design time and runtime. At design time, the metadata of the internal table comprises the structure given by the line type. The dimension of the internal table (how many lines the data object holds at runtime) is not part of the definition.
334
© Copyright. All rights reserved.
Lesson: Setting Context Node Properties
At runtime, multiple lines can be appended to the internal table data object, just as multiple elements can be appended to a collection originating from a context node at runtime. However, because there are no restrictions on the minimum and maximum number of lines an internal table can hold, there is no counterpart for the cardinality property. Internal tables always have zero lines after the declaration of the object and they can hold an unrestricted number of lines at runtime.
Lead Selection
Figure 179: Lead Selection Index
Each context node contains the attribute LEAD_SELECTION_INDEX . This attribute is of type, integer , and is used to simplify access to the node’s collection. The lead selection index is set automatically by the Web Dynpro framework if the context node property Initialize Lead Selection is set to true . In this case, the attribute is automatically set to 1 as soon as the first element has been created. The lead selection index can also be set by program source code or it can be set by user actions related to UI elements (for example, by selecting a line in a Table UI element bound to the node).
Hint: The lead selection index is cleared by assigning the value of the constant IF_WD_CONTEXT_NODE=>NO_SELECTION . Lead Selection Index – Usage In the controller source code, special methods can be used to access the value of a node’s lead selection index and the element related to it.
© Copyright. All rights reserved.
335
Unit 11: Web Dynpro Context
Lead selection index is important in the following situations: ●
●
●
If a single row is selected in a table, the lead selection index automatically adjusts according to the selected row. The related context element can be accessed without having to find out the element index explicitly. On the other side, the marked row can be manipulated programmatically by changing the lead selection index. Form fields may be bound to attributes of a context node with the cardinality 0:n or 1:n . In this case, the form data originates from the element related to the node’s lead selection index. The data set displayed by the form can be manipulated programmatically by changing the lead selection index. Special methods (supply functions) can be assigned to context nodes. The framework may call a supply function automatically if the lead selection in the parent node changes.
The Singleton Property
Figure 180: Context Structure at Runtime – Singleton Property (1)
The figure shows that the context node N1 has a child node called N2. The N2 node is a distinct node with its own element collection. The Boolean property Singleton critically affects the relationship between a node and its parent node. If the singleton property of the N2 node is set to false (node N2 at runtime is a non-singleton – which is the default), then for every element in the parent node collection N1 there is a distinct instance of the child node N2. The most important thing here is that each instance of the N2 node is related to the respective element in the parent node collection. Note that the arrows pointing to each of the N2 node collections originate in the elements of the parent node. Therefore, if there are n elements in the parent node, there are n distinct instances of a non-singleton child node.
336
© Copyright. All rights reserved.
Lesson: Setting Context Node Properties
Context Structure at Runtime – Singleton Property
Figure 181: Context Structure at Runtime – Singleton Property (2)
If the Singleton property of the node N2 is set to true, the number of elements present in the parent node collection N1 does not matter. There will only ever be one instance of the child node N2 for the N2 at runtime if it is a singleton. LESSON SUMMARY You should now be able to: ●
Explain the cardinality property
●
Set the singleton property of a context node
© Copyright. All rights reserved.
337
Unit 11 Lesson 3 Sharing Data Between Controllers with Context Mapping
LESSON OVERVIEW This lesson explains context mapping. Business Example You need to access data from the context to another controller. For this reason, you require the following knowledge: ●
How to map the context
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Define internal context mapping
Context Mapping
Figure 182: Context Mapping
Context mapping allows a controller (typically a view controller) to access data that was preprocessed by some other controller. Because a mapping relationship allows a direct
338
© Copyright. All rights reserved.
Lesson: Sharing Data Between Controllers with Context Mapping
reference to be made to data in another controller, there is no need for this data to be copied or moved. The context node that acts as the data source is known as the mapping origin node and the context node that is mapped is known as the mapped node.
Note: A mapped node does not maintain its own element collection. Instead, it references the element collection of the mapping origin node. A view controller cannot act as a data source for a mapping relationship because this violates the principles of MVC program design. Design Principle In programs designed according to the MVC principle, a view controller is written in such a way that it takes no part in the generation of the data it displays. Instead, the view controller is only concerned with displaying pregenerated data and then handling the resulting user interaction (validation, error handling, and so on). It is the job of the component controller or custom controller to interact with back-end logic to generate the required data. Once the data has been generated, the component controller (custom controller) supplies it to a view controller for display. If a view controller acts as the data source (origin) for a mapping relationship, a situation can arise in which the component controller (custom controller) is dependent upon functionality found in a view controller. This is a bad design and is therefore not permitted. Mapping Between Controllers To establish context mapping between two controllers, the target controller has to declare the source controller as a used controller in its properties. If the Context tab page is chosen in edit mode of the target controller, the contexts of all used controllers are displayed. A node of a source context can then be referenced in the following ways: ● If an independent node to be mapped is not yet defined in the target controller’s context, the complete structure related to the source node is copied by dragging it from the source controller context to the root node of the target controller context. In addition, the copied node is mapped to the source node. ●
If the structure related to a node is already defined in the context of the target controller, the mapping can be established by dragging one of the nodes to the other node. However, the mapping origin is always the node contained in the used controller (displayed on the right side).
Hint: If the node you want to map contains attributes that are not contained in the mapping origin, these attributes are deleted when the node is mapped. The mapping origin and mapped node may have different names. After mapping has been executed between two nodes, all of their elements are mapped – including their attributes and child nodes. If the node structure of the mapping origin changes (attributes added, deleted, or modified), the mapping can be updated (synchronized) by using the context menu of the mapped node.
© Copyright. All rights reserved.
339
Unit 11: Web Dynpro Context
Internal Mapping
Figure 183: Context Mapping – Internal Mapping
Internal mapping is the name given to a mapping relationship in which both the mapped node and the mapping origin node lie within the boundaries of one component. This means that the mapping relationship can be fully established when writing the current component. However, there is a special case in which a mapping relationship can only be partially established when writing the current component. This is known as external mapping. This is a situation in which the mapping origin node lies outside the boundaries of, or is external to, the current component.
Note: External mapping is covered in detail later in the course.
340
© Copyright. All rights reserved.
Unit 11 Exercise 20 Define, Map, and Bind Data to the Context
Business Example You want to develop a Web Dynpro application that allows you to enter data into input fields on the first view. The user input is displayed on the next view. Template: NET310_CTRL_S Solution: NET310_COND_S Create nodes in contexts of components and views, and bind UI elements to view context nodes. Copy Your Solution from the Previous Exercise Copy your solution from the previous exercise or the template component. 1. Copy your solution from the previous exercise (ZNET310_CTRL_##) or the Web Dynpro component NET310_CTRL_S to the new component, ZNET310_COND_##. Create a Context Node with Attributes In the context of the component controller, create a context node that contains attributes to store a carrier ID and a connection ID. Create the same context node in each of the two views and map the nodes defined in the view controller contexts to the node defined in the component controller context. 1. In the context of the component controller, create a context node with the name FLIGHTINFO. This node is based on the dictionary type SFLIGHT and has cardinality 1..1. Add two attributes based on the SFLIGHT fields CARRID and CONNID. 2. Create the same node in the context of each view controller and map the context node of the view controllers to the context node FLIGHTINFO of the component controller. Create a Form with an Attribute and Input Fields For both views, create a form displaying a label and an input field for each context attribute of the node FLIGHTINFO. Use the Web Dynpro Code Wizard to perform this step. 1. On the layout of the view INPUT_VIEW, create a form with references to the context attributes CARRID and CONNID. Use the Web Dynpro Code Wizard to create the form. 2. Repeat the previous step for the view OUTPUT_VIEW. However, display the attribute values by UI elements of type TextView. 3. Activate your component. Create a Web Dynpro application for your component. Test the application.
© Copyright. All rights reserved.
341
Unit 11 Solution 20 Define, Map, and Bind Data to the Context
Business Example You want to develop a Web Dynpro application that allows you to enter data into input fields on the first view. The user input is displayed on the next view. Template: NET310_CTRL_S Solution: NET310_COND_S Create nodes in contexts of components and views, and bind UI elements to view context nodes. Copy Your Solution from the Previous Exercise Copy your solution from the previous exercise or the template component. 1. Copy your solution from the previous exercise (ZNET310_CTRL_##) or the Web Dynpro component NET310_CTRL_S to the new component, ZNET310_COND_##. a) On the Object Navigator screen, select the Web Dynpro component (ZNET310_CTRL_##) and choose (Other Object) in the Web Dynpro Explorer toolbar. b) In the Object Selection dialog box, select the Web Dynpro Comp./Intf. and enter ZNET310_CTRL_##. c) Choose
(Copy).
d) In the Copy Web Dynpro component dialog box, enter the following data: Field
Value
Name of Copy
ZNET310_COND_##
e) Choose Continue. f) On the Create Object Directory Entry dialog box, choose Save. g) On the Prompt for transportable Workbench request dialog box, choose Continue. Create a Context Node with Attributes In the context of the component controller, create a context node that contains attributes to store a carrier ID and a connection ID. Create the same context node in each of the two views and map the nodes defined in the view controller contexts to the node defined in the component controller context. 1. In the context of the component controller, create a context node with the name FLIGHTINFO. This node is based on the dictionary type SFLIGHT and has cardinality 1..1. Add two attributes based on the SFLIGHT fields CARRID and CONNID.
342
© Copyright. All rights reserved.
Lesson: Sharing Data Between Controllers with Context Mapping
a) Double-click COMPONENTCONTROLLER and choose the Context tab page. b) In the context menu of the root context node COMPONENTCONTROLLER, choose Create → Node. c) In the Create Nodes dialog box, enter the following data: Field
Value
Node Name
FLIGHTINFO
Dictionary structure
SFLIGHT
Cardinality
1..1
d) Choose the Add Attributes from Structure button. e) In the Select Components of Structure SFLIGHT dialog box, mark the structure components CARRID and CONNID, by clicking to the left of each, and choose Continue. f) Choose Save. 2. Create the same node in the context of each view controller and map the context node of the view controllers to the context node FLIGHTINFO of the component controller. a) Open the Web Dynpro view INPUT_VIEW and choose the Context tab page. b) Drag the context node FLIGHTINFO from the COMPONENTCONTROLLER context and drop it on the root node of the view controller CONTEXT under Context INPUT_VIEW. c) Choose Save. d) Open the Web Dynpro view OUTPUT_VIEW and choose the Context tab page. e) Drag the context node FLIGHTINFO from the COMPONENTCONTROLLER context and drop it on the root node of the view controller CONTEXT. f) Choose Save. Create a Form with an Attribute and Input Fields For both views, create a form displaying a label and an input field for each context attribute of the node FLIGHTINFO. Use the Web Dynpro Code Wizard to perform this step. 1. On the layout of the view INPUT_VIEW, create a form with references to the context attributes CARRID and CONNID. Use the Web Dynpro Code Wizard to create the form. a) Open the view INPUT_VIEW and choose the Layout tab page. b) Choose the ROOTUIELEMENTCONTAINER UI element in the UI element hierarchy. c) Choose the Web Dynpro Code Wizard button
.
d) In the Template Gallery dialog box, choose Form. Choose Continue. e) In the Create Form Elements for Container ROOTUIELEMENTCONTAINER dialog box, choose the Context button and double-click the context node FLIGHTINFO. f) Select the Create Form in New Container and Create Section Header checkbox. g) Choose Continue. h) Choose Save.
© Copyright. All rights reserved.
343
Unit 11: Web Dynpro Context
2. Repeat the previous step for the view OUTPUT_VIEW. However, display the attribute values by UI elements of type TextView. a) On the Web Dynpro Explorer: Change View for ZNET310_COND_## screen, open the view OUTPUT_VIEW and choose the Layout tab page. b) Choose ROOTUIELEMENTCONTAINER in the UI element hierarchy. c) Choose the Web Dynpro Code Wizard button. d) In the Template Gallery dialog box, choose Form. Choose Continue. e) In the Create Form Elements for Container ROOTUIELEMENTCONTAINER dialog box, choose the Context button and double-click the context node FLIGHTINFO. f) In the Standard Cell Editor field, select the item TextView. g) Select the Create Form in New Container and Create Section Header checkbox. h) Choose Continue. i) Choose Save. 3. Activate your component. Create a Web Dynpro application for your component. Test the application. a) In the context menu of the component ZNET310_COND_##, choose Activate. b) In the Inactive Objects for NET310-## dialog box, choose Continue. c) On the Web Dynpro Explorer: Change View for ZNET310_COND_## screen, in the context menu of the component ZNET310_COND_##, choose Create → Web Dynpro Application. d) In the Create Web Dynpro Application dialog box, choose Continue. e) Choose Save. f) On the Create Web Dynpro Application dialog box, choose Save. g) On the Prompt for transportable Workbench request dialog box, choose Continue. h) From the context menu of your Web Dynpro application ZNET310_COND_##, choose Test to open a browser window and start your application.
344
© Copyright. All rights reserved.
Lesson: Sharing Data Between Controllers with Context Mapping
LESSON SUMMARY You should now be able to: ●
Define internal context mapping
© Copyright. All rights reserved.
345
Unit 11: Web Dynpro Context
346
© Copyright. All rights reserved.
Unit 11 Learning Assessment
1. A context always has a parent node known as the context root node. What kind of properties does this context root node have? Choose the correct answer. X
A Fixed properties and it cannot be deleted
X
B No fixed properties and it cannot be deleted
X
C Fixed properties and it can be deleted
X
D Some fixed properties and it can be deleted
2. What happens when the cardinality of a node equals 1..1 or 1..n? Choose the correct answer. X
A The element with a random index is created automatically when the node is instantiated
X
B The element with index 1 is created automatically when the node is instantiated
X
C The element with index 1 is deleted automatically when the node is instantiated
3. Which of the following are true about internal mapping? Choose the correct answer. X
A Only the mapped node lies within the boundaries of one component
X
B Only the mapping origin node lies within the boundaries of one component
X
C Both the mapped node and the mapping origin node lie within the boundaries of one component
X
D Both the mapped node and the mapping origin node lie outside the boundaries of one component
© Copyright. All rights reserved.
347
Unit 11 Learning Assessment - Answers
1. A context always has a parent node known as the context root node. What kind of properties does this context root node have? Choose the correct answer. X
A Fixed properties and it cannot be deleted
X
B No fixed properties and it cannot be deleted
X
C Fixed properties and it can be deleted
X
D Some fixed properties and it can be deleted
2. What happens when the cardinality of a node equals 1..1 or 1..n? Choose the correct answer. X
A The element with a random index is created automatically when the node is instantiated
X
B The element with index 1 is created automatically when the node is instantiated
X
C The element with index 1 is deleted automatically when the node is instantiated
3. Which of the following are true about internal mapping? Choose the correct answer.
348
X
A Only the mapped node lies within the boundaries of one component
X
B Only the mapping origin node lies within the boundaries of one component
X
C Both the mapped node and the mapping origin node lie within the boundaries of one component
X
D Both the mapped node and the mapping origin node lie outside the boundaries of one component
© Copyright. All rights reserved.
UNIT 12
Web Dynpro User Interface
Lesson 1 Defining the View Layout Exercise 21: Arrange UI Elements with Layout Managers
350 365
Lesson 2 Controlling UI Element Behavior with Data Binding
371
Lesson 3 Using Composite UI Elements Exercise 22: Display Tables with the Service Wizard
379 389
UNIT OBJECTIVES ●
Differentiate UI elements
●
Define the layout using container elements
●
Add UI elements to the layout
●
Bind UI element properties to context attributes
●
Control UI element behavior
●
Outline UI composite element hierarchy
●
Bind a table UI element and its child elements to the context
●
Set the selection property for table UIs
© Copyright. All rights reserved.
349
Unit 12 Lesson 1 Defining the View Layout
LESSON OVERVIEW This lesson explains how to arrange the various UI elements to form the layout of a view. Not only simple UI elements are described in this lesson, but also complex elements, that is, nested UI elements (for example, the table). It also shows how to define data binding between UI element properties and context attributes. Business Example You want to create a Web Dynpro application that has an optimized User Interface (UI) and arrange the elements on the screen in groups or trays. You want to create a Web Dynpro application that has an optimized User Interface (UI), using different container elements to arrange the elements on the screen. You would also like to be able to display multiple records to the user in a table, and understand how the properties of some of your UI elements can be manipulated at runtime (for example, their visibility). For this reason, you require the following knowledge: ●
How to define the view layout by arranging UI elements and setting their properties
●
How to bind UI element properties to context attributes
●
How to use the table UI element as an example of composite UI elements
LESSON OBJECTIVES After completing this lesson, you will be able to:
350
●
Differentiate UI elements
●
Define the layout using container elements
●
Add UI elements to the layout
© Copyright. All rights reserved.
Lesson: Defining the View Layout
UI Elements
Figure 184: UI Elements
A UI element is any graphical entity that occupies a position within a view layout. However, this does not mean that all UI elements are visible on the screen. Certain UI elements, such as TransparentContainer , ViewContainerUIElement , or InvisibleElement , are not visible on the screen. These elements occupy a position in the UI element hierarchy similar to any other visible UI element and help structure the UI. In addition, all UI elements can be set to invisible at runtime without freeing the space they would occupy as visible UI elements. For example, hiding the Label UI element located to the left of an InputField UI element does not mean that the InputField UI elements move left and appear at the position where the Label UI element was previously displayed. Web Dynpro is designed to operate with any form-based UI. This implies that any UI element is only an abstract description of the source code that is rendered at runtime, and not just an HTML or WML representation of this element.
© Copyright. All rights reserved.
351
Unit 12: Web Dynpro User Interface
UI Element Categories
Figure 185: UI Element Categories
There are numerous elements available for designing the UI of a Web Dynpro application. All available UI elements are divided into categories. When the layout preview is visible, the view designer displays the following categories: ● The Text category This category contains elements that can be used to display texts or to enter literals. ●
The Action category This category contains simple elements that the users can choose to trigger navigation or just a round trip.
●
The Selection category This category contains simple elements that display multiple values. Depending on the element type, users may select one or more values.
●
The Complex category This category contains elements that require subelements to define a valid UI element.
●
The Layout category This category contains UI elements that are used to structure the layout. A special subset (container elements) consists of the UI elements Group , Panel , TransparentContainer , and Tray . These elements define rectangular areas in which subelements are ordered according to the rules defined by the container.
●
The Graphics category This category contains elements to render graphical members of the page.
352
© Copyright. All rights reserved.
Lesson: Defining the View Layout
●
The Integration category This category contains elements to embed all kinds of non-ABAP technologies in Web Dynpro.
Arrangement of UI Elements
Figure 186: Arrangement of UI Elements
All view layouts are composed of a hierarchy of UI elements. The root node is of the type TransparentContainer and is known as RootUIElementContainer . You cannot change the element's ID because it is hard-coded. However, you may swap the UI element type from the context menu of this element. This is important if you want to embed a Flash file or a Silverlight file into a Web Dynpro view. All subsequent UI elements added to a view layout are hierarchically subordinate to RootUIElementContainer . Context_Menus is the second item displayed above the RootUIElementContainer . This context menu provider allows you to create context menus at design time. At runtime, these context menus may be instantiated and assigned to UI elements. The user would need to right-click on a UI element at runtime to display the related context menu items, together with the standard context menu.
Container Elements and Layout Managers Container elements are UI elements that may contain arbitrary child elements. Available Container Elements ●
Group
●
Panel
●
TransparentContainer
●
Tray
© Copyright. All rights reserved.
353
Unit 12: Web Dynpro User Interface
Container elements occupy a rectangular area in the layout of the view. All UI elements that are children of a container element, are located in this rectangular area. All container elements define the arrangement of their children. They do this by using the layout property, which assigns a layout manager to the container UI element. All child elements of a container UI element inherit a set of properties related to the layout manager assigned to the parent container UI element. Layout Property Possible Values ●
FlowLayout
●
RowLayout
●
MatrixLayout
●
FormLayout
●
GridLayout (instead, use MatrixLayout whenever possible)
●
FormLayoutAdvanced
Layout Managers – FlowLayout
Figure 187: Layout Managers – FlowLayout
FlowLayout is the default layout manager. All child elements of a container that uses FlowLayout as the layout manager will be arranged sequentially. Therefore, line breaks cannot be specified explicitly. However, depending on the element type, a line break may be forced by the element implicitly. Elements that do not force a line break are displayed in a row, as long as the container is wide enough. If the container is too narrow for these child elements to be displayed in one row (for example, if the browser window is too narrow), they are automatically wrapped to the next row(s). This wrapping cannot be forced at design time. However, wrapping can be switched off by setting the property wrapping to false.
354
© Copyright. All rights reserved.
Lesson: Defining the View Layout
Elements in different lines are not related to each other. This kind of container can be used to arrange sub containers. Elements that do not Force a Line Break ●
InputField
●
Label
●
FormattedTextView, and TextView
●
Button, ButtonChoice, ToggleButton
●
LinkChoice, LinkToAction, LinkToUrl, ToggleLink
●
CheckBox, TriStateCheckBox
●
DropDownByIndex, DropDownByKey
●
RadioButton
●
Image
Layout Managers – RowLayout
Figure 188: Layout Managers – RowLayout
If RowLayout is used for the container UI element, all the children inherit the property LayoutData, which can have the values RowData or RowHeadData. If you set this property to RowHeadData, a line break is forced. If you set the property to RowData, no line break is forced. However, depending on the element type, a line break may be forced by the element implicitly. Elements that do not force a line break and have the property LayoutData = RowData are displayed in the same row as the previous element, even if the right-hand margin of the container is reached.
© Copyright. All rights reserved.
355
Unit 12: Web Dynpro User Interface
UI elements located in different rows are not related to each other because all the elements are aligned in a single column. Layout Managers – MatrixLayout
Figure 189: Layout Managers – MatrixLayout
If MatrixLayout is used with the container UI element, all the children inherit the property LayoutData, which can have the values MatrixData or MatrixHeadData. If you set this property to MatrixHeadData, a line break is forced. If you set the property to MatrixData, the child elements are displayed in the same row as the previous element, even if the right-hand margin has been reached. The child elements in this container are arranged in columns. Using this layout manager, the number of columns is not defined statically, but rather by the maximum number of child elements in any row. The number of elements in different rows may vary. You can use the properties StretchedHorizontally and StretchedVertically to specify whether or not the UI elements are to be distributed across the container area. If both properties are set to space, the elements are positioned in the upper left corner of the container. UI elements arranged in a MatrixLayout can occupy multiple cells (colSpan property).
356
© Copyright. All rights reserved.
Lesson: Defining the View Layout
Layout Managers – GridLayout
Figure 190: Layout Managers – GridLayout
Like MatrixLayout, GridLayout can be used if a vertical alignment of the elements is desired. However, in this case the number of columns is defined statically using the colCount property of the container element. You cannot define explicit line breaks. A line break takes place when all the cells of a row are occupied. If an element is removed from the hierarchy, the entire arrangement changes because all subsequent elements in the hierarchy move as many cells to the left as were occupied by the removed element. You use this layout manager only if all the rows have the same number of columns and if complete rows are inserted or deleted. When using this layout manager, ensure that UI elements are not removed completely, but replaced by an InvisibleElement to retain the original element arrangement.
© Copyright. All rights reserved.
357
Unit 12: Web Dynpro User Interface
Layout Managers – FormLayout (1)
Figure 191: Layout Managers – FormLayout (1)
If FormLayout is used with the container UI element, all children inherit the property LayoutData, which can have the values FormTopData, FormHeadData, and FormData.
Note: FormLayout is available only in SAP NetWeaver 7.0 enhancement package 2 and later versions. The setting FormTopData divides the page horizontally in sections, with each section containing a statically defined number of columns. The width of these columns is unique across all sections. Thus, the ratio of the section widths is given by the ratio of the column counts related to the sections. For example, in the figure, Layout Managers-FormLayout (1), FormLayout is assigned to the group with the heading Form Layout and to each of the embedded groups. The groups with headings Group 1 and Group 2 define a new section with respect to the embedding group. For Group 1, colCount is set to 4, and for Group 2, colCount is set to 8. Each of the embedded groups also use FormLayout as their layout manager. The column count for each of the embedded groups is defined by the first label defined in the group.
358
© Copyright. All rights reserved.
Lesson: Defining the View Layout
Layout Managers – FormLayout (2)
Figure 192: Layout Managers – FormLayout (2)
In each section, line breaks can be forced by setting LayoutData = FormHeadData. If you set the property to FormData, the child elements are displayed in the same row as the previous element. UI elements arranged in a FormLayout can occupy multiple cells (colSpan property). If colSpan is left at its default value (-1), the elements are spread across the columns automatically. For example, in the figure, Layout Managers – FormLayout (2), LayoutData = FormHeadData is assigned to the group with heading Group 3, while LayoutData = FormData is assigned to the group with heading Group 4. For the group with heading Group 3, colCount is set to 6, while for the group with heading Group 4, this property is set to -1. In each of these groups, the first element in the first line has the property LayoutData = FormTopData, while all other elements starting a new row have the property LayoutData = FormHeadData. All form fields not beginning a new row have LayoutData = FormData.
Hint: For details on automatically spreading UI elements across the grid, refer to the online documentation. In SAP NetWeaver 7.0 enhancement package 2, the property LayoutData is never displayed for the first subelement of a container. This is because the value of this property for the first subelement has only one valid value. The one value of the first element for property LayoutData is determined as follows: If RowLayout is assigned to the property Layout of the container, the first subelement automatically becomes LayoutData = RowHeadData.
●
© Copyright. All rights reserved.
359
Unit 12: Web Dynpro User Interface
●
●
If MatrixLayout is assigned to the property Layout of the container, the first subelement automatically becomes LayoutData = MatrixHeadData. If FormLayout is assigned to the property Layout of the container, the first subelement automatically becomes LayoutData = FormTopData.
FormLayoutAdvanced
Figure 193: FormLayoutAdvanced
FormLayoutAdvanced supports the alignment of UI elements across container boundaries. It is also possible to arrange UI elements cascaded in different rows. The layout data for a UI element, which belongs to a container that has FormLayoutAdvanced assigned, is provided by FormDataAdvanced. The height of the FormLayoutAdvanced in the form of rowspan must be specified for each UI element. FormLayoutAdvanced is available only in SAP NetWeaver 7.0 enhancement package 3 / SAP NetWeaver 7.3 enhancement package 1.
Note: The height of the layout cell does not adjust itself automatically to the height of your UI element. If it is too large, it is truncated. Other layouts do adjust themselves to the height. For more information, see MatrixLayout and GridLayout.
360
© Copyright. All rights reserved.
Lesson: Defining the View Layout
Addition of UI Elements to the Layout
Figure 194: Using the View Editor
The view editor is a Web Dynpro-specific tool that allows you to edit a view layout. The view editor is available only when you edit a view controller. It does not appear when you edit a custom controller because these controllers have no visual interface. The view editor can be used with or without the layout preview. Note: The following description assumes that you are familiar with the basic layout preview.
© Copyright. All rights reserved.
361
Unit 12: Web Dynpro User Interface
View Editor
Figure 195: View Editor
A new UI element can be added in the hierarchical representation from the context menu of any element in the hierarchy that can have child elements (for example, a TransparentContainer element or a Group element). To change the position of a UI element in the element hierarchy, you can move it up or down using the related functionality from the context menu of the element.
Note: If you move an element on another element that may serve as its superordinate element, the dropped element becomes a subelement. Use the following methods to copy an element with all of its subelements: To copy an element within the same view, choose Copy Element from the context menu of the element you would like to copy. Then select the element that should be the parent of the copied element. Finally, choose Insert Copied Element from the context element of the parent element.
●
●
To create a copy template of an element, select Save as Template from the context menu of this element. To use the template, use the Web Dynpro Code Wizard. For each copy template, a list entry is displayed below the standard wizard entries.
The Properties tab page displays all the properties of a selected UI element. The client-side events supported by a UI element are listed in the Events properties section. Properties related to client-side events begin with the prefix on (for example, onFilter, onSort, or onAction). To handle these client-side events, actions are associated with each of the events.
362
© Copyright. All rights reserved.
Lesson: Defining the View Layout
Hint: Client-side events are events related to UI elements that are predefined by the Web Dynpro framework. It is not possible to handle additional events on the client side (for example, by using JavaScript).
© Copyright. All rights reserved.
363
Unit 12: Web Dynpro User Interface
364
© Copyright. All rights reserved.
Unit 12 Exercise 21 Arrange UI Elements with Layout Managers
Business Example Develop a Web Dynpro application with an image on the first view. In addition, arrange the UI elements in a sensible way. Template: NET310_COND_S Solution: NET310_UI_S1 Copy your Solution from the Previous Exercise 1. Copy your solution from the previous exercise (ZNET310_COND_##) or the Web Dynpro template component NET310_COND_S to the new component, ZNET310_UI1_##. Add an Image UI element to the View 1. Add an image UI element to the layout of view INPUT_VIEW. The Image UI element should display the file reisen_1.jpg located in the MIME Repository folder: SAP → BC → WebDynpro → SAP → PUBLIC → NET310. Arrange the UI Elements of INPUT_VIEW Arrange the UI elements of the view, INPUT_VIEW. The transparent container embedding the input fields and the image should be displayed in one row. Both elements together should occupy the complete page width. The transparent container and image should occupy the same height. Alter the background color to visualize the space occupied by the transparent container. 1. Correct the order of the UI elements in the UI element hierarchy. Locate the button in the transparent container embedding the form. At the end of this exercise, the transparent container should be located to the left of the image. 2. Adjust the layout manager assigned to the ROOTUIELEMENTCONTAINER. Instead of the default (FlowLayout), use MatrixLayout. In addition, the Button should be displayed in a new row below the form fields. 3. Change the background color of the form. The area occupied by the surrounding transparent container should be displayed in gray. Arrange the UI Elements of OUTPUT_VIEW in Rows Arrange the UI elements of the view OUTPUT_VIEW in rows. The transparent container containing the form fields should occupy the complete page width. Display the area occupied by this container in gray. 1. Correct the order of the UI elements in the UI element hierarchy. At the end of this task, the button should be displayed below the transparent container embedding the form. Use the menu item Up or Down in the context menu of the button to make it the last element in the UI element hierarchy.
© Copyright. All rights reserved.
365
Unit 12: Web Dynpro User Interface
2. Arrange the UI elements of the view using the RowLayout manager (columns are not needed, but the content can be arranged in rows). 3. Change the background color of the form. The area occupied by the surrounding transparent container should be displayed in gray. Test Your Web Dynpro Component Activate and test your Web Dynpro component. 1. Activate your component. Create a Web Dynpro application with the same name as your component. Start the Web Dynpro application.
366
© Copyright. All rights reserved.
Unit 12 Solution 21 Arrange UI Elements with Layout Managers
Business Example Develop a Web Dynpro application with an image on the first view. In addition, arrange the UI elements in a sensible way. Template: NET310_COND_S Solution: NET310_UI_S1 Copy your Solution from the Previous Exercise 1. Copy your solution from the previous exercise (ZNET310_COND_##) or the Web Dynpro template component NET310_COND_S to the new component, ZNET310_UI1_##. a) On the Object Navigator screen, choose the Other Object button Objects tab.
and select the Web
b) Enter the name of the Web Dynpro component ZNET310_COND_## in the Web Dynpro Comp./Intf. field and choose the Copy button
.
c) In the Copy Web Dynpro component dialog box, enter the new component ZNET310_UI1_## in the Name of Copy field. d) Choose Continue. e) On Create Object Directory Entry dialog box, enter your package and choose Save. f) On the Prompt for transportable Workbench request dialog box, choose continue. Add an Image UI element to the View 1. Add an image UI element to the layout of view INPUT_VIEW. The Image UI element should display the file reisen_1.jpg located in the MIME Repository folder: SAP → BC → WebDynpro → SAP → PUBLIC → NET310. a) On the Web Dynpro Explorer: Display Component screen, choose ZNET310_UI1_## → Views → INPUT_VIEW. b) Choose the layout tab of view, INPUT_VIEW. c) In the context menu of the ROOTUIELEMENTCONTAINER, choose Insert Element. d) Choose element type IMAGE and enter the ID, IMG_PLANE. Choose Continue. e) Choose the MIME Repository button at the top of the navigation area of the ABAP Workbench. f) Open the specified folder by choosing SAP → BC → WebDynpro → SAP → PUBLIC → NET310). Drag the MIME object reisen_1.jpg to the Image UI element in the UI element hierarchy.
© Copyright. All rights reserved.
367
Unit 12: Web Dynpro User Interface
g) Save your settings. Hint: The image can also be assigned to the UI element by setting the element property source to {PUBLIC}/net310/reisen_1.jpg. Arrange the UI Elements of INPUT_VIEW Arrange the UI elements of the view, INPUT_VIEW. The transparent container embedding the input fields and the image should be displayed in one row. Both elements together should occupy the complete page width. The transparent container and image should occupy the same height. Alter the background color to visualize the space occupied by the transparent container. 1. Correct the order of the UI elements in the UI element hierarchy. Locate the button in the transparent container embedding the form. At the end of this exercise, the transparent container should be located to the left of the image. a) Drag the button But_Details onto FORM_CONTAINER. The button will be the last element in the transparent container. 2. Adjust the layout manager assigned to the ROOTUIELEMENTCONTAINER. Instead of the default (FlowLayout), use MatrixLayout. In addition, the Button should be displayed in a new row below the form fields. a) Double-click ROOTUIELEMENTCONTAINER, and in the Layout property, choose MatrixLayout. b) Select BUT_DETAILS. Note: There is no need to correct the layout settings of the transparent container embedding the form òr of the image. In SAP NW 7.0 EhP2, the first subelement of a container assigned the layout manager MatrixLayout automatically receives the layout MatrixHeadData. All other subelements automatically receive the layout MatrixData. This means that the transparent container and image form one row. c) For the Button, set the Layout Data property to FormHeadData. d) Set colSpan to 2. Hint: If the default value (-1) for the property colSpan is not altered, the button stretches across the complete row. 3. Change the background color of the form. The area occupied by the surrounding transparent container should be displayed in gray. a) Edit the properties of the transparent container embedding the form fields, by selecting FORM_CONTAINER. In the cellBackgroundDesign field, choose border. b) Choose Save.
368
© Copyright. All rights reserved.
Lesson: Defining the View Layout
Arrange the UI Elements of OUTPUT_VIEW in Rows Arrange the UI elements of the view OUTPUT_VIEW in rows. The transparent container containing the form fields should occupy the complete page width. Display the area occupied by this container in gray. 1. Correct the order of the UI elements in the UI element hierarchy. At the end of this task, the button should be displayed below the transparent container embedding the form. Use the menu item Up or Down in the context menu of the button to make it the last element in the UI element hierarchy. a) Choose Repository Browser. Double-click OUTPUT_VIEW. b) Expand FORM_CONTAINER. c) In the context menu of BUT_BACK, choose TO LAST POSITION. 2. Arrange the UI elements of the view using the RowLayout manager (columns are not needed, but the content can be arranged in rows). a) For the ROOTUIELEMENTCONTAINER, set the Layout property to RowLayout. Hint: Do not correct the layout settings of the transparent container embedding the form. As of SAP NW 7.0 EhP2, the first subelement of a container assigned the layout manager RowLayout automatically receives the layout RowHeadData. All other subelements automatically receive the layout RowData. b) Edit the properties for BUT_BACK. Set Layout Data to RowHeadData. 3. Change the background color of the form. The area occupied by the surrounding transparent container should be displayed in gray. a) Edit the properties of the transparent container. Set rowBackgroundDesign to Border. Choose Save. Test Your Web Dynpro Component Activate and test your Web Dynpro component. 1. Activate your component. Create a Web Dynpro application with the same name as your component. Start the Web Dynpro application. a) Perform this step as done in the exercise, Create a Simple Web Dynpro.
© Copyright. All rights reserved.
369
Unit 12: Web Dynpro User Interface
LESSON SUMMARY You should now be able to:
370
●
Differentiate UI elements
●
Define the layout using container elements
●
Add UI elements to the layout
© Copyright. All rights reserved.
Unit 12 Lesson 2 Controlling UI Element Behavior with Data Binding
LESSON OVERVIEW This lesson explains how to control UI element behavior by using data binding. Business Example You want to control the behavior of UI elements dynamically (for example, changing their visibility). For this you need to manipulate the entities in the context to which the UI element properties are bound. For this reason, you require the following knowledge: ●
How to bind properties of UI elements to context attributes
●
How to control UI element behavior programmatically
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Bind UI element properties to context attributes
●
Control UI element behavior
Data Binding
Figure 196: Data Binding
To control the behavior of UI elements, you need to manipulate the context nodes or attributes to which the UI element properties are bound. Once a UI element property is bound to a context node or attribute, the context data supplies a value to the UI element property. If the user can update the UI element property (such as the value property of an InputField UI element), the context is automatically updated with the new value during the next round trip.
© Copyright. All rights reserved.
371
Unit 12: Web Dynpro User Interface
Almost all of the properties of a UI element can be bound either to a context node or to a context attribute with the correct data type.
Note: A binding relationship can only exist between the context and UI elements of the same view controller. The developer has full control over the appearance of the screen layout of the Web Dynpro view controller without needing direct access to the UI element objects. To have programmatic control over any property, it should be bound to an appropriate context node or attribute. Context Binding Relationship The context path to the node or attribute is displayed as the value of the property. In addition, the empty circle is replaced by a green check mark icon. The UI element on the layout preview also displays the context path of the node or attribute to which it is bound. The establishment of a binding relationship instructs the Web Dynpro screen renderer to obtain the value for a UI element property from the context node or attribute to which it is bound. Data binding is not limited to supplying a value to an InputField. The value property of a UI element can be supplied with data through a binding relationship. This is the mechanism by which a view controller can adjust the appearance and behavior of its view layout without the need to access the UI element objects themselves. Data Binding Relationship
Figure 197: Positioning Data on the Layout of the View Screen
Data binding is a two-way relationship. Once a binding relationship has been declared, the data in the bound nodes and attributes are transported automatically to the corresponding UI
372
© Copyright. All rights reserved.
Lesson: Controlling UI Element Behavior with Data Binding
elements. After the user has interacted with the screen and initiated an HTTP round trip, the new or modified data in the UI elements is transported back to the same nodes and attributes in the view controller’s context. By the time the Web Dynpro framework hands over control to your action handler, the context already holds the updated information. This two-way transport process is entirely automatic and requires no action on the part of the application developer.
Note: The data entered by the user is automatically converted to the internal format. Then the Web Dynpro Runtime checks whether the data type matches the type of the bound attribute (including domain fixed values). If a validation error occurs, the data is not transported to the context attribute. However, the Web Dynpro Runtime stores the user input so that it can be displayed again (with a validation error message displayed on the next view assembly).
To Define Data Binding The following steps are the minimum requirements to display data on the view controller screen: 1. Create a node or attribute in the context of the view controller that contains the data. 2. Create the UI element in your view layout. 3. For all properties that require data binding, a button with a yellow icon and an empty circle is displayed on the right side of the property. Define the required binding by choosing this button. A dialog box displays the context of the view controller. All nodes or attributes, which have the correct type for binding to the UI element property, are displayed. 4. Select an appropriate node or attribute.
© Copyright. All rights reserved.
373
Unit 12: Web Dynpro User Interface
Definition of UI Element Properties at Design Time
Figure 198: Defining UI Element Properties Statically
The value of a UI element property can either be hard-coded or bound to a context attribute with a suitable data type. If a property value is hard-coded at design time, it can only be changed at runtime by accessing the UI element directly from the source code of the view controller. This can only be done through the hook method wddomodifyview( ) because only this method provides a reference to the UI element hierarchy.
Caution: Accessing the UI element hierarchy directly from a controller’s method is considered poor design because the separation between flow logic and UI is no longer retained. Avoid this technique.
374
© Copyright. All rights reserved.
Lesson: Controlling UI Element Behavior with Data Binding
Dynamic Control of UI Element Properties
Figure 199: Controlling UI Element Properties
To control the behavior of a UI element programmatically, create a context attribute with a data type that matches the property you wish to control. This allows you to control the behavior of the UI element by modifying the related attribute value in any method of any controller that has access to this context attribute. Directly accessing the UI element object from the controller source code is not necessary.
© Copyright. All rights reserved.
375
Unit 12: Web Dynpro User Interface
Binding UI Element Properties
Figure 200: Binding UI Element Properties
Once the context attribute has been created, it must be bound to the appropriate UI element property. The figure shows that the readOnly property of an InputField UI element has been bound to a Boolean context attribute. The value of the context attribute can now be manipulated through any controller hook method or through additionally defined methods. This technique is applicable to most of the UI element properties. Appropriate data types can be found using the Types of the Web Dynpro Runtime tab page in the dialog box displayed when typing a context attribute. Properties that are typically bound to context attributes are the primary property of the UI element (for example, the property value for the InputField) and the properties enabled, readOnly, state, and visible.
376
© Copyright. All rights reserved.
Lesson: Controlling UI Element Behavior with Data Binding
Binding UI Element Properties (1)
Figure 201: Data Binding in SAP NetWeaver 7.0 (ABAP SPS ≥ 12)
In SAP NetWeaver 7.0 SAP_ABAP Support Package Stack 12, each context attribute does not only allow you to bind the primary property of the UI element to it, but also the properties: enabled, visible, readOnly, and state. To allow this kind of data binding, the dialog box displayed in the data binding process contains an additional radio button group consisting of two radio buttons. If you select the upper radio button, a direct data binding is established. If you select the lower radio button, the properties, enabled, visible, readOnly, and state, can be bound to the corresponding context attribute properties. Texts from the ABAP Dictionary Many UI elements (TextViews, Labels, Captions, and so on) display texts in the rendered UI. Texts can be obtained from the ABAP Dictionary in the following ways: The property related to the text is explicitly bound to a data element, a structure field, or a field of a transparent table.
●
●
The UI element is related to a second UI element and the primary property of this second element is bound to a context element typed with a data element. In this case, the property related to the text must be kept blank to use the dictionary text.
For example, Label is related to an InputField and the Text property of the Label is kept blank. The label text originates from the data element related to property value of the InputField. LESSON SUMMARY You should now be able to: ●
Bind UI element properties to context attributes
© Copyright. All rights reserved.
377
Unit 12: Web Dynpro User Interface
●
378
Control UI element behavior
© Copyright. All rights reserved.
Unit 12 Lesson 3 Using Composite UI Elements
LESSON OVERVIEW This lesson explains composite UI elements and in particular the table UI. It also shows you how to perform the necessary context binding, and describes the selection property for tables. Business Example You want to display multiple records to the user on the screen in the form of a table. For this reason, you require the following knowledge: ●
●
●
How to define composite UI elements How to perform the necessary context binding and use the selection property for table User Interfaces (UIs) How to use the test page for UI elements
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Outline UI composite element hierarchy
●
Bind a table UI element and its child elements to the context
●
Set the selection property for table UIs
© Copyright. All rights reserved.
379
Unit 12: Web Dynpro User Interface
Composite UI Elements
Figure 202: Composite UI Elements (1)
Certain UI elements, such as the Table UI, are displayed on the screen as aggregations of simpler, more basic UI elements. Composite UI Elements (2)
Figure 203: Composite UI Elements (2)
Without the subordinate (or child) UI elements, a composite UI element is not capable of displaying any information. Composite UI elements, such as Group and Tray , have a mandatory Caption child UI element, but beyond that, their structure is entirely user defined.
380
© Copyright. All rights reserved.
Lesson: Using Composite UI Elements
Composite UI elements, such as Table and Tree , however, require a more complex mandatory child structure. The Table UI Element
Figure 204: The Table UI Element
The Table UI element acts as a parent of several TableColumn UI elements, each of which acts as the parent for a header (implemented by a Caption UI element) and a cell editor. The term, cell editor, is an abstract expression for all kinds of UI elements that can serve as cell elements in a given column. The default UI element for the cell editor is the TextView UI element. However, depending on the cell value and whether it is changeable, other UI elements can be used as cell editors (for example, InputField , DropDownByKey , Checkbox , or Button ). The Table UI element is an example of a composite UI element. The TableColumn UI element is also a composite UI element.
© Copyright. All rights reserved.
381
Unit 12: Web Dynpro User Interface
Context Binding for the Table UI
Figure 205: Binding a Table UI Element to the Context
The Table UI element allows a two-dimensional display of data in cells arranged in rows and columns. The UI element consists of an optional header area, zero or more rows, and a footer area. The Table UI elements must be bound to a context node of cardinality 0..n or 1..n. The element at the lead selection in the context node is displayed as a highlighted row on the screen (only if a selection column is displayed). The Table UI element, along with its child elements, can be created using the Web Dynpro Code Wizard. If you build it in this way, the necessary data binding will be done automatically as part of the process. However, if the Table UI element has been added to the element hierarchy manually, the context menu option Create Binding is used to create the complete binding.
382
© Copyright. All rights reserved.
Lesson: Using Composite UI Elements
TableColumn UI Elements
Figure 206: TableColumn UI Elements
The Table UI element must contain at least one TableColumn UI element. TableColumn UI elements are composite UI elements. This means that they must have child UI elements to function correctly. The column header is created using a Caption element. The text displayed in the column header can be obtained from the ABAP Dictionary if the text property of the Caption UI element is kept blank and if the primary property of the context attribute displayed in this column is typed with an ABAP Dictionary data element.
© Copyright. All rights reserved.
383
Unit 12: Web Dynpro User Interface
Child UI Elements of a TableColumn
Figure 207: Defining Child UI Elements for a TableColumn
To present information to the user, a TableColumn UI element must have a child UI element that acts as the cell editor. You need to clarify the kind of interaction between the user and the data in each column to decide which UI element is to be used. Despite calling it a cell editor, the user cannot necessarily change the data. If you select a display-only UI element, such as TextView, the UI element does not allow the user to modify the data. If you choose a Button, the cell value is displayed as the text of the button. In this case, you cannot input data but you can fire a client event. If you choose an InputField in the table cell editor, all the cells appearing in that column will be open for input by default. The caption that appears as the column header is optional, but if defined, is always of type Caption.
384
© Copyright. All rights reserved.
Lesson: Using Composite UI Elements
Selection of Table Rows
Figure 208: Table Row Selection
Whenever you choose the selection button of a table row on the rendered screen, a round trip is initiated (default behavior). This round trip causes the lead selection of the context node to which this table is bound, to be altered. In the figure, the node collection contains five elements and the user chooses the first table row. This corresponds to element 1 of node FLIGHTS and the lead selection of this node is altered to reflect the user's selection. The number of rows in the table equals the number of elements in the node collection. You can also define a Web Dynpro action and associate it with the onLeadSelect event of the table. This ensures that when the lead selection index is changed by the user choosing a table row, the wddobeforeaction( ) hook method, the corresponding action handler method, and the wddoafteraction( ) hook method of the view containing the Table UI element are processed.
© Copyright. All rights reserved.
385
Unit 12: Web Dynpro User Interface
Multiple Selections of Rows from a Table
Figure 209: Selecting Multiple Rows from a Table
To allow a user to select multiple rows in a table (by holding down SHIFT or CTRL and choosing the required rows), the context node to which the Table UI element is bound MUST have a selection cardinality of either 0...n or 1...n. Before this, the context node to which the Table UI element is bound must have a selection cardinality of either 0..n or 1..n. The default selection cardinality setting for any context node is 0..1, which means that zero or one element may be selected at any one time. The Table UI Element Property SelectionMode The default value of the table property selectionMode (auto) can be adjusted to none, single, multi, singleNoLead, and multiNoLead. This setting influences user's ability to mark rows and set the lead selection. Settings for the Table UI Element Property SelectionMode ●
selectionMode = none The selection column is not displayed. The row related to the lead selection is not highlighted.
●
selectionMode = single or singleNoLead Only one row may be selected. This is independent of the context node property Selection.
●
selectionMode = singleNoLead or multiNoLead The lead selection index is not changed by selecting table rows.
386
© Copyright. All rights reserved.
Lesson: Using Composite UI Elements
Test Page for UI Elements
Figure 210: Test Page for UI Elements
The Web Dynpro application WDR_TEST_UI_ELEMENTS allows you to investigate and test the functionality of the available UI elements. WDR_TEST_UI_ELEMENTS is delivered in every system containing the Web Dynpro framework.
© Copyright. All rights reserved.
387
Unit 12: Web Dynpro User Interface
388
© Copyright. All rights reserved.
Unit 12 Exercise 22 Display Tables with the Service Wizard
Business Example You have found a function module, which you plan to use to retrieve the data to be used in your Web Dynpro component. You decide to use the Service Wizard to help you create the Context and code based on this function module. Template: N/A Solution: NET310_UI_S2 Create a Web Dynpro Component with a View Create a Web Dynpro component with one view embedded in a window. 1. Create the Web Dynpro component ZNET310_UI2_## containing one view (DISPLAY_VIEW), which is embedded in a window (MAIN_WINDOW). Create a Service Call Create a service call of function module BAPI_FLIGHT_GETLIST in the component controller. This creates a method encapsulating the BAPI call. In addition, the BAPI’s interface parameters are to be used to create the component controller context nodes and attributes. 1. Define the service method and the related context nodes and attributes in the component controller. In Adapt Context, choose Context (Node/Attribute) in the Object Type column of the parameters DESTINATION_FROM, DESTINATION_TO, and FLIGHT_LIST. When asked for the name of the service method, accept the default name (EXECUTE_BAPI_FLIGHT_GETLIST). 2. What entities of the component have been created?
3. What are the cardinalities of nodes DESTINATION_FROM and FLIGHT_LIST? Why are they different?
Copy the Node to the View and Define Context Mapping 1. Copy the node BAPI_FLIGHT_GETLIST defined in the component controller context to the context of the view and define the context mapping. Create Two Groups in One Row In the layout, create two groups in one row. Each group occupies 50% of the total page width. The first group has to embed a form containing input fields to enter the departure city and
© Copyright. All rights reserved.
389
Unit 12: Web Dynpro User Interface
departure country. The second group has to embed a form containing input fields to enter the destination city and destination country. 1. Create a group as a subelement of the ROOTUIELEMENTCONTAINER. Name the group GROUP_DEPA. Display Departure in the header of the group. 2. Create the second group. Name the group GROUP_DEST. Display Destination in the header of the group. 3. Use the Web Dynpro Code Wizard to create a form containing input fields to enter the departure city and departure country in the group GROUP_DEPA. Arrange the form fields using the MatrixLayout layout manager. 4. Repeat the last step for group GROUP_DEST. Create a form containing input fields to enter the destination city and destination country. 5. Adjust the properties of the UI elements. Each group should occupy 50% of the total page width. Use a matrix layout for the page to define two columns. Create a Table to Display the Flights Define a table displaying the related flights below the two forms you created. The table has to occupy the complete page width and display 10 rows. Suppress the selection column. 1. Use the Web Dynpro Code Wizard to create a table displaying the flights stored in node FLIGHT_LIST. The table should display all information, except the carrier ID and the ISO code of the currency. 2. Adjust the properties of the UI element. The table has to occupy the complete page width and display 10 rows. Suppress the selection column. Define a Button to Call the Service Method Define a button that calls the service method defined in the component controller. Locate the button in a new row between the groups and the table. 1. Define the button. 2. Adapt the UI element hierarchy. At the end of this task, the button should be displayed in a new row between the groups and the table. 3. Adjust the properties of the button. Make the button the first element in a new row and define a text to be displayed. Assign an action to the button (DISPLAY_DETAILS). 4. Implement the source code of the action handler method. Call the service method. Test Your application Activate your component and test your application. 1. Activate your component. Create an application to access your component so that you can test it.
390
© Copyright. All rights reserved.
Unit 12 Solution 22 Display Tables with the Service Wizard
Business Example You have found a function module, which you plan to use to retrieve the data to be used in your Web Dynpro component. You decide to use the Service Wizard to help you create the Context and code based on this function module. Template: N/A Solution: NET310_UI_S2 Create a Web Dynpro Component with a View Create a Web Dynpro component with one view embedded in a window. 1. Create the Web Dynpro component ZNET310_UI2_## containing one view (DISPLAY_VIEW), which is embedded in a window (MAIN_WINDOW). a) For detailed steps, see the exercise, Create a Simple Web Dynpro.. Create a Service Call Create a service call of function module BAPI_FLIGHT_GETLIST in the component controller. This creates a method encapsulating the BAPI call. In addition, the BAPI’s interface parameters are to be used to create the component controller context nodes and attributes. 1. Define the service method and the related context nodes and attributes in the component controller. In Adapt Context, choose Context (Node/Attribute) in the Object Type column of the parameters DESTINATION_FROM, DESTINATION_TO, and FLIGHT_LIST. When asked for the name of the service method, accept the default name (EXECUTE_BAPI_FLIGHT_GETLIST). a) In the context menu of ZNET310_UI2_##, choose Create → Service Call. b) In the Web Dynpro Wizard: Start dialog box, choose Continue. c) Select Use Existing Controller, select the component controller of your component, and choose Continue. d) In the Web Dynpro Wizard: Select Service Type dialog box, select Function Module, and choose Continue. e) In the Dynpro Wizard: Select Service dialog box, enter BAPI_FLIGHT_GETLIST for the Function Module, and choose Continue. f) In the Dynpro Wizard: Adapt Node Name dialog box, choose Context (Node/Attribute) in the Object Type column of the controller context parameters DESTINATION_FROM, DESTINATION_TO, and FLIGHT_LIST. Choose Continue. g) In the Dynpro Wizard: Specify Method Name dialog box, choose Continue. h) In the D ynpro Wizard: Generate Controller dialog box, choose Complete.
© Copyright. All rights reserved.
391
Unit 12: Web Dynpro User Interface
2. What entities of the component have been created? The following have been created: The context node BAPI_FLIGHT_GETLIST with several subnodes for the selected IMPORTING and TABLES parameters of the function module; the method EXECUTE_BAPI_FLIGHT_GETLIST( ) in the component controller, which encapsulates the call of the function module; and the controller attributes for the function module parameters AIRLINE and MAX_ROWS. 3. What are the cardinalities of nodes DESTINATION_FROM and FLIGHT_LIST? Why are they different? The cardinalities of node DESTINATION_FROM is 1..1 and of node FLIGHTLIST is 0..n. They are different because the parameter DESTINATION_FROM is a structure, whereas parameter FLIGHT_LIST is an internal table. Copy the Node to the View and Define Context Mapping 1. Copy the node BAPI_FLIGHT_GETLIST defined in the component controller context to the context of the view and define the context mapping. a) On the Web Dynpro Explorer: Change Controller for ZNET310_UI2_## screen, rightclick DISPLAY_VIEW, then double-click DISPLAY_VIEW. If you are prompted, save the component controller. b) Choose the Context tab page. c) In the COMPONENTCONTROLLER context, drag the node BAPI_FLIGHT_GETLIST to the context of the view controller and drop it on the context root node CONTEXT. d) Save your entries. Create Two Groups in One Row In the layout, create two groups in one row. Each group occupies 50% of the total page width. The first group has to embed a form containing input fields to enter the departure city and departure country. The second group has to embed a form containing input fields to enter the destination city and destination country. 1. Create a group as a subelement of the ROOTUIELEMENTCONTAINER. Name the group GROUP_DEPA. Display Departure in the header of the group. a) On the Web Dynpro Explorer: Change View for ZNET310_UI2_## screen, for the view DISPLAY_VIEW, choose the Layout tab page. b) In the context menu of the ROOTUIELEMENTCONTAINER, choose Insert Element and enter the following data: Field Name
Value
ID
GROUP_DEPA
TYP
Group
c) Choose Continue. d) With GROUP_DEPA expanded, double-click CAPTION [Header]. e) For the property text of caption, enter Departure in the Value field.
392
© Copyright. All rights reserved.
Lesson: Using Composite UI Elements
f) Save your entries. 2. Create the second group. Name the group GROUP_DEST. Display Destination in the header of the group. a) Perform this step as described in the previous step. 3. Use the Web Dynpro Code Wizard to create a form containing input fields to enter the departure city and departure country in the group GROUP_DEPA. Arrange the form fields using the MatrixLayout layout manager. a) On the Web Dynpro Explorer: Change View for ZNET310_UI2_## screen, for the view DISPLAY_VIEW, in the Layout tab page, choose the element GROUP_DEPA. b) Choose the Web Dynpro Code Wizard button
.
c) In the Template Gallery dialog box, double-click the Form template. d) In the Create From Elements for Container GROUP_DEPA dialog box, choose the Context button. e) In the Choose Content Element dialog box, double-click DESTINATION_FROM. f) In the Create From Elements for Container GROUP_DEPA dialog box, deselect the checkboxes in the Binding column for the attributes AIRPORTID and COUNTR_ISO. g) Enter MatrixLayout in the Layout of New Container field and choose Continue. 4. Repeat the last step for group GROUP_DEST. Create a form containing input fields to enter the destination city and destination country. a) Perform this step as described in the previous steps, using the node DESTINATION_TO for the destination information. 5. Adjust the properties of the UI elements. Each group should occupy 50% of the total page width. Use a matrix layout for the page to define two columns. a) On the Web Dynpro Explorer: Change View for ZNET310_UI2_## screen, for ROOTUIELEMENTCONTAINER, enter the following property data: Field Name
Value
Layout
MatrixLayout
width
100%
b) Select the checkbox for the property stretchedHorizontally. c) For the group GROUP_DEPA, enter the following property data: Field Name
Value
width
100%
width (LayoutData)
50%
d) For the group GROUP_DEST, enter the following data: Field Name
Value
width
100%
© Copyright. All rights reserved.
393
Unit 12: Web Dynpro User Interface
Field Name
Value
width (LayoutData)
50%
e) Save your entries. Create a Table to Display the Flights Define a table displaying the related flights below the two forms you created. The table has to occupy the complete page width and display 10 rows. Suppress the selection column. 1. Use the Web Dynpro Code Wizard to create a table displaying the flights stored in node FLIGHT_LIST. The table should display all information, except the carrier ID and the ISO code of the currency. a) On the Web Dynpro Explorer: Change View for ZNET310_UI2_## screen, for the view DISPLAY_VIEW, in the Layout tab page, choose ROOTUIELEMENTCONTAINER. b) Choose the Web Dynpro Code Wizard button. c) In the Template Gallery dialog box, double-click the Table template. d) In the Create Context Binding for Table "TABLE" dialog box, choose the Context button. e) In the Choose Context Element dialog box, double-click FLIGHT_LIST. f) In the Create Context Binding for Table "TABLE" dialog box, deselect the checkbox in the Binding column for the attributes AIRLINEID and CURR_ISO. g) Choose Continue. 2. Adjust the properties of the UI element. The table has to occupy the complete page width and display 10 rows. Suppress the selection column. a) On the Web Dynpro Explorer: Change View for ZNET310_UI2_## screen, expand ROOTUIELEMENTCONTAINER and select Table. Enter the following property data: Field Name
Value
Layout Data
MatrixHeadData
selectionMode
none
visableRowCount
10
width
100%
colSpan
2
b) Save your entries. Define a Button to Call the Service Method Define a button that calls the service method defined in the component controller. Locate the button in a new row between the groups and the table. 1. Define the button. a) On the Web Dynpro Explorer: Change View for ZNET310_UI2_## screen, for the view DISPLAY_VIEW, in the context menu of ROOTUIELEMENTCONTAINER, choose InsertElement.
394
© Copyright. All rights reserved.
Lesson: Using Composite UI Elements
b) In the Create Element dialog box, enter the following data: Field Name
Value
ID
BUT_CALL_SERVICE
Typ
Button
c) Choose Continue. 2. Adapt the UI element hierarchy. At the end of this task, the button should be displayed in a new row between the groups and the table. a) On the Web Dynpro Explorer: Change View for ZNET310_UI2_## screen, from the UI element hierarchy, drag the button BUT_CALL_SERVICE and drop it on TABLE. This interchanges the positions of these two elements. 3. Adjust the properties of the button. Make the button the first element in a new row and define a text to be displayed. Assign an action to the button (DISPLAY_DETAILS). a) In the properties of the button BUT_CALL_SERVICE, enter the following data: Field Name
Value
Layout Data
MatrixHeadData
Text
Display flights
b) In the onAction row, choose the Create button
.
c) In the Create Action dialog box, enter the following data: Field Name
Value
Action
DISPLAY_DETAILS
Description
display details button
d) Choose Continue. 4. Implement the source code of the action handler method. Call the service method. a) On the Web Dynpro Explorer: Change View for ZNET310_UI2_## screen, choose the Actions tab page. b) In the Event Handler column, double-click the method ONACTIONDISPLAY_DETAILS. This displays the source code of the method. c) Choose the Web Dynpro Code Wizard button. d) In the Web Dynpro Statement Structure dialog box, choose the General tab page. e) Choose Method Call In Used Controller and enter the following data: Field Name
Value
Component Name
ZNET310_UI2_##
Controller Name
COMPONENTCONTROLLER
© Copyright. All rights reserved.
395
Unit 12: Web Dynpro User Interface
Field Name
Value
Method Name
EXECUTE_BAPI_FLIGHT_GETLIST
f) Choose Continue. g) Save your entries. Test Your application Activate your component and test your application. 1. Activate your component. Create an application to access your component so that you can test it. a) Perform this step as in the exercise, Create a Simple Web Dynpro.
396
© Copyright. All rights reserved.
Lesson: Using Composite UI Elements
LESSON SUMMARY You should now be able to: ●
Outline UI composite element hierarchy
●
Bind a table UI element and its child elements to the context
●
Set the selection property for table UIs
© Copyright. All rights reserved.
397
Unit 12: Web Dynpro User Interface
398
© Copyright. All rights reserved.
Unit 12 Learning Assessment
1. A UI element is any graphical entity that occupies a position within a view layout. Determine whether this statement is true or false. X
True
X
False
2. The __________ category contains elements that are used to display texts or to enter literals. Choose the correct answer. X
A text
X
B action
X
C selection
X
D complex
3. You use the view editor within the custom controller for editing the view layout. Determine whether this statement is true or false. X
True
X
False
4. Once a UI element property is bound to a context node or attribute, the ___________ is used to supply a value to the UI element property. Choose the correct answer. X
A context data
X
B corresponding UI element
X
C Web Dynpro view controller
X
D controller hook method
© Copyright. All rights reserved.
399
Unit 12: Learning Assessment
5. To control the behavior of a UI element programmatically, create a context attribute with a _____________ that matches the property you wish to control. Choose the correct answer. X
A data type
X
B status
X
C data binding
6. The Table UI element allows a ____________ display of data in cells arranged in rows and columns. Choose the correct answer. X
A two-dimensional
X
B one-dimensional
X
C three-dimensional
X
D four-dimensional
7. What is the default selection cardinality for any context node? Choose the correct answer.
400
X
A 0
X
B 1
X
C 1..1
X
D 0..1
© Copyright. All rights reserved.
Unit 12 Learning Assessment - Answers
1. A UI element is any graphical entity that occupies a position within a view layout. Determine whether this statement is true or false. X
True
X
False
2. The __________ category contains elements that are used to display texts or to enter literals. Choose the correct answer. X
A text
X
B action
X
C selection
X
D complex
3. You use the view editor within the custom controller for editing the view layout. Determine whether this statement is true or false. X
True
X
False
4. Once a UI element property is bound to a context node or attribute, the ___________ is used to supply a value to the UI element property. Choose the correct answer. X
A context data
X
B corresponding UI element
X
C Web Dynpro view controller
X
D controller hook method
© Copyright. All rights reserved.
401
Unit 12: Learning Assessment - Answers
5. To control the behavior of a UI element programmatically, create a context attribute with a _____________ that matches the property you wish to control. Choose the correct answer. X
A data type
X
B status
X
C data binding
6. The Table UI element allows a ____________ display of data in cells arranged in rows and columns. Choose the correct answer. X
A two-dimensional
X
B one-dimensional
X
C three-dimensional
X
D four-dimensional
7. What is the default selection cardinality for any context node? Choose the correct answer.
402
X
A 0
X
B 1
X
C 1..1
X
D 0..1
© Copyright. All rights reserved.
UNIT 13
Controller and Context Programming
Lesson 1 Outlining Controller Methods and Attributes
404
Lesson 2 Accessing the Context at Runtime with Controller Methods Exercise 23: Access the Context at Runtime
414 423
Lesson 3 Adding New Elements to a Context Node Exercise 24: Display Mass Data Using Tables
428 435
Lesson 4 Implementing Supply Functions Exercise 25: Implement Supply Functions
442 445
UNIT OBJECTIVES ●
Explain how hook methods are processed
●
Use controller method
●
Use controller attributes
●
Access the context of a controller
●
Access the context node elements
●
Add new elements to a context node
●
Use supply functions
© Copyright. All rights reserved.
403
Unit 13 Lesson 1 Outlining Controller Methods and Attributes
LESSON OVERVIEW This lesson explains the different hook methods and the order in which they are processed. It also describes how additional controller methods and attributes can be created. Business Example You already know how to create a Web Dynpro component, but until now, you have exclusively worked with entities that can be created in a declarative manner. Now you need to implement the flow logic (including access to the back-end logic) by writing ABAP source code in controller methods. For this reason, you require the following knowledge: ●
An understanding of the phase model and hook methods
●
An understanding of additional controller methods
●
An understanding of controller attributes
LESSON OBJECTIVES After completing this lesson, you will be able to:
404
●
Explain how hook methods are processed
●
Use controller method
●
Use controller attributes
© Copyright. All rights reserved.
Lesson: Outlining Controller Methods and Attributes
Entities of Controllers
Figure 211: Controller Methods
Every Web Dynpro controller is a separate local ABAP class defined in the global ABAP class related to the Web Dynpro component. The definition of these classes is generated automatically when a new component or controller is declared. The source code that implements these controllers is generated automatically. Each controller provides a number of predefined methods, which are called hook methods. Hook methods are called by the Web Dynpro runtime in a predefined order. When the controller is created, these methods are empty, but then the developer can add code to them as required. In addition to the hook methods, the developer can define the following types of methods: ● Ordinary methods ●
Event handler methods
●
Supply functions
The controller class is generated from all controller methods – hook methods and userdefined methods – every time the controller is activated. The ABAP Workbench allows you to enter source code in the controller methods only. The generated controller class is not accessible.
© Copyright. All rights reserved.
405
Unit 13: Controller and Context Programming
Standard Hook Methods for all Controllers
Figure 212: Standard Hook Methods for all Controllers
All controller types provide the following standard hook methods: wddoinit( ) This is the first method processed in the lifetime of the controller. It is only called once in the controller's lifecycle. All your initialization code should go inside this method as the method is called immediately after the controller has been instantiated. wddoexit() This is the last method processed at the end of the lifecycle of the controller. All your cleanup code should go inside this method. Additional hook methods are available depending on the controller type. Standard Hook Methods – Component Controller
Figure 213: Standard Hook Methods – Component Controller
406
© Copyright. All rights reserved.
Lesson: Outlining Controller Methods and Attributes
The component controller has the following additional standard hook methods: ● wddobeforenavigation( ) Whenever a client event is raised, the corresponding action method in the view controller is processed. The wddobeforenavigation( ) method is called after the action method has been processed and just before the Web Dynpro framework processes the events in the navigation queue. In complex Web Dynpro applications, it may be necessary to validate the data from multiple components before the next step in the business process can be taken. This method can be used for this purpose ●
wddopostprocessing( ) This is the last controller method processed before the user interface (UI) is sent to the client.
●
wddoapplicationstatechange( ) This method is processed each time the application is suspended or resumed. Suspending a Web Dynpro application happens if a suspend plug of the window is fired. This method can be used to start a new application without exiting the current Web Dynpro application. The temporarily disabled Web Dynpro application is resumed automatically if the second application has stopped. The suspended Web Dynpro application is then resumed by entering the window through a resume plug. If a suspend plug is created for a window, one resume plug should also be created.
View Controller Standard Hook Methods
Figure 214: Standard Hook Methods – View Controller
View controllers have the following additional hook methods: wddobeforeaction( )
●
This method typically contains the source code related to input checks.
© Copyright. All rights reserved.
407
Unit 13: Controller and Context Programming
After the user has raised a client event bound to an action, the first methods processed in the Web Dynpro application are the wddobeforeaction( ) methods of all view controllers of the previously rendered view assembly. This happens even before the action handler method related to the client event is processed. ●
wddoafteraction( ) This method can be used to modularize the source code related to action handling. After an action handler method has been processed, the wddoafteraction( ) methods of all view controllers of the previously rendered view assembly are processed.
●
wddomodifyview( ) This method can be used to manipulate the UI element hierarchy dynamically. The only method that permits access to the UI element hierarchy is the view’s wddomodifyview( ) method. The interface parameter VIEW is a reference to the UI element hierarchy. The FIRST_TIME parameter can be used to find out if this method has been previously processed in the lifecycle of the view controller.
●
wddooncontextmenu( ) This method is processed each time the user right-mouse clicks on any UI element defined in the related view layout. From the source code of this method, statically defined context menus can be instantiated and new context menus can be defined. These context menus can be assigned to any UI element defined in the view hierarchy. This enables the standard context menu accessed through a right-click to be extended to include application specific functions.
Special Hook Methods for Window Controllers The special hook methods for window controllers are as follows: wddoonopen( )
●
This special hook method is processed if the window is sent as a dialog box, just before the dialog box is opened. ●
wddoonclose( ) This special hook method is processed if the window is sent as a dialog box, just before the dialog box is closed.
Note: These two special hook methods can contain code that should only be processed if the window is displayed as a dialog box (for example, defining buttons displayed in the frame of the dialog box).
408
© Copyright. All rights reserved.
Lesson: Outlining Controller Methods and Attributes
Phase Model (Basics)
Figure 215: Phase Model (Simple Case)
The phase model describes the order in which the controller methods are processed. Depending on the complexity of the Web Dynpro application (if subcomponents are involved and if the views are nested by using ViewContainerUIElements ), the phase model may also be complex. In addition, error messages influence the phase model.
Note: This section describes the simplest situation with one component, one view, and no error situations. Starting a Web Dynpro Application When a Web Dynpro application is started, the controllers are processed as follows: ● All controllers needed for the first display are instantiated. This means that the wddoinit( ) methods are processed for component controller, window controller, and view controller. ●
The inbound plug method of the interface view related to the application is processed. By default, the Default plug is used. This means that the handledefault( ) method is processed.
●
The component controller wddobeforenavigation( ) method is processed.
●
The view controller wddomodifyview( ) method is processed.
●
The component controller wddopostprocessing( ) method is processed.
A user interaction typically triggers the next request. For some UI elements (for example, a button), it is necessary that an action is bound to the client side event. However, some user interactions lead to a request without having to bind an action to the related client side event (for example, scrolling in a table and selecting a new table row).
© Copyright. All rights reserved.
409
Unit 13: Controller and Context Programming
The phase model for a request triggered by a user interaction can be described as follows: ● If the client side event is bound to an action, the wddobeforeaction( ) , onaction( ) , and wddoafteraction( ) methods are processed. In the component controller, the wddobeforenavigation( ) method is processed. ●
●
If an outbound plug is fired and a navigation link to an inbound plug is defined in the window, the view related to the inbound plug is instantiated and the wddoinit( ) method is processed. The inbound plug handle( ) method is processed for this view. If the lifetime of the previous view is restricted, the wddoexit( ) method is processed for the previous view.
●
In the view controller, the wddomodifyview( ) method is processed for the next view.
●
In the component controller, the wddopostprocessing( ) method is processed.
Additional Controller Methods
Figure 216: Additional Controller Methods
You can create additional methods for all controllers by declaring the method name and its parameters on the Methods tab page of the controller editor window. To define an ordinary method, choose Method Type = Method. If you choose Method Type = Event Handler, an event handler method is created. This event handler method can be registered statically (in the Event column) to any event fired in a controller that is defined as a Used Controller on the Properties tab page. Finally, Method Type = Supply Function can be set to define methods that can be bound to context nodes (Supply Function property). The methods that can be bound to context nodes can be called by the Web Dynpro framework in the following conditions: ● One or more elements of the context node are accessed and the context node is not filled yet or is initial.
410
© Copyright. All rights reserved.
Lesson: Outlining Controller Methods and Attributes
●
The context node has been invalidated in a previous step.
Hint: Supply functions cannot be called explicitly from the source code of the controller methods. Only the Web Dynpro runtime may call this type of method. Controller Method Definitions When you double-click the method name, you can define the signature and source code of the method. All methods are public and can be used by any other controller of the same component (except for methods defined in a view controller, which can only be called within the view itself). As a prerequisite, the controller that calls the method has to define a usage relation to the controller that owns the methods. The ABAP source code to call a method in the used controller can be generated using the Web Dynpro Code Wizard. If the Interface flag is set for a user-defined component controller method, this method appears in the component interface. As a result, this method also becomes visible to other components.
Controller Attributes
Figure 217: Standard Controller Attributes
Each controller is a separate local ABAP class with predefined and user-defined methods and attributes. For each controller, at least two attributes are predefined. The visibility of these attributes is restricted to the methods of the same controller. A controller has the following standard attributes: WD_THIS
●
© Copyright. All rights reserved.
411
Unit 13: Controller and Context Programming
This is a self-reference to the local controller interface. This attribute is distinguished from the standard ABAP self-reference ME, which should not be used in the source code of any controller. WD_THIS is a reference to the interface of the current controller, IF_, and represents all the functionality implemented in the generated class. It also gives you access to standard Web Dynpro functionality, such as validation. ●
WD_CONTEXT This is a reference to the context root node of the controller and thus to the entire context. Any access to the context of the controller starts with this reference.
Additional Attributes If the component controller is declared as a used controller on the Properties tab page of any other controller, an additional attribute, WD_COMP_CONTROLLER, is automatically created for the controller that declared the usage. WD_COMP_CONTROLLER is a reference to the component controller. Using this reference, all methods and public attributes of the component controller can be accessed (wd_comp_controller->, where is a placeholder for the method name, or wd_comp_controller->, where is a placeholder for the attribute name). For all other controllers, even if declared as used controllers, such a reference is not available. However, this does not mean that user-defined methods and public attributes are not available. Instead, it means that the reference must be determined first. To access the local controller interface of a used controller , use the following statement: DATA: lo_ctrl TYPE REF TO ig_ . lo_ctrl = wd_this->get__ctr( ). User-Defined Attributes
Figure 218: User-Defined Controller Attributes and Controller Methods
On the Attributes tab page, additional attributes can be defined for the related controller. If the Public flag is set, these attributes are also visible for other controllers of the same Web Dynpro component. Attributes cannot be exposed to the interface of the component. The reference variable WD_THIS is used to access public controller attributes in any of the methods of the controller. To access the public attributes defined in other controllers of the
412
© Copyright. All rights reserved.
Lesson: Outlining Controller Methods and Attributes
same component, determine the reference to the local controller interface of the used controller. LESSON SUMMARY You should now be able to: ●
Explain how hook methods are processed
●
Use controller method
●
Use controller attributes
© Copyright. All rights reserved.
413
Unit 13 Lesson 2 Accessing the Context at Runtime with Controller Methods
LESSON OVERVIEW This lesson explains how to access context nodes and elements. It also shows how to read and change attribute values. Business Example You want to use the appropriate Web Dynpro methods to access the controller context at runtime, and to read, change, add, or delete information stored there. For this reason, you require the following knowledge: ●
An understanding of how to access the controller context
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Access the context of a controller
●
Access the context node elements
Access to Context Nodes and Elements
Figure 219: Accessing a Context Node
414
© Copyright. All rights reserved.
Lesson: Accessing the Context at Runtime with Controller Methods
Controller attributes can be used to hold data that is visible throughout the controller. However, it is not possible to bind UI element properties to these controller attributes. UI element properties can be bound only to the attributes that are defined in the controller context. Accessing the controller context at runtime (for example to read or change data) requires knowledge of the appropriate Web Dynpro methods. To access a context element or a context attribute, you first need a reference to the related context node. A local interface is generated with the name IF_ for each controller (). Within this interface, a constant (WDCTX_) is generated for each node () of the controller context. It has the name of the node (in uppercase letters) as its value. This constant can be used to access the context node. Accessing the Context Root Node The context root node can be accessed through the standard attribute WD_CONTEXT. Child nodes of the context root node can be identified using the get_child_node( ) method. This method returns a reference to the node instance of type IF_WD_CONTEXT_NODE. The get_child_node( ) method requires the caller to pass in the name of the node. Optionally, you can supply the method the index of the element of the parent node to which the desired node instance belongs. If the index is not provided, the lead selection index is used implicitly. Hint: For independent nodes, the index can always be omitted because the context root node only ever has one element being the element at lead selection.
Note: The path_get_node ( path = ’’ ) method is a special means of accessing the reference to a dependent node. As a parameter, the complete path to the desired node is passed to the method. The node names and the element indexes construct the path (for example, ..). If the element index is omitted (in this case, .), the sub node instance is determined for the element at lead selection of the superordinate node .
© Copyright. All rights reserved.
415
Unit 13: Controller and Context Programming
Accessing a Node Element
Figure 220: Accessing the Node Element at Lead Selection
After accessing a context node, the reference to the element at lead selection of this node can be obtained by calling the get_element( ) method. This method returns a reference to the element instance of type IF_WD_CONTEXT_ELEMENT. The element with index n can be accessed using the method get_element(index = n). The number of elements in a collection can be obtained from the method get_element_count( ). Accessing Context Nodes and Node Elements To access context nodes and node elements, the following methods can be used:
Table 8: Methods to Access Context Nodes and Node Elements Action
416
Method
Reference to context node
lo_nd_ = wd_context->get_child_node( name = wd_this->wdctx_ ).
Reference to element at lead selection
lo_el_ = lo_nd_->get_element( ).
Reference to element with index n
lo_el_ = lo_nd_->get_element( index = n ).
© Copyright. All rights reserved.
Lesson: Accessing the Context at Runtime with Controller Methods
Action
Method
Get number of elements in collection
n = lo_->get_element_count( ).
Attribute Values
Figure 221: Accessing a Single Attribute of a Node Element
The Web Dynpro framework offers various methods to access the attributes of one node element or to access the attributes of all elements of a context node. Once you have obtained the reference to a node element, you can obtain the attribute values of this element in the following ways: ● You can access any attribute of a node element using the method get_attribute( ). You must export the name of the attribute. The attribute value is returned in an import parameter. ●
You can obtain all statically defined attributes by calling the method get_static_attributes( ). A structure is returned. The target structure can be different from the node structure, if a dictionary type was used to define it, but not all fields were used as attributes.
© Copyright. All rights reserved.
417
Unit 13: Controller and Context Programming
Accessing All Statically Defined Attributes of a Node Element
Figure 222: Accessing All Statically Defined Attributes of a Node Element
By using the method get_static_attributes( ), you can retrieve all attributes of the elements in a structure instead of having to call the method, get_attribute( ), several times. The following information is important when accessing context attributes: For each node () of a controller context, a structure type element_ is implicitly generated in the interface IF_. If the node is typed using the dictionary, element_ is typed identically. If the node is not typed, the structure fields correspond to the attributes defined in the node. This structure type can be used to type a data object, which is filled by the get_attribute( ) and the get_static_attributes( ) methods.
●
●
418
In addition, for each node () of a controller context, a standard table type, elements_, is implicitly generated in the interface, IF_. The line type of this table is element_. This table type can be used to type an internal table that can hold the attributes of multiple node elements.
© Copyright. All rights reserved.
Lesson: Accessing the Context at Runtime with Controller Methods
Access to the Static Attributes of All Node Elements
Figure 223: Access to the Static Attributes of All Node Elements
The attributes of all elements can be retrieved as an internal table with the method, get_static_attributes_table( ). To access the datasets related to multiple table rows selected by the user, call the method, get_selected_elements( ), of the node. This method returns all the selected elements in an internal table (type WDR_CONTEXT_ELEMENT_SET). Each row in this internal table contains the reference to one selected element.
Note: To select a context element, the user marks the corresponding table row. Although the element at lead selection is highlighted, the related context element is not automatically selected. When calling the method, get_selected_elements( ), the application has to define whether the element at lead selection has to be returned even if not selected explicitly. This is determined by the value of parameter, INCLUDING_LEAD_SELECTION.
© Copyright. All rights reserved.
419
Unit 13: Controller and Context Programming
Changing the Attribute Values of a Node Element
Figure 224: Changing a Single Attribute of a Node Element
Once the reference to a certain node element has been determined, you can read the attribute values using the appropriate GET methods. You can also change the existing attribute values by calling the related SET methods. The method set_attribute( ) can be used to change the value of any attribute of the node element. Multiple attributes can be changed if they are statically defined using the method, set_static_attributes( ).
420
© Copyright. All rights reserved.
Lesson: Accessing the Context at Runtime with Controller Methods
Changing Multiple Attributes of a Node Element
Figure 225: Changing Multiple Attributes of a Node Element
The figure shows a code snippet which changes multiple attributes of a node element at the same time.
Table 9: Methods to Access and Change Attributes of a Node Action Read value of attribute
Method DATA: lv_ TYPE wd_this->element_-. lo_el_->get_attribute( EXPORTING name = '' IMPORTING value = lv_ ).
Read value of multiple static attributes
DATA: ls_ TYPE wd_this->element_. lo_el_-> get_static_attributes( IMPORTING static_attributes = ls_ ).
© Copyright. All rights reserved.
421
Unit 13: Controller and Context Programming
Action Read static attribute values for all node elements
Method DATA: lt_ TYPE wd_this->elements_. lo_nd_-> get_static_attributes_table( IMPORTING table = lt_ ).
Change value lv_ of a single attribute
DATA: lv_ TYPE wd_this->element_-. lv_ = ... lo_el_->set_attribute( EXPORTING name = '' value = lv_ ).
Change multiple attributes of a node element
DATA: ls_ TYPE wd_this->element_. ls_- = ... ... lo_el_-> set_static_attributes( EXPORTING static_attrs = ls_ ).
422
© Copyright. All rights reserved.
Unit 13 Exercise 23 Access the Context at Runtime
Business Example You want to develop a Web Dynpro application that displays default values in the input fields of the first view at runtime. Template: NET310_UI_S1 Solution: NET310_CONR_S1 Make a Copy of Your Web Component Copy your Web Dynpro component ZNET310_UI1_## or the template NET310_UI_S1 to Web Dynpro component ZNET310_CONR1_##. Create an application to access this component. 1. Copy the template. 2. Create a Web Dynpro application to access the new component. Set AA as Default Field Value Make AA the default value of the field displaying the carrier ID on INPUT_VIEW. 1. Implement the method WDDOINIT of the view controller. Use the Web Dynpro Code Wizard to set the default value of context attribute FLIGHTINFO.CARRID. 2. Activate your changes and test your application. Set Default Values for All Input Fields Set default values for all input fields before the view is displayed. Make LH the default value of the field displaying the carrier ID and make 0400 the default value of the field displaying the connection number. 1. Comment out the code you added in the last task. 2. Use the Web Dynpro Code Wizard to set the default values of context attributes FLIGHTINFO.CARRID and FLIGHTINFO.CONNID in one step. 3. Activate your changes and test your application.
© Copyright. All rights reserved.
423
Unit 13 Solution 23 Access the Context at Runtime
Business Example You want to develop a Web Dynpro application that displays default values in the input fields of the first view at runtime. Template: NET310_UI_S1 Solution: NET310_CONR_S1 Make a Copy of Your Web Component Copy your Web Dynpro component ZNET310_UI1_## or the template NET310_UI_S1 to Web Dynpro component ZNET310_CONR1_##. Create an application to access this component. 1. Copy the template. a) On the Object Navigator screen, double-click the Web Dynpro component ZNET310_UI1_## and choose the Other Object button from the Web Dynpro Explorer bar. b) On the Object Selection screen, select Enhanced Options. In the Web Objects tab, select Web Dynpro Comp./Intf. and enter ZNET310_UI1_02. Choose Copy . c) In the Copy Web Dynpro Component dialog box, enter ZNET310_CONR1_## in the Name of Copy field. d) Choose Continue. e) In the Create Object Directory Entry screen, choose Save. f) In the Prompt for transportable Workbench request screen, choose Continue. 2. Create a Web Dynpro application to access the new component. a) For detailed steps, see the exercise, Create a Simple Web Dynpro. Set AA as Default Field Value Make AA the default value of the field displaying the carrier ID on INPUT_VIEW. 1. Implement the method WDDOINIT of the view controller. Use the Web Dynpro Code Wizard to set the default value of context attribute FLIGHTINFO.CARRID. a) On the Web Dynpro Explorer: Change Web Dynpro Application screen, for the component ZNET310_CONR1_##, choose the view INPUT_VIEW and choose the Methods tab page. b) In the Method column, double-click WDDOINIT and choose the Web Dynpro Code Wizard button. c) In the Web Dynpro Statement Structure dialog box, choose the Context tab, select the Set radio button and choose the Context button.
424
© Copyright. All rights reserved.
Lesson: Accessing the Context at Runtime with Controller Methods
d) In the CONTEXT_VIEWER dialog box, double-click the attribute CARRID. e) Choose Continue. f) Before the method SET_ATTRIBUTE, which the code wizard should have inserted (lo_el_flightinfo->set_attribute), delete the asterisk before lv_carrid = 1 and set the value of the variable LV_CARRID to 'AA'. g) See the source code provided at the end of this task. 2. Activate your changes and test your application. a) Perform this step as in the exercise, Create a Simple Web Dynpro. The form field displaying the carrier should display the value AA. The source code is as follows: View INPUT_VIEW, Method WDDOINIT METHOD DATA DATA DATA DATA
wddoinit . lo_nd_flightinfo TYPE REF TO if_wd_context_node. lo_el_flightinfo TYPE REF TO if_wd_context_element. ls_flightinfo TYPE wd_this->element_flightinfo. lv_carrid TYPE wd_this->element_flightinfo-carrid.
* navigate from to via lead selection lo_nd_flightinfo = wd_context->get_child_node( name = wd_this->wdctx_flightinfo ). * get element via lead selection lo_el_flightinfo = lo_nd_flightinfo->get_element( ). * @TODO fill attribute lv_carrid = 'AA'. * set single attribute lo_el_flightinfo->set_attribute( name = `CARRID` value = lv_carrid ). ENDMETHOD. Set Default Values for All Input Fields Set default values for all input fields before the view is displayed. Make LH the default value of the field displaying the carrier ID and make 0400 the default value of the field displaying the connection number. 1. Comment out the code you added in the last task. a) See the source code given at the end of this task. 2. Use the Web Dynpro Code Wizard to set the default values of context attributes FLIGHTINFO.CARRID and FLIGHTINFO.CONNID in one step. a) In the view INPUT_VIEW of the component ZNET310_CONR1_##, choose the Methods tab page and double-click the WDDOINIT method. b) Choose the Web Dynpro Code Wizard button. c) In the Web Dynpro Statement Structure dialog box, select the Set radio button and choose the Context button. d) In the CONTEXT_VIEWER dialog box, double-click the node FLIGHTINFO.
© Copyright. All rights reserved.
425
Unit 13: Controller and Context Programming
e) Choose Continue. f) Before the method SET_STATIC_ATTRIBUTES which the code wizard should have inserted (lo_el_flightinfo->set_static_attributes), fill the structure LS_FLIGHTINFO as follows: ls_flightinfo-carrid = 'LH'. ls_flightinfo-connid = '0400'. g) The source code is as follows: View INPUT_VIEW, Method WDDOINIT, Task 2 METHOD wddoinit . * DATA lo_nd_flightinfo TYPE REF TO if_wd_context_node. * DATA lo_el_flightinfo TYPE REF TO if_wd_context_element. * DATA ls_flightinfo TYPE wd_this->element_flightinfo. * DATA lv_carrid TYPE wd_this->element_flightinfo-carrid. *** navigate from to via lead selection * lo_nd_flightinfo = wd_context->get_child_node( name = wd_this->wdctx_flightinfo ). *** get element via lead selection * lo_el_flightinfo = lo_nd_flightinfo->get_element( ). *** @TODO fill attribute * lv_carrid = 'AA'. *** set single attribute * lo_el_flightinfo->set_attribute( * name = `CARRID` * value = lv_carrid ). DATA lo_nd_flightinfo TYPE REF TO if_wd_context_node. DATA lo_el_flightinfo TYPE REF TO if_wd_context_element. DATA ls_flightinfo TYPE wd_this->element_flightinfo. * navigate from to via lead selection lo_nd_flightinfo = wd_context->get_child_node( name = wd_this->wdctx_flightinfo ). * get element via lead selection lo_el_flightinfo = lo_nd_flightinfo->get_element( ). * @TODO fill static attributes ls_flightinfo-carrid = 'LH'. ls_flightinfo-connid = '0400'. * set all declared attributes lo_el_flightinfo->set_static_attributes( static_attributes = ls_flightinfo ). ENDMETHOD. 3. Activate your changes and test your application. a) Perform this step as in the exercise Create a Simple Web Dynpro. The form field displaying the carrier should display the value 'LH' and the connection number should display the value 0400.
426
© Copyright. All rights reserved.
Lesson: Accessing the Context at Runtime with Controller Methods
LESSON SUMMARY You should now be able to: ●
Access the context of a controller
●
Access the context node elements
© Copyright. All rights reserved.
427
Unit 13 Lesson 3 Adding New Elements to a Context Node
LESSON OVERVIEW This lesson explains how to add new elements to a context node. Business Example You know how to read and change data already stored in the controller context. You know how to read and change data already stored in the controller context, but you now need to understand how to add new elements to the context to provide the data for a Table UI element. For this reason, you require the following knowledge: ●
How to add new elements to a context node
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Add new elements to a context node
Addition of New Elements to a Context Node The process of adding a new element to a node is like the process of adding a new row to an internal table where you first define the cell values of a work area that has the correct row type, and then insert the work area into the internal table. You add a new element to a node in the following steps: 1. Create an element that can be added to a certain context node. 2. Define the appropriate attribute values. 3. Add the new element to the context node.
428
© Copyright. All rights reserved.
Lesson: Adding New Elements to a Context Node
Getting the Reference to a Context Node
Figure 226: Getting the Reference to a Context Node
To create an element that can be added to a certain context node, the reference to this node has to be determined first. You can do this by using the get_child_node( ) method of the standard attribute WD_CONTEXT., and pointing it to the context root node. Once you have obtained this reference, use the create_element( ) method to create the new element. The attribute values can either be provided by using the parameter static_attribute_values parameter of the create_element( ) method, or by separately calling the methods set_attribute( ) or set_static_attributes( ).
Caution: The new element is not yet a part of the context node.
© Copyright. All rights reserved.
429
Unit 13: Controller and Context Programming
Creation of a New Node Element
Figure 227: Creating a New Node Element
The figure shows the call of the create_element( ) method to create and return the reference to a new element. Setting the Attribute Values of the New Element
Figure 228: Setting the Attribute Values of the New Element
430
© Copyright. All rights reserved.
Lesson: Adding New Elements to a Context Node
The figure shows the use of the set_attribute( ) method to provide values for the attributes of the newly created element. Binding an Element to a Context Node
Figure 229: Binding an Element to a Context Node
The newly created element must now be added to the context node. This is done by calling the bind_element( ) method for the node in question. The bind_element( ) method has the following import parameters: ● The new_item parameter The element reference is submitted through this parameter ●
The set_initial_elements parameter This parameter defines whether the new element is simply added to the element collection (value = abap_false) or replaces all existing elements in the collection (value = abap_true).
© Copyright. All rights reserved.
431
Unit 13: Controller and Context Programming
Binding a Structure to a Context Node
Figure 230: Binding a Structure to a Context Node
In ABAP programs, datasets are handled as structures. To display the structure contents in the UI, the structure content must be copied to a context element. This means that a new element must be defined, the attribute values must be set, and the element must be bound to the appropriate context node. There is an easier way to copy the structure content as a new element to the context node. Instead of using the bind_element( ) method and submitting the element reference, you can use the bind_structure( ) method with the new_item parameter to submit the structure. The existing collection can be extended or replaced by using the set_initial_elements parameter.
432
© Copyright. All rights reserved.
Lesson: Adding New Elements to a Context Node
Binding an Internal Table to a Context Node
Figure 231: Binding an Internal Table to a Context Node
Multiple datasets with identical structures are handled as internal tables in ABAP programs. However, to be able to display the datasets in the UI, copy the internal table content to as many context elements as there are rows in the internal table. The best way to add multiple new elements to a context node is to use the bind_table( ) method. The internal table is submitted through the parameter new_items. The existing collection can be extended or replaced (set_initial_elements parameter). Deleting Elements from a Context Node To remove an element from a collection, call the remove_element( ) method. Submit the reference to the element using the element parameter. To add or delete elements from the context, use the following methods: Action
Method
Create a new element
lo_el_ = lo_nd_->create_element( ).
Add element to collection
lo_nd_->bind_element( new_item = lo_el_ set_initial_elements = abap_false ).
© Copyright. All rights reserved.
433
Unit 13: Controller and Context Programming
Action Bind structure ls_ to collection
Method DATA: ls_ TYPE wd_this->element_. ... lo_nd_->bind_structure( new_item = ls_ set_initial_elements = abap_false ).
Bind internal table lt_ to collection
DATA: lt_ TYPE wd_this->elements_. ... lo_nd_->bind_table( new_items = lt_ set_initial_elements = abap_false ).
Remove element from collection
434
lo_nd_->remove_element( element = lo_el_ ).
© Copyright. All rights reserved.
Unit 13 Exercise 24 Display Mass Data Using Tables
Business Example You want to develop a Web Dynpro application in which the user can enter selection criteria in the first view. After the user clicks a button, the application reads the related flights from the database, and navigates to a second view, in which the selected flights are displayed as a table. Template: NET310_CONR_S1 Solution: NET310_CONR_S2 Make a Copy of Your Component Copy your Web Dynpro component ZNET310_CONR1_## or the template NET310_CONR_S1 to Web Dynpro component ZNET310_CONR2_##. Create a new application to access this component. 1. Copy the template. 2. Create a new application to access your component. Create a New Context Node In the context of the component controller, create a new context node to store datasets for flights read from database table SFLIGHT. Copy this context node to the context of the view OUTPUT_VIEW and map the context nodes. 1. In the component controller context, create a new context node (suggested name: FLIGHTTAB)‚ with reference to the ABAP Dictionary structure SFLIGHT, and with cardinality 0...n. The node should contain the following attributes: ●
CARRID
●
CONNID
●
FLDATE
●
PLANETYPE
●
SEATSMAX
●
SEATSOCC
2. Copy and map the new context node to the context of the view OUTPUT_VIEW. Display the Flight Data in a Table Extend the layout of the view OUTPUT_VIEW to display the flight data in a table. 1. Use the Web Dynpro Code Wizard to create a table with binding to the context node FLIGHTTAB.
© Copyright. All rights reserved.
435
Unit 13: Controller and Context Programming
Create a Method for Storing Flight Data in an Internal Table Create a method in the component controller in which you select flights from database table SFLIGHT and store them in an internal table. Use the static method CL_NET310_FLIGHTMODEL=>READ_FLIGHTS( ) to collect the data. Store the result in context node FLIGHTTAB. 1. Create a new method in the component controller (name: FLIGHTTAB_FILL). 2. Use the Web Dynpro Code Wizard to read the user input from the element at lead selection of node FLIGHTINFO. 3. In the FLIGHTTAB_FILL method, edit the generated source code to create an internal table (name: LT_FLIGHTTAB) of table type NET310_T_SFLIGHT. Use the CL_NET310_FLIGHTMODEL=>READ_FLIGHTS( ) static method to fill the internal table (export parameter ET_FLIGHTS). Use CARRID and CONNID entered by the user to restrict the data selection. 4. Use the code wizard to insert the necessary code to store the contents of the internal table in the context node FLIGHTTAB. Set the Order of Execution Make sure that your new component controller method is executed after the navigation, immediately before the view OUTPUT_VIEW is displayed. 1. Edit the HANDLEIN_DEFAULT( ) method of the view OUTPUT_VIEW and use the Web Dynpro Code Wizard to implement a call of the component controller FLIGHTTAB_FILL( ) method.
436
© Copyright. All rights reserved.
Unit 13 Solution 24 Display Mass Data Using Tables
Business Example You want to develop a Web Dynpro application in which the user can enter selection criteria in the first view. After the user clicks a button, the application reads the related flights from the database, and navigates to a second view, in which the selected flights are displayed as a table. Template: NET310_CONR_S1 Solution: NET310_CONR_S2 Make a Copy of Your Component Copy your Web Dynpro component ZNET310_CONR1_## or the template NET310_CONR_S1 to Web Dynpro component ZNET310_CONR2_##. Create a new application to access this component. 1. Copy the template. a) For detailed steps, see the exercise Create View Assemblies. 2. Create a new application to access your component. a) For detailed steps, see the exercise Create a Simple Web Dynpro. Create a New Context Node In the context of the component controller, create a new context node to store datasets for flights read from database table SFLIGHT. Copy this context node to the context of the view OUTPUT_VIEW and map the context nodes. 1. In the component controller context, create a new context node (suggested name: FLIGHTTAB)‚ with reference to the ABAP Dictionary structure SFLIGHT, and with cardinality 0...n. The node should contain the following attributes: ●
CARRID
●
CONNID
●
FLDATE
●
PLANETYPE
●
SEATSMAX
●
SEATSOCC
a) For detailed steps, see the exercise, Define, Map, and Bind Data to the Context. 2. Copy and map the new context node to the context of the view OUTPUT_VIEW.
© Copyright. All rights reserved.
437
Unit 13: Controller and Context Programming
a) For detailed steps, see the exercise: Define, Map, and Bind Data to the Context, task: Create a Form with an Attribute and Input Fields. Display the Flight Data in a Table Extend the layout of the view OUTPUT_VIEW to display the flight data in a table. 1. Use the Web Dynpro Code Wizard to create a table with binding to the context node FLIGHTTAB. a) On the Web Dynpro Explorer: Change View for ZNET310_CONR2_## screen, for view OUTPUT_VIEW, choose the Layout tab page and choose ROOTUIELEMENTCONTAINER. b) Choose the Web Dynpro Code Wizard button. c) In the Template Gallery dialog box, choose Table and choose Continue. d) In the Create Context Binding for Table "TABLE" dialog box, choose the Context button and double-click the context node FLIGHTTAB. Choose Continue. e) On the OUTPUT_VIEW overview screen, in the Properties for the table UI element, enter the following data: Field Name
Value
Layout Data
RowHeadData
width
100%
f) Save your entries. Create a Method for Storing Flight Data in an Internal Table Create a method in the component controller in which you select flights from database table SFLIGHT and store them in an internal table. Use the static method CL_NET310_FLIGHTMODEL=>READ_FLIGHTS( ) to collect the data. Store the result in context node FLIGHTTAB. 1. Create a new method in the component controller (name: FLIGHTTAB_FILL). a) Choose COMPONENTCONTROLLER. b) Choose the Methods tab. c) In the Method column, enter FLIGHTTAB_FILL. 2. Use the Web Dynpro Code Wizard to read the user input from the element at lead selection of node FLIGHTINFO. a) Double-click the FLIGHTTAB_FILL method and choose the Web Dynpro Code Wizard button. b) On the Context tab page in the Web Dynpro Statement Structure dialog box, select the Read radio button. c) Choose the Context button and double-click the node FLIGHTINFO. d) Choose Continue. e) Save your entries. 3. In the FLIGHTTAB_FILL method, edit the generated source code to create an internal table (name: LT_FLIGHTTAB) of table type NET310_T_SFLIGHT. Use the
438
© Copyright. All rights reserved.
Lesson: Adding New Elements to a Context Node
CL_NET310_FLIGHTMODEL=>READ_FLIGHTS( ) static method to fill the internal table (export parameter ET_FLIGHTS). Use CARRID and CONNID entered by the user to restrict the data selection. a) Declare the table using "DATA lt_flighttab TYPE net310_t_sflight." b) Read all flights related to CARRID and CONNID entered by user by adding the code found in the source code at the end of the exercise. 4. Use the code wizard to insert the necessary code to store the contents of the internal table in the context node FLIGHTTAB. a) On the Web Dynpro Explorer: Change Controller for ZNET310_CONR2_## screen, position your cursor after the code you just added, and choose the Web Dynpro Code Wizard button. b) In the Web Dynpro Statement Structure dialog box, select the Set radio button and As Table Operation checkbox. c) Choose the Context button and double-click the node FLIGHTTAB. d) Choose Continue. e) In the FLIGHTTAB_FILL method, correct the generated source code. Pass the internal table LT_FLIGHTTAB to the BIND_TABLE( ) method. f) Save your entries. g) See the source code provided at the end of the exercise. Set the Order of Execution Make sure that your new component controller method is executed after the navigation, immediately before the view OUTPUT_VIEW is displayed. 1. Edit the HANDLEIN_DEFAULT( ) method of the view OUTPUT_VIEW and use the Web Dynpro Code Wizard to implement a call of the component controller FLIGHTTAB_FILL( ) method. a) On the Web Dynpro Explorer: Change View for ZNET310_CONR2_## screen, for view OUTPUT_VIEW, choose the Methods tab page. b) Double-click the HANDLEIN_DEFAULT method. c) Choose the Web Dynpro Code Wizard button. d) In the Web Dynpro Statement Structure dialog box, choose the General tab page. e) Choose the Method Call in Used Controller radio button and enter the following data: Field Name
Value
Component Name
ZNET310_CONR2_##
Controller Name
COMPONENTCONTROLLER
Method Name
FLIGHTTAB_FILL
f) Choose Continue. g) Save your entries. h) See the source code provided at the end of the exercise.
© Copyright. All rights reserved.
439
Unit 13: Controller and Context Programming
The source code is as follows: Comp. Controller, Method FLIGTHTAB_FILL METHOD flighttab_fill . DATA DATA DATA DATA DATA
lo_nd_flightinfo lo_el_flightinfo ls_flightinfo lt_flighttab lo_nd_flighttab
TYPE REF TO if_wd_context_node. TYPE REF TO if_wd_context_element. TYPE wd_this->element_flightinfo. TYPE net310_t_sflight. TYPE REF TO if_wd_context_node.
* navigate from CONTEXT to FLIGHTINFO via lead selection lo_nd_flightinfo = wd_context→get_child_node( name = wd_this->wdctx_flightinfo ). * get element via lead selection lo_el_flightinfo = lo_nd_flightinfo->get_element( ). * get all declared attributes lo_el_flightinfo->get_static_attributes( IMPORTING static_attributes = ls_flightinfo ). * read all flights related to CARRID and CONNID entered by user cl_net310_flightmodel=>read_flights( EXPORTING iv_carrid = ls_flightinfo-carrid iv_connid = ls_flightinfo-connid IMPORTING et_flights = lt_flighttab ). * navigate from CONTEXT to FLIGHTTAB via lead selection lo_nd_flighttab = wd_context->get_child_node( name = wd_this->wdctx_flighttab ). * bind table to context node FLIGHTTAB lo_nd_flighttab->bind_table( new_items = lt_flighttab set_initial_elements = abap_true ). ENDMETHOD. View OUTPUT_VIEW, Method HANDLEIN_DEFAULT METHOD handlein_default . DATA lo_componentcontroller TYPE REF TO ig_componentcontroller . lo_componentcontroller = wd_this->get_componentcontroller_ctr( ). lo_componentcontroller->flighttab_fill( ). ENDMETHOD.
440
© Copyright. All rights reserved.
Lesson: Adding New Elements to a Context Node
LESSON SUMMARY You should now be able to: ●
Add new elements to a context node
© Copyright. All rights reserved.
441
Unit 13 Lesson 4 Implementing Supply Functions
LESSON OVERVIEW This lesson explains how to implement supply functions. Business Example You want to display a table of bookings underneath the existing table of flights in your Web Dynpro component. The bookings to be displayed in this table should be the bookings related to the flight selected by the user in the first table, and the bookings should change if the user chooses a different flight. To achieve this, you need to assign a supply function to the BOOKINGS context node. For this reason, you require the following knowledge: ●
How to use supply functions
LESSON OBJECTIVES After completing this lesson, you will be able to: ●
Use supply functions
Supply Functions
Figure 232: Repopulating a Dependent Node (Singleton Node) – Supply Function
The figure shows that there can be many different elements in the N1 node collection.
442
© Copyright. All rights reserved.
Lesson: Implementing Supply Functions
We need to ensure that when the child node N2 is accessed, it contains the correct data for the selected element in the parent node. Supply functions can be used to ensure child nodes are repopulated automatically. A supply function can be assigned to each context node of a controller. The Web Dynpro runtime calls the supply function automatically in the following situations: ● If the node's collection is initial. ●
If the lead selection index of the parent node is changed.
●
If the collection of node is invalidated programmatically.
Hint: For all of these situations, the supply function is only called when necessary. If the child node N2 is neither accessed programmatically, nor bound to any UI element on the next view assembly, the supply function is not called. Supply functions may not be called from the source code of a controller method. Only the Web Dynpro runtime can access such a method. Assignment of a Supply Function to a Node A supply function can be assigned to a node by setting the value of property Supply Function. As a result, an additional controller method is generated with a given signature. A reference to the element at lead selection in the parent node (PARENT_ELEMENT) allows access to the attributes of this element. A reference to the node to which the supply function is related (NODE) allows you to store the dependent data in the child node’s collection. When a typical business transaction is being used, information is presented in the form of a list of header records of some sort (for example, sales order headers). From this list, the user typically selects one order header and then looks at its line items. It makes much more sense to read the line item information only when it is needed rather than reading all line items for all sale orders on the assumption that it might be relevant for someone. This would result in an inefficient application architecture, both in terms of processing requirements and memory usage. Lazy Data Instantiation Web Dynpro follows the principle of lazy data instantiation. The data is only created when it is actually needed. When this principle is applied to the context architecture, the child node remains unprocessed unless the program actually needs to look at the data in it. Lazy data instantiation also means that dependent collections are not automatically created for all elements of the parent node. The creation of a collection of the dependent node is delayed until the point at which the related element of the parent collection obtains the lead selection.
© Copyright. All rights reserved.
443
Unit 13: Controller and Context Programming
444
© Copyright. All rights reserved.
Unit 13 Exercise 25 Implement Supply Functions
Business Example You want to develop a Web Dynpro application with a view that displays two tables, a list of flights, and a list of bookings. The data displayed in the second table should depend on the selected row in the first table. You want to use a supply function to ensure that the data in the second table changes whenever the user selects a different row in the first table. Template: NET310_CONR_S2 Solution: NET310_CONR_S3 Use supply functions to populate context nodes. Make a Copy of Your Web Dynpro Component Copy your Web Dynpro Component ZNET310_CONR2_## or the template NET310_CONR_S2 to Web Dynpro Component ZNET310_CONR3_##. Create a new application to access your component. 1. Copy the template. 2. Create a new application to access your component. Create a New Context Node as a Subnode of FLIGHTTAB In the component controller context, create a new context node as a subnode of node FLIGHTTAB. This new context node has to store bookings read from the database table SBOOK. Update the mapping of context node FLIGHTTAB in view OUTPUT_VIEW. 1. In the component controller context tab, create a new context node (BOOKINGTAB) as a subnode of node FLIGHTTAB. Set Dictionary structure = SBOOK and Cardinality = 0..n. The node should contain the attributes that are BOOKID, CUSTOMID, CUSTTYPE, LUGGWEIGHT, WUNIT, CLASS, and PASSNAME. 2. Update the mapping for context node FLIGHTTAB in the context of view OUTPUT_VIEW. Display the Bookings in a Second Table Display the bookings in a second table positioned below the flights table. 1. Use the Web Dynpro Code Wizard to create a table with binding to the context node BOOKINGTAB. Implement a Supply Function to Fill BOOKINGTAB Create and implement a supply function to fill the subnode BOOKINGTAB according to the element at lead selection in node FLIGHTTAB. 1. In the component controller context, assign a supply function (BOOKINGS_READ) to the node BOOKINGTAB.
© Copyright. All rights reserved.
445
Unit 13: Controller and Context Programming
2. The supply method contains commented source code. Remove the comments for the following statements: ●
The declaration of the structure LS_PARENT_ATTRIBUTES
●
The call of method GET_STATIC_ATTRIBUTES( ) for the parent element
●
The declaration of internal table LT_BOOKINGTAB
●
The call of method BIND_TABLE( ) used to bind the table LT_BOOKINGTAB to the context node
The rest of the commented lines can be deleted. 3. Call the static method CL_NET310_FLIGHTMODEL=>READ_BOOKINGS( ) to read all bookings for the selected flight. Use the attributes CARRID, CONNID, and FLDATE of the parent element to restrict the data selection.
446
© Copyright. All rights reserved.
Unit 13 Solution 25 Implement Supply Functions
Business Example You want to develop a Web Dynpro application with a view that displays two tables, a list of flights, and a list of bookings. The data displayed in the second table should depend on the selected row in the first table. You want to use a supply function to ensure that the data in the second table changes whenever the user selects a different row in the first table. Template: NET310_CONR_S2 Solution: NET310_CONR_S3 Use supply functions to populate context nodes. Make a Copy of Your Web Dynpro Component Copy your Web Dynpro Component ZNET310_CONR2_## or the template NET310_CONR_S2 to Web Dynpro Component ZNET310_CONR3_##. Create a new application to access your component. 1. Copy the template. a) Perform this step as in the exercise, Create View Assemblies. 2. Create a new application to access your component. a) Perform this step as in the exercise, Create a Simple Web Dynpro. Create a New Context Node as a Subnode of FLIGHTTAB In the component controller context, create a new context node as a subnode of node FLIGHTTAB. This new context node has to store bookings read from the database table SBOOK. Update the mapping of context node FLIGHTTAB in view OUTPUT_VIEW. 1. In the component controller context tab, create a new context node (BOOKINGTAB) as a subnode of node FLIGHTTAB. Set Dictionary structure = SBOOK and Cardinality = 0..n. The node should contain the attributes that are BOOKID, CUSTOMID, CUSTTYPE, LUGGWEIGHT, WUNIT, CLASS, and PASSNAME. a) Perform this step as in the exercise, Define, Map, and Bind Data to the Context. 2. Update the mapping for context node FLIGHTTAB in the context of view OUTPUT_VIEW. a) On the Web Dynpro Explorer: Change Controller for ZNET310_CONR3_## screen, choose OUTPUT_VIEW for ZNET310_CONR3_## and choose the Context tab page. b) In the context menu of the context node FLIGHTTAB for OUTPUT_VIEW, choose Update Mapping. c) In the Copy Child Nodes dialog box, choose Yes. d) Save your entries.
© Copyright. All rights reserved.
447
Unit 13: Controller and Context Programming
Display the Bookings in a Second Table Display the bookings in a second table positioned below the flights table. 1. Use the Web Dynpro Code Wizard to create a table with binding to the context node BOOKINGTAB. a) On the Web Dynpro Explorer: Change View for ZNET310_CONR3_## screen, for view OUTPUT_VIEW, in the Layout tab page, choose ROOTUIELEMENTCONTAINER. b) Choose the Web Dynpro Code Wizard button. c) In the Template Gallery dialog box, choose the Table template. d) In the Create Context Binding for Table "TABLE" dialog box, choose the Context button and double-click the node BOOKINGTAB. e) Choose Continue. f) In the Properties screen area for the new TABLE_1 UI element, enter the following data: Field Name
Value
Layout Data
RowHeadData
width
100%
g) Save your entries. Implement a Supply Function to Fill BOOKINGTAB Create and implement a supply function to fill the subnode BOOKINGTAB according to the element at lead selection in node FLIGHTTAB. 1. In the component controller context, assign a supply function (BOOKINGS_READ) to the node BOOKINGTAB. a) On the Web Dynpro Explorer: Change Controller for ZNET310_CONR3_## screen, in the Context tab page of COMPONENTCONTROLLER, expand FLIGHTTAB and doubleclick BOOKINGTAB. b) In the Properties screen area table for BOOKINGTAB, enter BOOKINGS_READ for the property Supply Function. c) Save your entries. d) Double click the BOOKINGS_READ entry to navigate to the generated code for the supply method. 2. The supply method contains commented source code. Remove the comments for the following statements: ●
The declaration of the structure LS_PARENT_ATTRIBUTES
●
The call of method GET_STATIC_ATTRIBUTES( ) for the parent element
●
The declaration of internal table LT_BOOKINGTAB
●
The call of method BIND_TABLE( ) used to bind the table LT_BOOKINGTAB to the context node
The rest of the commented lines can be deleted.
448
© Copyright. All rights reserved.
Lesson: Implementing Supply Functions
a) Choose the Methods tab, and double-click BOOKINGS_READ. b) See the source code provided at the end of the exercise. 3. Call the static method CL_NET310_FLIGHTMODEL=>READ_BOOKINGS( ) to read all bookings for the selected flight. Use the attributes CARRID, CONNID, and FLDATE of the parent element to restrict the data selection. a) See the source code provided at the end of the exercise under " * read related bookings". The source code is as follows: Comp. Controller, Method BOOKINGS_READ METHOD bookings_read . DATA ls_parent_attributes TYPE wd_this->element_flighttab. DATA lt_bookingtab TYPE wd_this->Element_bookingtab. * get all static attributes of parent element parent_element->get_static_attributes( IMPORTING static_attributes = ls_parent_attributes ). * read related bookings lt_bookingtab = cl_net310_flightmodel=>read_bookings( iv_carrid = ls_parent_attributes-carrid iv_connid = ls_parent_attributes-connid iv_fldate = ls_parent_attributes-fldate ). * bind all the elements node->bind_table( new_items = lt_bookingtab set_initial_elements = abap_true ). ENDMETHOD.
© Copyright. All rights reserved.
449
Unit 13: Controller and Context Programming
LESSON SUMMARY You should now be able to: ●
450
Use supply functions
© Copyright. All rights reserved.
Unit 13 Learning Assessment
1. Which of the following are hook methods found in Web Dynpro component controllers? Choose the correct answers. X
A WDDOINIT
X
B WDDOBEFOREACTION
X
C WDDOEXIT
X
D WDDOONCLOSE
2. Which of the following types of method can be defined in a Web Dynpro controller? Choose the correct answers. X
A Supply Functions
X
B Event Handlers
X
C Static Methods
3. On the Attributes tab page, additional attributes can be defined for the related controller. Determine whether this statement is true or false. X
True
X
False
4. What do you need to access a context element or a context attribute? Choose the correct answer. X
A A declaration of a binding relationship
X
B A reference to the related context node
X
C A definition of variables that can be bound to UI elements and that can be easily exchanged between different controllers
X
D A reference to the node to be altered by the supply function
© Copyright. All rights reserved.
451
Unit 13: Learning Assessment
5. Which node method should you call to access the data sets related to multiple table rows selected by the user? Choose the correct answer. X
A get_selected_elements( )
X
B get_value_attribute( )
X
C get_static_attributes( )
X
D get_child_node( )
6. To create an element that can be added to a certain context node, you have to determine the reference to this node first. How can you do this? Choose the correct answer.
452
X
A By calling the get_child_node( ) method through the standard attribute WD_CONTEXT.
X
B By calling the set_static_attributes( ) method
X
C By using the PARENT_ELEMENT parameter
X
D By instantiating CL_WD_CONTEXT_NODE
© Copyright. All rights reserved.
Unit 13 Learning Assessment - Answers
1. Which of the following are hook methods found in Web Dynpro component controllers? Choose the correct answers. X
A WDDOINIT
X
B WDDOBEFOREACTION
X
C WDDOEXIT
X
D WDDOONCLOSE
2. Which of the following types of method can be defined in a Web Dynpro controller? Choose the correct answers. X
A Supply Functions
X
B Event Handlers
X
C Static Methods
3. On the Attributes tab page, additional attributes can be defined for the related controller. Determine whether this statement is true or false. X
True
X
False
4. What do you need to access a context element or a context attribute? Choose the correct answer. X
A A declaration of a binding relationship
X
B A reference to the related context node
X
C A definition of variables that can be bound to UI elements and that can be easily exchanged between different controllers
X
D A reference to the node to be altered by the supply function
© Copyright. All rights reserved.
453
Unit 13: Learning Assessment - Answers
5. Which node method should you call to access the data sets related to multiple table rows selected by the user? Choose the correct answer. X
A get_selected_elements( )
X
B get_value_attribute( )
X
C get_static_attributes( )
X
D get_child_node( )
6. To create an element that can be added to a certain context node, you have to determine the reference to this node first. How can you do this? Choose the correct answer.
454
X
A By calling the get_child_node( ) method through the standard attribute WD_CONTEXT.
X
B By calling the set_static_attributes( ) method
X
C By using the PARENT_ELEMENT parameter
X
D By instantiating CL_WD_CONTEXT_NODE
© Copyright. All rights reserved.