SAP ALV OOPS

OBJECT ORIENTED ALV
The ALV grid control is a flexible tool for displaying lists. The tool provides common list operation as generic functions and can be enhanced by self-defined options. This allows us to use the ALV grid control in a large range of application programs. The ALV grid control in OO(Object Oriented) Context uses controls technology to achieve state-of-the-art on-screen display and the ALV grid control offers methods through a global class in the system which can be used to affect its behavior. As a result of using ABAP Objects, lists are displayed through an ALV instance. Note : The ALV concept is same in Both Using Function Modules (REUSE_ALV_GRID_DISPLAY) and ABAP Objects. Limitations: The ALV grid control does not allows us to display Blocked and Hierarchical lists Only Simple lists can be displayed in single-line format only Steps to Work With ALV GRID This section describes the easiest way to display a list with selected data in the ALV grid control. 1) Create a Module Pool/Report Program and link the Normal Screen <Screen Number>. 2) Place Custom Container Control on the Screen and Name it. Declare the Reference Variable and Create the INSTANCE for Container CLASS. DATA ALV_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER. PBO: CREATE OBJECT O_CONTAINER EXPORTING CONTAINER_NAME = <NAME> 3) Declare the Reference Variable AND Create the INSTANCE (Obj) For ALV GRID and CUSTOM CONTAINER Object (CUSTOM_CONTAINER) as the parent. DATA ALV_GRID TYPE REF TO CL_GUI_ALV_GRID PBO: CREATE OBJECT GRID EXPORTING I_PARENT = CUSTOM_CONTAINER

1) Since ALV GRID Instance is ready Now, we can start Calling the Methods i.e. to DISPLAY the Data and to enjoy all the ALV Grid Functionalities. Note: We Can See the ALV GRID Control Object on the Screen Only While Displaying the Data

Displaying a List in the ALV GRID CONTROL Once ALV grid control is Instantiated and Integrated it into a screen using a container control, We Must Pass What to Display (<ITAB> With DATA) AND How to Display (The Field Catalog Information) to the Corresponding Method

CALL METHOD ALV_GRID->set_table_for_first_display EXPORTING I_STRUCTURE_NAME = ‘SFLIGHT’ (“Name of Standard table”) CHANGING IT_OUTTAB = I_LIST (“Name of our internal table”)

Note: Make Sure the Required Data is Collected INTO I_LIST before Calling the above Method

EXAMPLE PROGRAM :
REPORT ZALVOOPS. CLASS event_class definition deferred. DATA : ALV_GRID type ref to CL_GUI_ALV_GRID, field_typ type lvc_t_fcat , CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER , layout type lvc_s_layo ,

event_receiver TYPE REF TO event_class. CLASS event_class DEFINITION. PUBLIC SECTION. METHODS : handle_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row . ENDCLASS. CLASS EVENT_CLASS IMPLEMENTATION. METHOD HANDLE_DOUBLE_CLICK.

WRITE: 'SUCCESS'. LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0. SUPPRESS DIALOG. ENDMETHOD. ENDCLASS. DATA BEGIN OF i_list OCCURS 0 . INCLUDE STRUCTURE SFLIGHT . DATA END OF i_list .

* CALL SCREEN 9011 . MODULE USER_COMMAND_9011 INPUT. case sy-ucomm . when 'DISPLAY'. SELECT * FROM SFLIGHT INTO TABLE i_list . CALL SCREEN 9012. when 'EXIT' . LEAVE PROGRAM . ENDCASE . endmodule . MODULE display_alv output . PERFORM display_alv . CREATE OBJECT: EVENT_RECEIVER. SET HANDLER EVENT_RECEIVER->HANDLE_DOUBLE_CLICK FOR ALV_GRID. ENDMODULE . FORM display_alv .

* if alv_grid is initial . CREATE OBJECT CUSTOM_CONTAINER EXPORTING PARENT = CONTAINER_NAME = 'CC_ALV' STYLE = LIFETIME = cntl_lifetime_default REPID = DYNNR = NO_AUTODEF_PROGID_DYNNR = EXCEPTIONS CNTL_ERROR =1 CNTL_SYSTEM_ERROR =2 CREATE_ERROR =3 LIFETIME_ERROR =4 LIFETIME_DYNPRO_DYNPRO_LINK = 5 others =6 . IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. else .

* * * * *

* * *

CREATE OBJECT ALV_GRID EXPORTING * I_SHELLSTYLE =0 * I_LIFETIME = I_PARENT = CUSTOM_CONTAINER I_APPL_EVENTS = space * I_PARENTDBG = * I_APPLOGPARENT = * I_GRAPHICSPARENT = * I_NAME = I_FCAT_COMPLETE = SPACE EXCEPTIONS ERROR_CNTL_CREATE = 1 ERROR_CNTL_INIT = 2 ERROR_CNTL_LINK = 3 ERROR_DP_CREATE = 4 others =5 . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING I_BUFFER_ACTIVE = I_BYPASSING_BUFFER = I_CONSISTENCY_CHECK = I_STRUCTURE_NAME = 'SFLIGHT' IS_VARIANT =

* * * *

* * * * * * * * * * * * * * * * * * * * *

I_SAVE = 'X' I_DEFAULT = 'X' IS_LAYOUT = IS_PRINT = IT_SPECIAL_GROUPS = IT_TOOLBAR_EXCLUDING = IT_HYPERLINK = IT_ALV_GRAPHICS = IT_EXCEPT_QINFO = IR_SALV_ADAPTER = CHANGING IT_OUTTAB = i_list[] IT_FIELDCATALOG = IT_SORT = IT_FILTER = EXCEPTIONS INVALID_PARAMETER_COMBINATION = 1 PROGRAM_ERROR =2 TOO_MANY_LINES =3 others =4 . IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.

ENDIF . ENDFORM . *&---------------------------------------------------------------------* *& Module STATUS_9011 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE STATUS_9011 OUTPUT. SET PF-STATUS 'STAT'. ** SET TITLEBAR 'xxx'. * case sy-ucomm . ** when 'BACK' . ** CALL SCREEN 9011 . ** when 'CANCEL' . ** CALL SCREEN 9011 . * when 'EXIT' . * LEAVE PROGRAM . * ENDCASE . ENDMODULE. " STATUS_9011 OUTPUT *&---------------------------------------------------------------------* *& Module STATUS OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* " STATUS OUTPUT *&---------------------------------------------------------------------* *& Module STATUS_9012 OUTPUT *&---------------------------------------------------------------------* * text

*----------------------------------------------------------------------* MODULE STATUS_9012 OUTPUT. SET PF-STATUS 'STAT'. * SET TITLEBAR 'xxx'. case sy-ucomm . when 'BACK' . CALL SCREEN 9011 . when 'CANCEL' . CALL SCREEN 9011 . when 'EXIT' . LEAVE PROGRAM . ENDCASE . ENDMODULE. ----------* *& " STATUS_9012 OUTPUT*&-----------------------------------------------------------

We have to write this program in SE80(ABAP WORKBENCH). In se80 we can make: Classes Fields PBO Module PAI Module Subroutines Screens GUI Status Transactions

How to call Screen: In SE80 Right Click on Program name Then Create>SCREENS It will be displayed as shown below

Now we have to give SCREEN number(9000 to 9999) After this Click on OK button The next SCREEN will appear like below Now give Short Description for it Click on LAYOUT

Click on LAYOUT LAYOUT will be displayed as below:

Select CONTAINER and drag it through the page it will look as below

Now give CONTAINER name as:

Now Click on page and give Name here too:

The PBO AND PAI for the SCREEN will be :

And SCREEN Number is 9012 Now CREATE another SCREEN for entering the input PARAMETERS with SCREEN number 9011. Its LAYOUT will look like :

Now give name for text field and FUNCTION CODE for BUTTON

Function code for Button is given as ‘DISPLAY’ After SCREENS add MODULES as MODULE STATUS_9011 in program and EXECUTE it.

For EXECUTION right click on program name in SE80, then activate, after that again right click and click DIRECT PROCESSING. The output Screens will look as below

Here it will ask for input PARAMETERS. After giving the values the output table will be DISPLAYED.

Sign up to vote on this title
UsefulNot useful