Sample OOPS ALV with Docking Container
*&---------------------------------------------------------------------*
*& Report ZACHI_TEST_ALV_DOCK
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zachi_test_alv_dock.
CONSTANTS: n TYPE i VALUE '10'.
CLASS lcl_event_rcvr DEFINITION DEFERRED.
DATA: go_cont TYPE REF TO cl_gui_docking_container,
go_alv TYPE REF TO cl_gui_alv_grid,
go_event TYPE REF TO lcl_event_rcvr,
go_toolbar TYPE REF TO cl_alv_event_toolbar_set.
TYPES: BEGIN OF ty_data ,
object_id LIKE crmd_orderadm_h-object_id,
process_type LIKE crmd_orderadm_h-process_type,
posting_date LIKE crmd_orderadm_h-posting_date,
style TYPE lvc_t_styl,
END OF ty_data.
DATA: gt_data TYPE STANDARD TABLE OF ty_data,
wa_data TYPE ty_data,
gs_lay TYPE lvc_s_layo,
it_fcat TYPE lvc_t_fcat,
it_fcat2 TYPE lvc_t_fcat, "After Change
wa_fcat TYPE lvc_s_fcat,
wa_tool TYPE stb_button,
wa_style TYPE lvc_s_styl.
*----------------------------------------------------------------------*
* CLASS lcl_event_rcvr DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_rcvr DEFINITION.
PUBLIC SECTION.
METHODS:
handle_dbl_clk FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column,
handle_lay_chng FOR EVENT after_user_command OF cl_gui_alv_grid
IMPORTING e_ucomm e_saved e_not_processed,
set_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive.
ENDCLASS. "lcl_event_rcvr DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_rcvr IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_rcvr IMPLEMENTATION.
METHOD handle_dbl_clk.
READ TABLE gt_data INDEX e_row INTO wa_data.
IF sy-subrc EQ 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = 'Row Number'
txt1 = e_row
txt2 = e_column
* TXT3 = ' '
* TXT4 = ' '
.
ENDIF.
ENDMETHOD. "handle_dbl_clk
METHOD handle_lay_chng.
DATA: wa_fcat2 LIKE wa_fcat.
CASE e_ucomm.
WHEN '&COL0'.
CALL METHOD go_alv->get_frontend_fieldcatalog
IMPORTING
et_fieldcatalog = it_fcat2.
LOOP AT it_fcat2 INTO wa_fcat2.
CLEAR wa_fcat.
READ TABLE it_fcat INTO wa_fcat WITH KEY fieldname = wa_fcat2-fieldname.
wa_fcat2-col_pos = wa_fcat-col_pos.
IF wa_fcat2-fieldname = 'OBJECT_ID'.
IF wa_fcat2-no_out = 'X'.
wa_fcat2-no_out = space.
ENDIF.
ENDIF.
MODIFY it_fcat2 FROM wa_fcat2.
ENDLOOP.
CALL METHOD go_alv->set_frontend_fieldcatalog
EXPORTING
it_fieldcatalog = it_fcat2.
WHEN 'CUST'.
MESSAGE i001(00) WITH 'Hello'.
WHEN OTHERS.
ENDCASE.
ENDMETHOD. "handle_lay_chng
METHOD set_toolbar.
wa_tool-function = 'CUST'.
wa_tool-text = 'Custom Func'.
wa_tool-butn_type = 0.
APPEND wa_tool TO e_object->mt_toolbar.
ENDMETHOD. "set_toolbar
ENDCLASS. "lcl_event_rcvr IMPLEMENTATION
START-OF-SELECTION.
*---- Data Retrieval --------*
SELECT object_id
process_type
posting_date
INTO CORRESPONDING FIELDS OF TABLE gt_data
FROM crmd_orderadm_h
UP TO n ROWS.
CALL SCREEN 9100.
*&---------------------------------------------------------------------*
*& Module ALV_OUTPUT OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE alv_output OUTPUT.
IF go_cont IS INITIAL.
SET PF-STATUS 'ALV_GUI'.
PERFORM sub_init_container.
PERFORM sub_init_alv_grid.
PERFORM sub_field_cat.
*---- Making 3rd row non-editable.
CLEAR wa_style.
wa_style-fieldname = 'POSTING_DATE'.
wa_style-style = cl_gui_alv_grid=>mc_style_disabled.
REFRESH wa_data-style.
APPEND wa_style TO wa_data-style.
MODIFY gt_data FROM wa_data INDEX 3 TRANSPORTING style.
*create OBJECT go_toolbar.
CREATE OBJECT go_event.
SET HANDLER go_event->handle_dbl_clk FOR go_alv.
SET HANDLER go_event->handle_lay_chng FOR go_alv.
SET HANDLER go_event->set_toolbar FOR go_alv.
CALL METHOD go_alv->set_table_for_first_display
EXPORTING
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* I_CONSISTENCY_CHECK =
* I_STRUCTURE_NAME =
* IS_VARIANT =
* I_SAVE =
* I_DEFAULT = 'X'
is_layout = gs_lay
* IS_PRINT =
* IT_SPECIAL_GROUPS =
* IT_TOOLBAR_EXCLUDING =
* IT_HYPERLINK =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO =
* IR_SALV_ADAPTER =
CHANGING
it_outtab = gt_data
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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDMODULE. " ALV_OUTPUT OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9100 INPUT.
CASE sy-ucomm.
WHEN 'CANCEL' OR 'EXIT'.
PERFORM sub_free_object.
LEAVE PROGRAM.
WHEN 'BACK'.
PERFORM sub_free_object.
SET SCREEN '0'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_9100 INPUT
*&---------------------------------------------------------------------*
*& Form SUB_CREATE_CONTAINER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM sub_init_container .
*--- Create Container -------------------*
CREATE OBJECT go_cont
EXPORTING
* parent =
* repid =
* dynnr =
* side = dock_at_left
* extension = 50
* style =
* lifetime = lifetime_default
* caption =
* metric = 0
ratio = '100'
* no_autodef_progid_dynnr =
* name =
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.
ENDFORM. " SUB_CREATE_CONTAINER
*&---------------------------------------------------------------------*
*& Form SUB_INIT_ALV_GRID
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM sub_init_alv_grid .
*--- Create Alv Grid ---------------------*
CREATE OBJECT go_alv
EXPORTING
* i_shellstyle = 0
* i_lifetime =
i_parent = go_cont
* 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.
ENDFORM. " SUB_INIT_ALV_GRID
*&---------------------------------------------------------------------*
*& Form SUB_FIELD_CAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM sub_field_cat .
gs_lay-grid_title = 'Order Data'.
gs_lay-zebra = 'X'.
gs_lay-stylefname = 'STYLE'.
CLEAR wa_fcat.
wa_fcat-fieldname = 'OBJECT_ID'.
wa_fcat-tabname = 'GT_DATA'.
wa_fcat-ref_table = 'CRMD_ORDERADM_H'.
wa_fcat-ref_field = 'OBJECT_ID'.
wa_fcat-col_pos = 1.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'PROCESS_TYPE'.
wa_fcat-tabname = 'GT_DATA'.
wa_fcat-ref_table = 'CRMD_ORDERADM_H'.
wa_fcat-ref_field = 'PROCESS_TYPE'.
wa_fcat-col_pos = 2.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'POSTING_DATE'.
wa_fcat-tabname = 'GT_DATA'.
wa_fcat-ref_table = 'CRMD_ORDERADM_H'.
wa_fcat-ref_field = 'POSTING_DATE'.
wa_fcat-edit = 'X'.
wa_fcat-col_pos = 3.
APPEND wa_fcat TO it_fcat.
ENDFORM. " SUB_FIELD_CAT
*&---------------------------------------------------------------------*
*& Form SUB_FREE_OBJECT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM sub_free_object .
IF go_alv IS NOT INITIAL.
CALL METHOD go_alv->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
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.
IF go_cont IS NOT INITIAL.
CALL METHOD go_cont->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
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. " SUB_FREE_OBJECT
*& Report ZACHI_TEST_ALV_DOCK
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zachi_test_alv_dock.
CONSTANTS: n TYPE i VALUE '10'.
CLASS lcl_event_rcvr DEFINITION DEFERRED.
DATA: go_cont TYPE REF TO cl_gui_docking_container,
go_alv TYPE REF TO cl_gui_alv_grid,
go_event TYPE REF TO lcl_event_rcvr,
go_toolbar TYPE REF TO cl_alv_event_toolbar_set.
TYPES: BEGIN OF ty_data ,
object_id LIKE crmd_orderadm_h-object_id,
process_type LIKE crmd_orderadm_h-process_type,
posting_date LIKE crmd_orderadm_h-posting_date,
style TYPE lvc_t_styl,
END OF ty_data.
DATA: gt_data TYPE STANDARD TABLE OF ty_data,
wa_data TYPE ty_data,
gs_lay TYPE lvc_s_layo,
it_fcat TYPE lvc_t_fcat,
it_fcat2 TYPE lvc_t_fcat, "After Change
wa_fcat TYPE lvc_s_fcat,
wa_tool TYPE stb_button,
wa_style TYPE lvc_s_styl.
*----------------------------------------------------------------------*
* CLASS lcl_event_rcvr DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_rcvr DEFINITION.
PUBLIC SECTION.
METHODS:
handle_dbl_clk FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column,
handle_lay_chng FOR EVENT after_user_command OF cl_gui_alv_grid
IMPORTING e_ucomm e_saved e_not_processed,
set_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive.
ENDCLASS. "lcl_event_rcvr DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_rcvr IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_rcvr IMPLEMENTATION.
METHOD handle_dbl_clk.
READ TABLE gt_data INDEX e_row INTO wa_data.
IF sy-subrc EQ 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = 'Row Number'
txt1 = e_row
txt2 = e_column
* TXT3 = ' '
* TXT4 = ' '
.
ENDIF.
ENDMETHOD. "handle_dbl_clk
METHOD handle_lay_chng.
DATA: wa_fcat2 LIKE wa_fcat.
CASE e_ucomm.
WHEN '&COL0'.
CALL METHOD go_alv->get_frontend_fieldcatalog
IMPORTING
et_fieldcatalog = it_fcat2.
LOOP AT it_fcat2 INTO wa_fcat2.
CLEAR wa_fcat.
READ TABLE it_fcat INTO wa_fcat WITH KEY fieldname = wa_fcat2-fieldname.
wa_fcat2-col_pos = wa_fcat-col_pos.
IF wa_fcat2-fieldname = 'OBJECT_ID'.
IF wa_fcat2-no_out = 'X'.
wa_fcat2-no_out = space.
ENDIF.
ENDIF.
MODIFY it_fcat2 FROM wa_fcat2.
ENDLOOP.
CALL METHOD go_alv->set_frontend_fieldcatalog
EXPORTING
it_fieldcatalog = it_fcat2.
WHEN 'CUST'.
MESSAGE i001(00) WITH 'Hello'.
WHEN OTHERS.
ENDCASE.
ENDMETHOD. "handle_lay_chng
METHOD set_toolbar.
wa_tool-function = 'CUST'.
wa_tool-text = 'Custom Func'.
wa_tool-butn_type = 0.
APPEND wa_tool TO e_object->mt_toolbar.
ENDMETHOD. "set_toolbar
ENDCLASS. "lcl_event_rcvr IMPLEMENTATION
START-OF-SELECTION.
*---- Data Retrieval --------*
SELECT object_id
process_type
posting_date
INTO CORRESPONDING FIELDS OF TABLE gt_data
FROM crmd_orderadm_h
UP TO n ROWS.
CALL SCREEN 9100.
*&---------------------------------------------------------------------*
*& Module ALV_OUTPUT OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE alv_output OUTPUT.
IF go_cont IS INITIAL.
SET PF-STATUS 'ALV_GUI'.
PERFORM sub_init_container.
PERFORM sub_init_alv_grid.
PERFORM sub_field_cat.
*---- Making 3rd row non-editable.
CLEAR wa_style.
wa_style-fieldname = 'POSTING_DATE'.
wa_style-style = cl_gui_alv_grid=>mc_style_disabled.
REFRESH wa_data-style.
APPEND wa_style TO wa_data-style.
MODIFY gt_data FROM wa_data INDEX 3 TRANSPORTING style.
*create OBJECT go_toolbar.
CREATE OBJECT go_event.
SET HANDLER go_event->handle_dbl_clk FOR go_alv.
SET HANDLER go_event->handle_lay_chng FOR go_alv.
SET HANDLER go_event->set_toolbar FOR go_alv.
CALL METHOD go_alv->set_table_for_first_display
EXPORTING
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* I_CONSISTENCY_CHECK =
* I_STRUCTURE_NAME =
* IS_VARIANT =
* I_SAVE =
* I_DEFAULT = 'X'
is_layout = gs_lay
* IS_PRINT =
* IT_SPECIAL_GROUPS =
* IT_TOOLBAR_EXCLUDING =
* IT_HYPERLINK =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO =
* IR_SALV_ADAPTER =
CHANGING
it_outtab = gt_data
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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDMODULE. " ALV_OUTPUT OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9100 INPUT.
CASE sy-ucomm.
WHEN 'CANCEL' OR 'EXIT'.
PERFORM sub_free_object.
LEAVE PROGRAM.
WHEN 'BACK'.
PERFORM sub_free_object.
SET SCREEN '0'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_9100 INPUT
*&---------------------------------------------------------------------*
*& Form SUB_CREATE_CONTAINER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM sub_init_container .
*--- Create Container -------------------*
CREATE OBJECT go_cont
EXPORTING
* parent =
* repid =
* dynnr =
* side = dock_at_left
* extension = 50
* style =
* lifetime = lifetime_default
* caption =
* metric = 0
ratio = '100'
* no_autodef_progid_dynnr =
* name =
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.
ENDFORM. " SUB_CREATE_CONTAINER
*&---------------------------------------------------------------------*
*& Form SUB_INIT_ALV_GRID
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM sub_init_alv_grid .
*--- Create Alv Grid ---------------------*
CREATE OBJECT go_alv
EXPORTING
* i_shellstyle = 0
* i_lifetime =
i_parent = go_cont
* 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.
ENDFORM. " SUB_INIT_ALV_GRID
*&---------------------------------------------------------------------*
*& Form SUB_FIELD_CAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM sub_field_cat .
gs_lay-grid_title = 'Order Data'.
gs_lay-zebra = 'X'.
gs_lay-stylefname = 'STYLE'.
CLEAR wa_fcat.
wa_fcat-fieldname = 'OBJECT_ID'.
wa_fcat-tabname = 'GT_DATA'.
wa_fcat-ref_table = 'CRMD_ORDERADM_H'.
wa_fcat-ref_field = 'OBJECT_ID'.
wa_fcat-col_pos = 1.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'PROCESS_TYPE'.
wa_fcat-tabname = 'GT_DATA'.
wa_fcat-ref_table = 'CRMD_ORDERADM_H'.
wa_fcat-ref_field = 'PROCESS_TYPE'.
wa_fcat-col_pos = 2.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'POSTING_DATE'.
wa_fcat-tabname = 'GT_DATA'.
wa_fcat-ref_table = 'CRMD_ORDERADM_H'.
wa_fcat-ref_field = 'POSTING_DATE'.
wa_fcat-edit = 'X'.
wa_fcat-col_pos = 3.
APPEND wa_fcat TO it_fcat.
ENDFORM. " SUB_FIELD_CAT
*&---------------------------------------------------------------------*
*& Form SUB_FREE_OBJECT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM sub_free_object .
IF go_alv IS NOT INITIAL.
CALL METHOD go_alv->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
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.
IF go_cont IS NOT INITIAL.
CALL METHOD go_cont->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
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. " SUB_FREE_OBJECT
Comments
Post a Comment