This method is called automatically if you use CREATE OBJECT to create an object of class CL_GUI_ALV_GRID . When the control is generated, it is created on the frontend and linked to a container control.

CREATE OBJECT < reference variable to CL_GUI_ALV_GRID> EXPORTING i_shellstyle = < var. of type I > i_lifetime = < var. of type I > i_parent = < ref. var. to CL_GUI_CONTAINER> i_appl_events = < var. of type CHAR01> .

The constructor method is called automatically when you instantiate the class ( create object statement). You generally pass the parameters of the method in the create object statement. Since the SAP Container is a superclass, its constructor is called indirectly when the constructor method of one of its subclasses is called. create object container exporting clsid = clsid parent = parent style = style dynnr = dynnr repid = repid container_name = container_name lifetime = lifetime autoalign = autoalign no_autodef_progid_dynnr = no_autodef_progid_dynnr exceptions cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5 lifetime_dynpro_illegal_parent = 6.

Parameters clsid parent

Description Class ID Parent of the instance, that is, the contain in which the control is to be displayed Controls the appearance and behavior of the control

Possible values


Constants from the class CL_GUI_CONTROL that begin with WS_*


Number of the screen to which you want to attach the control Report ID: Program to which you want to attach the control Name of the Custom Container defined in the Screen Painter Lifetime management parameter specifying the lifetime of the control cntl_lifetime_imode : The control remains alive for the lifetime of the internal session (that is, until a statement such as leave program or leave to transaction ). cntl_lifetime_dynpro : The control remains alive for the lifetime of the screen (that is, while it remains in the screen stack). It is not destroyed, for example, by a call screen or call transaction statement.





Automatic alignment of the container Switches off automatic definition of the program ID and screen number.

Default: None


space Program ID and screen number are used automatically (default value) Switches off automatic definition of the program ID and screen number.

ÖRNEK: Data:
cont_ k_code LIKE sy-ucomm, gt_sflight TYPE TABLE OF sflight, gt_sbook TYPE TABLE OF sbook, g_repid LIKE sy-repid, g_max type i value 100, gs_layout TYPE lvc_s_layo, on_main TYPE scrfname VALUE 'BCALVC_TOOLBAR_D100_C 1', cont_on_dialog TYPE scrfname VALUE 'BCALVC_TOOLBAR_D101_C1' , grid1 TYPE REF TO cl_gui_alv_grid, grid2 TYPE REF TO cl_gui_alv_grid, custom_container1 TYPE REF TO cl_gui_custom_container, custom_container2 TYPE REF TO cl_gui_custom_container, event_receiver TYPE REF TO lcl_event_receiver. CREATE OBJECT custom_container1 EXPORTING container_name = cont_on_main EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5. CREATE OBJECT grid1 EXPORTING i_parent = custom_container1. gs_layout-grid_title = 'Flights' (100). * allow to select multiple lines gs_layout-sel_mode = 'A'.

Methods of Class CL_GUI_ALV_GRID
CALL METHOD grid1->set_table_for_first_display EXPORTING i_structure_name = 'SFLIGHT' is_layout = gs_layout CHANGING it_outtab = gt_sflight.

Method CONSTRUCTOR set_table_for_first_display refresh_table_display

Application Generate an instance of the ALV Grid Control Display an output table in the control Refresh the data displayed in the control



Elements of the Grid Control Method get_current_cell set_current_cell_via_id get_scroll_info_via_id set_scroll_info_via_id get_selected_cells Application Get indexes and properties of a selected cell Set cursor on a specific cell Get current scroll position Set scroll position Get content and position of selected cells from frontend Select cells in the ALV Grid Control Get indexes of currently selected cells Select cells using index table Get field names of selected columns from frontend Get indexes of selected rows from frontend Select rows HTML () X X X        set_selected_cells get_selected_cells_id set_selected_cells_id get_selected_columns get_selected_rows set_selected_rows Layout and Structure Informationen Method get_frontend_fieldcatalog set_frontend_fieldcatalog get_frontend_layout set_frontend_layout set_3d_border Application Get current field catalog from frontend Set field catalog at frontend Get layout structure at frontend Set layout structure at frontend Enable/disable 3D format of ALV Grid Control border HTML      Generic Functions .

If this flag is not set. you triggered the event using method set_toolbar_interactive . HTML X set_toolbar_interactive  This event is triggered by the ALV each time the toolbar of the control needs to be regenerated. If this flag is set. . you trigger the event using method set_toolbar_interactive and write an event handler method Event parameter E_OBJECT Type Ref To CL_ALV_EVENT_TOOLBAR_SET E_INTERACTIVE Type CHAR01 Meaning The object contains only one attribute with a table for the functions of the toolbar. the event was triggered by the ALV Grid Control.Method get_filtered_entries Application Get indexes of rows that are not displayed due to a filter set Get filter properties for all columns that have a filter set currently Get values of current subtotals lines Set filter properties for columns Get sort criteria for sorted columns Set sort criteria for columns Get current layout Disallow users to assign their own layout name Use another container control for diagram display Change function code to be executed currently HTML           get_filter_criteria get_subtotals set_filter_criteria get_sort_criteria set_sort_criteria get_variant save_variant_dark set_graphics_container set_user_command Event Handling Method register_delayed_event Application Register event DELAYED_CALLBACK or DELAYED_SEL_CHANGED_CALLBACK Trigger event toolbar. To add self-defined functions to the toolbar.

Report BCALV_GRID_DEMO of development class SLIS illustrates the simplest way to call this method. sort the table by fields. Before execution. you must specify either a reference structure of the Data Dictionary or a suitable field catalog .Interfaces Method activate_reprep_interface offline Application Enable report/report interface Check if the ALV Grid Control runs without frontend handling HTML   set_table_for_first_display Use Display an output table in the ALV Grid Control instance. you can use optional parameters to load a layout. var. to CL_GUI_ALV_GRID> ->set_table_for_first_ display EXPORTING I_BUFFER_ACTIVE I_STRUCTURE_NAME IS_VARIANT I_SAVE I_DEFAULT IS_LAYOUT IS_PRINT IT_SPECIAL_GROUPS IT_TOOLBAR_EXCLUDING IT_HYPERLINK IT_ALV_GRAPHICS CHANGING IT_OUTTAB IT_FIELDCATALOG IT_SORT IT_FILTER = = = = = = = = = = = <any type ( ANY )> <string of type DD02L-TABNAME > <structure of type DISVARIANT > <var. of type CHAR01 > <var. CALL METHOD < ref. set a filter for columns and define properties of the grid control. of type CHAR01 > <structure of type LVC_S_LAYO > <structure of type LVC_S_PRNT > <internal table of type LVC_T_SGRP > <internal table of type UI_FUNCTIONS > <internal table of type LVC_T_HYPE > <internal table of type DTC_T_TC > = = = = <internal table> <internal table of type LVC_T_FCAT > <internal table of type LVC_T_SORT > <internal table of type LVC_T_FILT > . Method set_table_for_first_display must only be called a second time if the structure of the output table changes. If you want to refresh the data displayed in the output table. use method refresh_table_display . Prerequisites The output table must either be defined globally or be a public attribute of a class. In the call sequence.

If you use this parameter. sort. axis labels). In this case. 'SFLIGHT') for the data in the output table. This accelerates the display of small lists. you can then include hyperlinks in the grid. Name of the DDIC structure (for example. This table contains function codes of the toolbar that you want to hide for the lifetime of the ALV Grid Control. IS_LAYOUT Determines properties of the grid control. the field catalog can be held in a special buffer. the field catalog is generated automatically. If you specify this parameter. The function codes are constant attributes and are prefixed with MC_FC_ . On the current layout window. This means the method is always called with the same field catalog. you must at least fill field REPORT of the structure of type DISVARIANT . Settings for displaying the ALV list as a diagram (for example. This table assigns a hyperlink address (field HREF of LVC_S_HYPE ) to each handle (field HANDLE of LVC_S_HYPE ).Parameter I_BUFFER_ACTIVE Meaning Flag to be set by the application if the method call is static. you must pass a table with texts for these groups. Parameter for printing on the backend If in the field catalog the columns were grouped together with field SP_GROUP . Determines the options available to the user for saving a layout: y y y y 'X': global saving only 'U': user-specific saving only 'A': corresponds to 'X' and 'U' SPACE: no saving I_STRUCTURE_NAME IS_VARIANT I_SAVE I_DEFAULT This parameter determines if the user is allowed to define default layouts: y y 'X': Default layouts allowed (default setting) SPACE: Default layouts not allowed If default layouts are allowed and if such a layout exists and no other layout is specified in IS_VARIANT . The layout structure has nothing to do with the layout for saving filter. Using this handle. Determines the layout to be used for displaying the output table. the default layout is automatically loaded when this method is called. it is then possible to use a list box to restrict column selection to one of these groups. in particular. and column properties. The row type of the table has two fields (variables/value pairs): IS_PRINT IT_SPECIAL_GROUPS IT_TOOLBAR_EXCLUDING IT_HYPERLINK IT_ALV_GRAPHICS .

for example. for example. Use the CL_ALV_GRAPHICS_CU=>CO_PROPID_TITLE attribute. to refer to the title of the diagram. IT_OUTTAB IT_FIELDCATALOG Output table with the data to be displayed Determines the structure of the output table and the format of the data to be displayed Table with sort properties for columns that are to be sorted initially Table with filter properties for columns for which a filter is to be set initially IT_SORT IT_FILTER Events of Class CL_GUI_ALV_GRID The section Working With the ALV Grid Control describes the special points and issues you must consider when you handle events of the ALV Grid Control. User-defined Text Output Event print_end_of_list Application Define output text to be printed at the end of the entire list Define output text to be printed at the beginning of the entire list Define output text to be printed at the end of each page Define output text to be printed at the beginning of each page Define self-defined subtotals texts HTML      print_top_of_list print_end_of_page print_top_of_page subtotal_text Mouse-controlled Actions in the Grid Control Event button_click Application Query a click on a pushbutton in the ALV Grid Control HTML  . PROP_VAL : The value of the relevant topic. 'My Title'.y y PROP_ID : Assign a constant attribute of the class CL_ALV_GRAPHICS_CU with prefix CO_PROPID_ to this field to determine the changes to be made to the graphic.

double_click Query a double-click on a cell of the ALV Grid control Query a hotspot click on columns defined for this purpose in advance Collect information when elements of the ALV Grid Control are dragged Process information when elements of the ALV Grid Control are dropped Perform final actions after successful Drag&Drop Distinguish between options for Drag&Drop behavior   X X X X hotspot_click onDrag onDrop onDropComplete onDropGetFlavor Processing of Self-defined and Standard Functions Event before_user_command user_command after_user_command Application Query self-defined and standard function codes Query self-defined function codes Query self-defined and standard function codes HTML    Definition of Self -defined Functions Event toolbar menu_button context_menu_request onf1 Application Change. delete or add GUI elements in the toolbar Define menus for menu buttons in the toolbar Change context menu Define self-defined F1 help HTML   X () .

PUBLIC SECTION...... event_receiver TYPE REF TO lcl_event_receiver...... METHOD handle_toolbar..Structure Araç çubu u dü mesi......... namly MT_TOOLBAR... * This class has got one attribute.. DATA: ls_toolbar TYPE stb_button... CLASS lcl_event_receiver DEFINITION .. CLASS lcl_event_receiver IMPLEMENTATION . * E_OBJECT of event TOOLBAR is of type REF TO CL_ALV_EVENT_TOOLBAR_SET......... handle_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm.... ³stb_button ..In event handler method for event TOOLBAR: Append own functions * by using event parameter E_OBJECT.Örnek: CLASS lcl_event_receiver DEFINITION DEFERRED.. One line of this table is . * § 2........... which * is a table of type TTB_BUTTON... ENDCLASS...... PRIVATE SECTION. Yap s FUNCTION ICON UI_FUNC CHAR CHAR 30 CHAR INT4 1 40 1 70 0 30 10 0 0 0 0 Function Code ICONNAME Name of an Icon 0 0 Bir kon için h zl bilgi QUICKINFO BUTN_TYPE DISABLED TEXT TEXT40 ICONQUICK TB_BTYPE CHAR CHAR CHAR Araç çubu u dü mesi tipi Etkinle tirilmedi 40 karakter uzunlu undaki metin Yazd r ld CHECKED ______________________________ ______________________________ _____________________________________________________________________ _______________________________________________________________ ______ ______ ____________________________________________________________ *.. METHODS: handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object e_interactive............

APPEND ls_toolbar TO e_object->mt_toolbar.* defined by the Structure STB_BUTTON (see data deklaration above). WHEN 'BOOKINGS' . * You can distinguish this way if the event was raised * by yourself or by ALV * (e. "handle_user_command *---------------.. MOVE 3 TO ls_toolbar -butn_type. MOVE 'Show Bookings' (111) TO ls_toolbar -quickinfo. CALL METHOD cl_gui_cfw=>flush. * An application of this feature is still unknown.g. ENDIF.. MOVE ' ' TO ls_toolbar -disabled. MOVE 'BOOKINGS' TO ls_toolbar -function. * add your handling. ENDCASE. else. ENDMETHOD. CASE e_ucomm. DATA: lt_rows TYPE lvc_t_row. :-) * append a separator to normal toolbar CLEAR ls_toolbar. APPEND ls_toolbar TO e_object->mt_toolbar. in method 'refresh_table_display'). MOVE 'Detail'(112) TO ls_toolbar -text. IF sy-subrc ne 0. .------------------------------------------------ENDCLASS. for example CALL FUNCTION 'POPUP_TO_INFORM' EXPORTING titel = g_repid txt2 = sy-subrc txt1 = 'Error in Flush'(500).In event handler method for event USER_COMMAND: Query your * function codes defined in step 2 and react accordingly. if this event is raised due to * the call of 'set_toolbar_interactive' by the user. ENDMETHOD. CALL METHOD grid1->get_selected_rows IMPORTING et_index_rows = lt_rows. * § 3. * * A remark to the flag E_INTERACTIVE: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * 'e_interactive' is set. * append an icon to show booking table CLEAR ls_toolbar. MOVE icon_employee TO ls_toolbar -icon. perform show_booking_table tables lt_rows. *------------------------------------------------------------------METHOD handle_user_command.

LOAD CLASS class DEFINITION { DEFERRED [PUBLIC]} | LOAD. You cannot access individual components of the class before it is actually defined. DEFERRED [PUBLIC] Effect The variant with the DEFERRED addition makes a class known provisionally in the program.Icon for the button (optional) TEXT . this variant makes a local class known before its actual definition.Button type that will be added to the toolbar.Adds the button as disabled The Available button types are: 0: Button (normal) 1: Menu and default button 2: Menu 3: Separator 4: Radio button 5: Checkbox 6: Menu entry CLASS . These variants do not introduce a declaration part and must not be enclosed using ENDCLASS.. y Addition 2 . You need to use this statement if you want to make a reference to a local class before it is defined. This statement can be used to prevent unwanted recursion when making references to global classes. With the PUBLIC addition.. this variant makes a global class known and defers loading the class until the end of the current program unit. regardless of the location of the actual definition of the class in the program. y Without the PUBLIC addition. The program must contain an actual declaration part for class at a later point in the program. Effect These two variants of the CLASS statement are used to make the class class known. You can only access individual components of the class after it has been loaded.The fields of the structure we fill are as follows: FUNCTION .Text for the button (optional) QUICKINFO . ICON . LOAD Effect ...Quick info for the button (optional) DISABLED .The function code for the function BUTN_TYPE . Addition 1 .DEFERRED.

the class c1 uses the class c2 and vice versa.2 3. the entire class cannot be loaded before the type group. DEFERRED PUBLIC statement. CLASS cl_gui_cfw DEFINITION LOAD. CLASS c1 DEFINITION DEFE RRED. The global class cl_gui_cfw is also loaded before one of its static attributes is used. Table of contents 1 2 3 3. PUBLIC SECTION. This statement was needed before Release 6. PUBLIC SECTION.The variant with the LOAD addition loads a global class class from the Class Library.1 3. ENDCLASS. CLASS c2 DEFINITION. the class name can be specified after REF TO without the class having been loaded previously. or to declare an event handler for class before class had been loaded automatically. the LOAD addition is only needed if the compilation of an ABAP program fails because it includes recursive accesses of a globa l class. after the CLASS DEFINITION .. This means that one of the classes must be made known before it is actually defined. From Release 6.4 3.3 3. which itself contains components with references to this reference type. However. ENDCLASS. DATA state LIKE cl_gui_cfw=>system_state.. An example of using the DEFERRED PUBLIC addition would be a type group in which a reference type is declared with a reference to a global class. since the types are not yet known. In this situation. you may be able to make the program compilable by explicitly loading the class before recursion. DATA c2ref TYPE REF TO c2.20 onwards. In such cases. Example In this example. CLASS c1 DEFINITION.5 Introduction Overview of OOPs Concepts Why Object-Oriented ABAP? ENHANCED LEVEL OF DATA ENCAPSULAT ON MULT PLE INSTANT AT ON CODE REUSE INHER TANCE ADVANCED EVENT HANDL NG CONCEPTS . DATA c1ref TYPE REF TO c1.20 if you wanted to access one of the static components of class from within a program.

2 4.1 get_container set_row_height 5 Conclusion .5 4.2 ABAP Object restrictions HOW TO USE A GLOBAL CLASS GLOBAL CLASS: CL_GUI_ALV_GRID Commonly used methods set_table_for_first_display Free Get_selected_rows refresh_table_display Commonly Used Events Context_menu_request Data_changed Double_click Toolbar User command Hotspot_click Coloring a row: Coloring a column: Coloring a cell: SAPÏ¿½S CONTAINER CLASS: CL_GUI_SPLITTER_CONTAINER Commonly used methods: 4.4 4.4 4.3 4.2.6 4.3 4.2 4.2 4.2.6 SKELETON OF ABAP CLASS 4 4.2.5 4.3 4.2.1

6 7 Reference: Appendix .

Now we have to remove all the modifications done. Then came release 6. our idea is like this: �Programmers are very fast and if they are not. This statement might not arouse the interest of most of the programmers (individually) as we have already set a long list of procedures and tools to maintain the programs . The ABAP Objects can considerably improve the productivity by speeding the development time and increasing the application maintainability. As a part of Release extending the ABAP programming language with Classes and Interfaces and the ability to create objects from classes. This document is just meant to give an overview of ABAP Objects .5.2. ABAP has been a hybrid language. search for unused variables. the customer may ask for some changes or the older version itself. 2 Why Object-Oriented ABAP? Since Release 4. adding full -blown objectoriented features to the latter. structures and work areas. how many of us (ABAP developers) are trying to keep aside the conviction that the procedural approach of ABAP development works fine and that there is no need to migrate to a new programming method. Regarding the development time.. who is in a hurry?� Let me take the example of business scenario programmers (especially those in support projects) who get a lot of change requests..the key feature of OO technology.Version management tools. with which you can choose whether you want to stay with the procedural programming model . we will go and add /delete the variables and subroutines involved. SAP introduced ABAP Objects . This statement fits exactly into the growth profile of an ABAP attempt to tap some of the myriad merits of the still unexplored OO technology and to give an opportunity for all fellow programmers to �move on with the technology�.the OO extension of ABAP . Quality assurance systems etc.based on function modules. . SAP Basis Release 4. Still we stick on to that merely because that is the way in which we have always done it. One fine morning. I hope you can very well get the level of discipline that procedural programming demand. with highly advanced OO concepts like �Friendship� between classes and �Shared Object� concepts. Although SAP has given a clear-cut idea of moving towards a completely Object-Oriented world. What we ABAP developers usually do is. ABAP Objects were never intended to completely replace the classical ABAP/4. make a comparison with the older version (if we have not mistakenly done a pretty print).1 and 6. and we don�t find any reason to change from the conventional method adopted.1 Introduction �The growth of a programmer depends not on following a technology but on moving with the technology and dreaming beyond the technology�. These will involve adding a new functionality to the selection screen or removing functionality.6 delivered the complete version of ABAP Objects by enabling Inheritance . ABAP Objects is a fully viable object-oriented extension of ABAP.

when we call a function module. One function might change the application state in such a way that many other functions are affected. and the handling of events from the runtime environment � or. which features: 2. We can inherit some or all the characteristics of a general (or global) class to specialized classes simply by programming the difference between the two. Instead. Keeping the state stable thus require a lot of discipline. you want to use the object-oriented programming model. which relieves the programmer from knowing exactly how the functionality is implemented. In procedural programming. the events are explicitly .subroutines.4 Inheritance This feature permits the creation of objects with reference to an existing global class. we make use of parameter interface for subroutines and procedural interfaces for the function modules. The programmer has to know the particular program processes (reporting. rather than working with the objects directly. We are wellacquainted with the event concepts in procedural programming like AT-SELECTIONSCREEN. In ABAP Objects. it gets loaded into the global memory(instantiated). 2. it is not possible to deactivate an event once it is implemented and we cannot define and trigger our own events. Either you have a piece of code that performs the functionality or else you need to write a new one. The main problem with these methods is their implicitness. 2. In procedural programming. the greatest disadvantage is that it allows the �all or none� concept. even if a method fails. With the procedural method of code reuse. 2. dialog. In a large application.. In this case. the state is kept in objects and the state of an application is defined by its attributes. 2.3 Code Reuse Modularizations of a program and code reuse are possible in procedural programming by the use of subroutines and function modules. In procedural programming. for eg. selection-screen or list process) in the ABAP runtime environment in order to understand the program flow and handle the events properly. you can instantiate a functionality only once. all the data objects. ABAP Objects enable the programmers to work with an Objects Business Logic through standalone interfaces. AT-LINE SELECTION etc.2 Multiple Instantiation Multiple instantiation is one among the unique feature of Object-Oriented programming. the variables and the work areas that we use get populated in a global data area. This maintains the stability of the application. In ObjectOriented programming. in procedural programming.1 Enhanced level of Data Encapsulation The ABAP Objects improve the maintainability and stability of the programs. it will work with the global data that is already available in the existing function pool. Also. If the same or another program in the same internal session calls the function again it wont get re-instantiated. AT-USER COMMAND.5 Advanced Event handling concepts ABAP Objects make it easy to implement the event-driven programming model. predicting the state of eac object is nearly h impossible. This is possible through a stable stand-alone interface. the application will continue to run successfully.

Procedural/event-based ABAP/4 language runs in the same legacy system and has the following features:     Runs on the SAP Application Server in the ABAP runtime environment Is downward-compatible with the existing coding Is inter-operable with the procedural coding Embraces the benefits of classical ABAP . in order to make even a small change. which are available only via interfaces in other languages. it is a scrupulous job for a programmer to make changes on a standard code or a big custom application program. Open SQL These facts offer an evolutionary approach to object-orientation.g. The main reason being. it was a conscious decision to realize them directly as language elements of ABAP Objects. CFW (SAP Control Frame Works) etc.for example. and data. from the point of view of a developer. Most of the error prone concepts (e. one should know the actual program flow. ABAP Objects is the only platform on which we can use the new SAP technologies like NetWeaver. ABAP Objects is especially a language for business applications. As mentioned earlier. BSP (Business Server Pages). functionality. We can activate and deactivate the events as required and also can set up multiple handlers for an event. which leverages SAP�s own and its customers� investments in existing business processes. for the powerful concept of events and event handling. ABAP Objects offer better syntax and semantic rules.:. and all the new advanced GUI concepts like DOI (Desktop Office Integration). But while dealing with classes.declared as components in a class. The greatest benefit of ABAP Objects lies in the fact that they are an extension of the former ABAP programming concepts. Most of the above-mentioned features are common in all the Object-Oriented programming languages. „y „y It frees the programmer of the ABAP�s runtime implicit control of program flow. It was designed to be simpler than Java and C++ and it omits complex concepts that lack in benefits (such as multiple inheritance or destructors). for all entries command) are not permitted in the ABAP classes. (A separate kernel has been set up for the ABAP Objects that significantly improves the processing capabilities) Regarding the maintenance. We can also pass some additional parameters that are interested in reacting to the event. it will reduce the person hours about N times when compared to procedural programming where the factor �N� depends on the expertise level and how well the object design has been made. the developer can activate and deactivate the functionality or create a new functionality simply by commenting . Apart from all these. „y From a business perspective. This gives the freedom to the programmer to explicitly call an event by the command RAISE EVENT.header. On the other hand. migration to Object-Oriented ABAP programming will surely impress the clients due to its enhanced processing speed. Analyzing the impact of changes takes a major amount of development time.

LOOP and REFRESH from on Database tables Not permitted.WHEN.FIELDS. detects and prevents many potentially incorrect data . COMMONPARTS. Not permitted on numeric data objects. NON-LOCAL not permitted TRANSLATE. SORTED BY.. NODES.F.ADD-CORRESPONDING. procedural programming permits this which sometimes shows surprising implicit behaviors. READ. <> .ASSIGN�TYPE.=> not allowed .DIVIDE CORRESPONDING.the method calls or implementing a new method inside the class. No header lines. compatible work areas. TABLES.MULTIPLY_CORRESPONDING not allowed. No operational statements between CASE.CODEPAGE and TRANSLATE �NUMBER FORMAT not permitted Clear�with NULL. OCCURS. 2. Database access: NO implicit work areas. No length specifications on data types I.=<.. passing of SY-SUBRC and raising of undefined exceptions not allowed.RANGES INFOTYPES. no redundant key. No implicit type assignment. Conversions Operations: String processing: FIELD-SYMBOLS Logic Expression Control structures Internal tables Procedures Program calls: All these syntax restrictions imposed on the Object-Oriented programming prohibit many obsolete statements and additions.. WRITE TO ITAB not permitted.6 Skeleton of abap class 3 ABAP Object restrictions Syntax restrictions on ABAP Objects:Declarations Like reference to Data objects only. COLLECT. Passing formal parameters implicitly in CALL DIALOG not permitted. No implicit work areas.SUBSTRACT CORRESPONDING. No joint use of Using and SKIP FIRST SCREEN in calling transactions.ASSIGN TABLE FIELD not permitted. No implicit types in Field symbols: FIELDSYMOLS��STRUCTURE. There is no need to manually delete the variables or structures or work spaces as the automatic garbage collector will clear the entire memory whenever an object is de-referenced. Compatible initial values only.D or T. No implicit lengths or decimal places in Types. WITH HEADER.

in addition to an internal table. To create a custom container instance. Define a variable in the program of type scrfname and value �CONT1�. DATA :<go_container> TYPE REF to cl_gui_custom_container. While doing so. CONT1). 3. we make use of tables with header lines. Call screen 100. Create a screen <100>. a second data object is implicitly created with the same name. Step by step approach: ALV grid instance needs a container to be linked with the screen. 8. Place the custom control on the screen and give the proper name for the control (eg. 2. create an instance for the container (go_container) passing the container name as the scrfname�s variable(go_cont1). For eg. TYPE REF to cl_gui_alv_grid. programming using Objects is much easier than the procedural method. Let us take the case of an ALV grid programming. 7. we create an event-driven report and call the function module REUSE_ALV_GRID_DISPLAY with field catalogue. b. In procedural concepts. Let us see how the same functionality is attained using ABAP Objects.1 How to use a Global Class Although coding seems to be a bit confusing in the early stage. consider the declaration of an internal table. Declare all the required global fields. Declare an internal table to hold the output list. Create instance for the container a.<gt_outtab> ). Create the instance for the alv grid exporting the parent container say go_container. MODULE status_0100 OUTPUT. The syntax-enforced Object-Oriented ABAP allows defining a table without the implicit definition of a header-line only. 3. In procedural programming. 6. 5.. Usually instance of the class �CL_GUI_CUSTOM_CONTAINER� is used for this purpose.. This is a significant source of confusion as the developer has to identify whether it refers to a header or a table. Call the screen <100> In the PBO of the screen. CREATE OBJECT <go_container> . DATA: <go_cont1> DATA: <go_grid > TYPE scrfname value �CONT1�. a. 1. IF go_container IS INITIAL.handling and reduces the implicitness of the coding. (eg. layout and internal tables. 4. you need to place a custom control area on the screen. which often leads to programming errors.

EXPORTING ii. Defining Local Classes Local classes consist of ABAP source code. 9. 11. When you define local classes. CREATE OBJECT < go_grid> ii. you must also write an implementation part for it.2 GLOBAL CLASS: CL_GUI_ALV_GRID Global class that contains all the methods. It contains the declaration for all components (attributes. events) of the class. . ENDCLASS.. enclosed in the ABAP statements CLASS . Create instance for the grid i. Subsequent coding that is not itself part of a processing block is therefore not accessible. EXPORTING iii. You should therefore place it at the beginning of the program. you will be able to view the grid by using the method set_table-for_first_dispaly of the class cl_gui_alv_grid(which is explained in detail later in this bok). i_parent = <go_container>. ENDCLASS. Once you have created the instances for the container and grid... The implementation part of a local class is a processing block. ENDMODULE. A complete class definition consists of a declaration part and...i. you can handle all the general user commands. the declaration part belongs to the global program data. ENDIF. 12. if required. container_name = '<CONT1>'. The declaration part of a class <class> is a statement block: CLASS <class> DEFINITION. an implementation part. 3. The implementation part of a class contains the implementation of all methods of the class.. In the PAI of the screen. This consists of a further statement block: CLASS <class> IMPLEMENTATION. ENDCLASS. methods. 13. If you declare methods in the declaration part of a class. attributes and events that are necessary to . . 10.

Contains function codes of the toolbar to be excluded from the list (function codes are attributes prefixed with mc_fc_). TYPE STANDARD TABLE OF < t_outtab> WITH HEADER LINE.display a list in the ALV grid.1. 3. you can call a method with which you can define and change the property of the grid control. Internal table of type lvc_s_fcat. . Name IS_LAYOUT Type LVC_S_LAYO Function For setting the general graphical layout for the grid. TYPE lvc_s_layo TYPE ui_function WITH HEADER LINE.1 It�s a public method that is used to display an output table in the specified grid control.2. With the help of the instances.Carries the field catalogue informations.1 Commonly used methods set_table_for_first_display 3. You can create �N� number of instances of a class. Parameters: Some of the parameters should be passed when u call this method are .2. Internal table contains the data to be listed in the grid IT_TOOLBAR_EXCLUDING UI_FUNCTION IT_FIELDCATALOG LVC_S_FCAT IT_OUTTAB Sample code: DATA:go_test DATA:gs_layout DATA:gt_excl DATA:gt_outtab TYPE REF TO cl_gui_avl_grid.

CALL METHOD: go_test->get_selected_rows IMPORTING et_index_rows = lt_rows.4 refresh_table_display .1.2.1. 3. 3.1.2 Free Public method used to free up the reference variables and along with this method use clear command to clear all the interfaces and attributes of the object. Sample code: CALL METHOD: Go_test->free. CLEAR: Go_test. CALL METHOD go_test->set_table_for_first_display EXPORTING Is_layout = gs_layout It_toolbar_excluding = gt_excl[] CHANGING It_outtab It_fieldcatlog = gt_outtab[] = gt_fieldcat[].DATA:gt_fieldcat TYPE lvc_s_fcat WITH HEADER LINE.2.2. Parameters: Name ET_INDEX_ROWS Type LVC_T_ROW Function Contains the indexes of the selected rows. 3. Sample code: Data: lt_rows type lvc_t_row.3 Get_selected_rows Public method used to get the indexes of the selected row from the grid in case of selecting more than one row from the grid.

for implementing the above functions what you need to do is just pass the constant attributes that precedes with mc_fc_(function codes) of the class cl_gui_alv_grid to a table that is of type ui_functions.2.2 Commonly Used Events Context_menu_request 3. Sample code: To add your own options to the existing context menu use the method �add function�. iv.2. After adding the function code you can code for the function code (UPDATE) in the event user command. show_functions.Public method used to refresh the output table in the grid control. hide_functions. . 3. And if u want to hide/show/disable/enable the existing options u can use these methods i. CALL METHOD e_object->add_function EXPORTING fcode = �UPDATE� text = �Update details�. enable_functions iii. disable_functions ii. Sample code: CALL METHOD: Go_test->refresh_table_display. Parameters: Name E_OBJECT (Ref variable) Type CL_CTMENU Function Standard context menu of the ALV grid control.1 In this event you can add your own defined functions to the existing context menu and you can also hide/disable the existing context menu functions.2.

3. Method name Get_cell_value Modify_cell Function Used to get the cell value Used to modify the cell content Values of the changed data are stored in the attributes of this instance.2 Data_changed This event gets triggered when the user tries to change any data present in the grid. list of attributes : Attribute name Mt_mod_cells Function Contains the input value of the modified cell with row-ids and fieldnames( Field validations doesn�t happen at this point) Contains proper values of the cell. TO lt_fcode.2. TO lt_fcode. TO lt_fcode. Sample code for hiding the options DATA: lt_fcodes TYPE ui_functions.And call the appropriate method and export the function codes to the table. For controlling the data changes on the grid.By using this method user can get value of the modified cell. List of methods used in the class cl_alv_changed_data_protocol. Mt_good_cells . ALV uses the instance of the Class CL_ALV_CHANGED_DATA_PROTOCOL and passess it as an attribute to the event Data_Change. TO lt_fcode. CLEAR lt_fcodes. TO lt_fcode.2. APPEND go_test->mc_fc_loc_copy APPEND go_test->mc_fc_col_optimize APPEND go_test->mc_fc_help APPEND go_test->mc_fc_find APPEND go_test->mc_fc_loc_cut APPEND go_test->mc_fc_loc_insert_row APPEND go_test->mc_fc_fix_columns CALL METHOD e_object->hide_functions TO lt_fcode. EXPORTING fcodes = lt_fcode. TO lt_fcode.

Sample code: DATA: er_data_changed TYPE REF TO cl_alv_changed_data_protocol.Parameters: Name ER_DATA_CHANGED (reference variable) Type CL_ALV_CHANGED_DATA_PROTOCOL Function Public class that contains the attributes . DATA: wa_test DATA : row_index DATA : wa_curr TYPE lvc_s_modi. = wa_test-row_id = wa_test-fieldname CALL METHOD p_er_data_changed->modify_cell EXPORTING i_row_id = wa_test-row_id i_fieldname = wa_test-fieldname i_value row_index = wa_curr. TYPE lvc-index. CASE:�<PRICE >�.methods and events handling the data _change event. CALL METHOD er_data_changed->get_cell_value. = wa_test-row_id . EXPORTING i_row_id i_fieldname IMPORTING e_value = wa_curr. TYPE P DECIMALS 2. LOOP AT er_data_changed->mt_mod_cells INTO wa_test. .

2. ENDLOOP. TYPE <gt_outtab>. TYPE lvc_s_roid. IF SY-SUBRC = 0.READ TABLE <gt_outtab> INDEX row_index. <gt_outtab-paymentsum> = <gt_outtab-price> * <gt_outtab-seatsocc>. ENDIF. . <gt_outtab-price> = wa_curr . ENDCASE.3 Double_click This event gets triggered when the user double clicks on a cell of the control. Parameters: Name E_ROW E_COLUMN ES_ROW_NO Type LVC_S_ROW LVC_S_COL LVC_S_ROID Function Contains the row-id of the clicked cell. TYPE lvc_s_col. Sample code: DATA: e_row_id e_column_id es_row_id <lt_outtab> TYPE lvc_s_row. 3. MODIFY <gt_outtab> INDEX row_index. Contains the numeric row-id of the clicked cell. IF SY-SUBRC = 0 AND e_column_id-fieldname = � CARRID�.2. Contains the column name of the clicked cell. READ TABLE <gt_outtab> into <gs_struct> INDEX lvc_s_row-row_id.

4 Toolbar This event is used to add self defined functions to the existing tool bar. . Sample code: Following step depicts how to add a user defined button on the existing toolbar. Field Function Butn_typ Description Function code for the function List of Value 0 1 2 3 4 5 6 Icon Text Quickinfo Disabled. button types Constant cntb_btype_button cntb_btype_dropdown cntb_btype_menu cntb_btype_sep cntb_btype_group cntb_btype_check Meaning Button (normal) Pushbutton with menu Menu Seperator Pushbutton group Checkbox Menu entry Icon for the button(optional) Text for the button (optional) Tool tip for the button(optional) Adds the button as disabled Parameters: Name E_OBJECT Type CL_ALV_EVENT_TOOLBAR_SET Function Contains an attribute(mt_toolbar) with the table for functions of the standard toolbar. this event gets triggered when each time the toolbar of the control needs to get regenerated .2. ENDIF.2.<lt_outtab> = <gt_outtab>. The fields of the structure that normally contains. 3. APPEND lt_outtab.

3. MOVE �Flight details� TO ls_toolbar-quickinfo. Declare a structure for adding a toolbar element. DATA :ls_toolbar TYPE can write your own function under this function code and u can call this function under this event.2. ****pushbutton. Use the event parameter e_object to append the attributes for the newly added button in the toolbar. . TO ls_toolbar-text. Say. c. MOVE �0� MOVE �DET� MOVE �DETAILS� TO ls_toolbar-butn_type. d. Note: you can hide the entire tool bar by adding �NO_TOOLBAR� field to the layout structure. Here is the code that depicts how to query for selecting the details for more than one row from the alv grid.2. APPEND ls_toolbar TO e_object->mt_toolbar. In the event handler method user_command. user can place his own logic into the corresponding function code which is moved into function field of the table. CLEAR ls_tolbar.5 User command This event gets triggered when the user defines his own function code. e_object TYPE REF TO CL_ALV_EVENT_TOOLBAR_SET. TO ls_toolbar-function. Move the relevant values into the structure fields. b. Parameters: Name E_UCOMM Type SY_UCOMM Function Function code used for self-defined function Sample code: User can query the function codes of the self defined functions under this event.a. Define a event handler method for the toolbar event. ** structure for adding a ** toolbar element.

WHEN �<DET>�.2. APPEND lt_outtab. 3. TYPE lvc_t_row. ENDIF.6 Hotspot_click This event is similar to the double click event of the class cl_gui_alv_grid.DATA: e_ucomm DATA:lt_rows DATA:ls_selected_line DATA:ls_row_index DATA:<lt_outtab> CASE: e_ucomm. Clear: lt_outtab. IF SY-SUBRC = 0. Parameters: . gt_outtab. TYPE lvc_s_row. CLEAR: lt_outtab. Its triggered when the user clicks on a column which is designated as a hotspot column which is identified by hand stretch mouse pointer. TYPE sy-ucomm. READ TABLE gt_outtab into <gt_wa> INDEX ls_row_index. TYPE lvc_index. CALL METHOD go_test->get_selected_rows IMPORTING et_index_rows = lt_rows.(you can designate hotspot column when u build the field-catalog by setting the field �hotspot� to �X� ) . LOOP AT lt_rows INTO ls_selected_line. ls_row_index = ls_selected_line-index.2. TYPE <gt_outtab>. ENDCASE. ENDLOOP.

Sample code: DATA: e_row_id TYPE lvc_s_row. IF SY-SUBRC = 0 AND e_column_id-fieldname = � CARRID�.2. Where x-> Color number. Color code is a 4 character field that is of the format. 3.Name E_ROW_ID E_COLUMN_ID ES_ROW_NO Type LVC_S_ROW LVC_S_COL LVC_S_ROID Function Contains the row-id of the clicked cell. Contains the numeric rowid of the clicked cell. TYPE <gt_outtab>. Contains the column name of the clicked cell. Format: Cxyz. READ TABLE <gt_outtab> into <gt_wa> INDEX lvc_s_row-row_id. Color numbers are listed out in the below table. Before going further let us discuss how to construct a color code.3 Coloring a row: For coloring an entire row you need to add one more field in your output list table structure. . es_row_id <lt_outtab> TYPE lvc_s_roid. y-> 1 0r 0 (�1� for inverse ON and �0� for inverse OFF) z->1 or 0 ( �1� for intensified ON and �0� for intensified OFF). which is a 4 character field that one is used to fill the color code for the row. ENDIF. APPEND lt_outtab. e_column_id TYPE lvc_s_col. <lt_outtab> = <gt_outtab>.

x 1 2 3 4 5 6 7 Color gray-blue light gray yellow blue-green green red orange Intended for headers list bodies totals key columns positive threshold value negative threshold value Control levels After moving the color code to the field created on the output table structure . 3. you need to add a deep structure field of type LVC_T_SCOL to the output table structure .you need to pass this field name to the field �INFO_FNAME� of the layout structure Sample code: Add <col_row(4)> type c in the gt_outtab. �inv�. *col_row is a 4 character field * in the table gt_outtab. . this deep structure table used to fill the color datas. for each cell column append a line to this deep structure table which inturn also contains the column name at field �fname� and some color values in the �col� field and 1 or 0 in the field �int� . Move �<COL_ROW>� to <gs_layout>-info_fname. Move �C310� to <gt_outtab>-<col_row>. To color an individual cell .2.2. 3.4 Coloring a column: Coloring an entire column is very simple .what you need to do is when you build the field catalog make the option �EMPHASIZE� to �X� for the column you need make color.5 Coloring a cell: Coloring an cell is similar to coloring a row .

3. The control is driven by the application logic. You use custom controls to embed controls. they have a unique name. MOVE �SEATSOCC� MOVE �6� MOVE �1� MOVE �1� Append wa_color to gt_color.3.1 CLASS: CL_GUI_SPLITTER_CONTAINER This class is used to minimize the memory area occupied by the normal container. TYPE TABLE of lvc_s_scol. which can be either an ActiveX control or a JavaBean.Sample code: 1. They allow you to perform tasks. such as editing texts. <Gt_outtab>-<color_cell> [] = gt_color[]. and split the container as we require. 3. TO wa_color-col. DATA : wa_color DATA : gt_color DATA: row_index TYPE lvc_s_scol. TO wa_color-fname.1 Commonly used methods: get_container Used to get the sub container that is got spitted from parent container. which still runs on the application server. TO wa_color-int. Parameters: Name ROW(exporting) Function Numeric value that is used to represent . like all other screen objects. Modify gt_outtab index <row_index> 3.1. TO wa_color-inv.3. locally on the presentation server. and. We can pass these sub-containers to the alv grid.3 SAP�s CONTAINER A custom control is an area on a screen. A control is a software component on the presentation server. Here we can create a single custom control area in the screen. You create them in the Screen Painter. TYPE lvc_index. depending on the SAPgui you are using. Include a field <color_cell> of type lvc_t_scol to the output list table structure.

Parameters: Name Id Height Funtion Sub container�s id Numerics value that species the height of the sub container.the row id of the sub container. Sample code: . Container(receiving) Sample code: DATA:<go_cont1> TYPE REF TO cl_gui_container. DATA: go_splitter TYPE REF TO l_gui_splitter_container. Sub container name that is of refernce type cl_gui_container. Column(exporting) Numeric value that is used to represent the column id of the sub container. =1 set_row_height Used to set the height of the sub-container. CALL METHOD <go_splitter> ->get_container EXPORTING row =1 column RECEIVING container = <go_cont1>.

SAP provides a method that does the container-placing for them. When we use cl_gui_container=>screen0 as parent. NO CONTAINER DEFINITION IS REQUIRED. For those programmers who find it difficult to create the custom containers over the screens.CALL METHOD <go_splitter>->set_row_height EXPORTING id height =1 = 25. DATA: cl_alv TYPE REF TO cl_gui_alv_grid CREATE OBJECT cl_alv EXPORTING i_parent = cl_gui_container=>screen0 . the ALVGrid control will automatically use the full screen to display the grid. pass the attribute cl_gui_container=>screen0 as the parent container. While creating the object. What you have to do is to define a class of type cl_gui_alv_grid.

Sign up to vote on this title
UsefulNot useful