ABAP Tutorials Blog Archive ABAP Program For ALV Grid, The OOPS Way - ABAP Tutorials
ABAP Tutorials Blog Archive ABAP Program For ALV Grid, The OOPS Way - ABAP Tutorials
ABAP Tutorials Blog Archive ABAP Program for ALV Grid, the OOPS way - ABAP Tutorials
ABAP Tutorials
ABAP Tutorials, Guides, Training, Manuals
Welcome
Blog
Archives
Subscribe
Downloads
Interview Q&A
Code Contribution
ABAP Books
Disclaimer
About
Subscribe To Entries
Subscribe To Comments
Subscribe Via Email
Want to find something?
ALV
The Grid
ABAP in Sap
ABAP
09 Jul
The program below shows OOPS concept implementation in ALV. ALV is created inside the Custom Container, which acts as
wrapper for ALV. For both ALV and Custom Container, Objects has been created from the respective classes.
http://www.abap-tutorials.com/2009/07/09/alv-grid-the-oops-way/#more-45
1/6
10/27/2014
ABAP Tutorials Blog Archive ABAP Program for ALV Grid, the OOPS way - ABAP Tutorials
REPORT zalv_using_objects.
********Data declarations with respect to classes
DATA :
t_cust TYPE REF TO cl_gui_custom_container,
t_grid TYPE REF TO cl_gui_alv_grid .
*******Declaration of Structure with respect to SPFLI
TYPES:
BEGIN OF type_s_flight,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
END OF type_s_flight.
*******Fieldstring Declaration
DATA:
fs_flight TYPE type_s_flight.
******Table Declaration
DATA:
t_flight LIKE STANDARD TABLE OF fs_flight.
*******Declarations with respect to ALV
DATA:
t_fcat TYPE lvc_t_fcat, Field Catalog for List Viewer Control
w_fcat TYPE lvc_s_fcat, ALV control: Field catalog
w_lay TYPE lvc_s_layo . ALV control: Layout structure
********Select Query to retrive values from table SPFLI
SELECT *
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE t_flight.
*******Calling the screen that has been designed in SE51 in the following manner
******* Goto SE51,design a layout and give the name of the container (ZALV01)
CALL SCREEN 100.
*&*
*& Module STATUS_0100 OUTPUT
*&*
* Module that has been called from SE51
*-*
MODULE status_0100 OUTPUT.
SET PF-STATUS BACK.
SET TITLEBAR FLIGHT.
ENDMODULE. STATUS_0100 OUTPUT
*&*
*& Module ALV_OUTPUT OUTPUT
*&*
* Module that has been created in SE51 and called
*-*
MODULE alv_output OUTPUT.
*****Appending data to t_fcat
w_fcat-fieldname = CARRID.
w_fcat-coltext = Carrid.
APPEND w_fcat TO t_fcat.
w_fcat-fieldname = CONNID.
w_fcat-coltext = Connid.
APPEND w_fcat TO t_fcat.
*******Create a object of class CL_GUI_CUSTOM_CONTAINER
CREATE OBJECT t_cust
EXPORTING
http://www.abap-tutorials.com/2009/07/09/alv-grid-the-oops-way/#more-45
2/6
10/27/2014
ABAP Tutorials Blog Archive ABAP Program for ALV Grid, the OOPS way - ABAP Tutorials
* parent =
container_name = ZALV01
* style =
* lifetime = 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.
*******Create a object of class CL_GUI_ALV_GRID
CREATE OBJECT t_grid
EXPORTING
* i_shellstyle = 0
* i_lifetime =
i_parent = t_cust
* 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 a method of instance t_grid , class cl_gui_grid_alv and method set_table_for_first_display
CALL METHOD t_grid->set_table_for_first_display
EXPORTING
* i_buffer_active =
* i_bypassing_buffer =
* i_consistency_check =
i_structure_name = T_SPFLI
* is_variant =
* i_save =
* i_default = X
is_layout = w_lay
* is_print =
http://www.abap-tutorials.com/2009/07/09/alv-grid-the-oops-way/#more-45
3/6
10/27/2014
ABAP Tutorials Blog Archive ABAP Program for ALV Grid, the OOPS way - ABAP Tutorials
* it_special_groups =
* it_toolbar_excluding =
* it_hyperlink =
* it_alv_graphics =
* it_except_qinfo =
* ir_salv_adapter =
CHANGING
it_outtab = t_flight
it_fieldcatalog = t_fcat
* 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.
ENDMODULE. ALV_OUTPUT OUTPUT
*&*
*& Module USER_COMMAND_0100 INPUT
*&*
* Module that has been called from SE51
*-*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN BACK.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. USER_COMMAND_0100 INPUT
http://www.abap-tutorials.com/2009/07/09/alv-grid-the-oops-way/#more-45
4/6
10/27/2014
ABAP Tutorials Blog Archive ABAP Program for ALV Grid, the OOPS way - ABAP Tutorials
Thanks for the explanation and sample code. It was very much useful.
Post a Comment
Name (Required)
E-Mail (Required) (Will not be published)
Website
Submit
BLOG CATEGORIES
Select Category
POPULAR POSTS
About ABAP
Unicode in SAP
Tcodes in SAP Part 1
Add Search Help to Screen Field in SAP
http://www.abap-tutorials.com/2009/07/09/alv-grid-the-oops-way/#more-45
5/6
10/27/2014
ABAP Tutorials Blog Archive ABAP Program for ALV Grid, the OOPS way - ABAP Tutorials
Welcome
Blog
Archives
Subscribe
Downloads
Interview Q&A
Code Contribution
ABAP Books
Disclaimer
About
http://www.abap-tutorials.com/2009/07/09/alv-grid-the-oops-way/#more-45
6/6