Beruflich Dokumente
Kultur Dokumente
Demonstration
Exercises HelpMe
5
India SAP CoE, Slide 2
Demonstration
Exercises HelpMe
5
India SAP CoE, Slide 3
Introduction
ALV: Object Oriented way CL_GUI_ALV_GRID
Purpose
Use
Challenges
Introduction
Purpose The ALV Grid control is a flexible tool for displaying lists & provides common list operations as generic functions and can be enhanced by selfdefined options. Purpose of this Tutorial is to demonstrate how to implement ALV using Classes CL_GUI_ALV_GRID and CL_GUI_CUSTOM_CONTAINER
Introduction
Use used to build non-hierarchical, interactive, and modern-design lists. provides typical list functions as sorting, filtering, summing, while also gives the opportunity to develop user functions where needed. It presents numerous interfaces like Excel Inplace and Crystal Reports.
Introduction
Challenges To use ALV Grid Control in a simple manner, sufficient just having experience on dialog programming. However, to make use of more capabilities, it is required some knowledge on object-oriented perspective of ABAP programming & control framework
Demonstration
Exercises HelpMe
5
India SAP CoE, Slide 8
Custom Controls
Custom control is: an area on a screen used to embed controls are software components of the presentation server control is driven by the application logic, which still runs on the application server have a wrapper class in ABAP Objects
Control Framework
The controls on the presentation server and the ABAP application programs on the application server communicate using the SAP Control Framework
India SAP CoE, Slide 11
Container Controls
Before you can work with a custom control on a screen, you must assign a Container Control to it. Container controls are instances of special global classes (global class for custom controls is called CL_GUI_CUSTOM_CONTAINER). To link a custom control to a container control, pass the custom control name to the constructor of the container control when you instantiate it using CREATE OBJECT.
India SAP CoE, Slide 12
with the instance on the presentation server, along with many other functions. For this reason, you should instantiate this class, not its super class.
India SAP CoE, Slide 14
CL_GUI_ALV_GRID class provides various methods. Go to SE24 and explore the various methods provided by this class.
India SAP CoE, Slide 15
CL_GUI_ALV_GRID class provides various events. All the supported events can be viewed under Events Tab
Demonstration
Exercises HelpMe
5
India SAP CoE, Slide 18
Create a screen. Go to Screen Layout & Add a custom control on the screen. Give it a name say CC_ALV
1. Create instance reference for creating instances of class CL_GUI_ALV_GRID and Custom Container CL_GUI_CUSTOM_CONTAINER. 2. Field Catalog Internal Table will of type LVC_T_FCAT 3. Layout will be of type LVC_S_LAYO 4. Internal Table to hold List Data that is to be displayed as ALV
India SAP CoE, Slide 20
We will now add a PBO Module Display_alv. This routine will have the code for: Instantiating the Custom Control & ALV Grid Populating the Field Catalog & Layout Calling the appropriate method of class CL_GUI_ALV_GRID to display the ALV Grid output
India SAP CoE, Slide 21
Instantiate the Container. Pass the name of the Custom Control we defined in the Screen 9000 above
As we are using the concept of Classes, we will now create instance of the Custom Container. Use the Pattern > ABAP Objects > Create Object > Specify the Instance name as the one we specified in the Data Definition Step.
India SAP CoE, Slide 22
Instantiate the ALV Grid. Pass the Container (instance of which we created in the previous slide)
We will now create instance of the ALV Grid. Again use the Pattern > ABAP Objects > Create Object > Specify the Instance name as the one we specified in the Definition Step (type ref to CL_GUI_ALV_GRID) Class Name: CL_GUI_ALV_GRID
India SAP CoE, Slide 23
REF_TABLE
The work in this procedure is just filling the internal table for the field catalog. We have already seen the structure of a field catalog. To achieve filling the field catalog correctly, one must at least fill the above fields of the field catalog structure for each column of the list.
Data transfer to the ALV control takes place during the call of method SET_TABLE_FOR_FIRST_DISPLAY of class CL_GUI_ALV_GRID. The method call must be programmed at the PBO event of the screen with the SAP Grid Control container. Remember to use Pattern > ABAP Objects > Method of a Class
India SAP CoE, Slide 31
If the ALV_GRID is initial (First Call) the method SET_TABLE_FOR_FIRST_DISPLAY is called as described in the previous slide. Else on subsequent calls; REFRESH_TABLE_DISPLAY is called. Reason being; there is no need to instantiate the Custom Container, Grid every time in the PBO of the Screen. The parameters of this method: IS_STABLE: If the row or column field of this structure is set, the position of the scroll bar for the rows or columns remains stable. I_SOFT_REFRESH: If set, any totals created, any sort order defined and any filters set for the data displayed remain unchanged when the grid control is refreshed.
India SAP CoE, Slide 32
Execute the Program to test the output. The ALV Grid output is displayed as expected!!
As being developed by object-oriented methodology, ALV Grid control has some events that are triggered during interaction between the user. These events are used to utilize some additional functionalities of the ALV Grid. For these types of functionalities, we require a class to be implemented (generally local in our program) to be the event handler for the ALV Grid instance. It is assumed in this tutorial that the objectoriented perspective of ABAP programming is known.
India SAP CoE, Slide 38
SE80 > Right Click and Create Class Implementation. Give the same name as the Class Definition created above.
Having an event handler class we are now able to instantiate it and register its methods to handle ALV Grid instance events.
Create an instance & Register the event handlers. Add this in the routine after the code instantiating the Custom Container & ALV Grid. (before the method call SET_TABLE_FOR_FIRST_DISPLAY
India SAP CoE, Slide 43
We will now put the handler code (what we want to do when the event is raised?) inside the appropriate event handler method.
Use the event toolbar to add the button and the event user_command to implement the new function. In the method handling the toolbar event, we define a new button by filling a structure and appending it to the table attribute mt_toolbar of the object to whose reference we can reach via the parameter e_object of the event.
India SAP CoE, Slide 45
Step 1 Split the screen into two parts using the splitter container and then use the first part to TOP_OF_PAGE and the second one to show the Grid data. Create the Top document object Create Splitter for Custom Container Assigning Part 1 for TOP_OF_PAGE Assigning the Part 2 to ALV GRID (using method GET_CONTAINER) Step 2 Have a local class inside the report to handle the TOP_OF_PAGE event Step 3 Use of methods ADD_TEXT, ADD_PICTURE, ADD_GAP.
Add the Method to handle event TOP_OF_PAGE in Local Class Definition Implement Method as event handler for TOP_OF_PAGE in Local Class Implementation
Use various methods provided by the Class CL_DD_DOCUMENT. Here, we have added Text & Logo
Display the document. Pass the Top as Parent parameter. GR_PARENT_TOP is Top Container where we want to display the Logo & Heading
Assign the Areas of the Screen to display Logo & Heading (Top) and ALV Display (Parent Container). Note the Row & Column Parameters passed to the Method
Create the ALV Grid instance (TYPE REF TO CL_GUI_ALV_GRID) and remember to pass the Parent Container instance (GR_PARENT_GRID)
Demonstration
Exercises HelpMe
5
India SAP CoE, Slide 61
Exercises
1. Add custom buttons to the above ALV & Implement the logic for the same in User Command Handler Routine Try out the various Layout Options Create a Report Variant (of type disvariant) Develop an ALV Report using Object-oriented methods discussed in the previous slides.
Refer the attached technical specification document
2. 3. 4.
Demonstration
Exercises HelpMe
5
India SAP CoE, Slide 63
HelpMe
HelpMe
Additional Info:
NEW ALV OBJECT MODEL: Usage of Service Class CL_SALV_TABLE for ALV Display. Refer to SAP Knowledge Warehouse (help.sap.com) for more information. http://help.sap.com/saphelp_nw04/helpdata/en/f9/1ab54099de3726e1000 0000a1550b0/frameset.htm The new object model of the SAP List Viewer (ALV) is an object-oriented encapsulation of the ALV tool that already exists. Simple, two-dimensional table Hierarchical-sequential list Tree structure
Create an Instance reference to Service Class Cl_SALV_TABLE
HelpMe
Additional Info: (NEW ALV OBJECT
SE24 Check the Methods supported MODEL)by the Class Cl_SALV_TABLE
HelpMe
Additional Info: (NEW ALV OBJECT MODEL)
SE80 > Check the SALV Package and the Various Classes it includes