ABAP Program for ALV Grid, the OOPS way

1
713

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.

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
* 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 =
* 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


*Source = Amuktha Naraparaju

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here