) EXCEPTIONS EXCEPTIONS
Method implementations
... 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 with 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
(C) SAP AG
BC412 2-58
Syntax: Handler Method for an Event
CLASS
" method implementation
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
(C) SAP AG
BC412 2-59
ABAP Objects: Registering Handler Methods List of registered methods of other instances for event
Instance
method_x
ref_1
method_y
ref_2
...
...
1
method_x
1
method_y
1
method_n
1
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 2-60
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. What happens? 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 lcl_ on_ _picture_ lcl_event_ event_handler=> handler=>on picture_click FOR my_picture. my_ my_picture. picture.
Who is reacting to whose 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 2-61
Syntax: Linking an Event to a Static Handler Method
DATA:
Static method
Instance of class
... SET HANDLER
© SAP AG 1999
The statement SET HANDLER
(C) SAP AG
BC412 2-62
Syntax: Linking an Event to an Instance Handler Method
DATA:
Instance method
Instances of the classes
... SET HANDLER
© SAP AG 1999
The statement SET HANDLER
(C) SAP AG
BC412 2-63
Overview: Control Events Control Events and the Control Framework Overview Overview Controlsand andscreens screens Controls SAP Picture PictureControl Controland and SAP SAP HTML HTMLViewer Viewer SAP Changingthe theattributes attributesof of aacontrol control Changing Controlevents events Control Overview Overview ABAP Objects Objectsevents events ABAP Controlevents events and andthe theControl ControlFramework Framework Control Event types types Event Controls and andprogram programmodularization modularization Controls © SAP AG 1999
(C) SAP AG
BC412 2-64
Control Events: Overview SAPgui 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 SAPgui.
(C) SAP AG
BC412 2-65
Control Events: Automation Control as Filter Control events: e1, e2, e3, e4, e5
EnjoySAP control e1
e2
e3
e4
e5
e3
e2 Registered events
Automation Controller *1: e1, e2, e4 Function code
© SAP AG 1999
The function of the Automation Controller in the SAPgui 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 than the event registration we have already seen in ABAP Objects.
(C) SAP AG
BC412 2-66
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: y 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. y 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 (above: Basis services). y 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 definitions of the proxy classes in the Class Builder.
(C) SAP AG
BC412 2-67
SAP 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 ...
...
Events for drag and drop operations
...
ondropcomplete
...
=2
=4
© SAP AG 1999
The SAP Picture Control has the following static constants that represent the event IDs: y eventid_picture_click for the event picture_click y eventid_picture_dblclick for the event picture_dblclick y eventid_control_click for the event control_click y eventid_control_dblclick for the event control_dblclick y eventid_context_menu for the event context_menu y eventid_context_menu_selected for the event context_menu_selected Drag and drop events are treated differently than 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 2-68
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
sapevent
Application event
ctxmenu_request
action frame ...
m_id_navigate_complete = 2
m_id_sapevent
=1
m_id_ctxmenu_request
=4
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: y m_id_navigate_complete for the event navigate_complete y m_id_sapevent for the event sapevent y m_id_cxtmenu_request for the event ctxmenu_request y m_id_cxtmenu_selected for the event ctxmenu_selected
(C) SAP AG
BC412 2-69
Registering Control Events with the CFW 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_ _eventscl_ eventid_ _picture_ wa events-eventid cl_gui_ gui_picture=> picture=>eventid picture_click wa_events-eventid = cl_gui_picture=>eventid_picture_click. INSERT wa_events wa_ it_ wa_events INTO TABLE it_events. it_events ii)control_dblclick ... . . . CALL METHOD my_ my_picture->set_registered_events _picturemy picture->set_ set_registered_ registered_events EXPORTING events = it_ 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 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). 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 2-70
Overview: Control Events Event Types Overview Overview Controlsand andscreens screens Controls SAP Picture PictureControl Controland and SAP SAP HTML HTMLViewer Viewer SAP Changingthe theattributes attributesof of aacontrol control Changing Controlevents events Control Overview Overview ABAP Objects Objectsevents events ABAP Controlevents events and andthe theControl ControlFramework Framework Control Event types types Event Controls and andprogram programmodularization modularization Controls © SAP AG 1999
(C) SAP AG
BC412 2-71
Event Type: System Event SAPgui
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 2-72
Event Type: Application Event SAPgui
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 from system events. If a control triggers an application event, control is returned to its container screen. y The control triggers the event to the Automation Control y The Automation Controller passes the information connected to the event (EXPORTING parameters and function code) to the Basis services on the application server. y 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 2-73
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. wa_events-appl_event 'X'. wa_ _eventswa events-appl_ 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 2-74
Screen and Control: Call Sequence for Application Events External SAPgui session Window
EnjoySAP control Application Event SAPgui 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: y 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. y Otherwise, you call the method before the check modules.
(C) SAP AG
BC412 2-75
Application Events and Screen Input Checks (1) SAPgui
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 2-76
Application Events and Screen Input Checks (2) SAPgui
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. y 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. y 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 the entries on the screen and then trigger a different event with a different function code. y 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 the event handling for the first event. 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 2-77
System Event and set_new_ok_code SAPgui
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 2-78
Introduction to the Control Framework: Controls and Program Modularization
Overview Overview Controlsand andscreens screens Controls SAP Picture PictureControl Controland and SAP SAP HTML HTMLViewer Viewer SAP Changingthe theattributes attributesof of aacontrol control Changing Controlevents events Control Controls and andprogram programmodularization modularization Controls
© SAP AG 1999
(C) SAP AG
BC412 2-79
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 2-80
Other Modularization Possibilities my_container
my_control
Methods
calls
calls 100: Screen
my_application: my_application: lcl_application lcl_application
Application data Screen data Methods, event_handler calls
calls Transport
sapbc412d_...: Program
calls auxiliary data
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, which is beyond the scope of this course. There is, however, a dedicated ABAP Objects course BC404.
(C) SAP AG
BC412 2-81
Introduction to the Control Framework: Unit Summary
You are now able to: z Describe how the SAP Control Framework works z Display data in a SAP Picture Control and SAP HTML Viewer on a screen z Changing the attributes of a control z React to the events of a control z Use selected ABAP Objects statements
© SAP AG 1999
(C) SAP AG
BC412 2-82
Control Framework Basics Exercise 1 Unit: Introduction to the Control Framework Topic: Controls and Screens At the conclusion of these exercises, you will be able to: • Create screen elements of the Custom Control area type in the Screen Painter • Create and use reference variables for ABAP Objects instances • Create Container Control and Picture Control instances • Assign Container Control instances to Custom Control areas • Link Picture Control instances to containers • Find information about global classes in the Class Builder You copy a program template consisting of an ABAP program that calls a screen. This screen has a status with the standard navigation functions. Having analysed the structure of the template, you create a Custom Control area on the screen of the program. You create a container instance that you link to the Custom Control area, and a Picture Control instance that you assign to the container. Program:
ZBC412_##_CFW_EX1
Template:
SAPBC412_BAST_EXERCISE1
Sample solution:
SAPBC412_BASS_EXERCISE1
## is your group number
1-1
Copy the program template SAPBC412_BAST_EXERCISE1 with all its subobjects to program ZBC412_##_CFW_EX1, and make yourself familiar with the functions provided by that program.
1-2
On screen 100, create a Custom Control area with the following properties:
(C) SAP AG
BC412 2-83
Attribute
Value
Proposal
Element type
Custom Control
Name
CONTROL_AREA1
Line
Freely definable
2
Column
Freely definable
2
Def.Length/
Freely definable
50
Height
Freely definable
11
Resizing
on
Min. lines
Freely definable
3
Min. columns
Freely definable
5
Vis.Length
Activate the screen. 1-3
Create a container instance. You do this in a PBO module of screen 100. 1-3-1 Create a reference variable for your container instance (suggested name: ref_container). Use the global class type cl_gui_custom_container. 1-3-2 Create a flag variable (type C, length 1, suggested name: first_time). 1-3-3 Screen 100 has the PBO module init_control_processing. Extend the module to create a Container Control instance when the program is executed for the first time. Pass the name of the Custom Control area you created in interface parameter container_name. Handle all exceptions triggered by the 'constructor' under the special exception other. Terminate program execution if one of the exceptions is triggered. In this context, use dialog message 010 of message class bc412 (message type A).
1-4
Create an instance of the Picture Control. The corresponding source code is also encapsulated in PBO module init_control_processing that is used in 1-3-3 above. 1-4-1 Create a reference variable for your Picture Control instance (suggested name: ref_picture). Use the global class type cl_gui_picture. 1-4-2 Extend the module init_control_processing to create a Picture Control instance when the program is executed for the first time. Pass your Container Control reference to interface parameter parent. Handle all exceptions triggered by the 'constructor' under the special exception other. Terminate program execution if one of the exceptions is triggered. In this context, use dialog message 011 of message class bc412 (message type A).
(C) SAP AG
BC412 2-84
1-4
(C) SAP AG
Activate and test your program. If your program runs correctly you see an empty screen (or an empty control area). If your program contains errors, you see the effects of either an 'A message' or of a runtime error. •
Message class bc412 has been set globally for the program (see statement REPORT).
•
The pushbuttons on the screen of the template have not yet been assigned a function. You will use them in one of the next exercises.
BC412 2-85
Exercise 2 Unit: Introduction to the Control Framework Topic: Changing the Attributes of a Control At the conclusion of these exercises, you will be able to: • Change attributes of controls using method calls • Display data in the Picture Control Using the first exercise as a starting-point, you will now display an image in your Picture Control instance. The data source you use is the BDS (Business Document Server).
Program:
ZBC412_##_CFW_EX2
Template:
SAPBC412_BAST_EXERCISE2
Sample solution:
SAPBC412_BASS_EXERCISE2
## is your group number
2-1
Copy program template SAPBC412_BAST_EXERCISE2 with all its subobjects to program ZBC412_##_CFW_EX2, or use the solution you created in the last exercise.
2-2
To be able to display an image in your Picture Control instance, you need a URL for that image. For this training course, data objects have been added to the BDS that can be displayed in the Picture Control. Use these objects in your program. You can use function module BC412_BDS_GET_PIC_URL to get a valid URL for an image in the BDS. 2-2-1 Define an ABAP field for the URL with the following properties: ABAP type C, length 80 (suggested name: l_url). 2-2-2 Call the function module BC412_BDS_GET_PIC_URL. This function module encapsulates the technical details for accessing the images contained in the BDS. Set the value of the IMPORT parameter NUMBER to 1 (default value). The EXPORT parameter URL returns a valid URL. This URL is valid as long as the program executes. To keep your code clearly structured, you should use the function module at START-OF-SELECTION before the screen 100 is called.
(C) SAP AG
BC412 2-86
Terminate your program if the function module cannot return a valid URL. To do this, use the LEAVE PROGRAM statement. 2-2-3 Make sure that the image for which you now have a URL is displayed in your control instance. To do this, you use the instance method load_picture_from_url of class cl_gui_picture. Handle all exceptions triggered by the 'constructor' under the special exception other. Terminate program execution if one of the exceptions is triggered. In this context, use dialog message 012 of message class bc412 (message type A). If you receive the EXPORT parameter RESULT (ABAP type I), you can use dialog messages 013 and 014 (message class bc412, message type S or I) to indicate whether the attempt to display the image was successful or not. Note the semantic significance of the value returned (parameter result): 1 = Image loaded successfully, 0 = Image could not be loaded.
(C) SAP AG
BC412 2-87
Exercise 3 Unit: Introduction to the Control Framework Topic: Changing the Attributes of a Control At the conclusion of these exercises, you will be able to: • Destroy control instances at the frontend • Release reference variables to proxy objects • Change control attributes through method calls (controlled through pushbuttons of a screen) You extend the sample solution you created in the last exercise to destroy all frontend instances before the program is ended. In addition, you allow the user to control the mode in which the image is displayed in the control by means of pushbuttons on the screen. Program:
ZBC412_##_CFW_EX3
Template:
SAPBC412_BAST_EXERCISE3
Sample solution:
SAPBC412_BASS_EXERCISE3
## is your group number 3-1
Copy the program template SAPBC412_BAST_EXERCISE3 with all its subobjects to program ZBC412_##_CFW_EX3, or use the solution you created in the last exercise.
3-2
Make sure that your frontend control instances are destroyed correctly before the program is ended. To do this, implement the FORM subroutine free_control_ressources. Call the instance method free for each proxy instance, and release the ABAP reference variables. Note: The call and the interface of the subroutine have already been created in your program.
3-3
Make sure that you can change the display mode for your Picture Control instance by using the pushbuttons on screen 100. 3-3-1 Implement the functions 'STRETCH', 'NORMAL', 'NORMAL_CENTER', 'FIT', 'FIT_CENTER' defined by the pushbuttons. The implementation of these functions has been provided for in the PAI module user_command_0100. Use the instance method set_display_mode of class cl_gui_picture. If an exception is triggered when the method is executed, you should issue dialog message 015 of message class bc412 (message type S or I).
(C) SAP AG
BC412 2-88
3-3-2 Test the mode in which the control displays the image by resizing the window of the screen. To set a value for the interface parameter display_mode of method set_display_mode, use the following class constants: display_mode_stretch, display_mode_normal, display_mode_normal_center, display_mode_fit and display_mode_fit_center of class cl_gui_picture. Access is possible using cl_gui_picture=>display_mode_fit.
(C) SAP AG
BC412 2-89
Exercise 3 Optional Parts At the conclusion of these optional exercises, you will be able to: • Determine attributes of a frontend control (read access) You allow the user to display the current display mode of the Picture Control.
3-4
Program:
same program
Template:
as above
Sample solution:
SAPBC412_BASS_EXERCISE3A
Add another pushbutton to screen 100 which, when chosen, displays the current display mode of the Picture Control (as a technical value) in a dialog box. 3-4-1 Create another pushbutton on screen 100 with the following attributes: Attribut
Value
Proposal
Element type
Pushbutton
Name
Freely definable
BUT6
Text
Freely definable
Query mode
Icon
Freely definable
ICON_INFORMATION
FctCode
MODE_INFO
FctType
' ' (
3-4-2 Implement the associated function (function code MODE_INFO) in the module user_command_0100. Read the attribute display_mode of 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 type the variable with reference to cl_gui_picture=>display_mode. Output the content of your data object (current_mode) using dialog message 025 (message class bc412, message type I) .
(C) SAP AG
BC412 2-90
Exercise 4 Unit: Introduction to the Control Framework Topic: Control Events At the conclusion of these exercises, you will be able to: • Define and implement a static method of a local class as an event handler • Register a static handler method for an ABAP Objects event • Register control events at the Control Framework • Find information about control events in the ABAP Workbench Your task is to allow the user of your program to determine the coordinates of a pixel of the image. The user should be able to do this by clicking the selection button of the mouse on the image. To implement this function, you use a control event. Program:
ZBC412_##_CFW_EX4
Template:
SAPBC412_BAST_EXERCISE4
Sample solution:
SAPBC412_BASS_EXERCISE4
## is your group number 4-1
Copy the program template SAPBC412_BAST_EXERCISE4 with all its subobjects to program ZBC412_##_CFW_EX4, or use the solution you created in the last exercise.
4-2
Create a local class in your program that contains an event handling method for the event PICTURE_CLICK of your Picture Control instance. 4-2-1 Go to the Class Builder and obtain information on the interface of the event PICTURE_CLICK of class cl_gui_picture. 4-2-2 Define a local class in the data declaration part of your program (suggested name: lcl_event_handler). 4-2-3 The local class should have a public static method which is to be used as the event handling method. Use the CLASS-METHODS statement to define an event handling method for
(C) SAP AG
BC412 2-91
the event PICTURE_CLICK of class cl_gui_picture (suggested name: on_picture_click). Define the interface of the method so that it receives the coordinates of the pixel on which the user clicked from the event. 4-2-4 Implement the method in the implementation part of the class. In response to the event, output the coordinates returned using dialog message 016 (message class bc412, message type I). 4-3
Register the static method you created for the event PICTURE_CLICK of your proxy instance for the Picture Control instance at the frontend. 4-3-1 Add the SET HANDLER statement to the PBO module init_control_processing to register the static method for the event of your Picture Control instance.
4-4
Register the control event PICTURE_CLICK of your control instance at the Control Framework. 4-4-1 In the data declaration part of your program, define two additional data objects: - An internal table that you use to pass the events to be registered at the CFW to the instance method set_registered_events of class cl_gui_picture (suggested name for the internal table: it_events), - A work area that you need when you fill the internal table (suggested name: wa_events). 4-4-2 Type the internal table with reference to cntl_simple_events (type of an internal table; type declaration in the ABAP Dictionary; new for Release 4.6). Type the work area so that is has the same row structure as the internal table. 4-4-3 In the Class Builder, inform yourself about the names of the class constants for the control events (Æ event_ids). You need these names to register the events at the Control Framework. 4-4-4 Fill the internal table with the data for the event PICTURE_CLICK, and register the event at the Control Framework using the instance method set_registered_events. To do this, extend 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 use cl_gui_picture=>eventid_picture_click to access class constants. (C) SAP AG
BC412 2-92
(C) SAP AG
BC412 2-93
Exercise 4 Optional Parts At the conclusion of these exercises, 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 at the Control Framework • Find information about control events in the ABAP Workbench Your task is to allow the user of your program to determine the coordinates of a pixel which is in the control area but not in the image area. The user should be able to do this by double-clicking the selection button of the mouse on the control area. To implement this function, you use another control event.
4-6
Program:
same as above
Template :
same as above
Sample solution:
SAPBC412_BASS_EXERCISE4A
Extend your program to show a user double-clicking in the control area outside the image displayed the coordinates of the position on which the mouse was doubleclicked.
To do this, use the event CONTROL_DBLCLICK, and perform the same steps for this new event as described in 4-2 to 4-4.
(C) SAP AG
•
Use the same local class, and add another public static method for handling CONTROL_DBLCLICK events of your Picture Control instance to this class.
•
Use dialog message 017 of message class bc412 (message type I) to respond to the event.
BC412 2-94
Note 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 2-95
Introduction to the Control Framework Solution Task 1 Unit: Introduction to the Control Framework Topic: Controls and Screens
Sample solution SAPBC412_BASS_EXERCISE1 Screen flow logic SCREEN 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.
ABAP program Data 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 TYPE c, " return flag (used in " standard user dialogs) *
control specific: object references ref_container TYPE REF TO cl_gui_custom_container, ref_picture TYPE REF TO cl_gui_picture,
(C) SAP AG
BC412 6-96
*
control specific: auxiliary fields first_time TYPE c. " flag (screen + control)
(C) SAP AG
BC412 6-97
Event blocks of the ABAP main program * start of main program START-OF-SELECTION. CALL SCREEN 100.
" container screen for SAP-Enjoy " controls
* end of main program
Modules *&-----------------------------------------------------------------* *& 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 first_time IS INITIAL. " prevent re-processing on ENTER first_time = 'X'. * 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. ENDIF. *
" cancel program processing
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. ENDIF.
ENDIF. ENDMODULE.
(C) SAP AG
" cancel program processing
" INIT_CONTROL_PROCESSING
BC412 6-98
OUTPUT
*&-----------------------------------------------------------------* *& 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 to WHEN to WHEN to WHEN to WHEN to
'STRETCH'. " picture be implemented later 'NORMAL'. " picture be implemented later 'NORMAL_CENTER'. " picture be implemented later 'FIT'. " picture be implemented later 'FIT_CENTER'. " picture be implemented later
ENDCASE. ENDMODULE.
operation: stretch to fit area operation: fit to normal size operation: center normal size operation: zoom picture operation: zoom and center
" USER_COMMAND_0100
INPUT
*&-----------------------------------------------------------------* *& Module STATUS_0100 OUTPUT *&-----------------------------------------------------------------* * Set GUI for screen 0100 *------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'STATUS_NORM_0100'. (C) SAP AG
BC412 6-99
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' 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
(C) SAP AG
BC412 6-100
INPUT
Subroutines *&-----------------------------------------------------------------* *& Form free_control_ressources *&-----------------------------------------------------------------* * Here you should implement: Free all control related * ressources. *------------------------------------------------------------------* * no interface *------------------------------------------------------------------* FORM free_control_ressources. * to be implemented later ENDFORM. " free_control_ressources
(C) SAP AG
BC412 6-101
Solution for Task 2 Unit: Introduction to the Control Framework Topic: Changing the Attributes of a Control Sample solution SAPBC412_BASS_EXERCISE2 ABAP program Data 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 TYPE c, " return flag (used in " 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 first_time TYPE c, " flag (screen + control) 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 7-102
Event blocks of the ABAP main program * 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. LEAVE PROGRAM. ENDIF.
" no picture --> end of program
CALL SCREEN 100.
" container screen for SAP-Enjoy " controls
* end of main program
Modules *&-----------------------------------------------------------------* *& 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 first_time IS INITIAL. " prevent re-processing on ENTER first_time = 'X'. * 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. ENDIF. *
" cancel program processing
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. ENDIF.
(C) SAP AG
BC412 7-103
" cancel programn processing
*
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. MESSAGE s013. WHEN 1. MESSAGE s014. ENDCASE.
ENDIF. ENDMODULE.
(C) SAP AG
" picture not loaded " load of picture successful
" INIT_CONTROL_PROCESSING
BC412 7-104
OUTPUT
Solution for Task 3 Unit: Introduction to the Control Framework Topic: Changing the Attributes of a Control
Sample solution SAPBC412_BASS_EXERCISE3 ABAP program Modules *&-----------------------------------------------------------------* *& 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.
(C) SAP AG
BC412 8-105
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'. " 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. ENDCASE. ENDMODULE.
(C) SAP AG
" USER_COMMAND_0100
BC412 8-106
INPUT
Subroutines *&-----------------------------------------------------------------* *& 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. " free_control_ressources
(C) SAP AG
BC412 8-107
Solution for Task 3: Optional Parts Unit: Introduction to the Control Framework Topic: Changing the Attributes of a Control
Sample solution SAPBC412_BASS_EXERCISE3A ABAP program Data 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 TYPE c, " return flag (used in " 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 first_time TYPE c, " flag (screen + control) 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.
(C) SAP AG
BC412 9-108
Modules *&-----------------------------------------------------------------* *& 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. 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 9-109
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 9-110
INPUT
Solution for Task 4 Unit: Introduction to the Control Framework Topic: Control Events
Sample solution SAPBC412_BASS_EXERCISE4 ABAP program Local 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 10-111
Data declarations * data declarations * screen specific DATA: ok_code TYPE sy-ucomm, copy_ok_code LIKE ok_code, l_answer TYPE c,
" " " "
command field copy of ok_code return flag (used in 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 first_time TYPE c, " flag (screen + control) 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
Modules *&-----------------------------------------------------------------* *& 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 first_time IS INITIAL. " prevent re-processing on ENTER first_time = 'X'. * 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. ENDIF.
(C) SAP AG
BC412 10-112
" cancel program processing
*
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. ENDIF.
*
" cancel program processing
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. MESSAGE s013. WHEN 1. MESSAGE s014. ENDCASE.
* *
" picture not loaded " load of picture successful
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 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 10-113
OUTPUT
Solution for Task 4: Optional Parts Unit: Introduction to the Control Framework Topic: Control Events
Sample solution SAPBC412_BASS_EXERCISE4A ABAP program Local 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. ENDMETHOD. METHOD on_control_dblclick. MESSAGE i017 WITH mouse_pos_x mouse_pos_y. ENDMETHOD. ENDCLASS.
(C) SAP AG
BC412 11-114
Modules *&-----------------------------------------------------------------* *& 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 first_time IS INITIAL. " prevent re-processing on ENTER first_time = 'X'. * 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. 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. ENDIF.
*
" cancel program processing
" cancel program processing
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.
(C) SAP AG
BC412 11-115
ENDIF.
(C) SAP AG
BC412 11-116
CASE l_result. WHEN 0. MESSAGE s013. WHEN 1. MESSAGE s014. ENDCASE. * *
" picture not loaded " load of picture successful
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 11-117
OUTPUT
Complete Solution for all Tasks Unit: Introduction to the Control Framework
Sample solution SAPBC412_BASS_EXERCISE Screen flow logic SCREEN 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.
ABAP program Local 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 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 13-118
*------------------------------------------------------------------* * 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.
Data declarations * data declarations * screen specific DATA: ok_code TYPE sy-ucomm, copy_ok_code LIKE ok_code, l_answer TYPE c,
" " " "
command field copy of ok_code return flag (used in 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 first_time TYPE c, " flag (screen + control) 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
(C) SAP AG
BC412 13-119
Event blocks of the ABAP main program * 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. LEAVE PROGRAM. ENDIF.
" no picture --> end of program
CALL SCREEN 100.
" container screen for SAP-Enjoy " controls
* end of main program
Modules *&-----------------------------------------------------------------* *& 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 first_time IS INITIAL. " prevent re-processing on ENTER first_time = 'X'. * 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. ENDIF.
(C) SAP AG
BC412 13-120
" cancel program processing
*
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. ENDIF.
*
" cancel program processing
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. MESSAGE s013. WHEN 1. MESSAGE s014. ENDCASE.
* *
" picture not loaded " load of picture successful
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 13-121
*
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'. 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 13-122
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. 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. (C) SAP AG
BC412 13-123
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' 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
(C) SAP AG
BC412 13-124
INPUT
Subroutines *&-----------------------------------------------------------------* *& 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. " free_control_ressources
(C) SAP AG
BC412 13-125
SAP Container
Contents: z The SAP container concept z SAP Custom Container Control z SAP Dialog Box Container Control z SAP Docking Container Control z SAP Splitter Control z SAP Easy Splitter Control
© SAP AG 1999
(C) SAP AG
BC412 14-1
SAP Container: Unit Objectives
At the conclusion of this unit, you will be able to: z Explain how SAP containers work in the Control Framework z List the container controls that you can use in the SAP System z Describe the features of each of the container controls z Use SAP container controls
© SAP AG 1999
(C) SAP AG
BC412 14-2
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 14-3
SAP Container Overview: The Container Concept
Thecontainer containerconcept concept The SAPCustom CustomContainer ContainerControl Control SAP SAPDialog DialogBox BoxContainer Container Control Control SAP SAPDocking DockingContainer ContainerControl Control SAP SAP Splitter SplitterContainer ContainerControl Control SAP SAP Easy EasySplitter SplitterContainer ContainerControl Control SAP
© SAP AG 1999
(C) SAP AG
BC412 14-4
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 14-5
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: y SAP Custom Container (global class cl_gui_custom_container) y SAP Dialog Box Container (global class cl_gui_dialogbox_container) y SAP Docking Container (global class cl_gui_docking_container) y SAP Splitter Container (global class cl_gui_splitter_container) y SAP Easy Splitter Container (global class cl_gui_easy_splitter_container)
(C) SAP AG
BC412 14-6
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 y An area on a screen (SAP Custom Container) y A entire screen (SAP Docking Container, SAP Dialog Box Container) y Another container (SAP Splitter Container, SAP Easy Splitter Container) The fact that you can nest controls provides further display possibilities.
(C) SAP AG
BC412 14-7
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
(C) SAP AG
BC412 14-8
Technical Methods for Attaching SAP Containers SAPgui
Abbreviated display
Screen 100 Container
Frontend
Abbreviated display
Appl. server Internal session Top level container SCREEN9
dialog box level 1 dialog box level 0
0100
Container visible at the frontend Container not visible at the frontend
Container Program
SCREEN1 SCREEN0
Container destroyed at frontend
© 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
(C) SAP AG
BC412 14-9
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. y Either on the screen with which the container control was created, or y 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: y 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). y 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 14-10
SAP Container Overview: SAP Custom Container Control
Thecontainer containerconcept concept The SAPCustom CustomContainer ContainerControl Control SAP SAPDialog DialogBox BoxContainer Container Control Control SAP SAPDocking DockingContainer ContainerControl Control SAP SAP Splitter SplitterContainer ContainerControl Control SAP SAP Easy EasySplitter SplitterContainer ContainerControl Control SAP
© SAP AG 1999
(C) SAP AG
BC412 14-11
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
N N N N
( 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: y Program name y Screen number y Name of the area y Number of the dialog box level at which the container and screen can be displayed.
(C) SAP AG
BC412 14-12
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
(C) SAP AG
BC412 14-13
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
SAP Container Overview: SAP Dialog Box Container Control
Thecontainer containerconcept concept The SAPCustom CustomContainer ContainerControl Control SAP SAPDialog DialogBox BoxContainer Container Control Control SAP SAPDocking DockingContainer ContainerControl Control SAP SAP Splitter SplitterContainer ContainerControl Control SAP SAP Easy EasySplitter SplitterContainer ContainerControl Control SAP
© SAP AG 1999
(C) SAP AG
BC412 14-15
SAP Dialog Box Container: Features
Screen
Properties
Window title
Modeless window
Container
N N N N
( 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
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 14-16
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_container. To create the instance itself, use the statement CREATE OBJECT
(C) SAP AG
BC412 14-17
SAP Container Overview: SAP Docking Container Control
Thecontainer containerconcept concept The SAPCustom CustomContainer ContainerControl Control SAP SAPDialog DialogBox BoxContainer Container Control Control SAP SAPDocking DockingContainer ContainerControl Control SAP SAP Splitter SplitterContainer ContainerControl Control SAP SAP Easy EasySplitter SplitterContainer ContainerControl Control SAP
© SAP AG 1999
(C) SAP AG
BC412 14-18
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 14-19
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 14-20
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 the container control IF sy-subrc NE 0. ...
at the left-hand edge of screen
© 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
(C) SAP AG
BC412 14-21
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 14-22
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 14-23
SAP Container Overview: SAP Splitter Container Control
Thecontainer containerconcept concept The SAPCustom CustomContainer ContainerControl Control SAP SAPDialog DialogBox BoxContainer Container Control Control SAP SAPDocking DockingContainer ContainerControl Control SAP SAP Splitter SplitterContainer ContainerControl Control SAP SAP Easy EasySplitter SplitterContainer ContainerControl Control SAP
© SAP AG 1999
(C) SAP AG
BC412 14-24
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 14-25
SAP Splitter Container: Use
Splitter container a0101 a0102
1
a0201 a0202
2
Container
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 14-26
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 parent = cust_container instance with a 2 x 2 grid * repid = " program name (four cells = four areas for * dynnr = " screen number further controls) rows = 2 The splitter container is linked columns = 2 to a custom container ... 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 the 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
(C) SAP AG
BC412 14-27
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 14-28
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 14-29
SAP Container Overview: SAP Easy Splitter Container Control
Thecontainer containerconcept concept The SAPCustom CustomContainer ContainerControl Control SAP SAPDialog DialogBox BoxContainer Container Control Control SAP SAPDocking DockingContainer ContainerControl Control SAP SAP Splitter SplitterContainer ContainerControl Control SAP SAP Easy EasySplitter SplitterContainer ContainerControl Control SAP
© SAP AG 1999
(C) SAP AG
BC412 14-30
SAP Easy Splitter Container: Features
Properties
or
( 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
© 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 14-31
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 an instance of the CREATE OBJECT easy_split_container SAP Easy Splitter Container EXPORTING Control with a horizontal parent = cust_container splitter bar. The container * repid = " program name is linked to a custom container. * dynnr = " screen number orientation = easy_split_container->orientation_vertical ... EXCEPTIONS others = 1. IF sy-subrc NE 0. ... Parameter parent orientation
Meaning Reference variable to the 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
(C) SAP AG
BC412 14-32
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 14-33
SAP Container: Unit Summary
You are now able to: z Explain how SAP containers work in the Control Framework z List the container controls that you can use in the SAP System z Describe the features of each of the container controls z Use SAP container controls
© SAP AG 1999
(C) SAP AG
BC412 14-34
SAP 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
Test your program.
(C) SAP AG
BC412 14-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 14-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
Test your program.
(C) SAP AG
BC412 14-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 14-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
BC412 14-39
•
•
A reference variable for a Splitter Container instance (suggested name: ref_splitter). Type this variable with reference to cl_gui_splitter_container.
•
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.
(C) SAP AG
BC412 14-40
Message
Usage
Number
Class
Type
012
bc412
A
Exception
013
bc412
S
Not loaded
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 14-41
Note 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 14-42
SAP Container Solution Task 1 Unit: SAP Container Topic: SAP Docking Container
Sample solution SAPBC412_CONS_EXERCISE1 Screen flow logic SCREEN 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.
ABAP program Local 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 FOR EVENT control_dblclick OF cl_gui_picture IMPORTING mouse_pos_x mouse_pos_y. ENDCLASS.
(C) SAP AG
BC412 18-43
*------------------------------------------------------------------* * 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.
Data declarations * data declarations * screen specific DATA: ok_code TYPE sy-ucomm, copy_ok_code LIKE ok_code, l_answer TYPE c,
" " " "
command field copy of ok_code return flag (used in 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 first_time TYPE c, " flag (screen + control) 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
(C) SAP AG
BC412 19-44
Event blocks of the ABAP main program * 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. LEAVE PROGRAM. ENDIF.
" no picture --> end of program
CALL SCREEN 100.
" container screen for SAP-Enjoy " controls
* end of main program
Modules *&-----------------------------------------------------------------* *& 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 first_time IS INITIAL. " prevent re-processing on ENTER first_time = 'X'. * create container object and link to screen (left screen side) CREATE OBJECT ref_container EXPORTING side = cl_gui_docking_container=>dock_at_left EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a010. ENDIF.
(C) SAP AG
BC412 21-45
" cancel program processing
*
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. ENDIF.
*
" cancel program processing
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. MESSAGE s013. WHEN 1. MESSAGE s014. ENDCASE.
* *
" picture not loaded " load of picture successful
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 21-46
*
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'. 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 21-47
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. WHEN 'MODE_INFO'. current_mode = ref_picture->display_mode. MESSAGE i025 WITH current_mode. ENDCASE. ENDMODULE.
(C) SAP AG
" USER_COMMAND_0100
BC412 21-48
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'. 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.
(C) SAP AG
BC412 21-49
SET SCREEN sy-dynnr. ENDCASE. ENDCASE. ENDMODULE.
" EXIT_COMMAND_0100
INPUT
Subroutines *&-----------------------------------------------------------------* *& 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. " free_control_ressources
(C) SAP AG
BC412 22-50
Solution for the Optional Parts of Task 1 Unit: SAP Container Topic: SAP Docking Container
Sample solution SAPBC412_CONS_EXERCISE1A ABAP program Data declarations and selection screen * data declarations * screen specific DATA: ok_code TYPE sy-ucomm, copy_ok_code LIKE ok_code, l_answer TYPE c,
" " " "
command field copy of ok_code return flag (used in 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 first_time TYPE c, " flag (screen + control) 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 PARAMETERS: p_side AS CHECKBOX.
(C) SAP AG
BC412 23-51
Modules *&-----------------------------------------------------------------* *& 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 first_time IS INITIAL. " prevent re-processing on ENTER first_time = 'X'. * 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. ENDIF. *
" cancel program processing
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. ENDIF.
(C) SAP AG
BC412 23-52
" cancel program processing
*
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. MESSAGE s013. WHEN 1. MESSAGE s014. ENDCASE.
* *
" picture not loaded " load of picture successful
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 23-53
OUTPUT
Solution for Task 2 Unit: SAP Container Topic: SAP Splitter Container
Sample solution SAPBC412_CONS_EXERCISE2 Screen flow logic SCREEN 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.
ABAP program Local 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 FOR EVENT control_dblclick OF cl_gui_picture IMPORTING mouse_pos_x mouse_pos_y. ENDCLASS.
(C) SAP AG
BC412 27-54
*------------------------------------------------------------------* * 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.
Data declarations * data declarations * screen specific DATA: ok_code TYPE sy-ucomm, copy_ok_code LIKE ok_code, l_answer TYPE c,
" " " "
command field copy of ok_code return flag (used in 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 first_time TYPE c, " flag (screen + control) l_url1(80) TYPE c, " URL of picture 1 to be shown l_url2(80) TYPE c, " URL of picture 2 to be shown 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. " work area
(C) SAP AG
BC412 27-55
Event blocks of the ABAP main program * 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_url1 EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. LEAVE PROGRAM. ENDIF.
" no picture --> end of program
CALL FUNCTION 'BC412_BDS_GET_PIC_URL'" fetch URL of second picture EXPORTING " from BDS number = 2 IMPORTING url = l_url2 EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. LEAVE PROGRAM. ENDIF.
" no picture --> end of program
CALL SCREEN 100.
" container screen for SAP-Enjoy " controls
* end of main program
(C) SAP AG
BC412 27-56
Modules *&-----------------------------------------------------------------* *& 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 first_time IS INITIAL. " prevent re-processing on ENTER first_time = 'X'. * 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. ENDIF. *
create splitter container object and link to custom control CREATE OBJECT ref_splitter EXPORTING parent = ref_container rows = '1' columns = '2' EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a010. ENDIF.
* *
" cancel program processing
" cancel program processing
fetch pointer to splitter control areas left cell CALL METHOD ref_splitter->get_container EXPORTING row = '1' column = '1'
(C) SAP AG
BC412 27-57
RECEIVING container = cell_1_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) CREATE OBJECT ref_pic_left EXPORTING parent = cell_1_1 EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a011. ENDIF.
*
picture control object 2 (right cell) CREATE OBJECT ref_pic_right EXPORTING parent = cell_1_2 EXCEPTIONS others = 1. IF sy-subrc NE 0. MESSAGE a011. ENDIF.
* *
" cancel program processing
" cancel program processing
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. MESSAGE s013. WHEN 1. MESSAGE s014.
(C) SAP AG
BC412 27-58
" picture not loaded " load of picture successful
ENDCASE.
(C) SAP AG
BC412 27-59
*
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. MESSAGE s013. WHEN 1. MESSAGE s014. ENDCASE.
* *
" picture not loaded " load of picture successful
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 EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE a012. ENDIF.
*
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 27-60
* *
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 = ' ' 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 27-61
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'. " picture operation: zoom and center 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. (C) SAP AG
BC412 27-62
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'. 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
(C) SAP AG
BC412 27-63
PERFORM free_control_ressources. LEAVE PROGRAM. WHEN 'A'. CLEAR ok_code. SET SCREEN sy-dynnr. ENDCASE. ENDCASE. ENDMODULE. " EXIT_COMMAND_0100
INPUT
Subroutines *&-----------------------------------------------------------------* *& Form free_control_ressources *&-----------------------------------------------------------------* * 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. " free_control_ressources
(C) SAP AG
BC412 27-64
SAP Tree Control
Contents: z Tree Control types: Simple tree Column tree List tree z Properties z Use z Data handling z Events
© SAP AG 1999
(C) SAP AG
BC412 28-1
SAP Tree Control: Unit Objectives
At the conclusion of this unit, you will be able to: z Describe the features of the different tree control variants:
Attributes
Methods
Events
z Display data in a tree control:
© SAP AG 1999
(C) SAP AG
BC412 28-2
Create hierarchies
Use additional information (items)
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 28-3
SAP Tree Control Overview: Introduction - Tree Controls and Their Attributes
Introduction:Tree Treecontrols controlsand andtheir theirattributes attributes Introduction: Constructor,methods, methods,and and events events Constructor, Creatingaahierarchy hierarchy Creating Datahandling handling strategies strategies Data Itemtables tables Item
© SAP AG 1999
(C) SAP AG
BC412 28-4
SAP Tree Control
Object name Description SAPBC412 Development class object types Dictionary structures Programs BC412: Demo ... SAPBC412_BASD_AREA... BC412: Demo ... SAPBC412_BASD_CALL... . . . . . . Function groups Message classes
Properties ( Data displayed hierarchically in a list
( List can be expanded and collapsed
( User interaction possible
( Can be used as: - Navigation aid - Value list - Item 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 y Navigation aid y Value list y 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: y Individual lines y Areas consisting of several lines y Elements within lines y 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 28-5
SAP Tree Control: Principal 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. y There is a hierarchy area, in which the hierarchy data is displayed. y There is a second structured area, in which data can be displayed as a table or list. y 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 28-6
Tree Control Implementation
Areas used
Control name
ABAP class
( Simple Tree
cl_gui_simple_tree
( Column Tree
cl_gui_column_tree
( List Tree
cl_gui_list_tree
Unused
Headings
Additional info
© 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: y cl_gui_simple_tree for the Simple Tree y cl_gui_column_tree for the Column Tree y cl_gui_list_tree for the List Tree
(C) SAP AG
BC412 28-7
Simple Tree: Properties
Root node First folder Leaf 1 in folder 1 Leaf 2 in folder 2
Node area
Hierarchy area Unused
( Only hierarchy area ( 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 28-8
Simple Tree: Node Structure
Hierarchy area Text can appear here Icon
Example:
Hierarchy text
Root node First folder Leaf 1 in folder 1 Leaf 2 in folder 2 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 28-9
Column Tree: Properties
Hierarchy heading Root node First folder Leaf 1 in folder 1 Leaf 2 in folder 2
Hierarchy area Column 1
Column 2 Root text 1 Entry 1
Column 3 Root text 2 Entry ... Leaf 1 column 3 Leaf 2 column 2 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 28-10
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
© SAP AG 1999
The nodes in the column tree can contain one icon. You can display items in the columns as follows: y As an icon with text (both are optional) y As a checkbox with icon and text (icon and text are optional) y As a pushbutton with icon and text (icon and text are optional) y As a link (text displayed as hotspot. The mouse pointer changes shape when it is positioned over a link.) You should not use columns that display all of their items as pushbuttons. Instead, you should display the data as a link.
(C) SAP AG
BC412 28-11
List Tree: Properties
Headings
Hierarchy heading Objects Screens Screen 1 Screen 2 Programs Prog 1 Prog 2
List heading
SAPTROX1 Comment on SAPTROX SAPTRIXTROX Comment on ...
Hierarchy area
List area
0100 MUELLER Comment on ... Comment on ... 0200 JONES
Node area
( Hierarchy area ( Headings ( Additional information as list lines (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 28-12
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 : Link
© SAP AG 1999
The nodes in the column tree can contain one icon. You can display the items of a node as follows: y As an icon with text (both are optional) y As a checkbox with icon and text (icon and text are optional) y As a pushbutton with icon and text (icon and text are optional) y As a link (text displayed as hotspot. The mouse pointer changes shape when it is positioned over a link.) You should avoid excessive use of pushbuttons. The List Tree allows you to choose between fixed font and proportional font for text items. For items with proportional font, you should use the "Automatic length" attribute.
(C) SAP AG
BC412 28-13
SAP Tree Control Overview: Constructor, Methods, and Events
Introduction:Tree Treecontrols controlsand andtheir theirattributes attributes Introduction: Constructor,methods, methods,and and events events Constructor, Creatingaahierarchy hierarchy Creating Datahandling handling strategies strategies Data Itemtables tables Item
© SAP AG 1999
(C) SAP AG
BC412 28-14
SAP Tree Control: Communication and Data Flow
Tree Control
Display data
Data for display
Methods Packet of data to be displayed and/or display information
Events Retrieved set, selected nodes and/or display information
Element name •Node •Heading •Column item •List item
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 28-15
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: y All of the Tree Control classes are derived from cl_tree_control_base, which itself inherits from cl_gui_control. y The class cl_gui_simple_tree inherits directly from cl_tree_control_base. y 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. y Only the classes cl_gui_simple_tree, cl_gui_column_tree, and cl_gui_list_tree can be instantiated.
(C) SAP AG
BC412 28-16
Constructor, Methods, and Events : Simple Tree
Introduction:Tree Treecontrols controlsand andtheir theirattributes attributes Introduction: Constructor,methods, methods,and and events events Constructor, SimpleTree Tree Simple ColumnTree Tree Column ListTree Tree List Creatingaahierarchy hierarchy Creating Datahandling handling strategies strategies Data Itemtables tables Item © SAP AG 1999
(C) SAP AG
BC412 28-17
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 nodes:
( ' ' : 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. y Node selection mode y Highlighting of selected nodes when the focus changes at the frontend.
(C) SAP AG
BC412 28-18
Simple Tree: Method Overview
Changing attributes Creating and changing nodes Nodes Expanding Selecting Deleting Changing the attributes Setting up keyboardkeyboard-triggered events Other methods Finding 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 y Methods that you use to create and change nodes y Methods that you use to change individual nodes (expand, select, delete, change attributes) y Methods that define the keys that can trigger an event y 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 further information about the precise names of the methods and their interfaces, refer to the online documentation for the Simple Tree.
(C) SAP AG
BC412 28-19
Simple Tree: Event Overview
Nodes node_double_click
Double-click on a node
node_keypress
Node selected and key pressed
expand_no_children
User expanded a node with no contents at frontend
selection_changed
Selected node has changed
Context menu Drag and drop
© SAP AG 1999
The Simple Tree has y Events that are triggered by mouse operations on nodes y Events that are triggered by drag and drop operations y 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 28-20
Constructor, Methods, and Events: Column Tree
Introduction:Tree Treecontrols controlsand andtheir theirattributes attributes Introduction: Constructor,methods, methods,and and events events Constructor, SimpleTree Tree Simple ColumnTree Tree Column ListTree Tree List Creatingaahierarchy hierarchy Creating Datahandling handling strategies strategies Data Itemtables tables Item © SAP AG 1999
(C) SAP AG
BC412 28-21
Column Tree: Constructor Container reference Node selection:
( Single node (node_sel_mode_single) 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 ...
( Multiple nodes (node_sel_mode_multiple) Highlight selected nodes: = = = = = = = =
( ' ' : Yes ( 'X' : No Column items can be selected: ( 'X' : Yes ( ' ' : No Column name in hierarchy area Heading in hierarchy area (structure with 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): y Whether single items can be selected (parameter item_selection) y Technical name of the column to be displayed in the hierarchy area y The heading for the hierarchy area (text and displayed length)
(C) SAP AG
BC412 28-22
Column Tree: Method Overview Changing attributes Creating, changing, and deleting column items and nodes Column items Nodes Columns Setting up keyboardkeyboard-triggered events Other methods Finding out attributes Nodes 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: y Columns y Items y 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 28-23
Column Tree: Overview of Modifying Methods Column items Change individual items Select individual items Nodes Expanding
Method overview
Selecting Deleting Changing the attributes Columns Specifying the sequence Inserting, changing, deleting Change column attributes Hierarchy heading: Changing 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: y Changing the column sequence y Inserting, changing, and deleting columns y Changing column attributes y Changing the attributes of the hierarchy heading
(C) SAP AG
BC412 28-24
Column Tree: Event Overview
Nodes 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: y Mouse click on a column heading y Events on items - Keyboard event for selected items - Pushbutton event for item type pushbutton - Click on a link - Click on 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 28-25
Constructor, Methods, and Events: List Tree
Introduction:Tree Treecontrols controlsand andtheir theirattributes attributes Introduction: Constructor,methods, methods,and and events events Constructor, SimpleTree Tree Simple ColumnTree Tree Column ListTree Tree List Creatingaahierarchy hierarchy Creating Datahandling handling strategies strategies Data Itemtables tables Item © SAP AG 1999
(C) SAP AG
BC412 28-26
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 ... © SAP AG 1999
Highlight selected nodes:
( ' ' : Yes ( 'X' : No List items can be selected: ( 'X' : Yes ( ' ' : No Use column headings ( 'X' : Yes ( ' ' : No Heading in hierarchy area (structure with type treev_hhdr) Heading in list area (structure with type treev_lhdr)
The List Tree allows you to set headings for the hierarchy area and the list area.
(C) SAP AG
BC412 28-27
List Tree: Method Overview Changing attributes Creating, changing, and deleting list items and nodes List items Nodes Hierarchy heading List heading Setting up keyboardkeyboard-triggered events Other methods Finding out attributes Nodes 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
List Tree: Overview of Modifying Methods List items Change individual items Select individual items Nodes
Method overview
Expanding Selecting Deleting Changing the attributes
© SAP AG 1999
Since the List Tree displays its additional node information in a list instead of columns, it does not have the methods that apply to columns that the Column Tree has.
(C) SAP AG
BC412 28-29
List Tree: Event Overview
Nodes 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 28-30
SAP Tree Control Overview: Creating a Hierarchy
Introduction:Tree Treecontrols controlsand andtheir theirattributes attributes Introduction: Constructor,methods, methods,and and events events Constructor, Creatingaahierarchy hierarchy Creating Datahandling handling strategies strategies Data Itemtables tables Item
© SAP AG 1999
(C) SAP AG
BC412 28-31
Simple Tree: Control Data
Tree Control Data for display DATA: itab TYPE TABLE OF struc.
Packet of data 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 (itab) Structure in 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 control 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 28-32
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 thef rontend) 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: Node (folder) can have child nodes 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 28-33
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 child node of the reference node, or as the last child node. You can use the following static constants with the relatship field: y cl_tree_control_base=>relat_first_child y cl_tree_control_base=>relat_last_child
(C) SAP AG
BC412 28-34
Node Relationships (2) relatkey
relatship
before
node_key
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: y cl_tree_control_base=>relat_prev_sibling y cl_tree_control_base=>relat_next_sibling
(C) SAP AG
BC412 28-35
Node Relationships (3) relatkey
relatship
before
node_key
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: y cl_tree_control_base=>relat_first_sibling y cl_tree_control_base=>relat_last_sibling
(C) SAP AG
BC412 28-36
Passing the Node Table to the Frontend
node_text_01 node_text_12 node_text_11 node_text_10 SAP GUI
add_nodes ABAP program node_01
...
node_text_01
node_10
node_01
first_child
...
node_text_10
node_11
node_01
first_child
...
node_text_11
node_12
node_01
first_child
...
node_text_12
node_ node_key
relatkey
relatship
...
text
Node table
© SAP AG 1999
You should note the following points when constructing a node table: y The entries in the node table are processed at the frontend in the order in which they appear in the internal table (that is, the order in which you filled the table). y This means that the reference node relatkey for a given node node_key must already be declared at the frontend. If you send the reference node to the frontend in the same data packet as the new node, it must occur before the new node in the node table. y For the top-level root node, you must leave the fields relatkey and relatship empty. y The relationships specified in the node table are not absolute; they only apply to that particular row of the table.
(C) SAP AG
BC412 28-37
SAP Tree Control Overview: Data Handling Strategies
Introduction:Tree Treecontrols controlsand andtheir theirattributes attributes Introduction: Constructor,methods, methods,and and events events Constructor, Creatingaahierarchy hierarchy Creating Datahandling handling strategies strategies Data Itemtables tables Item
© SAP AG 1999
(C) SAP AG
BC412 28-38
Sending Data on Request From the User Tree Control (Frontend)
ABAP program + Basis services
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: y 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'. y If the data has already been sent to the frontend, the control can expand the folder itself.
(C) SAP AG
BC412 28-39
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, but you must ensure, even if it is longer, that there is a 11 relationship between the application keys and the node keys.
(C) SAP AG
BC412 28-40
Tree Events and Node Keys Nodes node_double_click node_keypress expand_no_children selection_changed
Tree Control Data for display event Node Keys
Column items item_double_click item_keypress button_click ABAP program link_click checkbox_change
Convert key for application data
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 28-41
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 28-42
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 28-43
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
'node_key'
htab1 htab2 insert_node delete_node get_business_key get_node_key ...
htab1: Hash table with key: business_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 in parallel. The advantage of a hash table 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 28-44
Example: Flight Bookings Tree
Flight booking hierarchy cl_gui_simple_tree Data Methods expand_no_children node_double_click
lcl_mapping Data for key mapping Methods
lcl_flight_info_tree Flight booking and auxiliary data
( 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
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 local 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 it 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 all tree events 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 28-45
Example: Using the Flight Booking Tree (1): Modularization
lcl_event_handler on_node_double_click o1: cl_bc412_flight_info_tree1 Flight booking data
Auxiliary data
Methods that publish information about flight data externally node_double_click
o2: cl_gui_docking_container
0100: Screen Screen data
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 28-46
Example: Using the Flight Booking Tree (1): Screen Structure Flight information system Airline American Airlines 0017 New York --> San Francisco 0046 San Francisco --> New York Air Canada Air France
Flight Information System
Custom Control area displaying flight booking tree (SCARR, SPFLI, SFLIGHT, SBOOK)
Detail information Airline ID Airline 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: y Flight booking tree on the left y 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 control. The detail screens are implemented as screens. There is one screen for each database table. The screens corresponding to the user's node selection is displayed on the right side (the docking container control is re-linked).
(C) SAP AG
BC412 28-47
Example: Using the Flight Booking Tree (1): Control Flow Tree Control
flight_info_tree
my_application
Screen
Expand node that has information Expand node with no information
expand_no_children
Send data
Double-click on node
Read and buffer data
node_double_click Get business key node_double_click Find out detail info.
Analyze key (table)
Send detail info. PBO 100 © SAP AG 1999
The diagram illustrates the control flow when the user interacts with the Tree Control at the frontend.
(C) SAP AG
BC412 28-48
Example: Using the Flight Booking Tree (2):
Flight Information System
Custom Control area displaying flight booking tree (SCARR, SPFLI, SFLIGHT)
Detail Information
Doubleclick
Custom Control area displaying Booking list in an ALV Grid Control
Same functions:
Features:
( Hierarchical display ( Data retrieval on
( Booking list displayedfor
request from user ( Data managment (SCARR, SPFLI, SFLIGHT)
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: y A flight booking tree on the left containing nodes for the tables SCARR, SPFLI, and SFLIGHT. y 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 doubleclicking it.
(C) SAP AG
BC412 28-49
SAP Tree Control Overview: Item Tables
Introduction:Tree Treecontrols controlsand andtheir theirattributes attributes Introduction: Constructor,methods, methods,and and events events Constructor, Creatingaahierarchy hierarchy Creating Datahandling handling strategies strategies Data Itemtables tables Item
© SAP AG 1999
(C) SAP AG
BC412 28-50
Sending Column or List Items
Tree Control or
Data for display
DATA: item_itab TYPE TABLE OF struc.
Data packet for display + display info.
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 a further 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 28-51
Line Structure of the Item Table treev_item
SAP structure treev_item
text
Structure in the ABAP Dictionary
Freely-defined text field Line structure for node attributes
Node name (must be unique at the frontend) node_key item_name Item name Type of entry: Text, checkbox, pushbutton, link class disabled Flag: Item cannot be selected yes/no Flag: Item can be changed yes/no editable hidden Flag: Entry invisible yes/no Alignment (List Tree only) alignment t_image Icon name Flag: Checkbox is selected yes/no chosen togg_right Obsolete Flag: Do not add width of icons and checkbox field Y/N ignore_imag List Tree only: Flag for background color of an item usebgcolor 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: y item_class_text y item_class_checkbox y item_class_button y item_class_link.
(C) SAP AG
BC412 28-52
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 28-53
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 28-54
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 = '1'
node_key = 'Node3' item_name = '2'
© 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 28-55
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 28-56
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 for a simple tree. SAPSIMPLE_TREE_CONTEXT_MEN_DEM: Example program for using context menus with a simple tree. SAPCOLUMN_TREE_CONTROL_DEMO: Example program for implementing a column tree. SAPTLIST_TREE_CONTROL_DEMO: Example program for implementing a list tree. SAPTLIST_TREE_CONTROL_DEMO_HDR: Example program for implementing a list tree with headings. SAPSIMPLE_TREE_DRAG_DROP_DEMO: Example program for drag and drop operations with a tree control. It uses two simple tree contorl instances with single line selection. RSDEMO_DRAG_DROP_TREE_MULTI: Example program for drag and drop operations in Tree Control applications using multiple selection. RSDEMO_DRAG_DROP_EDIT_TREE: Example for drag and drop operations between a Tree Control and a Textedit Control.
(C) SAP AG
BC412 28-57
SAP Tree Control: Unit Summary
You are now able to: z Describe the features of the different tree control variants:
Attributes
Methods
Events
z Display data in a tree control:
Create hierarchies
Use additional information (items)
© SAP AG 1999
(C) SAP AG
BC412 28-58
ALV Grid Control
Contents: z Features z Constructor, methods and events z Data descriptions
© SAP AG 1999
(C) SAP AG
BC412 29-1
ALV Grid Control: Unit Objectives
At the conclusion of this unit, you will be able to: z Describe the features of the ALV Grid Control z Display list data in the ALV Grid Control z Read and change properties of the ALV Grid Control z Format print lists with the ALV Grid Control z Generate a field catalog
© SAP AG 1999
(C) SAP AG
BC412 29-2
ALV Grid Control Overview: Features
Features Features Method overview overview Method Eventoverview overview Event Thefield fieldcatalog catalog The
© SAP AG 1999
(C) SAP AG
BC412 29-4
ALV Grid Control
Properties ( Display of nonhierarchical lists
( Typical list functions: Air... Flight.. Date Curr... Price 17 2000-01-17 513,69 USD AA 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 29-5
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: y 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. y 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). y Sort in descending order: This function is analogous to Sort in ascending order. y Find: You can determine a search term and the search order (columns or rows). y 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). y Total: The system calculates totals for the columns selected. y Subtotal: This function is analogous to Total. (Note: You can only display subtotals if totals are calculated). y Print: The options available are Print (print dialog ->Print) and Print preview. y Export: The options available are Spreadsheet, Word processing, Local file, Send, Office and ABC Analysis. y Display variants: The functions available are Choose display variant, Change display variant, and Manage display variant.
(C) SAP AG
BC412 29-6
Features Overview: Technical View
Features Features Technical view view Technical Screen and andprint printlist list Screen Method overview overview Method Eventoverview overview Event Thefield fieldcatalog catalog The
© SAP AG 1999
(C) SAP AG
BC412 29-7
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: y Frontend Grid Control: Display of the list data as a table y ABAP program: User y 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 29-8
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 29-9
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
( 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
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 29-10
ALV Grid Control: The Field Catalog
ALV Grid Control
Printer/spool
Frontend
Application server
ALV proxy object
ABAP program List data
Field catalog
© SAP AG 1999
The field catalog is dealt with in more detail in the following.
(C) SAP AG
BC412 29-11
Additional info
Functions of the Field Catalog
ALV Grid Control / print list
Pr s tie
Co nt en t
er op
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
20000312 . . . ... ...
fldate
Properties of column fldate
...
Properties of column . . .
Properties of column connid
© 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 29-12
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 29-13
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 Formatting of column contents
For details, see the section on the field catalog
Texts Technical column properties Other fields
© SAP AG 1999
Row type LVC_S_FCAT contains the following information: y Column indicator (names of the fields, names of the reference fields in the ABAP Dictionary, ...) y Formatting options for currency and quantity fields y Output properties of the columns (order, ...) y Formatting of the column contents (decimal place formatting, ...) y Texts for column headers, detail screens and output in hotspot format y Technical column properties y Other fields For more detailed information, see the section The field catalog of this unit.
(C) SAP AG
BC412 29-14
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 29-15
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: y Layout information - For the frontend control - For the print list y Information that contains the display rules for the data to be output - Sort criteria - Filter criteria - Texts for field groups
(C) SAP AG
BC412 29-16
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: y 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. y Layout of the print list: - You can use the fields of a structure to control parts of the list layout. y 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 29-17
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: y General display options (optimize column width, title size, ...) y Grid customizing (horizontal/vertical gridlines on/off, use column headers, ...) y Totals options (totals display before single records, ...) y Exception handling (use traffic light symbols, ...) y Interactive control (properties of the detail screen, ...) y Drag&Drop settings y Colors (print lists with striped pattern, ...) For more details, see the online documentation.
(C) SAP AG
BC412 29-18
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 29-19
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 29-20
Features Overview: Screen/Print List
Features Features Technical view view Technical Screen and andprint printlist list Screen Method overview overview Method Eventoverview overview Event Thefield fieldcatalog catalog The
© SAP AG 1999
(C) SAP AG
BC412 29-21
Screen Layout of the ALV Grid Control
Toolbar List header
Toolbar
( Functions can be hidden ( Pushbuttons and menu options can be added
( Functions are triggered as events
Data display area (grid)
List header ( Optional ( Single-line Data area
( Further structured
© SAP AG 1999
The ALV Grid Control screen consists of three areas: y 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. y Below the toolbar, you can display a single-line list header. y Below the header is the area in which the list data is displayed (data area).
(C) SAP AG
BC412 29-22
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 on setting): - Single cells - Entire rows/columns ( Column headers can be used ( Gridlines can be shown/ hidden ( Context menus ( Drag&Drop ( ... Selection keys (optional)
Area for key columns (fixable)
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 29-23
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: y 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. y 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 29-24
ALV Grid Control Overview: Method Overview
Features Features Method overview overview Method Eventoverview overview Event Thefield fieldcatalog catalog The
© SAP AG 1999
(C) SAP AG
BC412 29-25
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 29-26
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: y Elementary methods y Methods for changing/reading the properties of the Grid Control y Methods for changing/reading the layout y Methods for operations on filter criteria, sort criteria, and variants y Methods for event handling and function code handling y Methods for connecting the control to the report-report interface For details on methods and interfaces, see the online documentation.
(C) SAP AG
BC412 29-27
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: y The constructor y Method set_table_for_first_display y Method refresh_table_display.
(C) SAP AG
BC412 29-28
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: ( ' ' : Yes ( 'X' : No
© SAP AG 1999
Optional parameters are shown as (ABAP) comments.
The constructor for ALV Grid Control instances has four interface parameters: y i_shellstyle: You use this parameter to determine the general appearance of the control (for details, see the online documentation). y i_lifetime: You use this parameter to influence the lifetime of the frontend control. Possible values are: lifetime_imode (default), lifetime_dynpro (for details, see the online documentation). y i_parent: You use this parameter to pass a container reference. y i_appl_events: You use this parameter to determine if all events of your ALV Grid Control instance should be registered as system events (default) or as application events (value 'X'). The proxy object registers the ALV controls at the Control Framework.
(C) SAP AG
BC412 29-29
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 29-30
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 29-31
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 =
Select, change and save current display variant
is_variant i_save i_save i_save
= = = =
DATA:
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: y The user can change the current display variant: To set this mode, you set both parameters to SPACE (default value). y 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. y 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 29-32
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: y Cells y Scroll bars y Columns y Rows The methods for the layout and the structure information can be subdivided as follows: y Methods for the field catalog y Methods for the layout y Methods for the general control layout (frames) For details on the method names and the interfaces, see the online documentation.
(C) SAP AG
BC412 29-33
ALV Grid Control Overview: Event Overview
Features Features Method overview overview Method Eventoverview overview Event Thefield fieldcatalog catalog The
© SAP AG 1999
(C) SAP AG
BC412 29-34
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
UserUser-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: y Events that mark a specific point during print list creation y Events for mouse operations - Double-clicks on a cell - Click on a hotspot of a cell y Events that allow you to - Execute implementations for self-defined functions - Change the process flow of the standard functions y Events for context menus y Events for Drag&Drop operations For details on the event names and interfaces, see the online documentation.
(C) SAP AG
BC412 29-35
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 self-defined 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 29-36
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 29-37
ALV Grid Control Overview: The Field Catalog
Features Features Method overview overview Method Eventoverview overview Event Thefield fieldcatalog catalog The
© SAP AG 1999
(C) SAP AG
BC412 29-38
Recap: Functions of the Field Catalog
ALV Grid Control / print list
Pr s tie
Co nt en t
er op
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
20000312 . . . ... ...
fldate
Properties of column fldate
...
Properties of column . . .
Properties of column connid
© 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 29-39
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 29-40
Field Catalog Overview: Information in the Field Catalog in Detail
Features Features Method overview overview Method Eventoverview overview Event Thefield fieldcatalog catalog The Informationin inthe thefield fieldcatalog catalogin indetail detail Information Generatingthe thefield fieldcatalog catalog Generating © SAP AG 1999
(C) SAP AG
BC412 29-41
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 Entries in the field catalog
Internal table itab with data carrid . . . seatsfree . . . AA AZ LH QA
... ...
12 . . . 30 . . .
... ...
70 . . . 0 ...
fieldname
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 29-42
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: y 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. y 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. y If a value is assigned to the field currency, entries in the field cfieldname are ignored. Unit of measure formatting: y 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. y 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. y 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 29-43
Example: Currency Formatting
Entries in the field catalog
Internal table itab with data carrid . . . ... AA AZ ...
... ...
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 29-44
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: y 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, ...). y 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 29-45
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 29-46
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 29-47
Field Catalog: Technical Column Properties
Used for fields without
reference to ABAP Dic tionary types
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 29-48
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 29-49
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. y The field fieldname contains the column name. y The fields ref_field and ref_table establish the relationship to any global types (fields of structures in the ABAP Dictionary). y All of the other fields contain values for the attributes of the columns.
(C) SAP AG
BC412 29-50
Field Catalog Overview: Generating the Field Catalog
Features Features Method overview overview Method Eventoverview overview Event Thefield fieldcatalog catalog The Informationin inthe thefield fieldcatalog catalogin indetail detail Information Generatingthe thefield fieldcatalog catalog Generating © SAP AG 1999
(C) SAP AG
BC412 29-51
Generating the Field Catalog 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
List data
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 (semiautomatic 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 29-52
Fields of a Single Dictionary Structure Internal table it_data with list data Row type: SFLIGHT AA
...
300
USD
AZ ...
... ...
7000 ...
ITL ...
SFLIGHT
SPFLI ABAP Dictionary
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 29-53
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: y Declare an internal table for the field catalog DATA: it_fcat TYPE lvc_t_fcat. y 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. y 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. y The proxy object then generates a full field catalog.
(C) SAP AG
BC412 29-54
Fields of Several Dictionary Structures ABAP Dictionary
Field catalog it_fcat Column
SFLIGHT
SPFLI
fill
CARRID CONNID FLDATE DEPTIME CITY_F CITY_T ...
DDIC Relation SFLIGHT SFLIGHT SFLIGHT SPFLI CITYFROM SPFLI SPFLI CITYTO ...
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: y Declare an internal table for the field catalog: DATA: it_fcat TYPE lvc_t_fcat. y 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. y 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. y The proxy object then creates the full field catalog.
(C) SAP AG
BC412 29-55
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: y Declare an internal table for the field catalog: DATA: it_fcat TYPE lvc_t_fcat. y 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). y 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. y 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. y The proxy object then generates the full field catalog.
(C) SAP AG
BC412 29-56
Fields With Local Types Only Field catalog it_fcat fill Local ABAP types
Cn
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: y Declare an internal table for the field catalog: DATA: it_fcat TYPE lvc_t_fcat. y 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. y 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 29-57
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 29-58
ALV Grid Control: Unit Summary
Now you are able to: z Describe the features of the ALV Grid Control z Display list data in the ALV Grid Control z Read and change properties of the ALV Grid Control z Format print lists with the ALV Grid Control z Generate a field catalog
© SAP AG 1999
(C) SAP AG
BC412 29-59
Appendix
Contents: z Information about the global classes used in BC412 z Table of contents
© SAP AG 1999
(C) SAP AG
BC412 30-1
Information on the Global Classes of BC412 Content 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.
Overview 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
BC412 31-2
5.
4.2.6
The Method GET_SBOOK_DETAILS
4.2.7
The Method GET_SCUSTOM_DETAILS
4.2.8
The Event NODE_DOUBLE_CLICK
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
Global Class CL_BC412_PICTURE_1
General 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.
Interface 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.
The Method Constructor The constructor has the following interface: CREATE OBJECT object EXPORTING
(C) SAP AG
BC412 31-3
i_parent
= variable_1
i_url
= variable_2
i_picture_click
= variable_3
i_appl_event_pc
= variable_4
i_stretch_text
= variable_5
i_fit_text
= variable_6
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
(C) SAP AG
BC412 31-4
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
The 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.
The 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.
Context 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.
(C) SAP AG
BC412 31-5
Definition 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 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
(C) SAP AG
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)
TYPE bc412_text1 DEFAULT 'X'
BC412 31-6
value(i_stretch_text)
TYPE gui_text DEFAULT 'STRETCH'
value(i_fit_text)
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 *---------------------------------------------------------------------PROTECTED SECTION.
*" instance attributes DATA: context_menu_ref TYPE REF TO cl_ctmenu , picture_ref
TYPE REF TO cl_gui_picture ,
url
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
(C) SAP AG
BC412 31-7
IMPORTING fcode sender .
Implementation 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 = 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
(C) SAP AG
BC412 31-8
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
= 1
cntl_system_error
= 2
illegal_event_combination = 3. IF sy-subrc NE 0. *
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.
(C) SAP AG
BC412 31-9
" 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. *---------------------------------------------------------------------------------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.
(C) SAP AG
BC412 31-10
* 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'. 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.
(C) SAP AG
BC412 31-11
*
IF sy-subrc NE 0.
*
RAISE error.
*
ENDIF.
ENDMETHOD.
Global Class CL_BC412_MAPPING_4_2_TREE
General 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.
Interface 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).
The Method INSERT_BUSINESS_KEY The method creates a node key for the application key passed. CALL METHOD inset_business_key EXPORTING i_bkey1 = variable1 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: (C) SAP AG
BC412 32-12
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
The Method DELETE_BUSINESS_KEY The method DELETE_BUSINESS_KEY has one predefined interface (sample), but no implementation (which must be added as required).
The Method DELETE_TECHNICAL_KEY The method DELETE_TECHNICAL_KEY has one predefined interface (sample), but no implementation (which must be added as required).
The 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
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
(C) SAP AG
Third key component of the application key BC412 32-13
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.
The 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.
Definition of the Class *---------------------------------------------------------------------* *
CLASS CL_BC412_MAPPING_4_2_TREE
DEFINITION
*---------------------------------------------------------------------* *
........
*
*---------------------------------------------------------------------* CLASS cl_bc412_mapping_4_2_tree DEFINITION
(C) SAP AG
BC412 32-14
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
(C) SAP AG
BC412 32-15
value(e_bkey3) TYPE s_date 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
(C) SAP AG
BC412 32-16
DATA: map1 TYPE bc412_map_hash1 , map2 TYPE bc412_map_hash2 .
*---------------------------------------------------------------------*" private components of class CL_BC412_MAPPING_4_2_TREE *---------------------------------------------------------------------PRIVATE SECTION. *" instance attributes DATA: counter TYPE i .
Implementation 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.
(C) SAP AG
BC412 32-17
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. 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.
(C) SAP AG
BC412 32-18
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.
*----------------------------------------------------------------------
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.
Global Class CL_BC412_FLIGHT_INFO_TREE1
General 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.
Interface The class has: (C) SAP AG
BC412 33-19
•
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.
The 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 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
= variable_6
i_level_no
= 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.
(C) SAP AG
BC412 33-20
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_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
The Method FREE The method FREE is used to release all resources used by the instantiated control at the frontend.
The 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.
The 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. (C) SAP AG
BC412 33-21
The 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.
The 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.
The 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.
The 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)
Data, 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.
Definition of the Class *" type-pools TYPE-POOLS: cntl .
(C) SAP AG
BC412 33-22
*---------------------------------------------------------------------* *
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
TYPE bc412_text1
VALUE 'X' ,
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) *" methods METHODS: constructor
(C) SAP AG
BC412 33-23
TYPE bc412_level OPTIONAL .
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)
TYPE bc412_text1
value(i_level_no)
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 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
(C) SAP AG
BC412 33-24
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 DATA: it_scarr
TYPE bc412_scarr_itt ,
it_spfli
TYPE bc412_spfli_itt ,
it_sflight
TYPE bc412_sflight_itt ,
it_sbook
TYPE bc412_sbook_itt ,
it_scustom
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
(C) SAP AG
BC412 33-25
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 , *---------------------------------------------------------------------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
(C) SAP AG
BC412 33-26
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 .
Implementation 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
= ' '
EXCEPTIONS lifetime_error
= 1
cntl_system_error
= 2
create_error
= 3
illegal_node_selection_mode = 4 failed IF sy-subrc NE 0. RAISE tree_create_error. ENDIF.
(C) SAP AG
BC412 33-27
= 5.
* 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. 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.
(C) SAP AG
BC412 33-28
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 fldate = i_fldate. IF sy-subrc NE 0. RAISE no_data_found. ENDIF.
(C) SAP AG
BC412 33-29
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
= ' '.
" ' ' = visible, 'X' = invisible
wa_node-disabled
= 'X'.
" node is not selectable
wa_node-isfolder
= 'X'.
(C) SAP AG
BC412 33-30
wa_node-n_image
= ' '.
" use default icon (closed folder)
wa_node-exp_image
= ' '.
" use default icon (expand folder)
wa_node-style
= 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
= 1
failed
= 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.
(C) SAP AG
BC412 33-31
*
test for ROOT (special case) 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 IF sy-subrc NE 0.
(C) SAP AG
BC412 33-32
= 2.
*
open to implement ENDIF. ELSEIF mapping-fldate IS INITIAL.
" expand connection node " -> i_sflight
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
(C) SAP AG
BC412 33-33
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 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.
(C) SAP AG
BC412 33-34
*----------------------------------------------------------------------
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 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
= ' '.
" use default icon (expand folder)
wa_node-style
= 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 = .
(C) SAP AG
BC412 33-35
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 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
= 1
failed
= 2
dp_error
= 3
table_structure_name_not_found = 4. IF sy-subrc NE 0. RAISE node_add_error. ENDIF. ENDMETHOD.
(C) SAP AG
BC412 33-36
*----------------------------------------------------------------------
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
TYPE SORTED TABLE OF spfli 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
= ' '.
" use default icon (expand folder)
wa_node-style
= 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
(C) SAP AG
= 'X'.
BC412 33-37
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.
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.
INSERT wa_spfli INTO TABLE it_spfli.
" fill node table " 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
= 1
failed
= 2
(C) SAP AG
BC412 33-38
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, * 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
(C) SAP AG
BC412 33-39
wa_node-isfolder
= 'X'.
wa_node-n_image
= ' '.
" use default icon (closed folder)
wa_node-exp_image
= ' '.
" use default icon (expand folder)
wa_node-style
= 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 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.
(C) SAP AG
" no free seats
BC412 33-40
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.
INSERT wa_sflight INTO TABLE it_sflight.
" fill node table " 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
= 1
failed
= 2
dp_error
= 3
table_structure_name_not_found = 4. IF sy-subrc NE 0. RAISE node_add_error. ENDIF. ENDMETHOD.
*----------------------------------------------------------------------
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,
(C) SAP AG
BC412 33-41
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
= ' '.
" ' ' = visible, 'X' = invisible
wa_node-disabled
= ' '.
" node is selectable
wa_node-isfolder
= ' '.
wa_node-n_image
= ' '.
" use default icon (closed folder)
wa_node-exp_image
= ' '.
" use default icon (expand folder)
wa_node-style
= cl_gui_simple_tree=>style_default.
*
wa_node-last_hitem = .
*
wa_node-no_branch
= .
IF level_no = c_level_4. wa_node-expander
= ' '.
ELSE.
(C) SAP AG
BC412 33-42
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.
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. wa_prev_node = wa_node. ENDLOOP. CALL METHOD o_simple_tree->add_nodes
(C) SAP AG
BC412 33-43
" fill global data table
EXPORTING table_structure_name = 'BC412_SIM_TREE_NODE_STRUC' node_table
= node_table
EXCEPTIONS error_in_node_table
= 1
failed
= 2
dp_error
= 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. IF sy-subrc EQ 0.
*
read new customers SELECT * FROM scustom
(C) SAP AG
BC412 33-44
" new customers to read
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.
Global Data Types Used in the ABAP Dictionary
Table Types BC412_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
BC412_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 34-45
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.
BC412_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.
BC412_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.
BC412_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).
BC412_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.
BC412_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.
BC412_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.
BC412_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 34-46
Structure Types BC412_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).
Data 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 34-47
Workbench Edition – Controls Technology Overview 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.
About 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.
Target 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.
Features 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
Content 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 34-53
How 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.
How to Order. SAP Partners and Customers Outside Europe You can order Controls Technology online at www.fatbrain.com
Karl Kessler
(C) SAP AG
BC412 34-54