|
|
|
|
|
|
| An |
| |
| Easy Reference |
| for |
| ALV GRID CONTROL |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| Serdar SIMSEKLER |
| 2004, Ankara TURKEY |
| |
| |
| © Copyright 2003 SAP AG. All rights reserved. |
| |
| No part of this publication may be reproduced or transmitted in any form or for any purpose |
| without the express permission of SAP AG. The information contained herein may be |
| changed without prior notice. |
| |
| Some software products marketed by SAP AG and its distributors contain proprietary |
| software components of other software vendors. |
| |
| Microsoft®, WINDOWS®, NT®, EXCEL®, Word®, PowerPoint® and SQL Server® are |
| registered trademarks of Microsoft Corporation. |
| |
| IBM®, DB2®, DB2 Universal Database, OS/2®, Parallel Sysplex®, MVS/ESA, AIX®, |
| S/390®, AS/400®, OS/390®, OS/400®, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, |
| Intelligent Miner, WebSphere®, Netfinity®, Tivoli®, Informix and Informix® Dynamic |
| ServerTM are trademarks of IBM Corporation in USA and/or other countries. |
| |
| ORACLE® is a registered trademark of ORACLE Corporation. |
| |
| UNIX®, X/Open®, OSF/1®, and Motif® are registered trademarks of the Open Group. |
| |
| Citrix®, the Citrix logo, ICA®, Program Neighborhood®, MetaFrame®, WinFrame®, |
| VideoFrame®, MultiWin® and other |
| Citrix product names referenced herein are trademarks of Citrix Systems, Inc. |
| |
| HTML, DHTML, XML, XHTML are trademarks or registered trademarks of W3C®, World |
| Wide Web Consortium, Massachusetts Institute of Technology. |
| |
| JAVA® is a registered trademark of Sun Microsystems, Inc. |
| |
| JAVASCRIPT® is a registered trademark of Sun Microsystems, Inc., used under license for |
| technology invented and implemented by Netscape. |
| |
| MarketSet and Enterprise Buyer are jointly owned trademarks of SAP AG and Commerce |
| One. |
| |
| SAP, SAP Logo, R/2, R/3, mySAP, mySAP.com, xApps, SAP NetWeaver , mySAP |
| Business Suite, and other SAP products and services mentioned herein as well as their |
| respective logos are trademarks or registered trademarks of SAP AG in Germany and |
| in several other countries all over the world. All other product and service names |
| mentioned are the trademarks of their respective companies. |
| |
| |
| Table of Contents |
| |
| Purpose..........................................................................................................................1 |
| Prerequisites .................................................................................................................1 |
| A. Introduction .............................................................................................................1 |
| B. Building Blocks ........................................................................................................1 |
| B.1. General Scheme..................................................................................................2 |
| B.2. Building Field Catalog .......................................................................................7 |
| B.2.1. Structure of a Field Catalog ........................................................................7 |
| B.2.2. Building Field Catalog Manually...............................................................9 |
| B.2.3. Building Field Catalog Semi-Automatically............................................10 |
| B.3. Layout Adjustments .........................................................................................12 |
| B.4. Printing Adjustments........................................................................................14 |
| B.5. Excluding Unwanted Standard Function Buttons ............................................15 |
| C. Non-Event Based Additional Functionalities .....................................................16 |
| C.1. Changing Field Catalog or Layout after First Display.....................................16 |
| C.2. Setting Sort Conditions ....................................................................................16 |
| C.3. Filtering ............................................................................................................17 |
| C.4. Making Selections ............................................................................................18 |
| C.5. Retrieving and Setting Scroll Status Info.........................................................19 |
| C.6. Coloring ............................................................................................................19 |
| C.6.1. Coloring an Entire Column .......................................................................20 |
| C.6.2. Coloring an Entire Row.............................................................................20 |
| C.6.3. Coloring Individual Cells ..........................................................................21 |
| C.7. Inserting Hyperlinks .........................................................................................22 |
| C.8. Making Fields as Dropdown Menus ................................................................23 |
| C.9. Managing variants ............................................................................................24 |
| D. Event Based Additional Functionalities ..............................................................25 |
| D.1. General Scheme for the Event Handler Class ..................................................26 |
| D.2. Hotspot Clicking ..............................................................................................28 |
| D.3. Double Clicking ...............................................................................................29 |
| D.4. Pushbuttons On The List..................................................................................29 |
| D.5. Adding Your Own Functions ...........................................................................30 |
| D.6. Overriding Standard Functions ........................................................................32 |
| D.7. Context Menus .................................................................................................32 |
| D.8. About printing..................................................................................................33 |
| D.9. Making ALV Grid Editable .............................................................................34 |
| D.10. Controlling Data Changes ..............................................................................35 |
| D.11. Linking F1 Help to Fields ..............................................................................36 |
| D.12. Linking F4 Help to Fields ..............................................................................37 |
| E. A Piece of Troubleshooting...................................................................................38 |
| TRADEMARKS .......................................................... Error! Bookmark not defined. |
| |
|
|
| Purpose |
| |
| The purpose of this tutorial is to provide an easy and quick reference that may |
| be used as a guide while coding to build lists using ALV Grid Control. Actually, there |
| is easy-to-reach information about implementing ALV Grid lists. However, it is |
| generally required to find the information sought in a quicker way. This tutorial |
| handles this, being a condensed source that can be used as a “guide.” It will not deal |
| with the technical infrastructure on which ALV lays. Some of the tables are taken |
| from the online SAP Library, which is the most trustable source about the topic. |
| Shortly, this will be a booklet summarizing major capabilities of the ALV Grid |
| Control. |
| To get deep into the ALV Grid control, you can refer to the standard SAP |
| course “BC412 – ABAP Dialog Programming Using EnjoySAP Controls” and the |
| book “Controls Technology”. Also you had better inspect demo programs. |
| Prerequisites |
| To use ALV Grid Control in a simple manner, it will be 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. A |
| general knowledge on control framework is supposed to exist. |
| |
| A. Introduction |
| Here is the definition for ALV from SAP Help: |
| “The ALV Grid control is a flexible tool for displaying lists. The tool provides |
| common list operations as generic functions and can be enhanced by self-defined |
| options.” |
| The ALV Grid control is used to build non-hierarchical, interactive, and |
| modern-design lists. As a control, it is a component that is installed on the local PC. |
| The ALV Grid control provides typical list functions as sorting, filtering, |
| summing, etc.,while also gives the opportunity to develop user functions where |
| needed. It presents numerous interfaces like Excel Inplace and Crystal Reports. |
| The wrapper class implemented to encapsulate ALV Grid functionality is |
| “CL_GUI_ALV_GRID”. There is another way to display lists with ALV utilizing |
| “REUSE_ALV...” functions. However, that way is not comprised in this tutorial. |
| |
| B. Building Blocks |
| While preparing a list to be displayed via an ALV grid control, we have some |
| basic components to prepare. These are; |
| i. List data: Obviously, this is the data in an internal table to be listed. Standard |
| ALV functions except sorting makes just read access to the list data. |
| However, sorting changes state of the internal table. The internal table |
| holding list data may be of any flat type. Deep types are only allowed |
| when set for some functionalities of ALV Grid. |
| ii. Field Catalog: We use another internal table to define specifications on how |
| the fields of our list will be displayed. This internal table is called the |
| |
|
|
| “field catalog”. The field catalog must comprise some technical and |
| additional information about display options for each column to be |
| displayed. There are three procedures to generate the field catalog as |
| “Automatic generation”, “Semi-automatic generation”, and “Manual |
| generation”. The internal table for the field catalog must be referenced to |
| the dictionary type “LVC_T_FCAT”. |
| iii. Layout Structure: We fill a structure to specify general layout options for the |
| grid. With this structure we can set general display options, grid |
| customizing, totals options, color adjustments etc... The layout structure |
| must be of type “LVC_S_LAYO”. |
| iv. Event Handler: We should define and implement an event handler class if |
| we want to handle events triggered by the ALV Grid instance. After |
| creating ALV Grid instance, we must register an instance of this event |
| handler class to handle ALV Grid events. |
| v. Additional Data: To trigger some additional features of ALV Grid we can |
| have some additional data to pass as parameters. For example, initial |
| sorting criteria, buttons to be deactivated, etc... |
| |
| B.1. General Scheme |
| Now, we can figure out a primitive scheme to prepare our ALV Grid. As a |
| control object, ALV Grid instance requires a container to be linked to the screen. |
| Generally, an instance of the class “cl_gui_custom_container” is used for this |
| purpose. Instances of some other container classes such as |
| “cl_gui_docking_container”, “cl_gui_dialogbox_container” may also be |
| used. In our example we take a custom container. To create a custom container |
| instance, we need a custom control area on the screen. |
| |
| Step 1 Add a custom control on the screen which will be related to the |
| custom container. Let’s give it the name ‘CC_ALV’. |
| Step 2 Declare global variables to be used for ALV Grid. |
| |
| |
| *-- Global data definitions for ALV |
| |
| |
| |
| *--- ALV Grid instance reference |
| |
| DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid . |
| *--- Name of the custom control added on the screen |
| |
| DATA gc_custom_control_name TYPE scrfname VALUE ‘CC_ALV’ . |
| |
| *--- Custom container instance reference |
| |
| DATA gr_ccontainer TYPE REF TO cl_gui_custom_container . |
| |
| *--- Field catalog table |
| |
| DATA gt_fieldcat TYPE lvc_t_fcat . |
| *--- Layout structure |
| |
| DATA gs_layout TYPE lvc_s_layo . |
| |
| |
| |
| |
| Code Part 1 – Global data definitions for ALV |
| |
| Step 3 Declare your internal table which is supposed to hold the list data. |
| Let’s name it “gt_list”. Here is an example declaration. |
| |

1 comments:
Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Monitor de LCD, I hope you enjoy. The address is http://monitor-de-lcd.blogspot.com. A hug.
Post a Comment