Steps need to follow to create OOALV
- Create Screen
- Insert Custom Container UI element.
- Create Module.
- Create instance for Custom Container and add instance to ALV.
- Get data from tables
- Set data to ALV
*&———————————————————————*
*& Report ZOOALV_TEST_1
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT zooalv_test_1.
TYPES : BEGIN OF ty_mara,
matnr TYPE matnr,
mtart TYPE mtart,
mbrsh TYPE mbrsh,
END OF ty_mara.
DATA : lv_container TYPE REF TO cl_gui_custom_container,
lv_alv TYPE REF TO cl_gui_alv_grid,
it_mara TYPE TABLE OF ty_mara,
it_fcat TYPE lvc_t_fcat,
wa_fcat TYPE lvc_s_fcat.
START-OF-SELECTION.
CALL SCREEN 100.
*&———————————————————————*
*& Module STATUS_0100 OUTPUT
*&———————————————————————*
* text
*———————————————————————-*
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘ZTEST1’.
SET TITLEBAR ‘ZTEST2’.
CASE sy–ucomm.
WHEN ‘BACK’ OR ‘CANC’.
LEAVE TO SCREEN 0.
WHEN ‘SAVE’.
MESSAGE ‘OPERATION NOT POSSIBLE NOW’ TYPE ‘I’.
WHEN OTHERS.
ENDCASE.
CREATE OBJECT lv_container
EXPORTING
* parent =
container_name = ‘CC_ALV’
* 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 OBJECT lv_alv
EXPORTING
* i_shellstyle = 0
* i_lifetime =
i_parent = lv_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.
*SELECT * FROM mara into TABLE it_mara
* UP TO 50 rows.
* Build Field catalog
wa_fcat–col_pos = ‘1’.
wa_fcat–fieldname = ‘MATNR’.
wa_fcat–tabname = ‘MARA’.
wa_fcat–scrtext_m = ‘Material No’.
APPEND wa_fcat to it_fcat.
CLEAR : wa_fcat.
wa_fcat–col_pos = ‘2’.
wa_fcat–fieldname = ‘MTART’.
wa_fcat–tabname = ‘MARA’.
wa_fcat–scrtext_m = ‘Material Type’.
APPEND wa_fcat to it_fcat.
CLEAR : wa_fcat.
wa_fcat–col_pos = ‘3’.
wa_fcat–fieldname = ‘MBRsh’.
wa_fcat–tabname = ‘MARA’.
wa_fcat–scrtext_m = ‘Induxtry sector’.
APPEND wa_fcat to it_fcat.
CLEAR : wa_fcat.
SELECT matnr
mtart
mbrsh
FROM mara
into TABLE it_mara
UP TO 50 ROWS.
CALL METHOD lv_alv->set_table_for_first_display
EXPORTING
* i_buffer_active =
* i_bypassing_buffer =
* i_consistency_check =
i_structure_name = ‘ty_MARA’
* is_variant =
* i_save =
* 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 = it_mara
it_fieldcatalog = it_fcat
* it_sort =
* it_filter =
* EXCEPTIONS
* invalid_parameter_combination = 1
* program_error = 2
* too_many_lines = 3
* others = 4
.
IF sy–subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDMODULE. ” STATUS_0100 OUTPUT