BC412 46C ABAP Dialogprogrammierung Mit EnjoySAP Controls En
November 10, 2016 | Author: Mario Alejandro Facal | Category: N/A
Short Description
SAP...
Description
BC412 ABAP Dialogprogrammierung mit EnjoySAP-Controls BC412
R/3 System Release 46C August 2000
0
BC412 ABAP Dialogprogrammierung mit EnjoySAP-Controls.............................................................................0-1 Copyright.............................................................................................................................................................0-2 ABAP Workbench............................................................................................................................................0-4 ITS...................................................................................................................................................................0-5 Course Prerequisites........................................................................................................................................0-6 Target Group....................................................................................................................................................0-7 Course Overview.................................................................................................................................................1-1 Course Goal.....................................................................................................................................................1-2 Course Objectives............................................................................................................................................1-3 Course Content................................................................................................................................................1-4 Overview Diagram - Course Overview...........................................................................................................1-5 Style Conventions Used in this Handbook......................................................................................................1-6 Introduction to the Control Framework...............................................................................................................2-1 Introduction to the Control Framework: Unit Objectives................................................................................2-2 Overview Diagram - BC412............................................................................................................................2-3 Introduction to the Control Framework:Overview..........................................................................................2-4 Control Framework (CFW) - General Architecture.........................................................................................2-5 CFW Architecture in Detail.............................................................................................................................2-6 Custom Controls and ABAP Objects...............................................................................................................2-7 Custom Controls: Automation Queue..............................................................................................................2-8 Custom Controls: Events.................................................................................................................................2-9 Control Framework: Class Hierarchy............................................................................................................2-10 SAP's GUI Strategy for R/3...........................................................................................................................2-11 Introduction to the Control Framework:Controls and Screens......................................................................2-12 Relationship Between Controls and Screens.................................................................................................2-13 Using Objects Graphically.............................................................................................................................2-14 Creating a Custom Control Area....................................................................................................................2-15 Creating a Container Control: Process Flow................................................................................................2-16 Creating a Container Control: Sample Code................................................................................................2-17 Syntax: Declaring Reference Variables.........................................................................................................2-18 Information in the Class Builder....................................................................................................................2-19 Syntax: Creating an Instance (With a Constructor).......................................................................................2-20 Ensuring that Controls Are Generated Only Once.........................................................................................2-21 Creating an EnjoySAP Control Instance: Process Flow...............................................................................2-22 Example: Creating an Instance of the SAP Picture Control..........................................................................2-23 Example 2: Creating an Instance of the SAP HTML Viewer........................................................................2-24 Result: Screen, Container, and EnjoySAP Control.......................................................................................2-25 Overview: Properties of the Picture Control and HTML Viewer.................................................................2-26 URL: Pointer to Data.....................................................................................................................................2-27 URLs for External Data Sources...................................................................................................................2-28 SAP Controls: Accessing External Data by URL..........................................................................................2-29
SAP Controls: Accessing Internal Data by URL...........................................................................................2-30 SAP Picture Control: Features.......................................................................................................................2-31 SAP Picture Control: DISPLAY_MODE......................................................................................................2-32 SAP HTML Viewer: Features........................................................................................................................2-33 Overview: Changing the Attributes (Syntax)................................................................................................2-34 Displaying Data: Process Flow.....................................................................................................................2-35 Example: Displaying a Picture in the Picture Control...................................................................................2-36 Syntax: Calling Instance Methods (1)...........................................................................................................2-37 Syntax: Calling Instance Methods (2):Functional Methods..........................................................................2-38 Syntax: Reading Instance Attributes..............................................................................................................2-39 Overview: The Automation Queue...............................................................................................................2-40 Method Calls and the Automation Queue......................................................................................................2-41 Sending the Automation Queue to the GUI: End of PBO............................................................................2-42 Dependent Method Calls...............................................................................................................................2-43 Solution: Explicit Flush................................................................................................................................2-44 Optimizing Performance in the Automation Queue......................................................................................2-45 Method Calls: Possible Causes of Errors (1).................................................................................................2-46 Method Calls: Solving the Problem (1).........................................................................................................2-47 Method Calls: Possible Causes of Errors(2)..................................................................................................2-48 Method Calls: Solving the Problem (2).........................................................................................................2-49 Method Calls: Possible Causes of Errors(3)..................................................................................................2-50 Recommendations for Calling Methods at PAI.............................................................................................2-51 Method Calls and EXCEPTIONs..................................................................................................................2-52 Overview: Tracing Errors in Controls Programming...................................................................................2-53 Automation Queue: Using the ABAP Debugger...........................................................................................2-54 Automation Queue: Using the Automation Trace..........................................................................................2-55 Destroying Control Instances........................................................................................................................2-56 Overview: Control Events - Overview.........................................................................................................2-57 Recap: Control Events..................................................................................................................................2-58 Control Events: General Overview................................................................................................................2-59 Overview: Control Events - ABAP Objects Events......................................................................................2-60 Control Events: Overview.............................................................................................................................2-61 Overview: ABAP Objects Events.................................................................................................................2-62 Events of ABAP Objects Instances................................................................................................................2-63 Example: Events of the SAP Picture Control................................................................................................2-64 Example: Events of the SAP HTML Viewer.................................................................................................2-65 ABAP Objects: Creating Handler Methods..................................................................................................2-66 Creating an Event Handler Method:Static Methods......................................................................................2-67 Syntax: Local Classes....................................................................................................................................2-68 Syntax: Methods of Local Classes.................................................................................................................2-69 Syntax: Handler Method for an Event...........................................................................................................2-70 ABAP Objects: Registering Handler Methods.............................................................................................2-71
Linking an Event to a Handler Method.........................................................................................................2-72 Syntax: Linking an Event to a Static Handler Method..................................................................................2-73 Syntax: Linking an Event to an Instance Handler Method............................................................................2-74 Overview: Control Events - Control Events and the Control Framework....................................................2-75 Control Events: Overview.............................................................................................................................2-76 Control Events: Automation Control as Filter...............................................................................................2-77 Control Events: Configuring the Control Framework...................................................................................2-78 Example of Picture Control Events: Event IDs.............................................................................................2-79 Example of SAP HTML Viewer Events: Event IDs......................................................................................2-80 Registering Control Events with the CFW....................................................................................................2-81 Overview: Control Events - Event Types......................................................................................................2-82 Event Type: System Event............................................................................................................................2-83 Event Type: Application Event.....................................................................................................................2-84 Registering Application Events.....................................................................................................................2-85 Screen and Control:Call Sequence for Application Events...........................................................................2-86 Application Events and Screen Input Checks (1)..........................................................................................2-87 Application Events and Screen Input Checks (2)..........................................................................................2-88 System Event and set_new_ok_code.............................................................................................................2-89 Introduction to the Control Framework:Controls and program modularization............................................2-90 Modularization Used So Far..........................................................................................................................2-91 Other Modularization Possibilities................................................................................................................2-92 Introduction to the Control Framework: Unit Summary...............................................................................2-93 Introduction to the Control Framework Exercise 1.......................................................................................2-94 Note on the Sample Solutions for Unit 02...................................................................................................2-106 Introduction to the Control Framework Solutions to Exercise 1.................................................................2-107 SAP Container...................................................................................................................................................14-1 SAP Container: Unit Objectives....................................................................................................................14-2 Overview Diagram BC412............................................................................................................................14-3 SAP Container Overview:The Container Concept........................................................................................14-4 Uses for Containers........................................................................................................................................14-5 SAP Container Classes..................................................................................................................................14-6 Graphical Visualization of Containers...........................................................................................................14-7 Dialog Box Level and Top-Level Container..................................................................................................14-8 Technical Methods for Attaching SAP Containers........................................................................................14-9 Visibility and Lifetime of SAP Containers..................................................................................................14-10 SAP Container Overview:SAP Custom Container Control.........................................................................14-11 SAP Custom Container: Features................................................................................................................14-12 Creating an Instance of the SAP Custom Container Control.......................................................................14-13 Relinking an SAP Custom Container..........................................................................................................14-14 SAP Container Overview:SAP Dialog Box Container Control...................................................................14-15 SAP Dialog Box Container: Features..........................................................................................................14-16 Creating an Instance of the SAP Dialog Box Container Control.................................................................14-17
SAP Container Overview:SAP Docking Container Control........................................................................14-18 SAP Docking Container: Features...............................................................................................................14-19 SAP Docking Container: Linking to the Screen..........................................................................................14-20 Creating an Instance of the SAP Docking Container Control.....................................................................14-21 Reading and Setting Attributes....................................................................................................................14-22 Relinking an SAP Docking Container.........................................................................................................14-23 SAP Container Overview:SAP Splitter Container Control..........................................................................14-24 SAP Splitter Container: Features.................................................................................................................14-25 SAP Splitter Container: Use........................................................................................................................14-26 Creating an Instance of the SAP Splitter Container Control.......................................................................14-27 SAP Splitter Container: Finding a Cell Reference......................................................................................14-28 Reading and Setting Attributes....................................................................................................................14-29 SAP Container Overview:SAP Easy Splitter Container Control.................................................................14-30 SAP Easy Splitter Container: Features........................................................................................................14-31 Creating an Instance of the SAP Easy Splitter Container Control...............................................................14-32 SAP Easy Splitter Container: Reference Variables for the Cells.................................................................14-33 SAP Container: Unit Summary....................................................................................................................14-34 SAP Container Exercise 1............................................................................................................................14-35 Note on the Sample Solutions for Unit 03...................................................................................................14-42 SAP Container Solutions to Exercise 1.......................................................................................................14-43 SAP Tree Control...............................................................................................................................................28-1 SAP Tree Control: Unit Objectives................................................................................................................28-2 Overview Diagram - BC412..........................................................................................................................28-3 SAP Tree Control Overview:Display Attributes............................................................................................28-4 SAP Tree Control...........................................................................................................................................28-5 SAP Tree Control: Principles of Construction...............................................................................................28-6 Tree Control Implementation.........................................................................................................................28-7 Simple Tree: Display Attributes.....................................................................................................................28-8 Simple Tree: Node Structure..........................................................................................................................28-9 Column Tree: Display Attributes.................................................................................................................28-10 Column Tree: Node Structure......................................................................................................................28-11 List Tree: Display Attributes........................................................................................................................28-12 List Tree: Node Structure.............................................................................................................................28-13 SAP Tree Control Overview:Constructor, Methods, and Events.................................................................28-14 SAP Tree Control: Communication and Data Flow....................................................................................28-15 Modeling View of the Tree Classes.............................................................................................................28-16 SAP Tree Control Overview: Methods and events of the Simple Tree.......................................................28-17 Simple Tree: Constructor.............................................................................................................................28-18 Simple Tree: Method Overview...................................................................................................................28-19 Simple Tree: Event Overview......................................................................................................................28-20 Constructor, Methods, and Events of the Column Tree...............................................................................28-21 Column Tree: Constructor..........................................................................................................................28-22
Column Tree: Method Overview................................................................................................................28-23 Overview: Methods for Changing Column Trees.......................................................................................28-24 Column Tree: Event Overview....................................................................................................................28-25 SAP Tree Control Overview: Methods and Events of the List Tree............................................................28-26 List Tree: Constructor..................................................................................................................................28-27 List Tree: Method Overview........................................................................................................................28-28 List Tree: Overview of Modifying Methods................................................................................................28-29 List Tree: Event Overview...........................................................................................................................28-30 SAP Tree Control Overview: Creating a Hierarchy....................................................................................28-31 Objective: Display Data in a Simple Tree Control.....................................................................................28-32 Simple Tree: Control Data...........................................................................................................................28-33 Line Structure of the Node Table.................................................................................................................28-34 Filling the Node Table.................................................................................................................................28-35 Node Relationships (1)................................................................................................................................28-36 Node Relationships (2)................................................................................................................................28-37 Node Relationships (3)................................................................................................................................28-38 Passing the Node Table to the Front End.....................................................................................................28-39 Sending Large Volumes of Dataon Request from the User.........................................................................28-40 SAP Tree Control Overview: Item Tables...................................................................................................28-41 Objective: Display Data in a Column Tree Control.....................................................................................28-42 Sending Column or List Items.....................................................................................................................28-43 Line Structure of the Item Table..................................................................................................................28-44 Item Names in a Column Tree.....................................................................................................................28-45 The Node Table for the Column Tree Control.............................................................................................28-46 Columns in the Column Tree Control..........................................................................................................28-47 The Item Table in the Column Tree Control................................................................................................28-48 Creating a Column Tree: Sequence.............................................................................................................28-49 Item Names in a List Tree............................................................................................................................28-50 Creating a List Tree: Sequence....................................................................................................................28-51 Demonstration Programs for Tree Control Programming...........................................................................28-52 Data Handling Strategy for 4.6A/B.............................................................................................................28-53 Tree Events and Node Keys.........................................................................................................................28-54 Node Keys...................................................................................................................................................28-55 Storing Node Information: Strategy A.........................................................................................................28-56 Storing Node Information: Strategy B.........................................................................................................28-57 Storing Node Information: Implementation Idea for Strategy B.................................................................28-58 Example of Flight Bookings Tree................................................................................................................28-59 Example of Using the Flight Booking Tree (1): Modularization................................................................28-60 Example of Using the Flight Booking Tree (1): Screen Structure..............................................................28-61 Example: Using the Flight Booking Tree (1): Control Flow......................................................................28-62 Example: Using the Flight Booking Tree (2)...............................................................................................28-63 Overview: Data Transfer Strategy from Release 4.6C................................................................................28-64
Tree Model Classes......................................................................................................................................28-65 Modeling View of the Tree Classes.............................................................................................................28-66 How the Tree Model Controls Data Flow....................................................................................................28-67 SAP Tree Control: Unit Summary...............................................................................................................28-68 Notes on Exercises.......................................................................................................................................28-69 Reading and Writing Node Keys Using a Structure....................................................................................28-70 Exercise 1.....................................................................................................................................................28-71 Model Solutions for the SAP Tree Control Unit..........................................................................................28-89 ALV Grid Control..............................................................................................................................................70-1 ALV Grid Control: Unit Objectives...............................................................................................................70-2 Course Overview Diagram BC412................................................................................................................70-3 ALV Grid Control Overview: Features..........................................................................................................70-4 ALV Grid Control..........................................................................................................................................70-5 Standard Pushbuttons.....................................................................................................................................70-6 Features Overview: Technical View..............................................................................................................70-7 ALV Grid Control: Technical View...............................................................................................................70-8 ALV Grid Control: List Data.........................................................................................................................70-9 Creating List Data and Holding Data..........................................................................................................70-10 ALV Grid Control: The Field Catalog.........................................................................................................70-11 Functions of the Field Catalog.....................................................................................................................70-12 Data Descriptions: The Field Catalog..........................................................................................................70-13 Information in the Field Catalog (Structure)...............................................................................................70-14 ALV Grid Control: Additional Information.................................................................................................70-15 ALV Grid Control: Function of Additional Information.............................................................................70-16 Function of Additional Information in Detail..............................................................................................70-17 Layout Information for the Data Area: Overview.......................................................................................70-18 Layout Information for the Toolbar.............................................................................................................70-19 Layout Information for the Print List..........................................................................................................70-20 Features Overview: Screen/Print List..........................................................................................................70-21 Screen Layout of the ALV Grid Control......................................................................................................70-22 Data Area Layout.........................................................................................................................................70-23 Print List Layout..........................................................................................................................................70-24 ALV Grid Control Overview: Method Overview........................................................................................70-25 Inheritance Hierarchy..................................................................................................................................70-26 ALV Grid Control: Method Overview (1)...................................................................................................70-27 ALV Grid Control: Elementary Methods....................................................................................................70-28 The Constructor...........................................................................................................................................70-29 Method SET_TABLE_FOR_FIRST_DISPLAY.........................................................................................70-30 Method REFRESH_TABLE_DISPLAY.....................................................................................................70-31 Display Variants...........................................................................................................................................70-32 ALV Grid Control: Method Overview (2)...................................................................................................70-33 ALV Grid Control Overview: Event Overview...........................................................................................70-34
ALV Grid Control: Events...........................................................................................................................70-35 BEFORE_USER_COMMAND and AFTER_USER_COMMAND...........................................................70-36 ALV Grid Control: Print List Events...........................................................................................................70-37 ALV Grid Control Overview: The Field Catalog........................................................................................70-38 Recap: Functions of the Field Catalog.........................................................................................................70-39 Overview: Information in the Field Catalog................................................................................................70-40 Field Catalog Overview: Information in the Field Catalog in Detail..........................................................70-41 Field Catalog: Column Indicators................................................................................................................70-42 Field Catalog: Unit-Specific Formatting.....................................................................................................70-43 Example: Currency Formatting...................................................................................................................70-44 Field Catalog: Output Properties for Columns............................................................................................70-45 Field Catalog: Formatting of Column Contents..........................................................................................70-46 Field Catalog: Texts.....................................................................................................................................70-47 Field Catalog: Technical Column Properties...............................................................................................70-48 Field Catalog: Other Fields..........................................................................................................................70-49 Summary: Structure of the Field Catalog....................................................................................................70-50 Field Catalog Overview: Generating the Field Catalog...............................................................................70-51 Generating the Field Catalog.......................................................................................................................70-52 Fields of a Single Dictionary Structure........................................................................................................70-53 Fields of a Dictionary Structure and Local Types.......................................................................................70-54 Fields of Several Dictionary Structures.......................................................................................................70-55 Fields With and Without Dictionary Relationships.....................................................................................70-56 Fields With Local Types Only.....................................................................................................................70-57 Demo Programs Delivered...........................................................................................................................70-58 ALV Grid Control: Unit Summary..............................................................................................................70-59 ALV Grid Control: Exercise 1.....................................................................................................................70-60 ALV Grid Control: Solutions to Exercise 1.................................................................................................70-67 Appendix..........................................................................................................................................................101-1 Information on the Global Classes of BC412..............................................................................................101-2 BC412 - Table of Contents........................................................................................................................105-45 Workbench Edition – Controls Technology...............................................................................................105-50
0 BC412 ABAP Dialogprogrammierung mit EnjoySAP-Controls
BC412 ABAP Dialog Programming Using EnjoySAP Controls
SAP AG 1999
System R/3
Release 4.6C
August 2000
5004 0873
(C) SAP AG
BC412
1
0.2 Copyright
Copyright 2000 SAP AG. All rights reserved. Neither this training manual nor any part thereof may be copied or reproduced in any form or by any means, or translated into another language, without the prior consent of SAP AG. The information contained in this document is subject to change and supplement without prior notice. All rights reserved.
SAP AG 1999
Trademarks:
Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.
Microsoft®, WINDOWS®, NT®, EXCEL®, Word® and SQL Server® are registered trademarks of Microsoft Corporation.
IBM®, DB2®, OS/2®, DB2/6000®, Parallel Sysplex®, MVS/ESA®, RS/6000®, AIX®, S/390®, AS/400®, OS/390®, and OS/400® are registered trademarks of IBM Corporation.
ORACLE® is a registered trademark of ORACLE Corporation, California, USA.
INFORMIX®-OnLine for SAP and Informix® Dynamic ServerTM are registered trademarks of Informix Software Incorporated.
UNIX®, X/Open®, OSF/1®, and Motif® are registered trademarks of The Open Group.
HTML, DHTML, XML, XHTML are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Laboratory for Computer Science NE43-358, Massachusetts Institute of Technology, 545 Technology Square, Cambridge, MA 02139.
JAVA® is a registered trademark of Sun Microsystems, Inc. , 901 San Antonio Road, Palo Alto, CA 94303 USA.
JAVASCRIPT® is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape.
SAP, SAP Logo, mySAP.com, mySAP.com Marketplace, mySAP.com Workplace, mySAP.com Business Scenarios, mySAP.com Application Hosting, WebFlow, R/2, R/3, RIVA, ABAP™, SAP Business Workflow, SAP EarlyWatch, SAP ArchiveLink, BAPI, SAPPHIRE, Management Cockpit,
(C) SAP AG
BC412
2
SEM, are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other products mentioned are trademarks or registered trademarks of their respective companies.
Design: SAP Communications Media
(C) SAP AG
BC412
3
0.3 ABAP Workbench Level 2
3 days BC402 ABAP Programming Techniques 3 days BC404 ABAP Objects: Object Oriented Programming in R/3 BC405 3 days Techniques of List Processing and InfoSet Query
BC400 5 days ABAP Workbench: Foundations and Concepts MBC40
2 days
Managing ABAP Developments Projects
BC410 Programming User Dialogs
5 days
BC420 Data Transfer
5 days
BC412 3 days Dialog Programming using EnjoySAP Controls
BC430 ABAP Dictionary
2 days
BC460 3 days SAPscript: Forms Design and Text Management
SAP AG 1999
(C) SAP AG
CA610 (Rel. 4.0) 2 days CATT:Test Workbench and Computer Aided Test Tool
BC412
BC490 3 days ABAP Performance Tuning
2 days BC415 Communication Interfaces in ABAP BC425 3 days Enhancements and Modifications
BC470 2 days Form Printing Using SAP Smart Forms
Level 3 BC414 3 days Programming Database Updates
Recommended supplementary courses are: Business Process Technologies CA925, CA926, CA927 BC095 (Business Integ. Techn.) BC619 (ALE), BC620, BC621
4
0.4 ITS Level 3 Level 3
Level 2 Level 2
BC400 5 days ABAP Workbench: Foundation and Concepts
ITS100 2 days Developing EasyWebTransactions
ITS050 3 days SAP Internet Transaction Server: Foundations
2 days ITS110 Developing Web Scenarios and MiniApps using ITS Flow Logic ITS150
2 days
Corporate Identity Design ITS070 2 days SAP Internet Transaction Server: Administration
SAP AG 1999
(C) SAP AG
BC412
5
0.5 Course Prerequisites Required:
Sound knowledge of the ABAP Workbench (for example, from course BC400 - 'ABAP Workbench: Concepts and Tools')
ABAP dialog programming knowledge (for example, from course BC410 - 'Programming User Dialogs')
Knowledge of object-oriented programming
Recommended additional courses:
BC402 ABAP Programming Techniques
BC404 ABAP Objects
SAP AG 1999
(C) SAP AG
BC412
6
0.6 Target Group
Participants:
Experienced ABAP programmers (specializing in dialog programming)
Consultants
Project team members
Duration: 3 days
SAP AG 1999
Notes to the participant
This course material is not a self-teach program. It is only complete in conjunction with the instructor's comments. There is space in the course book for you to write your own notes.
(C) SAP AG
BC412
7
1 Course Overview
Contents: Course goal Course objectives Course content Course overview diagram Main business scenario
SAP AG 1999
(C) SAP AG
BC412
1
1.2 Course Goal
This course will prepare you to: Write user dialogs in ABAP using EnjoySAP
controls
SAP AG 1999
(C) SAP AG
BC412
2
1.3 Course Objectives
At the conclusion of this course, you will be able to: Use the SAP Control Framework Use EnjoySAP controls Set the attributes Pass and receive data Handle events Find further information about EnjoySAP controls
SAP AG 1999
(C) SAP AG
BC412
3
1.4 Course Content
Preface Unit 1
Course Overview
Unit 2
Introduction to the Control Framework
Unit 3
SAP Container
Unit 4
SAP Tree Control
Unit 5
ALV Grid Control
Exercises and solutions appear at the end of the relevant unit
Appendix
SAP AG 1999
(C) SAP AG
BC412
4
1.5 Overview Diagram - Course Overview
Course Overview
Unit 1
Unit 2
Introduction to the Control Framework
Unit 3
SAP Container
Unit 4
SAP Tree Control
Unit 5
ALV Grid Control
SAP AG 1999
(C) SAP AG
BC412
5
1.6 Style Conventions Used in this Handbook
General ABAP code and the names of ABAP Dictionary objects are always shown using a monospaced font.
ABAP key words and names of structures in the ABAP Dictionary are shown in BLOCK CAPITALS
Names of variables, class components, and field names are shown in lower case.
Slides ABAP code is always displayed in a
blue
box
Highlighted ABAP code is always displayed in a dark blue box using an inverse font
highlighted
SAP AG 1999
The style conventions outlined under the "General" heading also apply to the notes in this manual.
Paths in the online documentation or system are written in italics.
Text is highlighted using either italic or bold type.
User interface texts in the R/3 System, such as pushbutton texts, are also written in italics.
A table of contents, structured by topic, is included at the end of this course.
(C) SAP AG
BC412
6
2 Introduction to the Control Framework
Contents: Overview: System requirements, CFW architecture Controls and screens SAP HTML Viewer and SAP Picture Control Changing the attributes of a control Control events Controls and program modularization
SAP AG 1999
(C) SAP AG
BC412
1
2.2 Introduction to the Control Framework: Unit Objectives
At the conclusion of this unit, you will be able to: Describe how the SAP Control Framework works Display data in a SAP Picture Control and SAP HTML Viewer on a screen Change the attributes of a control React to the events of a control Use selected ABAP Objects statements
SAP AG 1999
(C) SAP AG
BC412
2
2.3 Overview Diagram - BC412
Unit 1
Course overview
Unit 2
Introduction to the Control Framework
Unit 3
SAP Container
Unit 4
SAP Tree Control
Unit 5
ALV Grid Control
SAP AG 1999
(C) SAP AG
BC412
3
2.4 Introduction to the Control Framework: Overview
Overview Overview Controlsand andscreens screens Controls Changingthe the attributes attributes of ofaa control control Changing The automation automationqueue queue The Controlevents events Control Controlsand andprogram programmodularization modularization Controls
SAP AG 1999
(C) SAP AG
BC412
4
2.5 Control Framework (CFW) - General Architecture External SAP GUI session SAP GUI window EnjoySAP control 1
SAP GUI services Automation Controller Service: y
Data
DIAG
GUI RFC Control Framework Data
Service: x Runtime system services ABAP application (program) External session on application server
SAP AG 1999
The graphical user interface in the SAP System is based on SAP GUI windows (screens, from the technical viewpoint of the programmer). Each user dialog in the system is implemented using screens in an application program.When you design SAP GUI windows, the Screen Painter provides you with a range of graphical elements that you can use. For example, there are input/output fields, pushbuttons, checkboxes, table controls, and so on. These elements are controlled (data exchange and element attributes) from the corresponding application program. These elements are controlled (data exchange and element attributes) from the corresponding application program. At runtime, application programs and screens communicate using runtime system services (the ABAP processor and screen processor) and other services from the SAP GUI (window management, dialog box level, data transfer, and so on).
From R/3 Release 4.5 onwards, developers have been able to use graphical elements in SAP GUI windows apart from those provided by the Screen Painter - known as controls. Controls are reusable standalone software components. As a developer, you can use controls in your user dialog. Communication between the control and your application takes place through different channels to "classic" screen elements. From the Enjoy R/3 Release (4.6) onwards, the communication channel for all controls (EnjoySAP controls) is the SAP Control Framework (CFW). The Control Framework uses special services in the SAP GUI and the runtime system on the application server - the Automation Controller in the SAP GUI, and the Control Framework service on the application server).
(C) SAP AG
BC412
5
2.6 CFW Architecture in Detail Beans
Java
ActiveX
OLE
Automation controller Automation queue
Automation Handler
Instances Events
SAP GUI Application server
GUI RFC Control Framework Automation queue
ABAP program
CFW service
Instances Events
SAP AG 1999
The two services of the Control framework - the CFW service in the runtime system and the Automation Handler in the SAP GUI - each control their own data pertaining to a control. A list of all of the instances (EnjoySAP controls) with which they have to communicate The automation queue A list of the events of the EnjoySAP controls that the application program is to handle.
The aim of the Control Framework is to optimize communication between controls and the application program.
EnjoySAP controls are installed on the presentation server, either as Java Beans or ActiveX controls. Communication between the EnjoySAP control instances and the automation handler takes place using the OLE or Java interface in the Automation Controller.
(C) SAP AG
BC412
6
2.7 Custom Controls and ABAP Objects EnjoySAP control 1
EnjoySAP control 2 Automation Controller
Automation handler
Instances *1
*2
SAP GUI Application server Control Framework
ABAP Program
Instances 1 2
#1
#2
CFW service
SAP AG 1999
Each EnjoySAP control with which an application program communicates is an object - that is, an instance - in an object-oriented sense. The communication between the program and the instances is implemented using method calls and the events of the objects.
From Release 4.6, there are proxy classes in the global class library for all controls. These access the Control Framework in a uniform manner and encapsulate the control-specific communication. We call this kind of class a control wrapper.
When you use a control in an ABAP program, there are actually two objects involved. There is an instance in the ABAP program, and an instance of the control at the frontend. The communication between the application program and the control is implemented as follows: The ABAP program always communicates with the proxy object (method calls, setting and retrieving attribute values). The proxy object uses the CFW and executes the corresponding operation on the frontend instance. When an action comes from the frontend, the CFW directs it to the proxy object, which then communicates with the ABAP program.
The CFW contains a list of the active instances both on the frontend and on the application server.
(C) SAP AG
BC412
7
2.8 Custom Controls: Automation Queue EnjoySAP- control 1
EnjoySAP- control 2 Automation Controller
Automation Handler
Automation queue *1: m1, m2, attr1= 5 *2: m1, m3, attr2 = 11
SAP GUI Application server Control Framework
ABAP program
Automation queue #1: m1, m2, attr1= 5 #2: m1, m3, attr2 = 11
1 2
CFW service
SAP AG 1999
Each communication step between the program and a control involves data transfer over the network between the application server and presentation server. This communication is separate from the communication involving other screen elements, and can therefore cause increased network load. (Remember - screens are always transferred as a whole unit.)
To improve performance, method calls and attribute operations in the Control Framework are collected in the automation queue. The contents of the queue are automatically sent to the frontend (flushed) at particular synchronization points. The corresponding operations are then carried out at the frontend. In the same step, all values that had been collected at the frontend are passed back to the application server.
(C) SAP AG
BC412
8
2.9 Custom Controls: Events EnjoySAP control 1
EnjoySAP control 2
Events: e1 - e7
Automation Controller Events: e1 - e5 Automation Handler
Events *1: e1, e2, e4 *2: e1, e3
SAP GUI Application server Control Framework
ABAP program
1 2
CFW service
Events #1: e1, e2, e4 #2: e1, e3
SAP AG 1999
The control at the frontend can have events, which could be triggered by user actions on the screen. These events are transferred back to the appropriate proxy objects in the ABAP program with the help of the Control Framework. The proxy object then handles the event using the normal event concept of ABAP Objects.
There is a large number of events that each control could trigger. However, as a rule, only a few of these will be relevant for an application program. You can restrict the number of events that is passed back to the proxy objects in the ABAP program by setting a filter in the Control Framework.
Since each event that the Control Framework redirects to a proxy object requires a communication step and data transfer, the filter is an important performance consideration. The initial state of the filter is not to transfer any events. If you want to handle events in your ABAP program, you must construct your own filter.
(C) SAP AG
BC412
9
2.10 Control Framework: Class Hierarchy Component Integration cl_gui_cfw cl_gui_object cl_gui_control cl_gui_picture cl_gui_html_viewer cl_gui_textedit cl_gui_tree_control cl_gui_alv_grid cl_gui... cl_gui_container cl_gui_..._container
SAP AG 1999
The proxy objects for EnjoySAP controls are instances of global classes. A global class is a class that has been created using the Class Builder. It is a "public" Repository object, which means that, like ABAP Dictionary objects, it is visible in any program.
All proxy classes for EnjoySAP controls inherit attributes and methods from the classes cl_gui_object and cl_gui_control.
All of the classes used in control programming have the prefix cl_gui. "CL" means that the object is a global class, and "GUI" indicates that all of the classes belong to the controls inheritance hierarchy.
There is an additional class, cl_gui_cfw, which provides service functions (in the form of methods). These are used extensively in the individual control wrappers, but you can also use them directly in your programs.
You can display individual classes either in the Class Builder or in the Object Navigator. To display the inheritance hierarchy, use the Class Browser.
The classes derived from cl_gui_container are control wrappers with a special function within the Control Framework.
This unit contains details of the tools and syntax for ABAP Objects, the object-oriented extension of ABAP.
(C) SAP AG
BC412
10
2.11 SAP's GUI Strategy for R/3 SAP GUI for Windows 32 Bit Windows 16 Bit
native Windows 16 Bit
Unix / Motif
native Motif
Mac
native Mac
OS/2
native OS/2
Java Application
Java Applet-based
Browser
HTML Template-based R/3 3.0
R/3 3.1
native Windows 32 Bit
R/3 4.0 / 4.5
Browserbased
Windows
Java
HTML
R/3 4.6
SAP supports all common frontend platforms
SAP AG 1999
SAP offers platform-specific graphical user interfaces. SAP GUI for the Windows ® environment (or SAP GUI for Windows) for the Microsoft Windows frontend platform. SAP GUI for the JAVA™ environment (or SAP GUI for Java) for Unix/Motif, Macintosh and OS/2 platforms. SAP GUI for HTML for any platform on which a web browser can be used.
From Release 4.6, EnjoySAP controls are delivered on the installation CD as ActiveX controls for SAP GUI for Windows and as Java Beans for SAP GUI for Java. They are installed on the frontend when you install the relevant SAP GUI. Both versions of the EnjoySAP controls have the full range of functions and features as described in the documentation.
This does not apply to EnjoySAP controls running under the SAP GUI for HTML. Not all of the EnjoySAP controls are supported, and certain functions (like drag and drop) are not supported. However, the most important controls, such as the ALV Grid Control and the SAP Tree Control are supported. For a list of the EnjoySAP transactions supported in the SAP GUI for HTML, see Solutions / SAP Business Technology / Presentation Client (SAPNet Link Presentation Clients) in SAPNet.
(C) SAP AG
BC412
11
2.12 Introduction to the Control Framework: Controls and Screens
Overview Overview Controlsand andscreens screens Controls Changingthe the attributes attributes of ofaa control control Changing The automation automationqueue queue The Controlevents events Control Controlsand andprogram programmodularization modularization Controls
SAP AG 1999
(C) SAP AG
BC412
12
2.13 Relationship Between Controls and Screens External SAP GUI session
1
2
3
Container control
EnjoySAP control
Window Control area
Runtime system services
ABAP program
1
2
CALL SCREEN 100.
1
3 1
SAP AG 1999
You cannot create a standalone instance of a control at the frontend. You must always have two other components - a screen and a special control called a container control.
The container control attaches a control to a screen. The screen contains a reserved area (like a subscreen area) In your program, you assign an instance of the container control class cl_gui_custom_container to the reserved area on the screen. Finally, you assign an instance of the control you want to display to the container control instance.
The first two steps help to integrate the frontend control into normal screen processing (PBO, PAI, resizing).
Since each frontend control has a proxy instance in the ABAP program, you will be communicating with two ABAP Objects instances and at least one screen. (There are four instances in total - two in the ABAP program, two at the frontend).
There are other ways of attaching a container instance to a screen. We will look at these in a later unit. In this unit, we will only use the case explained on this page.
(C) SAP AG
BC412
13
2.14 Using Objects Graphically
Area 100
Container control
Picture control
SAP AG 1999
If we look at it graphically, attaching an EnjoySAP control to a screen is just like pasting the different areas onto it: First, we define an area in which to display the control. Next, we attach a container control to the area. The container control holds the actual control that we want to use (for example, to display a picture).
We will now look at what you need to do to carry out these three steps in a program.
(C) SAP AG
BC412
14
2.15 Creating a Custom Control Area Screen Painter: Layout Element toolbar
Area
Screen element: Type: CUSTOM CONTROL Name: CONTROL_AREA1 Resizing: Minimum size vertical: 'X' 10 horizontal:'X' 20
C
SAP AG 1999
To reserve a screen area for an EnjoySAP control, start the layout editor in the Screen Painter.
The element toolbar at the left-hand edge of the screen contains an icon with the label Custom Control. This works very similarly to the Subscreen function. Choose Custom Control. Define the custom control area on the screen as follows: Define the top left-hand corner of the area by single-clicking. Hold the mouse button down and drag the container area out to the required size. Then release the mouse button. You can change the size and position of the area at any time by clicking one of the "handles" at the edge of the object and dragging it to its new size. This handling is similar to that of subscreen areas.
Give the screen element a name (in the example: CONTROL_AREA1).
The Resizing vertical and Resizing horizontal attributes allow you to specify whether the control area should be resized when the user changes the window size. If you set the attributes, you can specify the minimum size to which the area can be reduced in the Lines min. and Columns min. fields. The maximum size of the area is the size in which you created it.
(C) SAP AG
BC412
15
2.16 Creating a Container Control: Process Flow Screen 100
PBO 100
PAI 100
program Start program DATA: my_container DATA: my_container ... ... CALL SCREEN 100
MODULE start_control_handling init_control_processing MODULE CREATE OBJECT ... 1
MODULE user_command_0100
SAP AG 1999
The next step is to create a container control instance. You must do this in your program before the screen containing the control is displayed. Therefore the PBO event of the screen containing the custom control area is an appropriate point in the program.
To make your program easier to follow, it is a good idea to place all control programming in a separate module. In our example, we have a module called init_control_processing.
Before you can create a container control instance, you need a reference variable for it.
The actual processing steps required are explained on the following pages.
(C) SAP AG
BC412
16
2.17 Creating a Container Control: Sample Code * data declarations DATA: my_container TYPE REF TO cl_gui_custom_container, ...
* PBO of screen containing CONTROL_AREA1 MODULE init_control_processing OUTPUT. IF my_container IS INITIAL. * create container object and link to screen area CREATE CREATE OBJECT OBJECT my_container my_container EXPORTING EXPORTING container_name container_name = = 'CONTROL_AREA1' 'CONTROL_AREA1' EXCEPTIONS EXCEPTIONS others others = = 1. 1. IF sy-subrc NE 0. MESSAGE a... ENDIF. ...
SAP AG 1999
To create a reference variable for your container control instance, use the DATA statement to create a field that has the type TYPE REF TO cl_gui_custom_container. In our example, we have called it my_container.
You can now create the proxy instance for the container control (instance of class cl_gui_custom_container) using the ABAP statement CREATE OBJECT. This also creates the container control instance at the frontend.
In the EXPORTING parameter CONTAINER_NAME of the CREATE OBJECT statement, you specify the name of the custom control area you defined on the screen. ('CONTROL_AREA1').
The CREATE OBJECT statement allows you to react to errors (exceptions) that may have occurred during the statement (in the same way as the CALL FUNCTION statement). If our CREATE OBJECT statement fails, the most appropriate reaction is a termination (type A) message.
Let us now look in more detail at some of the ABAP Objects syntax used here.
(C) SAP AG
BC412
17
2.18 Syntax: Declaring Reference Variables General syntax DATA: "
Name of reference variable
TYPE REF TO
"
Specifies that the variable is an object reference
.
"
Name of a class (global or local)
Example DATA: my_container TYPE REF TO
"
Name of reference variable
"
Object reference
cl_gui_custom_container. "
custom container
Name of a global class
picture control
Class Builder
SAP AG 1999
If you write a program that uses instances of classes ("object-oriented programming"), you need a pointer to the objects (instances) that the Basis system creates and administers in main memory. You administer these pointers in your ABAP programs using reference variables.
To create a reference variable in a program, use the DATA statement and assign a name to it. To specify the type of the variable (field), use the addition TYPE REF TO . This addition declares a data object that can contain a pointer to an instance. After TYPE REF TO you must specify the name of a class. The reference variable can then contain pointers to instances of that class. For further details about reference variables (static types, dynamic types, and so on), refer to the keyword documentation for the DATA statement.
The class to which you refer when you define a reference variable can be either local or global. The classes used for controls are global classes. They are defined in the Class Builder and can be accessed from any program in the system.
(C) SAP AG
BC412
18
2.19 Information in the Class Builder Component Class Properties
Name, description, inherits from, general data (...), ...
Interfaces
Name, description ...
Attributes
Name, description, visibility, static/instance, ...
Methods
Name, description, visibility, static/instance, ...
Parameters
Name, description, type, pass by value, reference type, ...
Exceptions
Name, description ...
Parameters Internal types
class 1 class 2
Name
Events
Properties
Name, description, visibility, static/instance, ... Name, description, type, pass by value, reference type, ... Name, description, visibility, reference type, ...
SAP AG 1999
The Class Builder is one of the tools in the ABAP Workbench (available since Release 4.5A). You use it to create global classes. The following details of a class have to be maintained: Properties Interfaces implemented by the class Attributes (with properties) Methods (with properties and interface) Events (with properties and interface) Internal types used in the class
The Class Builder is similar in layout to the Function Builder. You define the elements, their properties, types, and interfaces in tables on different tab pages, and write the method implementations in the ABAP Editor (choose Source code or double-click the method name).
(C) SAP AG
BC412
19
2.20 Syntax: Creating an Instance (With a Constructor) General syntax DATA: TYPE REF TO . CREATE OBJECT EXPORTING = ... = EXCEPTIONS
Constructor interface
= ... = return_code_m>.
Example CREATE OBJECT my_container EXPORTING container_name = 'CONTROL_AREA1' EXCEPTIONS others = 1.
SAP AG 1999
The CREATE OBJECT statement creates an instance of the class specified after TYPE REF TO in the definition of the reference variable .
If the class that you want to instantiate has a method called constructor, this method is executed automatically when the instance is created. The constructor method can only have IMPORTING parameters and EXCEPTIONS in its interface. You must fill the interface parameters in the CREATE OBJECT statement. In the EXPORTING parameters of the CREATE OBJECT statement, you must specify values for all of the obligatory IMPORTING parameters in the interface of the constructor method.
The syntax of the interface in the call is similar to that for function modules: The names of the interface parameters of the method are on the left-hand side of the expressions in the EXPORTING section. On the right of the equals sign, you specify literals or program variables that you want to pass to the method. You can assign return codes to the exceptions listed in the interface. Directly after the CREATE OBJECT statement, you can find out the value of the return code from the system field SYSUBRC.
(C) SAP AG
BC412
20
2.21 Ensuring that Controls Are Generated Only Once Screen 100
PBO 100
PAI 100
Program
Next screen 100 CALL SCREEN 100 MODULE init_...
Start program DATA: my_container ... ...
IF my_container IS INITIAL. CREATE OBJECT ... 1
ENDIF.
ENTER MODULE user_...
SAP AG 1999
Since we have chosen to place our control-specific processing within the flow logic of the container screen (the screen on which we are going to display the control), we need a mechanism to ensure that the steps that create the control are only carried out the first time the screen is called. Otherwise we would create a new object each time the screen was processed: The statically-defined next screen for the container screen is usually itself. Each user action on the screen, such as choosing Enter, leads to the screen being processed again after the PAI event has finished. This means that the PBO event runs again, and a new instance would be created. Any control operations (method calls) processed during PAI would not be displayed on the screen, since another instance would be linked to the container screen in each PBO.
We can stop this happening by using a flag variable - in our example, the data object MY_CONTAINER.
It is also perfectly possible to use the data object itself as a flag, as follows: DATA: first_time. IF first_time IS INITIAL. first_time = 'X' CREATE OBJECT my_container ... ENDIF.
(C) SAP AG
BC412
21
2.22 Creating an EnjoySAP Control Instance: Process Flow Screen 100
PBO 100
PAI 100
Program
CALL SCREEN 100 MODULE init_...
Start program DATA: my_container ..., my_picture ... ... my_gui_control
IF my_container IS INITIAL. CREATE OBJECT ... 1
CREATE OBJECT ... 1
ENDIF.
MODULE user_...
SAP AG 1999
You create the EnjoySAP control instance in the same way that you created the instance for the container control.
The instance of the EnjoySAP control must be created after the container control instance, but before the screen is sent to the presentation server. It is therefore a good idea to create this instance in the same PBO module that you used for the container control instance.
(C) SAP AG
BC412
22
2.23 Example: Creating an Instance of the SAP Picture Control * data declarations DATA: my_container TYPE REF TO cl_gui_custom_container, my_picture
TYPE REF TO cl_gui_picture,
... MODULE start_control_handling OUTPUT. IF my_container IS INITIAL. ... * create picture control object and link to container CREATE CREATE OBJECT OBJECT my_picture my_picture EXPORTING EXPORTING parent = my_container parent = my_container EXCEPTIONS EXCEPTIONS others = 1.= 1. others IF sy-subrc NE 0. MESSAGE a... ENDIF.
SAP AG 1999
To create an SAP Picture Control instance, you need a reference variable declared with reference to class cl_gui_picture. In our example, this is called my_picture.
The class cl_gui_picture has a constructor. In the CREATE OBJECT statement, you must fill the parameter PARENT with the reference to the container control instance that you have already created.
If an error occurs when the system tries to create the instance, you should react with a termination (type A) message.
The instance of the SAP Picture Control is linked to the container control whose reference variable you specified as the parent control in the CREATE OBJECT statement. This also links it to the container screen.
(C) SAP AG
BC412
23
2.24 Example 2: Creating an Instance of the SAP HTML Viewer
* data declarations DATA: my_container my_html_viewer
TYPE REF TO cl_gui_custom_container, TYPE REF TO cl_gui_html_viewer,
... MODULE start_control_handling OUTPUT. IF my_container IS INITIAL. ... * create html viewer object and link to container CREATE CREATE OBJECT OBJECT my_html_viewer my_picture EXPORTING EXPORTING parent = my_container parent = my_container EXCEPTIONS EXCEPTIONS others = 1.= 1. others IF sy-subrc NE 0. MESSAGE a... ENDIF.
SAP AG 1999
The procedure for creating an instance of the SAP HTML Viewer Control is similar to that for the SAP Picture Control. You must create the reference variable with reference to class cl_gui_html_viewer. In the CREATE OBJECT statement, pass the reference to your container control instance in the PARENT parameter.
(C) SAP AG
BC412
24
2.25 Result: Screen, Container, and EnjoySAP Control External SAP GUI session Custom control Area
Container control
Window
Empty!?!
EnjoySAP control
Runtime system services
1 CALL SCREEN 100.
ABAP program
2
3
1
1
SAP AG 1999
The result of the steps up to this point is that we have now created an EnjoySAP control on a screen. However, we have still not seen anything in the SAP GUI window, since the controls are not displaying anything. We still need to supply the frontend control with data that it can display.
This will be our next step.
However, let us first take a look at the features of the SAP Picture Control and SAP HTML Viewer Control.
(C) SAP AG
BC412
25
2.26 Overview: Properties of the Picture Control and HTML Viewer
Overview Overview Controlsand andscreens screens Controls Changingthe the attributes attributes of ofaa control control Changing Introduction--picture picture control controland andHTML HTML Viewer Viewer Introduction attributes attributes Changingthe the attributes attributes Changing The automation automationqueue queue The Controlevents events Control Controlsand andprogram programmodularization modularization Controls
SAP AG 1999
(C) SAP AG
BC412
26
2.27 URL: Pointer to Data System R/3
External
SAP GUI Screen
local PC file
SAP control
Pointer HTTP server
ABAP program URL
FTP server R/3 DB
BDS
SAP WR
R/3 DB : R/3 database BDS : Business Document Server R/3 WR : SAP Web Repository
SAP AG 1999
Both the SAP Picture Control and SAP HTML Viewer Control access the data they display using URLs (uniform resource locators).
URLs point to data sources. In ABAP, you can administer them using a variable with type C.
The data can be stored either in the R/3 System or externally.
Within the R/3 System, you can save files in the R/3 database as a cluster table, in the Business Document Server (BDS) and in the SAP Web Repository. For details of the BDS, refer to the documentation for class cl_bds_document_sets or the Business Document Navigator section of the SAP Archive Link documentation (Basis ->Basis Services/Communication Interfaces -> SAP Archive Link ->BC-SAP SAP Archive Link -> Information for Everyone -> Business Document Navigator). For further details of the SAP Web Repository (transaction SMW0, or Tools -> Web development -> Web Repository), refer to Basis -> Frontend services -> ITS/WebStudio -> IAC Programming -> Implementing Internet Applications -> WebRFC Programming -> Maintaining Web Objects.
External data sources could be files on your PC (presentation server), shared directories accessible from the PC, or files on an HTTP or FTP server.
(C) SAP AG
BC412
27
2.28 URLs for External Data Sources
General Structure: Location
service://host.domain[:port]/pathname/filename
Examples: PC
file://c:/public/pictures/LogonSequence.gif file://c:/public/htmlpages/home.html http://www.sap.com/images/Enjoy_new.gif
HTTP
http://www.sap.com/index.html ftp://sapserv3/usr/picture.gif
FTP
ftp://sapserv3/usr/home.html
SAP AG 1999
URLs for external data sources are structured as follows: Name of the service (file for local PC files, http for files on an HTTP server, and ftp for files on an FTP server) :// followed by the host name.domain name and the port number (if the port number differs from the standard port number). /directory path/filename
(C) SAP AG
BC412
28
2.29 SAP Controls: Accessing External Data by URL
Access
SAP GUI Picture control or HTML Viewer
Screen
PC
HTTP
FTP
URL
ABAP program URL
SAP AG 1999
To display external data in an SAP Picture Control or SAP HTML Viewer Control, you must pass the URL of the data source to the frontend control (using a method call on the proxy object).
The data source is accessed by the frontend control itself.
(C) SAP AG
BC412
29
2.30 SAP Controls: Accessing Internal Data by URL
SAP GUI Screen
Picture control or HTML Viewer
Access
SAP Control: Data Provider
URL
ABAP Program
Function module DP_CREATE_URL
display
BDS method
HTML Viewer Method
Internal table
R/3 DB
BDS
SAP WR
SAP AG 1999
To access data sources in R/3, you also pass a URL to the control. At runtime, this URL points to a data source in the Data Provider. The SAP Data Provider is a control in the SAP GUI. You can pass data to it that is then administered locally by the control instance. When data is sent to the Data Provider, it returns a URL pointing to this data. The SAP Picture Control and the SAP HTML Viewer Control can use this URL to access the data. The Data Provider behaves like an external Web server when interacting with these controls.
There are three ways of implementing data transfer from the R/3 System, depending on the data source used: Data stored in the SAP Web Repository can be loaded into the Data Provider using an instance method of the class cl_gui_html_viewer (see later units for more details). The Data Provider then returns a URL pointing to the data. The method returns a URL to the data in the Data Provider. Data stored in the Business Document Service (for example, for the SAP Picture Control) can be loaded into the Data Provider using the instance method get_with_url on an instance of the class cl_bds_document_set. The method returns a URL to the data in the Data Provider. Data from a cluster table in the R/3 database (you can store binary objects in this way) must be read into an internal table. You can then send them to the Data Provider using the function modules DP_CREATE_URL_FROM_ITAB or DP_CREATE_URL. The function module returns a URL to the data in the Data Provider.
(C) SAP AG
BC412
30
2.31 SAP Picture Control: Features Legend:
set_3d_border
Container control
Class: cl_gui_picture method_name
set_display_mode Picture control
File format • .gif • .jpg • .bmp
constructor
load_picture_from_url load_picture_from_sap_icon Enlarge picture Reduce picture size Center picture ...
display_context_menu
SAP AG 1999
You can use the MIME types GIF (Graphic Interchange Format), JPG (Joint Photographic Experts Group) and BMP (Bitmap) with the SAP Picture Control as well as SAP icons. The corresponding global class is called cl_gui_picture.
You can display pictures with the above MIME types using the method load_picture_from_url. To display an SAP icon, use the method load_picture_from_sap_icon. To stop the current data being displayed, use the CLEAR_PICTURE method.
The methods SET_3D_BORDER and SET_DISPLAY_MODE (see next page) allow you to change the display attributes of the control.
You can also display context menus and implement drag and drop operations with the SAP Picture Control.
For a full list of the available methods and how to use them, refer to the online documentation for the SAP Picture Control. You will find it under Basis -> Controls & Control Framework -> SAP Picture in the SAP Library.
Details of the events of the control will follow later.
(C) SAP AG
BC412
31
2.32 SAP Picture Control: DISPLAY_MODE normal
cl_gui_picture
set_display_mode
normal_center
stretch
display_mode_...
fit_center
fit
SAP AG 1999
The display_mode method allows you to determine how the SAP Picture Control displays pictures. The current display mode is always stored in the public instance attribute display_mode. There are five different display modes, corresponding to the five technical values that display_mode can take. For each of these values there is a static constant with a relevant name. The naming convention is display_mode_). The five values of are: normal: The picture loaded into the control is displayed in its original size. If the picture is larger than the area occupied by the control, the system provides scrollbars. If it is smaller, unused space remains blank. normal_center: The picture loaded into the control is displayed in its original size but centered within the control area. stretch: The picture loaded into the control is always displayed so that it fills the entire control area. The original picture may appear stretched. fit: The picture loaded into the control is displayed so that it fills the control area (similar to stretch, except that the length/width ratio is always maintained). fit_center: Similar to fit, but centered within the control area.
(C) SAP AG
BC412
32
2.33 SAP HTML Viewer: Features get_current_url
Legend:
set_ui_flag
Class: cl_gui_html_viewer
stop
method_name
Container control
do_refresh go_back
HTML
go_forward
Viewer
constructor
go_home File format: • .html • .gif • .jpg • .bmp • .doc • .xls • ...
show_url show_url_in_browser load_html_document load_mime_object Back Forward Copy ...
load_data show_data
track_context_menu
SAP AG 1999
The SAP HTML Viewer is a control developed by SAP for use within the SAP GUI. SAP does not have its own Web browser. Instead, the SAP HTML Viewer for Windows 95 and NT 4.0 uses the Microsoft Internet Explorer Web browser Control. It supports Internet Explorer from Version 4.0. Java Beans are available for all other platforms.
The interface of the SAP HTML Viewer is the same for all platforms, but the available functions differ depending on the HTML browser you are using.
The SAP HTML Viewer allows you to display HTML pages, graphics, or pictures in your transactions. These can either be stored in the database or created at runtime. If the SAP HTML Viewer is supported by your HTML browser, you can also use it as a generic container for Java applets and ActiveX controls, or as a generic viewer for any kind of document (for example, MIME contents).
The following applies to Windows platforms: You can only use the SAP HTML Viewer if you have installed Microsoft Internet Explorer. Internet Explorer is not installed during the SAP GUI installation. You need a SAP GUI installation with Release 4.6 or higher.
On all other platforms, the Java Bean is installed with the SAP GUI.
For further information, refer to the online documentation for the SAP HTML viewer. You will find it under Basis -> Controls & Control Framework -> SAP HTML Viewer in the SAP Library.
(C) SAP AG
BC412
33
2.34 Overview: Changing the Attributes (Syntax) Overview Overview Controlsand andscreens screens Controls Changingthe the attributes attributes of ofaa control control Changing Introduction--picture picture control controland andHTML HTML Viewer Viewer Introduction attributes attributes Changingthe the attributes attributes Changing The automation automationqueue queue The Controlevents events Control Controlsand andprogram programmodularization modularization Controls
SAP AG 1999
(C) SAP AG
BC412
34
2.35 Displaying Data: Process Flow Screen 100
PBO 100
PAI 100
Program
CALL SCREEN 100
Start program DATA: my_container ... ...
MODULE init_... IF my_container IS INITIAL. CREATE OBJECT ... 1
CREATE OBJECT ... 1
CALL CALL METHOD METHOD ... ENDIF.
MODULE user_...
SAP AG 1999
If you want your frontend control to display data, you must program the data transfer in a PBO module.
To do this, you simply call a control-specific method that sends data to the control after you have created your container instance and the instance for the EnjoySAP control.
(C) SAP AG
BC412
35
2.36 Example: Displaying a Picture in the Picture Control MODULE start_control_handling OUTPUT. IF my_container IS INITIAL. ... * load picture into picture control object on screen CALL CALL METHOD METHOD my_picture->load_picture_from_url my_picture->load_picture_from_url EXPORTING EXPORTING url == l_url url l_url IMPORTING IMPORTING result result == l_result l_result EXCEPTIONS EXCEPTIONS OTHERS others == 1. 1. IF sy-subrc NE 0. MESSAGE A... ENDIF. CASE l_result. WHEN 0. ... WHEN 1. ...
SAP AG 1999
To display a picture in a SAP Picture Control, use the instance method load_picture_from_url. In the interface of the method, you pass the URL of the data source of the picture to the control. You can find out whether the method was successful or not from the return parameter result and in the form of EXCEPTIONS.
If the method triggers an exception, you should react with a suitable termination message. The return parameter result is useful for status messages concerning the load operation. For details, refer to the online documentation of the control.
For the SAP HTML Viewer Control, you must use one or more (often two) methods of the control to display data in the browser. This depends on the actual data source. (External data source: show_url, show_url_in_browser, SAP Web Repository: load_html_document, load_mime_object, SAP Data Provider: load_data, show_data).
For further information about the SAP HTML Viewer, refer to the online documentation.
(C) SAP AG
BC412
36
2.37 Syntax: Calling Instance Methods (1) General syntax CALL CALL METHOD METHOD -> -> EXPORTING = ... = IMPORTING = ... = CHANGING = ... = EXCEPTIONS = ... = .
... ... ... ...
: : : :
Interface parameters of the method Actual parameters of the calling program Names of exceptions of the method Values currently assigned to return codes
SAP AG 1999
Methods are internal procedures within a class. They can access all of the attributes of that class. You can use them to change the state of an object.
Methods have a parameter interface that you can use to pass values to them. The method can also use it to pass values back to the user.
Instance methods can access all of the attributes of a class and can trigger all of its events. You call them using the CALL METHOD statement. The syntax is the same as for the CALL FUNCTION statement. You must specify the name of the method and the object on which you want to execute it. The syntax is: CALL METHOD ref->meth.
ref is a reference variable pointing to the required object, and meth is a method of the class on which the object is based.
For a comprehensive syntax, refer to the keyword documentation for CALL METHOD.
(C) SAP AG
BC412
37
2.38 Syntax: Calling Instance Methods (2): Functional Methods General syntax CALL CALL METHOD METHOD -> -> EXPORTING = ... = RECEIVING
Single return parameter
= .
Short form ( = -> = ->( ... == ) ). ... : Import parameters of the method ... : Actual parameters of the calling program : Return parameters of the method : Program variable to which the value is returned
SAP AG 1999
Methods that have only one return parameter can return it using the RECEIVING interface (passing by value). The methods are known as functional methods.
You can call functional methods using a short form of the MOVE statement
From the point of view of the caller, a method can either return values using IMPORTING and CHANGING parameters, or a single value using RECEIVING, but not both. Consequently, if you use RECEIVING in the interface, you cannot use IMPORTING or CHANGING. Conversely, using IMPORTING or CHANGING precludes you from using RECEIVING.
For a comprehensive syntax, refer to the keyword documentation for CALL METHOD.
(C) SAP AG
BC412
38
2.39 Syntax: Reading Instance Attributes General syntax DATA: TYPE REF TO .
LIKE =>.
... CREATE OBJECT . ... * read attribute of the object == ->. ->
Example DATA: my_picture TYPE REF TO cl_gui_picture, display_mode LIKE cl_gui_picture=>display_mode. ... CREATE OBJECT my_picture EXPORTING ... ... display_mode = my_picture->display_mode.
SAP AG 1999
Attributes are internal data objects within a class.
The contents of instance attributes determine the state of a particular object.
You create instance attributes using the CREATE OBJECT statement. From outside the class, you can only address them using object references.
When you access them from outside the class, you must use the object component selector -> as follows: Reference->attribute. You can assign the result to a program variable.
Note: You can read the attributes of proxy instances of frontend controls at any time without any problems. However, you should not change the public instance attributes of a proxy object, since the changes are generally not passed to the frontend control. You should only change instance attributes using the methods of the control wrapper. This way, you ensure that they will be passed to the frontend control.
(C) SAP AG
BC412
39
2.40 Overview: The Automation Queue
Overview Overview Controlsand andscreens screens Controls Changingthe the attributes attributes of ofaa control control Changing The automation automationqueue queue The Controlevents events Control Controlsand andprogram programmodularization modularization Controls
SAP AG 1999
(C) SAP AG
BC412
40
2.41 Method Calls and the Automation Queue GUI + Control
CFW
Control instance 1
ABAP application
CALL METHOD ... call_method... set_property... get_property... Automation Queue FLUSH flush... Automation calls Return values Return values
SAP AG 1999
Method calls to a proxy instance are not normally executed straight away. Instead, they are buffered in the automation queue of the Control Framework. This is for performance reasons.
The actions are not transferred to the frontend control until a particular Control Framework method called FLUSH is triggered.
In the Control Framework, there is a single automation queue for all controls. When the flush occurs, all of the actions stored for all frontend controls are transferred. You cannot perform a "partial flush" that only applies to a single control.
When the flush takes place, result values are also transferred from the frontend controls back to the Control Framework.
(C) SAP AG
BC412
41
2.42 Sending the Automation Queue to the GUI: End of PBO GUI + Control
CFW
Control instance 1
PBO
ABAP Program
Method A
Method B
Automatic FLUSH
End of PBO
SAP AG 1999
At the end of the PBO event of a screen, the runtime services trigger an automatic flush of the automation queue.
If a screen contains subscreens, the flush is not automatically triggered until the PBO event for the main screen (containing the subscreens) has been processed, immediately before the SAPgui information is sent to the front end. The same applies to hierarchically-nested screens (a screen containing a subscreen that itself includes a subscreen). Once again, there is only one flush directly before the SAP GUI information is sent.
(C) SAP AG
BC412
42
2.43 Dependent Method Calls GUI + Control
CFW
Control instance 1
PBO / PAI
ABAP Program
Method A
Method B
What do I do? Method B needs the results from method A CALL METHOD cl_ cl_gui_ gui_cfw=>flush cfw=>flush EXCEPTIONS others = 1.
SAP AG 1999
If you call two instance methods one after the other, and the second method needs results provided by the first, you must ensure that the automation queue is transferred to the front end after the first method call. You can do this by calling the static method flush of the class cl_gui_cfw.
(C) SAP AG
BC412
43
2.44 Solution: Explicit Flush GUI + Control
CFW
Control instance 1
PBO / PAI
ABAP Program
Method A
cl_ cl_gui_ gui_cfw=>flush cfw=>flush
Method B
SAP AG 1999
If you explicitly trigger a flush in the CFW, all of the data collected in the automation queue up to that point (above: method A) is transferred to the frontend control.
This means that subsequent methods can work with the results of the methods that have already been sent to the frontend. They start a new queue.
Note: You do not always need to use explicit flushes. The automation queue is handled in the Control Framework in such a way that queries for the values of control attributes that can be answered with data that is already in the automation queue can be answered without any communication with the frontend. Example: Suppose method A sets attribute a1 of object O to value v1. If method B of object O is executed and queries the value of a1, the Control Framework will return the value v1 from the automation queue. It does not make sense to call the flush method of cl_gui_cfw just "for safety" after each method call, since each flush increases the system load and can affect performance. You should only use it where really necessary.
(C) SAP AG
BC412
44
2.45 Optimizing Performance in the Automation Queue Control 1
Control 2
value(1)
value(2)
SAP GUI Copy data object x from control 1 to control 2 in the GUI + get x from control 1
X = get(value) value(1) value(2)
Automation queue Requests? CALL METHOD proxy1->get_value IMPORTING value = x.
CALL METHOD proxy2->set_value EXPORTING value = x.
CALL METHOD cl_gui_cfw=>flush.
ABAP program
SAP AG 1999
As outlined in the previous slide, the Automation Queue is implemented in a way that optimizes performance. This concept is explained in more detail below.
To move or copy data between controls, you must call two methods: the first method queries the first control for the data to be moved; the second moves this data to the second control. The implementation of the Automation Queue optimizes this process by making the copying process take place at the front end, without involving the application server - that is, avoiding unnecessary round trips between the SAP GUI and the application server (from the system's point of view) . You should always use this method to exchange large volumes of data between controls.
Note: The system transports data to the application server at every synchronization point (variable x). Therefore, once you set a synchronization point after the first method (get_value), using cl_gui_cfw=>flush, you can no longer use the performance optimization feature of the Automation Queue.
Remarks: The system transports the data queried from control 1 to the declared variable at the end of executing the method cl_gui_cfw=>flush (that is, performs a round trip between the SAP GUI and the application server).
(C) SAP AG
BC412
45
2.46 Method Calls: Possible Causes of Errors (1) Program variable
Automation queue
DATA: x TYPE I.
x=0
x=1
x=1
x = 10
GUI control value = 10
CALL METHOD proxy->get_value IMPORTING value = x.
x=0
Implementation
X = get(value)
value = 10
x = x + 1.
X = get(value)
value = 10
CALL METHOD proxy->set_value EXPORTING value = x.
X = get(value) value value
value = 10
CALL METHOD cl_gui_cfw->flush.
x is reused in the queue value = 10
SAP AG 1999
It is important to be aware of the effects of performance optimization in the automation queue. Otherwise concatenated method calls can lead to undesirable results.
For example, variables that have been passed to the automation queue cannot subsequently be used directly as program variables. The example above clarifies this issue: When you first obtain the value of an attribute using a method, the system creates an entry in the automation queue (x is saved). All subsequent operations on x (in the ABAP program) modify the ABAP program data object. If x is then sent again to the same queue, performance optimization ensures that the x in the queue is used again. The value of the attribute, using x, is set in the SAP GUI. The value of the attribute, using x, is set in the SAP GUI. The result, however, make it seem as if the system suppressed both calls (x = x + 1 and the method set_value).
(C) SAP AG
BC412
46
2.47 Method Calls: Solving the Problem (1) Program variable
Implementation
Automation queue
DATA: x TYPE I.
x=0
value = 10
CALL METHOD proxy->get_value IMPORTING value = x.
x=0
GUI control:
X = get(value)
value = 10
x = 10
CALL METHOD cl_gui_cfw->flush.
value = 10
x = 11
x = x + 1.
value = 10
x = 11
CALL METHOD proxy->set_value EXPORTING value = x.
X = set(value)
FLUSH
value = 10
value = 11
SAP AG 1999
The solution to the above problem is to set a synchronization point before the data passed to the program is processed further (x = x +1).
Note: The value of x is passed to the control at the next synchronization point - at the latest, after the end of the next PBO processing block.
General note: If you want to work with return codes from automation calls, you must always set a synchronization point. Never rely on internal synchronization points or encapsulated triggered synchronization points (that is, synchronization points within other subroutines or methods).
Note: If the automation queue is empty, the system does not perform a round trip between the application server and the SAP GUI.
(C) SAP AG
BC412
47
2.48 Method Calls: Possible Causes of Errors(2) Program variable
x=0 y=1 x=0 y=1
x = 10 y=1
GUI control: value = 10
CALL METHOD proxy->get_value IMPORTING value = x.
x=0 y=0
Automation queue
DATA: x TYPE I, y TYPE I.
x=0 y=0
Implementation
X = get(value)
value = 10
Y = X + 1.
X = get(value)
value = 10
CALL METHOD proxy->set_value EXPORTING value = y.
X = get(value) Y = set(value)
value = 10
CALL METHOD cl_gui_cfw->flush.
y appears in the queue for the first time! value = 1
SAP AG 1999
Errors can also occur when you are working with the automation queue if you use different variables in the method interfaces, but do not set the synchronization point correctly. The example above clarifies this issue: You obtain the value of an attribute of a control. The variable name x is stored in the automation queue. As the previous slide shows, statements pertaining to x are performed only on the data object in the ABAP program. y is calculated from x (as above). Subsequently, when a method is called that sets the attributes used by y, the name y is stored in the queue. (y is described by means of x). However, the queue does not recognize that there is a logical connection between x and y. Consequently, two operations are performed. x is not reused within the queue. The sequence of automation calls remains the same in the SAP GUI as in the automation queue.
(C) SAP AG
BC412
48
2.49 Method Calls: Solving the Problem (2) Program variable
Implementation
Automation queue
DATA: x TYPE I, y TYPE I.
x=0 y=0
value = 10
CALL METHOD proxy->get_value IMPORTING value = x.
x=0 y=0
x = 10 y=0
CALL METHOD cl_gui_cfw->flush.
x = 10 y = 11
Y = X + 1.
x = 10 y = 11
X = get(value)
value = 10
value = 10
value = 10
CALL METHOD proxy->set_value EXPORTING value = y.
Y = set(value)
FLUSH
GUI control:
value = 10
value = 11
SAP AG 1999
The solution to the above problem is to set a synchronization point before the data passed to the program is processed further (y = x +1).
Note: The value of x is passed to the control at the next synchronization point - at the latest, after the end of the next PBO processing block.
(C) SAP AG
BC412
49
2.50 Method Calls: Possible Causes of Errors(3) Program variable
Implementation
Automation queue
PERFORM my_form. ...
x=0
Memory for x released
GUI control:
value = 10
FORM my_form. DATA: x TYPE I. ... CALL METHOD proxy->get_value IMPORTING value = X. ENDFORM.
X = get(value)
CALL METHOD cl_gui_cfw=>flush
value = 10
value = 10
Data object x no longer exists!
Runtime error
SAP AG 1999
A third cause of errors is using a temporary data object (in the method interface), which no longer exists when the method is executed (when a synchronization point has been set using cl_gui_cfw=>flush). The example above clarifies this issue: You obtain a value for an attribute of a control and use a variable, x, in the method interface. The variable x is declared locally in the subroutine in which the method is called. The method call and the variable name x are both stored in the automation queue. The next synchronization point (created using the static method cl_gui_cfw=>flush) triggers a runtime error, since x, the data object declared in the interface, no longer exists.
From Release 4.6B onwards: A non-catchable runtime error is triggered (system_pointer_plucking) The order in which methods were called is available in the Debugger The Debugger also displays a reference to the variable causing the error.
(C) SAP AG
BC412
50
2.51 Recommendations for Calling Methods at PAI PAI flow logic:
PAI flow logic: Control 1
Read attributes (control 1)
Read attributes
Read attributes (control 2)
FLUSH Make decisions + set attributes
FLUSH
FLUSH
Make decisions
Control 2
Set attributes (control 1) Set attributes (control 2)
Automatic
FLUSH
2 * FLUSH for each PAI/PBO cycle
(2 * Objects + 1) * FLUSH for each PAI/PBO cycle
SAP AG 1999
To improve performance in your programs, you should always try to minimize the number of round trips between the SAP GUI and the application server.
In many cases the transfer rate is the decisive limiting factor, not the bandwidth available.
Example: A user is connected to an R/3 System by satellite. Typically, it will take 0,5 seconds to set up a connection between the SAP GUI and the server. If your screen requires 10 round trips, the user will have to wait 10 seconds before he or she can perform an action on the screen.
To minimize the number of round trips, you should structure your PAI source code in such a way that you call all methods only after obtaining the attributes of all the controls you are using. If other actions depend on the results of these reading operations, you must set a synchronization point (cl_gui_cfw=>flush). You can then call all the methods that change attributes, depending on the results.
Structuring your PAI code in this way leads to much better performance than structuring it as shown on the right of the above slide - that is, calling the method cl_gui_cfw=>flush twice for each control.
Note: When you use automatic synchronization points, make sure that the contents of the automation queue are transferred after the rest of the screen data. Unless you use an explicit synchronization point, the screen fields will contain obsolete values, if you filled them using return parameters from method interfaces.
(C) SAP AG
BC412
51
2.52 Method Calls and EXCEPTIONs Control
CFW
Automation queue
m1 m2 m3
ABAP Program
For test purposes
Method m1
EXCEPTIONS Method m2 EXCEPTIONS Method m3 EXCEPTIONS
cl_gui_cfw=>flush EXCEPTIONS
EXCEPTIONS
Installation error in control component System error
Must be queried! End of program Check GUI installation
SAP AG 1999
Exceptions in the interfaces of proxy methods generally refer to errors in the frontend control. Since method calls are buffered in the automation queue, these exceptions are not triggered at runtime. You should still implement exceptions, so that you can perform meaningful tests on the program in the Debugger. (The Debugger allows you to execute all methods synchronously. More details are available later in this course).
If an error occurs at the front end while the automation queue is being processed (at a synchronization point), the system aborts processing of the entire queue and triggers an exception. You should always implement exceptions in the interface of the method cl_gui_cfw=>flush.
Errors processing the automation queue at the front end generally occur when the control has been incorrectly installed. If such an error occurs, you should make sure that processing is terminated cleanly (with a termination ("A") or exit ("X") message), and that the frontend installation is tested and repaired by an administrator.
(C) SAP AG
BC412
52
2.53 Overview: Tracing Errors in Controls Programming Test tool
SAP GUI + Controls
Automation Trace
Used to Log all incoming Automation calls
Asynchronous control communication
ABAP Program + runtime services
ABAP Debugger
Change to synchronous control communication and execute in the Debugger
SAP AG 1999
There are two tools you can use to analyze communication between controls your ABAP program: The ABAP Debugger lets you test communication between controls and the ABAP program synchronously, in Debugger mode. You can switch on a trace at GUI level , which logs all incoming automation calls
(C) SAP AG
BC412
53
2.54 Automation Queue: Using the ABAP Debugger
ABAP Debugger
Fields
...
Settings
Settings System debugging . . ... Automation Controller: Always process requests synchronously
SAP AG 1999
When you use buffered operations to communicate with controls, errors in a method call are not visible until you synchronize the automation queue. It is therefore a good idea to synchronize the automation queue after each method call when you are debugging. You can do this by setting the Automation Controller: Always process requests synchronously option in the Debugger. This calls the static method cl_gui_cfw=>flush after each automation method.
If the error no longer occurs when you run the program in this way, you have called the method cl_gui_cfw=>flush at the wrong point somewhere in your program. You should include appropriate error handling after every method call (query value of SY-SUBRC). Note that the error handling is normally only processed within Debugging.
(C) SAP AG
BC412
54
2.55 Automation Queue: Using the Automation Trace
Options ... ...
Options General
Cursor
Trace
Mode ...
...
...
Trace level
Automation 1
2
Trace file: front.trc
Switch on
Options
OK
Cancel
window Apply
SAP AG 1999
You can set up a trace for the automation queue. To do this, select Automation in the Trace group of the SAP GUI settings. All subsequent calls and their parameters (create object, call method, set/get property, free object) to the automation queue are logged in a trace file.
If an error occurs, it is logged in the trace file (HRESULT error_code).
You can also check the number of synchronizations (times the automation queue is flushed) that your application uses in each PAI/PBO block. You can then eliminate any redundant flushes.
Remember when you follow the method calls in the trace file that the ABAP method names generally differ from the method names in the trace. The method names in the trace are those of the automation calls to the control. Remember too that a single ABAP method call may cause more than one automation method call.
(C) SAP AG
BC412
55
2.56 Destroying Control Instances MODULE exit_commands_0100 INPUT. CASE ok_code. WHEN 'EXIT'. " leave program PERFORM free_control_ressources. free_control_ressources. PERFORM LEAVE PROGRAM. WHEN 'CANCEL'.
" cancel screen processing
PERFORM free_control_ressources. free_control_ressources. PERFORM LEAVE TO SCREEN 0. ... ENDMODULE. FORM free_control_ressources. CALL METHOD my_control->free. CALL METHOD my_container->free. FREE: my_control, my_container. ENDFORM.
SAP AG 1999
To release the resources occupied by a frontend control, call the instance method free of the control you have finished with.
All control wrappers inherit this method from the class cl_gui_object.
You should call this method At the end of your program In any cases where you know you will no longer require the frontend controls in the course of your program.
By releasing the object references (above, the statement FREE: my_control, my_container), you ensure that the resources allocated to the proxy objects in your program are released by the garbage collector.
(C) SAP AG
BC412
56
2.57 Overview: Control Events Overview Overview Overview Controlsand andscreens screens Controls Changingthe the attributes attributes of ofaa control control Changing The automation automationqueue queue The Controlevents events Control Overview Overview ABAP Objects Objectsevents events ABAP Controlevents eventsand andthe the Control ControlFramework Framework Control Eventtypes types Event Controlsand andprogram programmodularization modularization Controls
SAP AG 1999
(C) SAP AG
BC412
57
2.58 Recap: Control Events EnjoySAP control 1
EnjoySAP control 2
Events: e1 - e7
Automation Controller Events: e1 - e5 Automation handler
Events *1: e1, e2, e4 *2: e1, e3
SAP GUI Application server Control Framework
ABAP Program
1 2
CFW service
Events #1: e1, e2, e4 #2: e1, e3
SAP AG 1999
EnjoySAP controls can trigger events. The Control Framework directs them to the approrpriate proxy objects in your ABAP program. You can then process them using the event concept implemented in ABAP Objects.
(C) SAP AG
BC412
58
2.59 Control Events: General Overview SAP GUI GUI + control
Basis services
Autom. controller
ABAP application
Services
Event handler
event fcode, ...
ABAP Objects event
SAP AG 1999
An event that is passed from a frontend control passes through various levels. SAP GUI/Automation Controller: The event triggered at the front end is received by the Automation Controller in the SAP GUI. The Automation Control passes information about this event to the Basis services of the runtime system in the form of a special function code and some additional data. Basis Services: The Basis services pass the information on to the proxy class in the ABAP application. ABAP Application: The proxy object in the ABAP application triggers an ABAP Objects event. This informs the components that are registered for the event that the event has occurred.
In each level Certain settings are required for the whole chain to function. Certain settings can be made to affect how the chain works.
The next section explains in more detail what settings you have to make and which you can make.
(C) SAP AG
BC412
59
2.60 Overview: Control Events ABAP Objects Events Overview Overview Controlsand andscreens screens Controls Changingthe the attributes attributes of ofaa control control Changing The automation automationqueue queue The Controlevents events Control Overview Overview ABAP Objects Objectsevents events ABAP Controlevents eventsand andthe the Control ControlFramework Framework Control Eventtypes types Event Controlsand andprogram programmodularization modularization Controls
SAP AG 1999
(C) SAP AG
BC412
60
2.61 Control Events: Overview SAP GUI GUI + control
Basis services
Autom. controller
Services
ABAP application Event handler
event fcode, ...
ABAP Objects event
SAP AG 1999
First, we will look at the steps necessary to make your application react to events triggered by a proxy object.
(C) SAP AG
BC412
61
2.62 Overview: ABAP Objects Events List of registered methods of other instances for event of instance 1 method_name
Instance
method_x
ref_1
method_y
ref_2
...
...
1
method_x
1
method_y
1
method_n
1 Event
Basis service
Method
SAP AG 1999
An object can announce that its state has changed by triggering an event.
Other objects can contain handler methods, which are processed when the event occurs.
In order for the handler methods of the other instances to be executed, they must be entered in a list in the object that triggers the event.
When the event is triggered, a Basis service takes responsibility for executing the registered methods.
In a normal method call, the caller has control of the program and knows what methods it is calling. When an event is triggered, the trigger does not know what methods (if any) will be called. This applies both to the point at which the event is defined and the point at which the event occurs at runtime.
(C) SAP AG
BC412
62
2.63 Events of ABAP Objects Instances List of registered methods of other instances for event of instance 1 method_name
Instance
method_x
ref_1
method_y
ref_2
...
...
1
method_x
1
method_y
1
method_n
1 Event
Basis service
Method
SAP AG 1999
If you want to react to events from an EnjoySAP control in your program, you first need to find out what events the object can trigger.
You can check this in the definition of the proxy class of the control in the Class Builder.
(C) SAP AG
BC412
63
2.64 Example: Events of the SAP Picture Control Component
Description
Parameters class 1
class 2
cl_gui_picture
Events
picture_click
Mouse click on the picture
mouse_pos_x mouse_pos_y
picture_dblclick
Mouse double-click on the picture
mouse_pos_x mouse_pos_y
control_click
Mouse click within the control
mouse_pos_x mouse_pos_y
control_dblclick
Mouse double-click within the control
mouse_pos_x mouse_pos_y
context_menu
Events for context menus
...
ondropcomplete
Events for drag and drop operations
...
SAP AG 1999
The class for the SAP Picture Control has the following events: Four events are triggered by mouse operations on the control contents or the control area. picture_click: A single-click on the contents of the control (picture or icon). picture_dblclick: A double-click on the contents of the control (picture or icon). control_click: A single-click on the control area (but not on the contents). control_dblclick: A double-click on the control area (but not on the contents). Two events are triggered that can be used in conjunction with context menus: context_menu, context_menu_selected. Four events are used together with drag and drop operations: ondrag, ondrop, ondropcomplete and ongetflavour.
When the mouse click events are triggered, the position of the mouse when the user clicked is passed in parameters.
Note that you cannot use the single- and double-click events together, since a single-click is always triggered before a double-click. The double-click is then lost when the event is transferred from the frontend.
For further details of the events, refer to the online documentation for the SAP Picture Control.
(C) SAP AG
BC412
64
2.65 Example: Events of the SAP HTML Viewer Component
Description
Parameters class 1
class 2
cl_gui_html_viewer
Events navigate_complete
Page loaded completely
url
sapevent
Application-specific event
action frame ...
ctxmenu_request Events for context menus ctxmenu_selected
SAP AG 1999
The SAP HTML Viewer Control has four events: navigate_complete: This event is triggered each time a page is fully loaded in the browser. The URL of the page is returned in the parameter url. sapevent: You can trigger this event in an HTML page using SAPEVENT:?data. The two events ctxmenu_request and ctxmenu_selected, which are both triggered when you use context menus.
For further details of the events, refer to the online documentation for the SAP HTML Viewer Control.
(C) SAP AG
BC412
65
2.66 ABAP Objects: Creating Handler Methods List of registered methods of other instances for event of instance 1 method_name
Instance
method_x
ref_1
method_y
ref_2
...
...
1
method_x
1
method_y
1
method_n
1 Event
Basis service
Method
SAP AG 1999
If you want to react to events from EnjoySAP controls, you need to define handler methods that are executed when the event is triggered. We will now look at the steps required to do this.
(C) SAP AG
BC412
66
2.67 Creating an Event Handler Method: Static Methods class lcl_event_handler DEFINITION. CLASS DEFINITION PUBLIC SECTION. CLASS-METHODS: on_picture_click FOR EVENT picture_click OF cl_gui_picture mouse_pos_y. IMPORTING mouse_pos_x mouse_pos_y ... ENDCLASS ENDCLASS. IMPLEMENTATION CLASS lcl_event_handler IMPLEMENTATION. METHOD on_picture_click. ... MESSAGE i016(bc412) WITH mouse_pos_x mouse_pos_y. ENDMETHOD. ... ENDCLASS ENDCLASS.
SAP AG 1999
A simple way of creating a handler method is to use a static method of a local class.
The graphic shows how you can create a static method of a local class that reacts to the event picture_click of an instance of the SAP Picture Control.
The method receives the coordinates of the mouse position from the event and displays an information message (type I) containing the coordinates and a text.
Since methods are components of a class, the graphic shows the method definition within a local class.
Let us now look in more detail at the components.
(C) SAP AG
BC412
67
2.68 Syntax: Local Classes General syntax " Class definition
CLASS DEFINITION. [PUBLIC| PUBLIC PROTECTED PROTECTED| PRIVATE PRIVATE] SECTION. SECTION CLASS- DATA [CLASS-]DATA:
" Visibility sections
...
[CLASS-]METHODS:... METHODS
" Components in each
[CLASS-]EVENTS: EVENTS ...
" Visibility section
... ENDCLASS ENDCLASS. IMPLEMENTATION CLASS IMPLEMENTATION>. METHOD ... " Implementation of
...
" methods in the class
ENDMETHOD ENDMETHOD. ENDCLASS. ENDCLASS
SAP AG 1999
A class is a template for objects. Classes that you define in ABAP programs are called local classes.
A class definition consists of a declaration part (CLASS DEFINITION. ... ENDCLASS.) and an implementation part (CLASS IMPLEMENTATION. ... ENDCLASS.).
The class contains components. All of the components of the class have to be listed in the declaration part of the class. The components define the attributes of the objects in a class. Each component must be declared in one of three visibility sections. The visibility sections define the external interface of the class. Within a class, all of the components are visible. The three visibility sections are: PUBLIC - All public components of a class are visible to all users and in the class itself. The public components form the external interface of the class. PROTECTED - All protected components of a class are visible to the subclasses of the class and in the class itself. PRIVATE - Private components can only be addressed in the methods of the class in which they are delared.
All of the methods of the class must be implemented in the implementation part of the class.
As a rule, your local classes should have the prefix lcl_
For further information, refer to the keyword documentation for the CLASS statement.
(C) SAP AG
BC412
68
2.69 Syntax: Methods of Local Classes CLASS DEFINITION. [PUBLIC| PROTECTED| PRIVATE] SECTION. METHODS [CLASS-]METHODS: Interface definition
IMPORTING TYPE ... TYPE EXPORTING TYPE ... CHANGING
TYPE ...
RETURNING VALUE( ) EXCEPTIONS ... . ENDCLASS. CLASS IMPLEMENTATION. METHOD . METHOD
Interface parameters of the method
... ENDMETHOD. ENDMETHOD. ENDCLASS.
SAP AG 1999
Methods are internal procedures within a class. They can access all of the attributes of a class.
Methods have a parameter interface that you can use to pass values to them. The method can also use it to pass values back to the user. You can declare local data types and objects within a method. Local variables and interface parameters (which are handled like local variables) obscure other attributes in the class with identical names.
Instance methods can access all of the attributes of a class and can trigger all of its events.
Static methods (declared using CLASS-METHODS) can only access the static attributes of a class, and can only trigger its static events. They can be executed even without there being an instance of the class.
Each method of a class must be implemented in a METHOD ... ENDMETHOD block in the implementation part of the class. You do not have to list the interface parameters in the method implementation, because you have already specified them in the definition.
Like function modules, you can use the RAISE and MESSAGE RAISING statements to react to errors.
A method with any number of IMPORTING parameters and a single RETURNING parameter is called a functional method. The RETURNING parameter is always passed by value.
(C) SAP AG
BC412
69
2.70 Syntax: Handler Method for an Event
CLASS DEFINITION. [PUBLIC| PROTECTED| PRIVATE] SECTION. METHODS [CLASS-]METHODS: FOR EVENT OF IMPORTING IMPORTING ... [SENDER], SENDER ... ENDCLASS. CLASS IMPLEMENTATION. METHOD . ...
" method implementation
ENDMETHOD. ENDMETHOD. ENDCLASS.
SAP AG 1999
Any class can contain handler methods for events of other classes.
In the declaration part of an event handler method, you must use the FOR EVENT OF addition. This specifies the event of class to which the method can react.
When assigning names to event handler methods, you should observe the following rules: ON_ where is the name of the event.
The interface of an event handler method may only contain formal parameters that are defined in the declaration of the corresponding event. The attributes of the parameters are inherited from the event definition. The event handler method does not have to import all of the parameters passed in the RAISE EVENT statement.
All events have an implicit parameter called SENDER, which you can include in the IMPORTING parameters. This contains an object reference to the object that triggered the event, and hence allows the handler to access the triggering object.
The example contains a static method, declared using CLASS-METHODS. This can run without an instance of the class having to exist.
When you declare an event handler method in the class, the class or its instances are, in principle, able to handle the event.
(C) SAP AG
BC412
70
2.71 ABAP Objects: Registering Handler Methods List of registered methods of other instances for event of instance 1 method_name
Instance
method_x
ref_1
method_y
ref_2
...
...
1
method_x
1
method_y
1
method_n
1 Event
Basis service
Method
SAP AG 1999
The last step in event handling is to ensure that the event handler method is executed when the proxy object triggers the event. To do this, you must register the event handler method (of the local class) with the instance that triggers the event.
(C) SAP AG
BC412
71
2.72 Linking an Event to a Handler Method CLASS lcl_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_picture_click FOR EVENT picture_click OF cl_gui_picture ... ENDCLASS. CLASS lcl_event_handler IMPLEMENTATION. METHOD on_picture_click. ... ENDMETHOD. ENDCLASS. . . . CREATE OBJECT my_container ... CREATE OBJECT my_picture ... SET HANDLER lcl_event_handler=>on_picture_click FOR my_picture.
What's happening?
Which method reacts to each event?
SAP AG 1999
In order for an event handler method to react to an event, you must specify the triggering object at runtime.
The SET HANDLER statement links a list of handler methods with event triggers.
The graphic shows that the static method (not instance-specific) on_picture_click of class lcl_event_handler runs when the instance to which the object reference in my_picture is pointing triggers the event picture_click.
(C) SAP AG
BC412
72
2.73 Syntax: Linking an Event to a Static Handler Method
DATA: TYPE REF TO , TYPE REF TO . ... CLASS DEFINITION. PUBLIC SECTION. CLASS-METHODS: CLASSFOR EVENT OF ... ... ENDCLASS. . . . CREATE OBJECT: , .
contains Static method reacts to event
Instances of class
... SET HANDLER => => FOR FOR .
runs when an event of is triggered
SAP AG 1999
The statement SET HANDLER => FOR specifies that the static method of class is executed when the instance to which is pointing triggers the event . points to an instance of the class , which has the event .
The second instance, to which object reference is pointing, can also trigger the event . However, if it does, the method of class is not processed, because it is not registered for this instance (no SET HANDLER statement).
(C) SAP AG
BC412
73
2.74 Syntax: Linking an Event to an Instance Handler Method
DATA: TYPE REF TO , TYPE REF TO . ... CLASS DEFINITION. PUBLIC SECTION. METHODS: FOR EVENT OF ... ... ENDCLASS. ... DATA: TYPE REF TO , TYPE REF TO . ... CREATE OBJECT: , . CREATE OBJECT: , . ... SET HANDLER -> -> FOR .
SAP AG 1999
should contain event Instance method reacts to event
Instances of the classes and of the instance runs when an event of is triggered
The statement SET HANDLER -> FOR specifies that the instance method of class is executed when the instance to which is pointing triggers the event . points to an instance of the class , which has the event .
The second instance, to which object reference is pointing, can also trigger the event . However, even if the event occurs, there will be no reaction, because no instance is registered for the event (no SET HANDLER statement).
The instance to which is pointing is not involved in event handling.
For further information about registering handler methods for events, refer to the keyword documentation for the SET HANDLER statement.
(C) SAP AG
BC412
74
2.75 Overview: Control Events Control Events and the Control Framework Overview Overview Controlsand andscreens screens Controls Changingthe the attributes attributes of ofaa control control Changing The automation automationqueue queue The Controlevents events Control Overview Overview ABAP Objects Objectsevents events ABAP Controlevents eventsand andthe the Control ControlFramework Framework Control Eventtypes types Event Controlsand andprogram programmodularization modularization Controls
SAP AG 1999
(C) SAP AG
BC412
75
2.76 Control Events: Overview SAP GUI GUI + control
Basis services
Autom. controller
Services
ABAP application Event handler
event fcode, ...
ABAP Objects event
SAP AG 1999
The next component that is involved in event processing is the Automation Controller in the SAP GUI.
(C) SAP AG
BC412
76
2.77 Control Events: Automation Control as Filter EnjoySAP control e1
e2
e3
e4
e5
e3
Control Events: e1, e2, e3, e4, e5 e2
Registered events
Automation Controller *1: e1, e2, e4 Function code Basis services
SAP AG 1999
The function of the Automation Controller in the SAP GUI is to act as a filter for the various control events. The Automation Controller has a list of all events registered for an instance. Only these events are passed from the Automation Controller to the Basis services (in the form of function codes). All other control events that are not registered are filtered out by the Automation Controller.
The list that the Automation Controller administers for each instance must be filled from the ABAP application that is going to handle the control events.
Note that the procedure of filling the list of events that the Automation Controller should direct to the program is also called registering events. However, it is a different process to the event registration we have already seen in ABAP Objects.
(C) SAP AG
BC412
77
2.78 Control Events: Configuring the Control Framework EnjoySAP control
Control Events: e1, e2, e3, e4, e5 Registered events
Automation Controller *1: e1, e2, e4
Basis services
1 Method: set_registered_events ABAP Program
e1 e2 e4
eventid appl_event 1 Internal table 2 4711
SAP AG 1999
You construct the list of events to be registered in the Automation Controller as follows: In the ABAP program, an internal table is constructed containing the technical names (event IDs) of the events you want to register with the Automation Controller. You then send this internal table to the proxy object of the control using the instance method set_registered_events. The proxy object then places the data in the Automation Queue in the Control Framework ( Basis Services, in the example above). When the next synchronization (FLUSH) occurs, the list is automatically sent to the Automation Controller.
In the internal table in the ABAP program, you enter the technical name of the event in the eventid field.
The event IDs for each EnjoySAP control are listed in the online documentation and n the definitions of the proxy classes in the Class Builder.
(C) SAP AG
BC412
78
2.79 Example of Picture Control Events: Event IDs Component
Description
Parameters
ID
class 1 class 2
cl_gui_picture
Class constants:
Events picture_click
Mouse click...
mouse_... ...
eventid_picture_click
picture_dblclick
Double-click...
...
eventid_picture_dblclick = 3
control_click
...
...
eventid_control_click
control_dblclick
...
...
eventid_control_dblclick = 5
context_menu
Events for context menus ...
ondropcomplete
SAP AG 1999
Events for drag and drop operations
...
=2
=4
...
...
The SAP Picture Control has the following static constants that represent the event IDs: eventid_picture_click for the event picture_click eventid_picture_dblclick for the event picture_dblclick eventid_control_click for the event control_click eventid_control_dblclick for the event control_dblclick eventid_context_menu for the event context_menu eventid_context_menu_selected for the event context_menu_selected
Drag and drop events are treated differently than the other events, which are explained here. For further details, refer to the Drag and Drop section of the online documentation SAP Control Framework (SAP Control Framework -> Architecture of the Control FRamework -> Event Handling -> Drag and Drop). You will find it under Basis -> Controls & Control Framework -> SAP Control Framework in the SAP Library.
(C) SAP AG
BC412
79
2.80 Example of SAP HTML Viewer Events: Event IDs Component
Description
Parameters ID
class 1 class 2
cl_gui_html_viewer
Class constants:
Events navigate_complete
Page complete... url
m_id_navigate_complete = 2
sapevent
Application event
m_id_sapevent
=1
m_id_ctxmenu_request
=4
action frame ...
ctxmenu_request Events for context menus ctxmenu_selected
m_id_ctxmenu_selected = 3
SAP AG 1999
The SAP HTML Viewer Control has the following static constants that represent the event IDs: m_id_navigate_complete for the event navigate_complete m_id_sapevent for the event sapevent m_id_cxtmenu_request for the event ctxmenu_request m_id_cxtmenu_selected for the event ctxmenu_selected
(C) SAP AG
BC412
80
2.81 Registering Control Events with the CFW TYPE-POOLS: cntl. DATA: it_events TYPE cntl_simple_events, " internal (event) table wa_events LIKE LINE OF it_events. " work area * register events:i) picture_click wa_events-eventid cl_gui_picture=>eventid_picture_click wa_events-eventid = cl_gui_picture=>eventid_picture_click. INSERT wa_events INTO TABLE it_events it_events. * ii)control_dblclick ... . . . CALL CALL METHOD METHOD my_picture->set_registered_events my_picture->set_registered_events EXPORTING events events = = it_events it_events EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a... ENDIF.
*
SAP AG 1999
You use the event IDs of the relevant events (registered in the Automation Controller) to construct an internal table that you can then pass to the proxy object in your ABAP application.
To do this, create an internal table (above: it_events) with the data type cntl_simple_events. You also need a work area for the internal table (above: wa_events).
The table type cntl_simple_events is declared in the type pool CNTL Add this to your program using the TYPE-POOLS cntl. statement.
Fill the internal table with the IDs of the events you want to register (eventid field).
Call the instance method set_registered_events for the proxy instance, and pass the internal table to the interface parameter events.
Use a termination message to react to any exceptions.
(C) SAP AG
BC412
81
2.82 Overview: Control Events - Event Types Overview Overview Controlsand andscreens screens Controls Changingthe the attributes attributes of ofaa control control Changing The automation automationqueue queue The Controlevents events Control Overview Overview ABAP Objects Objectsevents events ABAP Controlevents eventsand andthe the Control ControlFramework Framework Control Eventtypes types Event Controlsand andprogram programmodularization modularization Controls
SAP AG 1999
(C) SAP AG
BC412
82
2.83 Event Type: System Event SAP GUI
Basis services
GUI + Autom. control controller
Services (CFW)
ABAP application PAI
Event handler
Event fcode, ...
SAP AG 1999
Control events that you register with the Automation Controller as we have just seen are known as system events.
With system events, the Basis services inform the proxy object about the event directly when the corresponding function code arrives. In reaction, the proxy object triggers the corresponding event in the ABAP application. The screen containing the frontend control is not processed, that is, the PAI event is not triggered. Consequently, no data from other screen elements is transferred back to the program. The event handling is restricted to the "object-oriented world" of the ABAP application.
(C) SAP AG
BC412
83
2.84 Event Type: Application Event SAP GUI
Basis services
GUI + Autom. control controller
Services (CFW)
ABAP application PAI
Event handler
Event fcode, ... Screen data transport
cl_gui_cfw=>dispatch
SAP AG 1999
As well as using system events, you can also register a control event with the Control Framework as an application event.
Application events are processed differently to system events.
If a control triggers an application event, control is returned to its container screen. The control triggers the event to the Automation Control The Automation Controller passes the information connected to the event (EXPORTING parameters and function code) to the Basis services on the application server. The Basis services trigger the PAI event of the container screen.
At the beginning of the PAI event, the normal field transport takes place from the screen to the program.
Since control is passed back the container screen of the control, the ABAP application determines itself when to pass the control on to the proxy object to complete the event handling. You do this in your application using the method cl_gui_cfw=>dispatch.
As soon as the method cl_gui_cfw=>dispatch is called, the Basis services pass the information about the control event to the proxy object. The proxy event can then trigger the corresponding event on the ABAP side.
(C) SAP AG
BC412
84
2.85 Registering Application Events 1 Method: set_registered_events ABAP program
e1 e2 e4
eventid appl_event x 1 x Internal table 2 x 4711
* register application event: picture_click wa_events-eventid = cl_gui_picture=>eventid_picture_click. 'X'. wa_events-appl_event = 'X' INSERT wa_events INTO TABLE it_events. . . . CALL METHOD my_picture->set_registered_events EXPORTING events = it_events ...
SAP AG 1999
You specify that an event should be an application event when you register it with the CFW. To register an event as an application event, assign the value 'X' to the appl_event column for the relevant line of the internal table that you pass to the proxy object in the set_registered_events method.
(C) SAP AG
BC412
85
2.86 Screen and Control: Call Sequence for Application Events External SAP GUI session Window
EnjoySAP control Application event SAP GUI services
GS1
GSn
AC
GS = GUI Service AC = Automation Controller
Function code Runtime system services RS1
RSm
CFW
RS = Runtime system Service CFW = Control Framework
Sequence? Check modules m1
mr
event handler
ABAP application m = module
SAP AG 1999
If you use application events in your application, you must specify the order in which you want your own check modules and the event handler methods to run: If you want to process the screen-specific input checks first, then the event handler, you must call the method cl_gui_cfw=>dispatch after the check modules. Otherwise, you call the method before the check modules.
(C) SAP AG
BC412
86
2.87 Application Events and Screen Input Checks (1) SAP GUI
Basis services
GUI + control controller
Services (CFW)
ABAP application PAI
Event handler
Input checks
fcode, ...
dispatch
Question: What do we do if the event handler needs screen data? The screen entries have not yet been checked.
SAP AG 1999
If you want to run the screen-specific input checks after the event handling, you must remember that you cannot use up-to-date values from the screen, since they are not transported until the relevant check module is processed (FIELD statement).
If you need to use current screen data in the event handler method, you should trigger the event handling after the check modules have run.
(C) SAP AG
BC412
87
2.88 Application Events and Screen Input Checks (2) SAP GUI
Basis services
GUI + control
Services (CFW)
event fcode, ...
ABAP application PAI
Event handler
Input checks
MESSAGE e123 New input new fcode (new event)
SAP AG 1999
If you perform the screen-specific checks before the event handling, it is possible for control events to be lost during an error dialog. The frontend control triggers an event that is passed to the application server as an application event. Control returns to the container screen, which processes the screen-specific check modules. If an error or warning message (MESSAGE Ennn or MESSAGE Wnnn, where nnn is the message number) occurs during a check module, the user can change his or her entries on the screen and then trigger a different event with a different function code. The new function code overwrites the function code linked to the event originally triggered by the user. The cl_gui_cfw=>dispatch call then does not lead to any event handling.
This does not occur if the new function is triggered by a screen element such as a pushbutton or menu entry. The original event is not lost.
(C) SAP AG
BC412
88
2.89 System Event and set_new_ok_code SAP GUI
Basis services
GUI + control controller
ABAP application
Services (CFW)
PAI
Event handler
event fcode, ...
set_new_ok_code ok_code
Data transport
SAP AG 1999
If you handle a control event as a system event and want to pass control to the container screen after the event handling, you must use the method cl_gui_cfw=>set_new_ok_code.
You pass a new function code to the ok_code parameter of the method. The system places this in the Basis services, and when the event handling is finished, the PAI of the container screen is triggered with the new function code.
Note that the event handling takes place before any field transport, since the PAI is not triggered until after the event handling.
(C) SAP AG
BC412
89
2.90 Introduction to the Control Framework: Controls and program modularization
Overview Overview Controlsand andscreens screens Controls Changingthe the attributes attributes of ofaa control control Changing The automation automationqueue queue The Controlevents events Control Controlsand andprogram programmodularization modularization Controls
SAP AG 1999
(C) SAP AG
BC412
90
2.91 Modularization Used So Far
my_container
my_control
event_handler
100: Screen
loc. data Methods
Methods
Screen data
Transport calls
calls
calls
calls
sapbc412d_...: Program Application and auxiliary data
F1: FORM
Screen data
FY: FORM
M1: MODULE
MX: MODULE
calls
SAP AG 1999
The procedures we have just seen use event handler methods as a special kind of modularization unit that works similarly to a subroutine in ABAP. If you have encapsulated special functions in subroutines in your program, you will also have called these from the method. This is because the event handlers do not have any data themselves. If you use this method, you are only making restricted use of the possibility offered by object-oriented programming to encapsulate functions and data in instances.
Classes that provide event handlers in this way have no semantics.
(C) SAP AG
BC412
91
2.92 Other Modularization Possibilities my_container
my_control
Methods calls
calls 100: Screen
my_application: my_application: lcl_application
Application data Screen data
Methods, event_handler calls
calls Transport
sapbc412d_...: Program auxiliary data
calls
Screen data
M1: MODULE
MX: MODULE
SAP AG 1999
Another way of modularizing your program is to encapsulate the application data for the control within the event hander methods in a single instance. The class behind the instance then assumes its own semantics, and becomes reusable.
To do this, you need further knowledge of ABAP Objects. This knowledge is beyond the scope of the course. There is a separate course for this - BC404: ABAP Objects.
(C) SAP AG
BC412
92
2.93 Introduction to the Control Framework: Unit Summary
You are now able to: Describe how the SAP Control Framework works Display data in a SAP Picture Control and SAP HTML Viewer on a screen Changing the attributes of a control React to the events of a control Use selected ABAP Objects statements
SAP AG 1999
(C) SAP AG
BC412
93
2.94Introduction to the Control Framework Exercise 1 Unit: Introduction to the Control Framework Topic: Controls and screens
At the conclusion of this unit, you will be able to: Create custom control areas (that is, screen elements) in the Screen Painter Create and use reference variables for instances of ABAP Objects Create instances of container control and picture controls Assign container control instances to custom controls Link picture control instances with containers Find information on global classes in the Class Library in the Class Builder. You copy a template consisting of an ABAP program that calls a screen. The screen has one status, plus the standard navigation functions. After you have become familiar with the structure of the template, create a custom control area on the screen. You create a container instance that is linked to the custom control area, and an instance of a picture control that is assigned to the container. Program:
ZBC412_##_CFW_EX1
Template:SAPBC412_BAST_EXERCISE1 Model solution: SAPBC412_BASS_EXERCISE1 where ## is the group number 1-1
Copy the template SAPBC412_BAST_EXERCISE1 (including all its sub-objects) to the program ZBC412_##_CFW_EX1 and get to know the features of the program.
1-2
On screen 100, create a custom control area with the following attributes:
(C) SAP AG
Attribute
Value
Suggested value
Element type
Custom control
Name
CONTROL_AREA1 BC412
94
Row
Any
2
columns
Any
2
defLength/
Any
50
Height
Any
11
Resize
to
Rows (minimum)
Any
3
Columns (minimum)
Any
5
visLength
Activate the screen. 1-3
Create a container instance in a PBO module for screen 100: 1-3-1 Create a reference variable for the container instance (We suggest you use the name ref_tree). Use the global class type cl_gui_custom_container. 1-3-2 Screen 100 already has a PBO module init_control_processing. Extend this module so that the system generates a container control instance when it executes the program for the first time. Pass the name of the custom control area you created to the interface parameter container_name. Catch the generic exception, OTHERS, instead of evaluating each exception individually. When an exception occurs, make sure your program stops processing. To do this, use message 010 from message class BC412 (message type I).
1-4
Create a picture control instance. The source text you need is encapsulated in init_control_processing, the PBO module used in section 1-3-3 of this exercise. 1-4-1 Create a reference variable for the picture control instance (We suggest you use the name ref_picture). Use the global class type cl_gui_picture. 1-4-2 Extend the init_control_processing module so that the system generates a picture control instance when it executes the program for the first time. Pass your container control reference to the interface parameter parent. Catch the generic exception, OTHERS, instead of evaluating each exception individually. When an exception occurs, make sure your program stops processing. To do this, use message 011 from message class BC412 (message type A).
1-5
(C) SAP AG
Activate and test your program. If your program runs correctly, you will still see an empty screen (and an empty control area). If an error occurs, the system either displays a type A message or a runtime error occurs.
The message class BC412 has already been set globally for this program (see the REPORT statement).
The buttons that are displayed on the screen attached to BC412
95
the template do not yet have functions. Assigning these functions is part of a subsequent exercise in this unit.
(C) SAP AG
BC412
96
Exercise 2 Unit: Introduction to the Control Framework Topic: Changing the attributes of a control
At the conclusion of this unit, you will be able to: Change attributes of controls by calling methods Display data in the picture control
You will extend the program you wrote in the first exercise so that it displays a picture in your picture control instance. Use the Business Document Server (BDS) as your data source.
Program:
ZBC412_##_CFW_EX2
Template:SAPBC412_BAST_EXERCISE2 Model solution: SAPBC412_BASS_EXERCISE2 where ## is the group number
2-1
Copy the template SAPBC412_BAST_EXERCISE2 (including all its sub-objects) to the program ZBC412_##_CFW_EX2 or use your solution from the previous exercise.
2-2
To display a picture in a picture control instance, you need a URL pointing to the picture. Data objects used in this course that can be displayed in a picture control are stored in the BDS. Use them in your program. Use the function module BC412_BDS_GET_PIC_URL to create a valid URL for a picture in the BDS. 2-2-1 For the URL, create an ABAP field with type C, length 80, and suggested name 1_url. 2-2-2 Call the function module BC412_BDS_GET_PIC_URL. This function module encapsulates technical details for accessing the picture in the BDS. Fill the IMPORTING parameter NUMBER with a 1 (default value). The EXPORTING parameter URL returns a URL that is valid for the duration of the program. To make your program clearer, call the function module at the START-OF-SELECTION event, before you call screen 100.
(C) SAP AG
BC412
97
If the function module cannot return a valid URL, have the program terminate, using the LEAVE PROGRAM statement. 2-2-3 Now you have a URL pointing to a picture. Get the program to display this picture in your control instance, using the instance method load_picture_from_url from the class cl_gui_picture. Catch the generic exception, OTHERS, instead of evaluating each exception individually. When an exception occurs, make sure your program stops processing. To do this, use message 012 from message class BC412 (message type ). If you choose to receive the method to receive the EXPORTING parameter RESULT (ABAP type I) you can use the messages 013 and 014 (from message class BC412, message type S or I) to tell the user whether or not the picture could be loaded successfully. The meaning of the value returned by the result parameter is: 1 = Picture loaded successfully, 0 = System could not load picture
(C) SAP AG
BC412
98
Exercise 3 Unit: Introduction to the Control Framework Topic: Changing the attributes of a control
At the conclusion of this unit, you will be able to: Destroy control instances at the front end Release reference variables to proxy objects Change attributes of a control by calling methods (controlled by pushbuttons on a screen) You extend the model solution from the previous exercise to destroy all frontend instances before the program ends in all cases. Make sure that the user can also specify how the picture appears in the control using buttons on the screen.
Program:
ZBC412_##_CFW_EX3
Template:SAPBC412_BAST_EXERCISE3 Model solution: SAPBC412_BASS_EXERCISE3 where ## is the group number 3-1
Copy the template SAPBC412_BAST_EXERCISE3 (including all its sub-objects) to the program ZBC412_##_CFW_EX3 or use your solution from the previous exercise.
3-2
Make sure that your control instances at the front end are destroyed before the program ends, by implementing the free_control_ressources subroutine. In addition, call the instance method free and release the ABAP reference variables. Note: You have already added the call statement and created the subroutine interface.
3-3
Make sure that users can specify how the picture control instance is to be displayed, using buttons on screen 100. 3-3-1 Implement the functions 'STRETCH', 'NORMAL', 'NORMAL_CENTER', 'FIT', and 'FIT_CENTER', defined by the pushbuttons. These functions are already implemented in the PAI module user_command_0100. To do this, use the instance method set_display_mode in the class cl_gui_picture. If an exception occurs while the program is running,
(C) SAP AG
BC412
99
make the system display the message 015 from the message class BC412 (message type S or I). 3-3-2 Test the mode in which the control displays the picture by resizing the window on the subscreen container. To fill the interface parameter display_mode of the set_display_mode method, use the class constants: display_mode_stretch, display_mode_normal, display_mode_normal_center, display_mode_fit and display_mode_fit_center der Klasse cl_gui_picture. Access them using cl_gui_picture=>display_mode_fit.
(C) SAP AG
BC412
100
Exercise 3 (Optional Sections) At the conclusion of these optional exercises, you will be able to: Ascertain the attributes of a frontend control (read access)
You let users show the current display mode for the picture control.
Program:
same program
Template: as above Model solution: SAPBC412_BASS_EXERCISE3A
3-4
Extend container screen 100 by adding a button, which – when clicked – displays the current display mode for the picture control, as a technical value, in a separate dialog box. 3-4-1 On screen 100, create a pushbutton with the following attributes: Attribute
Value
Suggested value
Element type
Pushbutton
Name
Any
BUT6
Text
Any
Query mode
Icon
Any
ICON_INFORMATION
FktCode
MODE_INFO
FktTyp
' ' ()
3-4-2 Implement the associated function (function code MODE_INFO) in the module user_command_0100. Read the attribute display_mode for your picture control proxy instance and save the result in an ABAP field (suggested name: current_mode). Declare the data object in the data declaration part of your program and assign a type to the variable using cl_gui_picture=>display_mode. Display the content of your data object (current_mode) using the message 025 (message class bc412, message type I).
(C) SAP AG
BC412
101
Exercise 4 Unit: Introduction to the Control Framework Topic: Control Events
At the conclusion of this exercise, you will be able to: Define and implement a static method of a local class as an event handler Register a static handler method to an ABAP Objects event Register control events with the Control Framework Find information on control events in the ABAP Workbench You should make it possible for your user to ascertain the coordinates of a point in a picture by clicking it. Implement this using a control event.
Program:
ZBC412_##_CFW_EX4
Template:SAPBC412_BAST_EXERCISE4 Model solution: SAPBC412_BASS_EXERCISE4 where ## is the group number 4-1
Copy the template SAPBC412_BAST_EXERCISE4 (including all its sub-objects) to the program ZBC412_##_CFW_EX4 or use your solution from the previous exercise.
4-2
In your program, create a local class that contains a method for handling the PICTURE_CLICK event for your picture control instance. 4-2-1 Open the Class Builder and find out about the interface to the PICTURE_CLICK event in the cl_gui_picture class. 4-2-2 In the declaration part of your program, define a local class (suggested name: lcl_event_handler). 4-2-3 The local class should contain a public, static method, which the system will use as an event-handling method. Using the CLASS-METHODS statement, define a method for handling the PICTURE_CLICK event in the cl_gui_picture class
(C) SAP AG
BC412
102
(suggested name: on_picture_click). Define the method interface so that the event passes the coordinates of the point clicked to the method. 4-2-4 Implement the method in the implementation part of the class. Display the coordinates from the event using the message 016 (message class bc412, message type I). 4-3
You have now created a static method to handle the PICTURE_CLICK event of your proxy instance for the picture control instance. Register this method with the proxy instance. 4-3-1 Extend the PBO module init_control_processing using the SET HANDLER statement by registering the static method for the event of your picture control instance.
4-4
Register the control event PICTURE_CLICK of your control instance with the Control Framework. 4-4-1 In the declaration part of your program, create two more data objects: – An internal table, used to pass the events (which are to be registered with the CFW) to the instance method set_registered_events of the cl_gui_picture class. (We suggest the name: it_events). – A work area, which you will need to fill the internal table (suggested name: wa_events). 4-4-2 Assign a type to the internal table using cntl_simple_event (that is, the type of an internal table, type declaration in the type group CNTL). Assign a type to the work area that gives it the same line type as the internal table. Include the type group in your program. 4-4-3 In the Class Builder, find out more about the names of the class constants for control events ( event_ids), since you will need them to register events with the Control Framework. 4-4-4 Fill the internal table with data for the PICTURE_CLICK event. Register the event with the CFW using the instance method set_registered_events by extending the PBO module init_control_processing. Note: Call the instance method set_registered_events for your picture control instance.
4-5
Test your program.
You can access the class constants using cl_gui_picture=>eventid_picture_click.
(C) SAP AG
BC412
103
Exercise 4 (Optional Sections) At the conclusion of this unit, you will be able to: Define and implement a static method of a class as an event handler Register a static handler method for an ABAP Objects event Register control events with the Control Framework Find information on control events in the ABAP Workbench The user should be able to ascertain the coordinates of a point that is in the control area but not in the picture, by clicking the control area. Use another control event to implement this.
Program:
as above
Template: as above Model solution: SAPBC412_BASS_EXERCISE4A
4-6
Extend your program so that if users double-clicks the control area outside the picture, the program displays the cursor coordinates. To do this, use the CONTROL_DBLCLICK event. Proceed as for steps 4-2 to 4-4 in exercise 4, for the new event.
(C) SAP AG
Use the same local class. Add another public static method to handle CONTROL_DBLCLICK events of your picture control instance.
Use message 017 from message class BC412 (message type ) to react to the event.
BC412
104
2.95Note on the Sample Solutions for Unit 02 The sample solutions provided include the statements of the screen flow logic and of the ABAP program parts required in the sample solution. The exercises of this chapter are sequential so that you extend the program step by step based on the content of each chapter. For better clarity, we did not include the complete source code for each sample solution. Instead, we have applied the following principles:
(C) SAP AG
The sample solution of the first task is printed completely.
All subsequent sample solutions that are based on this first one only contain changed or new flow logic, subroutines or modules. The statements you need to add in each case in order to solve the task are printed in bold.
After the sample solution for the last exercise of this chapter (Exercise 4), you find a complete version of the program developed during the exercises.
BC412
105
2.96Introduction to the Control Framework Solutions to Exercise 1 Unit: Introduction to the Control Framework Topic: Controls and Screens
Model solution SAPBC412_BASS_EXERCISE1 3Screen flow logic 4SCREEN 100 PROCESS BEFORE OUTPUT. MODULE status_0100. MODULE init_control_processing. PROCESS AFTER INPUT. MODULE exit_command_0100 AT EXIT-COMMAND. MODULE user_command_0100.
5ABAP program 6Data declarations *&-----------------------------------------------------------------* *& Report
SAPBC412_BASS_EXERCISE1
*
*&
*
*&-----------------------------------------------------------------* REPORT
sapbc412_bass_exercise1 MESSAGE-ID bc412.
* data declarations *
screen specific
DATA: ok_code
TYPE sy-ucomm,
" command field
copy_ok_code LIKE ok_code,
" copy of ok_code
l_answer
" return flag (used in
TYPE c,
" standard user dialogs) *
control specific: object references
(C) SAP AG
BC412
106
ref_container TYPE REF TO cl_gui_custom_container, ref_picture
(C) SAP AG
TYPE REF TO cl_gui_picture,
BC412
107
6.2Main ABAP Program: Event Blocks * start of main program START-OF-SELECTION. CALL SCREEN 100.
" container screen for SAP-Enjoy " controls
* end of main program
6.3Modules *&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* * Implementation of EnjoySAP control processing: * 1) create container object and link to screen area *
2)
create picture object and link to container
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
" prevent re-processing on ENTER
create container object and link to screen area CREATE OBJECT ref_container EXPORTING container_name = 'CONTROL_AREA1' EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a010.
" cancel program processing
ENDIF. *
create picture control and link to container object CREATE OBJECT ref_picture EXPORTING parent = ref_container EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a011.
" cancel program processing
ENDIF. (C) SAP AG
BC412
108
ENDIF. ENDMODULE.
(C) SAP AG
" INIT_CONTROL_PROCESSING
BC412
OUTPUT
109
*&-----------------------------------------------------------------* *&
Module
USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
Implementation of user commands of type ' ':
*
- push buttons on the screen
*
- GUI functions
*------------------------------------------------------------------* MODULE user_command_0100 INPUT. copy_ok_code = ok_code. CLEAR ok_code. CASE copy_ok_code. WHEN 'BACK'. CLEAR l_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING *
DEFAULTOPTION
= 'Y'
textline1
= text-004
textline2
= text-005
titel
= text-007
cancel_display = ' ' IMPORTING answer
= l_answer.
CASE l_answer. WHEN 'J'. PERFORM free_control_ressources. LEAVE TO SCREEN 0. WHEN 'N'. SET SCREEN sy-dynnr. ENDCASE. WHEN 'STRETCH'. *
to be implemented later WHEN 'NORMAL'.
*
" picture operation: center normal size
to be implemented later WHEN 'FIT'.
*
" picture operation: fit to normal size
to be implemented later WHEN 'NORMAL_CENTER'.
*
" picture operation: stretch to fit area
" picture operation: zoom picture
to be implemented later
(C) SAP AG
BC412
110
WHEN 'FIT_CENTER'. *
" picture operation: zoom and center
to be implemented later ENDCASE.
ENDMODULE.
" USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *&
Module
STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *
Set GUI for screen 0100
*------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'STATUS_NORM_0100'. SET TITLEBAR 'TITLE_NORM_0100'. ENDMODULE.
" STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *&
Module
EXIT_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
Implementation of user commands of type 'E'.
*------------------------------------------------------------------* MODULE exit_command_0100 INPUT. CASE ok_code. WHEN 'CANCEL'.
" cancel current screen processing
CLEAR l_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING *
DEFAULTOPTION
= 'Y'
textline1
= text-004
textline2
= text-005
titel
= text-006
cancel_display = ' ' IMPORTING answer
= l_answer.
CASE l_answer. WHEN 'J'. PERFORM free_control_ressources. LEAVE TO SCREEN 0. WHEN 'N'. (C) SAP AG
BC412
111
CLEAR ok_code. SET SCREEN sy-dynnr. ENDCASE. WHEN 'EXIT'.
" leave program
CLEAR l_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING *
DEFAULTOPTION
= 'Y'
textline1
= text-001
textline2
= text-002
titel
= text-003
cancel_display = 'X' IMPORTING answer
= l_answer.
CASE l_answer. WHEN 'J' OR 'N'.
" no data to update
PERFORM free_control_ressources. LEAVE PROGRAM. WHEN 'A'. CLEAR ok_code. SET SCREEN sy-dynnr. ENDCASE. ENDCASE. ENDMODULE.
(C) SAP AG
" EXIT_COMMAND_0100
BC412
INPUT
112
6.4Subroutines *&-----------------------------------------------------------------* *&
Form
free_control_ressources
*&-----------------------------------------------------------------* *
Here you should implement: Free all control related
*
ressources.
*------------------------------------------------------------------* *
no interface
*------------------------------------------------------------------* FORM free_control_ressources. * to be implemented later ENDFORM.
(C) SAP AG
" free_control_ressources
BC412
113
Solution to Exercise 2 Unit: Introduction to the Control Framework Topic: Changing the attributes of a control
Model solution SAPBC412_BASS_EXERCISE2
7ABAP program 7.2Data declarations *&-----------------------------------------------------------------* *& Report
SAPBC412_BASS_EXERCISE2
*
*&
*
*&-----------------------------------------------------------------* REPORT
sapbc412_bass_exercise2 MESSAGE-ID bc412.
* data declarations *
screen specific
DATA: ok_code
TYPE sy-ucomm,
" command field
copy_ok_code LIKE ok_code,
" copy of ok_code
l_answer
" return flag (used in
TYPE c,
" standard user dialogs) *
control specific: object references ref_container TYPE REF TO cl_gui_custom_container, ref_picture
*
TYPE REF TO cl_gui_picture,
control specific: auxiliary fields l_url(80)
TYPE c,
" URL of picture to be shown
l_result
TYPE i value 1.
" status variable of load_picture
..................................." 1 = o.k., 0 = error
(C) SAP AG
BC412
114
7.3Main ABAP Program: Event Blocks * start of main program START-OF-SELECTION.
7.3.2 CALL FUNCTION 'BC412_BDS_GET_PIC_URL'" fetch URL of first picture * EXPORTING *
" from BDS
NUMBER
= 1
IMPORTING url
= l_url
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0.
" no picture --> end of program
LEAVE PROGRAM. ENDIF. CALL SCREEN 100.
" container screen for SAP-Enjoy " controls
* end of main program
7.4Modules *&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
Implementation of EnjoySAP control processing:
*
1)
create container object and link to screen area
*
2)
create picture object and link to container
*
3)
load picture into picture control
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
" prevent re-processing on ENTER
create container object and link to screen area CREATE OBJECT ref_container EXPORTING container_name = 'CONTROL_AREA1' EXCEPTIONS others = 1.
(C) SAP AG
BC412
115
IF sy-subrc NE 0. MESSAGE a010.
" cancel program processing
ENDIF. *
create picture control and link to container object CREATE OBJECT ref_picture EXPORTING parent = ref_container EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a011.
" cancel programn processing
ENDIF.
*
load picture into picture control CALL METHOD ref_picture->load_picture_from_url EXPORTING url
= l_url
IMPORTING result = l_result EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF. CASE l_result. WHEN 0.
" picture not loaded
MESSAGE s013. WHEN 1.
" load of picture successful
MESSAGE s014. ENDCASE. ENDIF. ENDMODULE.
(C) SAP AG
" INIT_CONTROL_PROCESSING
BC412
OUTPUT
116
Solution to Exercise 3 Unit: Introduction to the Control Framework Topic: Changing the attributes of a control
Model solution SAPBC412_BASS_EXERCISE3
8ABAP program 8.2Modules *&-----------------------------------------------------------------* *&
Module
USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
Implementation of user commands of type ' ':
*
- push buttons on screen 100
*
- GUI functions
*------------------------------------------------------------------* MODULE user_command_0100 INPUT. copy_ok_code = ok_code. CLEAR ok_code. CASE copy_ok_code. WHEN 'BACK'.
" back to program, leave screen
CLEAR l_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING *
DEFAULTOPTION
= 'Y'
textline1
= text-004
textline2
= text-005
titel
= text-007
cancel_display = ' ' IMPORTING answer
= l_answer.
CASE l_answer. WHEN 'J'. PERFORM free_control_ressources. LEAVE TO SCREEN 0. (C) SAP AG
BC412
117
WHEN 'N'. SET SCREEN sy-dynnr. ENDCASE.
(C) SAP AG
BC412
118
WHEN 'STRETCH'.
" picture operation: stretch to fit area
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_stretch EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'NORMAL'. " picture operation: fit to normal size CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_normal EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'NORMAL_CENTER'.
" picture operation: center normal size
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_normal_center EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'FIT'.
" picture operation: zoom picture
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_fit EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'FIT_CENTER'. (C) SAP AG
" picture operation: zoom and center BC412
119
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_fit_center EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. ENDCASE. ENDMODULE.
(C) SAP AG
" USER_COMMAND_0100
BC412
INPUT
120
8.3Subroutines *&-----------------------------------------------------------------* *&
Form
free_control_ressources
*&-----------------------------------------------------------------* *
Free all control related ressources.
*------------------------------------------------------------------* *
no interface
*------------------------------------------------------------------* FORM free_control_ressources. CALL METHOD ref_picture->free. CALL METHOD ref_container->free. FREE: ref_picture, ref_container. ENDFORM.
(C) SAP AG
" free_control_ressources
BC412
121
Solution to Exercise 3: Optional Sections Unit: Introduction to the Control Framework Topic: Changing the attributes of a control
Model solution SAPBC412_BASS_EXERCISE3A
9ABAP program 9.2Data declarations *&-----------------------------------------------------------------* *& Report
SAPBC412_BASS_EXERCISE3A
*
*&
*
*&-----------------------------------------------------------------* REPORT
sapbc412_bass_exercise3a MESSAGE-ID bc412.
* data declarations *
screen specific
DATA: ok_code
TYPE sy-ucomm,
" command field
copy_ok_code LIKE ok_code,
" copy of ok_code
l_answer
" return flag (used in
TYPE c,
" standard user dialogs) *
control specific: object references ref_container TYPE REF TO cl_gui_custom_container, ref_picture
*
TYPE REF TO cl_gui_picture,
control specific: auxiliary fields l_url(80)
TYPE c,
" URL of picture to be shown
l_result
TYPE i value 1,
" status variable of load_picture " 1 = o.k., 0 = error
current_mode
(C) SAP AG
LIKE cl_gui_picture=>display_mode.
BC412
122
9.3Modules *&-----------------------------------------------------------------* *&
Module
USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
Implementation of user commands of type ' ':
*
- push buttons on screen 100
*
- GUI functions
*------------------------------------------------------------------* MODULE user_command_0100 INPUT. copy_ok_code = ok_code. CLEAR ok_code. CASE copy_ok_code. WHEN 'BACK'.
" back to program, leave screen
CLEAR l_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING *
DEFAULTOPTION
= 'Y'
textline1
= text-004
textline2
= text-005
titel
= text-007
cancel_display = ' ' IMPORTING answer
= l_answer.
CASE l_answer. WHEN 'J'. PERFORM free_control_ressources. LEAVE TO SCREEN 0. WHEN 'N'. SET SCREEN sy-dynnr. ENDCASE. WHEN 'STRETCH'.
" picture operation: stretch to fit area
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_stretch EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. (C) SAP AG
BC412
123
MESSAGE s015. ENDIF. WHEN 'NORMAL'.
" picture operation: fit normal size
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_normal EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF.
(C) SAP AG
BC412
124
WHEN 'NORMAL_CENTER'.
" picture operation: center normal size
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_normal_center EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'FIT'.
" picture operation: zoom picture
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_fit EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'FIT_CENTER'.
" picture operation: zoom and center
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_fit_center EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'MODE_INFO'. current_mode = ref_picture->display_mode. MESSAGE i025 WITH current_mode. ENDCASE. ENDMODULE.
(C) SAP AG
" USER_COMMAND_0100
BC412
INPUT
125
Solution to Exercise 4 Unit: Introduction to the Control Framework Topic: Control Events
Model solution SAPBC412_BASS_EXERCISE4 10ABAP program 10.2Local Classes
REPORT sapbc412_bass_exercise4 MESSAGE-ID bc412. *------------------------------------------------------------------* *
CLASS lcl_event_handler DEFINITION
*------------------------------------------------------------------* *
Definition of a local class containing event handler
*
*
methods for picture control objects
*
*------------------------------------------------------------------* CLASS lcl_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_picture_click FOR EVENT picture_click OF cl_gui_picture IMPORTING mouse_pos_x mouse_pos_y. ENDCLASS. *------------------------------------------------------------------* *
CLASS lcl_event_handler IMPLEMENTATION
*------------------------------------------------------------------* *
Corresponding class implementation
*
*------------------------------------------------------------------* CLASS lcl_event_handler IMPLEMENTATION. METHOD on_picture_click. MESSAGE i016 WITH mouse_pos_x mouse_pos_y. ENDMETHOD. ENDCLASS.
(C) SAP AG
BC412
126
10.3Data declarations * global types: Type Pool TYPE_POOLS: cntl. * data declarations *
screen specific
DATA: ok_code
TYPE sy-ucomm,
" command field
copy_ok_code LIKE ok_code,
" copy of ok_code
l_answer
" return flag (used in
TYPE c,
" standard user dialogs) *
control specific: object references ref_container TYPE REF TO cl_gui_custom_container, ref_picture
*
TYPE REF TO cl_gui_picture,
control specific: auxiliary fields l_url(80)
TYPE c,
" URL of picture to be shown
l_result
TYPE i value 1,
" status variable of load_picture
..................................." 1 = o.k., 0 = error current_mode *
LIKE cl_gui_picture=>display_mode,
event handling it_events
TYPE cntl_simple_events, " internal (event) table
wa_events
LIKE LINE OF it_events.
" work area
10.4Modules *&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
Implementation of EnjoySAP control processing:
*
1)
create container object and link to screen area
*
2)
create picture object and link to container
*
3)
load picture into picture control
*
4)
event handling
*
a) register event PICTURE_CLICK at CFW
*
b) register event handler method ON_PICTURE_CLICK
*
for the picture control object
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. (C) SAP AG
" prevent re-processing on ENTER BC412
127
*
create container object and link to screen area CREATE OBJECT ref_container EXPORTING container_name = 'CONTROL_AREA1' EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a010.
" cancel program processing
ENDIF.
(C) SAP AG
BC412
128
*
create picture control and link to container object CREATE OBJECT ref_picture EXPORTING parent = ref_container EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a011.
" cancel program processing
ENDIF. *
load picture into picture control CALL METHOD ref_picture->load_picture_from_url EXPORTING url
= l_url
IMPORTING result = l_result EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF. CASE l_result. WHEN 0.
" picture not loaded
MESSAGE s013. WHEN 1.
" load of picture successful
MESSAGE s014. ENDCASE. *
event handling
*
1. register events for control framework wa_events-eventid
= cl_gui_picture=>eventid_picture_click.
wa_events-appl_event = ' '. INSERT wa_events INTO TABLE it_events. CALL METHOD ref_picture->set_registered_events EXPORTING events = it_events (C) SAP AG
BC412
129
EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF. *
2. set event handler for ABAP object instance: ref_picture SET HANDLER lcl_event_handler=>on_picture_click FOR ref_picture. ENDIF.
ENDMODULE.
(C) SAP AG
" INIT_CONTROL_PROCESSING
BC412
OUTPUT
130
Solution to Exercise 4: Optional Sections Unit: Introduction to the Control Framework Topic: Control Events
Model solution SAPBC412_BASS_EXERCISE4A
11ABAP program 11.2Local Classes REPORT
sapbc412_bass_exercise4a MESSAGE-ID bc412.
*------------------------------------------------------------------* *
CLASS lcl_event_handler DEFINITION
*------------------------------------------------------------------* *
Definition of a local class containing event handler
*
*
methods for picture control objects
*
*------------------------------------------------------------------* CLASS lcl_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_picture_click FOR EVENT picture_click OF cl_gui_picture IMPORTING mouse_pos_x mouse_pos_y, *
-------------------------------------------------------------on_control_dblclick FOR EVENT control_dblclick OF cl_gui_picture IMPORTING mouse_pos_x mouse_pos_y.
ENDCLASS. *------------------------------------------------------------------* *
CLASS lcl_event_handler IMPLEMENTATION
*------------------------------------------------------------------* *
Corresponding class implementation
*
*------------------------------------------------------------------* CLASS lcl_event_handler IMPLEMENTATION. METHOD on_picture_click. MESSAGE i016 WITH mouse_pos_x mouse_pos_y. (C) SAP AG
BC412
131
ENDMETHOD. METHOD on_control_dblclick. MESSAGE i017 WITH mouse_pos_x mouse_pos_y. ENDMETHOD. ENDCLASS.
11.3Modules *&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
Implementation of EnjoySAP control processing:
*
1)
create container object and link to screen area
*
2)
create picture object and link to container
*
3)
load picture into picture control
*
4)
event handling
*
a1) register event PICTURE_CLICK at CFW
*
a2) register event CONTROL_DBLCLICK at CFW
*
b1) register event handler method ON_PICTURE_CLICK
*
for the picture control object
*
b2) register event handler method ON_CONTROL_DBLCLICK
*
for the picture control object
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
" prevent re-processing on ENTER
create container object and link to screen area CREATE OBJECT ref_container EXPORTING container_name = 'CONTROL_AREA1' EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a010.
(C) SAP AG
" cancel program processing BC412
132
ENDIF. *
create picture control and link to container object CREATE OBJECT ref_picture EXPORTING parent = ref_container EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a011.
" cancel program processing
ENDIF. *
load picture into picture control CALL METHOD ref_picture->load_picture_from_url EXPORTING url
= l_url
IMPORTING result = l_result EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF.
(C) SAP AG
BC412
133
CASE l_result. WHEN 0.
" picture not loaded
MESSAGE s013. WHEN 1.
" load of picture successful
MESSAGE s014. ENDCASE. *
event handling
*
1. register events for control framework wa_events-eventid
= cl_gui_picture=>eventid_picture_click.
wa_events-appl_event = ' '. INSERT wa_events INTO TABLE it_events. wa_events-eventid
= cl_gui_picture=>eventid_control_dblclick.
wa_events-appl_event = ' '. INSERT wa_events INTO TABLE it_events.
CALL METHOD ref_picture->set_registered_events EXPORTING events = it_events EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF. *
2. set event handler for ABAP object instance: ref_picture SET HANDLER lcl_event_handler=>on_picture_click FOR ref_picture. SET HANDLER lcl_event_handler=>on_control_dblclick FOR ref_picture. ENDIF.
ENDMODULE.
(C) SAP AG
" INIT_CONTROL_PROCESSING
BC412
OUTPUT
134
Complete Solution to Exercises Unit: Introduction to the Control Framework
Model solution SAPBC412_BASS_EXERCISE 12Screen flow logic 12.2SCREEN 0100 PROCESS BEFORE OUTPUT. MODULE status_0100. MODULE init_control_processing. PROCESS AFTER INPUT. MODULE exit_command_0100 AT EXIT-COMMAND. MODULE user_command_0100.
13ABAP program 13.2Local Classes *&-----------------------------------------------------------------* *& Report SAPBC412_BASS_EXERCISE * *& * *&-----------------------------------------------------------------* REPORT
sapbc412_bass_exercise MESSAGE-ID bc412.
*------------------------------------------------------------------* *
CLASS lcl_event_handler DEFINITION
*------------------------------------------------------------------* *
Definition of a local class containing event handler
*
*
methods for picture control objects
*
*-----------------------------------------------------_------------* CLASS lcl_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_picture_click (C) SAP AG
BC412
135
FOR EVENT picture_click OF cl_gui_picture IMPORTING mouse_pos_x mouse_pos_y, *
-------------------------------------------------------------on_control_dblclick FOR EVENT control_dblclick OF cl_gui_picture IMPORTING mouse_pos_x mouse_pos_y.
ENDCLASS.
(C) SAP AG
BC412
136
*------------------------------------------------------------------* *
CLASS lcl_event_handler IMPLEMENTATION
*------------------------------------------------------------------* *
Corresponding class implementation
*
*------------------------------------------------------------------* CLASS lcl_event_handler IMPLEMENTATION. METHOD on_picture_click. MESSAGE i016 WITH mouse_pos_x mouse_pos_y. ENDMETHOD. METHOD on_control_dblclick. MESSAGE i017 WITH mouse_pos_x mouse_pos_y. ENDMETHOD. ENDCLASS.
13.3Data declarations * global types: Type Pool TYPE-POOLS: cntl. * data declarations *
screen specific
DATA: ok_code
TYPE sy-ucomm,
" command field
copy_ok_code LIKE ok_code,
" copy of ok_code
l_answer
" return flag (used in
TYPE c,
" standard user dialogs) *
control specific: object references ref_container TYPE REF TO cl_gui_custom_container, ref_picture
*
TYPE REF TO cl_gui_picture,
control specific: auxiliary fields l_url(80)
TYPE c,
" URL of picture to be shown
l_result
TYPE i value 1,
" status variable of load_picture " 1 = o.k., 0 = error
current_mode *
LIKE cl_gui_picture=>display_mode,
event handling it_events
TYPE cntl_simple_events, " internal (event) table
wa_events
LIKE LINE OF it_events.
(C) SAP AG
BC412
" work area
137
13.4Main ABAP Program: Event Blocks * start of main program START-OF-SELECTION. CALL FUNCTION 'BC412_BDS_GET_PIC_URL'" fetch URL of first picture *
EXPORTING
*
" from BDS
NUMBER
= 1
IMPORTING url
= l_url
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0.
" no picture --> end of program
LEAVE PROGRAM. ENDIF. CALL SCREEN 100.
" container screen for SAP-Enjoy " controls
* end of main program
13.5Modules *&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
Implementation of EnjoySAP control processing:
*
1)
create container object and link to screen area
*
2)
create picture object and link to container
*
3)
load picture into picture control
*
4)
event handling
*
a1) register event PICTURE_CLICK at CFW
*
a2) register event CONTROL_DBLCLICK at CFW
*
b1) register event handler method ON_PICTURE_CLICK
*
for the picture control object
*
b2) register event handler method ON_CONTROL_DBLCLICK
*
for the picture control object
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
" prevent re-processing on ENTER
create container object and link to screen area CREATE OBJECT ref_container
(C) SAP AG
BC412
138
EXPORTING container_name = 'CONTROL_AREA1' EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a010.
" cancel program processing
ENDIF.
(C) SAP AG
BC412
139
*
create picture control and link to container object CREATE OBJECT ref_picture EXPORTING parent = ref_container EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a011.
" cancel program processing
ENDIF. *
load picture into picture control CALL METHOD ref_picture->load_picture_from_url EXPORTING url
= l_url
IMPORTING result = l_result EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF. CASE l_result. WHEN 0.
" picture not loaded
MESSAGE s013. WHEN 1.
" load of picture successful
MESSAGE s014. ENDCASE. *
event handling
*
1. register events for control framework wa_events-eventid
= cl_gui_picture=>eventid_picture_click.
wa_events-appl_event = ' '. INSERT wa_events INTO TABLE it_events. wa_events-eventid
= cl_gui_picture=>eventid_control_dblclick.
wa_events-appl_event = ' '. INSERT wa_events INTO TABLE it_events. (C) SAP AG
BC412
140
CALL METHOD ref_picture->set_registered_events EXPORTING events = it_events EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF.
(C) SAP AG
BC412
141
*
2. set event handler for ABAP object instance: ref_picture SET HANDLER lcl_event_handler=>on_picture_click FOR ref_picture. SET HANDLER lcl_event_handler=>on_control_dblclick FOR ref_picture. ENDIF.
ENDMODULE.
" INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *&
Module
USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
Implementation of user commands of type ' ':
*
- push buttons on screen 100
*
- GUI functions
*------------------------------------------------------------------* MODULE user_command_0100 INPUT. copy_ok_code = ok_code. CLEAR ok_code. CASE copy_ok_code. WHEN 'BACK'.
" back to program, leave screen
CLEAR l_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING *
DEFAULTOPTION
= 'Y'
textline1
= text-004
textline2
= text-005
titel
= text-007
cancel_display = ' ' IMPORTING answer
= l_answer.
CASE l_answer. WHEN 'J'. PERFORM free_control_ressources. LEAVE TO SCREEN 0. WHEN 'N'. (C) SAP AG
BC412
142
SET SCREEN sy-dynnr. ENDCASE. WHEN 'STRETCH'.
" picture operation: stretch to fit area
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_stretch EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF.
(C) SAP AG
BC412
143
WHEN 'NORMAL'.
" picture operation: fit normal size
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_normal EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'NORMAL_CENTER'.
" picture operation: center normal size
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_normal_center EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'FIT'.
" picture operation: zoom picture
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_fit EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'FIT_CENTER'.
" picture operation: zoom and center
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_fit_center EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF.
(C) SAP AG
BC412
144
WHEN 'MODE_INFO'. current_mode = ref_picture->display_mode. MESSAGE i025 WITH current_mode. ENDCASE. ENDMODULE.
" USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *&
Module
STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *
Set GUI for screen 0100
*------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'STATUS_NORM_0100'. SET TITLEBAR
'TITLE_NORM_0100'.
ENDMODULE.
" STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *&
Module
EXIT_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
Implementation of user commands of type 'E'.
*------------------------------------------------------------------* MODULE exit_command_0100 INPUT. CASE ok_code. WHEN 'CANCEL'.
" cancel current screen processing
CLEAR l_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING *
DEFAULTOPTION
= 'Y'
textline1
= text-004
textline2
= text-005
titel
= text-006
cancel_display = ' ' IMPORTING answer
= l_answer.
CASE l_answer. WHEN 'J'. PERFORM free_control_ressources. LEAVE TO SCREEN 0. WHEN 'N'. (C) SAP AG
BC412
145
CLEAR ok_code. SET SCREEN sy-dynnr. ENDCASE. WHEN 'EXIT'.
" leave program
CLEAR l_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING *
DEFAULTOPTION
= 'Y'
textline1
= text-001
textline2
= text-002
titel
= text-003
cancel_display = 'X' IMPORTING answer
= l_answer.
CASE l_answer. WHEN 'J' OR 'N'.
" no data to update
PERFORM free_control_ressources. LEAVE PROGRAM. WHEN 'A'. CLEAR ok_code. SET SCREEN sy-dynnr. ENDCASE. ENDCASE. ENDMODULE.
(C) SAP AG
" EXIT_COMMAND_0100
BC412
INPUT
146
13.6Subroutines *&-----------------------------------------------------------------* *&
Form
free_control_ressources
*&-----------------------------------------------------------------* *
Free all control related ressources.
*------------------------------------------------------------------* *
no interface
*------------------------------------------------------------------* FORM free_control_ressources. CALL METHOD ref_picture->free. CALL METHOD ref_container->free. FREE: ref_picture, ref_container. ENDFORM.
(C) SAP AG
" free_control_ressources
BC412
147
14 SAP Container
Contents: The SAP container concept SAP Custom Container Control SAP Dialog Box Container Control SAP Docking Container Control SAP Splitter Control SAP Easy Splitter Control
SAP AG 1999
(C) SAP AG
BC412
1
14.2 SAP Container: Unit Objectives
At the conclusion of this unit, you will be able to: Explain how SAP containers work in the Control Framework List the container controls that you can use in the SAP System Describe the features of each of the container controls Use SAP container controls
SAP AG 1999
(C) SAP AG
BC412
2
14.3 Overview Diagram BC412
Course Overview
Unit 1
Unit 2
Introduction to the Control Framework
Unit 3
SAP Container
Unit 4
SAP Tree Control
Unit 5
ALV Grid Control
SAP AG 1999
(C) SAP AG
BC412
3
14.4 SAP Container Overview: The Container Concept
Thecontainer containerconcept concept The SAPCustom CustomContainer ContainerControl Control SAP SAPDialog DialogBox BoxContainer ContainerControl Control SAP SAPDocking DockingContainer ContainerControl Control SAP SAPSplitter SplitterContainer ContainerControl Control SAP SAPEasy EasySplitter SplitterContainer ContainerControl Control SAP
SAP AG 1999
(C) SAP AG
BC412
4
14.5 Uses for Containers
Container control
Container control
or EnjoySAP control
Container control
SAP AG 1999
A SAP container is a control that can accomodate other controls, such as the SAP Tree Control, SAP Picture Control, or the SAP Textedit Control. It maintains the controls in a logical collection, and provides an area in which they can be displayed.
Each control lives in a container. Since containers are themselves controls, you can nest them.
Controls within a container are usually displayed in the size of the container itself.
(C) SAP AG
BC412
5
14.6 SAP Container Classes
cl_gui_control cl_gui_container cl_gui_custom_container cl_gui_dialogbox_container cl_gui_docking_container cl_gui_splitter_container cl_gui_easy_splitter_container
Passes to
SAP AG 1999
Containers are known as the 'parent' of the control that they contain.
All SAP containers have a shared parent class with the type cl_gui_control. They are derived from this basic container and thus have a uniform object-oriented interface.
There are five different SAP Containers: SAP Custom Container (global class cl_gui_custom_container) SAP Dialog Box Container (global class cl_gui_dialogbox_container) SAP Docking Container (global class cl_gui_docking_container) SAP Splitter Container (global class cl_gui_splitter_container) SAP Easy Splitter Container (global class cl_gui_easy_splitter_container)
(C) SAP AG
BC412
6
14.7 Graphical Visualization of Containers
Custom control area
SAP Custom Container
Screen
SAP Dialog Box Container SAP Docking Container
Container
SAP Splitter Container SAP Easy Splitter Container
SAP AG 1999
You can assign an SAP container to An area on a screen (SAP Custom Container) A entire screen (SAP Docking Container, SAP Dialog Box Container) Another container (SAP Splitter Container, SAP Easy Splitter Container)
The fact that you can nest controls provides further display possibilities.
(C) SAP AG
BC412
7
14.8 Dialog Box Level and Top-Level Container
300 200 100
Dialog box level 2 Dialog box level 1 Dialog box level 0
Frontend Appl. server
Top level container
Call sequence in program
SCREEN9
SET/CALL SCREEN 100. CALL SCREEN 200 STARTING AT x1 y1.
SCREEN2 SCREEN1
CALL SCREEN 300 STARTING AT x2 y2.
SCREEN0
SAP AG 1999
When you create an instance of a SAP container, you assign it to a dialog box level, which you cannot subsequently change.
A dialog box level is created in ABAP when the CALL SCREEN STARTING AT [ENDING AT ].
When you instantiate a container, the class constructor creates the container instances SCREEN0, SCREEN1, ..., SCREEN9. These are assigned to the different dialog box levels. Dialog box level 0 = SCREEN0, level 1 = SCREEN1, ... Dialog box level 9 = SCREEN9.
The container instances SCREEN0, ... , SCREEN9 are called top-level containers. They are used directly as parent controls for the SAP Custom Control, SAP Docking Control, and SAP Dialog Box Control.
(C) SAP AG
BC412
8
14.9 Technical Methods for Attaching SAP Containers SAPgui
Abbreviated display
Screen 100 Container
Frontend
Abbreviated display
Appl. server
dialog box level 1 dialog box level 0
Internal session Top level container
0100
Container visible at the frontend
SCREEN9
Container not visible at the frontend Container Program
SCREEN1 Container destroyed at frontend
SCREEN0
SAP AG 1999
When you instantiate an SAP container, the top-level containers SCREEN0 to SCREEN9 are created.
They are created in the internal session in which the program is running.
The SAP container control at the frontend is controlled using the ABAP runtime object you create using the CREATE OBJECT statement.
When you create the container object in ABAP, the container object is assigned to a top-level container (by default, the current dialog box level). Once a container has been attached to a top-level container, you cannot change the assignment during the program.
The top-level container to which a container is assigned affects its visibility, and hence that of the other controls you display in it.
Controls in a container are only visible when the corresponding container is visible.
(C) SAP AG
BC412
9
14.10 Visibility and Lifetime of SAP Containers
Frontend
Dialog box level 1 Dialog box level 0
0100
0100
0100
CREATE CALL OBJECT SCREEN my_cont 100 EXPORTING STARTING dynnr = 100. AT x1 y1.
0100
LEAVE TO SCREEN 0.
0200
SET/CALL SCREEN 200.
0100
SET/CALL SCREEN 100.
LEAVE PROGRAM.
SAP AG 1999
As a rule, a SAP container object at the frontend can be addressed for as long as the program that created the container is active in main memory (for the lifetime of the corresponding internal session). We say that the lifetime of the frontend control is linked to that of the internal session.
The container control is only visible at the frontend on screens with the same dialog box level. Either on the screen with which the container control was created, or On screens to which the container is subsequently assigned (re-linked).
The level in the screen stack to which a screen belongs is irrelevant - the decisive factor is the dialog box level: In the graphic, the container control on screen 100 is assigned to dialog box level 0. The container is visible at the frontend whenever screen 100 appears in dialog box 0 (regardless of whether it is called using SET SCREEN 100 or CALL SCREEN 100 from dialog box level 0). The container is not visible at the frontend (but still active) if the screen containing it is hidden by another screen at the same dialog box level or if the dialog box level changes up or down.
(C) SAP AG
BC412
10
14.11 SAP Container Overview: SAP Custom Container Control
Thecontainer containerconcept concept The SAPCustom CustomContainer ContainerControl Control SAP SAPDialog DialogBox BoxContainer ContainerControl Control SAP SAPDocking DockingContainer ContainerControl Control SAP SAPSplitter SplitterContainer ContainerControl Control SAP SAPEasy EasySplitter SplitterContainer ContainerControl Control SAP
SAP AG 1999
(C) SAP AG
BC412
11
14.12 SAP Custom Container: Features
Custom control area
Properties Attached to a reserved area on a screen Resizable Can be used at dialog box levels 0 to 9
Container
Can be assigned to another area at runtime (re-link)
Program name Screen number Name of screen area Dialog box level
SAP AG 1999
You use the SAP Custom Container Control to attach a control to a reserved area on a screen.
You create the area using the Custom Control element in the Screen Painter. The area can be resized.
You can assign a Custom Container Control instance to the area. This assigns the container to the screen. The container can be resized if the user changes the size of the SAP window.
The following parameters identify a custom control area uniquely at the CFW: Program name Screen number Name of the area Number of the dialog box level at which the container and screen can be displayed.
(C) SAP AG
BC412
12
14.13 Creating an Instance of the SAP Custom Container Control Screen element: Name: AREA1 Type: Custom control
AREA1 100
DATA: cust_container TYPE REF TO cl_gui_custom_container. ... CREATE OBJECT cust_container EXPORTING * parent = " SCREEN0, ..., SCREEN9 * repid = " program name * dynnr = " screen number container_name = 'AREA1' " area name ... EXCEPTIONS others = 1. IF sy-subrc NE 0. ...
SAP AG 1999
To create an instance of the SAP Custom Container Control, you need a data object that you declare using TYPE REF TO cl_gui_custom_container.
To create the instance itself, use the statement CREATE OBJECT . In the statement, you must pass the relevant parameters to specify the attributes of the container. This is illustrated in the graphic. If you do not assign values to the parameters parent, repid, and dynnr, the system uses the current values at runtime (current dialog box level , current program name, current screen).
You must specify the name of the screen area in which the container should appear in the parameter container_name.
For details of the other interface parameters in the constructor, refer to the online documentation. You can find this under SAP Library -> Basis -> Controls and Control Framework -> SAP Container.
(C) SAP AG
BC412
13
14.14 Relinking an SAP Custom Container
Screen 100
Screen 200 (same dialog box level)
Custom control
Custom control
AREA1
Before call
Container
AREA2
After call CALL METHOD container->link EXPORTING * repid = dynnr = 200 container = 'AREA2' EXCEPTIONS others = 1.
SAP AG 1999
At runtime, you can assign a custom container instance to a different screen area (with the type Custom Control). The new area can be on the same screen, on another screen in the same program, or even on a screen in a different program.
The screen containing the new area to which you want to link the control can only be displayed in the same dialog box level.
To reassign an instance, you call the method link for the container instance you want to reassign. The method links the container instance to the new screen area and dissolves the link to the old one.
(C) SAP AG
BC412
14
14.15 SAP Container Overview: SAP Dialog Box Container Control
Thecontainer containerconcept concept The SAPCustom CustomContainer ContainerControl Control SAP SAPDialog DialogBox BoxContainer ContainerControl Control SAP SAPDocking DockingContainer ContainerControl Control SAP SAPSplitter SplitterContainer ContainerControl Control SAP SAPEasy EasySplitter SplitterContainer ContainerControl Control SAP
SAP AG 1999
(C) SAP AG
BC412
15
14.16 SAP Dialog Box Container: Features
Screen
Properties
Window title
Container is displayed in a movable modeless dialog box Modeless window can have a title Container cannot be attached to the screen Container can trigger the event close when the user closes the dialog box
Modeless window
Container
Program name Screen number Height and width of area Window title SAP AG 1999
The SAP Dialog Box Container allows you to display controls in a moveable modeless dialog box. You can also display controls in a full screen.
The modeless dialog box can have a title.
(C) SAP AG
BC412
16
14.17 Creating an Instance of the SAP Dialog Box Container Control
DATA: diabox_container TYPE REF TO cl_gui_dialogbox_container. ... CREATE OBJECT diabox_container EXPORTING Creates a modeless dialog box * dynnr = " screen number with the title 'Window title' * repid = " program name Window serves as a width = 150 Container height = 150 caption = 'Window title' ... EXCEPTIONS others = 1. IF sy-subrc NE 0. ...
SAP AG 1999
To create an instance of the SAP Dialog Box Container Control, you need a data object that you declare using TYPE REF TO cl_gui_dialogbox_control.
To create the instance itself, use the statement CREATE OBJECT . In the statement, you must pass the relevant parameters to specify the attributes of the container. This is illustrated in the graphic. If you do not assign values to the parameters parent, repid, and dynnr, the system uses the current values at runtime (current dialog box level , current program name, current screen).
Use the width and height parameters to specify the size of the dialog box. The user can also change the size of the dialog box at runtime.
Use the caption parameter to give a title to the modeless dialog box.
For details of the other interface parameters in the constructor, refer to the online documentation. You can find this under SAP Library -> Basis -> Controls and Control Framework -> SAP Container.
You can also change the window title at runtime using the instance method set_caption.
The control has an event called close. This is triggered when the user tries to close the modeless dialog box. In the event handler method, you can close the window using the class method free of class cl_gui_cfw.
(C) SAP AG
BC412
17
14.18 SAP Container Overview: SAP Docking Container Control
Thecontainer containerconcept concept The SAPCustom CustomContainer ContainerControl Control SAP SAPDialog DialogBox BoxContainer ContainerControl Control SAP SAPDocking DockingContainer ContainerControl Control SAP SAPSplitter SplitterContainer ContainerControl Control SAP SAPEasy EasySplitter SplitterContainer ContainerControl Control SAP
SAP AG 1999
(C) SAP AG
BC412
18
14.19 SAP Docking Container: Features Available screen area
Properties Container is docked at one edge of the screen The user can change the size of the container area The space taken up by the docking container is deducted from the overall space available to the rest of the screen
Container
Docking container
Original size of the window
SAP AG 1999
The SAP Docking Container allows you to attach one or more areas to a screen. You can attach the area to any of the four edges of the screen. The area available to the actual screen is reduced by the space taken up by the docking container.
The user can change the size of the docking container control.
(C) SAP AG
BC412
19
14.20 SAP Docking Container: Linking to the Screen
dock_at_top dock_at_left
dock_at_right
dock_at_bottom
Linking options
SAP AG 1999
You can attach the container area of a SAP Docking Container Control to any of the four edges of the screen. To set the edge to which you want to attach it, use one of the four static constants dock_at_top, dock_at_bottom, dock_at_left, or dock_at_right.
You determine where to dock the control in the side parameter of the constructor.
You can change this assignment at runtime by using the method dock_at. For further details, refer to the online documentation. You can find this under SAP Library -> Basis -> Controls and Control Framework -> SAP Container.
(C) SAP AG
BC412
20
14.21 Creating an Instance of the SAP Docking Container Control
DATA: dock_container TYPE REF TO cl_gui_docking_container. ... CREATE OBJECT dock_container EXPORTING side = cl_gui_docking_container=>dock_at_left " default * repid = " program name * dynnr = " screen number ... EXCEPTIONS others = 1. Creates a container control at the left edge of the screen
IF sy-subrc NE 0. ...
SAP AG 1999
To create an instance of the SAP Docking Container Control, you need a data object that you declare using TYPE REF TO cl_gui_docking_container.
To create the instance itself, use the statement CREATE OBJECT . In the statement, you must pass the relevant parameters to specify the attributes of the container. This is illustrated in the graphic. If you do not assign values to the parameters parent, repid, and dynnr, the system uses the current values at runtime (current dialog box level , current program name, current screen).
Use the side parameter to determine the side of the screen to which the container will be attached.
For details of the other interface parameters in the constructor, refer to the online documentation. You can find this under SAP Library -> Basis -> Controls and Control Framework -> SAP Container.
(C) SAP AG
BC412
21
14.22 Reading and Setting Attributes
Attribute
Method name dock_at
Function
Width/height
get_extension
Reads length parameter
of container
set_extension
Sets
Contact with screen
Sets edge of screen to which container is attached
length parameter
SAP AG 1999
The methods shown on the graphic allow you to find out or set the values of attributes of your container control. For further details about how they work and their interface, refer to the online documentation under SAP Library -> Basis -> Controls and Control Framework -> SAP Container.
(C) SAP AG
BC412
22
14.23 Relinking an SAP Docking Container
Screen 100
Before call
container
Screen 200 (same dialog box level)
After call CALL METHOD container->link EXPORTING * repid = dynnr = 200 * container = EXCEPTIONS others = 1.
SAP AG 1999
At runtime, you can attach a docking container to another screen at the same dialog box level (re-link it). To do this, use the instance method link. In the interface, you need to specify the new screen number and the name of the program to which it belongs. If you do not set a new program name, the system assumes that the new screen belongs to the same program as the old one.
(C) SAP AG
BC412
23
14.24 SAP Container Overview: SAP Splitter Container Control
Thecontainer containerconcept concept The SAPCustom CustomContainer ContainerControl Control SAP SAPDialog DialogBox BoxContainer ContainerControl Control SAP SAPDocking DockingContainer ContainerControl Control SAP SAPSplitter SplitterContainer ContainerControl Control SAP SAPEasy EasySplitter SplitterContainer ContainerControl Control SAP
SAP AG 1999
(C) SAP AG
BC412
24
14.25 SAP Splitter Container: Features
Properties 1 2
16
1
2
16
Can be displayed in other containers Can be divided into up to 16 x 16 cells You can display a different control in each cell Split bars can be movable or fixed You can control the height and width of the cells from the program You can display a frame for the container
SAP AG 1999
The SAP Splitter Container Control allows you to display a group of controls in individual cells. The splitter control regulates the cells and displays them. The user can change the size of the individual cells using split bars. Increasing the size of one cell decreases that of the adjacent cell.
You can make the splitter bars immovable from within your program.
You can only place a Splitter Container Control in another container such as a Custom Container or a Docking Container.
You can nest Splitter Control instances.
The grid of a Splitter Container Control instance is initially set to 0 x 0. The maximum division is 16 x 16. You can specify the size of the lines and columns either absolutely in pixels or relatively as a percentage. The default setting is relative.
(C) SAP AG
BC412
25
14.26 SAP Splitter Container: Use
Splitter container
Container
a0101 a0102
1
a0201 a0202
2
a1601 a1602
1 anm
Container area in line n column m
2
a1616
16
16
Each area is a container for other controls
SAP AG 1999
You can only assign a Splitter Container Control instance to a screen by using another container that is directly attached to the screen.
The cells in a Splitter Container Control serve as container areas for further controls, that is, each is the parent of another control.
(C) SAP AG
BC412
26
14.27 Creating an Instance of the SAP Splitter Container Control DATA: split_container TYPE REF TO cl_gui_splitter_container, cust_container TYPE REF TO cl_gui_custom_container. ... CREATE OBJECT split_container EXPORTING Creates a splitter control instance parent = cust_container with a 2 x 2 grid * repid = " program name (four cells = four areas for * dynnr = " screen number other controls) rows = 2 Custom control contains columns = 2 splitter control ... EXCEPTIONS others = 1. IF sy-subrc NE 0. ...
Parameter parent
Meaning
rows
Number of rows in grid
columns
Number of columns in grid
Reference variable to relevant container object
SAP AG 1999
To create an instance of the SAP Splitter Container Control, you need a data object that you declare using TYPE REF TO cl_gui_splitter_container.
To create the instance itself, use the statement CREATE OBJECT . In the statement, you must pass the relevant parameters to specify the attributes of the container. This is illustrated in the graphic. If you do not assign values to the parameters parent, repid, and dynnr, the system uses the current values at runtime (current dialog box level , current program name, current screen).
Use the rows and columns parameters to specify the number of rows and columns that your grid should have.
Use the parent parameter to assign your splitter control instance to another container.
For details of the other interface parameters in the constructor, refer to the online documentation. You can find this under SAP Library -> Basis -> Controls and Control Framework -> SAP Container.
(C) SAP AG
BC412
27
14.28 SAP Splitter Container: Finding a Cell Reference
DATA: split_container TYPE REF TO cl_gui_splitter_container, area_1_2 TYPE REF TO cl_gui_container. ... CALL METHOD split_container->get_container EXPORTING row = '1' Returns an object reference to column = '2' cell (1,2), that is, the first line RECEIVING and second column of the container = area_1_2. SAP Splitter Container Control ...
Parameter rows
Meaning
columns
Column number in grid
Row number in grid
SAP AG 1999
In order to assign further control instances to the cells of your splitter container, you need object references to the individual cells. To get a reference to a cell, use the instance method get_container. In the method call, use the row and column parameters to specify the cell. The RETURNING parameter container contains a reference to a container instance.
(C) SAP AG
BC412
28
14.29 Reading and Setting Attributes Attribute Cell
Columns
Column
Rows
Row
Border
Method name add_control
Function
remove_control
Removes a control from a cell
get_container
Gets a container reference to a cell
get_columns
Reads the number of columns
get_column_mode set_column_mode
Reads mode for division: absolute/relative Sets mode for division: absolute/relative
get_column_width set_column_width
Reads column width Sets column width
get_column_sash set_column_sash
Reads mode for splitter bar: fixed/movable Sets mode for splitter bar: fixed/movable
get_rows
Reads the number of lines
get_row_mode set_row_mode
Reads mode for division: absolute/relative Sets mode for division: absolute/relative
get_row_height set_row_height
Reads line height Sets line height
get_row_sash set_row_sash
Reads mode for splitter bar: fixed/movable Sets mode for splitter bar: fixed/movable
set_border
Sets border display: Yes/no
Assigns a control to a cell
SAP AG 1999
The methods shown on the graphic allow you to find out or set the values of attributes of your container control. For further details about how they work and their interface, refer to the online documentation under SAP Library -> Basis -> Controls and Control Framework -> SAP Container.
(C) SAP AG
BC412
29
14.30 SAP Container Overview: SAP Easy Splitter Container Control
Thecontainer containerconcept concept The SAPCustom CustomContainer ContainerControl Control SAP SAPDialog DialogBox BoxContainer ContainerControl Control SAP SAPDocking DockingContainer ContainerControl Control SAP SAPSplitter SplitterContainer ContainerControl Control SAP SAPEasy EasySplitter SplitterContainer ContainerControl Control SAP
SAP AG 1999
(C) SAP AG
BC412
30
14.31 SAP Easy Splitter Container: Features
Properties Simplified version of Splitter Container Control Can be divided into two cells Division can be vertical or horizontal Can only be placed in another container control Split bars can be movable or fixed You can control the height and width of the cells from the program You can display a frame for the container
or
SAP AG 1999
The SAP Easy Splitter Container is a simplified version of the SAP Splitter Container with a smaller range of functions. It allows you to display two controls in separate cells of a container area. You can arrange the cells either horizontally or vertically.
You can only use instances of the SAP Easy Splitter Container in other container instances.
You can nest Easy Splitter Control instances.
(C) SAP AG
BC412
31
14.32 Creating an Instance of the SAP Easy Splitter Container Control DATA: easy_split_container TYPE REF TO cl_gui_easy_splitter_container, cust_container TYPE REF TO cl_gui_custom_container. ... Creates easy splitter control CREATE OBJECT easy_split_container instance, split horizontally. EXPORTING parent = cust_container Custom container control * repid = " program name contains custom control * dynnr = " screen number orientation = easy_split_container->orientation_vertical ... EXCEPTIONS others = 1. IF sy-subrc NE 0. ... Parameter parent orientation
Meaning Reference variable to relevant container object orientation_vertical Areas arranged vertically orientation_horizontal Areas arranged horizontally
SAP AG 1999
To create an instance of the SAP Easy Splitter Container Control, you need a data object that you declare using TYPE REF TO cl_gui_easy_splitter_container.
To create the instance itself, use the statement CREATE OBJECT . In the statement, you must pass the relevant parameters to specify the attributes of the container. This is illustrated in the graphic. If you do not assign values to the parameters parent, repid, and dynnr, the system uses the current values at runtime (current dialog box level , current program name, current screen).
Use the orientation parameter to specify whether the areas should be arranged horizontally or vertically. You can do this using the class constants cl_gui_easy_splitter_container=>orientation_vertical and cl_gui_easy_splitter_container=>orientation_horizontal.
Use the parent parameter to assign your splitter control instance to another container.
For details of the other interface parameters in the constructor, refer to the online documentation. You can find this under SAP Library -> Basis -> Controls and Control Framework -> SAP Container.
To set the position of the splitter bar from your program, use the instance method set_sash_position. For further details, refer to the online documentation.
(C) SAP AG
BC412
32
14.33 SAP Easy Splitter Container: Reference Variables for the Cells
Easy Splitter Container Instance attributes Control 1 top_left_container Container bottom_right_container Control 2
SAP AG 1999
In order to assign further control instances to the cells of your splitter container, you need object references to the individual cells. These are contained in the instance attributes top_left_container and bottom_right_container.
(C) SAP AG
BC412
33
14.34 SAP Container: Unit Summary
You are now able to: Explain how SAP containers work in the Control Framework List the container controls that you can use in the SAP System Describe the features of each of the container controls Use SAP container controls
SAP AG 1999
(C) SAP AG
BC412
34
14.35SAP Container Exercise 1 Unit: SAP Container Topic: SAP Docking Container At the conclusion of these exercises, you will be able to: Use instances of the Docking Container Control
You copy a program template consisting of an ABAP program that calls a screen. By means of a Custom Container Control instance, an image is displayed in a Picture Control on this screen. Instead of the Custom Container, you use the Docking Container Control. Program:
ZBC412_##_CON_EX1
Template:
SAPBC412_CONT_EXERCISE1
Sample solution:
SAPBC412_CONS_EXERCISE1
## is your group number 1-1
Copy the program template SAPBC412_CONT_EXERCISE1 with all its subobjects to program ZBC412_##_CON_EX1, or use your solution of the last task of the chapter Introduction to the Control Framework. This template has the same range of functions as the sample solution for the last exercise (Exercise 4) of the chapter Introduction to the Control Framework.
1-2
Modify your program to use the SAP Docking Container instead of the SAP Custom Container. 1-2-1 Remove the Custom Control area on screen 100. You no longer need it. 1-2-2 Change the typing of your container reference variable (ref_container) to cl_gui_docking_container. 1-2-3 Create an instance of the SAP Docking Container Control in module init_control_processing. To do this, change the EXPORTING parameters in the CREATE OBJECT ref_container statement to make them compatible with the constructor for instances of class cl_gui_docking_container. Attach the Docking Container instance to the left side of your screen.
1-3
(C) SAP AG
Test your program.
BC412
35
Use the class constant dock_at_left of class cl_gui_docking_container to set a value for interface parameter side in the constructor.
(C) SAP AG
BC412
36
Exercise 1: Optional Parts At the conclusion of these exercises, you will be able to: Attach instances of the SAP Docking Container Control to different sides of a screen Your task is to allow the user of your program to choose whether the Picture Control should appear on the right or on the left side of the screeen.
Program:
same program
Template:
same program
Sample solution:
SAPBC412_CONS_EXERCISE1A
## is your group number 1-4
Allow the user to choose the screen side where the Picture Control should appear by defining a checkbox on the default selection screen of your program. 1-4-1 Add a PARAMETER statement to the data declaration part of your program that you use to create a checkbox on a selection screen (suggested name for the parameter: p_side). Use the addition AS CHECKBOX to display the parameter as a checkbox. Maintain the selection text (suggested text: Attach to right screen side). 1-4-2 Define another variable in the data declaration part that you use to process the parameter (of the selection screen). It should contain the technical name of the screen side to which the control is to be attached (suggested name: docking_side). Type the variable with reference to LIKE cl_gui_docking_container=>dock_at_right. 1-4-3 Process the parameter p_side in module init_control_processing before the container is instantiated: If the parameter p_side has not been selected, assign the value cl_gui_docking_container=>dock_at_left to the variable docking_side; if the parameter has been selected, assign the value cl_gui_docking_container=>dock_at_right. 1-4-4 Use the variable docking_side in the interface of the constructor for the Container instance.
1-5
(C) SAP AG
Test your program.
BC412
37
You cannot use the instance attribute docking_side of class cl_gui_docking_container to type your program variable docking_side, since this instance attribute has visibility PPROTECTED and not PUBLIC.
(C) SAP AG
BC412
38
Exercise 2 Unit: SAP Container Topic: SAP Splitter Container Control At the conclusion of these exercises, you will be able to: Generate and configure (organise into cells) instances of the SAP Splitter Container Control Determine references to the cells of your Splitter Container instance Use the cell references as containers for other EnjoySAP controls Modify your program so that two images appear side by side on the screen. To do this, you use an SAP Splitter Control instance that consists of two cells. As in the previous exercises, your task is to allow the user to change the Picture Control instance of the right cell using the pushbuttons on the screen. Event handling (PICTURE_CLICK and CONTROL_DBLCICK) should be possible for both Picture Control instances. Program:
ZBC412_##_CON_EX2
Template:
SAPBC412_CONT_EXERCISE2
Sample solution:
SAPBC412_CONS_EXERCISE2
## is your group number 2-1
Copy the program template SAPBC412_CONT_EXERCISE2 with all its subobjects to program ZBC412_##_CON_EX2. Execute the program copied to make yourself familiar with the functions it provides. The template has the same range of functions as the template for task 1 of this chapter (an image is displayed in a Picture Control that is linked to a Custom Control).
2-2
Since Splitter Container instances must be linked to another container, and the Splitter Container consists of several cells that can contain other control instances, you need some more data objects.
Define the following data objects in the data declaration part of your program:
(C) SAP AG
A reference variable for a Splitter Container instance (suggested name: ref_splitter). Type this variable with reference to cl_gui_splitter_container.
BC412
39
A reference variable for a second Picture Control instance (suggested name: ref_pic_left). Type this variable with reference to cl_gui_picture. To make the source code easier to read, you should rename the reference to the first Picture Control object (suggested name: ref_pic_right).
Two reference variables for the two cells of your Splitter Container instance (suggested names: cell_1_1 and cell_1_2). Type these variables with reference to cl_gui_container.
A second variable that contains the URL for the second image you want to display (suggested name: l_url2, ABAP data type C, length 80 characters). To make the source code easier to read, you should rename variable l_url to read l_url1. 2-3
You need a second image for your second Picture Control instance (you can also use the same image in both Picture Control instances). Again, use one of the images added to the BDS for this training course. 2-3-1 Use function module BC412_BDS_GET_PIC_URL to get a valid URL for an image in the BDS. Set the value for the IMPORT parameter number of the function module to 2. Place the URL for the image that you receive from the function module in the data object l_url2. Again, this URL is valid as long as the program executes.
2-4
Extend the PBO module init_control_processing as follows: 2-4-1 Instantiate a Splitter Container object that you link to your Custom Control instance. Your Splitter Container instance should have two horizontally arranged cells (one row, two columns). Issue dialog message 010 (message class bc412, message type A) to respond to exceptions of the constructor. Note that you must have initiated the Custom Container object before. 2-4-2 Determine the references (pointers) to the cells of your Splitter Container instance. To do this, use the instance method get_container of class cl_gui_splitter_container. Note: Since this method does not have exceptions, error handling is not necessary. 2-4-3 Create the two Picture Control instances and use the cell references you determined to link them to the two cells of your Splitter Container instance. Issue dialog message 011 (message class bc412, message type A) to respond to any exceptions of the constructor. 2-4-4 Use the URL variables (l_url1 and l_url2) to load the two images into your Picture Control instances. Use the dialog messages of the previous tasks to respond to exceptions and indicate the status of the image loading process. Message
(C) SAP AG
Usage
Number
Class
Type
012
bc412
A
Exception
013
bc412
S
Not loaded
BC412
40
014
bc412
S
Loaded
2-4-5 For both Picture Control instances, register the events PICTURE_CLICK and CONTROL_DBLCLICK at the Control Framework. Execute the method set_registered_events for both Picture Control instances. Use dialog message 012 (message class bc412, message type A) to respond to exceptions. 2-4-6 Register the static handler methods on_picture_click and on_control_dblclick of your local class lcl_event_handler for both Picture Control instances. 2-5
In the PAI module user_command_0100, modify the implementations of the functions STRETCH, NORMAL, NORMAL_CENTER, FIT, FIT_CENTER and MODE_INFO to execute the methods specified there for the Picture Control instance of the right cell of the Splitter Container. To do this, change the name of the Picture Control reference variable into ref_pic_right in all implementations.
2-6
Modify the subroutine free_control_ressources to correctly destroy all control instances created at the frontend. Note that you must execute instance method free in reversed instantiation order.
2-7
Test your program.
(C) SAP AG
BC412
41
14.36Note on the Sample Solutions for Unit 03 The sample solutions provided include the statements of the screen flow logic and of the ABAP program parts required in the sample solution. For exercises 1 and 2 of this chapter, we have included the complete source code of the sample solutions. The code sections that you need to add in order to solve the task are printed in bold. For the solutions of the optional parts of task 1, we have only included those program parts (data declarations and modules) that need to be changed. Again, the code sections that you need to add in order to solve the task are printed in bold.
(C) SAP AG
BC412
42
14.37SAP Container Solutions to Exercise 1 Unit: SAP Container Topic: SAP Docking Container
Model solution SAPBC412_CONS_EXERCISE1 15Screen flow logic 16SCREEN 100 PROCESS BEFORE OUTPUT. MODULE status_0100. MODULE init_control_processing. PROCESS AFTER INPUT. MODULE exit_command_0100 AT EXIT-COMMAND. MODULE user_command_0100.
17ABAP Program 18Local Classes REPORT
sapbc412_cons_exercise1 MESSAGE-ID bc412.
*------------------------------------------------------------------* *
CLASS lcl_event_handler DEFINITION
*------------------------------------------------------------------* *
Definition of a local class containing event handler
*
* methods for picture control objects * *------------------------------------------------------------------* CLASS lcl_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_picture_click FOR EVENT picture_click OF cl_gui_picture IMPORTING mouse_pos_x mouse_pos_y, *
-------------------------------------------------------------on_control_dblclick
(C) SAP AG
BC412
43
FOR EVENT control_dblclick OF cl_gui_picture IMPORTING mouse_pos_x mouse_pos_y. ENDCLASS.
(C) SAP AG
BC412
44
*------------------------------------------------------------------* *
CLASS lcl_event_handler IMPLEMENTATION
*------------------------------------------------------------------* *
Corresponding class implementation
*
*------------------------------------------------------------------* CLASS lcl_event_handler IMPLEMENTATION. METHOD on_picture_click. MESSAGE i016 WITH mouse_pos_x mouse_pos_y. ENDMETHOD. METHOD on_control_dblclick. MESSAGE i017 WITH mouse_pos_x mouse_pos_y. ENDMETHOD. ENDCLASS.
19Data Declarations * global types: Type Pools TYPE-POOLS: cntl. * data declarations *
screen specific
DATA: ok_code
TYPE sy-ucomm,
" command field
copy_ok_code LIKE ok_code,
" copy of ok_code
l_answer
" return flag (used in
TYPE c,
" standard user dialogs) *
control specific: object references ref_container TYPE REF TO cl_gui_docking_container, ref_picture
*
TYPE REF TO cl_gui_picture,
control specific: auxiliary fields l_url(80)
TYPE c,
" URL of picture to be shown
l_result
TYPE i value 1,
" status variable of load_picture " 1 = o.k., 0 = error
current_mode (C) SAP AG
LIKE cl_gui_picture=>display_mode, BC412
45
*
event handling it_events
TYPE cntl_simple_events, " internal (event) table
wa_events
LIKE LINE OF it_events.
(C) SAP AG
BC412
" work area
46
20Main ABAP Program: Event Blocks * start of main program START-OF-SELECTION. CALL FUNCTION 'BC412_BDS_GET_PIC_URL' " fetch URL of first picture *
EXPORTING
*
" from BDS
NUMBER
= 1
IMPORTING url
= l_url
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0.
" no picture --> end of program
LEAVE PROGRAM. ENDIF. CALL SCREEN 100.
" container screen for SAP-Enjoy " controls
* end of main program
21Modules *&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
Implementation of EnjoySAP control processing:
*
1)
create container object and link to screen (left side)
*
2)
create picture object and link to container
*
3)
load picture into picture control
*
4)
event handling
*
a1) register event PICTURE_CLICK at CFW
*
a2) register event CONTROL_DBLCLICK at CFW
*
b1) register event handler method ON_PICTURE_CLICK
*
for the picture control object
*
b2) register event handler method ON_CONTROL_DBLCLICK
*
for the picture control object
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
" prevent re-processing on ENTER
create container object and link to screen (left screen side)
(C) SAP AG
BC412
47
CREATE OBJECT ref_container EXPORTING side = cl_gui_docking_container=>dock_at_left EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a010.
" cancel program processing
ENDIF.
(C) SAP AG
BC412
48
*
create picture control and link to container object CREATE OBJECT ref_picture EXPORTING parent = ref_container EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a011.
" cancel program processing
ENDIF. *
load picture into picture control CALL METHOD ref_picture->load_picture_from_url EXPORTING url
= l_url
IMPORTING result = l_result EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF. CASE l_result. WHEN 0.
" picture not loaded
MESSAGE s013. WHEN 1.
" load of picture successful
MESSAGE s014. ENDCASE. *
event handling
*
1. register events for control framework wa_events-eventid
= cl_gui_picture=>eventid_picture_click.
wa_events-appl_event = ' '. INSERT wa_events INTO TABLE it_events. wa_events-eventid
= cl_gui_picture=>eventid_control_dblclick.
wa_events-appl_event = ' '. INSERT wa_events INTO TABLE it_events. (C) SAP AG
BC412
49
CALL METHOD ref_picture->set_registered_events EXPORTING events = it_events EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF.
(C) SAP AG
BC412
50
*
2. set event handler for ABAP object instance: ref_picture SET HANDLER lcl_event_handler=>on_picture_click FOR ref_picture. SET HANDLER lcl_event_handler=>on_control_dblclick FOR ref_picture. ENDIF.
ENDMODULE.
" INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *&
Module
USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
Implementation of user commands of type ' ':
*
- push buttons on screen 100
*
- GUI functions
*------------------------------------------------------------------* MODULE user_command_0100 INPUT. copy_ok_code = ok_code. CLEAR ok_code. CASE copy_ok_code. WHEN 'BACK'.
" back to program, leave screen
CLEAR l_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING *
DEFAULTOPTION
= 'Y'
textline1
= text-004
textline2
= text-005
titel
= text-007
cancel_display = ' ' IMPORTING answer
= l_answer.
CASE l_answer. WHEN 'J'. PERFORM free_control_ressources. LEAVE TO SCREEN 0. WHEN 'N'. (C) SAP AG
BC412
51
SET SCREEN sy-dynnr. ENDCASE. WHEN 'STRETCH'.
" picture operation: stretch to fit area
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_stretch EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF.
(C) SAP AG
BC412
52
WHEN 'NORMAL'.
" picture operation: fit to normal size
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_normal EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'NORMAL_CENTER'.
" picture operation: center normal size
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_normal_center EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'FIT'.
" picture operation: zoom picture
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_fit EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'FIT_CENTER'.
" picture operation: zoom and center
CALL METHOD ref_picture->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_fit_center EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF.
(C) SAP AG
BC412
53
WHEN 'MODE_INFO'. current_mode = ref_picture->display_mode. MESSAGE i025 WITH current_mode. ENDCASE. ENDMODULE.
(C) SAP AG
" USER_COMMAND_0100
BC412
INPUT
54
*&-----------------------------------------------------------------* *&
Module
STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *
Set GUI for screen 0100
*------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'STATUS_NORM_0100'. SET TITLEBAR
'TITLE_NORM_0100'.
ENDMODULE.
" STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *&
Module
EXIT_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
Implementation of user commands of type 'E'.
*------------------------------------------------------------------* MODULE exit_command_0100 INPUT. CASE ok_code. WHEN 'CANCEL'.
" cancel current screen processing
CLEAR l_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING *
DEFAULTOPTION
= 'Y'
textline1
= text-004
textline2
= text-005
titel
= text-006
cancel_display = ' ' IMPORTING answer
= l_answer.
CASE l_answer. WHEN 'J'. PERFORM free_control_ressources. LEAVE TO SCREEN 0. WHEN 'N'. CLEAR ok_code. SET SCREEN sy-dynnr. ENDCASE. WHEN 'EXIT'.
" leave program
CLEAR l_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' (C) SAP AG
BC412
55
EXPORTING *
DEFAULTOPTION
= 'Y'
textline1
= text-001
textline2
= text-002
titel
= text-003
cancel_display = 'X' IMPORTING answer
= l_answer.
CASE l_answer. WHEN 'J' OR 'N'.
" no data to update
PERFORM free_control_ressources. LEAVE PROGRAM. WHEN 'A'. CLEAR ok_code. SET SCREEN sy-dynnr. ENDCASE. ENDCASE. ENDMODULE.
" EXIT_COMMAND_0100
INPUT
22Subroutines *&-----------------------------------------------------------------* *&
Form
free_control_ressources
*&-----------------------------------------------------------------* *
Free all control related ressources.
*------------------------------------------------------------------* *
no interface
*------------------------------------------------------------------* FORM free_control_ressources. CALL METHOD ref_picture->free. CALL METHOD ref_container->free. FREE: ref_picture, ref_container. ENDFORM.
(C) SAP AG
" free_control_ressources
BC412
56
Solution to the Optional Sections of Exercise 1 Unit: SAP Container Topic: SAP Docking Container
Model solution SAPBC412_CONS_EXERCISE1A 23ABAP Program 23.2Data Declarations and Selection Screen * global types TYPE-POOLS: cntl. * data declarations *
screen specific
DATA: ok_code
TYPE sy-ucomm,
" command field
copy_ok_code LIKE ok_code,
" copy of ok_code
l_answer
" return flag (used in
TYPE c,
" standard user dialogs) *
control specific: object references ref_container TYPE REF TO cl_gui_docking_container, ref_picture
*
TYPE REF TO cl_gui_picture,
control specific: auxiliary fields l_url(80)
TYPE c,
" URL of picture to be shown
l_result
TYPE i value 1,
" status variable of load_picture " 1 = o.k., 0 = error
*
current_mode
LIKE cl_gui_picture=>display_mode,
docking_side
LIKE cl_gui_docking_container=>dock_at_right,
event handling it_events
TYPE cntl_simple_events, " internal (event) table
wa_events
LIKE LINE OF it_events.
" work area
* selection screen definition (C) SAP AG
BC412
57
PARAMETERS: p_side AS CHECKBOX.
(C) SAP AG
BC412
58
23.3Modules *&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
Implementation of EnjoySAP control processing:
*
1)
create container object and link to screen (left side)
*
2)
create picture object and link to container
*
3)
load picture into picture control
*
4)
event handling
*
a1) register event PICTURE_CLICK at CFW
*
a2) register event CONTROL_DBLCLICK at CFW
*
b1) register event handler method ON_PICTURE_CLICK
*
for the picture control object
*
b2) register event handler method ON_CONTROL_DBLCLICK
*
for the picture control object
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
" prevent re-processing on ENTER
create container object and link to screen IF p_side IS INITIAL. docking_side = cl_gui_docking_container=>dock_at_left. ELSE.
" dock to right side selected
docking_side = cl_gui_docking_container=>dock_at_right. ENDIF.
CREATE OBJECT ref_container EXPORTING side = docking_side EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a010.
" cancel program processing
ENDIF. *
create picture control and link to container object CREATE OBJECT ref_picture EXPORTING
(C) SAP AG
BC412
59
parent = ref_container EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a011.
" cancel program processing
ENDIF.
(C) SAP AG
BC412
60
*
load picture into picture control CALL METHOD ref_picture->load_picture_from_url EXPORTING url
= l_url
IMPORTING result = l_result EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF. CASE l_result. WHEN 0.
" picture not loaded
MESSAGE s013. WHEN 1.
" load of picture successful
MESSAGE s014. ENDCASE. *
event handling
*
1. register events for control framework wa_events-eventid
= cl_gui_picture=>eventid_picture_click.
wa_events-appl_event = ' '. INSERT wa_events INTO TABLE it_events. wa_events-eventid
= cl_gui_picture=>eventid_control_dblclick.
wa_events-appl_event = ' '. INSERT wa_events INTO TABLE it_events.
CALL METHOD ref_picture->set_registered_events EXPORTING events = it_events EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF. (C) SAP AG
BC412
61
*
2. set event handler for ABAP object instance: ref_picture SET HANDLER lcl_event_handler=>on_picture_click FOR ref_picture. SET HANDLER lcl_event_handler=>on_control_dblclick FOR ref_picture. ENDIF.
ENDMODULE.
(C) SAP AG
" INIT_CONTROL_PROCESSING
BC412
OUTPUT
62
Solution to Exercise 2 Unit: SAP Container Topic: SAP Splitter Container
Model solution SAPBC412_CONS_EXERCISE2 24Screen flow logic 25SCREEN 100 PROCESS BEFORE OUTPUT. MODULE status_0100. MODULE init_control_processing. PROCESS AFTER INPUT. MODULE exit_command_0100 AT EXIT-COMMAND. MODULE user_command_0100.
26ABAP Program 27Local Classes REPORT
sapbc412_cons_exercise2 MESSAGE-ID bc412.
*------------------------------------------------------------------* *
CLASS lcl_event_handler DEFINITION
*------------------------------------------------------------------* *
Definition of a local class containing event handler
*
* methods for picture control objects * *------------------------------------------------------------------* CLASS lcl_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_picture_click FOR EVENT picture_click OF cl_gui_picture IMPORTING mouse_pos_x mouse_pos_y, *
-------------------------------------------------------------on_control_dblclick
(C) SAP AG
BC412
63
FOR EVENT control_dblclick OF cl_gui_picture IMPORTING mouse_pos_x mouse_pos_y. ENDCLASS.
(C) SAP AG
BC412
64
*------------------------------------------------------------------* *
CLASS lcl_event_handler IMPLEMENTATION
*------------------------------------------------------------------* *
Corresponding class implementation
*
*------------------------------------------------------------------* CLASS lcl_event_handler IMPLEMENTATION. METHOD on_picture_click. MESSAGE i016 WITH mouse_pos_x mouse_pos_y. ENDMETHOD. METHOD on_control_dblclick. MESSAGE i017 WITH mouse_pos_x mouse_pos_y. ENDMETHOD. ENDCLASS.
27.2Data Declarations * global types TYPE-POOLS: cntl. * data declarations *
screen specific
DATA: ok_code
TYPE sy-ucomm,
" command field
copy_ok_code LIKE ok_code,
" copy of ok_code
l_answer
" return flag (used in
TYPE c,
" standard user dialogs) *
*
*
control specific: object references ref_container
TYPE REF TO cl_gui_custom_container,
ref_splitter
TYPE REF TO cl_gui_splitter_container,
ref_pic_left
TYPE REF TO cl_gui_picture,
ref_pic_right
TYPE REF TO cl_gui_picture,
object references to splitter control areas cell_1_1
TYPE REF TO cl_gui_container,
cell_1_2
TYPE REF TO cl_gui_container,
control specific: auxiliary fields l_url1(80)
TYPE c,
" URL of picture 1 to be shown
l_url2(80)
TYPE c,
" URL of picture 2 to be shown
(C) SAP AG
BC412
65
l_result1
TYPE i value 1,
" status variable of load_picture " 1 = o.k., 0 = error
l_result2
TYPE i value 1,
" status variable of load_picture " 1 = o.k., 0 = error
current_mode *
LIKE cl_gui_picture=>display_mode,
event handling it_events
TYPE cntl_simple_events, " internal (event) table
wa_events
LIKE LINE OF it_events.
(C) SAP AG
BC412
" work area
66
27.3Main ABAP Program: Event Blocks * start of main program START-OF-SELECTION. CALL FUNCTION 'BC412_BDS_GET_PIC_URL' " fetch URL of first picture *
EXPORTING
*
NUMBER
" from BDS = 1
IMPORTING url
= l_url1
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0.
" no picture --> end of program
LEAVE PROGRAM. ENDIF. CALL FUNCTION 'BC412_BDS_GET_PIC_URL'" fetch URL of second picture EXPORTING number
" from BDS = 2
IMPORTING url
= l_url2
EXCEPTIONS OTHERS IF sy-subrc 0.
= 1. " no picture --> end of program
LEAVE PROGRAM. ENDIF. CALL SCREEN 100.
" container screen for SAP-Enjoy " controls
* end of main program
(C) SAP AG
BC412
67
27.4Modules *&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
Implementation of EnjoySAP control processing:
*
1)
create custom container object and link to screen area
*
2)
create splitter container object and link to the custom
*
control object
*
3)
fetch pointer to splitter control areas
*
4)
create two picture objects and link to splitter control
*
areas
*
5)
load pictures into picture control objects
*
6)
event handling (for the picture on the left side only)
*
a1) register event PICTURE_CLICK at CFW
*
a2) register event CONTROL_DBLCLICK at CFW
*
b1) register event handler method ON_PICTURE_CLICK
*
for both picture control objects
*
b2) register event handler method ON_CONTROL_DBLCLICK
*
for both picture control objects
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
" prevent re-processing on ENTER
create custom container object and link to screen area CREATE OBJECT ref_container EXPORTING container_name = 'CONTROL_AREA1' EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a010.
" cancel program processing
ENDIF. *
create splitter container object and link to custom control CREATE OBJECT ref_splitter EXPORTING parent
= ref_container
rows
= '1'
columns = '2' (C) SAP AG
BC412
68
EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a010.
" cancel program processing
ENDIF. *
fetch pointer to splitter control areas
*
left cell CALL METHOD ref_splitter->get_container EXPORTING row
= '1'
column
= '1'
RECEIVING container = cell_1_1. * * *
alternatively possible: (functional method) cell_1_1 = ref_splitter->get_container( row = '1' column = '1' ).
* *
right cell CALL METHOD ref_splitter->get_container EXPORTING row
= '1'
column
= '2'
RECEIVING container = cell_1_2. *
create picture control objects and link to cell pointer
*
picture control object 1 (left cell)
27.4.2
CREATE OBJECT ref_pic_left EXPORTING parent = cell_1_1 EXCEPTIONS others = 1.
IF sy-subrc NE 0. MESSAGE a011.
" cancel program processing
ENDIF. *
picture control object 2 (right cell)
(C) SAP AG
BC412
69
CREATE OBJECT ref_pic_right EXPORTING parent = cell_1_2 EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a011.
" cancel program processing
ENDIF. *
load pictures into picture control objects
*
left cell CALL METHOD ref_pic_left->load_picture_from_url EXPORTING url
= l_url1
IMPORTING result = l_result1 EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF. CASE l_result1. WHEN 0.
" picture not loaded
MESSAGE s013. WHEN 1.
" load of picture successful
MESSAGE s014. ENDCASE.
(C) SAP AG
BC412
70
*
right cell CALL METHOD ref_pic_right->load_picture_from_url EXPORTING url
= l_url2
IMPORTING result = l_result2 EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF. CASE l_result2. WHEN 0.
" picture not loaded
MESSAGE s013. WHEN 1.
" load of picture successful
MESSAGE s014. ENDCASE. *
event handling
*
1. register events for control framework wa_events-eventid
= cl_gui_picture=>eventid_picture_click.
wa_events-appl_event = ' '. INSERT wa_events INTO TABLE it_events. wa_events-eventid
= cl_gui_picture=>eventid_control_dblclick.
wa_events-appl_event = ' '. INSERT wa_events INTO TABLE it_events. *
send event table for picture in left cell to cfw CALL METHOD ref_pic_left->set_registered_events EXPORTING events = it_events
27.4.3
EXCEPTIONS OTHERS = 1.
IF sy-subrc NE 0. MESSAGE a012. ENDIF. (C) SAP AG
BC412
71
*
send event table for picture in right cell to cfw CALL METHOD ref_pic_right->set_registered_events EXPORTING events = it_events EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF.
(C) SAP AG
BC412
72
*
2. set event handler for ABAP object instance:
*
ref_pic_left (left cell) SET HANDLER lcl_event_handler=>on_picture_click FOR ref_pic_left. SET HANDLER lcl_event_handler=>on_control_dblclick FOR ref_pic_left.
*
ref_pic_right (right cell) SET HANDLER lcl_event_handler=>on_picture_click FOR ref_pic_right. SET HANDLER lcl_event_handler=>on_control_dblclick FOR ref_pic_right. ENDIF.
ENDMODULE.
" INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *&
Module
USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
Implementation of user commands of type ' ':
*
- push buttons on screen 100
*
- GUI functions
*------------------------------------------------------------------* MODULE user_command_0100 INPUT. copy_ok_code = ok_code. CLEAR ok_code. CASE copy_ok_code. WHEN 'BACK'.
" back to program, leave screen
CLEAR l_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING *
DEFAULTOPTION
= 'Y'
textline1
= text-004
textline2
= text-005
titel
= text-007
cancel_display = ' ' (C) SAP AG
BC412
73
IMPORTING answer
= l_answer.
CASE l_answer. WHEN 'J'. PERFORM free_control_ressources. LEAVE TO SCREEN 0. WHEN 'N'. SET SCREEN sy-dynnr. ENDCASE.
(C) SAP AG
BC412
74
WHEN 'STRETCH'.
" picture operation: stretch to fit area
CALL METHOD ref_pic_right->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_stretch EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'NORMAL'.
" picture operation: fit to normal size
CALL METHOD ref_pic_right->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_normal EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'NORMAL_CENTER'.
" picture operation: center normal size
CALL METHOD ref_pic_right->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_normal_center EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'FIT'.
" picture operation: zoom picture
CALL METHOD ref_pic_right->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_fit EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'FIT_CENTER'. (C) SAP AG
" picture operation: zoom and center BC412
75
CALL METHOD ref_pic_right->set_display_mode EXPORTING display_mode = cl_gui_picture=>display_mode_fit_center EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE s015. ENDIF. WHEN 'MODE_INFO'. current_mode = ref_pic_right->display_mode. MESSAGE i025 WITH current_mode. ENDCASE. ENDMODULE.
" USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *&
Module
STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *
Set GUI for screen 0100
*------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'STATUS_NORM_0100'. SET TITLEBAR
'TITLE_NORM_0100'.
ENDMODULE.
" STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *&
Module
EXIT_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
Implementation of user commands of type 'E'.
*------------------------------------------------------------------* MODULE exit_command_0100 INPUT. CASE ok_code. WHEN 'CANCEL'.
" cancel current screen processing
CLEAR l_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING *
(C) SAP AG
DEFAULTOPTION
= 'Y'
textline1
= text-004 BC412
76
textline2
= text-005
titel
= text-006
cancel_display = ' ' IMPORTING answer
= l_answer.
CASE l_answer. WHEN 'J'. PERFORM free_control_ressources. LEAVE TO SCREEN 0. WHEN 'N'. CLEAR ok_code. SET SCREEN sy-dynnr. ENDCASE. WHEN 'EXIT'.
" leave program
CLEAR l_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING *
DEFAULTOPTION
= 'Y'
textline1
= text-001
textline2
= text-002
titel
= text-003
cancel_display = 'X' IMPORTING answer
= l_answer.
CASE l_answer. WHEN 'J' OR 'N'.
" no data to update
PERFORM free_control_ressources. LEAVE PROGRAM. WHEN 'A'. CLEAR ok_code. SET SCREEN sy-dynnr. ENDCASE. ENDCASE. ENDMODULE.
" EXIT_COMMAND_0100
INPUT
27.5Subroutines *&-----------------------------------------------------------------* *& (C) SAP AG
Form
free_control_ressources BC412
77
*&-----------------------------------------------------------------* *
Free all control related ressources.
*------------------------------------------------------------------* *
no interface
*------------------------------------------------------------------* FORM free_control_ressources. CALL METHOD ref_pic_left->free. CALL METHOD ref_pic_right->free. CALL METHOD ref_splitter->free. CALL METHOD ref_container->free. FREE: ref_pic_left, ref_pic_right, cell_1_1, cell_1_2, ref_splitter, ref_container. ENDFORM.
(C) SAP AG
" free_control_ressources
BC412
78
28 SAP Tree Control
Contents: Tree Control types: simple tree Column Tree List Tree Properties Use Data handling Events
SAP AG 1999
(C) SAP AG
BC412
1
28.2 SAP Tree Control: Unit Objectives
At the conclusion of this unit, you will be able to: Describe the features of the different tree control variants:
Attributes
Methods
Events
Display data in a tree control:
Creating hierarchies
Using additional information (items)
SAP AG 1999
(C) SAP AG
BC412
2
28.3 Overview Diagram - BC412
Course Overview
Unit 1
Unit 2
Introduction to the Control Framework
Unit 3
SAP Container
Unit 4
SAP Tree Control
Unit 5
ALV Grid Control
SAP AG 1999
(C) SAP AG
BC412
3
28.4 SAP Tree Control Overview: Display Attributes
Introduction:display display attributes attributes Introduction: TreeControl: Control:Constructor, Constructor,methods, methods,and andevents events Tree Creatingaahierarchy hierarchy Creating Itemtables tables Item Data handling handlingstrategies strategies Data
SAP AG 1999
(C) SAP AG
BC412
4
28.5 SAP Tree Control
Object name SAPBC412 Development class object type Dictionary objects Programs SAPBC412_BASD_AREA... SAPBC412_BASD_CALL... . . . Function groups Message class
Description
Properties Data displayed hierarchically in a list
List can be expanded BC412: Demo ... BC412: Demo ... . . .
and collapsed
User interaction possible
Can be used as: - Navigation aid - Value list - Object list
SAP AG 1999
The SAP Tree Control is suitable for displaying data in hierarchical structures.
You can display the tree in either expanded or collapsed form. It is therefore particularly useful for displaying data in a structured format. You can use it as a navigation aid value list item list.
The SAP Tree Control is a control that displays data. You cannot enter data. However, user interaction is possible with the following components: individual lines areas consisting of several lines elements within lines title elements
All user actions on components of a tree control trigger control events.
On Windows platforms, the SAP Tree Control supports drag and drop and context menus.
You cannot print the contents of a SAP Tree Control display in the same way you can an ABAP list.
(C) SAP AG
BC412
5
28.6 SAP Tree Control: Principles of Construction
Optional headings Node 1 Node 2 Node 3 . . .
Display area for the hierarchy
Optional area for displaying additional information (as table or list)
SAP AG 1999
All tree controls are structured in the same way. They display data in up to three areas. There is a display area for the hierarchy. There is a second structured area, in which data can be displayed as a table or list. The third area can contain headings above the two other areas.
The data displayed in the hierarchy area are called nodes. (We often refer to the entire line as a node.)
(C) SAP AG
BC412
6
28.7 Tree Control Implementation
Areas used
Control name
ABAP class
Unused
Headings
Additional info
Simple tree
cl_gui_simple_tree cl_simple_tree_model
Column tree
cl_gui_column_tree cl_column_tree_model
List tree
cl_gui_list_tree cl_list_tree_model
SAP AG 1999
There are three different tree control implementations. Each one uses the three areas illustrated above differently.
The simple tree only uses the hierarchy area. It has no headings, and cannot display any special structured data.
There are two tree control versions that use all three data areas: The column tree and the list tree. Each of these implementations structures its additional information differently.
Each tree control implementation has its own class in the class library:
cl_gui_simple_tree
for the Simple Tree
cl_gui_column_tree
for the Column Tree
cl_gui_list_tree
for the List Tree
From Release 4.6C onwards, there are three additional tree classes available:
cl_simple_tree_model
for the Simple Tree
cl_column_tree_model
for the Column Tree
cl_list_tree_model
for the List Tree
These classes have the same display attributes as the other three classes but contain an application tree in addition. For more details, see the last section in this unit.
(C) SAP AG
BC412
7
28.8 Simple Tree: Display Attributes
Root node First folder Node 1, folder 1 Node 2, folder 1
Node area
Hierarchy area Unused
Hierarchy area only No headings No additional information
SAP AG 1999
The Simple Tree only displays data in a hierarchy area. The data is displayed as texts by each node.
There are no headings and no additional information.
(C) SAP AG
BC412
8
28.9 Simple Tree: Node Structure
Hierarchy area Text can appear here Icon
Example:
Hierarchy text
Root node First folder Node 25,40 mm, folder 1 Node 2, folder 1 Any icon
SAP AG 1999
Nodes in a simple tree can consist of an icon and a text.
The node text is displayed to the right of the icon. The icon indicates where the node is positioned in the hierarchy.
You can use any icon and any text.
As a rule, you use folder symbols to indicate that the node has child nodes.
(C) SAP AG
BC412
9
28.10 Column Tree: Display Attributes
Hierarchy heading Column 2 Root node Root text 1 Entry 1 First folder Node 25,40 mm, folder 1 Node 2, folder 2 Leaf 2 column 2
Hierarchy area Column 1
Column 3 Root text 2 Entry ... Leaf 1 column 3 Leaf 2 column 3
Headings
Node area
Column area Column 2 - column n
Hierarchy area Headings Additional information as table (columns)
SAP AG 1999
The Column Tree uses the hierarchy area, headings, and the additional information area.
The data in the Column Tree is displayed as a table.
The contents of the first column are displayed in the hierarchy area. They appear left-justified next to the node.
All of the other columns are displayed in the additional information area. They are aligned vertically (displayed as a table).
Column tree displays can have column headings.
You can display more than one column in the hierarchy area (use the method add_hierarchy_column).
(C) SAP AG
BC412
10
28.11 Column Tree: Node Structure Hierarchy
Icon
Columns
Possible column entries (items) Text Text Text Link
: Icon + text : Checkbox + icon + text : Pushbutton with icon + text : Text as link + icon
SAP AG 1999
The nodes in the column tree can contain one icon.
You can display items in the columns as follows: As an icon with text (both are optional) As a checkbox with icon and text (icon and text are optional) As a checkbox with icon and text (icon and text are optional) As a link (text displayed as hotspot. The mouse pointer changes shape when it is positioned over a link.)
Do not use columns that display all of their items as pushbuttons. Instead, display the data as a link.
(C) SAP AG
BC412
11
28.12 List Tree: Display Attributes Hierarchy heading Objects Screens Screen 1 Screen 2 Programs Prog 1 Prog 2 Hierarchy area
Headings
List heading
0100 MUELLER Description of ... Description of ... 0200 JONES
Node area
SAPTROX1 Description of ...SAPTROX1 SAPTRIXTROX Description of ... List area
Hierarchy area Headings Additional information as rows of list (variable line structure)
SAP AG 1999
Like the column tree, the list tree uses the hierarchy area, headings, and the additional information area (to display items).
Unlike the Column Tree, however, the List Tree does not have a uniform line structure for its items, so they are not displayed in tabular form. Each line (node) can have a different structure. The items are displayed sequentially after each node.
When you display text in a List Tree, you can specify the font size for each item, along with whether the system should use a proportional or non-proportional font.
For each node, you can specify the number of items you want to display in the hierarchy area.
Both the hierarchy area and the list area can have separate headings.
(C) SAP AG
BC412
12
28.13 List Tree: Node Structure Hierarchy
Icon
List Possible list entries (items) Text Text Text Text as link
: Icon + text : Checkbox + icon + text : Pushbutton with icon + text : Text as link + icon
SAP AG 1999
The nodes in the column tree can contain one icon.
You can display the items of a node as follows: As an icon with text (both are optional) As a checkbox with icon and text (icon and text are optional) As a checkbox with icon and text (icon and text are optional) As a link (text displayed as hotspot. The mouse pointer changes shape when it is positioned over a link.)
Avoid excessive use of pushbuttons.
The List Tree allows you to choose between fixed font and proportional font for text items.
For items with a proportional font, use the Automatic length attribute.
(C) SAP AG
BC412
13
28.14 SAP Tree Control Overview: Constructor, Methods, and Events
Introduction:display display attributes attributes Introduction: TreeControl: Control:Constructor, Constructor,methods, methods,and andevents events Tree Creatingaahierarchy hierarchy Creating Itemtables tables Item Data handling handlingstrategies strategies Data
SAP AG 1999
(C) SAP AG
BC412
14
28.15 SAP Tree Control: Communication and Data Flow Tree Control
Display data
Data for display
Methods Data packet for display application and display info
Events Get number of selected rows or display info
Element name •Node •Heading •Column entry •List entry
ABAP program Application data and display information
Other data
SAP AG 1999
The control used at the frontend to display a Tree Control only displays the data. The proxy instance in ABAP has no data of its own. Consequently, all of the information necessary to display the tree (texts, icons, pushbuttons, checkboxes, and the descriptions of how they should be displayed) must be administered by the ABAP program that uses the control.
Normally, when a user interacts with a control, you must find out the application data that belongs to the node and its display information in your program.
(C) SAP AG
BC412
15
28.16 Modeling View of the Tree Classes cl_gui_control
cl_tree_control_base
cl_gui_simple_tree
cl_item_tree_control
cl_gui_column_tree
cl_gui_list_tree
SAP AG 1999
The three Tree Control classes cl_gui_simple_tree, cl_gui_column_tree, and cl_gui_list_tree are modeled as follows in the class library: All of the Tree Control classes are derived from cl_tree_control_base, which itself inherits from cl_gui_control. The class cl_gui_simple_tree inherits directly from cl_tree_control_base. The two classes cl_gui_column_tree and cl_gui_list_tree are subclasses of cl_item_tree_control, which inherits from cl_tree_control_base. Only the classes cl_gui_simple_tree, cl_gui_column_tree, and cl_gui_list_tree can be instantiated.
(C) SAP AG
BC412
16
28.17 SAP Tree Control Overview: Methods and events of the Simple Tree
Introduction:display display attributes attributes Introduction: TreeControl: Control:Constructor, Constructor,methods, methods,and andevents events Tree Simpletree tree Simple Columntree tree Column Listtree tree List Creatingaahierarchy hierarchy Creating Itemtables tables Item Data handling handlingstrategies strategies Data
SAP AG 1999
(C) SAP AG
BC412
17
28.18 Simple Tree: Constructor
DATA: my_tree TYPE REF TO cl_gui_simple_tree. ... CREATE OBJECT my_tree EXPORTING * lifetime = parent = * shellstyle = node_selection_mode = * hide_selection = EXCEPTIONS ...
Container reference Node selection: Single node (node_sel_mode_single) Multiple nodes (node_sel_mode_multiple) Highlight selected node(s): ' ' : Yes 'X' : No
SAP AG 1999
Optional parameters are indicated as ABAP comment lines.
The constructor allows you to set the general behavior of the tree. Node selection mode Highlighting of selected nodes when the focus changes at the front end.
(C) SAP AG
BC412
18
28.19 Simple Tree: Method Overview
Change attributes Create and change nodes Node Expand Select Delete Change the attributes Set up keyboard-triggered events Other methods Find out attributes Node attributes
SAP AG 1999
The methods of the Simple Tree can be divided into methods that you use to change attributes and methods you use to find out the values of attributes in the frontend control.
The methods that you use to change the attributes include Methods that you use to create and change nodes Methods that you use to change individual nodes (expand, select, delete, change attributes) Methods that define the keys that can trigger an event Methods that you use to change general display attributes (such as the frame around the control area)
There is a set of methods that you can use to find out attributes of the control, including, for example, which nodes are selected or expanded.
For more information about the precise names of the methods and their interfaces, refer to the online documentation for the Simple Tree.
(C) SAP AG
BC412
19
28.20 Simple Tree: Event Overview
Node node_double_click
Double-click on a node
node_keypress
Node selected and key pressed
expand_no_children
User expanded a node that has no contents at the frontend
selection_changed
Selected node has changed
Context menu Drag and drop
SAP AG 1999
The Simple Tree has Events that are triggered by mouse operations on nodes Events that are triggered by drag and drop operations Events that are triggered by context menu operations
For details of the dependencies of the events, detailed information about their interfaces, and the names of their "event IDs", refer to the documentation for the Simple Tree.
(C) SAP AG
BC412
20
28.21 Constructor, Methods, and Events of the Column Tree
Introduction:display display attributes attributes Introduction: TreeControl: Control:Constructor, Constructor,methods, methods,and andevents events Tree Simpletree tree Simple Columntree tree Column Listtree tree List Creatingaahierarchy hierarchy Creating Itemtables tables Item Data handling handlingstrategies strategies Data
SAP AG 1999
(C) SAP AG
BC412
21
28.22 Column Tree: Constructor Container reference
DATA: my_tree TYPE REF TO cl_gui_column_tree. ... CREATE OBJECT my_tree EXPORTING * lifetime parent * shellstyle node_selection_mode * hide_selection item_selection hierarchy_column_name hierarchy_header EXCEPTIONS ...
Node selection: Single node (node_sel_mode_single) Multiple nodes (node_sel_mode_multiple) Highlight selected node(s): ' ' : Yes 'X' : No
= = = = = = = =
Can user select column items? 'X' : Yes ' ' : No Column name in hierarchy area Heading in hierarchy area (Structure, of type treev_hhdr)
SAP AG 1999
The constructor of the Column Tree allows you to set the following attributes (in addition to those we have already seen for the Simple Tree): Whether single items can be selected (parameter item_selection) Technical name of the column to be displayed in the hierarchy area The heading for the hierarchy area (text and displayed length)
(C) SAP AG
BC412
22
28.23 Column Tree: Method Overview Change attributes Creating, changing, and deleting column items and nodes Column items Node Columns Set up keyboard-triggered events Other methods Find out attributes Node Selected item Width of hierarchy heading Columns
SAP AG 1999
As well as the methods for changing and finding out node attributes, the Column Tree has methods that allow you to change or find out attributes of the following tree components: Columns Items Headings
For further information about the precise names of the methods and their interfaces, refer to the online documentation for the Column Tree.
(C) SAP AG
BC412
23
28.24 Overview: Methods for Changing Column Trees Column items Change individual items Select individual items Node Method overview
Expand Select Delete Change the attributes Columns Specifying the sequence Inserting, changing, deleting Change column attributes Hierarchy heading: Change the attributes
SAP AG 1999
The item methods can be divided into those that change individual items, and those with which you can select a single item.
For node operations, the Column Tree offers the same methods as the Simple Tree.
The following column operations are available: Changing the column sequence Inserting, changing, and deleting columns Changing column attributes Changing the attributes of the hierarchy heading
(C) SAP AG
BC412
24
28.25 Column Tree: Event Overview
Node Headings header_click
Click on column heading
Column items item_double_click
Click on an item
item_keypress
Item selected and key pressed
button_click
Click on a pushbutton
link_click
Click on a link
checkbox_change
Contents of a checkbox have changed
Context menu Drag and drop
SAP AG 1999
The Column Tree has the following events in addition to those of the Simple Tree: Mouse click on a column heading Events on items Keyboard event for seleted items Pushbutton event for item type pushbutton Click a link Click a checkbox
For details of the dependencies of the events, detailed information about their interfaces, and the names of their "event IDs", refer to the documentation for the Column Tree.
(C) SAP AG
BC412
25
28.26 SAP Tree Control Overview: Methods and Events of the List Tree
Introduction:display display attributes attributes Introduction: TreeControl: Control:Constructor, Constructor,methods, methods,and andevents events Tree Simpletree tree Simple Columntree tree Column Listtree tree List Creatingaahierarchy hierarchy Creating Itemtables tables Item Data handling handlingstrategies strategies Data
SAP AG 1999
(C) SAP AG
BC412
26
28.27 List Tree: Constructor Container reference Node selection: Single node (node_sel_mode_single) Multiple nodes (node_sel_mode_multiple) DATA: my_tree TYPE REF TO cl_gui_list_tree. ... CREATE OBJECT my_tree EXPORTING * lifetime = parent = * shellstyle = node_selection_mode = * hide_selection = item_selection = with_header = hierarchy_header = list_header = EXCEPTIONS ...
Highlight selected node(s): ' ' : Yes 'X' : No Can user select list items? 'X' : Yes ' ' : No Use column headings 'X' : Yes ' ' : No Heading in hierarchy area (Structure, of type treev_hhdr) Heading in list area (Structure, of type treev_lhdr)
SAP AG 1999
The List Tree allows you to set headings for the hierarchy area and the list area.
(C) SAP AG
BC412
27
28.28 List Tree: Method Overview Change attributes Creating, changing, and deleting list items and nodes List items Node Hierarchy heading List heading Set up keyboard-triggered events Other methods Find out attributes Node Selected item Width of hierarchy heading
SAP AG 1999
The List Tree has the same methods as the Column Tree.
For further information about the precise names of the methods and their interfaces, refer to the online documentation for the List Tree.
(C) SAP AG
BC412
28
28.29 List Tree: Overview of Modifying Methods List items Change individual items Select individual items Node
Method overview
Expand Select Delete Change the attributes
SAP AG 1999
Since the List Tree displays its additional node information in a list instead of columns, the List Tree does not have the methods applied to columns that the Column Tree has.
(C) SAP AG
BC412
29
28.30 List Tree: Event Overview
Node Headings header_click
Click on column heading
List items item_double_click
Click on a list item
item_keypress
Item selected and key pressed
button_click
Click on a pushbutton
link_click
Click on a link
checkbox_change
Contents of a checkbox have changed
Context menu Drag and drop
SAP AG 1999
The List Tree has the same events as the Column Tree.
For details of the dependencies of the events, detailed information about their interfaces, and the names of their "event IDs", refer to the documentation for the List Tree.
(C) SAP AG
BC412
30
28.31 SAP Tree Control Overview: Creating a Hierarchy
Introduction:display display attributes attributes Introduction: TreeControl: Control:Constructor, Constructor,methods, methods,and andevents events Tree Creatingaahierarchy hierarchy Creating Itemtables tables Item Data handling handlingstrategies strategies Data
SAP AG 1999
(C) SAP AG
BC412
31
28.32 Objective: Display Data in a Simple Tree Control GUI control: simple tree
"Logical tree"
Airline carrier American Airlines Lufthansa 0400: FRA -> NYA
Airline carrier American Airlines Lufthansa 0400: FRA -> NYA
Depiction
Structured
Content
Texts
information (Hierarchy) Folder/node - Icons - Can be expanded
SAP AG 1999
The purpose of this section is to show you how to display data using a simple tree control.
To do this, we must tell the system: the tree control proxy class, the texts it is to contain, and how to display them.
(C) SAP AG
BC412
32
28.33 Simple Tree: Control Data Tree Control Data for display DATA: itab TYPE TABLE OF struc. Data packet for display + display information
CALL METHOD my_tree->add_nodes EXPORTING node_table = itab table_structure_name = struc EXCEPTIONS ...
ABAP program Application data Other data
Line type of internal table (item_itab) Structure in the ABAP Dictionary
SAP AG 1999
To display hierarchically-related data in a simple tree, you must send the texts you want to display to the front end along with information about the hierarchy. You use the add_nodes method to do this.
In the add_nodes method, use the node_table parameter to pass an internal table containing the data you want to display.
You must define the internal table with reference to a structure that you have defined in the ABAP Dictionary. You pass the name of this structure using the parameter table_structure_name.
(C) SAP AG
BC412
33
28.34 Line Structure of the Node Table treev_node SAP structure treev_node node_key relatkey relatship hidden disabled isfolder n_image exp_image style last_hitem no_branch expander dragdropid
text
Structure in the ABAP Dictionary
Freely-defined text field
Line structure for node attributes Node name (must be unique at the front end) Name of a node to which the node is related Type of relationship between node_key and relatkey. Flag: Node invisible yes/no Flag: Node cannot be selected yes/no Flag: (Folder) node can have subnodes yes/no Icon name for non-expanded nodes Icon name for non-expanded nodes Node style Number of last list entry in the hierarchy area (List Tree only) Flag: Switch off line linking nodes yes/no Flag: Make '+' sign appear for empty folders yes/no ID for drag and drop operations
SAP AG 1999
To specify the type of the node table, you first need to create a structure in the ABAP Dictionary.
In this structure, you must include the Dictionary structure treev_node (provided by SAP). You can use the fields in this structure to set the attributes of the nodes in the node table.
As well as including treev_node, you must add a field to your structure with the type CHAR. You will use this to pass the node text to the control.
The node_key field contains the technical name under which the node is identified at the frontend. This technical name must be unique within the entire hierarchy.
The three fields node_key, relatkey, and relatship determine the position of the node in the hierarchy.
For each node (node_key) that you send to the control, you must specify its relationship (relatship) to an existing node in the control (relatkey).
The no_branch field has no effect in the new SAP visual design.
(C) SAP AG
BC412
34
28.35 Filling the Node Table Airline Texts
American Airlines Lufthansa 0400: FRA -> NYA Hierarchy
Node table node_key
relatkey
ROOT
isfolder
c_last_child
X
AA
ROOT
c_last_child
X
LH
ROOT
c_last_child
X
LH_0400
LH
c_last_child
relatship isfolder
expander
text Airline
X
American Airlines Lufthansa 0400: FRA -> NYA
c_last_child = cl_gui_simple_tree=>relat_last_child 'X' =
expander 'X' =
relatship
,
''= ''=
SAP AG 1999
The columns specified above must be filled in the node table.
The first three fields determine the position of the node in the hierarchy.
The node texts are transferred using the entries in the text column.
The isfolder column specifies whether the node is to displayed as a folder ('X') or an endnode (' ').
The expander column allows you to specify that an empty folder should still be displayed with a plus sign (implying that it can be expanded). Example (see slide): The airline American Airlines does not have any subnodes, but is displayed as expandable. (Subnodes can then be filled subsequently with the event handler).
(C) SAP AG
BC412
35
28.36 Node Relationships (1) relatkey
relatship
before
node_key
after
first_child
last_child
SAP AG 1999
You can insert a node either as the first subnode of the reference node, or as the last subnode.
You can use the following static constants with the relatship field: cl_tree_control_base=>relat_first_child cl_tree_control_base=>relat_last_child
(C) SAP AG
BC412
36
28.37 Node Relationships (2) relatkey
relatship
node_key
before
after
prev_sibling
next_sibling
SAP AG 1999
You can insert a node directly before or after the reference node at the same hierarchy level.
You can use the following static constants with the relatship field: cl_tree_control_base=>relat_prev_sibling cl_tree_control_base=>relat_next_sibling
(C) SAP AG
BC412
37
28.38 Node Relationships (3) relatkey
relatship
node_key
before
after
first_sibling
last_sibling
SAP AG 1999
You can insert a node as the first or last node in a the hierarchy level of the reference node.
You can use the following static constants with the relatship field: cl_tree_control_base=>relat_first_sibling cl_tree_control_base=>relat_last_sibling
(C) SAP AG
BC412
38
28.39 Passing the Node Table to the Front End
Airline American Airlines Lufthansa Qantas Airlines SAP GUI
add_nodes ABAP Programm ROOT
...
Airline carrier
QA
ROOT
first_child
...
Qantas Airlines
LH
ROOT
first_child
...
Lufthansa
AA
ROOT
first_child
...
American Airlines
node_ node_key
relatkey
relatship
...
text
Node table
SAP AG 1999
You should note the following points when constructing a node table: The entries in the node table are processed at the front end in the order in which they appear in the internal table (that is, the order in which you filled the table). This means that the reference node relatkey for a given node node_key must already have been declared in the table. If you send the reference node to the front end in the same data packet as the new node, it must occur before the new node in the node table. For the top-level root node, you must leave the fields relatkey and relatship empty. The relationships specified in the node table are not absolute; they only apply to that particular row of the table.
(C) SAP AG
BC412
39
28.40 Sending Large Volumes of Data on Request from the User ABAP program + Basis services
Tree Control (front end) Data for root node
User expands node
Event: expand_no_children Data for first hierarchy level
User expands node
Construct control Basic settings
Read data from DB
Event: expand_no_children Data for next hierarchy level
Read data from DB
for expanded node
SAP AG 1999
To minimize the amount of data that has to be passed between the frontend and the application server, you should only send data to the tree when the user requests it.
If the user expands a folder, the frontend control reacts as follows: If there is no data at the frontend for the lower-level nodes, the control triggers the event expand_no_children. A node can always be expanded if its EXPANDER attribute has the value 'X'. If the data has already been sent to the frontend, the control can expand the folder itself.
(C) SAP AG
BC412
40
28.41 SAP Tree Control Overview: Item Tables
Introduction:display display attributes attributes Introduction: Treecontrol: control: methods methodsand and events events Tree Creatingaahierarchy hierarchy Creating Itemtables tables Item Data handling handlingstrategies strategies Data
SAP AG 1999
(C) SAP AG
BC412
41
28.42 Objective: Display Data in a Column Tree Control GUI control: column tree Flight information Airline American Airlines Lufthansa 0400: FRA -> NYA
Details 20 flights 15 flights Frankfurt -> New York
Logical tree Flight information
Headings
Details
Airline carrier American Airlines
20 flights
Lufthansa
15 flights
0400: FRA -> NYA
Hierarchy
Frankfurt -> New York
Column 1
Column 2
SAP AG 1999
The purpose of this section is to show you how you would display the above data using a column tree control.
The following information must be passed to the column tree control: Headings, if they are to be used The data to be displayed (nodes and item texts), as the content of columns. Information on the hierarchy structure.
(C) SAP AG
BC412
42
28.43 Sending Column or List Items Tree Control or
Data for Data
DATA: item_itab TYPE TABLE OF struc. Data packet for display + display information
1 2
CALL METHOD my_tree->add_nodes_and_items EXPORTING node_table = node_itab item_table = item_itab table_struc_name = struc EXCEPTIONS ...
ABAP program application data Other data
Line type of internal table (item_itab) Structure in the ABAP Dictionary
SAP AG 1999
If you want to display data in a Column Tree or List Tree, you need to pass another table to the control containing data about the items in the control. This is called the item table. You use the add_nodes_and_items method to do this.
In the add_nodes_and_items method, pass the node table in the node_table parameter and the item table in the item_table parameter.
The node table of a Column Tree or List Tree must have the line type treev_node.
The item table must have a line type that is based on a structure in the ABAP Dictionary.
(C) SAP AG
BC412
43
28.44 Line Structure of the Item Table treev_item
text
SAP structure treev_item
Structure in the ABAP Dictionary
Freely-defined text field Line structure for node attributes
node_key Node name (must be unique at the front end) item_name Item name class Type of entry: Text, checkbox, pushbutton, link disabled Flag: Item cannot be selected yes/no editable Flag: Item can be changed yes/no hidden Flag: Entry invisible yes/no alignment Alignment (List Tree only) t_image Icon name chosen Flag: Checkbox is selected yes/no togg_right Obsolete ignore_imag Flag: Do not add width of icons and checkbox field Y/N usebgcolor List Tree only: Flag for background color of an item font, style, length, length_pix
SAP AG 1999
The structure that you have to create for the line type of the item table in the ABAP Dictionary must include the structure treev_item. This structure is delivered by SAP. You need to add a text field to the structure.
The node_key and item_name fields identify the item uniquely.
You assign an item to a node by entering the relevant node key in the node_key field.
You can only use the ignore_imag, usebgcolor, length, and length_pix fields with the List Tree.
The values in the class field specify the item type (text, pushbutton, checkbox, link). You can use the following static constants to assign them a type: item_class_text item_class_checkbox item_class_button item_class_link.
(C) SAP AG
BC412
44
28.45 Item Names in a Column Tree
Column name 'Column1'
Node name
'Column2' 'Column3'
'Column4'
Node1 Node2 Node3 Node4 Node5 Node6 Node7
Item specified by
Item specified by
node_key = 'Node6' item_name = 'Column1'
node_key = 'Node6' item_name = 'Column3'
SAP AG 1999
In a Column Tree, you specify the name of the column that should contain the item in the item_name field.
You must define the column names before you use them. To define a column, use the add_column method.
Items in the Column Tree are identified by their node name and column name (Coordinate system).
(C) SAP AG
BC412
45
28.46 The Node Table for the Column Tree Control Flight information
Details
Airline American Airlines
20 flights
Lufthansa
15 flights
0400: FRA -> NYA
Hierarchy
Node table node_key
relatkey
ROOT
relatship
isfolder
c_last_child
X
AA
ROOT
c_last_child
X
LH
ROOT
c_last_child
X
LH_0400
LH
c_last_child
relatship
Frankfurt -> New York
expander No texts X
--> Item table
c_last_child = cl_gui_simple_tree=>relat_last_child
SAP AG 1999
Information on the hierarchical structure of the nodes and on the node type (folder, endnode, and so on) are passed using a node table (as for a simple tree control).
Note that the node table for the column or list tree control does not have a text column. The texts displayed in the hierarchy area are the texts in the first column. They are transferred using an item table.
The node table for the column or list tree control has the line type TREEV_NODE.
(C) SAP AG
BC412
46
28.47 Columns in the Column Tree Control Flight information
Details
Airline American Airlines
20 flights
Lufthansa
15 flights
0400: FRA -> NYA Column1
Frankfurt -> New York Column2
h_header-heading = text-003. h_header-width = 40. CALL METHOD
CREATE OBJECT ref_tree EXPORTING ... hierarchy_column_name = 'Column1' 'Column1' hierarchy_header ...
= h_header h_header
ref_tree->add_column add_column EXPORTING name = 'Column2' name width = 50 header_text header_text = text-005 ...
SAP AG 1999
Before the items can be passed, you need to have created the columns for the column tree control.
The system creates the column in the hierarchy area when it instantiates the tree control proxy object. In the constructor interface, give the column a name using the hierarchy_column_name parameter ('Column1' in the example above). Use the hierarchy_header parameter to pass a structure containing other attributes of the column (heading text, column width, tool tip text,...).
You can also define other columns using the add_column method. Use the name, width and header_text interface parameters to specify a technical name, column width, and header text for the column.
(C) SAP AG
BC412
47
28.48 The Item Table in the Column Tree Control Flight info
Details
Airline American Airlines
20 connections
Lufthansa
15 connections
0400: FRA -> NYA
Item table node_key
Frankfurt -> New York
item_name
class
text
ROOT
Column1
c_text
Airlines
AA
Column1
c_text
American Airlines
LH
Column1
c_text
Lufthansa
LH_0400
Column1
c_text
0400: FRA -> NYA
ROOT
Column2
c_text
AA
Column2
c_text
20 connections
LH
Column2
c_text
15 connections
LH_0400
Column2
c_text
Frankfurt -> New York
SAP AG 1999
class
Texts for column 1 (Column1)
Texts for column 2 (column2)
c_text = cl_gui_simple_tree=>item_class_text
The item table contains the item texts that you want to display in the columns, stored in the column text.
You must fill the columns node_key, item_name, class and text with values.
You specify the item using node_key and item_name (the equivalents of x and y in a coordinates system).
The entries in the column field specify the item type (text, pushbutton, checkbox, or link). You can do this using the class constants item_class_text, item_class_button, item_class_checkbox and item_class_link (only texts are displayed in the above example).
(C) SAP AG
BC412
48
28.49 Creating a Column Tree: Sequence 1. Create instance CREATE OBJECT obj Assign column name to hierarchy area (and hierarchy heading) in hierarchy_column_name 2. Create columns CALL METHOD obj->add_column Column name (name) Heading (header_text)
Further columns
3. Fill node table
Define node table with reference to treev_node
4. Fill item table 5. Send data CALL METHOD obj->add_nodes_and_items Node table (node_table) Item table (item_table)
SAP AG 1999
(C) SAP AG
BC412
49
28.50 Item Names in a List Tree
Item names: Items are numbered
Node name
Node1 Node2 Node3 Node4 Node5 Node6 Node7
1
2 1 1 1 1 2 3 1 1
3
4
5
2 2
3
4 2
3
4
5 5
Item specified by Item specified by
node_key = 'Node6' item_name = '2'
node_key = 'Node6' item_name = '1'
SAP AG 1999
The items in a List Tree are numbered sequentially for each node. Therefore, the item_name field contains the number of the item.
You identify items by their node name and item number.
(C) SAP AG
BC412
50
28.51 Creating a List Tree: Sequence 1. Create instance CREATE OBJECT obj Assign optional hierarchy heading (hierarchy_header) Assign optional list heading (list_header) 2. Fill node table
Define node table with reference to treev_node Specify number of items in hierarchy area for each node (last_hitem = number of last item in the hierarchy area)
3. Fill item table 4. Send data CALL METHOD obj->add_nodes_and_items Node table (node_table) Item table (item_table)
SAP AG 1999
(C) SAP AG
BC412
51
28.52 Demonstration Programs for Tree Control Programming Program name
Development class
SAPSIMPLE_TREE_CONTROL_DEMO SAPSIMPLE_TREE_CONTEXT_MEN_DEM SAPCOLUMN_TREE_CONTROL_DEMO SEU_TREE_CONTROL
SAPTLIST_TREE_CONTROL_DEMO SAPTLIST_TREE_CONTROL_DEMO_HDR SAPSIMPLE_TREE_DRAG_DROP_DEMO RSDEMO_DRAG_DROP_TREE_MULTI
SDW4
RSDEMO_DRAG_DROP_EDIT_TREE
SAP AG 1999
SAPSIMPLE_TREE_CONTROL_DEMO: Example program: implementing a simple tree.
SAPSIMPLE_TREE_CONTEXT_MEN_DEM: Example program: implementing a context menu in a simple tree.
SAPCOLUMN_TREE_CONTROL_DEMO: Example program: implementing a column tree.
SAPTLIST_TREE_CONTROL_DEMO: Example program: implementing a list tree.
SAPTLIST_TREE_CONTROL_DEMO_HDR: Example program: implementing a list tree with headings.
SAPSIMPLE_TREE_DRAG_DROP_DEMO: Example program: implementing Drag&Drop in tree control applications. It shows two simple tree control instances with single line selection.
RSDEMO_DRAG_DROP_TREE_MULTI: Example program: implementing Drag&Drop in tree control applications using multiple selections.
RSDEMO_DRAG_DROP_EDIT_TREE: Example program: implementing Drag&Drop between a tree control and a TextEdit control.
(C) SAP AG
BC412
52
28.53 Data Handling Strategy for 4.6A/B
Introduction:display display attributes attributes Introduction: Treecontrol: control: methods methodsand and events events Tree Creatingaahierarchy hierarchy Creating Itemtables tables Item Data handling handlingstrategies strategies Data Release 4.6A/B 4.6A/B Release FromRelease Release 4.6C 4.6C From
SAP AG 1999
(C) SAP AG
BC412
53
28.54 Tree Events and Node Keys Nodes
Tree Control
node_double_click
Data for display
node_keypress
event
expand_no_children selection_changed
Node Keys
Column items item_double_click item_keypress button_click ABAP program
link_click
Convert key for application application data
checkbox_change Context menu
SAP AG 1999
Remember - The Tree Control itself does not manage any application data.
Nearly all events return the node key of the node affected by the event.
In your ABAP program, you must process this node key to find out which data record is affected.
(C) SAP AG
BC412
54
28.55 Node Keys Tree Control instance node_key Node table node_table
CHAR 12 add_nodes ABAP program Internal table with application data for hierarchy level n Internal table with application data for hierarchy level n+1
SAP AG 1999
The structure of the data that you display in the Tree Control is usually determined by the hierarchical structure of the application data you want to display.
You will often read data into an internal table in your program and give the internal table the same key as the underlying database tables.
The node key (node_key field in the node table) for the Tree Control is a character field (type CHAR) with length 12.
The key for the application data that you want to display is normally shorter or longer than the node key. If it is shorter, you will not have any problems. However, you should make sure in either case that there is a 1-1 relationship between the application keys and the node keys.
(C) SAP AG
BC412
55
28.56 Storing Node Information: Strategy A Tree control instance add_nodes ABAP program Node table node_table
Program logic Application key
Node key An internal table
application data
Data for node table
SAP AG 1999
There are various ways of managing node information in your program.
Strategy A: Save the node-specific information (at least the node key) in the same internal table as the application data. The node key is then an alternative key for the table entries.
(C) SAP AG
BC412
56
28.57 Storing Node Information: Strategy B Tree control instance add_nodes ABAP program Node table node_table
Program logic
Internal table for key mapping application data
Application key
Node key
SAP AG 1999
Strategy B: Separate the node information from the application data and store each type of information in a separate table. You need at least one table for the key mapping (application key node key).
(C) SAP AG
BC412
57
28.58 Storing Node Information: Implementation Idea for Strategy B Service object
Internal table for key mapping
Mapping instance
Implemented as object
Application key
business_key
Node key
htab1 htab2 insert_node delete_node get_business_key get_node_key ...
htab1: Hash table wiht key: business_key
node_key
htab2: Hash table with key: node_key
SAP AG 1999
You will normally need to access the key mapping table using both application keys and node keys.
A good solution in terms of performance is to use two hashed tables. You must maintain both tables separately. The advantage is a constant access time, regardless of how many table entries there are and which key you use.
It is a good idea to administer the tables in a separate class that encapsulates all of the technical details and which provides the user with methods for key access. This separates the key mapping problem from the actual management of the application data. The auxiliary class that you use for key mapping can also be used for other functions that you want to separate from the tree display itself, such as adding drag and drop functions.
(C) SAP AG
BC412
58
28.59 Example of Flight Bookings Tree
Flight booking hierarchy cl_gui_simple_tree Data Methods expand_no_children node_double_click
cl_bc412_mapping _4_2_tree Data for key mapping Methods
cl_bc412_flight_info_tree1
Displays flight booking data in a hierarchy (SCARR, SPFLI, SFLIGHT, SBOOK) Reads the data requested by the user from the database and buffers it in the program Allows access to the buffered flight data using methods Returns the event node_double_click with application key
Flight booking and auxiliary data Methods that publish information about flight data externally node_double_click
SAP AG 1999
The BC412 training material contains an example for the model illustrated on the previous graphics: It is implemented as a global class that "wraps" a Simple Tree along with the data displayed in it. The class "wraps" the tree-specific handling and the corresponding application data.
The class administers data from the flight data model used in ABAP training (tables SCARR, SPFLI, SFLIGHT, SBOOK), and displays them in a simple tree.
Each instance of the local class is responsible for managing the data of the nodes that are displayed.
The object returns the node_double_click tree event to the user. However, it first converts the technical node key into the corresponding application key, which is more useful to the application program.
(C) SAP AG
BC412
59
28.60 Example of Using the Flight Booking Tree (1): Modularization
lcl_event_handler on_node_double_click o1: cl_bc412_flight_info_tree1 Flight booking data
o2: cl_gui_docking_container
auxiliary data
Methods that publish information about flight data externally
0100: Screen Screen data
node_double_click
sapbc412...: ABAP program auxiliary data
Screen data
SAP AG 1999
The graphic illustrates the structure of the example program.
It shows which instances communicate with each other, and how each instance is created.
(C) SAP AG
BC412
60
28.61 Example of Using the Flight Booking Tree (1): Screen Structure Flight Information System Airline carrier American Airlines 0017 New York --> San Francisco 0046 San Francisco --> New York Air Canada Air France
Flight Information System
Container control area displaying flight booking tree (SCARR, SPFLI, SFLIGHT, SBOOK)
Detail Information Airline carrier ID Airline carrier Currency
AA Amer... USD
Detail Information
Doubleclick
Screen to dock at: SCARR : 0102 SPFLI : 0103 SFLIGHT : 0104 SBOOK : 0105
SAP AG 1999
Application 1 for the flight booking tree - split screen: Flight booking tree on the left Detail screen on the right, containing details of the node selected in the tree. The user selects a node by double-clicking it.
The flight booking tree is displayed in a docking container. The detail screens are implemented as screens. There is one screen for each database table. The subscreen corresponding to the user's node selection is displayed on the container screen. (The docking control is re-linked to the new screen).
(C) SAP AG
BC412
61
28.62 Example: Using the Flight Booking Tree (1): Control Flow Tree Control
flight_info_tree
my_application
Screen
Expand node with info Expand node without info
expand_no_children Send data
Double-click node
Read and buffer data
node_double_click Get business key node_double_click Obtain detailed info
Analyze key (table)
Send detailed info PBO 100
SAP AG 1999
The diagram illustrates the control flow when the user interacts with the Tree Control at the front end.
(C) SAP AG
BC412
62
28.63 Example: Using the Flight Booking Tree (2) Flight Information System
Container control area displaying flight booking tree (SCARR, SPFLI, SFLIGHT)
Detail Information
DoubleDouble-click
Same functions. Hierarchical display Data retrieval on request from user Data managment (SCARR, SPFLI, SFLIGHT)
Custom Control area displaying Booking list in an ALV Grid Control
Features: Booking list displayedfor selected node: Bookings for a flight Bookings for a route Bookings for an airline
SAP AG 1999
Application 2 for the flight booking tree - split screen: A flight booking tree on the left containing nodes for the tables SCARR, SPFLI, and SFLIGHT. A detail screen on the right, displaying booking information as a list in the ALV Grid Control. The booking list is filled according to the user's selection in the tree. The user selects a node by double-clicking it.
(C) SAP AG
BC412
63
28.64 Overview: Data Transfer Strategy from Release 4.6C
Introduction:display display attributes attributes Introduction: TreeControl: Control:Constructor, Constructor,methods, methods,and andevents events Tree Creatingaahierarchy hierarchy Creating Itemtables tables Item Data handling handlingstrategies strategies Data Release 4.6A/B 4.6A/B Release FromRelease Release 4.6C 4.6C From
SAP AG 1999
(C) SAP AG
BC412
64
28.65 Tree Model Classes GUI tree SAP GUI asynchronous tests Application server Tree Control Proxy
Tree model object Administers 'application tree' and offers services synchronous tests
ABAP application
Properties: Print tree Search in tree No restrictions for node key Sends data to GUI tree when user requests it Node can reference any object ...
SAP AG 1999
From Release 4.6C onwards, there are three additional tree model classes available. They have the following properties: Tree model objects administer the data passed to them in an application tree. Tree model object interfaces use a string-type parameter for the node key and texts to be passed. This obviates the need for key mapping in ABAP application programming. Consistency checks (such as inserting a new node) are carried out synchronously on the tree model object interface. You can print the contents of the application tree. Tree model classes offer several methods for searching on the application tree. The tree model object administers data transfer from itself to the tree control. (Between the Tree Control and Tree Model EXPAND_NO_CHILDREN is used). For other properties, see the documentation on tree model classes.
Note: although you can print the application tree, the control used in the GUI can only display string type data formats. Therefore, the application program must format all data itself. If you want to print the application data already formatted, use the ALV Control.
(C) SAP AG
BC412
65
28.66 Modeling View of the Tree Classes Application hierarchy Basis ABAP Workbench cl_tree_model Inheritance hierarchy cl_tree_model
cl_simple_tree_model
cl_item_tree_model
cl_column_tree_model
cl_list_tree_model
SAP AG 1999
Three tree model classes that can be instantiated exist, similar to the tree control classes: cl_simple_tree_model, cl_column_tree_model and cl_list_tree_model. They encapsulate details of communication with the associated control classes. The model classes and control classes have the same display attributes.
(C) SAP AG
BC412
66
28.67 How the Tree Model Controls Data Flow Tree Control
Proxy
Tree model
ABAP program Data packet 1
Partial data User expands folder
Data E_N_C E_N_C
Data available
New data Data
User expands folder
E_N_C E_N_C
E_N_C Data packet 2
E_N_C = EXPAND_NO_CHILDREN
Data not available
SAP AG 1999
The tree model classes have the same events as the tree control classes.
The system triggers the EXPAND_NO_CHILDREN event if the tree control requests data for the subnodes of a folder (from the tree model) that the tree model does not have.
(C) SAP AG
BC412
67
28.68 SAP Tree Control: Unit Summary
You are now able to: Describe the features of the different tree control variants:
Attributes
Methods
Events
Display data in a tree control:
Create hierarchies
Use additional information (items)
SAP AG 1999
(C) SAP AG
BC412
68
28.69 Notes on Exercises There are four exercises in this chapter. Exercises 1,3, and 4 contain optional sections, which cover more advanced techniques. They are not essential to a basic understanding of the topics in the course. Note:
Exercises 1 and 2 pertain to tree control classes. They deal with fundamental procedures and concepts concerning communication with tree control instances.
Exercise 3 pertains to tree model classes (new from Release 4.6C).
Exercise 4 is completely optional. Participants should not attempt this exercise during the course unless there is time for them to complete it. It is more challenging than the other exercises, since it deals with concepts that are not explicitly handled in the courses. However, participants can complete it (with the help of the online documentation). Teaching participants to use the online documentation is one of the main objectives of this exercise.
Pay attention to the graphic on the next page. It tells you how to access node keys in all the exercises.
(C) SAP AG
BC412
69
28.70 Reading and Writing Node Keys Using a Structure
Using the structure mapping mapping carrid connid
node_key
read
LH 0400
LH_0400_____ write
Implementation of the ABAP program
Tree Control (proxy object + front end control)
Only structure fields mapping-carrid mapping-connid are interpreted
SAP AG 1999
In principle, the ABAP program always accesses the node key using a structure (mapping in the above example).
The implementation in the ABAP program interprets only the structure fields mapping-carrid and mapping-connid.
Examples: SCARR nodes: American Airlines carrid = 'AA ', connid = SPACE --> node_key = 'AA__________'. Lufthansa carrid = 'LH ', connid = SPACE --> node_key = 'LH__________'. SPFLI nodes: AA 0017: carrid = 'AA ', connid = SPACE --> node_key = 'AA__________'. LH 0400: carrid = 'LH ', connid = '0400' --> node_key = 'LH_0400_____'.
(C) SAP AG
BC412
70
28.71Exercise 1 Unit: SAP Tree Control Topic: Displaying Data in a Simple Tree Control
At the conclusion of this unit, you will be able to: Display Data in a Simple Tree Control
Display airlines (SCARR table) with their connections (SPFLI table) in an instance of a simple tree control. Use the fields CARRID and CONNID as the node key CARRID and CONNID. Create a structure containing both fields. Use this structure to read and write the node_key field. Note that the statements for data retrieval (into internal tables it_scarr and it_spfli) are included in the template. Program:
ZBC412_##_TRE_EX1
Template:SAPBC412_TRET_EXERCISE_1 Model solution: SAPBC412_TRES_EXERCISE_1 where ## is the group number 1-1
Copy the model solution SAPBC412_TRET_EXERCISE_1. and get to know how it works.
1-2
Create a tree control instance as follows: 1-2-1 In the declaration part of your program, create a reference variable for the tree control instance, with the same type as the class cl_gui_simple_tree (We suggest you use the name ref_tree). 1-2-2 In the init_control_processing module: Create a simple tree control object and link it with the docking container control. Users should only be able to select one node at a time. If an error occurs when the instance is being generated, your program should terminate, displaying the message 042 (from the message class BC412).
1-3
Copy the application data (the tables it_scarr and it_spfli) into a node table and send it to the tree control as follows: 1-3-1 In the declaration part of your program, create a node table, as an internal table with the name it_nodes (suggestion) and an appropriate work area
(C) SAP AG
BC412
71
with the name (wa_nodes (suggestion)). Use line type bc412_sim_tree_node_struc. 1-3-2 The node table will contain data from different tables (SCARR, SPFLI). Each node requires a unique key (node_key). Use the combination of the two fields carrid and connid as key fields for the nodes (the nodes of the table SCARR have an initial entry in the field connid). To simplify handling of the node key, create a structure containing the two fields carrid and connid (we suggest the name mapping). Use this structure to read and write the node_key field. 1-3-3 Fill the node table. The template already contains a subroutine call (for create_node_table) that fills the node table. Implement this subroutine. Use the following values for the three node types. The root node Field
Value
node_key
ROOT
relatkey
initial
relatship
initial
isfolder
'X'
expander
'X'
text
any (we suggest “Airlines”)
SCARR nodes: Copy wa_scarr to mapping (note that connid is initial) Field
Value
node_key
mapping
relatkey
?
relatship
Use relat_last_child
isfolder
'X'
expander
'X'
text
wa_scarr-carrname
SPFLI nodes: Copy wa_spfli to mapping Field
(C) SAP AG
Value
node_key
mapping
relatkey
?
relatship
Use relat_last_child
isfolder
initial
expander
initial BC412
72
text
wa_spfli-connid
1-3-4 Send the node table to the tree control using the method add_nodes. If errors occur, terminate processing and display the message 012 from the message class BC412. 1-3-5 Activate and test your program.
Use the class constant node_sel_mode_single to specify that the user can select only one line at a time in the tree control.
(C) SAP AG
BC412
73
Exercise 1 (Optional Sections) Unit: SAP Tree Control Topic: Displaying Data in a Simple Tree Control
At the conclusion of this unit, you will be able to: expand program-controlled nodes
Make sure that the root node is already expanded as soon as the user calls the program – the user should be able to see all the airlines from the start. Ensure also that the Connections node also shows the departure and arrival cities as well as the flight number (together as a single long text). Program:
same program
Template:SAPBC412_TRET_EXERCISE_1A Model solution: SAPBC412_TRES_EXERCISE_1A where ## is the group number 1-5
Make sure that the root node is displayed in its expanded form. Add the module init_control_processing, which will call the method expand_node for the root node. If errors occur, terminate processing and display the message 012 from the message class BC412.
1-6
Make sure that the node text for Connections node (SPFLI)includes the flight number, departure city, and arrival city. Use the ABAP language element CONCATENATE. For details on the syntax of this statement, see the online documentation.
(C) SAP AG
BC412
74
Exercise 2 Unit: SAP Tree Control Topic: Using Tree Control Events
At the conclusion of this unit, you will be able to: Send nodes to the tree control whenever the user requests them using the expand_no_children event.
Make sure that your program only sends nodes requested by the user to the frontend control, not all the nodes at once. Use the expand_no_children event.
Program:
ZBC412_##_TRE_EX1
Template:SAPBC412_TRET_EXERCISE_2 or your solution to the first task in Exercise 1. Model solution: SAPBC412_TRES_EXERCISE_2 where ## is the group number 2-1
Copy the program SAPBC412_TRET_EXERCISE_2 or your solution to the first task in exercise 1.
2-2
The program should send the correct nodes to the tree control when the user requests them, using the expand_no_children event. Therefore you need an event handler method. 2-2-1 Find out about the interface to the expand_no_children event in the cl_gui_simple_tree class. 2-2-2 Define a local class (suggested name: lcl_event_handler) that contains a static method for handling the expand_no_children event declared in instances of the class cl_gui_simple_tree (suggested name: on_expand_no_children). 2-2-3 Implement the method as follows Use the interface parameter node_key to find out which node the user wants to expand. a) If the user has selected the root node, send all the airline nodes (it_scarr) to the Tree Control. Copy the appropriate source code from the subroutine create_node_table.
(C) SAP AG
BC412
75
b) If the user has selected an node, get the connections data associated with it (using a LOOP ...WHERE) and copy this data into a node table. Again, you can copy large sections of source code from the subroutine create_node_table. Send the new node to the tree control using the method add_nodes. If an error occurs, inform the user by displaying an information message (message 012 from the message class BC412). Alternatively, you could abort the program. 2-2-4 In the subroutine create_node_table, delete the sections of code that create the airline and connection nodes. This subroutine must create the root node only. 2-2-5 If you used the solution to the first exercise as a template, you should comment out or delete the statement calling the method expand_node in the module init_control_processing. 2-3
Register the event expand_no_children in the Control Framework (CFW) and register your static method in your tree control instance, as follows: 2-3-1 Registering the event in the CFW: a) Declare an internal table it_events for the method set_registered_events, along with its associated work area. Use the table type cntl_simple_events. Include the type group cntl. b) Extend the module init_control_processing as follows: Fill the internal table using the event ID of the event expand_no_children. Then send this internal table to your tree control object using the instance method set_registered_events. If errors occur, terminate processing and display the message 012 from the message class BC412. 2-3-2 Register the handler method in the tree control object. Extend the module init_control_processing by adding an appropriate SET HANDLER statement.
(C) SAP AG
BC412
76
Exercise 3 Unit: SAP Tree Control Topic: Displaying Data in a Simple Tree Model
At the conclusion of this unit, you will be able to: Display data from the tables SCARR (airlines), SPFLI (connections) and SFLIGHT (flights) hierarchically, using an instance of a simple tree model.
Display data from the tables SCARR (airlines), SPFLI (connections) and SFLIGHT (flights) hierarchically in a tree model. Use an instance of the class cl_simple_tree_model (not of the simple tree control). Program:
ZBC412_##_TRE_EX3
Template:SAPBC412_TRET_EXERCISE_3 or your solution to the first task in Exercise 1. Model solution: SAPBC412_TRES_EXERCISE_3
or
SAPBC412_TRES_EXERCISE_3_A
where ## is the group number 3-1
Copy the model solution SAPBC412_TRET_EXERCISE_3, assigning it the above name. and get to know how it works.
3-2
Create a tree model instance as follows: 3-2-1 In the declaration part of your program, create a reference variable for the simple tree model instance (We suggest you use the name ref_tree). Use the class cl_simple_tree_model to specify the type. 3-2-2 In the init_control_processing module: a) Create a simple tree model object: Users should only be able to select one node at a time. If an error occurs while the object is being generated, your program should terminate, displaying the message 043 (from the message class BC412). b) Link your tree model instance to the Docking Container: Use the method create_tree_control. If an error occurs, the program should terminate, displaying message 042 from the message class BC412.
(C) SAP AG
BC412
77
3-3
Send the data – buffered in the internal tables it_scarr, it_spfli and it_sflight – to your tree model instance. There are two ways of doing this: a) Send the node to the tree model using a node table (similar to the procedure for the simple tree control). There are two steps to this procedure: 1) Create the node table 2) Send the node table to the tree model instance. You use the add_nodes method to do this. b) Alternatively, send each node individually to the tree model instance using the method add_node: 3-3-1 If you are passing data using a node table, first create it in the declaration part of your program (suggested name: it_nodes). Use the type treemsnota. 3-3-2 In the subroutine create_node_table, encapsulate the procedure for creating a node table (or for passing each node individually using add_node) Use a structure to read and write the node keys (as for the simple tree control). In this scenario, the program should also display data from the table SFLIGHT. Therefore, the structure must also contain another key field – fldate. To do this, use the structure key_struc. Pass the data from the internal tables it_scarr, it_spfli and it_sflight to your tree model instance (similar to the procedure used in the simple tree control). Use the following values for the four node types. Root node Field
Value
node_key
ROOT
relatkey
initial
relatship
initial
isfolder
'X'
expander
'X'
text
any (we suggest “Airlines”)
SCARR nodes:
(C) SAP AG
Field
Value
node_key
struc_key
relatkey
?
relatship
Use relat_last_child
isfolder
'X' BC412
78
expander
'X'
text
wa_scarr-carrname
SPFLI nodes: Field
Value
node_key
key_struc
relatkey
?
relatship
Use relat_last_child
isfolder
'X'
expander
'X'
text
wa_spfli-connid
SFLIGHT nodes: Field
Value
node_key
key_struc
relatkey
?
relatship
Use relat_last_child
isfolder
' '
expander
' '
text
wa_sflight-fldate
3-3-3 If you are using a node table in the module init_control_processing, you must send it to the tree model instance using the method add_nodes. If errors occur, terminate processing and display the message 012 from the message class BC412. 3-3-4 Activate and test your program . 1) Use the class constant node_sel_mode_single to specify that the user can select only one line at a time in the tree control. 2) Use a type ‘C’ auxiliary variable (length: 10, suggested name: 1_help), so that the program can output the date contained in the field wa_sflight-fldate in the correct format. (You use the WRITE TO statement to write wa_sflight-fldate to the auxiliary variable, which you then send to the model). If you pass the node data to your tree model instance without a node table (using the add_node method), you will need a string-type auxiliary variable for each interface parameter (C) SAP AG
BC412
79
of the method add_node that has the type string. Type checks take place at the method interface.
(C) SAP AG
BC412
80
Exercise 3 (Optional Sections) Unit: SAP Tree Control Topic: Tree model: Printing and Searching At the conclusion of this unit, you will be able to: Format the contents of the tree model such that they can be printed. Search for a string in the tree model. Extend your program to display the flight data in such a way that:
Users can print the contents of the tree
Users can search for a string in the tree model. The program should select the node once it has found the relevant string
same program or ZBC412_##_TRE_EX4 Program:
Template:SAPBC412_TRET_EXERCISE_3_B or your solution to the first task in Exercise 3. Model solution: SAPBC412_TRES_EXERCISE_3_B where ## is the group number 3-4
Either continue editing your program from task 3 or copy the template SAPBC412_TRET_EXERCISE_3_B.
3-5
Extend the program’s user interface to include the functions Print, Find, and Find next. Open the GUI status for screen 0100. Create the three functions and assign them to the usual pushbuttons in the standard toolbar. Use the following function attributes: Print
(C) SAP AG
Attribute
Value
Function code
PRINT
Function type
' '
Text
Print
Assigned to icon
ICON_PRINT
BC412
81
Find Attribute
Value
Function code
SEARCH
Function type
' '
Text
Find
Assigned to icon
ICON_SEARCH
Find next
3-6
Attribute
Value
Function code
SEARCH_NEXT
Function type
' '
Text
Find next
Assigned to icon
ICON_SEARCH_NEXT
Implement the appropriate functions in the module user_command_0100. 3-6-1 PRINT function: Use the method print_tree of your tree model instance to print the contents of the tree. Read the online documentation to learn more about the method interface. Use the preview mode for printing. Print only the nodes that the user can see on the screen. If errors occur, terminate processing of the method and display the message 012 from the message class BC412. Activate and test your program (the function). 3-6-2 SEARCH function: Use the method find of your tree model instance to search the contents of the tree. Read the online documentation to learn more about the scope and interface of the method. Create auxiliary variables that will receive the interface parameters. Assign appropriate global types to these auxiliary variables (Dictionary objects or class constants). The program should display the appropriate node as selected, once it finds the string. For a suitable method for doing this, refer to the online documentation. If none of the node texts match the search string, inform the user of this by displaying message 070 of the message class BC412. Activate and test your program (the function). If the user performs several searches, you must make sure that the selected node from the previous search is no longer highlighted. For a suitable method for doing this, refer to the online documentation. 3-6-3 SEARCH_NEXT function: Use the method find_next of your tree model instance to search the tree for the next node containing the search string. Read the online documentation to learn more about the scope and
(C) SAP AG
BC412
82
interface of the method. Decide whether you want to use the auxiliary variables you created for the search function, or whether you want to create new ones. If you decide to create new ones, remember that these must be appropriately typed. The program should display the appropriate node as selected, once it finds the string. Use the same method as you did to implement the SEARCH function. If none of the node texts match the search string, inform the user of this by displaying message 071 of the message class BC412. Activate and test your program (the function).
(C) SAP AG
Note that in some circumstances you will need auxiliary variables of type string if they are used in conjunction with method interface parameters of type string.
Use the class constants find_match, find_no_match, find_expander_node_hit and find_canceled of the cl_simple_tree_model class, to implement return codes for the methods find and find_next.
BC412
83
Exercise 4 (Optional) Unit: SAP Tree Control Topic: Simple Tree Controls and Toolbar Controls
At the conclusion of this unit, you will be able to: Use instances of the application toolbar control Expand or collapse all the nodes in a simple tree-control instance using pushbuttons. Insert a button bar using your tree control from task 2. There should be two pushbuttons on this button bar – one to expand all the nodes in the tree and one to close them again.
Program:
ZBC412_##_TRE_EX4
Template:SAPBC412_TRET_EXERCISE_4 or your solution to the first task in Exercise 2. Model solution: SAPBC412_TRES_EXERCISE_4 where ## is the group number (4-1
Copy the model solution SAPBC412_TRET_EXERCISE_4 or your solution from task 2. If you are using the template, get to know how it works.
4-2
Split the container surface of your docking control vertically into two adjacent areas by assigning a splitter container to the docking container. These two cells in the docking container act as containers for the toolbar control (upper cell) and tree control (lower area): 4-2-1 Declare the following references: ref_splitter
Splitter control instance
ref_top
Reference variable for the upper cell
ref_bottom
Reference variable for the lower cell
4-2-2 Implement the splitter control instance. Extend the module init_control_processing as follows: Create a splitter-control-instance, which the program will display in the docking container. Use the interface parameters row = 2, column = 1. Assign the two cell references to the two reference variables ref_top and (C) SAP AG
BC412
84
ref_bottom using the method get_container. Use ref_bottom for your tree control instance. 4-2-3 Activate and test your program. 4-2-4 Configure the splitter to divide the two cells, so that the program controls its appearance. The toolbar control area should be much smaller than the tree control area. The user should not be able to change the size of these two areas. Set up these two areas using a subroutine (suggested name: configure_splitter_container) Call this subroutine after you have created the splitter container object. Use the following methods, using these values for the interface parameters: a) set_border border = cl_gui_cfw=>false b) set_row_mode mode = ref_splitter->mode_absolute c) set_row_height id = 1 height = 20 d) set_row_sash id = 1 type = ref_splitter->type_movable value = ref_splitter->false Refer to the online documentation for more information on these methods. If errors occur, terminate processing and display the message 012 from the message class BC412. 4-2-5 Activate and test your program. 4-3
Create and configure a toolbar control instance as follows: 4-3-1 Read the online documentation to learn more about the scope and programming model of the application toolbar control. 4-3-2 In the data declaration part of your program, create a reference variable for the toolbar control instance. 4-3-3 Extend the module init_control_processing as follows: a)Create a toolbar instance and assign the upper cell of the splitter container to it. b) Configure the toolbar by creating two pushbuttons for it using a subroutine. (Suggested name: configure_toolbar). In this subroutine, use the add_button method, assigning the following values to the interface parameters: Pushbutton 1 fcode
any (we suggest EXPAND_ALL)
icon
'@68@' (Explanation: ICON_EXPAND_ALL)
butn_type
cntb_btype_button
quickinfo
any (we suggest ‘Expand all’)
Pushbutton 2
(C) SAP AG
fcode
any
icon
'@69@' (Explanation: ICON_COLLAPSE_ALL) BC412
85
butn_type
cntb_btype_button
quickinfo
any (we suggest ‘Collapse all’)
To obtain more information on icons, use the iconshow program.
4-3-4 Activate and test your program. 4-4
Extend your program so that it reacts when the user clicks one of the two toolbar buttons: 4-4-1 Define a static event-handler method for suitable events of the toolbar instance. 4-4-2 In the method, implement the reaction to the two pushbuttons ‘Expand all’ and ‘Close all’. Use the online documentation to find appropriate tree control methods for doing this and call them. If errors occur, terminate processing and display the message 012 from the message class BC412. 4-4-3 Register the appropriate toolbar event in the CFW. Then register the static event handler method on the toolbar object. 4-4-4 Activate and test your program.
(C) SAP AG
BC412
86
Exercise 4 (Additional Optional Sections) Unit: SAP Tree Control Topic: Simple Tree Controls and Toolbar Controls
At the conclusion of this unit, you will be able to: Implement the function ‘Expand all nodes’ for your own application tree
In the model solution for Exercise 4, the system’s reaction when the user chose Expand all depended on which nodes had already been sent to the front end (navigation history). Modify your program so that when the user chooses Expand all the system expands all the nodes in the program. Program:
ZBC412_##_TRE_EX4A
Template:SAPBC412_TRET_EXERCISE_4A or your solution to the first task in Exercise 4. Model solution: SAPBC412_TRES_EXERCISE_4A where ## is the group number 4-5
Modify the implementation of the Expand all function so that the program starts by sending all the nodes that have not been sent to the tree control, and then expands all nodes. Question: What do you need to do to transfer all the nodes that have not yet been sent? Answer: You must be able to find out which nodes have not yet been sent. There are two ways of doing this: You obtain from the tree control the number of nodes that have been sent to it, or you can note in your program the information that ‘Node has already been sent’. You should use the second option, since it may improve performance: 4-5-1 Define a line type for each of the internal tables it_scarr and it_spfli. The line types must contain all the fields of the structures SCARR and SPFLI, along with an addition al Selected (yes/no) field (suggested name: SEND). (Note: use the INCLUDE STRUCTURE statement). Use the line type for each of the internal tables it_scarr and it_spfli.
(C) SAP AG
BC412
87
4-5-2 Fill the SEND field each time you send a node to the tree control (on_expand_no_children module). 4-5-3 Implement the send procedure for all other (unsent) nodes in the ‘Expand all’ function by calling a subroutine (send_rest_of_nodes). 4-5-4 Implement the send_rest_of_nodes subroutine. You can copy large parts of the method implementation on_expand_no_children. Note: Execute the loop using a WHERE clause: LOOP ... WHERE send IS INITIAL. 4-5-5 Activate and test your program.
(C) SAP AG
BC412
88
28.72 Model Solutions for the SAP Tree Control Unit
Notes on the model solutions for this chapter. The model solutions reproduce the statements for screen flow logic and ABAP programs that you need to include. The exercises in this chapter are designed so that several different programs, accompanying the content of each unit, can be developed from one template. To make the examples clearer, we do not reproduce all the code necessary for every model solution. Instead we:
Present the model solution for each new exercise.
Reproduce changed or new flow logic, subroutines, and modules only. Highlight in bold each statement that you need to add or change, to complete the exercise.
New task blocks (that is , new logical content) begin with Exercise 1, Exercise 3, and Exercise 4. We have reproduced the solutions to these tasks in their entirety. Note that Exercise 4 is optional. Completing it requires knowledge beyond the scope of this course. However, you can complete it using the online documentation. Whether or not you can do so during the course itself depends on the time available.
(C) SAP AG
BC412
89
Solutions to Exercise 1 Unit: SAP Tree Control Topic: Display Data in a Simple Tree
Model solution SAPBC412_TRES_EXERCISE_1
29Screen flow logic 30SCREEN 100 PROCESS BEFORE OUTPUT. MODULE status_0100. MODULE init_control_processing. * PROCESS AFTER INPUT. MODULE user_command_0100.
31ABAP program 32Data declarations REPORT
sapbc412_tres_exercise_1 MESSAGE-ID bc412.
DATA:
*
ok_code
TYPE sy-ucomm,
" command field
copy_ok_code
LIKE ok_code,
" copy of ok_code
control specific: object references ref_container TYPE REF TO cl_gui_docking_container, ref_tree
*
TYPE REF TO cl_gui_simple_tree,
internal tables it_scarr
TYPE SORTED TABLE OF scarr WITH unique KEY carrid,
it_spfli
TYPE SORTED TABLE OF spfli WITH unique KEY carrid connid,
*
work areas wa_scarr
(C) SAP AG
LIKE LINE OF it_scarr, BC412
90
wa_spfli *
LIKE LINE OF it_spfli,
*
tree: node table and work area it_nodes
TYPE TABLE OF bc412_sim_tree_node_struc,
wa_nodes
LIKE LINE OF it_nodes,
mapping structure BEGIN OF mapping, carrid
TYPE spfli-carrid,
connid
TYPE spfli-connid,
END OF mapping.
33ABAP program event blocks *
start of main program
START-OF-SELECTION. *
read data SELECT * FROM
scarr INTO TABLE it_scarr.
IF sy-subrc NE 0. MESSAGE a060(bc412). ENDIF. SELECT * FROM
spfli INTO TABLE it_spfli.
IF sy-subrc NE 0. MESSAGE a061(bc412). ENDIF. *
call carrier screen CALL SCREEN 100.
34Modules *&-----------------------------------------------------------------* *&
Module
STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *
GUI settings
*------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'SCREEN_0100'. SET TITLEBAR 'SCREEN_0100'. ENDMODULE.
" STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* (C) SAP AG
BC412
91
*&
Module
USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
implementation of function codes
*------------------------------------------------------------------* MODULE user_command_0100 INPUT. copy_ok_code = ok_code. CLEAR ok_code. CASE copy_ok_code. WHEN 'BACK' OR 'CANCEL' OR 'EXIT'. LEAVE PROGRAM. ENDCASE. ENDMODULE.
" USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
control related processings
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
create container CREATE OBJECT ref_container EXPORTING
*
SIDE
= DOCK_AT_LEFT
EXTENSION
= 200
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a010(bc412). ENDIF. *
create tree control CREATE OBJECT ref_tree EXPORTING parent
= ref_container
node_selection_mode
= ref_tree->node_sel_mode_single
EXCEPTIONS others
= 1.
IF sy-subrc 0. (C) SAP AG
BC412
92
MESSAGE a042(bc412). ENDIF. *
fill node table it_nodes PERFORM create_node_table.
*
send node table to tree control CALL METHOD ref_tree->add_nodes EXPORTING table_structure_name
= 'BC412_SIM_TREE_NODE_STRUC'
node_table
= it_nodes
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. *
event registration
* *
to be implemented later
* ENDIF. ENDMODULE.
" INIT_CONTROL_PROCESSING
OUTPUT
35Subroutines *&-----------------------------------------------------------------* *&
Form
CREATE_NODE_TABLE
*&-----------------------------------------------------------------* *
create node table
*------------------------------------------------------------------* *
no interface
*------------------------------------------------------------------* FORM create_node_table. * create root
node
CLEAR wa_nodes. wa_nodes-node_key
= 'ROOT'.
* wa_nodes-relatkey
= .
" special case, root has no
* wa_nodes-relatship
= .
" related entry
wa_nodes-isfolder
= 'X'.
wa_nodes-expander
= 'X'.
(C) SAP AG
BC412
93
wa_nodes-text
= text-001.
" carrier
INSERT wa_nodes INTO TABLE it_nodes. * create scarr nodes LOOP AT it_scarr INTO wa_scarr. CLEAR mapping. MOVE-CORRESPONDING wa_scarr TO mapping. wa_nodes-node_key
= mapping.
wa_nodes-relatkey
= 'ROOT'.
wa_nodes-relatship
= cl_gui_simple_tree=>relat_last_child.
wa_nodes-isfolder
= 'X'.
wa_nodes-expander
= 'X'.
wa_nodes-text
= wa_scarr-carrname.
" root node is parent
INSERT wa_nodes INTO TABLE it_nodes. ENDLOOP.
* create spfli nodes LOOP AT it_spfli INTO wa_spfli. CLEAR mapping. MOVE-CORRESPONDING wa_spfli TO mapping. wa_nodes-node_key
= mapping.
clear mapping-connid. wa_nodes-relatkey
= mapping.
" SCARR node is parent
wa_nodes-relatship
= cl_gui_simple_tree=>relat_last_child.
wa_nodes-isfolder
= ' '.
wa_nodes-expander
= ' '.
wa_nodes-text
= wa_spfli-connid.
INSERT wa_nodes INTO TABLE it_nodes. ENDLOOP. ENDFORM.
(C) SAP AG
" CREATE_NODE_TABLE
BC412
94
(C) SAP AG
BC412
95
Solutions to Exercise 1 (optional sections) Unit: SAP Tree Control Topic: Topic: Display Data in a Simple Tree
Model solution SAPBC412_TRES_EXERCISE_1A
36ABAP program 37Modules *&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
control related processings
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
create container CREATE OBJECT ref_container EXPORTING
*
SIDE
= DOCK_AT_LEFT
extension
= 200
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a010(bc412). ENDIF. *
create tree control CREATE OBJECT ref_tree EXPORTING parent
= ref_container
node_selection_mode
=
cl_gui_simple_tree=>node_sel_mode_single EXCEPTIONS others
= 1.
IF sy-subrc 0. (C) SAP AG
BC412
96
MESSAGE a042(bc412). ENDIF. *
fill node table it_nodes PERFORM create_node_table.
*
send node table to tree control CALL METHOD ref_tree->add_nodes EXPORTING table_structure_name
= 'BC412_SIM_TREE_NODE_STRUC'
node_table
= it_nodes
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. *
expand root node entry CALL METHOD ref_tree->expand_node EXPORTING node_key
= 'ROOT'
*
LEVEL_COUNT
=
*
EXPAND_SUBTREE
=
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. *
event registration
* *
to be implemented later
* ENDIF. ENDMODULE.
" INIT_CONTROL_PROCESSING
OUTPUT
38Subroutines *&-----------------------------------------------------------------* *&
Form
CREATE_NODE_TABLE
*&-----------------------------------------------------------------* (C) SAP AG
BC412
97
*
create node table
*------------------------------------------------------------------* *
no interface
*------------------------------------------------------------------* FORM create_node_table. * create root
node
CLEAR wa_nodes. wa_nodes-node_key
= 'ROOT'.
* wa_nodes-relatkey
= .
" special case, root has no
* wa_nodes-relatship
= .
" related entry
wa_nodes-isfolder
= 'X'.
wa_nodes-expander
= 'X'.
wa_nodes-text
= text-001.
" carrier
INSERT wa_nodes INTO TABLE it_nodes. * create scarr nodes LOOP AT it_scarr INTO wa_scarr. CLEAR mapping. MOVE-CORRESPONDING wa_scarr TO mapping. wa_nodes-node_key
= mapping.
wa_nodes-relatkey
= 'ROOT'.
wa_nodes-relatship
= cl_gui_simple_tree=>relat_last_child.
wa_nodes-isfolder
= 'X'.
wa_nodes-expander
= 'X'.
wa_nodes-text
= wa_scarr-carrname.
" root node is parent
INSERT wa_nodes INTO TABLE it_nodes. ENDLOOP.
* create spfli nodes LOOP AT it_spfli INTO wa_spfli. CLEAR mapping. MOVE-CORRESPONDING wa_spfli TO mapping. wa_nodes-node_key (C) SAP AG
= mapping. BC412
98
clear mapping-connid. wa_nodes-relatkey
= mapping.
" SCARR node is parent
wa_nodes-relatship
= cl_gui_simple_tree=>relat_last_child.
wa_nodes-isfolder
= ' '.
wa_nodes-expander
= ' '.
CONCATENATE wa_spfli-connid wa_spfli-cityfrom '->' wa_spfli-cityto INTO wa_nodes-text SEPARATED BY ' '. INSERT wa_nodes INTO TABLE it_nodes. ENDLOOP. ENDFORM.
(C) SAP AG
" CREATE_NODE_TABLE
BC412
99
Solutions to Exercise 2 Unit: SAP Tree Control Topic: Using Events of a Simple Tree Control
Model solution SAPBC412_TRES_EXERCISE_2
39ABAP program 40Data declarations * global types (type pools) TYPE-POOLS: cntl. DATA:
*
ok_code
TYPE sy-ucomm,
" command field
copy_ok_code
LIKE ok_code,
" copy of ok_code
control specific: object references ref_container TYPE REF TO cl_gui_docking_container, ref_tree
*
TYPE REF TO cl_gui_simple_tree,
internal tables it_scarr
TYPE SORTED TABLE OF scarr WITH UNIQUE KEY carrid,
it_spfli
TYPE SORTED TABLE OF spfli WITH UNIQUE KEY carrid connid,
*
*
*
work areas wa_scarr
LIKE LINE OF it_scarr,
wa_spfli
LIKE LINE OF it_spfli,
tree: node table and work area it_nodes
TYPE TABLE OF bc412_sim_tree_node_struc,
wa_nodes
LIKE LINE OF it_nodes,
mapping structure BEGIN OF mapping, carrid
TYPE spfli-carrid,
connid
TYPE spfli-connid,
END OF mapping,
(C) SAP AG
BC412
100
*
event table it_events
TYPE cntl_simple_events,
wa_events
LIKE LINE OF it_events.
41Local Classes *
local event handler class
CLASS lcl_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_expand_no_children FOR EVENT expand_no_children OF cl_gui_simple_tree IMPORTING node_key. ENDCLASS. *-----------------------------------------------------------------* *
CLASS lcl_event_handler IMPLEMENTATION
*-----------------------------------------------------------------* CLASS lcl_event_handler IMPLEMENTATION. METHOD on_expand_no_children. *
local data objects DATA: l_carrid
*
TYPE spfli-carrid.
clear global data object: it_nodes CLEAR: it_nodes, wa_nodes.
*
find out which node to expand: node_key IF node_key = 'ROOT'.
*
" root to expand
create scarr nodes LOOP AT it_scarr INTO wa_scarr. CLEAR mapping. MOVE-CORRESPONDING wa_scarr TO mapping. wa_nodes-node_key
= mapping.
wa_nodes-relatkey
= node_key.
wa_nodes-relatship
= cl_gui_simple_tree=>relat_last_child.
wa_nodes-isfolder
= 'X'.
wa_nodes-expander
= 'X'.
wa_nodes-text
= wa_scarr-carrname.
" root node is parent
INSERT wa_nodes INTO TABLE it_nodes. ENDLOOP. (C) SAP AG
BC412
101
ELSE. *
" SCARR node to expand
store carrier id MOVE node_key TO mapping. l_carrid = mapping-carrid.
*
create spfli nodes LOOP AT it_spfli INTO wa_spfli WHERE carrid = l_carrid. CLEAR mapping. MOVE-CORRESPONDING wa_spfli TO mapping. wa_nodes-node_key
= mapping.
wa_nodes-relatkey
= node_key.
wa_nodes-relatship
= cl_gui_simple_tree=>relat_last_child.
wa_nodes-isfolder
= ' '.
wa_nodes-expander
= ' '.
CONCATENATE wa_spfli-connid wa_spfli-cityfrom '->' wa_spfli-cityto INTO wa_nodes-text SEPARATED BY ' '. INSERT wa_nodes INTO TABLE it_nodes. ENDLOOP. ENDIF. *
send additional nodes to tree control CALL METHOD ref_tree->add_nodes EXPORTING table_structure_name
= 'BC412_SIM_TREE_NODE_STRUC'
node_table
= it_nodes
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE i012(bc412).
" error during method call
ENDIF. ENDMETHOD. (C) SAP AG
BC412
102
ENDCLASS.
42Modules *&----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&----------------------------------------------------------------* *
Control related processing
*-----------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
create container CREATE OBJECT ref_container EXPORTING
*
SIDE
= DOCK_AT_LEFT
extension
= 200
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a010(bc412). ENDIF. *
create tree control CREATE OBJECT ref_tree EXPORTING parent
= ref_container
node_selection_mode
= ref_tree->node_sel_mode_single
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a042(bc412). ENDIF. *
fill node table it_nodes PERFORM create_node_table.
*
send node table to tree control CALL METHOD ref_tree->add_nodes EXPORTING table_structure_name
= 'BC412_SIM_TREE_NODE_STRUC'
node_table
= it_nodes
(C) SAP AG
BC412
103
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. *
event registration
*
1. cfw wa_events-eventid = cl_gui_simple_tree=>eventid_expand_no_children. wa_events-appl_event = ' '. APPEND wa_events TO it_events. CALL METHOD ref_tree->set_registered_events EXPORTING events
= it_events
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. *
2. ABAP objects SET HANDLER lcl_event_handler=>on_expand_no_children FOR ref_tree. ENDIF.
ENDMODULE.
" INIT_CONTROL_PROCESSING
OUTPUT
43Subroutines *&-----------------------------------------------------------------* *&
Form
CREATE_NODE_TABLE
*&-----------------------------------------------------------------* *
fill node table with root node only
*------------------------------------------------------------------* *
no interface
*------------------------------------------------------------------* FORM create_node_table. * create root (C) SAP AG
node BC412
104
CLEAR wa_nodes. wa_nodes-node_key
= 'ROOT'.
* wa_nodes-relatkey
= .
" special case, root has no
* wa_nodes-relatship
= .
" related entry
wa_nodes-isfolder
= 'X'.
wa_nodes-expander
= 'X'.
wa_nodes-text
= text-001.
" carrier
INSERT wa_nodes INTO TABLE it_nodes. * rest is taken out here event handler ENDFORM.
(C) SAP AG
" CREATE_NODE_TABLE
BC412
105
Solutions to Exercise 3 Unit: SAP Tree Control Topic: Display Data in a Simple Tree Model
Model solution SAPBC412_TRES_EXERCISE_3
44Screen flow logic 45SCREEN 100 PROCESS BEFORE OUTPUT. MODULE status_0100. MODULE init_control_processing. * PROCESS AFTER INPUT. MODULE user_command_0100.
46ABAP program 47Data declarations REPORT
sapbc412_tres_exercise_3 MESSAGE-ID bc412.
TYPES: *
work area types BEGIN OF key_struc_ty,
" used to type all node_key fields
carrid TYPE s_carr_id,
"
carrier id
connid TYPE s_conn_id,
"
connection id
fldate TYPE s_date,
"
flight date
END OF key_struc_ty.
" all node_key use this structure
DATA:
*
ok_code
TYPE sy-ucomm,
" command field
copy_ok_code
LIKE ok_code,
" copy of ok_code
control specific: object references ref_container
TYPE REF TO cl_gui_docking_container,
ref_tree_model TYPE REF TO cl_simple_tree_model, *
internal tables it_scarr
(C) SAP AG
TYPE SORTED TABLE OF scarr BC412
106
WITH UNIQUE KEY carrid, it_spfli
TYPE SORTED TABLE OF spfli WITH UNIQUE KEY carrid connid,
it_sflight
TYPE SORTED TABLE OF sflight WITH UNIQUE KEY carrid connid fldate,
it_nodes
TYPE treemsnota.
48ABAP program event blocks START-OF-SELECTION. *
read data SELECT * FROM
scarr
INTO TABLE it_scarr ORDER BY carrid.
IF sy-subrc NE 0. MESSAGE a060(bc412). ENDIF. SELECT * FROM
spfli
INTO TABLE it_spfli ORDER BY carrid connid.
IF sy-subrc NE 0. MESSAGE a061(bc412). ENDIF. SELECT * FROM
sflight INTO TABLE it_sflight ORDER BY carrid connid fldate.
IF sy-subrc NE 0. MESSAGE a062(bc412). ENDIF.
*
call carrier screen CALL SCREEN 100.
49Modules *&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
control related processings
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
create container CREATE OBJECT ref_container EXPORTING
(C) SAP AG
BC412
107
*
SIDE
= DOCK_AT_LEFT
extension
= 200
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a010(bc412). ENDIF. *
create tree model (backend tree) CREATE OBJECT ref_tree_model EXPORTING node_selection_mode
*
HIDE_SELECTION
= ref_tree_model->node_sel_mode_single =
EXCEPTIONS illegal_node_selection_mode = 1 others
= 2
. IF sy-subrc 0. MESSAGE a043(bc412). ENDIF. *
create frontend control and link to container CALL METHOD ref_tree_model->create_tree_control EXPORTING parent
*
IMPORTING
*
CONTROL
= ref_container =
EXCEPTIONS lifetime_error
= 1
cntl_system_error
= 2
create_error
= 3
failed
= 4
tree_control_already_created = 5 OTHERS
= 6
. IF sy-subrc 0. MESSAGE a042(bc412). ENDIF.
*
fill node table it_nodes
(C) SAP AG
BC412
108
PERFORM create_node_table CHANGING it_nodes. *
send node table to tree control CALL METHOD ref_tree_model->add_nodes EXPORTING node_table
= it_nodes
EXCEPTIONS error_in_node_table = 1 OTHERS
= 2
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF.
*
event registration
* *
to be implemented later
* ENDIF. ENDMODULE.
" INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *&
Module
STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *
GUI settings
*------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'SCREEN_0100'. SET TITLEBAR 'SCREEN_0100'. ENDMODULE.
" STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *&
Module
USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
implementation of function codes of type ' '
*------------------------------------------------------------------* MODULE user_command_0100 INPUT. copy_ok_code = ok_code. CLEAR ok_code. CASE copy_ok_code. (C) SAP AG
BC412
109
WHEN 'BACK' OR 'CANCEL' OR 'EXIT'. LEAVE PROGRAM. ENDCASE. ENDMODULE.
" USER_COMMAND_0100
INPUT
50Subroutines *&-----------------------------------------------------------------* *&
Form
CREATE_NODE_TABLE
*&-----------------------------------------------------------------* *
create node table
*------------------------------------------------------------------* *
p_it_nodes TYPE treemsnota
node table
*------------------------------------------------------------------* FORM create_node_table CHANGING p_it_nodes TYPE treemsnota. * local data objects DATA: wa_nodes
LIKE LINE OF p_it_nodes,
wa_scarr
LIKE LINE OF it_scarr,
wa_spfli
LIKE LINE OF it_spfli,
wa_sflight LIKE LINE OF it_sflight, key_struc
TYPE key_struc_ty,
* auxiliary l_help(20). * create root
node
wa_nodes-node_key
= 'ROOT'.
" nodekey for root node
wa_nodes-relatkey
= space.
" special case, root node has no
wa_nodes-relatship
= space.
" parent
* wa_nodes-hidden
=
* wa_nodes-disabled
=
wa_nodes-isfolder
= 'X'.
" display as folder
* wa_nodes-n_image
=
" icon, folder not expanded
* wa_nodes-exp_image
=
" icon, folder expanded
* wa_nodes-style
=
* wa_nodes-no_branch
=
" GUI specific flag (docu)
= 'X'.
" expandable without a child
wa_nodes-expander
* wa_nodes-dragdropid =
" used for drag and drop
* wa_nodes-userobject =
" any object reference
wa_nodes-text
(C) SAP AG
= text-001.
" relat_last_child.
wa_nodes-isfolder
= 'X'.
wa_nodes-text
= wa_scarr-carrname. " carrier name
" display as folder
INSERT wa_nodes INTO TABLE it_nodes. ENDLOOP.
* create spfli
nodes
LOOP AT it_spfli INTO wa_spfli. MOVE-CORRESPONDING wa_spfli TO key_struc. wa_nodes-node_key
= key_struc.
" nodekey for spfli nodes
CLEAR: key_struc-connid, key_struc-fldate. " parent is "corresponding " carrid wa_nodes-relatkey
= key_struc.
" parent nodekey = carrid
wa_nodes-relatship
= cl_simple_tree_model=>relat_last_child.
wa_nodes-isfolder
= 'X'.
" display as folder
wa_nodes-text
= wa_spfli-connid.
" connection id
INSERT wa_nodes INTO TABLE it_nodes. ENDLOOP. * create sflight nodes LOOP AT it_sflight INTO wa_sflight. MOVE-CORRESPONDING wa_sflight TO key_struc.
(C) SAP AG
BC412
111
wa_nodes-node_key
= key_struc.
" nodekey for spfli nodes
CLEAR: key_struc-fldate.
" parent is corresponding " carrid + connid
wa_nodes-relatkey
= key_struc.
" parent = (carrid, connid)
wa_nodes-relatship
= cl_simple_tree_model=>relat_last_child.
wa_nodes-isfolder
= ' '.
" display as leaf
WRITE wa_sflight-fldate TO l_help.
" write with date format
wa_nodes-text
" copy to node text
= l_help.
INSERT wa_nodes INTO TABLE it_nodes. ENDLOOP. ENDFORM.
(C) SAP AG
" CREATE_NODE_TABLE
BC412
112
Alternative Solution to Exercise 3 Unit: SAP Tree Control Topic: Display Data in a Simple Tree Model
Model solution SAPBC412_TRES_EXERCISE_3_A
51ABAP program 52Data declarations REPORT
sapbc412_tres_exercise_3_a MESSAGE-ID bc412.
TYPES: *
work area types BEGIN OF key_struc_ty,
" used to type all node_key fields
carrid TYPE s_carr_id,
"
carrier id
connid TYPE s_conn_id,
"
connection id
fldate TYPE s_date,
"
flight date
END OF key_struc_ty.
" all node_key use this structure
DATA:
*
ok_code
TYPE sy-ucomm,
" command field
copy_ok_code
LIKE ok_code,
" copy of ok_code
control specific: object references ref_container
TYPE REF TO cl_gui_docking_container,
ref_tree_model TYPE REF TO cl_simple_tree_model, *
internal tables it_scarr
TYPE SORTED TABLE OF scarr WITH UNIQUE KEY carrid,
it_spfli
TYPE SORTED TABLE OF spfli WITH UNIQUE KEY carrid connid,
it_sflight
TYPE SORTED TABLE OF sflight WITH UNIQUE KEY carrid connid fldate.
*
it_nodes
TYPE treemsnota. node_sel_mode_single =
EXCEPTIONS illegal_node_selection_mode = 1 others
= 2
. IF sy-subrc 0. MESSAGE a043(bc412). ENDIF. *
create frontend control and link to container CALL METHOD ref_tree_model->create_tree_control EXPORTING parent
*
IMPORTING
*
CONTROL
= ref_container =
EXCEPTIONS
(C) SAP AG
lifetime_error
= 1
cntl_system_error
= 2
create_error
= 3
failed
= 4 BC412
114
tree_control_already_created = 5 OTHERS
= 6
. IF sy-subrc 0. MESSAGE a042(bc412). ENDIF. *
transfer nodes to model
no interface needed
PERFORM create_node_table." CHANGING it_nodes. *----taken out, not needed any longer---------------* **
send node table to tree control
*
CALL METHOD ref_tree_model->add_nodes
*
EXPORTING
*
node_table
*
= it_nodes
EXCEPTIONS
*
error_in_node_table = 1
*
OTHERS
*
.
*
IF sy-subrc 0.
*
= 2
*
MESSAGE a012(bc412). ENDIF.
*---------------------------------------------------*
event registration
* *
to be implemented later
* ENDIF. ENDMODULE.
" INIT_CONTROL_PROCESSING
OUTPUT
54Subroutines *&-----------------------------------------------------------------* *&
Form
CREATE_NODE_TABLE
*&-----------------------------------------------------------------* *
create node table
*------------------------------------------------------------------* *
no interface
*------------------------------------------------------------------* FORM create_node_table.
" CHANGING p_it_nodes TYPE treemsnota.
* local data objects (C) SAP AG
BC412
115
DATA: wa_scarr
LIKE LINE OF it_scarr,
wa_spfli
LIKE LINE OF it_spfli,
wa_sflight
LIKE LINE OF it_sflight,
*
several auxiliary variables with type STRING are needed
*
for the interface variables of method ADD_NODE l_node_key
TYPE key_struc_ty,
l_relatkey
TYPE key_struc_ty,
if_relatship TYPE treemsnodt-relatship VALUE cl_simple_tree_model=>relat_last_child, if_node_key
type treemsnodt-node_key,
if_relatkey
type treemsnodt-relatkey,
if_text
type treemsnodt-text,
* auxiliary l_help(20) * create root
TYPE c.
node
if_text = text-001.
" carrier
CALL METHOD ref_tree_model->add_node EXPORTING node_key
= 'ROOT'
" same fields as in a node
*
RELATIVE_NODE_KEY
=
" table with structure
*
RELATIONSHIP
=
" TREEMNOTAB
isfolder
= 'X'
text
= if_text
*
HIDDEN
=
*
DISABLED
=
*
STYLE
=
*
NO_BRANCH
=
expander
= 'X'
*
IMAGE
=
*
EXPANDED_IMAGE
=
*
DRAG_DROP_ID
=
*
USER_OBJECT
=
EXCEPTIONS node_key_exists
= 1
illegal_relationship
= 2
relative_node_not_found = 3 node_key_empty (C) SAP AG
= 4 BC412
116
OTHERS
= 5
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. * create scarr
nodes
LOOP AT it_scarr INTO wa_scarr. MOVE-CORRESPONDING wa_scarr TO l_node_key. if_node_key = l_node_key. if_relatkey = 'ROOT'. if_text
= wa_scarr-carrname.
CALL METHOD ref_tree_model->add_node EXPORTING node_key
= if_node_key
relative_node_key
= if_relatkey
relationship
= if_relatship
isfolder
= 'X'
text
= if_text
expander
= 'X'
EXCEPTIONS OTHERS
= 5
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. ENDLOOP.
* create spfli
nodes
LOOP AT it_spfli INTO wa_spfli. MOVE-CORRESPONDING wa_spfli TO l_node_key. l_relatkey-carrid = wa_spfli-carrid. if_node_key
= l_node_key.
if_relatkey
= l_relatkey.
if_text
= wa_spfli-connid.
CALL METHOD ref_tree_model->add_node (C) SAP AG
BC412
117
EXPORTING node_key
= if_node_key
relative_node_key
= if_relatkey
relationship
= if_relatship
isfolder
= 'X'
text
= if_text
expander
= 'X'
EXCEPTIONS OTHERS
= 5
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. ENDLOOP. * create sflight nodes LOOP AT it_sflight INTO wa_sflight. MOVE-CORRESPONDING wa_sflight TO: l_node_key, l_relatkey. CLEAR: l_relatkey-fldate. WRITE wa_sflight-fldate TO l_help. if_node_key = l_node_key. if_relatkey = l_relatkey. if_text
= l_help.
CALL METHOD ref_tree_model->add_node EXPORTING node_key
= if_node_key
relative_node_key
= if_relatkey
relationship
= if_relatship
isfolder
= ' '
text
= if_text
expander
= 'X'
EXCEPTIONS OTHERS
= 5
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF.
(C) SAP AG
BC412
118
ENDLOOP. ENDFORM.
(C) SAP AG
" CREATE_NODE_TABLE
BC412
119
Solutions to the Optional Sections of Exercise 3 Unit: SAP Tree Control Topic: Tree Model: Printing and Searching
Model solution SAPBC412_TRES_EXERCISE_3_B
55ABAP program 56Data declarations REPORT
sapbc412_tres_exercise_3_b MESSAGE-ID bc412.
TYPES: *
work are types BEGIN OF key_struc_ty, carrid TYPE s_carr_id, connid TYPE s_conn_id, fldate TYPE s_date, END OF key_struc_ty.
DATA:
*
ok_code
TYPE sy-ucomm,
" command field
copy_ok_code
LIKE ok_code,
" copy of ok_code
control specific: object references ref_container
TYPE REF TO cl_gui_docking_container,
ref_tree_model TYPE REF TO cl_simple_tree_model, *
internal tables it_scarr
TYPE SORTED TABLE OF scarr WITH UNIQUE KEY carrid,
it_spfli
TYPE SORTED TABLE OF spfli WITH UNIQUE KEY carrid connid,
it_sflight
TYPE SORTED TABLE OF sflight WITH UNIQUE KEY carrid connid fldate,
it_nodes
TYPE treemsnota,
it_nodekey
TYPE treemnotab,
(C) SAP AG
BC412
120
*
auxiliary fields
*
- printing help_string
*
TYPE string,
- searching l_result_type
LIKE cl_simple_tree_model=>find_match,
l_result_nodekey TYPE tm_nodekey.
57Modules *&-----------------------------------------------------------------* *&
Module
USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
implementation of function codes
*------------------------------------------------------------------* MODULE user_command_0100 INPUT. copy_ok_code = ok_code. CLEAR ok_code. CASE copy_ok_code. WHEN 'BACK' OR 'CANCEL' OR 'EXIT'. LEAVE PROGRAM. *
---------------------------------------------------------------WHEN 'PRINT'.
*
---------------------------------------------------------------help_string = text-002.
" print_tree EXPORTING all_nodes
= ''
title
= help_string
preview
= 'X'
EXCEPTIONS control_not_existing = 1 control_dead
= 2
cntl_system_error
= 3
failed
= 4
OTHERS
= 5
. IF sy-subrc 0. MESSAGE a012(bc412). (C) SAP AG
BC412
121
ENDIF. *
---------------------------------------------------------------WHEN 'SEARCH'.
* *
---------------------------------------------------------------1. unselect all selected nodes CALL METHOD ref_tree_model->unselect_all.
* *
2. find first occurence (including user dialog for search pattern) CALL METHOD ref_tree_model->find IMPORTING result_type
= l_result_type
result_node_key = l_result_nodekey . CASE l_result_type. WHEN cl_simple_tree_model=>find_match. *
a) a node that matches the search string
*
i) store result into itab (needed for method select_nodes) CLEAR it_nodekey. INSERT l_result_nodekey INTO TABLE it_nodekey.
*
ii) select the corrresponding node CALL METHOD ref_tree_model->select_nodes EXPORTING node_key_table
= it_nodekey
EXCEPTIONS multiple_node_selection_only = 1 error_in_node_key_table
= 2
OTHERS
= 3
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. WHEN cl_simple_tree_model=>find_no_match. *
b) no node is found MESSAGE s070(bc412).
* (C) SAP AG
070: no node with search string found BC412
122
WHEN cl_simple_tree_model=>find_expander_node_hit. *
c) node found is expandable
*
does not occur in our case WHEN cl_simple_tree_model=>find_canceled.
*
d) search dialog canceled
*
do nothing ENDCASE.
*
---------------------------------------------------------------WHEN 'SEARCH_NEXT'.
* *
---------------------------------------------------------------find next occurence of search string in tree model CALL METHOD ref_tree_model->find_next IMPORTING result_type
= l_result_type
result_node_key = l_result_nodekey . CASE l_result_type. WHEN cl_simple_tree_model=>find_match. *
a) another node matches the search string
*
i) store result into itab (needed for method select_nodes) INSERT l_result_nodekey INTO TABLE it_nodekey.
*
ii)select the corresponding nodes CALL METHOD ref_tree_model->select_nodes EXPORTING node_key_table
= it_nodekey
EXCEPTIONS multiple_node_selection_only = 1 error_in_node_key_table
= 2
OTHERS
= 3
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. WHEN cl_simple_tree_model=>find_no_match. *
b) no more node found
(C) SAP AG
BC412
123
MESSAGE s071(bc412). *
071: no more node with search string found WHEN cl_simple_tree_model=>find_expander_node_hit.
*
c) node found is expandable WHEN cl_simple_tree_model=>find_canceled.
*
d) search dialog canceled
*
do nothing ENDCASE. ENDCASE.
ENDMODULE.
" USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
control related processings
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
create container CREATE OBJECT ref_container EXPORTING
*
SIDE
= DOCK_AT_LEFT
extension
= 400
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a010(bc412). ENDIF. *
create tree model (backend tree) CREATE OBJECT ref_tree_model EXPORTING node_selection_mode = ref_tree_model->node_sel_mode_multiple
*
HIDE_SELECTION
=
EXCEPTIONS illegal_node_selection_mode = 1 others
= 2
. (C) SAP AG
BC412
124
IF sy-subrc 0. MESSAGE a043(bc412). ENDIF. *
create frontend control and link to container CALL METHOD ref_tree_model->create_tree_control EXPORTING parent
*
IMPORTING
*
CONTROL
= ref_container =
EXCEPTIONS OTHERS
= 6
. IF sy-subrc 0. MESSAGE a042(bc412). ENDIF. *
fill node table it_nodes PERFORM create_node_table CHANGING it_nodes.
*
send node table to tree control CALL METHOD ref_tree_model->add_nodes EXPORTING node_table
= it_nodes
EXCEPTIONS OTHERS
= 2
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF.
*
event registration
* *
to be implemented later
* ENDIF. ENDMODULE.
(C) SAP AG
" INIT_CONTROL_PROCESSING
BC412
OUTPUT
125
Solutions to Optional Exercise 4 Unit: SAP Tree Control Topic: Simple Tree Control and Toolbar Control
Model solution SAPBC412_TRES_EXERCISE_4
58Screen flow logic 59SCREEN 100 PROCESS BEFORE OUTPUT. MODULE status_0100. MODULE init_control_processing. * PROCESS AFTER INPUT. MODULE user_command_0100.
60ABAP program 61Data declarations REPORT
sapbc412_tres_exercise_4 MESSAGE-ID bc412.
* global types (type pools) TYPE-POOLS: cntl. DATA:
*
ok_code
TYPE sy-ucomm,
" command field
copy_ok_code
LIKE ok_code,
" copy of ok_code
control specific: object references ref_container TYPE REF TO cl_gui_docking_container,
*
ref_splitter
TYPE REF TO cl_gui_splitter_container,
ref_top
TYPE REF TO cl_gui_container,
ref_bottom
TYPE REF TO cl_gui_container,
ref_toolbar
TYPE REF TO cl_gui_toolbar,
ref_tree
TYPE REF TO cl_gui_simple_tree,
internal tables it_scarr
TYPE SORTED TABLE OF scarr WITH UNIQUE KEY carrid,
(C) SAP AG
BC412
126
it_spfli
TYPE SORTED TABLE OF spfli WITH UNIQUE KEY carrid connid,
*
*
*
work areas wa_scarr
LIKE LINE OF it_scarr,
wa_spfli
LIKE LINE OF it_spfli,
tree: node table and work area it_nodes
TYPE TABLE OF bc412_sim_tree_node_struc,
wa_nodes
LIKE LINE OF it_nodes,
mapping structure BEGIN OF mapping, carrid
TYPE spfli-carrid,
connid
TYPE spfli-connid,
END OF mapping, *
event table it_events
TYPE cntl_simple_events,
wa_events
LIKE LINE OF it_events.
62Local Classes *
local event handler class
CLASS lcl_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_expand_no_children FOR EVENT expand_no_children OF cl_gui_simple_tree IMPORTING node_key, *
----------------------------------------------------on_function_selected FOR EVENT function_selected OF cl_gui_toolbar IMPORTING fcode.
ENDCLASS. *-----------------------------------------------------------------* *
CLASS lcl_event_handler IMPLEMENTATION
*-----------------------------------------------------------------* CLASS lcl_event_handler IMPLEMENTATION. METHOD on_expand_no_children. *
local data objects DATA: l_carrid
*
TYPE spfli-carrid.
clear global data object: it_nodes
(C) SAP AG
BC412
127
CLEAR: it_nodes, wa_nodes. *
find out which node to expand: node_key IF node_key = 'ROOT'.
*
" root to expand
create scarr nodes LOOP AT it_scarr INTO wa_scarr. CLEAR mapping. MOVE-CORRESPONDING wa_scarr TO mapping. wa_nodes-node_key
= mapping.
wa_nodes-relatkey
= node_key.
wa_nodes-relatship
= cl_gui_simple_tree=>relat_last_child.
wa_nodes-isfolder
= 'X'.
wa_nodes-expander
= 'X'.
wa_nodes-text
= wa_scarr-carrname.
" root node is parent
INSERT wa_nodes INTO TABLE it_nodes. ENDLOOP. ELSE. *
" SCARR node to expand
store parent node_key and carrier id MOVE node_key TO mapping. l_carrid = mapping-carrid.
*
create spfli nodes LOOP AT it_spfli INTO wa_spfli WHERE carrid = l_carrid. CLEAR mapping. MOVE-CORRESPONDING wa_spfli TO mapping. wa_nodes-node_key
= mapping.
wa_nodes-relatkey
= node_key.
wa_nodes-relatship
= cl_gui_simple_tree=>relat_last_child.
wa_nodes-isfolder
= ' '.
wa_nodes-expander
= ' '.
CONCATENATE wa_spfli-connid wa_spfli-cityfrom '->' wa_spfli-cityto INTO wa_nodes-text SEPARATED BY ' '. (C) SAP AG
BC412
128
INSERT wa_nodes INTO TABLE it_nodes. ENDLOOP. ENDIF. *
send additional nodes to tree control CALL METHOD ref_tree->add_nodes EXPORTING table_structure_name
= 'BC412_SIM_TREE_NODE_STRUC'
node_table
= it_nodes
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE i012(bc412). ENDIF. ENDMETHOD. * ----------------------------------------------------------------METHOD on_function_selected. CASE fcode. WHEN 'EXPAND_ALL'. *
expand all tree nodes CALL METHOD ref_tree->expand_root_nodes EXPORTING
*
LEVEL_COUNT
=
EXPAND_SUBTREE
= 'X'
EXCEPTIONS others
= 1
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. WHEN 'COLLAPSE_ALL'. CALL METHOD ref_tree->collapse_all_nodes EXCEPTIONS others
= 1
. IF sy-subrc 0. (C) SAP AG
BC412
129
MESSAGE a012(bc412). ENDIF. ENDCASE. ENDMETHOD. ENDCLASS.
63ABAP program event blocks START-OF-SELECTION. *
read data SELECT * FROM
scarr INTO TABLE it_scarr.
IF sy-subrc NE 0. MESSAGE a060(bc412). ENDIF. SELECT * FROM
spfli INTO TABLE it_spfli.
IF sy-subrc NE 0. MESSAGE a061(bc412). ENDIF. *
call carrier screen CALL SCREEN 100.
64Modules *&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
control related processings
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
create container CREATE OBJECT ref_container EXPORTING
*
SIDE
= DOCK_AT_LEFT
extension
= 200
EXCEPTIONS others
(C) SAP AG
= 1.
BC412
130
IF sy-subrc 0. MESSAGE a010(bc412). ENDIF. CREATE OBJECT ref_splitter EXPORTING parent
= ref_container
rows
= 2
columns
= 1
EXCEPTIONS others
= 1
. IF sy-subrc 0. MESSAGE a010(bc412). ENDIF. *
get cell references ref_top
= ref_splitter->get_container( row = 1 column = 1 ).
ref_bottom = ref_splitter->get_container( row = 2 column = 1 ). *
splitter container: fix height of first row
*
(for application toolbar) PERFORM configure_splitter_container.
*
create application toolbar and link to top splitter area CREATE OBJECT ref_toolbar EXPORTING parent
= ref_top
EXCEPTIONS others
= 1
. IF sy-subrc 0. MESSAGE a050(bc412). ENDIF. *
toolbar: add buttons to the application toolbar PERFORM configure_toolbar.
*
create tree control CREATE OBJECT ref_tree EXPORTING
(C) SAP AG
BC412
131
parent
= ref_bottom
node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a042(bc412). ENDIF. *
fill node table it_nodes PERFORM create_node_table.
*
send node table to tree control CALL METHOD ref_tree->add_nodes EXPORTING table_structure_name
= 'BC412_SIM_TREE_NODE_STRUC'
node_table
= it_nodes
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. *
event registration
*
1. cfw
*
1.a. tree control wa_events-eventid
= ref_tree=>eventid_expand_no_children.
wa_events-appl_event = ' '. APPEND wa_events TO it_events. CALL METHOD ref_tree->set_registered_events EXPORTING events
= it_events
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. (C) SAP AG
BC412
132
*
1.b. toolbar CLEAR: wa_events, it_events. wa_events-eventid = cl_gui_toolbar=>m_id_function_selected. wa_events-appl_event = ' '. APPEND wa_events TO it_events. CALL METHOD ref_toolbar->set_registered_events EXPORTING events
= it_events
EXCEPTIONS OTHERS
= 1
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF.
*
2. ABAP objects
*
2.a. tree control SET HANDLER lcl_event_handler=>on_expand_no_children FOR ref_tree.
*
2.b. toolbar set handler lcl_event_handler=>on_function_selected for ref_toolbar. ENDIF.
ENDMODULE.
" INIT_CONTROL_PROCESSING
OUTPUT
65Subroutines *&-----------------------------------------------------------------* *&
Form
CONFIGURE_SPLITTER_CONTAINER
*&-----------------------------------------------------------------* *
no interface
*------------------------------------------------------------------* FORM configure_splitter_container. * supress border (frame) CALL METHOD ref_splitter->set_border (C) SAP AG
BC412
133
EXPORTING border
= cl_gui_cfw=>false
EXCEPTIONS OTHERS
= 1
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF.
* set row mode CALL METHOD ref_splitter->set_row_mode EXPORTING mode
= ref_splitter->mode_absolute
EXCEPTIONS OTHERS
= 1
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. * set row height CALL METHOD ref_splitter->set_row_height EXPORTING id
= 1
height
= 20
EXCEPTIONS OTHERS
= 1
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. * fix sash position CALL METHOD ref_splitter->set_row_sash EXPORTING id
= 1
type
= ref_splitter->type_movable
value
= ref_splitter->false
*
IMPORTING
*
RESULT
=
EXCEPTIONS (C) SAP AG
BC412
134
OTHERS
= 1
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. ENDFORM.
" CONFIGURE_SPLITTER_CONTAINER
*&-----------------------------------------------------------------* *&
Form
CONFIGURE_TOOLBAR
*&-----------------------------------------------------------------* *
no interface
*------------------------------------------------------------------* FORM configure_toolbar. * expand all CALL METHOD ref_toolbar->add_button EXPORTING
* *
fcode
= 'EXPAND_ALL'
icon
= '@68@'
IS_DISABLED
=
butn_type
= cntb_btype_button
TEXT
=
quickinfo
" ICON_EXPAND_ALL
= text-003
" expand all
EXCEPTIONS OTHERS
= 1
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. * collapse all CALL METHOD ref_toolbar->add_button EXPORTING
* *
fcode
= 'COLLAPSE_ALL'
icon
= '@69@'
IS_DISABLED
=
butn_type
= cntb_btype_button
TEXT
=
quickinfo
= text-004
" ICON_COLLAPSE_ALL
" collapse all
EXCEPTIONS (C) SAP AG
BC412
135
OTHERS
= 1
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF.
ENDFORM.
(C) SAP AG
" CONFIGURE_TOOLBAR
BC412
136
Solution to the Optional Sections of Exercise 4 Unit: SAP Tree Control Topic: Simple Tree Control and Toolbar Control
Model solution SAPBC412_TRES_EXERCISE_4A
66ABAP program 67Data declarations REPORT
sapbc412_tres_exercise_4a MESSAGE-ID bc412.
TYPES: BEGIN OF scarr_ty.
" scarr fields + field send
INCLUDE STRUCTURE scarr. TYPES: send,
" !!!
END OF scarr_ty, *
---------------------BEGIN OF spfli_ty.
" spfli fields + field send
INCLUDE STRUCTURE spfli. TYPES: send,
" !!!
END OF spfli_ty. DATA:
*
ok_code
TYPE sy-ucomm,
" command field
copy_ok_code
LIKE ok_code,
" copy of ok_code
control specific: object references ref_container TYPE REF TO cl_gui_docking_container,
*
ref_splitter
TYPE REF TO cl_gui_splitter_container,
ref_top
TYPE REF TO cl_gui_container,
ref_bottom
TYPE REF TO cl_gui_container,
ref_toolbar
TYPE REF TO cl_gui_toolbar,
ref_tree
TYPE REF TO cl_gui_simple_tree,
internal tables it_scarr
TYPE SORTED TABLE OF scarr_ty WITH UNIQUE KEY carrid,
(C) SAP AG
BC412
137
it_spfli
TYPE SORTED TABLE OF spfli_ty WITH UNIQUE KEY carrid connid,
*
*
*
work areas wa_scarr
LIKE LINE OF it_scarr,
wa_spfli
LIKE LINE OF it_spfli,
tree: node table and work area it_nodes
TYPE TABLE OF bc412_sim_tree_node_struc,
wa_nodes
LIKE LINE OF it_nodes,
mapping structure BEGIN OF mapping, carrid
TYPE spfli-carrid,
connid
TYPE spfli-connid,
END OF mapping, *
event table it_events
TYPE cntl_simple_events,
wa_events
LIKE LINE OF it_events.
68Local Classes *
local event handler class
CLASS lcl_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_expand_no_children FOR EVENT expand_no_children OF cl_gui_simple_tree IMPORTING node_key, *
----------------------------------------------------on_function_selected FOR EVENT function_selected OF cl_gui_toolbar IMPORTING fcode.
ENDCLASS. *-----------------------------------------------------------------* *
CLASS lcl_event_handler IMPLEMENTATION
*-----------------------------------------------------------------* CLASS lcl_event_handler IMPLEMENTATION. METHOD on_expand_no_children. *
local data objects DATA: l_carrid
*
TYPE spfli-carrid.
clear global data object: it_nodes
(C) SAP AG
BC412
138
CLEAR: it_nodes, wa_nodes. *
find out which node to expand: node_key IF node_key = 'ROOT'.
*
" root to expand
create scarr nodes LOOP AT it_scarr INTO wa_scarr. CLEAR mapping. MOVE-CORRESPONDING wa_scarr TO mapping. wa_nodes-node_key
= mapping.
wa_nodes-relatkey
= node_key.
wa_nodes-relatship
= cl_gui_simple_tree=>relat_last_child.
wa_nodes-isfolder
= 'X'.
wa_nodes-expander
= 'X'.
wa_nodes-text
= wa_scarr-carrname.
" root node is parent
INSERT wa_nodes INTO TABLE it_nodes. wa_scarr-send = 'X'.
" mark that this node
MODIFY it_scarr FROM wa_scarr. " has been send ENDLOOP. ELSE. *
" SCARR node to expand
store parent node_key and carrier id MOVE node_key TO mapping. l_carrid = mapping-carrid.
*
create spfli nodes LOOP AT it_spfli INTO wa_spfli WHERE carrid = l_carrid. CLEAR mapping. MOVE-CORRESPONDING wa_spfli TO mapping. wa_nodes-node_key
= mapping.
wa_nodes-relatkey
= node_key.
wa_nodes-relatship
= cl_gui_simple_tree=>relat_last_child.
wa_nodes-isfolder
= ' '.
wa_nodes-expander
= ' '.
(C) SAP AG
BC412
139
CONCATENATE wa_spfli-connid wa_spfli-cityfrom '->' wa_spfli-cityto INTO wa_nodes-text SEPARATED BY ' '. INSERT wa_nodes INTO TABLE it_nodes. wa_spfli-send = 'X'.
" mark that this node has
MODIFY it_spfli FROM wa_spfli. " been send ENDLOOP. ENDIF. *
send additional nodes to tree control CALL METHOD ref_tree->add_nodes EXPORTING table_structure_name
= 'BC412_SIM_TREE_NODE_STRUC'
node_table
= it_nodes
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE i012(bc412).
" error during method execution
ENDIF. ENDMETHOD. * ----------------------------------------------------------------METHOD on_function_selected. CASE fcode. WHEN 'EXPAND_ALL'. *
send rest of missing nodes to the frontend control PERFORM send_rest_of_nodes.
*
expand all tree nodes CALL METHOD ref_tree->expand_root_nodes EXPORTING
*
LEVEL_COUNT
=
expand_subtree
= 'X'
EXCEPTIONS OTHERS
= 1
. IF sy-subrc 0. (C) SAP AG
BC412
140
MESSAGE a012(bc412). ENDIF. WHEN 'COLLAPSE_ALL'. CALL METHOD ref_tree->collapse_all_nodes EXCEPTIONS OTHERS
= 1
. IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. ENDCASE. ENDMETHOD. ENDCLASS.
69Subroutines *&-----------------------------------------------------------------* *&
Form
SEND_REST_OF_NODES
*&-----------------------------------------------------------------* *
determine nodes that haven't been send to the frontend control
*
so far, and send them to the frontend control (all modes shall
*
be expanded)
*------------------------------------------------------------------* *
no interface
*------------------------------------------------------------------* FORM send_rest_of_nodes. * local data DATA: it_nodes
TYPE TABLE OF bc412_sim_tree_node_struc,
wa_nodes
LIKE LINE OF it_nodes.
* scarr nodes LOOP AT it_scarr INTO wa_scarr WHERE send IS INITIAL. CLEAR mapping. MOVE-CORRESPONDING wa_scarr TO mapping. wa_nodes-node_key
= mapping.
wa_nodes-relatkey
= 'ROOT'.
wa_nodes-relatship
= cl_gui_simple_tree=>relat_last_child.
wa_nodes-isfolder
= 'X'.
wa_nodes-expander
= 'X'.
(C) SAP AG
" root node is parent
BC412
141
wa_nodes-text
= wa_scarr-carrname.
INSERT wa_nodes INTO TABLE it_nodes. wa_scarr-send = 'X'.
" mark that this node
MODIFY it_scarr FROM wa_scarr. " has been send ENDLOOP. * spfli nodes LOOP AT it_spfli INTO wa_spfli WHERE send IS INITIAL. CLEAR mapping. MOVE-CORRESPONDING wa_spfli TO mapping. wa_nodes-node_key
= mapping.
clear mapping-connid. wa_nodes-relatkey
= mapping.
wa_nodes-relatship
= cl_gui_simple_tree=>relat_last_child.
wa_nodes-isfolder
= ' '.
wa_nodes-expander
= ' '.
CONCATENATE wa_spfli-connid wa_spfli-cityfrom '->' wa_spfli-cityto INTO wa_nodes-text SEPARATED BY ' '. INSERT wa_nodes INTO TABLE it_nodes. wa_spfli-send = 'X'.
" mark that this node has
MODIFY it_spfli FROM wa_spfli. " been send ENDLOOP. * send nodes CALL METHOD ref_tree->add_nodes EXPORTING table_structure_name
= 'BC412_SIM_TREE_NODE_STRUC'
node_table
= it_nodes
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE i012(bc412). ENDIF. (C) SAP AG
BC412
142
ENDFORM.
(C) SAP AG
" SEND_REST_OF_NODES
BC412
143
70 ALV Grid Control
Contents: Features Constructor, methods and events Data descriptions
SAP AG 1999
(C) SAP AG
BC412
1
70.2 ALV Grid Control: Unit Objectives
At the conclusion of this unit, you will be able to: Describe the features of the ALV Grid Control Display list data in the ALV Grid Control Read and change properties of the ALV Grid Control Format print lists with the ALV Grid Control Generate a field catalog
SAP AG 1999
(C) SAP AG
BC412
2
70.3 Course Overview Diagram BC412
Unit 1
Course Overview
Unit 2
Introduction to the Control Framework
Unit 3
SAP Container
Unit 4
SAP Tree Control
Unit 5
ALV Grid Control
SAP AG 1999
(C) SAP AG
BC412
3
70.4 ALV Grid Control Overview: Features
Features Features Methodoverview overview Method Eventoverview overview Event The field fieldcatalog catalog The
SAP AG 1999
(C) SAP AG
BC412
4
70.5 ALV Grid Control Properties Display of nonhierarchical lists
Typical list functions: Air... Flight.. Date Curr... Price 17 AA 2000-01-17 513,69 USD 17 2000-02-20 513,69 USD AA 17 2000-03-11 513,69 USD AA 64 2000-05-19 369,00 USD AA 400 2000-01-13 1234,56 DEM LH 400 2000-02-16 1234,56 DEM LH 400 2000-03-21 1234,56 DEM LH 400 2000-03-04 1234,56 DEM LH 402 2000-05-28 1234,56 DEM LH
- Find - Filter - Sort - Totals/subtotals
Numerous interfaces: - Report-Report - Mail - Excel/Word - File, ...
Display variants supported - User-specific and / or global save mode
SAP AG 1999
The ALV Grid Control is a tool with which you can output non-hierarchical lists in a standardized format. The list data is displayed as a table on the screen.
The ALV Grid Control offers a range of interactive standard list functions that users need frequently (find, sort, filter, calculate totals and subtotals, print, print preview, send list, export list (in different formats), and so on. These functions are implemented in the proxy object class. You as the programmer have the possibility to turn off functions not needed. In most cases the implementations of the standard functions provided by the control are sufficient. However, if required, you can adjust these implementations to meet application-specific needs.
You can add self-defined functions to the toolbar, if necessary.
The ALV Grid Control allows users to adjust the layout of lists to meet their individual requirements (for example, they can swap columns, hide columns, set filters for the data to be displayed, calculate totals, and so on). The settings (list customizing) made by a specific user are called a display variant. Display variants can be saved on a user-specific or on a global basis. If such display variants exist for a list, they can be offered to the user for selection. If a display variant is set as the default variant, the associated list is always displayed based on the settings of this variant.
(C) SAP AG
BC412
5
70.6 Standard Pushbuttons Display list row details in a dialog box Sort in ascending order (by columns selected) Sort in descending order (by columns selected) Find items in the list Set filter: determine data to be displayed based on a condition (row selection) Calculate totals for selected columns Subtotals Print, print preview Transfer data --> spreadsheet, word-processing, local file, send, ... Display variants: customize column selection, select, change, save variants, and so on
SAP AG 1999
The control toolbar provides the following standard functions: Details: Select a row on the list. If you choose Details, the system displays the content of all list fields (including hidden columns) in a modal list window. Sort in ascending order: Select one or more columns. If you choose Sort in ascending order, the system sorts the list content by the columns selected. The sort order is determined by the display order of the columns on the screen. If you do not select a column beforehand, the system displays a dialog box on which you can select the column (sort order depends on the order of the columns selected). Sort in descending order: This function is analogous to Sort in ascending order. Find: You can determine a search term and the search order (columns or rows). Set filter: You can determine the amount of data displayed by defining value selections (SELECTOPTIONs) for each column (column selection: see Sort in ascending order). Total: The system calculates totals for the columns selected. Subtotal: This function is analogous to Total. (Note: You can only display subtotals if totals are calculated). Print: The options available are Print (print dialog ->Print) and Print preview. Export: The options available are Spreadsheet, Word processing, Local file, Send, Office and ABC Analysis. Display variants: The functions available are Choose display variant, Change display variant, and Manage display variant.
(C) SAP AG
BC412
6
70.7 Features Overview: Technical View
Features Features Technicalview view Technical Screenand andprint printlist list Screen Methodoverview overview Method Eventoverview overview Event The field fieldcatalog catalog The
SAP AG 1999
(C) SAP AG
BC412
7
70.8 ALV Grid Control: Technical View
ALV Grid Control
Printer/spool
Frontend
Application server ALV proxy object
ABAP program List data
Field catalog
Additional info
SAP AG 1999
The class cl_gui_alv_grid encapsulates the technical details of the communication with the frontend control of the ALV Grid Control.
From a technical point of view, the "wrapper" (cl_gui_alv_grid) does more than encapsulate the dialog with the frontend control, since the proxy objects communicate with three partners: Frontend Grid Control: Display of the list data as a table ABAP program: User Spool system / printer: Output of the list data as an ABAP print list
Communication through the ABAP program - proxy object - ALV Grid Control chain takes place interactively at runtime. The spool system is used for the output of the associated ABAP print lists.
The standard functions provided for screen output and the creation of the ABAP print list are implemented in proxy class cl_gui_alv_grid. The proxy class is an "application wrap" around the technical "wrapper" of the control communication.
ALV proxy objects maintain only a minimum amount of information on the data to be displayed. The data to be displayed and the rules according to which the data is to be displayed (field catalog) must be held in the program in global data objects.
(C) SAP AG
BC412
8
70.9 ALV Grid Control: List Data
ALV Grid Control
Printer/spool
Frontend
Application server ALV proxy object
ABAP program List data
Field catalog
Additional info
SAP AG 1999
Data that is to be output on the screen or as an ABAP print list is called list data.
(C) SAP AG
BC412
9
70.10 Creating List Data and Holding Data ALV Grid Control
Printer/spool
ALV proxy object
Proxy object holds only a pointer to the data object
ABAP program
Internal table must be a global data object in the program or a class or object attribute Sorting (using Grid Control button) is applied to the program data Read access for all other standard functions of the ALV Grid Control
Internal table
List data
SAP AG 1999
To display the data in the ALV Grid Control (or print the data using the control), you must pass the data in an internal table to the proxy object.
The proxy object does not have a copy of the data, but maintains a reference to the internal table passed.
To improve performance, the proxy object performs all interactive actions in the frontend control (sort, filter, and so on) on the internal table in the calling program. For this reason, the internal table that contains the list data must be declared as global in the program (or as a static variable in a class).
Sort processes in the ALV Grid Control change the state of the internal table in the calling program; all other actions perform only read access to the data.
(C) SAP AG
BC412
10
70.11 ALV Grid Control: The Field Catalog
ALV Grid Control
Printer/spool
Frontend
Application server ALV proxy object
ABAP program List data
Field catalog
Additional info
SAP AG 1999
The field catalog is dealt with in more detail in the following.
(C) SAP AG
BC412
11
70.12 Functions of the Field Catalog
ALV Grid Control / print list
Internal table itab with data carrid connid fldate AA
0603
AZ LH
1702 0400
QA
...
Field catalog: column properties
...
20001010 . . . 20000105 . . .
carrid connid
Properties of column carrid Properties of column connid
20000312 . . . ... ...
fldate
Properties of column fldate
...
Properties of column . . .
SAP AG 1999
The internal table with the data to be displayed that was passed to the proxy object can have any row type which can be chosen as required. So that the proxy object can properly format the data passed during screen output or creation of the print list, the object needs information on how the columns of the internal table are to be presented (properties of the fields of the internal table row type). You use another internal table to pass this information to the proxy object. This internal table is called the field catalog.
For each column of the data table, the field catalog must contain a row that determines the technical properties and additional formatting information of the column.
Depending on the row type of the data table, the field catalog can be generated differently. For row types defined in the ABAP Dictionary, you need only pass the name of the structure in the ABAP Dictionary to the proxy object. The proxy object copies all properties of the fields of the Dictionary structure and generates the field catalog automatically. This is the most common procedure and is called Automatically generated field catalog. If you use other row types, you must use different procedures referred to as Semi-Automatically Generated Field Catalog or Manually Generated Field Catalog. For more details, see the section The Field Catalog of this unit.
(C) SAP AG
BC412
12
70.13 Data Descriptions: The Field Catalog
LVC_T_FCAT
LVC_S_FCAT
Table type in the ABAP Dictionary for the field catalog
Row type in the ABAP Dictionary
Structure Properties of column 1 Properties of column 2 Properties of column 3 ...
Internal table with column/ field properties
SAP AG 1999
Internal tables that contain field catalogs must be typed with reference to table type LVC_T_FCAT (type of an internal table; defined in the ABAP Dictionary, new for Release 4.6).
Table type LVC_T_FCAT uses the global row type LVC_S_FCAT.
(C) SAP AG
BC412
13
70.14 Information in the Field Catalog (Structure)
LVC_S_FCAT
Structure type in the ABAP Dictionary for the field catalog
Column indicator Unit-specific formatting Output properties of columns For details, see the section on the field catalog
Formatting of column contents Texts Technical column properties Other fields
SAP AG 1999
Row type LVC_S_FCAT contains the following information: Column indicator (names of the fields, names of the reference fields in the ABAP Dictionary, ...) Formatting options for currency and quantity fields Output properties of the columns (order, ...) Formatting of the column contents (decimal place formatting, ...) Texts for column headers, detail screens and output in hotspot format Technical column properties Other fields
For more detailed information, see the section The field catalog of this unit.
(C) SAP AG
BC412
14
70.15 ALV Grid Control: Additional Information
ALV Grid Control
Printer/spool
Frontend
Application server ALV proxy object
ABAP program List data
Field catalog
Additional info
SAP AG 1999
In addition to the list data and the field catalog, you can pass additional information to the proxy object.
(C) SAP AG
BC412
15
70.16 ALV Grid Control: Function of Additional Information
Additional info Control layout info
Print list layout info
Data info
Formatting information for data output (data-independent)
Rules for data output (data-dependent)
SAP AG 1999
The additional information comprises: Layout information For the frontend control For the print list Information that contains the display rules for the data to be output Sort criteria Filter criteria Texts for field groups
(C) SAP AG
BC412
16
70.17 Function of Additional Information in Detail ALV Grid Control
Printer/spool
ALV proxy object
ABAP program Data area (grid)
Print list
Toolbar
Sort
Filter
Layout info
Field groups Data info
SAP AG 1999
You can use the following data object types to pass additional information to the ALV proxy object: Layout of the frontend control: Settings for the data area are passed using a structure. You can use an internal table to control the composition of the toolbar. Layout of the print list: You can use the fields of a structure to control parts of the list layout. You use internal tables to pass information about sort criteria, filter options, and field group texts to the proxy object.
Normally, you do not set up filter and sort criteria manually since they can be changed interactively by the user. The proxy object automatically modifies the associated internal tables in case of user interactions. Sort and filter criteria are usually handled (saved and read) as parts of display variants. You can find more information on the structure of the internal tables for the sort and filter criteria in the online documentation.
If the table to be displayed contains many fields, the user may be overwhelmed by the structure of the dialog boxes for selecting fields (columns) which are presented during interactions. For this reason, you can use the field catalog to group fields into logical groups (field groups). Using an internal table, you can pass texts for the field groups to the proxy object.
(C) SAP AG
BC412
17
70.18 Layout Information for the Data Area: Overview
LVC_S_LAYO
Structure type in the ABAP Dictionary for the control layout
General display options
Optimize column width, title size, ...
Grid customizing
Gridlines on/off, column headers off, ...
Totals options
Totals display before single records yes/no, ...
Exceptions
Indicate with traffic-light symbols yes/no, ...
Interactive control
Detail screen properties, key columns ...
Drag&Drop control settings
Drag&Drop control settings
Colors
List colors
SAP AG 1999
You can influence the control layout using a structure of type LVC_S_LAYO (structure type in the ABAP Dictionary). The structure type LVC_S_LAYO contains the following information: General display options (optimize column width, title size, ...) Grid customizing (horizontal/vertical gridlines on/off, use column headers, ...) Totals options (totals display before single records, ...) Exception handling (use traffic light symbols, ...) Interactive control (properties of the detail screen, ...) Drag&Drop settings Colors (print lists with striped pattern, ...)
For more details, see the online documentation.
(C) SAP AG
BC412
18
70.19 Layout Information for the Toolbar
UI_FUNCTIONS
ui_func (C70)
Table type in the ABAP Dictionary
Row type in the ABAP Dictionary: data element
Structure f_code1 f_code2 f_code3 f_code4
Internal table of type UI_FUNCTION (only one column)
Contains the function codes of the standard functions to be disabled (hidden)
SAP AG 1999
You can control the set of functions that are active in the toolbar using an internal table of type UI_FUNCTIONS (table type in the ABAP Dictionary). Table type UI_FUNCTIONS uses the field ui_func as the row type.
Using the internal table, you can set standard functions to inactive. To do this, you fill the internal table with the function codes of the functions that you want to disable. Inactive functions that have originally be assigned to icons in the toolbar will not be displayed. Inactive functions that have originally be assigned to a menu item are displayed disabled.
To set a value for field ui_func, you should use class constants of the class cl_gui_alv_grid. The class cl_gui_alv_grid has one class constant for each standard function. The class constants each begin with mc_fc_....
To hide the entire toolbar, you can use the field no_toolbar of structure LVC_S_LAYO.
(C) SAP AG
BC412
19
70.20 Layout Information for the Print List
LVC_S_PRNT
Structure type in the ABAP Dictionary: print parameters
print
Print output yes/no
reservelns
Line number for END-OF-PAGE
grpchgedit
Group change formatting yes/no
prntlstinf
Do not print list info yes/no
SAP AG 1999
Using the fields print, reservelns, grpchedit and prntlsinf of structure LVC_S_PRNT, you can make settings for the print list,
If you set parameter print to value 'X', you can use the ALV Grid Control as the default interface for printing: The table passed is directly formatted as an ABAP print list and placed into the spool; in this context, any interactive screen output is not processed. You do not need this parameter if you print lists interactively using the frontend control.
Using parameter reservelns, you can determine the number of lines required for the page footer (END-OF-PAGE).
Using field grpchgedit, you can determine if you want to print a line after a group change (default setting) or if you want to have a page break (if you want to have a page break, you must set the field to 'X'). The parameter applies for print lists only.
If you set the field prntlstinf to 'X', any settings made interactively such as filter criteria, and the total number of list lines also appear on the print list.
The other fields of the structure are not used for the ALV Grid Control.
(C) SAP AG
BC412
20
70.21 Features Overview: Screen/Print List
Features Features Technicalview view Technical Screenand andprint printlist list Screen Methodoverview overview Method Eventoverview overview Event The field fieldcatalog catalog The
SAP AG 1999
(C) SAP AG
BC412
21
70.22 Screen Layout of the ALV Grid Control
Toolbar Functions can be hidden Pushbuttons and menu options can be added Functions are triggered as events
Toolbar List header
List header Optional Single-line
Data display area (grid)
Data area Further structured
SAP AG 1999
The ALV Grid Control screen consists of three areas: In the header area of the control area, you can display a toolbar. The calling program determines which functions are active. You can hide the toolbar completely. Below the toolbar, you can display a single-line list header. Below the header is the area in which the list data is displayed (data area).
(C) SAP AG
BC412
22
70.23 Data Area Layout Area for scrollable columns
Column headers (can be hidden)
Colors can be used Striped patterns can be used (only print list)
User can select (based
Selection keys (optional)
Area for key columns (fixable)
on setting): - Single cells - Entire rows/columns Column headers can be used Gridlines can be shown/ hidden Context menus Drag&Drop ...
Scroll bars
SAP AG 1999
The data area itself also has a structure of its own.
The data passed as an internal table is displayed as a table. You can determine if you want to have horizontal and vertical gridlines for the cell structure.
The columns can have headers. You can hide the column headers.
If the data table contains more rows and more columns than can be displayed in the control area, horizontal and vertical scroll bars are available to go to a specific list position.
You can logically group columns into key columns and non-key columns. Key columns have another color than non-key columns. Key columns have a fixed position and therefore remain unchanged when the user scrolls horizontally through the list. You can make any column in your data table a key column.
You can define the items users can select. It is possible to select cells (cell areas), entire rows and/or entire columns. Optionally, you can display a selection column as the first column in the data area that can be used to select entire rows.
Drag&Drop operations are supported.
The ALV Grid control supports context menu handling.
For more information, see the online documentation.
(C) SAP AG
BC412
23
70.24 Print List Layout Complete layout
Page layout
Cover page Page header Page 1
Page body Page footer
Page n
Page
List properties List can be organised in pages - Cover page - Pages - Final page Each page can be organised in - Page header - Page body - Page footer This is controlled through events and layout information for the list Subtotals can also be output by means of an event (control levels)
Final page
SAP AG 1999
The print list layout is similar to the list layout of "classic" reporting: The list can consist of a logical cover page, a logical final page and any number of other pages in between that contain the actual list data. In addition to the page body, each page can have a page header and a page footer.
The logical organization of the complete list into cover page, pages, final page, and the organization of the individual pages into page header, page body and page footer is made possible by events (details to follow later).
(C) SAP AG
BC412
24
70.25 ALV Grid Control Overview: Method Overview
Features Features Methodoverview overview Method Eventoverview overview Event The field fieldcatalog catalog The
SAP AG 1999
(C) SAP AG
BC412
25
70.26 Inheritance Hierarchy
cl_gui_object
cl_gui_control
cl_gui_alv_grid_base
cl_gui_alv_grid
SAP AG 1999
Class cl_gui_alv_grid has the inheritance hierarchy specified.
Only class cl_gui_alv_grid is instantiated by applications.
(C) SAP AG
BC412
26
70.27 ALV Grid Control: Method Overview (1)
Elementary methods Read/ Read/change Grid Control properties Layout and structure information Operations on / information about Filter criteria Sort criteria Variants Event handling / function codes Report / report interface
SAP AG 1999
The methods of the ALV Grid Control can be subdivided into: Elementary methods Methods for changing/reading the properties of the Grid Control Methods for changing/reading the layout Methods for operations on filter criteria, sort criteria, and variants Methods for event handling and function code handling Methods for connecting the control to the report-report interface
For details on methods and interfaces, see the online documentation.
(C) SAP AG
BC412
27
70.28 ALV Grid Control: Elementary Methods
Elementary methods constructor
Link with container, event type, ...
set_table_for_first_display
Send data, data descriptions, layout information to control
refresh_table_display
Inform control that data, data descriptions or layout have been changed
SAP AG 1999
The ALV Grid Control has three elementary methods: The constructor Method set_table_for_first_display Method refresh_table_display.
(C) SAP AG
BC412
28
70.29 The Constructor
DATA: my_alv TYPE REF TO cl_gui_alv_grid. ... CREATE OBJECT my_alv EXPORTING * i_shellstyle = * i_lifetime = i_parent = * i_appl_events = EXCEPTIONS ...
Container reference
All registered events as application events: 'X' : Yes ' ' : No
SAP AG 1999
Optional parameters are indicated as ABAP comment lines.
The constructor for ALV Grid Control instances has four interface parameters: i_shellstyle: used to specify the general appearance of the control. For more details, see the online documentation. i_lifetime: used to control the lifetime of the frontend control. Possible values: lifetime_imode (default), lifetime_dynpro. For more details, see the online documentation. i_parent: Used to pass a container reference. i_appl_events: used to specify whether events of your ALV Grid Control instance are to be registered as system events (default) or application events (value: 'X'). The proxy object registers ALV events with Control Framework.
(C) SAP AG
BC412
29
70.30 Method SET_TABLE_FOR_FIRST_DISPLAY
CALL METHOD my_alv->set_table_for_first_display EXPORTING * i_structure_name = Field catalog: catalog: name of a Dictionary structure * is_variant = * i_save = Variant control parameter * i_default = * is_layout = Structure for control layout * is_print = Structure for print list layout * it_special_groups = Internal table with texts for the field groups * it_toolbar_excluding = Internal table with functions to be hidden CHANGING it_outtab = Internal table with list data * it_fieldcatalog = Internal table with the field catalog * it_sort = Internal table with initial sort criteria * it_filter = Internal table with initial filter criteria EXCEPTIONS ...
SAP AG 1999
You can use method set_table_for_first_display to pass the list data, the field catalog, and any additional information to the ALV Grid Control instance.
To pass the list data to be displayed, you use parameter it_outtab.
You pass the name of the row structure of the data table using parameter i_structure_name. The proxy object then generates the field catalog automatically. If you want to pass a field catalog that was generated manually or semi-automatically, you must additionally use parameter it_fieldcatalog. (For details, see the section The field catalog of this unit).
You use parameters is_variant and i_save to control the use of display variants. Using parameter i_default, you can determine that a display variants should be loaded as default variant. This is the default setting of the parameter.
Parameters is_layout, is_print, it_special_groups and it_toolbar_excluding allow you to pass your settings for the control layout and the print list, as well as the names of the field groups and the names of the functions to be disabled in the toolbar.
Using parameters it_filter and it_sort, you can pass initial filter and sort criteria to your proxy object.
The interface parameters use the following name conventions: i_ = single field, is_ = structure, it_ = internal table.
For details on the method and the interface parameters, see the online documentation.
(C) SAP AG
BC412
30
70.31 Method REFRESH_TABLE_DISPLAY
CALL METHOD my_alv->refresh_table_display EXPORTING * is_stable = Refresh with stable columns/ columns/rows * i_soft_refresh = Update data only, only, no sort criteria, criteria, and so on .
Informs proxy object that the
Content of the internal table with list data and/or Data objects for additional information have changed Update display at the frontend
SAP AG 1999
If you use method refresh_table_display, the proxy object sends the list data and the display information once more to the frontend control.
Using parameter i_soft_refresh, you can determine that only the data content is to be sent again (filter and sort criteria remain unchanged).
Using the fields of parameter is_stable, you can determine that any scroll positions that may exist should be kept (with reference to rows and columns) when the data is refreshed.
Important: If you change the structure of your data table you have to call method set_table_for_first_display again.
(C) SAP AG
BC412
31
70.32 Display Variants
MODE
Parameter value in method SET_TABLE_FOR_FIRST_DISPLAY
Change current display variant
is_variant = SPACE. i_save = SPACE.
Select and change current display variant
is_variant = . i_save = SPACE.
Select, change and save current display variant
is_variant i_save i_save i_save
= = = =
. 'U'. " Only user-specific 'X'. " Only global 'A'. " Global and user-specific
DATA: TYPE disvariant.
SAP AG 1999
Using parameters is_variant and i_save, you can determine the behavior of your proxy object with regard to display variant handling.
There are three modes which you can set with the help of these two parameters: The user can change the current display variant: To set this mode, you set both parameters to SPACE (default value). The user can select and change display variants: To set this mode, you pass a structure of the type disvariant to parameter is_variant in which the field report has the value sy-repid, and set parameter i_save to SPACE. The user can select, change, and save display variants: To set this mode, you assign the same value to parameter is_variant as with the above mode. The value you assign to parameter i_save allows you to control the user save mode for display variants: U: The user can save display variants only as user-specific. X: The user can save display variants only as global. A: The user can save display variants both as user-specific and as global.
(C) SAP AG
BC412
32
70.33 ALV Grid Control: Method Overview (2)
Read/ Read/change properties of the Grid Control Cells Scroll bars Columns Rows Layout and structure information Field catalog Layout Frames
SAP AG 1999
The ALV Grid Control has methods for the following subobjects that allow you to access the properties of these subobjects in change or read mode: Cells Scroll bars Columns Rows
The methods for the layout and the structure information can be subdivided as follows: Methods for the field catalog Methods for the layout Methods for the general control layout (frames)
For details on the method names and the interfaces, see the online documentation.
(C) SAP AG
BC412
33
70.34 ALV Grid Control Overview: Event Overview
Features Features Methodoverview overview Method Eventoverview overview Event The field fieldcatalog catalog The
SAP AG 1999
(C) SAP AG
BC412
34
70.35 ALV Grid Control: Events Events during print list creation Mouse operations double_click
Double-click on a cell
hotspot_click
Click on a cell hotspot
User-defined User-defined functions before_user_command
Before execution of a standard function
user_command
User-defined function code is triggered
after_user_command
After execution of a standard function
toolbar
Toolbar is changed
menu_button
A menu option is changed
Context menus Drag& Drag&Drop
SAP AG 1999
The ALV Grid Control has the following event types: Events that mark a specific point during print list creation Events for mouse operations Double-clicks on a cell Click on a hotspot of a cell Events that allow you to Execute implementations for self-defined functions Change the process flow of the standard functions Events for context menus Events for Drag&Drop operations
For details on the event names and interfaces, see the online documentation.
(C) SAP AG
BC412
35
70.36 BEFORE_USER_COMMAND and AFTER_USER_COMMAND Frontend control
Proxy instance
User triggers standard function
ABAP program
before_ before_user_ user_command Implementation 1 Implementation of standard function
after_ after_user_ user_command Implementation 2
SAP AG 1999
The events before_user_command and after_user_command allow you to run selfdefined processes directly before and after the execution of a standard function.
You can suppress the standard implementation of a standard function. To achieve this call the instance method set_user_command at the event for before_user_command and pass SPACE to the parameter i_ucomm.
(C) SAP AG
BC412
36
70.37 ALV Grid Control: Print List Events
Events during print list creation
print_end_of_list
Corresponds to event END-OF-SELECTION for list
print_top_of_list
Corresponds to event START-OF-SELECTION for list
print_end_of_page
Corresponds to list event END-OF-PAGE
print_top_of_page
Corresponds to list event TOP-OF-PAGE
subtotal_text
Subtotals texts of suppressed lines
SAP AG 1999
You can use events print_top_of_list, print_end_of_list, print_top_of_page, and print_end_of_page to implement the logical processing steps that correspond to the events START-OF-SELECTION, END-OF-SELECTION, TOP-OF-PAGE and END-OF-PAGE in "classic" reporting.
You can use event subtotal_text to output texts for subtotals lines that are not shown.
For more details, see the online documentation.
(C) SAP AG
BC412
37
70.38 ALV Grid Control Overview: The Field Catalog
Features Features Methodoverview overview Method Eventoverview overview Event The field fieldcatalog catalog The
SAP AG 1999
(C) SAP AG
BC412
38
70.39 Recap: Functions of the Field Catalog
ALV Grid Control / print list
Internal table itab with data carrid connid fldate AA
0603
AZ LH
1702 0400
QA
...
Field catalog: column properties
...
20001010 . . . 20000105 . . .
carrid connid
Properties of column carrid Properties of column connid
20000312 . . . ... ...
fldate
Properties of column fldate
...
Properties of column . . .
SAP AG 1999
Recap: the field catalog is an internal table containing the properties of all columns of the data table.
(C) SAP AG
BC412
39
70.40 Overview: Information in the Field Catalog
LVC_S_FCAT
Structure type in the ABAP Dictionary for the field catalog
Column indicator Unit-specific formatting Output properties of columns Formatting of column contents Texts Technical column properties Other fields
SAP AG 1999
(C) SAP AG
BC412
40
70.41 Field Catalog Overview: Information in the Field Catalog in Detail
Features Features Methodoverview overview Method Eventoverview overview Event The field fieldcatalog catalog The Informationin in the thefield fieldcatalog catalog in indetail detail Information Generating the thefield fieldcatalog catalog Generating
SAP AG 1999
(C) SAP AG
BC412
41
70.42 Field Catalog: Column Indicators
Column indicators fieldname
Column name in data table
ref_field
Column with Dictionary reference: field name
ref_table
Column with Dictionary reference: structure name
Example Internal table itab with data
Entries in the field catalog
carrid . . . seatsfree . . . AA AZ LH QA
... ... ... ...
fieldname
12 . . . 30 . . . 70 . . . 0 ...
ref_field
ref_table
CARRID
SFLIGHT
... ... SEATSFREE
...
...
...
...
SAP AG 1999
The column fieldname in the field catalog contains the names of the data table columns. Each column of the data table has a row in the field catalog.
If a field is typed with reference to the ABAP Dictionary (automatically generated entry in the field catalog), fields ref_field and ref_table contain the names of the reference field and the reference structure.
For more details, see the online documentation.
(C) SAP AG
BC412
42
70.43 Field Catalog: Unit-Specific Formatting
Unit-specific formatting
cfieldname
Name of column for currency formatting
currency
Explicit currency ID for entire column
qfieldname
Name of column for unit of measure formatting
quantity
Explicit unit of measure for entire column
SAP AG 1999
Currency formatting: If the content of a column is to be formatted based on the formatting options of a currency unit that is contained in another column of the data table, then you must specify the name of the column with the currency units in the field cfieldname. If all values of a column are to be formatted according to a fixed currency, you must enter the ID of that currency in the column currency. If a value is assigned to the field currency, entries in the field cfieldname are ignored.
Unit of measure formatting: If the content of a column is to be formatted based on the formatting options of a unit of measure that is contained in another column of the data table, then you must specify the name of the column with the units of measure in the field qfieldname. If all values of a column are to be formatted according to a fixed unit of measure, you must enter the ID of that unit of measure in the column quantity. If a value is assigned to the field quantity, entries in the field qfieldname are ignored.
For more details, see the online documentation.
(C) SAP AG
BC412
43
70.44 Example: Currency Formatting
Internal table itab with data carrid . . . AA AZ ...
... ... ...
Entries in the field catalog
price currency 300 USD 7000 ITL ... ...
fieldname
... cfieldname
CARRID
...
... PRICE
... ...
... CURRENCY
...
...
...
Screen output / printing Fli... . . .
AA AZ
... ...
...
...
Price Currency 300,00 USD 7000 ITL ... ...
SAP AG 1999
The above graphic shows the following: The data table contains the two columns price (amount to be paid for the flight) and currency (currency of price).
The entry currency in field cfieldname for the column price in the field catalog determines that the entries of the column price are formatted according to the currency specified in the column currency (example: USD -> two decimal places, ITL -> no decimal place).
(C) SAP AG
BC412
44
70.45 Field Catalog: Output Properties for Columns
Output properties for columns
checkbox
Display of a checkbox (no entry)
col_pos
Column position
do_sum
Totals calculation for column yes/no
hotspot
Column hotspot-sensitive yes/no
no_sum
Suppress totals calculation for column yes/no
emphasize
Highlight column content (color, bright, inverse)
key
Column is key column yes/no
lowercase
Upper/lower case yes/no
no_out
Do not output column yes/no
outputlen
Column width
tech
Do not output column yes/no
SAP AG 1999
The following difference exists between no_out and tech: no_out: The column is hidden in the list (screen or printout), but appears on the field selection dialog boxes for the standard functions (sort, filter, ...). tech: The column is hidden both in the list and on the field selection dialog boxes.
For more details, see the online documentation.
(C) SAP AG
BC412
45
70.46 Field Catalog: Formatting of Column Contents Formatting of column contents
decimals_o
Number of decimal places (currencies)
decmfield
Column name in data table for number of dec. places
edit_mask
Analogous to USING EDIT MASK for WRITE
exponent
Window exponent for ABAP data type F
icon
Display column content as icon yes/no
lzero
Leading zeros yes/no (NUMC)
just
Adjust column content (' ', 'R', 'L', 'C') (CHAR, NUMC)
no_sign
Suppress plus/minus signs yes/no
no_zero
Value 0 ('zero') not output yes/no
round
Analogous to ROUND for WRITE
roundfield
Column name in data table for ROUND
symbol
Display column content as symbol yes/no
SAP AG 1999
Similar to the formatting options for currency fields, you can use the fields decmfield and decimals_o to define the number of decimal places for numerical fields (ABAP data types P, I, F) either for individual column contents or for all entries of a column.
For more details, see the online documentation.
(C) SAP AG
BC412
46
70.47 Field Catalog: Texts
Texts
colddictxt
Text selection for column headers ('L', 'M', 'S')
coltext
Freely definable text (column header)
reptext
Copy from ABAP Dictionary
scrtext_l
Long text
scrtext_m
Medium text
scrtext_s
Short text
selddictxt
Text selection for selection dialog box ('L', 'M', 'S')
seltext
Freely definable text (selection dialog box)
tipddictxt
Text selection for tooltip ('L', 'M', 'S')
tooltip
Freely definable text (tooltip)
SAP AG 1999
Similar to the texts of a data element in the ABAP Dictionary, the fields scrtext_l, scrtext_m and scrtext_s can contain three texts of different lengths for columns, selection screens, and tool tips (S = 'short', M = ''middle', L = 'long'). For fields with reference to the Dictionary, the texts are copied from the Dictionary.
By assigning value 'L', 'M' or 'S' to field colddictext, you determine which text is to be used as the column header. Similarly, the values of fields selddictext and tipddictext determine which text is to be displayed on the dialog boxes (interactive standard functions) and as the tool tip.
The fields coltext, seltext and tooltip allow you to use freely definable texts as column headers, dialog box texts and tool tips. If you assign values to these fields, these values override any entries in the fields colddictext, selddictext and tipddictext.
For fields with reference to the Dictionary, the field reptext contains the headers from the data element (used for queries).
For more details, see the online documentation.
(C) SAP AG
BC412
47
70.48 Field Catalog: Technical Column Properties
Technical column properties
dd_outlen
Output length (width) of column
intlen
Internal column width
rollname
F1 help by data element documentation: name of data element
inttype
ABAP data type
SAP AG 1999
For more details, see the online documentation.
(C) SAP AG
BC412
48
70.49 Field Catalog: Other Fields
Other fields
dragdropid
Drag&Drop control
reprep
Link of column to report-report interface yes/no
sp_group
Identifier for field groups
txt_field
Column name for substitute texts for totals calculation
SAP AG 1999
You can replace numeric fields with a corresponding text using the txt_field field. Example: Suppose column A contains plant numbers, and column B the corresponding long texts. On the list, you want to display the text instead of the plant number (for example, Hamburg instead of 0001. For column A, the field txt_field must contain the name of column B (txt_field = 'B').
For further details, refer to the online documentation.
(C) SAP AG
BC412
49
70.50 Summary: Structure of the Field Catalog
Column name
Dictionary relationship
Properties
ref_table
ref_field
fieldname
FIELD CATALOG
Unit-specific formatting
Output Properties for Columns
Formatting of Column Contents
Texts
Technical Column Properties
Other Fields
SAP AG 1999
We can divide the fields in the field catalog into three groups according to their use in constructing the field catalog. The field fieldname contains the column name. The fields ref_field and ref_table establish the relationship to any global types (fields of structures in the ABAP Dictionary). All of the other fields contain values for the attributes of the columns.
(C) SAP AG
BC412
50
70.51 Field Catalog Overview: Generating the Field Catalog
Features Features Methodoverview overview Method Eventoverview overview Event The field fieldcatalog catalog The Informationin in the thefield fieldcatalog catalog in indetail detail Information Generating the thefield fieldcatalog catalog Generating
SAP AG 1999
(C) SAP AG
BC412
51
70.52 Generating the Field Catalog List data
List data
List data
Row type of data table contains only
Row type of data table contains
Fields of a single Dictionary structure
Fields of Dictionary structures
Row type of data table contains only Fields with local types
Fields with local types
Field catalog is generated automatically
Field catalog can be generated semisemi-automatically
Field catalog must be generated manually
SAP AG 1999
Depending on the row type of the data table, the field catalog is generated according to a different procedure. We have to distinguish between three cases:
Case 1: The row type of the data table is defined in the ABAP Dictionary. Example: Row type SFLIGHT. In this case, all information of the field catalog can be copied from the ABAP Dictionary. This is done independently by the proxy object: The field catalog is generated automatically.
Case 2: The row type of the data table contains fields with types of fields of Dictionary structures and fields with local types. Example: The row type consists of the fields of structure SFLIGHT to which fields with types defined locally in the program have been added. In this case, you can have the entries of the fields with reference to the Dictionary generated automatically, while you must manually add the entries of the other columns to the field catalog (semi-automatic procedure).
Case 3: The row type of the data table contains only fields with local types. In this case, the field catalog must be generated manually. This means that the program that uses the ALV Grid Control must generate the field catalog on its own.
(C) SAP AG
BC412
52
70.53 Fields of a Single Dictionary Structure Internal table it_data with list data Row type: SFLIGHT AA
...
300
AZ
...
7000
ITL
...
...
...
...
SFLIGHT
SPFLI ABAP Dictionary
USD
CALL METHOD my_alv->set_table_for_first_display EXPORTING i_structure_name i_structure _name = 'SFLIGHT' i_structure_ ... CHANGING it_outtab = it_data it_ it_ it_outtab it_data ...
SAP AG 1999
If the line type of the data table contains all of the fields in a particular ABAP Dictionary structure, the ALV proxy object can create the field catalog automatically.
To do this, specify the name of the ABAP Dictionary structure that corresponds to the line type of the data table in the i_structure_name parameter of the method set_table_for_first_display.
The proxy object obtains all of the requisite information from the ABAP Dictionary and constructs the field catalog itself.
(C) SAP AG
BC412
53
70.54 Fields of a Dictionary Structure and Local Types Field catalog it_fcat Local ABAP types
fill
Cn
DDIC
Properties
'empty' ABAP Dictionary Cn = Column name
STRUC send
CALL METHOD my_alv->set_table_for_first_display EXPORTING i_structure _name = 'STRUC' i_structure_ ... CHANGING it_ = it_ it_outtab it_data it_ it_fieldcatalog
= it_ it_fcat
...
SAP AG 1999
If the row type of your data table consists of all fields of a single Dictionary structure to which other fields have been added, you can generate the field catalog semi-automatically.
To dothis, you: Declare an internal table for the field catalog DATA: it_fcat TYPE lvc_t_fcat. Create an entry in the field catalog for each column in your data table that has a type that you defined locally in the program. Enter the column name and define its attributes. Call the instance method set_table_for_first_display and pass the data table (it_data in the graphic) to the it_outtab parameter, the field catalog (it_fcat) to the it_fieldcatalog parameter, and the name of the ABAP Dictionary structure to the i_structure_name parameter. The proxy object then generates a full field catalog.
(C) SAP AG
BC412
54
70.55 Fields of Several Dictionary Structures ABAP Dictionary SFLIGHT
SPFLI
Field catalog it_fcat Column fill
CARRID CONNID FLDATE DEPTIME CITY_F CITY_T ...
DDIC Relation SFLIGHT SFLIGHT SFLIGHT SPFLI CITYFROM SPFLI CITYTO SPFLI ...
Properties
'empty'
send CALL METHOD my_alv->set_table_for_first_display ... CHANGING
it_ it_outtab
= it_ it_data
it_ it_fieldcatalog ...
= it_ it_fcat
SAP AG 1999
You can also generate the field catalog semi-automatically if the fields in the line type of your data table have data types from more than one ABAP Dictionary structure.
To do this, you must: Declare an internal table for the field catalog: DATA: it_fcat TYPE lvc_t_fcat. Create an entry in the field catalog for each column in your data table. Fill the fieldname and ref_table fields for all of the columns that have the same name as the structure field to which you referred to define their types (fieldname contains the column name, ref_table the name of the reference table). For fields where the column name in the data table is different to the field name in the ABAP Dictionary structure (cityfrom and cityto in the graphic), you must also specify the name of the reference field. Call the instance method set_table_for_first_display and pass the data table (it_data in the example) to the it_outtab parameter and the field catalog (it_fcat) to the it_fieldcatalog parameter. The proxy object then creates the full field catalog.
(C) SAP AG
BC412
55
70.56 Fields With and Without Dictionary Relationships ABAP Dictionary
Field catalog it_fcat
STRUC
Cn
DDIC
Properties 'empty'
fill Local ABAP Types
'empty' Cn = Column name send
CALL METHOD my_alv->set_table_for_first_display ... CHANGING
it_ it_outtab
= it_ it_data
it_ it_fieldcatalog ...
= it_ it_fcat
SAP AG 1999
You can also generate the field catalog semi-automatically if the line type of your data table consists of fields from more than one ABAP Dictionary structure along with additional fields that have types that you defined locally in the program.
To do this, you must: Declare an internal table for the field catalog: DATA: it_fcat TYPE lvc_t_fcat. Create an entry in the field catalog for each column in your data table. For each column that has an ABAP Dictionary reference, fill the fieldname and ref_table columns (and ref_field if necessary). For each column in your data table that has a type that you defined locally in the program, create an entry in the field catalog by entering the column name and defining the attributes of the column. Call the instance method set_table_for_first_display and pass the data table (it_data in the example) to the it_outtab parameter and the field catalog (it_fcat) to the it_fieldcatalog parameter. The proxy object then generates the full field catalog.
(C) SAP AG
BC412
56
70.57 Fields With Local Types Only Field catalog it_fcat fill
Cn
Local ABAP types
DDIC
Properties
'empty'
Cn = Column name send
CALL METHOD my_alv->set_table_for_first_display EXPORTING ... CHANGING
it_ it_outtab
= it_ it_data
it_ it_fieldcatalog ...
= it_ it_fcat
SAP AG 1999
If the line type of your data table consists exclusively of data types that you declared locally in the program, you must create the field catalog by hand.
To do this, you must: Declare an internal table for the field catalog: DATA: it_fcat TYPE lvc_t_fcat. Create an entry in the field catalog for each column in your data table. Enter the column name and define the attributes for the columns. Call the instance method set_table_for_first_display and pass the data table (it_data in the example) to the it_outtab parameter and the field catalog (it_fcat) to the it_fieldcatalog parameter.
(C) SAP AG
BC412
57
70.58 Demo Programs Delivered
Dev. class
Programs
Demo for
SLIS
BCALV_GRID_01
Events for print lists
BCALV_GRID_02
Basic and details lists with one instance
BCALV_GRID_03
Detail list in modal dialog box
BCALV_GRID_04
Exception handling (exceptions / traffic light symbols)
BCALV_GRID_05
Self-defined pushbuttons in the toolbar
BCALV_GRID_06
Context menus
BCALV_GRID_07
Self-defined menus in the toolbar
BCALV_GRID_08
Toolbar menu with standard pushbutton
BCALV_GRID_09
Control options for display variants
BCALV_GRID_10
Initial usage of display variants
SAP AG 1999
You can find demo programs for the ALV Grid Control in development class SLIS.
This development class is delivered.
(C) SAP AG
BC412
58
70.59 ALV Grid Control: Unit Summary
Now you are able to: Describe the features of the ALV Grid Control Display list data in the ALV Grid Control Read and change properties of the ALV Grid Control Format print lists with the ALV Grid Control Generate a field catalog
SAP AG 1999
(C) SAP AG
BC412
59
70.60ALV Grid Control: Exercise 1 Unit: ALV Grid Control Topic: Displaying Data in an ALV Grid Control
At the conclusion of this unit, you will be able to: Display a basic list in an ALV Grid Control instance.
In an ALV Grid Control, display the flight connection data stored in the database table SPFLI.
Program:
ZBC412_##_ALV_EX1
Template:SAPBC412_ALVT_EXERCISE1 Model solution: SAPBC412_BASS_EXERCISE_1 where ## is the group number 1-1
Copy the program SAPBC412_ALVT_EXERCISE_1. and get to know how it works.
1-2
Create an instance of an ALV Grid Control, which you will display in an existing Docking Container: 1-2-1 Create a reference variable for ALV Grid Control instance (We suggest you use the name ref_alv). 1-2-2 In the init_control_processing module, create an ALV Grid object and link it with the Docking Container. If an error occurs, terminate processing and display the message 045 from the message class BC412. 1-2
In your ALV Grid Control, display the connection data stored in the internal table it_spfli, using the instance method set_table_for_first_display. If an error occurs, terminate processing and display the message 012 from the message class BC412. Pass the name of the line type of the internal table it_spfli using the parameter i_structure_name. Pass the data using the parameter it_outtab.
There is no need to pass values to the other interface parameters. (C) SAP AG
BC412
60
Exercise 2 Unit: ALV Grid Control Topic: Display a Basic List and Detail List in the ALV Grid Control (Using Events) At the conclusion of this unit, you will be able to: Use the double_click event of the ALV Grid Control to implement interactive reporting.
Allow users to choose a line in the basic list (of SPFLI data) by double-clicking it. When this occurs, your program should display a list of all flights (from SFLIGHT) for the connection the user has chosen, as a separate window. Use an ALV Grid Control to display the detail list and basic list. Program:
ZBC412_##_ALV_EX2
Template:SAPBC412_ALVT_EXERCISE_2 Model solution: SAPBC412_ALVS_EXERCISE_2 where ## is the group number 2-1
Copy the solution to the previous exercise or the program SAPBC412_ALVT_EXERCISE_4. If you are using the template program, get to know how it works.
2-2
Define and implement an event handler for the double_click event of the ALV Grid Control: 2-2-1 Find out about the interface to the double_click event in the ALV Grid Control proxy class.. 2-2-2 Define a local class (suggested name: lcl_event_handler). The class should contain a static method for handling the double_click event of instances of the class cl_gui_alv_grid. 2-2-3 Implement the on_double_click method in the implementation part of the local class. The method should contain the following steps: (a) Find out which record the user has chosen. (b) Get the relevant flight data (from SFLIGHT). (c) Instantiate a dialog box container and ALV Grid Control. (d) Copy the data from SFLIGHT to the ALV Grid Control. Proceed as follows:
(C) SAP AG
BC412
61
(a) Read the connection data record chosen into the internal table it_spfli, using READ TABLE ...INDEX. If an error occurs, inform the user by displaying message 075 from the message class BC412. Then terminate processing of the handler method. (b) Copy the appropriate flight data from the internal table it_sflight into an internal used by the second ALV Grid Control. To do this, create a suitable internal table in the declaration part of your program (suggested name: it_popup). (c) Create a dialog box container and an ALV Grid Control. To do this, declare two suitable reference variables in the declaration part of your program. (Suggested name: box_container, box_alv). Use the following values for the interface parameters of the dialog box container constructor: width
800
height
200
top
120
left
120
caption
any (suggested caption: Flight connections)
Handle errors using messages 010 and 045 from message class BC412. (d) Copy the flight data from SFLIGHT to the new ALV Grid Control, using the method set_table_for_first_display. Handle errors using message 012 from message class BC412. 2-2-4 Register your event handler method with the ALV Grid Control instance for the basic list (in the init_control_processing module). 2-2-5 Activate and test your program . 2-3
Make sure that the program does not display a new window (dialog box container) each time the user double-clicks a line. To do this, use the reference variables box_container and box_alv as indicators. Activate and test your program.
2-4
Make sure also that the contents of the detail list are updated each time the user double-clicks the basic list, using the instance method refresh_table_display.
(C) SAP AG
BC412
62
Exercise 2 (Optional Sections) Unit: ALV Grid Control Topic: Display a Basic List and Detail List in the ALV Grid Control (Using Events) At the conclusion of this unit, you will be able to: Use print list events (such as print_top_of_list). Close the window showing the detail list. Read the data for the detail list incrementally and buffer it in the program. Print a cover sheet text on the print list of flight connections (that is, the basic list). Allow the user to close the detail list again.
Program:
same program
Template:SAPBC412_ALVT_EXERCISE_2A Model solution: SAPBC412_ALVS_EXERCISE_2A where ## is the group number 2-6
On the print list of flight connections, print a text telling the user the airline concerned. To do this, use the print_top_of_list event. Suggested texts: Airline chosen
Text
All
List of connections for all airlines
One only (‘XX’)
List of connections for all XX.
Proceed as follows: 2-6-1 Define a static method to handle the print_top_of_list event (suggested name: on_print_tol). 2-6-2 Implement the method: (a) Find out which airline the user has chosen (READ on so_carr). Note: You need a work area. (b) Display an appropriate text for the airline chosen. 2-6-3 Register the method with the ALV Grid Control instance for the basic list (in the init_control_processing module). (C) SAP AG
BC412
63
2-7
Allow the user to close the detail list window (the dialog box container) again. 2-7-1 Define and implement a static method on_close, which reacts to the close event of instances of the class cl_gui_docking_container. Close the dialog box container when the method is executed. 2-7-2 Register the method on_close with the instance of the dialog box container (in the method on_double_click).
2-8
In your program, change it so that it accesses data incrementally. To improve performance, buffer connection data in the internal table, once the program has read them once: 2-8-1 Event block START-OF-SELECTION: Delete the statements that read the contents of the table SFLIGHT into the internal table it_sflight. 2-8-2 The on_double_click method of the local class lcl_event_handler: Obtain the return code of the loop by copying the SFLIGHT data to it_popup. If the loop does not return a record, read the data from the database using SELECT. Copy the results to the internal tables it_sflight and it_popup using a SELECT statement. In section 2-7: Note you cannot simply close the dialog box container at the front end, without carrying out any further actions in the method on_close. Otherwise, when the user double-clicks a line in the basic list, after the system has closed the dialog box, a runtime error occurs.
(C) SAP AG
BC412
64
Exercise 3 Unit: ALV Grid Control Topic: The Field Catalog
At the conclusion of this unit, you will be able to: Create and use a field catalog for the ALV Grid Control
Add two columns to the detail list containing the flight data: one for the percentage of seats occupied, and one for the % sign.
Program:
ZBC412_##_ALV_EX3
Template:SAPBC412_ALVT_EXERCISE_3 Model solution: SAPBC412_ALVS_EXERCISE_3 where ## is the group number 3-1
Copy the solution to the previous exercise or the program SAPBC412_ALVT_EXERCISE_3. If you are using the template program, get to know how it works.
3-2
Add two new columns to the detailed information table (it_popup) for the percentage of seats occupied, and fill them, as follows: 3-2-1 Define a local line type, ty_sflight, containing all the fields in the structure SFLIGHT, plus two additional fields, percentage and sign. Use the INCLUDE STRUCTURE statement to copy the fields of the SFLIGHT table. Type the field percentage using the global type sbc400focc-percentage. The sign field should have the ABAP type C. 3-2-2 Assign the new line type to the internal table it_popup. 3-3-3 Fill the field sign and calculate the content of the field percentage by filling the internal table it_popup (method: on_double_click).
(C) SAP AG
BC412
65
3-4
Create an appropriate field catalog for the table structure of it_popup and pass it using the method set_table_for_first_display (for the detailed display): 3-4-1 Declare an internal table for a field catalog (suggested name: it_fcat). Use the table type lvc_t_fcat. 3-4-2 Create a field catalog using a subroutine (suggested name: create_field_catalog), before you call the set_table_for_first_display method. For the percentage field, use the appropriate field in the structure SBC400FOCC. For the sign field, use a local program type and provide values, at least for the following fields: fieldname
SIGN
outputlen
2
coltext
'Unit'
tooltip
'Unit = %'
3-4-3 Adapt the method interface set_table_for_first_display to include the new information. To do this, fill the parameters i_structure_name, it_outtab and it_fieldcatalog with appropriate values.
(C) SAP AG
BC412
66
70.61 ALV Grid Control: Solutions to Exercise 1 Unit: ALV Grid Control Topic: Displaying Data in an ALV Grid Control
Model solution SAPBC412_BASS_EXERCISE_1
71Screen flow logic 71.2SCREEN 100 PROCESS BEFORE OUTPUT. MODULE status_0100. MODULE init_control_processing. * PROCESS AFTER INPUT. MODULE user_command_0100.
72ABAP Program 73Data Declarations REPORT
sapbc412_alvs_exercise_1
MESSAGE-ID bc412.
DATA:
*
ok_code
TYPE sy-ucomm,
" command field
copy_ok_code
LIKE ok_code,
" copy of ok_code
control specific: object references ref_container TYPE REF TO cl_gui_docking_container, ref_alv
*
*
TYPE REF TO cl_gui_alv_grid,
internal tables it_spfli
TYPE TABLE OF spfli,
it_sflight
TYPE TABLE OF sflight,
work areas wa_spfli
LIKE LINE OF it_spfli,
wa_sflight
LIKE LINE OF it_sflight.
(C) SAP AG
BC412
67
74Selection Screen * selection screen SELECT-OPTIONS: so_carr FOR wa_spfli-carrid NO-EXTENSION NO INTERVALS.
75ABAP Program: Event Blocks * start of main program START-OF-SELECTION. *
read data SELECT * FROM
spfli INTO TABLE it_spfli WHERE carrid IN so_carr
ORDER BY carrid connid. IF sy-subrc NE 0. MESSAGE a061(bc412). ENDIF. *
SELECT * FROM sflight INTO TABLE it_sflight WHERE carrid IN so_carr
* *
ORDER BY carrid connid fldate.
*
IF sy-subrc NE 0.
*
MESSAGE a062(bc412). ENDIF.
CALL SCREEN 100.
76Modules *&-----------------------------------------------------------------* *&
Module
STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *
GUI settings
*------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'SCREEN_0100'. SET TITLEBAR 'SCREEN_0100'. ENDMODULE.
" STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *&
Module
USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
implementation of GUI functions
*------------------------------------------------------------------* (C) SAP AG
BC412
68
MODULE user_command_0100 INPUT. copy_ok_code = ok_code. CLEAR ok_code. CASE copy_ok_code. WHEN 'BACK' OR 'CANCEL' OR 'EXIT'. LEAVE PROGRAM. ENDCASE. ENDMODULE.
" USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
control related processing
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
create container object CREATE OBJECT ref_container EXPORTING
*
SIDE
= DOCK_AT_LEFT
extension
= 2000
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a010(bc412). ENDIF. *
create alv grid object and link to container CREATE OBJECT ref_alv EXPORTING i_parent
*
I_APPL_EVENTS
= ref_container = space
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a045(bc412). ENDIF. (C) SAP AG
BC412
69
*
send basic list to alv grid control CALL METHOD ref_alv->set_table_for_first_display EXPORTING i_structure_name
= 'SPFLI'
*
IS_VARIANT
=
*
I_SAVE
=
*
I_DEFAULT
= 'X'
*
IS_LAYOUT
=
*
IS_PRINT
=
*
IT_SPECIAL_GROUPS
=
*
IT_TOOLBAR_EXCLUDING
=
CHANGING it_outtab
= it_spfli
*
IT_FIELDCATALOG
=
*
IT_SORT
=
*
IT_FILTER
=
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. ENDIF. ENDMODULE.
(C) SAP AG
" INIT_CONTROL_PROCESSING
BC412
OUTPUT
70
Solutions to Exercise 2 Unit: ALV Grid Control Topic: Events of the ALV Grid Control
Model solution SAPBC412_BASS_EXERCISE_2
77ABAP Program 78Data Declarations DATA:
*
ok_code
TYPE sy-ucomm,
" command field
copy_ok_code
LIKE ok_code,
" copy of ok_code
control specific: object references ref_container TYPE REF TO cl_gui_docking_container, ref_alv
TYPE REF TO cl_gui_alv_grid,
box_container TYPE REF TO cl_gui_dialogbox_container, box_alv *
*
TYPE REF TO cl_gui_alv_grid,
internal tables it_spfli
TYPE TABLE OF spfli,
it_sflight
TYPE TABLE OF sflight,
it_popup
TYPE TABLE OF sflight,
work areas wa_spfli
LIKE LINE OF it_spfli,
wa_sflight
LIKE LINE OF it_sflight.
79Local Classes *-----------------------------------------------------------------* *
CLASS lcl_event_handler DEFINITION
*-----------------------------------------------------------------* CLASS lcl_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_double_click FOR EVENT double_click OF cl_gui_alv_grid (C) SAP AG
BC412
71
IMPORTING e_row. ENDCLASS. *-----------------------------------------------------------------* *
CLASS lcl_event_handler IMPLEMENTATION
*-----------------------------------------------------------------* CLASS lcl_event_handler IMPLEMENTATION. METHOD on_double_click. *
find out selected line (double click) READ TABLE it_spfli INTO wa_spfli INDEX e_row-index. IF sy-subrc NE 0. MESSAGE i075(bc412).
" internal error
EXIT. ENDIF. *
copy corresponding flight data to it_popup CLEAR it_popup. LOOP AT it_sflight INTO wa_sflight WHERE carrid = wa_spfli-carrid AND
connid = wa_spfli-connid.
INSERT wa_sflight INTO TABLE it_popup. ENDLOOP. IF box_container IS INITIAL. *
create dialog box container CREATE OBJECT box_container EXPORTING width
= 800
height
= 200
top
= 120
left
= 120
caption
= text-002
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a010(bc412). ENDIF.
(C) SAP AG
BC412
72
ENDIF. IF box_alv IS INITIAL. *
create avl grid object and link to dialogbox container CREATE OBJECT box_alv EXPORTING i_parent
= box_container
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a045(bc412). ENDIF. *
send popup data to new alv object CALL METHOD box_alv->set_table_for_first_display EXPORTING i_structure_name
= 'SFLIGHT'
CHANGING it_outtab
= it_popup
*
IT_FIELDCATALOG
=
*
IT_SORT
=
*
IT_FILTER
=
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. ELSE.
" do only refresh alv contents
CALL METHOD box_alv->refresh_table_display. ENDIF. ENDMETHOD. ENDCLASS.
80Modules *&-----------------------------------------------------------------* *&
Module
(C) SAP AG
INIT_CONTROL_PROCESSING BC412
OUTPUT 73
*&-----------------------------------------------------------------* *
control related processing
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
create container object CREATE OBJECT ref_container EXPORTING
*
SIDE
= DOCK_AT_LEFT
extension
= 2000
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a010(bc412). ENDIF. *
create alv grid object and link to container CREATE OBJECT ref_alv EXPORTING i_parent
*
I_APPL_EVENTS
= ref_container = space
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a045(bc412). ENDIF. *
send basic list to alv grid control CALL METHOD ref_alv->set_table_for_first_display EXPORTING i_structure_name
= 'SPFLI'
*
IS_VARIANT
=
*
I_SAVE
=
*
I_DEFAULT
= 'X'
*
IS_LAYOUT
=
*
IS_PRINT
=
*
IT_SPECIAL_GROUPS
=
(C) SAP AG
BC412
74
*
IT_TOOLBAR_EXCLUDING
=
CHANGING it_outtab
= it_spfli
*
IT_FIELDCATALOG
=
*
IT_SORT
=
*
IT_FILTER
=
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. *
event handling --> only ABAP Objects part,
*
CFW registration is performed by ALV proxy object SET HANDLER lcl_event_handler=>on_double_click FOR ref_alv. ENDIF.
ENDMODULE.
(C) SAP AG
" INIT_CONTROL_PROCESSING
BC412
OUTPUT
75
Solutions to Exercise 2 (Optional Sections) Unit: ALV Grid Control Topic: Events of the ALV Grid Control
Model solution SAPBC412_BASS_EXERCISE_2A
81ABAP Program 82Local Classes *------------------------------------------------------------------* *
CLASS lcl_event_handler DEFINITION
*------------------------------------------------------------------* CLASS lcl_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row, *
------------------------------------------------------------on_close
FOR EVENT close OF cl_gui_dialogbox_container IMPORTING sender,
*
------------------------------------------------------------on_print_tol
FOR EVENT print_top_of_list OF cl_gui_alv_grid.
ENDCLASS.
*------------------------------------------------------------------* *
CLASS lcl_event_handler IMPLEMENTATION
*------------------------------------------------------------------* CLASS lcl_event_handler IMPLEMENTATION. METHOD on_double_click. *
find out selected line (double click) READ TABLE it_spfli INTO wa_spfli INDEX e_row-index. IF sy-subrc NE 0. MESSAGE i075(bc412).
" internal error
EXIT. ENDIF. (C) SAP AG
BC412
76
*
copy corresponding flight data to it_popup CLEAR it_popup. LOOP AT it_sflight INTO wa_sflight WHERE carrid = wa_spfli-carrid AND
connid = wa_spfli-connid.
INSERT wa_sflight INTO TABLE it_popup. ENDLOOP. IF sy-subrc NE 0.
" no data buffered
SELECT * FROM sflight INTO CORRESPONDING FIELDS OF wa_sflight WHERE carrid = wa_spfli-carrid AND
connid = wa_spfli-connid.
INSERT wa_sflight INTO TABLE: it_sflight, it_popup. ENDSELECT. *--------------------------------------------------------------* *
alternative algorithm
*--------------------------------------------------------------* *
SELECT * FROM sflight
*
APPENDING CORRESPONDING FIELDS OF TABLE it_sflight
*
WHERE carrid = wa_spfli-carrid
*
AND
connid = wa_spfli-connid.
* *
INSERT LINES OF it_sflight INTO TABLE it_popup.
*--------------------------------------------------------------* ENDIF.
IF box_container IS INITIAL. *
create dialog box container CREATE OBJECT box_container EXPORTING width
(C) SAP AG
= 800 BC412
77
height
= 200
top
= 120
left
= 120
caption
= text-002
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a010(bc412). ENDIF. *
set event handler for dialogbox container: --> close SET HANDLER on_close FOR box_container. ENDIF. IF box_alv IS INITIAL.
*
create avl grid object and link to dialogbox container CREATE OBJECT box_alv EXPORTING i_parent
= box_container
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a045(bc412). ENDIF. *
send popup data to new alv object CALL METHOD box_alv->set_table_for_first_display EXPORTING i_structure_name
= 'SFLIGHT'
CHANGING it_outtab
= it_popup
*
IT_FIELDCATALOG
=
*
IT_SORT
=
*
IT_FILTER
=
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. (C) SAP AG
BC412
78
MESSAGE a012(bc412). ENDIF. ELSE.
" do only refresh alv contents
CALL METHOD box_alv->refresh_table_display. ENDIF. ENDMETHOD. *------------------------------------------------------------------METHOD on_close. CALL METHOD sender->free. CLEAR: box_container, box_alv. ENDMETHOD. *------------------------------------------------------------------METHOD on_print_tol. *
local data DATA: wa_carr
LIKE LINE OF so_carr,
l_carrname TYPE scarr-carrname. SKIP 3. READ TABLE so_carr INTO wa_carr INDEX 1. IF sy-subrc NE 0. WRITE: / text-003. *
'List of connections for all flight carrier' ELSE. SELECT SINGLE carrname FROM scarr INTO l_carrname WHERE carrid = wa_carr-low. IF sy-subrc NE 0.
*
internal error: bad situation :-) ELSE. WRITE: / text-004, wa_carr-low, l_carrname.
*
'List of connections for carrier: ' ENDIF. ENDIF. SKIP 2.
(C) SAP AG
BC412
79
ENDMETHOD. ENDCLASS.
83ABAP Program: Event Blocks START-OF-SELECTION. *
read data SELECT * FROM
spfli INTO TABLE it_spfli WHERE carrid IN so_carr
ORDER BY carrid connid. IF sy-subrc NE 0. MESSAGE a061(bc412). ENDIF. *--------------------------------------------------------------*
taken out: --> read data incremental
*
(if user double clicks a line)
*--------------------------------------------------------------*
SELECT * FROM sflight INTO TABLE it_sflight
*
WHERE carrid IN so_carr
*
ORDER BY carrid connid fldate.
* *
IF sy-subrc NE 0.
*
MESSAGE a062(bc412). ENDIF. CALL SCREEN 100.
84Modules *&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
control related processing
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
create container object CREATE OBJECT ref_container EXPORTING
* (C) SAP AG
SIDE
= DOCK_AT_LEFT BC412
80
extension
= 2000
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a010(bc412). ENDIF. *
create alv grid object and link to container CREATE OBJECT ref_alv EXPORTING i_parent
*
I_APPL_EVENTS
= ref_container = space
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a045(bc412). ENDIF. *
send basic list to alv grid control CALL METHOD ref_alv->set_table_for_first_display EXPORTING i_structure_name
= 'SPFLI'
*
IS_VARIANT
=
*
I_SAVE
=
*
I_DEFAULT
= 'X'
*
IS_LAYOUT
=
*
IS_PRINT
=
*
IT_SPECIAL_GROUPS
=
*
IT_TOOLBAR_EXCLUDING
=
CHANGING it_outtab
= it_spfli
*
IT_FIELDCATALOG
=
*
IT_SORT
=
*
IT_FILTER
=
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. (C) SAP AG
BC412
81
MESSAGE a012(bc412). ENDIF. *
event handling --> only ABAP Objects part,
*
CFW registration is performed by ALV proxy object SET HANDLER: lcl_event_handler=>on_double_click FOR ref_alv, lcl_event_handler=>on_print_tol
FOR ref_alv.
ENDIF. ENDMODULE.
(C) SAP AG
" INIT_CONTROL_PROCESSING
BC412
OUTPUT
82
Solutions to Exercise 3 Unit: ALV Grid Control Topic: Field Catalog
Model solution SAPBC412_BASS_EXERCISE_3
85Screen flow logic 86SCREEN 100 PROCESS BEFORE OUTPUT. MODULE status_0100. MODULE init_control_processing. * PROCESS AFTER INPUT. MODULE user_command_0100.
87ABAP Program 88Data Declarations REPORT
sapbc412_alvs_exercise_3 MESSAGE-ID bc412.
TYPES: BEGIN OF ty_sflight. INCLUDE STRUCTURE sflight. TYPES:
percentage TYPE sbc400focc-percentage, sign
TYPE c,
END OF ty_sflight. DATA:
*
ok_code
TYPE sy-ucomm,
" command field
copy_ok_code
LIKE ok_code,
" copy of ok_code
control specific: object references ref_container TYPE REF TO cl_gui_docking_container, ref_alv
TYPE REF TO cl_gui_alv_grid,
box_container TYPE REF TO cl_gui_dialogbox_container, box_alv
(C) SAP AG
TYPE REF TO cl_gui_alv_grid,
BC412
83
*
*
internal tables it_spfli
TYPE TABLE OF spfli,
it_sflight
TYPE TABLE OF ty_sflight,
it_popup
TYPE TABLE OF ty_sflight,
it_fcat
TYPE lvc_t_fcat,
work areas wa_spfli
LIKE LINE OF it_spfli,
wa_sflight
LIKE LINE OF it_sflight.
89Selection Screen * selection screen SELECT-OPTIONS: so_carr FOR wa_sflight-carrid NO-EXTENSION NO INTERVALS.
90Local Classes *-----------------------------------------------------------------* *
CLASS lcl_event_handler IMPLEMENTATION
*-----------------------------------------------------------------* CLASS lcl_event_handler IMPLEMENTATION. METHOD on_double_click. *
local data DATA: wa_popup LIKE LINE OF it_popup.
*
find out selected line (double click) READ TABLE it_spfli INTO wa_spfli INDEX e_row-index. IF sy-subrc NE 0. MESSAGE i075(bc412).
" internal error
EXIT. ENDIF. *
copy corresponding flight data to it_popup CLEAR it_popup. LOOP AT it_sflight INTO wa_sflight WHERE carrid = wa_spfli-carrid AND
connid = wa_spfli-connid.
INSERT wa_sflight INTO TABLE it_popup.
(C) SAP AG
BC412
84
ENDLOOP. IF sy-subrc NE 0. wa_sflight-sign = '%'. SELECT * FROM sflight INTO wa_sflight WHERE carrid = wa_spfli-carrid AND
connid = wa_spfli-connid.
wa_sflight-percentage = wa_sflight-seatsocc * 100 / wa_sflight-seatsmax. INSERT wa_sflight INTO TABLE: it_sflight, it_popup. ENDSELECT. ENDIF. IF box_container IS INITIAL. *
create dialog box container CREATE OBJECT box_container EXPORTING width
= 800
height
= 200
top
= 120
left
= 120
caption
= text-002
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a010(bc412). ENDIF. *
set event handler for dialogbox container: --> close SET HANDLER on_close FOR box_container. ENDIF.
(C) SAP AG
BC412
85
IF box_alv IS INITIAL. *
create avl grid object and link to dialogbox container CREATE OBJECT box_alv EXPORTING i_parent
= box_container
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a045(bc412). ENDIF. *
maintain field catalog correspondingly CLEAR it_fcat. PERFORM create_field_catalog CHANGING it_fcat.
*
send popup data to new alv object CALL METHOD box_alv->set_table_for_first_display EXPORTING i_structure_name
= 'SFLIGHT'
CHANGING it_outtab
= it_popup
it_fieldcatalog
= it_fcat
*
IT_SORT
=
*
IT_FILTER
=
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. ELSE.
" do only refresh alv contents
CALL METHOD box_alv->refresh_table_display. ENDIF. ENDMETHOD. * ----------------------------------------------------------------METHOD on_close. CALL METHOD sender->free. (C) SAP AG
BC412
86
FREE: box_container, box_alv. ENDMETHOD. * ----------------------------------------------------------------METHOD on_print_tol. *
local data DATA: wa_carr
LIKE LINE OF so_carr,
l_carrname TYPE scarr-carrname. SKIP 3. READ TABLE so_carr INTO wa_carr INDEX 1. IF sy-subrc NE 0. WRITE: / text-003. *
'List of connections for all flight carrier' ELSE. SELECT SINGLE carrname FROM scarr INTO l_carrname WHERE carrid = wa_carr-low. IF sy-subrc NE 0.
*
internal error: bad situation :-) ELSE. WRITE: / text-004, wa_carr-low, l_carrname.
*
'List of connections for carrier: ' ENDIF. ENDIF. ENDMETHOD.
ENDCLASS.
91Subroutines *&----------------------------------------------------------------* *&
Form
CREATE_FIELD_CATALOG
*&----------------------------------------------------------------* *
build the field catalog
*-----------------------------------------------------------------* *
-->
p_it_fcat
field catalog
*-----------------------------------------------------------------* FORM create_field_catalog CHANGING p_it_fcat TYPE lvc_t_fcat. * local data DATA: wa_fcat LIKE LINE OF it_fcat. *----------------------------------------------------------------(C) SAP AG
BC412
87
* field PERCENTAGE *----------------------------------------------------------------* only DDIC relashionship fields needed wa_fcat-fieldname = 'PERCENTAGE'. * wa_fcat-ref_field = wa_fcat-ref_table = 'SBC400FOCC'. APPEND wa_fcat TO p_it_fcat. CLEAR wa_fcat. *----------------------------------------------------------------* field SIGN *----------------------------------------------------------------* field with local type no DDIC relationship wa_fcat-fieldname = 'SIGN'. wa_fcat-outputlen = 2. wa_fcat-coltext
= 'Unit'.
wa_fcat-tooltip
= 'Unit = %'.
APPEND wa_fcat TO p_it_fcat. ENDFORM.
(C) SAP AG
" CREATE_FIELD_CATALOG
BC412
88
Complete Solution to Exercises Unit: ALV Grid Control
Model solution SAPBC412_BASS_EXERCISE
92Screen flow logic 93SCREEN 100 PROCESS BEFORE OUTPUT. MODULE status_0100. MODULE init_control_processing. * PROCESS AFTER INPUT. MODULE user_command_0100.
94ABAP Program 95Data Declarations REPORT
sapbc412_alvs_exercise_3 MESSAGE-ID bc412.
TYPES: BEGIN OF ty_sflight. INCLUDE STRUCTURE sflight. TYPES:
percentage TYPE sbc400focc-percentage, sign
TYPE c,
END OF ty_sflight.
DATA:
*
ok_code
TYPE sy-ucomm,
" command field
copy_ok_code
LIKE ok_code,
" copy of ok_code
control specific: object references ref_container TYPE REF TO cl_gui_docking_container, ref_alv
TYPE REF TO cl_gui_alv_grid,
box_container TYPE REF TO cl_gui_dialogbox_container, box_alv (C) SAP AG
TYPE REF TO cl_gui_alv_grid, BC412
89
*
*
internal tables it_spfli
TYPE TABLE OF spfli,
it_sflight
TYPE TABLE OF ty_sflight,
it_popup
TYPE TABLE OF ty_sflight,
it_fcat
TYPE lvc_t_fcat,
work areas wa_spfli
LIKE LINE OF it_spfli,
wa_sflight
LIKE LINE OF it_sflight.
96Selection Screen SELECT-OPTIONS: so_carr FOR wa_spfli-carrid NO-EXTENSION NO INTERVALS.
97Local Classes * event handler class *------------------------------------------------------------------* *
CLASS lcl_event_handler DEFINITION
*------------------------------------------------------------------* CLASS lcl_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row, *
------------------------------------------------------------on_close
FOR EVENT close OF cl_gui_dialogbox_container IMPORTING sender,
*
------------------------------------------------------------on_print_tol
FOR EVENT print_top_of_list OF cl_gui_alv_grid.
ENDCLASS. *-----------------------------------------------------------------* *
CLASS lcl_event_handler IMPLEMENTATION
*-----------------------------------------------------------------* CLASS lcl_event_handler IMPLEMENTATION. METHOD on_double_click. *
local data DATA: wa_popup LIKE LINE OF it_popup.
(C) SAP AG
BC412
90
*
find out selected line (double click) READ TABLE it_spfli INTO wa_spfli INDEX e_row-index. IF sy-subrc NE 0. MESSAGE i018. EXIT. ENDIF.
*
copy corresponding flight data to it_popup CLEAR it_popup. LOOP AT it_sflight INTO wa_sflight WHERE carrid = wa_spfli-carrid AND
connid = wa_spfli-connid.
INSERT wa_sflight INTO TABLE it_popup. ENDLOOP. IF sy-subrc NE 0. wa_sflight-sign = '%'. SELECT * FROM sflight INTO wa_sflight WHERE carrid = wa_spfli-carrid AND
connid = wa_spfli-connid.
wa_sflight-percentage = wa_sflight-seatsocc * 100 / wa_sflight-seatsmax. INSERT wa_sflight INTO TABLE: it_sflight, it_popup. ENDSELECT. ENDIF. IF box_container IS INITIAL. *
create dialog box container CREATE OBJECT box_container EXPORTING
(C) SAP AG
BC412
91
width
= 800
height
= 200
top
= 120
left
= 120
caption
= text-002
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a010(bc412). ENDIF. *
set event handler for dialogbox container: --> close SET HANDLER on_close FOR box_container. ENDIF. IF box_alv IS INITIAL.
*
create avl grid object and link to dialogbox container CREATE OBJECT box_alv EXPORTING i_parent
= box_container
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a045(bc412). ENDIF. *
maintain field catalog correspondingly CLEAR it_fcat. PERFORM create_field_catalog CHANGING it_fcat.
*
send popup data to new alv object CALL METHOD box_alv->set_table_for_first_display EXPORTING i_structure_name
= 'SFLIGHT'
CHANGING
* (C) SAP AG
it_outtab
= it_popup
it_fieldcatalog
= it_fcat
IT_SORT
= BC412
92
*
IT_FILTER
=
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE a012(bc412). ENDIF. ELSE.
" do only refresh alv contents
CALL METHOD box_alv->refresh_table_display. ENDIF. ENDMETHOD. * ----------------------------------------------------------------METHOD on_close. CALL METHOD sender->free. FREE: box_container, box_alv. ENDMETHOD. * ----------------------------------------------------------------METHOD on_print_tol. *
local data DATA: wa_carr
LIKE LINE OF so_carr,
l_carrname TYPE scarr-carrname. SKIP 3. READ TABLE so_carr INTO wa_carr INDEX 1. IF sy-subrc NE 0. WRITE: / text-003. *
'List of connections for all flight carrier' ELSE. SELECT SINGLE carrname FROM scarr INTO l_carrname WHERE carrid = wa_carr-low. IF sy-subrc NE 0.
*
internal error: bad situation :-) ELSE. WRITE: / text-004, wa_carr-low, l_carrname.
*
'List of connections for carrier: ' ENDIF. ENDIF.
(C) SAP AG
BC412
93
ENDMETHOD. ENDCLASS.
98ABAP Program: Event Blocks START-OF-SELECTION. *
read data SELECT * FROM
spfli INTO TABLE it_spfli WHERE carrid IN so_carr
ORDER BY carrid connid. IF sy-subrc NE 0. MESSAGE a061. ENDIF. CALL SCREEN 100.
99Modules *&-----------------------------------------------------------------* *&
Module
STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *
GUI settings
*------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'SCREEN_0100'. SET TITLEBAR 'SCREEN_0100'. ENDMODULE.
" STATUS_0100
OUTPUT
*&-----------------------------------------------------------------* *&
Module
USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *
implementation of GUI functions
*------------------------------------------------------------------* MODULE user_command_0100 INPUT. copy_ok_code = ok_code. CLEAR ok_code. CASE copy_ok_code. WHEN 'BACK' OR 'CANCEL' OR 'EXIT'. LEAVE PROGRAM. ENDCASE. ENDMODULE. (C) SAP AG
" USER_COMMAND_0100 BC412
INPUT 94
*&-----------------------------------------------------------------* *&
Module
INIT_CONTROL_PROCESSING
OUTPUT
*&-----------------------------------------------------------------* *
control related processing
*------------------------------------------------------------------* MODULE init_control_processing OUTPUT. IF ref_container IS INITIAL. *
create container object CREATE OBJECT ref_container EXPORTING
*
SIDE
= DOCK_AT_LEFT
extension
= 2000
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a010(bc412). ENDIF. *
create alv grid object and link to container CREATE OBJECT ref_alv EXPORTING i_parent
*
I_APPL_EVENTS
= ref_container = space
EXCEPTIONS others
= 1.
IF sy-subrc 0. MESSAGE a045. ENDIF. *
send basic list to alv grid control CALL METHOD ref_alv->set_table_for_first_display EXPORTING i_structure_name
= 'SPFLI'
*
IS_VARIANT
=
*
I_SAVE
=
*
I_DEFAULT
= 'X'
(C) SAP AG
BC412
95
*
IS_LAYOUT
=
*
IS_PRINT
=
*
IT_SPECIAL_GROUPS
=
*
IT_TOOLBAR_EXCLUDING
=
CHANGING it_outtab
= it_spfli
*
IT_FIELDCATALOG
=
*
IT_SORT
=
*
IT_FILTER
=
EXCEPTIONS OTHERS
= 1.
IF sy-subrc 0. MESSAGE a012. ENDIF. *
event handling --> only ABAP Objects part,
*
CFW registration is performed by ALV proxy object SET HANDLER: lcl_event_handler=>on_double_click FOR ref_alv, lcl_event_handler=>on_print_tol
FOR ref_alv.
ENDIF. ENDMODULE.
" INIT_CONTROL_PROCESSING
OUTPUT
100Subroutines *&-----------------------------------------------------------------* *&
Form
CREATE_FIELD_CATALOG
*&-----------------------------------------------------------------* *
build the field catalog
*------------------------------------------------------------------* *
-->
p_it_fcat
field catalog
*------------------------------------------------------------------* FORM create_field_catalog CHANGING p_it_fcat TYPE lvc_t_fcat. * local data DATA: wa_fcat LIKE LINE OF it_fcat. *------------------------------------------------------------------* field PERCENTAGE *------------------------------------------------------------------(C) SAP AG
BC412
96
* only DDIC relashionship fields needed wa_fcat-fieldname = 'PERCENTAGE'. * wa_fcat-ref_field = wa_fcat-ref_table = 'SBC400FOCC'. APPEND wa_fcat TO p_it_fcat. CLEAR wa_fcat. *------------------------------------------------------------------* field SIGN *------------------------------------------------------------------* field with local type no DDIC relationship wa_fcat-fieldname = 'SIGN'. wa_fcat-outputlen = 2. wa_fcat-coltext
= 'Unit'.
wa_fcat-tooltip
= 'Unit = %'.
APPEND wa_fcat TO p_it_fcat. ENDFORM.
(C) SAP AG
" CREATE_FIELD_CATALOG
BC412
97
101 Appendix
Contents: Information about the global classes used in BC412 Table of contents
SAP AG 1999
(C) SAP AG
BC412
1
101.2Information on the Global Classes of BC412 102Content This appendix describes the global classes used in the demo programs of training course BC412. Class CL_BC412_PICTURE_1 illustrates the usage of context menus while classes CL_BC412_MAPPING_4_2_TREE and CL_BC412_FLIGHT_INFO_TREE1 are implementations of the flight booking tree described in the unit on the SAP Tree Control.
102.2Overview 1.
2.
3.
4.
Information on the Global Classes of BC412 1.1
Content
1.2.
Overview
Global Class CL_BC412_PICTURE_1 2.1
General Description
2.2
Interface 2.2.1
The Method Constructor
2.2.2
The Method FREE
2.2.3
The Event PICTURE_CLICK
2.3
Context Menus of the Picture Control
2.4
Definition of the Class
2.5
Implementation of the Class
Global Class CL_BC412_MAPPING_4_2_TREE 3.1
General Description
3.2
Interface 3.2.1
The Method INSERT_BUSINESS_KEY
3.2.2
The Method DELETE_BUSINESS_KEY
3.2.3
The Method DELETE_TECHNICAL_KEY
3.2.4
The Method GET_BUSINESS_KEY
3.2.5
The Method GET_TECHNICAL_KEY
3.3
Definition of the Class
3.4
Implementation of the Class
Global Class CL_BC412_FLIGHT_INFO_TREE1 4.1
General Description
4.2
Interface
(C) SAP AG
4.2.1
The Method CONSTRUCTOR
4.2.2
The Method FREE
4.2.3
The Method GET_SCARR_DETAILS
4.2.4
The Method GET_SPFLI_DETAILS
4.2.5
The Method GET_SFLIGHT_DETAILS
4.2.6
The Method GET_SBOOK_DETAILS
4.2.7
The Method GET_SCUSTOM_DETAILS
4.2.8
The Event NODE_DOUBLE_CLICK BC412
2
5.
4.3
Data, Methods, and Events Used Internally in the Class
4.4
Definition of the Class
4.5
Implementation of the Class
Global Data Types Used in the ABAP Dictionary 5.1
5.2
Table Types 5.1.1
BC412_FUNCTION_ITT
5.1.2
BC412_MAP_HASH1
5.1.3
BC412_MAP_HASH1
5.1.4
BC412_SBOOK_ITT
5.1.5
BC412_SBOOK_NODE_ITT
5.1.6
BC412_SCARR_ITT
5.1.7
BC412_SUSTOM_ITT
5.1.8
BC412_SFLIGHT_ITT
5.1.9
BC412_SPFLI_ITT
Structure Types 5.2.1
5.3
BC412_SIM_TREE_NODE_STRUC
Data Elements
102.3Global Class CL_BC412_PICTURE_1 102.4General Description The global class CL_BC412_PICTURE_1 is an example of a "wrapper" of a Picture Control instance that has a context menu. Using the options of the context menu, you can determine the display mode (attribute DISPLAY_MODE) of the Picture Control instance. Setting up the context menu and responding to an option chosen is handled independently by each instance. The class has been designed as an example of handling context menus.
102.5Interface The class has two methods - the CONSTRUCTOR and the method FREE – and the event PICTURE_CLICK. With the constructur, you pass the container reference, the URL of the image to be loaded, and texts to be displayed in the context menu. In addition, you can control if you want to handle the event PICTURE_CLICK or not. Using method FREE, you can release the resources of your Picture Control instance at the frontend. The event PICTURE_CLICK is triggered if you click the object displayed in the frontend control.
102.5.2The Method Constructor The constructor has the following interface: CREATE OBJECT object EXPORTING i_parent i_url
= variable_1 = variable_2
i_picture_click
= variable_3
i_appl_event_pc i_stretch_text i_fit_text
(C) SAP AG
= variable_4 = variable_5
= variable_6
BC412
3
i_normal_text
= variable_7
i_fit_center_text
= variable_8
i_normal_center_text = variable_9 EXCEPTIONS picture_error
= value_1
picture_load_error = value_2.
The interface parameters have the following meaning: Parameter name
Meaning
i_parent
Container reference You use this parameter to pass a container reference. The Picture Control instance is displayed in the corresponding container instance.
i_url
URL of the object to be displayed You use this parameter to pass the URL of the object to be displayed in the Picture Control (image in file format GIF, JPEG, BMP or SAP icon).
i_picture_click
Flag variable: Registering the event PICTURE_CLICK You use this parameter to determine if the event PICTURE_CLICK of the Picture Control instance is to be registered at the Control Framework. To assign a value to this parameter, you use the class constants C_TRUE and C_FALSE. i_picture_click = cl_bc412_picture_1=>c_true : The event PICTURE_CLICK is registered at the CFW. i_picture_click = cl_bc412_picture_1=>c_false : The event PICTURE_CLICK is not registered at the CFW.
i_appl_event_pc
Registering PICTURE_CLICK as an application event or as a system event i_appl_event_pc = cl_bc412_picture_1=>c_true: Application event i_appl_event_pc = cl_bc412_picture_1=>c_false : System event
It only makes sense to assign a value to parameter i_appl_event_pc if event PICTURE_CLICK is registered (see parameter i_picture_click) i_stretch_text
Text displayed in the context menu for the display mode DISPLAY_MODE_STRETCH
i_fit_text
Text displayed in the context menu for the display mode DISPLAY_MODE_FIT
i_normal_text
Text displayed in the context menu for the display mode DISPLAY_MODE_NORMAL
i_fit_center_text
Text displayed in the context menu for the display mode DISPLAY_MODE_FIT_CENTER
i_normal_center_text
Text displayed in the context menu for the display mode DISPLAY_MODE_NORMAL_CENTER
The exceptions have the following meaning: Parameter name
Meaning
picture_error
Error creating the Picture Control instance
picture_load_error
Error loading the data object to be displayed
(C) SAP AG
BC412
4
102.5.3The Method FREE The method FREE releases all resources used by the instantiated control at the frontend. The only interface parameter is the exception PICTURE_ERROR which indicates that an internal error occurred while the system tried to access the object.
102.5.4The Event PICTURE_CLICK The event PICTURE_CLICK is triggered if the mouse has been clicked in the data object (image) displayed. The parameters MOUSE_POS_X and MOUSE_POS_Y contain the coordinates of the pixel on which the cursor was positioned at the time the mouse was clicked.
102.6Context Menus of the Picture Control The class CL_BC412_PICTURE_1 supports a context menu for the "wrapped" Picture Control instance. The following steps are required:
In the constructor, the events CONTEXT_MENU and MENU_SELECTED of the Picture Control instance are registered at the Control Framework (SET_REGISTERED_EVENTS). The methods ON_CONTEXT_MENU and ON_CONTEXT_MENU_SELECTED (visibility PROTECTED) of the class CL_BC412_PICTURE_1 are registered as the handling methods on the ABAP side.
The context menu is set up dynamically. This means that the system does not generate a static program object (= an interface status of type CONTEXT_MENU must be created in the Screen Painter), but sets up the context menu (function codes + menu texts) at runtime (if requested by the user). Since the function codes and the texts displayed in the menu should always be the same, an internal table (instance attribute IT_FUNCTION) with the menu texts and associated function codes is set up in the constructor.
If a user requests a context menu on the Picture Control instance, the control triggers the event CONTEXT_MENU. As a result of the two registration steps, the method ON_CONTEXT_MENU is called.
In the method ON_CONTEXT_MENU, an instance of the type CL_CTMENU is created (CREATE OBJECT). Please note that, for all other EnjoySAP controls, you do not need to create the context menu instance explicitly. All other EnjoySAP controls create a context menu object independently, and pass a reference to this context menu instance through the event interface when the event CONTEXT_MENU is triggered. The options for the menu are sent to the context menu instance (function codes and menu texts are sent using the internal table IT_FUNCTION). You then send the context menu object to the Picture Control instance by calling the method DISPLAY_CONTEXT_MENU of your Picture Control instance. Using the interface of the method, you pass the reference to the context menu object.
If a user chooses a context menu option, the relevant control triggers the event CONTEXT_MENU_SELECTED. The function code of the function chosen (parameter FCODE) and a reference to the sending object (parameter SENDER; this parameter is not explicitly contained in the interface and is generally transferred for ABAP Objects events) are provided through the interface. As a result of the two registration steps, the method ON_CONTEXT_MENU_SELECTED is called.
In the method ON_CONTEXT_MENU_SELECTED, the value of the attribute DISPLAY_MODE of the Picture Control instance is determined based on the function code (FCODE) transmitted. This value is then passed to the Picture Control instance using the method SET_DISPLAY_MODE.
102.7Definition of the Class *" type-pools TYPE-POOLS: cntl ." Type definitions used by the Control Framework
*---------------------------------------------------------------------* *
CLASS CL_BC412_PICTURE_1 DEFINITION
*---------------------------------------------------------------------* *
........
*
*---------------------------------------------------------------------* CLASS cl_bc412_picture_1 DEFINITION PUBLIC
(C) SAP AG
BC412
5
FINAL CREATE PUBLIC .
*---------------------------------------------------------------------*" public components of class CL_BC412_PICTURE_1 *---------------------------------------------------------------------PUBLIC SECTION.
*" constants CONSTANTS: c_true TYPE bc412_text1 VALUE 'X' , c_false TYPE bc412_text1 VALUE ' ' .
*" events EVENTS: picture_click EXPORTING value(mouse_pos_x) TYPE i value(mouse_pos_y) TYPE i .
*" methods METHODS: constructor IMPORTING i_parent
TYPE REF TO cl_gui_container
value(i_url)
TYPE s_url
value(i_picture_click)
TYPE bc412_text1 DEFAULT 'X'
value(i_appl_event_pc) value(i_stretch_text) value(i_fit_text)
TYPE bc412_text1 DEFAULT 'X' TYPE gui_text DEFAULT 'STRETCH'
TYPE gui_text DEFAULT 'FIT'
value(i_normal_text)
TYPE gui_text DEFAULT 'NORMAL'
value(i_fit_center_text)
TYPE gui_text DEFAULT 'FIT_CENTER'
value(i_normal_center_text) TYPE gui_text DEFAULT 'NORMAL_CENTER' EXCEPTIONS picture_error picture_load_error , *---------------------------------------------------------------------free EXCEPTIONS picture_error .
*---------------------------------------------------------------------*" protected components of class CL_BC412_PICTURE_1 *----------------------------------------------------------------------
(C) SAP AG
BC412
6
PROTECTED SECTION.
*" instance attributes DATA: context_menu_ref TYPE REF TO cl_ctmenu , picture_ref url
TYPE REF TO cl_gui_picture , TYPE s_url ,
it_function
TYPE bc412_function_itt .
*" methods METHODS: on_picture_click FOR EVENT picture_click OF cl_gui_picture IMPORTING sender mouse_pos_x mouse_pos_y , *---------------------------------------------------------------------on_context_menu FOR EVENT context_menu OF cl_gui_picture IMPORTING sender , *---------------------------------------------------------------------on_context_menu_selected FOR EVENT context_menu_selected OF cl_gui_picture IMPORTING fcode sender .
102.8Implementation of the Class METHOD constructor. * local data DATA: l_events
TYPE cntl_simple_events,
l_wa_events LIKE LINE OF l_events, wa_function LIKE LINE OF it_function.
* create picture object CREATE OBJECT picture_ref EXPORTING *
LIFETIME =
*
SHELLSTYLE =
(C) SAP AG
BC412
7
parent
= i_parent
EXCEPTIONS error = 1.
IF sy-subrc NE 0. RAISE picture_error. ENDIF.
* send picture to picture control CALL METHOD picture_ref->load_picture_from_url EXPORTING url *
= i_url
RESULT = EXCEPTIONS error = 1.
IF sy-subrc NE 0. RAISE picture_load_error. ENDIF.
* register events: IF i_picture_click = c_true. * picture_click l_wa_events-eventid
= cl_gui_picture=>eventid_picture_click.
l_wa_events-appl_event = i_appl_event_pc. INSERT l_wa_events INTO TABLE l_events. ENDIF. * context_menu l_wa_events-eventid
= cl_gui_picture=>eventid_context_menu.
l_wa_events-appl_event = ' '. INSERT l_wa_events INTO TABLE l_events. * context_menu_selected l_wa_events-eventid
=
cl_gui_picture=>eventid_context_menu_selected. l_wa_events-appl_event = ' '. INSERT l_wa_events INTO TABLE l_events.
CALL METHOD picture_ref->set_registered_events EXPORTING events = l_events EXCEPTIONS cntl_error cntl_system_error
=1 =2
illegal_event_combination = 3. IF sy-subrc NE 0.
(C) SAP AG
BC412
8
*
to implement ENDIF.
SET HANDLER on_picture_click
FOR picture_ref.
SET HANDLER on_context_menu
FOR picture_ref.
SET HANDLER on_context_menu_selected FOR picture_ref. * store url of picture url = i_url. * construct context menu functions in it_functions wa_function-fcode = 'STRETCH'. wa_function-text = i_stretch_text. INSERT wa_function INTO TABLE it_function.
" 1.
wa_function-fcode = 'FIT'. wa_function-text = i_fit_text. INSERT wa_function INTO TABLE it_function.
" 2.
wa_function-fcode = 'NORMAL'. wa_function-text = i_normal_text. INSERT wa_function INTO TABLE it_function.
" 3.
wa_function-fcode = 'FIT_CENTER'. wa_function-text = i_fit_center_text. INSERT wa_function INTO TABLE it_function.
" 4.
wa_function-fcode = 'NORMAL_CENTER'. wa_function-text = i_normal_center_text. INSERT wa_function INTO TABLE it_function.
" 5.
ENDMETHOD.
*----------------------------------------------------------------------------------
METHOD free. CALL METHOD picture_ref->free EXCEPTIONS cntl_error
=1
cntl_system_error = 2.
IF sy-subrc NE 0. RAISE picture_error. ENDIF. ENDMETHOD.
*----------------------------------------------------------------------------------
(C) SAP AG
BC412
9
METHOD on_picture_click. RAISE EVENT picture_click EXPORTING mouse_pos_x = mouse_pos_x mouse_pos_y = mouse_pos_y. ENDMETHOD.
*----------------------------------------------------------------------------------
METHOD on_context_menu. * local data DATA: wa_function LIKE LINE OF it_function.
* create context menu object CREATE OBJECT context_menu_ref.
* create dynamic context menu LOOP AT it_function INTO wa_function. CALL METHOD context_menu_ref->add_function EXPORTING fcode = wa_function-fcode text = wa_function-text. ENDLOOP.
* display context menu CALL METHOD sender->display_context_menu EXPORTING context_menu = context_menu_ref EXCEPTIONS error = 1.
FREE context_menu_ref. ENDMETHOD.
*----------------------------------------------------------------------------------
METHOD on_context_menu_selected. * local data DATA: l_display_mode TYPE i.
CASE fcode. WHEN 'STRETCH'. l_display_mode = cl_gui_picture=>display_mode_stretch. WHEN 'FIT'.
(C) SAP AG
BC412
10
l_display_mode = cl_gui_picture=>display_mode_fit. WHEN 'NORMAL'. l_display_mode = cl_gui_picture=>display_mode_normal. WHEN 'FIT_CENTER'. l_display_mode = cl_gui_picture=>display_mode_fit_center. WHEN 'NORMAL_CENTER'. l_display_mode = cl_gui_picture=>display_mode_normal_center. ENDCASE.
CALL METHOD sender->set_display_mode EXPORTING display_mode = l_display_mode EXCEPTIONS error = 1.
* * *
IF sy-subrc NE 0. RAISE error. ENDIF.
ENDMETHOD.
103Global Class CL_BC412_MAPPING_4_2_TREE 103.2General Description The global class CL_BC412_MAPPING_4_2_TREE is used as an auxiliary class for instances of the class CL_BC412_FLIGHT_INFO_TREE_1 in training course BC412. The class CL_BC412_MAPPING_4_2_TREE illustrates key mapping (key of the application tables displayed in the tree node key). The instances of the class encapsulate two hash tables that implement key access to the logical mapping table in a manner favorable to performance (constant access time). Entries in the hash tables are generated by passing an application key using the method INSERT_BUSINESS_KEY. The instance subsequently assigns a technical node key and maintains both hash tables simultaneously. The node keys are assigned as values of a counter (which is managed by the object). The class implements the one-to-one mapping of a key with at most four components to the node keys.
103.3Interface The class has methods for creating key pairs (INSERT_BUSINESS_KEY), for managing key pairs (DELETE_BUSINESS_KEY, DELETE_TECHNICAL_KEY), and for determining the key partner (GET_BUSINESS_KEY, GET_TECHNICAL_KEY).
103.3.2The Method INSERT_BUSINESS_KEY The method creates a node key for the application key passed. CALL METHOD inset_business_key EXPORTING i_bkey1 = variable1
(C) SAP AG
BC412
11
i_bkey2 = variable2 i_bkey3 = variable3 i_bkey4 = variable4 IMPORTING e_tkey = variable5 EXCEPTIONS internal_error = value1 teckey_overflow = value2 invalid_buskey = value3.
The interface parameters have the following meaning: Parameter name
Meaning
i_bkey1
First key component of the application key From a semantic point of view, this component has the meaning of an airline ID.
i_bkey1
Second key component of the application key From a semantic point of view, this component has the meaning of an airline connection number.
i_bkey1
Third key component of the application key From a semantic point of view, this component has the meaning of a flight date.
i_bkey1
Fourth key component of the application key From a semantic point of view, this component has the meaning of a booking number for a flight booking.
i_tkey
Node key returned
The exceptions have the following meaning: Parameter name
Meaning
internal_error
Error accessing the hash table
teckey_overflow
Maximum node key that can be assigned has already been assigned
invalid_buskey
Application key passed already has a node key
103.3.3The Method DELETE_BUSINESS_KEY The method DELETE_BUSINESS_KEY has one predefined interface (sample), but no implementation (which must be added as required).
103.3.4The Method DELETE_TECHNICAL_KEY The method DELETE_TECHNICAL_KEY has one predefined interface (sample), but no implementation (which must be added as required).
103.3.5The Method GET_BUSINESS_KEY The method GET_BUSINESS_KEY returns the application key for the node key passed. The interface parameters have the following meaning: Parameter name
Meaning
i_tkey
Node key returned
(C) SAP AG
BC412
12
i_bkey1
First key component of the application key From a semantic point of view, this component has the meaning of an airline ID.
i_bkey1
Second key component of the application key From a semantic point of view, this component has the meaning of an airline connection number.
i_bkey1
Third key component of the application key From a semantic point of view, this component has the meaning of a flight date.
i_bkey1
Fourth key component of the application key From a semantic point of view, this component has the meaning of a booking number for a flight booking.
The exceptions have the following meaning: Parameter name
Meaning
invalid_teckey
Node key passed does not exist.
103.3.6The Method GET_TECHNICAL_KEY The method GET_TECHNICAL_KEY returns the node key for the application key passed. The interface parameters have the following meaning: Parameter name
Meaning
i_bkey1
First key component of the application key From a semantic point of view, this component has the meaning of an airline ID.
i_bkey1
Second key component of the application key From a semantic point of view, this component has the meaning of an airline connection number.
i_bkey1
Third key component of the application key From a semantic point of view, this component has the meaning of a flight date.
i_bkey1
Fourth key component of the application key From a semantic point of view, this component has the meaning of a booking number for a flight booking.
i_tkey
Node key returned
The exceptions have the following meaning: Parameter name
Meaning
invalid_buskey
Application key passed does not exist.
103.4Definition of the Class *---------------------------------------------------------------------* *
CLASS CL_BC412_MAPPING_4_2_TREE DEFINITION
*---------------------------------------------------------------------* *
........
(C) SAP AG
*
BC412
13
*---------------------------------------------------------------------* CLASS cl_bc412_mapping_4_2_tree DEFINITION PUBLIC FINAL CREATE PUBLIC .
*---------------------------------------------------------------------*" public components of class CL_BC412_MAPPING_4_2_TREE *---------------------------------------------------------------------PUBLIC SECTION.
*" methods METHODS: insert_business_key IMPORTING value(i_bkey1) TYPE s_carr_id value(i_bkey2) TYPE s_conn_id value(i_bkey3) TYPE s_date value(i_bkey4) TYPE s_book_id EXPORTING value(e_tkey) TYPE tv_nodekey EXCEPTIONS internal_error teckey_overflow invalid_buskey , *---------------------------------------------------------------------delete_business_key IMPORTING value(i_bkey1) TYPE s_carr_id value(i_bkey2) TYPE s_conn_id value(i_bkey3) TYPE s_date value(i_bkey4) TYPE s_book_id EXPORTING value(e_tkey) TYPE tv_nodekey EXCEPTIONS invalid_buskey , *---------------------------------------------------------------------delete_technical_key IMPORTING value(i_tkey) TYPE tv_nodekey EXPORTING value(e_bkey1) TYPE s_carr_id value(e_bkey2) TYPE s_conn_id value(e_bkey3) TYPE s_date
(C) SAP AG
BC412
14
value(e_bkey4) TYPE s_book_id EXCEPTIONS invalid_teckey , *---------------------------------------------------------------------get_business_key IMPORTING value(i_tkey) TYPE tv_nodekey EXPORTING value(e_bkey1) TYPE s_carr_id value(e_bkey2) TYPE s_conn_id value(e_bkey3) TYPE s_date value(e_bkey4) TYPE s_book_id EXCEPTIONS invalid_teckey , *---------------------------------------------------------------------get_technical_key IMPORTING value(i_bkey1) TYPE s_carr_id value(i_bkey2) TYPE s_conn_id value(i_bkey3) TYPE s_date value(i_bkey4) TYPE s_book_id EXPORTING value(e_tkey) TYPE tv_nodekey EXCEPTIONS invalid_buskey .
*---------------------------------------------------------------------*" protected components of class CL_BC412_MAPPING_4_2_TREE *---------------------------------------------------------------------PROTECTED SECTION.
*" types TYPES: buskey_1 TYPE s_carr_id , buskey_2 TYPE s_conn_id , buskey_3 TYPE s_date , buskey_4 TYPE s_book_id , teckey TYPE tv_nodekey .
*" instance attributes DATA: map1 TYPE bc412_map_hash1 , map2 TYPE bc412_map_hash2 .
(C) SAP AG
BC412
15
*---------------------------------------------------------------------*" private components of class CL_BC412_MAPPING_4_2_TREE *---------------------------------------------------------------------PRIVATE SECTION.
*" instance attributes DATA: counter TYPE i .
103.5Implementation of the Class METHOD insert_business_key. * local data DATA: wa_map TYPE bc412_map_linetype.
* existence check: valid key READ TABLE map1 WITH TABLE KEY bkey1 = i_bkey1 bkey2 = i_bkey2 bkey3 = i_bkey3 bkey4 = i_bkey4 TRANSPORTING NO FIELDS.
IF sy-subrc EQ 0.
" entry exists already
RAISE invalid_buskey. ENDIF.
* check for overflow of e_tkey IF counter GE 999999999999. RAISE teckey_overflow. ENDIF.
* note: maximum number to be hadled restricted by data type of *
tv_nodekey (CHAR 12)
* create new entry ADD 1 TO counter. wa_map-bkey1 = i_bkey1. wa_map-bkey2 = i_bkey2. wa_map-bkey3 = i_bkey3. wa_map-bkey4 = i_bkey4. wa_map-tkey = counter. e_tkey
= counter.
" return technical key
INSERT wa_map INTO TABLE map1.
(C) SAP AG
BC412
16
IF sy-subrc NE 0. RAISE internal_error. ENDIF.
INSERT wa_map INTO TABLE map2. IF sy-subrc NE 0. RAISE internal_error. ENDIF.
ENDMETHOD.
*----------------------------------------------------------------------
METHOD delete_business_key. * to be implemented ENDMETHOD.
*----------------------------------------------------------------------
METHOD delete_technical_key. * to be implemented ENDMETHOD.
*----------------------------------------------------------------------
METHOD get_business_key. * local data DATA: wa_map TYPE bc412_map_linetype.
* read entry READ TABLE map2 INTO wa_map WITH TABLE KEY tkey = i_tkey. IF sy-subrc NE 0. RAISE invalid_teckey. ENDIF.
e_bkey1 = wa_map-bkey1.
" return business key (1)
e_bkey2 = wa_map-bkey2.
" return business key (2)
e_bkey3 = wa_map-bkey3.
" return business key (3)
e_bkey4 = wa_map-bkey4.
" return business key (4)
ENDMETHOD.
(C) SAP AG
BC412
17
*----------------------------------------------------------------------
METHOD get_technical_key. * local data DATA: wa_map TYPE bc412_map_linetype.
* read entry READ TABLE map1 INTO wa_map WITH TABLE KEY bkey1 = i_bkey1 bkey2 = i_bkey2 bkey3 = i_bkey3 bkey4 = i_bkey4. IF sy-subrc NE 0. RAISE invalid_buskey. ENDIF.
e_tkey = wa_map-tkey.
" return technical key
ENDMETHOD.
104Global Class CL_BC412_FLIGHT_INFO_TREE1 104.2General Description The class CL_BC412_FLIGHT_INFO_TREE1 presents data of the flight data model (tables SCARR, SPFLI, SFLIGHT, SBOOK) by means of a Simple Tree instance in a hierarchical structure. The instances of the class collect the data (by means of incremental database accesses) (data is read if a user requests data for a node for the first time) and manage the application data read in internal tables. The class provides instance methods with which the users of the class can query the application data for a node. The read depth in the hierarchy can be determined using a parameter passed with the constructor.
104.3Interface The class has:
A constructor
The method FREE to release the resources used by the control at the frontend
Methods to query application data for a node
The event node_double_click which is triggered when a node is double-clicked.
104.3.2The Method CONSTRUCTOR You use the constructor to generate a Tree Control instance for which you create a root node (text: airlines), register events at the CFW and store texts required in the tree. In addition, the constructor instantiates an object of class CL_BC412_MAPPING_4_2_TREE. Through the interface of the constructor, you pass a container reference (i_container) and three texts, including the text for the root node (I_ROOT_NODE_TEXT) and texts used in the nodes for table SFLIGHT (I_FLIGHT_NODE_TEXT1, I_FLIGHT_NODE_TEXT2). You can use the parameters I_NODE_DOUBLE_CLICK and I_APPL_EVENT_NDC to determine if your instance should trigger the event NODE_DOUBLE_CLICK and if the event should be triggered as an application event or as a system event. Using (C) SAP AG
BC412
18
the parameter I_LEVEL_NO you define the read depth of your instance (the last node level that can be expanded). CREATE OBJECT object EXPORTING i_container
= variable_1
i_root_node_text
= variable_2
i_flight_node_text1 = variable_3 i_flight_node_text2 = variable 4 i_node_double_click = variable 5 i_appl_event_ndc i_level_no
= variable_6
= variable_7
EXCEPTIONS tree_create_error = value_1 root_create_error = value_2.
The interface parameters have the following meaning: Parameter name
Meaning
i_container
Container reference You use this parameter to pass a container reference. The Tree Control instance is displayed in the corresponding container instance.
i_root_node_text
Text for the root node
i_flight_node_text1
Text 1 used in nodes for table SFLIGHT. Pass the text "Number of available seats" (default value: "seats free").
i_flight_node_text2
Text 2 used in nodes for table SFLIGHT. Pass the text "No seats available" (default value: "no seats free").
i_node_double_click
Flag variable You use this parameter to determine if your instance can trigger the event NODE_DOUBLE_CLICK. To assign a value to this parameter, you can use the class constants C_TRUE and C_FALSE: CL_BC412_FLIGHT_INFO_TREE1=>C_TRUE: Instance should trigger event NODE_DOUBLE_CLICK (register at the CFW) CL_BC412_FLIGHT_INFO_TREE1=>C_FALSE: Instance should not trigger event NODE_DOUBLE_CLICK
i_appl_event_ndc
Flag variable You use this parameter to determine if event NODE_DOUBLE_CLICK should be triggered as an application or as a system event. CL_BC412_FLIGHT_INFO_TREE1=>C_TRUE: Application event CL_BC412_FLIGHT_INFO_TREE1=>C_FALSE: System event
i_level_no
Read depth of the instance in the hierarchy To assign a value to the parameter, use the class constants C_LEVEL_x, x = 1, ...4. C_LEVEL_1: SCARR C_LEVEL_2: SPFLI
(C) SAP AG
BC412
19
C_LEVEL_3: SFLIGHT C_LEVEL_4: SBOOK The exceptions have the following meaning: Parameter name
Meaning
tree_create_error
Error creating the Tree Control instance
root_create_error
Error creating the root node
104.3.3The Method FREE The method FREE is used to release all resources used by the instantiated control at the frontend.
104.3.4The Method GET_SCARR_DETAILS Using the method GET_SCARR_DETAILS, you can query detail data for an airline (values of the table fields of the database table at the time the node is read). Use the parameter I_CARRID to pass the key of the table SCARR. The method returns the relevant table row in parameter E_SCARR. The exception NO_DATA_FOUND is triggered if no entry exists for the key passed.
104.3.5The Method GET_SPFLI_DETAILS Using the method GET_SPFLI_DETAILS, you can query detail data for a flight connection (values of the table fields of the database table at the time the node is read). Use the parameters I_CARRID and I_CONNID to pass the key of the table SPFLI. The method returns the relevant table row in parameter E_SPFLI. The exception NO_DATA_FOUND is triggered if no entry exists for the key passed.
104.3.6The Method GET_SFLIGHT_DETAILS Using the method GET_SFLIGHT_DETAILS, you can query detail data for a flight (values of the table fields of the database table at the time the node is read). Use the parameters I_CARRID, I_CONNID, and I_FLDATE to pass the key of table SFLIGHT. The method returns the relevant table row in parameter E_SSFLIGHT. The exception NO_DATA_FOUND is triggered if no entry exists for the key passed.
104.3.7The Method GET_SBOOK_DETAILS Using the method GET_SBOOK_DETAILS, you can query detail data for a booking (values of the table fields of the database table at the time the node is read). Use the parameters I_CARRID, I_COONID, I_FLDATE, and I_BOOKID to pass the key of table SBOOK. The method returns the relevant table row in parameter E_SBOOK. The exception NO_DATA_FOUND is triggered if no entry exists for the key passed.
(C) SAP AG
BC412
20
104.3.8The Method GET_SCUSTOM_DETAILS Using the method GET_SCUSTOM_DETAILS, you can query detail data for a flight customer (values of the table fields of the database table at the time the SBOOK nodes are read). Use the parameter I_ID to pass the key of table SCUSTOM. The method returns the relevant table row in parameter E_SCUSTOM. The exception NO_DATA_FOUND is triggered if no entry exists for the key passed.
104.3.9The Event NODE_DOUBLE_CLICK The event NODE_DOUBLE_CLICK is triggered if a node is double-clicked (if registered). Through the interface of the event, the application key of the node (parameter E_CARRID, E_CONNID, E_FLDATE, E_BOOKID) and the hierarchy level of the node are transmitted (parameter E_LEVEL)
104.4Data, Methods, and Events Used Internally in the Class Each instance of the class buffers the table row assigned to a node displayed at the frontend in the internal tables IT_SCARR, IT_SPFLI, IT_SFLIGHT, IT_SBOOK, and IT_SCUSTOM. These internal tables are filled with data in the method ON_EXPAND_NO_CHILDREN. The method ON_EXPAND_NO_CHILDREN handles the event EXPAND_NO_CHILDREN of the Tree Control instance. If this method is called, the method determines the application key for the node key which is transmitted at the tree event (method GET_BUSINESS_KEY of the instance of class CL_BC412_MAPPING_4_2_TREE). The application key tells the system for which node hierarchically dependent data needs to be read. Database access and node table creation are implemented by means of the methods FILL_SCARR_NODE, FILL_SPLFLI_NODE, FILL_SFLIGHT_NODE, and FILL_SBOOK_NODE. The method GET_CUSTOMER_NAMES is used by the method FILL_SBOOK_NODE.
104.5Definition of the Class *" type-pools TYPE-POOLS: cntl .
*---------------------------------------------------------------------* *
CLASS CL_BC412_FLIGHT_INFO_TREE1 DEFINITION
*---------------------------------------------------------------------* *
........
*
*---------------------------------------------------------------------* CLASS cl_bc412_flight_info_tree1 DEFINITION PUBLIC FINAL CREATE PUBLIC .
*---------------------------------------------------------------------*" public components of class CL_BC412_FLIGHT_INFO_TREE1 *---------------------------------------------------------------------PUBLIC SECTION.
*" constants CONSTANTS: c_true
(C) SAP AG
TYPE bc412_text1 VALUE 'X' ,
BC412
21
c_false TYPE bc412_text1 VALUE ' ' , c_text1 TYPE bc412_text36 VALUE 'seats free' , c_text2 TYPE bc412_text36 VALUE 'no seats free' , c_level_0 TYPE bc412_level VALUE 0 , c_level_1 TYPE bc412_level VALUE 1 , c_level_2 TYPE bc412_level VALUE 2 , c_level_3 TYPE bc412_level VALUE 3 , c_level_4 TYPE bc412_level VALUE 4 .
*" events EVENTS: node_double_click EXPORTING value(e_carrid) TYPE s_carr_id OPTIONAL value(e_connid) TYPE s_conn_id OPTIONAL value(e_fldate) TYPE s_date OPTIONAL value(e_bookid) TYPE s_book_id OPTIONAL value(e_level) TYPE bc412_level OPTIONAL .
*" methods METHODS: constructor IMPORTING i_container
TYPE REF TO cl_gui_container
value(i_root_node_text)
TYPE bc412_sim_tree_node_struc-text
value(i_flight_node_text1) TYPE bc412_text36 value(i_flight_node_text2) TYPE bc412_text36 value(i_node_double_click) TYPE bc412_text1 value(i_appl_event_ndc) value(i_level_no)
TYPE bc412_text1
TYPE bc412_level
EXCEPTIONS tree_create_error root_create_error , *---------------------------------------------------------------------free , *---------------------------------------------------------------------get_scarr_details IMPORTING value(i_carrid) TYPE s_carr_id EXPORTING value(e_scarr) TYPE scarr EXCEPTIONS no_data_found , *---------------------------------------------------------------------get_spfli_details
(C) SAP AG
BC412
22
IMPORTING value(i_carrid) TYPE s_carr_id value(i_connid) TYPE s_conn_id EXPORTING value(e_spfli) TYPE spfli EXCEPTIONS no_data_found , *---------------------------------------------------------------------get_sflight_details IMPORTING value(i_carrid) TYPE s_carr_id value(i_connid) TYPE s_conn_id value(i_fldate) TYPE s_date EXPORTING value(e_sflight) TYPE sflight EXCEPTIONS no_data_found , *---------------------------------------------------------------------get_sbook_details IMPORTING value(i_carrid) TYPE s_carr_id value(i_connid) TYPE s_conn_id value(i_fldate) TYPE s_date value(i_bookid) TYPE s_book_id EXPORTING value(e_sbook) TYPE sbook EXCEPTIONS no_data_found , *---------------------------------------------------------------------get_scustom_details IMPORTING value(i_id)
TYPE s_customer
EXPORTING value(e_scustom) TYPE scustom EXCEPTIONS no_data_found .
*---------------------------------------------------------------------*" protected components of class CL_BC412_FLIGHT_INFO_TREE1 *---------------------------------------------------------------------PROTECTED SECTION.
*" instance attributes
(C) SAP AG
BC412
23
DATA: it_scarr it_spfli
TYPE bc412_scarr_itt , TYPE bc412_spfli_itt ,
it_sflight
TYPE bc412_sflight_itt ,
it_sbook it_scustom
TYPE bc412_sbook_itt , TYPE bc412_scustom_itt ,
o_simple_tree
TYPE REF TO cl_gui_simple_tree ,
o_mapping
TYPE REF TO cl_bc412_mapping_4_2_tree ,
sflight_node_text1 TYPE bc412_text36 , sflight_node_text2 TYPE bc412_text36 , level_no
TYPE bc412_level .
*" methods METHODS: create_root_node IMPORTING value(i_root_node_text) TYPE bc412_sim_tree_node_struc-text EXCEPTIONS root_create_error , *---------------------------------------------------------------------on_expand_no_children FOR EVENT expand_no_children OF cl_gui_simple_tree IMPORTING node_key , *---------------------------------------------------------------------on_node_double_click FOR EVENT node_double_click OF cl_gui_simple_tree IMPORTING node_key , *---------------------------------------------------------------------fill_scarr_node IMPORTING value(i_node_key) TYPE tv_nodekey EXCEPTIONS mapping_insert_error node_add_error , *---------------------------------------------------------------------fill_spfli_node IMPORTING value(i_node_key) TYPE tv_nodekey value(i_key1)
TYPE s_carr_id
EXCEPTIONS mapping_insert_error node_add_error , *----------------------------------------------------------------------
(C) SAP AG
BC412
24
fill_sflight_node IMPORTING value(i_node_key) TYPE tv_nodekey value(i_key1)
TYPE s_carr_id
value(i_key2)
TYPE s_conn_id
EXCEPTIONS mapping_insert_error node_add_error , *---------------------------------------------------------------------fill_sbook_node IMPORTING value(i_node_key) TYPE tv_nodekey value(i_key1) TYPE s_carr_id value(i_key2) TYPE s_conn_id value(i_key3) TYPE s_date EXCEPTIONS mapping_insert_error node_add_error , *---------------------------------------------------------------------get_customer_names CHANGING i_booking_info TYPE bc412_sbook_node_itt EXCEPTIONS data_error .
104.6Implementation of the Class METHOD constructor. * local data: internal table with registered eventids DATA events
TYPE cntl_simple_events.
DATA wa_events TYPE cntl_simple_event.
* 1. set current number of levels level_no = i_level_no.
* 2. create instances for tree control and mapping class * 2.a. create tree control CREATE OBJECT o_simple_tree EXPORTING *
lifetime parent
*
= cl_gui_simple_tree=>lifetime_imode = i_container
shellstyle
= shellstyle
node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single *
hide_selection
(C) SAP AG
=''
BC412
25
EXCEPTIONS lifetime_error
=1
cntl_system_error
=2
create_error
=3
illegal_node_selection_mode = 4 failed
= 5.
IF sy-subrc NE 0. RAISE tree_create_error. ENDIF.
* 2.b. create mapping object CREATE OBJECT o_mapping.
* 3. create ROOT node CALL METHOD me->create_root_node EXPORTING i_root_node_text = i_root_node_text EXCEPTIONS root_create_error = 1. IF sy-subrc NE 0. RAISE root_create_error. ENDIF.
* 4. register events * fill workarea for event registration
* event: node_double_click IF i_node_double_click = c_true. wa_events-eventid = cl_gui_simple_tree=>eventid_node_double_click. wa_events-appl_event = i_appl_event_ndc.
APPEND wa_events TO events. ENDIF.
* event: expand_no_children wa_events-eventid = cl_gui_simple_tree=>eventid_expand_no_children. wa_events-appl_event = c_false.
APPEND wa_events TO events.
* register events CALL METHOD o_simple_tree->set_registered_events EXPORTING events = events.
IF i_node_double_click = c_true.
(C) SAP AG
BC412
26
SET HANDLER me->on_node_double_click FOR o_simple_tree. ENDIF. SET HANDLER me->on_expand_no_children FOR o_simple_tree.
* 5. store node texts for sflight nodes in instance data sflight_node_text1 = i_flight_node_text1. sflight_node_text2 = i_flight_node_text2.
ENDMETHOD.
*----------------------------------------------------------------------
METHOD free. CALL METHOD o_simple_tree->free. FREE: o_simple_tree, o_mapping. ENDMETHOD.
*----------------------------------------------------------------------
METHOD get_scarr_details. READ TABLE it_scarr INTO e_scarr WITH TABLE KEY carrid = i_carrid. IF sy-subrc NE 0. RAISE no_data_found. ENDIF. ENDMETHOD.
*----------------------------------------------------------------------
METHOD get_spfli_details. READ TABLE it_spfli INTO e_spfli WITH TABLE KEY carrid = i_carrid connid = i_connid. IF sy-subrc NE 0. RAISE no_data_found. ENDIF. ENDMETHOD.
*----------------------------------------------------------------------
METHOD get_sflight_details. READ TABLE it_sflight INTO e_sflight WITH TABLE KEY carrid = i_carrid connid = i_connid
(C) SAP AG
BC412
27
fldate = i_fldate. IF sy-subrc NE 0. RAISE no_data_found. ENDIF. ENDMETHOD.
*----------------------------------------------------------------------
METHOD get_sbook_details. READ TABLE it_sbook INTO e_sbook WITH TABLE KEY carrid = i_carrid connid = i_connid fldate = i_fldate bookid = i_bookid. IF sy-subrc NE 0. RAISE no_data_found. ENDIF. ENDMETHOD.
*----------------------------------------------------------------------
METHOD get_scustom_details. READ TABLE it_scustom INTO e_scustom WITH TABLE KEY id = i_id. IF sy-subrc NE 0. RAISE no_data_found. ENDIF. ENDMETHOD.
*----------------------------------------------------------------------
METHOD create_root_node. * local node table DATA: node_table TYPE STANDARD TABLE OF bc412_sim_tree_node_struc, wa_node
LIKE LINE OF node_table.
* create root node entry CLEAR wa_node. wa_node-node_key = 'ROOT'. * wa_node-relatkey = .
" special case, root has no
* wa_node-relatship = .
" related entry
wa_node-hidden
= ' '.
wa_node-disabled = 'X'.
(C) SAP AG
" ' ' = visible, 'X' = invisible " node is not selectable
BC412
28
wa_node-isfolder = 'X'. wa_node-n_image
= ' '.
" use default icon (closed folder)
wa_node-exp_image = ' '. wa_node-style
" use default icon (expand folder)
= cl_gui_simple_tree=>style_default.
* wa_node-last_hitem = . * wa_node-no_branch = .
IF level_no = c_level_0. wa_node-expander = ' '. ELSE. wa_node-expander = 'X'. ENDIF.
* wa_node-dragdropid = . wa_node-text
= i_root_node_text.
INSERT wa_node INTO TABLE node_table.
CALL METHOD o_simple_tree->add_nodes EXPORTING table_structure_name = 'BC412_SIM_TREE_NODE_STRUC' node_table
= node_table
EXCEPTIONS error_in_node_table failed
=1 =2
dp_error
=3
table_structure_name_not_found = 4.
IF sy-subrc NE 0. RAISE root_create_error. ENDIF.
ENDMETHOD.
*----------------------------------------------------------------------
METHOD on_expand_no_children. * local data DATA: BEGIN OF mapping, carrid TYPE s_carr_id, connid TYPE s_conn_id, fldate TYPE s_date, bookid TYPE s_book_id, END OF mapping.
* test for ROOT (special case)
(C) SAP AG
BC412
29
IF node_key = 'ROOT'.
" expand root
node -> i_scarr
CALL METHOD me->fill_scarr_node EXPORTING i_node_key = 'ROOT' EXCEPTIONS mapping_insert_error = 1 node_add_error = 2.
IF sy-subrc NE 0. *
open to implement ENDIF.
ELSE.
" any other node to expand
* get business key of selected node CALL METHOD o_mapping->get_business_key EXPORTING i_tkey = node_key IMPORTING e_bkey1 = mapping-carrid e_bkey2 = mapping-connid e_bkey3 = mapping-fldate e_bkey4 = mapping-bookid EXCEPTIONS invalid_teckey = 1. IF sy-subrc NE 0. *
open to implement ENDIF.
IF mapping-connid IS INITIAL.
" expand carrier node
" -> i_spfli CALL METHOD me->fill_spfli_node EXPORTING i_node_key = node_key i_key1
= mapping-carrid
EXCEPTIONS mapping_insert_error = 1 node_add_error
= 2.
IF sy-subrc NE 0. *
open to implement ENDIF.
ELSEIF mapping-fldate IS INITIAL. " expand connection node " -> i_sflight
(C) SAP AG
BC412
30
CALL METHOD me->fill_sflight_node EXPORTING i_node_key = node_key i_key1
= mapping-carrid
i_key2
= mapping-connid
EXCEPTIONS mapping_insert_error = 1 node_add_error
= 2.
IF sy-subrc NE 0. *
open to implement ENDIF.
ELSEIF mapping-bookid IS INITIAL. " expand flight node " -> i_sbook CALL METHOD me->fill_sbook_node EXPORTING i_node_key = node_key i_key1
= mapping-carrid
i_key2
= mapping-connid
i_key3
= mapping-fldate
EXCEPTIONS mapping_insert_error = 1 node_add_error
= 2.
IF sy-subrc NE 0. *
open to implement ENDIF. ENDIF. ENDIF.
ENDMETHOD.
*----------------------------------------------------------------------
METHOD on_node_double_click. * local data DATA: l_carrid TYPE s_carr_id, l_connid TYPE s_conn_id, l_fldate TYPE s_date, l_bookid TYPE s_book_id, l_level
TYPE bc412_level.
* transform technical key of note (tree control) into business keys * of the flight model
(C) SAP AG
BC412
31
CALL METHOD o_mapping->get_business_key EXPORTING i_tkey = node_key IMPORTING e_bkey1 = l_carrid e_bkey2 = l_connid e_bkey3 = l_fldate e_bkey4 = l_bookid EXCEPTIONS invalid_teckey = 1. IF sy-subrc NE 0. *
should not happen ENDIF.
* determine node level IF l_connid IS INITIAL.
" carrier node selected
l_level = c_level_1. ELSEIF l_fldate IS INITIAL.
" connection node selected
l_level = c_level_2. ELSEIF l_bookid IS INITIAL.
" flight node selected
l_level = c_level_3. ELSE.
" booking node selected
l_level = c_level_4. ENDIF.
* raise event node_double_click with business key RAISE EVENT node_double_click EXPORTING e_carrid = l_carrid e_connid = l_connid e_fldate = l_fldate e_bookid = l_bookid e_level
= l_level.
ENDMETHOD.
*----------------------------------------------------------------------
METHOD fill_scarr_node. * local node table DATA: node_table TYPE STANDARD TABLE OF bc412_sim_tree_node_struc, wa_node
LIKE LINE OF node_table,
* handling of internal data table wa_scarr LIKE LINE OF it_scarr, * local mapping structure used to construct node_key
(C) SAP AG
BC412
32
BEGIN OF mapping, carrid TYPE s_carr_id, connid TYPE s_conn_id, fldate TYPE s_date, bookid TYPE s_book_id, END OF mapping.
* read data from database table scarr: * note: this method is executed only one time during program run *
it is called the first time the user tries to expand the root
*
node. In all other cases the corresponding data has already
*
send to the tree control. Thus the event expand_no_children
*
is only fired the first time. SELECT * FROM scarr INTO CORRESPONDING FIELDS OF TABLE it_scarr.
* create node entries CLEAR: wa_node. wa_node-hidden
= ' '.
" ' ' = visible, 'X' = invisible
wa_node-disabled = ' '.
" node is selectable
wa_node-isfolder = 'X'. wa_node-n_image
= ' '.
" use default icon (closed folder)
wa_node-exp_image = ' '. wa_node-style
" use default icon (expand folder)
= cl_gui_simple_tree=>style_default.
* wa_node-last_hitem = . * wa_node-no_branch = . IF level_no = c_level_1. wa_node-expander = ' '. ELSE. wa_node-expander = 'X'. ENDIF. * wa_node-dragdropid = .
LOOP AT it_scarr INTO wa_scarr.
CLEAR: mapping. MOVE-CORRESPONDING wa_scarr TO mapping. CALL METHOD o_mapping->insert_business_key EXPORTING i_bkey1 = mapping-carrid i_bkey2 = mapping-connid i_bkey3 = mapping-fldate i_bkey4 = mapping-bookid IMPORTING e_tkey = wa_node-node_key EXCEPTIONS
(C) SAP AG
BC412
33
internal_error = 1 teckey_overflow = 2 invalid_buskey = 3. IF sy-subrc NE 0. RAISE mapping_insert_error. ENDIF. wa_node-text
= wa_scarr-carrname.
* first entry of sub nodes wa_node-relatkey = i_node_key. wa_node-relatship = cl_gui_simple_tree=>relat_last_child. INSERT wa_node INTO TABLE node_table. ENDLOOP.
CALL METHOD o_simple_tree->add_nodes EXPORTING table_structure_name = 'BC412_SIM_TREE_NODE_STRUC' node_table
= node_table
EXCEPTIONS error_in_node_table failed
=1 =2
dp_error
=3
table_structure_name_not_found = 4.
IF sy-subrc NE 0. RAISE node_add_error. ENDIF. ENDMETHOD.
*----------------------------------------------------------------------
METHOD fill_spfli_node. * local node table DATA: node_table TYPE STANDARD TABLE OF bc412_sim_tree_node_struc, wa_node
LIKE LINE OF node_table,
* local mapping structure used to construct node_key BEGIN OF mapping, carrid TYPE s_carr_id, connid TYPE s_conn_id, fldate TYPE s_date, bookid TYPE s_book_id, END OF mapping, * local spfli table li_spfli
(C) SAP AG
TYPE SORTED TABLE OF spfli
BC412
34
WITH UNIQUE KEY carrid connid, * local workarea wa_spfli LIKE LINE OF it_spfli.
* read data from database table * remember: the event expand_no_children is only fired if the tree *
control on the frontend has no data to show as children SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE li_spfli WHERE carrid = i_key1.
* create node entries CLEAR: wa_node. wa_node-hidden
= ' '.
" ' ' = visible, 'X' = invisible
wa_node-disabled = ' '.
" node is selectable
wa_node-isfolder = 'X'. wa_node-n_image
= ' '.
" use default icon (closed folder)
wa_node-exp_image = ' '. wa_node-style
" use default icon (expand folder)
= cl_gui_simple_tree=>style_default.
* wa_node-last_hitem = . * wa_node-no_branch = .
IF level_no = c_level_2. wa_node-expander = ' '. ELSE. wa_node-expander = 'X'. ENDIF.
* wa_node-dragdropid = .
LOOP AT li_spfli INTO wa_spfli.
CLEAR: mapping. MOVE-CORRESPONDING wa_spfli TO mapping. CALL METHOD o_mapping->insert_business_key EXPORTING i_bkey1 = mapping-carrid i_bkey2 = mapping-connid i_bkey3 = mapping-fldate i_bkey4 = mapping-bookid IMPORTING e_tkey = wa_node-node_key EXCEPTIONS internal_error = 1 teckey_overflow = 2 invalid_buskey = 3.
(C) SAP AG
BC412
35
IF sy-subrc NE 0. RAISE mapping_insert_error. ENDIF.
CONCATENATE wa_spfli-connid ': ' wa_spfli-cityfrom '--> ' wa_spfli-cityto INTO wa_node-text SEPARATED BY ' '.
* first entry of sub node -> first child wa_node-relatkey = i_node_key. wa_node-relatship = cl_gui_simple_tree=>relat_last_child. INSERT wa_node INTO TABLE node_table. " fill node table INSERT wa_spfli INTO TABLE it_spfli.
" fill global data table
ENDLOOP.
CALL METHOD o_simple_tree->add_nodes EXPORTING table_structure_name = 'BC412_SIM_TREE_NODE_STRUC' node_table
= node_table
EXCEPTIONS error_in_node_table failed
=1 =2
dp_error
=3
table_structure_name_not_found = 4.
IF sy-subrc NE 0. RAISE node_add_error. ENDIF.
ENDMETHOD.
*----------------------------------------------------------------------
METHOD fill_sflight_node. * local node table DATA: node_table TYPE STANDARD TABLE OF bc412_sim_tree_node_struc, wa_node
LIKE LINE OF node_table,
* local mapping structure used to construct node_key BEGIN OF mapping, carrid TYPE s_carr_id, connid TYPE s_conn_id, fldate TYPE s_date, bookid TYPE s_book_id, END OF mapping,
(C) SAP AG
BC412
36
* local sflight table li_sflight TYPE SORTED TABLE OF sflight WITH UNIQUE KEY carrid connid fldate, * local workarea wa_sflight LIKE LINE OF it_sflight, * auxiliary fields freeseats(5), text1(36), text2(36).
* read database entry corresponding to node to expand SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE li_sflight WHERE carrid = i_key1 AND connid = i_key2.
* create node entry CLEAR: wa_node. wa_node-hidden
= ' '.
" ' ' = visible, 'X' = invisible
wa_node-disabled = ' '.
" node is selectable
wa_node-isfolder = 'X'. wa_node-n_image
= ' '.
" use default icon (closed folder)
wa_node-exp_image = ' '. wa_node-style
" use default icon (expand folder)
= cl_gui_simple_tree=>style_default.
* wa_node-last_hitem = . * wa_node-no_branch = .
IF level_no = c_level_3. wa_node-expander = ' '. ELSE. wa_node-expander = 'X'. ENDIF.
* wa_node-dragdropid = .
LOOP AT li_sflight INTO wa_sflight.
CLEAR: mapping, freeseats. MOVE-CORRESPONDING wa_sflight TO mapping. CALL METHOD o_mapping->insert_business_key EXPORTING i_bkey1 = mapping-carrid i_bkey2 = mapping-connid i_bkey3 = mapping-fldate i_bkey4 = mapping-bookid IMPORTING
(C) SAP AG
BC412
37
e_tkey = wa_node-node_key EXCEPTIONS internal_error = 1 teckey_overflow = 2 invalid_buskey = 3. IF sy-subrc NE 0. RAISE mapping_insert_error. ENDIF.
freeseats = wa_sflight-seatsmax - wa_sflight-seatsocc. IF freeseats > 0.
" still seats to book
WRITE wa_sflight-fldate TO text1. text2 = sflight_node_text1. CONCATENATE text1 ': ' freeseats text2 INTO wa_node-text SEPARATED BY ' '. ELSE.
" no free seats
WRITE wa_sflight-fldate TO text1. text2 = sflight_node_text2. CONCATENATE text1 ': ' text2 INTO wa_node-text SEPARATED BY ' '. ENDIF.
wa_node-relatkey = i_node_key. wa_node-relatship = cl_gui_simple_tree=>relat_last_child. INSERT wa_node
INTO TABLE node_table. " fill node table
INSERT wa_sflight INTO TABLE it_sflight. " fill global data table ENDLOOP.
CALL METHOD o_simple_tree->add_nodes EXPORTING table_structure_name = 'BC412_SIM_TREE_NODE_STRUC' node_table
= node_table
EXCEPTIONS error_in_node_table failed dp_error
=1 =2 =3
table_structure_name_not_found = 4.
IF sy-subrc NE 0. RAISE node_add_error. ENDIF.
ENDMETHOD.
*----------------------------------------------------------------------
(C) SAP AG
BC412
38
METHOD fill_sbook_node. * local node table DATA: node_table TYPE STANDARD TABLE OF bc412_sim_tree_node_struc, wa_node
LIKE LINE OF node_table,
wa_prev_node LIKE wa_node, * local mapping structure used to construct node_key BEGIN OF mapping, carrid TYPE s_carr_id, connid TYPE s_conn_id, fldate TYPE s_date, bookid TYPE s_book_id, END OF mapping, * local workarea wa_sbook LIKE LINE OF it_sbook, * local sbook table li_sbook
TYPE bc412_sbook_node_itt,
wa_l_sbook LIKE LINE OF li_sbook,
* auxiliary fields freeseats(5), text1(10), text2(10).
* read database table corresponding to node to expand SELECT * FROM sbook INTO CORRESPONDING FIELDS OF TABLE li_sbook WHERE carrid = i_key1 AND connid = i_key2 AND fldate = i_key3.
* get customer names corresponding to names CALL METHOD get_customer_names CHANGING i_booking_info = li_sbook EXCEPTIONS data_error = 1. IF sy-subrc NE 0. *
should not occur: inconsistent data in database tables ENDIF.
* create node entry CLEAR: wa_node. wa_node-hidden
= ' '.
wa_node-disabled = ' '.
(C) SAP AG
" ' ' = visible, 'X' = invisible " node is selectable
BC412
39
wa_node-isfolder = ' '. wa_node-n_image
= ' '.
" use default icon (closed folder)
wa_node-exp_image = ' '. wa_node-style
" use default icon (expand folder)
= cl_gui_simple_tree=>style_default.
* wa_node-last_hitem = . * wa_node-no_branch = .
IF level_no = c_level_4. wa_node-expander = ' '. ELSE. wa_node-expander = ' '.
" always not expandable
ENDIF.
wa_node-expander = ' '. * wa_node-dragdropid = .
LOOP AT li_sbook INTO wa_l_sbook WHERE carrid = i_key1 AND connid = i_key2 AND fldate = i_key3.
CLEAR: mapping, freeseats. MOVE-CORRESPONDING wa_l_sbook TO mapping. CALL METHOD o_mapping->insert_business_key EXPORTING i_bkey1 = mapping-carrid i_bkey2 = mapping-connid i_bkey3 = mapping-fldate i_bkey4 = mapping-bookid IMPORTING e_tkey = wa_node-node_key EXCEPTIONS internal_error = 1 teckey_overflow = 2 invalid_buskey = 3. IF sy-subrc NE 0. RAISE mapping_insert_error. ENDIF.
wa_node-text = wa_l_sbook-name.
*
construct hierarchy wa_node-relatkey = i_node_key. wa_node-relatship = cl_gui_simple_tree=>relat_last_child.
(C) SAP AG
BC412
40
INSERT wa_node INTO TABLE node_table.
" fill node table
MOVE-CORRESPONDING wa_l_sbook TO wa_sbook. INSERT wa_sbook INTO TABLE it_sbook.
" fill global data table
wa_prev_node = wa_node. ENDLOOP.
CALL METHOD o_simple_tree->add_nodes EXPORTING table_structure_name = 'BC412_SIM_TREE_NODE_STRUC' node_table
= node_table
EXCEPTIONS error_in_node_table failed dp_error
=1 =2 =3
table_structure_name_not_found = 4.
IF sy-subrc NE 0. RAISE node_add_error. ENDIF.
ENDMETHOD.
*----------------------------------------------------------------------
METHOD get_customer_names . DATA: wa_booking LIKE LINE OF i_booking_info, wa_scustom LIKE LINE OF it_scustom, it_cust_no LIKE TABLE OF wa_scustom-id, li_scustom TYPE TABLE OF scustom.
LOOP AT i_booking_info INTO wa_booking. READ TABLE it_scustom INTO wa_scustom WITH TABLE KEY id = wa_booking-customid. IF sy-subrc NE 0.
" customer not cashed so far
INSERT wa_booking-customid INTO TABLE it_cust_no. ELSE. *
" customer already cashed
copy name and modify booking_node_table wa_booking-name = wa_scustom-name. MODIFY TABLE i_booking_info FROM wa_booking. ENDIF. ENDLOOP.
* check: database access needed? READ TABLE it_cust_no INDEX 1 TRANSPORTING NO FIELDS.
(C) SAP AG
BC412
41
IF sy-subrc EQ 0. *
" new customers to read
read new customers SELECT * FROM scustom INTO CORRESPONDING FIELDS OF TABLE li_scustom FOR ALL ENTRIES IN it_cust_no WHERE id = it_cust_no-table_line. IF sy-subrc NE 0. RAISE data_error. ENDIF.
LOOP AT li_scustom INTO wa_scustom. *
store in global cash table INSERT wa_scustom INTO TABLE it_scustom.
*
add new names to booking_node_table LOOP AT i_booking_info INTO wa_booking WHERE customid = wa_scustom-id.
wa_booking-name = wa_scustom-name. MODIFY TABLE i_booking_info FROM wa_booking. ENDLOOP.
ENDLOOP. ELSE. *
nothing to do, because name have already been copied ENDIF.
ENDMETHOD.
105Global Data Types Used in the ABAP Dictionary 105.2Table Types 105.2.2BC412_FUNCTION_ITT The table type BC412_FUNCTION_ITT has the type STANDARD and uses the row type BC412_FUNCTION_STRUC. The row type consists of the following two fields: Field name
Data element
Type
FCODE
UI_FUNC
CHAR 70
TEXT
GUI_TEXT
CHAR 40
105.2.3BC412_MAP_HASH1 The table type BC412_MAP_HASH1 has the type HASH and uses the row type BC412_MAP_LINETYPE. The row type consists of the following fields: (C) SAP AG
BC412
42
Field name
Data element
BKEY1
S_CARR_ID
BKEY2
S_CONN_ID
BKEY3
S_DATE
BKEY4
S_BOOK_ID
TKEY
TV_NODEKEY
The fields BKEY1, BKEY2, BKEY3, and BKEY4 make up the table key.
105.2.4BC412_MAP_HASH1 The table type BC412_MAP_HASH1 has the type HASH and uses the row type BC412_MAP_LINETYPE. The field TKEY is the table key.
105.2.5BC412_SBOOK_ITT The table type BC412_SBOOK_ITT has the type SORTED and uses the row type SBOOK. The fields CARRID, CONNID, FLDATE, and BOOKID are key fields.
105.2.6BC412_SBOOK_NODE_ITT The table type BC412_SBOOK_NODE_ITT has the type STANDARD and uses the row type BC412_SBOOK_NODE_STRUC. The row type includes the structure SBOOK and additionally uses the field NAME (data element S_CUSTNAME).
105.2.7BC412_SCARR_ITT The table type BC412_SCARR_ITT has the type SORTED and uses the row type SCARR. The field CARRID is a key field.
105.2.8BC412_SUSTOM_ITT The table type BC412_SCUSTOM_ITT has the type SORTED and uses the row type SCUSTOM. The field ID is a key field.
105.2.9BC412_SFLIGHT_ITT The table type BC412_SFLIGHT_ITT has the type SORTED and uses the row type SFLIGHT. The fields CARRID, CONNID, and FLDATE are key fields.
105.2.10BC412_SPFLI_ITT The table type BC412_SPFLI_ITT has the type SORTED and uses the row type SPFLI. The fields CARRID and CONNID are key fields.
(C) SAP AG
BC412
43
105.3Structure Types 105.3.2BC412_SIM_TREE_NODE_STRUC The structure type BC412_SIM_TREE_NODE_STRUC includes the structure TREEV_NODE and additionally has the field TEXT (CHAR 120).
105.4Data Elements The following data elements are used: Data element
Type
BC412_LEVEL
INT2
BC412_TEXT1
CHAR 1
BC412_TEXT36
CHAR 36
BC412_TEXT_DE
CHAR 120
(C) SAP AG
BC412
44
105.5BC412 - Table of Contents Preface BC412 ABAP Dialog Programming Using EnjoySAP Controls......................................................... Copyright.............................................................................................................................................. ABAP Workbench................................................................................................................................ Course Prerequisites............................................................................................................................. Target Group.........................................................................................................................................
1 2 3 4 5
Course Overview Course Overview.................................................................................................................................. Course Goal.......................................................................................................................................... Course Objectives................................................................................................................................ Course Content..................................................................................................................................... Overview Diagram - Course Overview................................................................................................ Style Conventions Used in this Handbook...........................................................................................
1 2 3 4 5 6
Introduction to the Control Framework Introduction to the Control Framework............................................................................................... Introduction to the Control Framework: Unit Objectives.................................................................... Course Overview Diagram................................................................................................................... Introduction to the Control Framework: Overview....................................................................... Control Framework (CFW) - General Architecture.......................................................................... CFW Architecture in Detail............................................................................................................... SAP's GUI Strategy for R/3............................................................................................................... Custom Controls and ABAP Objects................................................................................................. Custom Controls: Automation Queue............................................................................................... Custom Control Events..................................................................................................................... Control Framework: Class Hierarchy................................................................................................ Introduction to the Control Framework: Controls and Screens................................................... Relationship Between Controls and Screens..................................................................................... Screen Element Custom Control: Use............................................................................................... Creating a Custom Control Area....................................................................................................... Creating a Container Control: Process Flow.................................................................................... Creating a Container Control Instance.............................................................................................. Syntax: Declaring Reference Variables............................................................................................. Information in the Class Builder....................................................................................................... Syntax: Creating an Instance (with a Constructor) .......................................................................... Using a Flag Variable........................................................................................................................ Creating an EnjoySAP Control Instance: Process Flow .................................................................. Creating an Instance of the SAP Picture Control.............................................................................. Creating an Instance of the SAP HTML Viewer............................................................................... Result: Screen, Container, and EnjoySAP Control.......................................................................... Overview: Control Framework: Changing the Attributes of a Control Overview: Attributes of the Picture Controls and the HTML Viewer............................................ URL: Pointer to Data...................................................................................................................... URLs for External Data Sources.................................................................................................... SAP Controls: Accessing External Data by URL .......................................................................... SAP Controls: Accessing Internal Data by URL ........................................................................... SAP Picture Control: Features........................................................................................................ SAP Picture Control: DISPLAY_MODE ...................................................................................... SAP HTML Viewer: Features......................................................................................................... Overview: Changing the Attributes (Syntax).................................................................................. Displaying Data: Process Flow..................................................................................................... Example: Displaying a Picture in the Picture Control ................................................................... Syntax: Calling Instance Methods (1)............................................................................................ Syntax: Calling Instance Methods (2) Functional Methods........................................................... Syntax: Reading Instance Attributes.............................................................................................. Overview: The Automation Queue.................................................................................................. Method Calls and the Automation Queue......................................................................................... Sending the Automation Queue to the GUI: End of PBO................................................................ (C) SAP AG
BC412
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 45
Dependent Method Calls................................................................................................................... Solution: Explicit Flush.................................................................................................................... Optimizing Performance in the Automation Queue.......................................................................... Method Calls: Possible Causes of Errors(1)...................................................................................... Method Calls: Solving the Problem (1)............................................................................................. Method Calls: Possible Causes of Errors(2)...................................................................................... Method Calls: Solving the Problem (2)............................................................................................. Method Calls: Possible Causes of Errors(3)...................................................................................... Recommendations for Calling Methods at PAI................................................................................. Method Calls and EXCEPTIONs...................................................................................................... Overview: Tracing Errors in Controls Programming....................................................................... Automation Queue: Using the ABAP Debugger............................................................................... Automation Queue: Using the Automation Trace............................................................................. Destroying Control Instances............................................................................................................ Overview: Control Events - Overview............................................................................................. Recap: Control Events...................................................................................................................... Control Events: General Overview................................................................................................... Overview: Control Events - ABAP Objects Events......................................................................... Control Events: Overview.............................................................................................................. Overview: ABAP Objects Events.................................................................................................. Events of ABAP Objects Instances................................................................................................. Example: Events of the SAP Picture Control ................................................................................ Example: Events of the SAP HTML Viewer.................................................................................. ABAP Objects: Creating Handler Methods................................................................................... Creating Event Handler Methods: Static Methods......................................................................... Syntax: Local Classes..................................................................................................................... Syntax: Methods of Local Classes................................................................................................. Syntax: Handler Method for an Event............................................................................................ ABAP Objects: Registering Handler Methods.............................................................................. Linking an Event to a Handler Method.......................................................................................... Syntax: Linking an Event to a Static Handler Method................................................................... Syntax: Linking an Event to an Instance Handler Method............................................................. Overview: Control Events - Control Events and the Control Framework.................................... Control Events: Overview.............................................................................................................. Control Events: Automation Control as Filter................................................................................ Control Events: Configuring the Control Framework.................................................................... Example: SAP Picture Control Events: Event IDs......................................................................... Example: SAP HTML Viewer Events: Event IDs.......................................................................... Registering Control Events with the CFW..................................................................................... Overview: Control Events - Event types......................................................................................... Event Type: System Event............................................................................................................. Event Type: Application Event...................................................................................................... Registering Application Events...................................................................................................... Screen and Control: Call Sequence for Application Events........................................................... Application Events and Screen Input Checks (1)........................................................................... Application Events and Screen Input Checks (2)........................................................................... System Event and set_new_ok_code.............................................................................................. Introduction to the Control Framework: Controls and program modularization...................... Modularization Used So Far.............................................................................................................. Other Modularization Possibilities.................................................................................................... Introduction to the Control Framework: Unit Summary......................................................................
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
SAP Container SAP Container ..................................................................................................................................... SAP Container: Unit Objectives........................................................................................................... Overview Diagram - BC412................................................................................................................ SAP Container Overview: The Container Concept........................................................................ Uses for Containers........................................................................................................................... SAP Container Classes...................................................................................................................... Graphical Visualization of Containers............................................................................................... Dialog Box Level and Top-Level Container..................................................................................... Technical Methods for Attaching SAP Containers............................................................................ Visibility and Lifetime of SAP Containers........................................................................................ SAP Container Overview: SAP Custom Container Control.............................................................. (C) SAP AG
BC412
1 2 4 5 6 7 8 9 10 11 46
SAP Custom Container: Features...................................................................................................... Creating an Instance of the SAP Custom Container Control............................................................ Relinking an SAP Custom Container Control................................................................................... SAP Container Overview: SAP Dialog Box Container Control..................................................... SAP Dialog Box Container: Features................................................................................................ Creating an Instance of the SAP Dialog Box Container Control...................................................... SAP Container Overview: SAP Docking Container Control......................................................... SAP Docking Container: Features..................................................................................................... SAP Docking Container: Linking to the Screen................................................................................ Creating an Instance of the SAP Docking Container Control........................................................... Reading and Setting Attributes.......................................................................................................... Relinking an SAP Docking Container............................................................................................... SAP Container Overview: SAP Splitter Container Control........................................................... SAP Splitter Container: Features....................................................................................................... SAP Splitter Container: Use.............................................................................................................. Creating an Instance of the SAP Splitter Container Control............................................................. SAP Splitter Container: Finding a Cell Reference............................................................................ Reading and Setting Attributes.......................................................................................................... SAP Container Overview: SAP Easy Splitter Container Control.................................................. SAP Easy Splitter Container: Features.............................................................................................. Creating an Instance of the SAP Easy Splitter Container Control.................................................... SAP Easy Splitter Container: Reference Variables for Cells............................................................ SAP Container: Unit Summary............................................................................................................
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
SAP Tree Control SAP Tree Control................................................................................................................................. SAP Tree Control: Unit Objectives...................................................................................................... Overview Diagram - BC412................................................................................................................ SAP Tree Control Overview: Overview: Display Attributes.......................................................... SAP Tree Control............................................................................................................................... SAP Tree Control: Principles of Construction.................................................................................. Tree Control Implementation............................................................................................................ Simple Tree: Display Attributes........................................................................................................ Simple Tree: Node Structure ............................................................................................................ Column Tree: Display Attributes...................................................................................................... Column Tree: Node Structure........................................................................................................... List Tree: Display Attributes............................................................................................................. List Tree: Node Structure.................................................................................................................. SAP Tree Control Overview: Constructor, Methods, and Events.................................................. SAP Tree Control: Communication and Data Flow.......................................................................... Modeling View of the Tree Classes................................................................................................... SAP Tree Control Overview: Methods, and Events of the Simple Tree......................................... Simple Tree: Constructor................................................................................................................ Simple Tree: Method Overview..................................................................................................... Simple Tree: Event Overview........................................................................................................ SAP Tree Control Overview: Methods, and events of the Column Tree........................................ Column Tree: Constructor............................................................................................................. Column Tree: Method Overview................................................................................................... Overview: Methods for Changing Column Trees.......................................................................... Column Tree: Event Overview...................................................................................................... SAP Tree Control Overview: Methods, and events of the List Tree............................................... List Tree: Constructor..................................................................................................................... List Tree: Method Overview.......................................................................................................... Overview: Methods for Changing List Trees................................................................................. List Tree: Event Overview.............................................................................................................. SAP Tree Control Overview: Creating a Hierarchy....................................................................... Objective: Displaying Data in a Simple Tree Control...................................................................... Simple Tree: Control Data................................................................................................................. Line Structure of the Node Table...................................................................................................... Filling the Node Table....................................................................................................................... Node Relationships (1)...................................................................................................................... Node Relationships (2)...................................................................................................................... Node Relationships (3)...................................................................................................................... Passing the Node Table to the Front End.......................................................................................... (C) SAP AG
BC412
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 47
Sending Large Volumes of Data on Request From the User............................................................. SAP Tree Control Overview: Item Tables........................................................................................ Objective: Displaying Data in a Column Tree Control.................................................................... Sending Column or List Items........................................................................................................... Line Structure of the Item Table........................................................................................................ Item Names in a Column Tree........................................................................................................... The Node Table in the Column Tree Control.................................................................................... Columns in the Column Tree Control............................................................................................... The Item Table in the Column Tree Control...................................................................................... Column Tree: Sequence..................................................................................................................... Item Names in a List Tree................................................................................................................. List Tree: Sequence........................................................................................................................... Demonstration Programs for Tree Control Programming................................................................. Overview: Data Handling Strategies Overview: Data Handling Strategies for 4.6A/B............................................................................. Tree Events and Node Keys........................................................................................................... Node Keys...................................................................................................................................... Storing Node Information: Strategy A........................................................................................... Storing Node Information: Strategy B........................................................................................... Storing Node Information: Implementation Idea for Strategy B.................................................... Example: Flight Bookings Tree...................................................................................................... Example: Using the Flight Booking Tree (1): Modularization..................................................... Example: Using the Flight Booking Tree (1): Screen Structure.................................................... Example: Using the Flight Booking Tree (1): Control Flow......................................................... Example: Using the Flight Booking Tree (2): ............................................................................... Overview: Data Handling Strategy from Release 4.6C................................................................... Tree Model Classes......................................................................................................................... Modeling View of the Tree Classes................................................................................................ How the Tree Model Controls Data Flow...................................................................................... SAP Tree Control: Unit Summary........................................................................................................
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
ALV Grid Control ALV Grid Control................................................................................................................................. ALV Grid Control: Unit Objectives..................................................................................................... Overview Diagram - BC412................................................................................................................ Overview: ALV Grid Control: Features........................................................................................... ALV Grid Control.............................................................................................................................. Standard Pushbuttons........................................................................................................................ Features Overview: Technical View................................................................................................. ALV Grid Control: Technical View................................................................................................ ALV Grid Control: List Data.......................................................................................................... Creating List Data and Data Handling........................................................................................... ALV Grid Control: The Field Catalog............................................................................................ Functions of the Field Catalog....................................................................................................... Data Descriptions: The Field Catalog............................................................................................ Information in the Field Catalog (Structure).................................................................................. ALV Grid Control: Additional Information.................................................................................... ALV Grid Control: Function of Additional Information................................................................ Function of Additional Information in Detail................................................................................. Layout Information for the Data Area: Overview.......................................................................... Layout Information for the Toolbar ............................................................................................... Layout Information for the Print List............................................................................................. Features Overview Screen/Print List............................................................................................... Screen Layout of the ALV Grid Control......................................................................................... Data Area Layout............................................................................................................................ Print List Layout............................................................................................................................. ALV Grid Control Overview: Method Overview............................................................................ Inheritance Hierarchy........................................................................................................................ ALV Grid Control: Method Overview (1)......................................................................................... ALV Grid Control: Elementary Methods.......................................................................................... The Constructor................................................................................................................................. The Method SET_TABLE_FOR_FIRST_DISPLAY....................................................................... The Method REFRESH_TABLE_DISPLAY.................................................................................... Display Variants................................................................................................................................. (C) SAP AG
BC412
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 48
ALV Grid Control: Method Overview (2)......................................................................................... ALV Grid Control Overview: Control Events................................................................................. ALV Grid Control: Events................................................................................................................. BEFORE_USER_COMMAND and AFTER_USER_COMMAND................................................ ALV Grid Control: Print List Events................................................................................................. Overview: ALV Grid Control: The Field Catalog........................................................................... Recap: Functions of the Field Catalog............................................................................................. Overview: Information in the Field Catalog.................................................................................... Overview: The Field Catalog Information in the Field Catalog in Detail..................................... Field Catalog: Column Indicators.................................................................................................. Field Catalog: Unit-Specific Formatting........................................................................................ Example: Currency Formatting...................................................................................................... Field Catalog: Output Properties for Columns............................................................................... Field Catalog: Formatting Column Contents................................................................................. Field Catalog: Texts........................................................................................................................ Field Catalog: Technical Column Properties.................................................................................. Field Catalog: Other Fields............................................................................................................ Summary: Structure of the Field Catalog....................................................................................... Field Catalog Overview: Generating the Field Catalog................................................................ Generating the Field Catalog.......................................................................................................... Fields of a Single Dictionary Structure.......................................................................................... Fields of a Dictionary Structure and Local Types.......................................................................... Fields of Several Dictionary Structures.......................................................................................... Fields with and Without Dictionary Relationships......................................................................... Fields with Local Types Only......................................................................................................... Demo Programs Delivered................................................................................................................... ALV Grid Control: Unit Summary.......................................................................................................
(C) SAP AG
BC412
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
49
105.6Workbench Edition – Controls Technology 105.7Overview Controls Technology is SAP's new book about controls programming in ABAP. R/3 Release 4.6 (EnjoySAP) has seen a comprehensive redesign of the user interface of the most important application and Basis transactions in the system. At the center of this initiative is the new controls technology. This book is an introduction to controls programming, containing numerous programming examples and a full programming reference.
105.8About the Authors Controls Technology has been written by the same experienced team of SAP information developers that brought you the successful ABAP/4 Development Workbench Documentation Set in Release 3.0. Controls Technology is the ideal companion to this existing documentation.
105.9Target Group Controls Technology is aimed at ABAP programmers and project managers who are interested in the new features of the R/3 Basis system in Release 4.6.
105.10Features at a Glance
Four-color printing on high-quality paper
Over 400 pages of comprehensive documentation
Easy introduction to controls technology
Numerous programming examples and illustrations
Full control programming reference
An indispensable companion for all ABAP professionals
Release 4.6A
Notes on performance optimization
105.11Content Summary
Introduction to control technology
The Control Framework
Container controls
SAP Toolbar Control
SAP Picture and SAP HTML Viewer
SAP Textedit Control
SAP Simple Tree, List Tree, and Column Tree Control
ALV Grid Control
Control tutorial
(C) SAP AG
BC412
50
105.12 105.13How to Order: SAP Partners and Customers in Europe SAP customers and partners can order Controls Technology online from the SAP Store (www.sap.com) using material number 500 32 529.
105.14How to Order. SAP Partners and Customers Outside Europe You can order Controls Technology online at www.fatbrain.com Karl Kessler
(C) SAP AG
BC412
51
View more...
Comments