Search on this Website

Saturday, June 2, 2007

Dynamic selection on ALV at run time

We also using selection groups like radiogrouos and etc. This code making this features on ALV.


REPORT ytest .

* Based on: BCALV_GRID_DEMO.

TYPE-POOLS: icon.

TYPES: BEGIN OF ty_s_sflight.
INCLUDE TYPE sflight.
TYPES: button1 TYPE lvc_emphsz.
TYPES: button2 TYPE lvc_emphsz.
TYPES: button3 TYPE lvc_emphsz.
TYPES: button4 TYPE lvc_emphsz.
TYPES: END OF ty_s_sflight.


DATA:
gt_sflight TYPE STANDARD TABLE OF ty_s_sflight,
gt_fcat TYPE lvc_t_fcat.

DATA: ok_code LIKE sy-ucomm,
* gt_sflight TYPE TABLE OF sflight,
g_container TYPE scrfname VALUE ‘BCALV_GRID_DEMO_0100_CONT1′,
grid1 TYPE REF TO cl_gui_alv_grid,
g_custom_container TYPE REF TO cl_gui_custom_container.

*———————————————————————*
* CLASS lcl_eventhandler DEFINITION
*———————————————————————*
*
*———————————————————————*
CLASS lcl_eventhandler DEFINITION.

PUBLIC SECTION.

CLASS-DATA:
md_cnt TYPE i.

CLASS-METHODS:
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING
e_row_id
e_column_id
es_row_no
sender.

ENDCLASS. “lcl_eventhandler DEFINITION

*———————————————————————*
* CLASS lcl_eventhandler IMPLEMENTATION
*———————————————————————*
*
*———————————————————————*
CLASS lcl_eventhandler IMPLEMENTATION.

METHOD handle_hotspot_click.
* define local data
FIELD-SYMBOLS:
TYPE ty_s_sflight,
TYPE ANY.

READ TABLE gt_sflight ASSIGNING INDEX es_row_no-row_id.
CHECK ( IS ASSIGNED ).

* Set all radio buttons “unselected”
-button1 = ICON_CANCEL.
-button2 = ICON_CANCEL.
-button3 = ICON_CANCEL.
-button4 = ICON_CANCEL.

ASSIGN COMPONENT e_column_id-fieldname OF STRUCTURE
TO .
IF ( IS ASSIGNED ).
* Set selected radio button “selected”.
= ICON_OKAY.
ENDIF.

* Force PAI followed by refresh of table display in PBO
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = ‘DUMMY’
* IMPORTING
* RC =
.

ENDMETHOD. “handle_hotspot_click

ENDCLASS. “lcl_eventhandler IMPLEMENTATION

START-OF-SELECTION.

*———————————————————————*
* MAIN *
*———————————————————————*

PERFORM select_data.

CALL SCREEN 100.

*———————————————————————*
* MODULE PBO OUTPUT *
*———————————————————————*
MODULE pbo OUTPUT.
SET PF-STATUS ‘MAIN100′.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING container_name = g_container.
CREATE OBJECT grid1
EXPORTING i_parent = g_custom_container.

PERFORM build_fieldcatalog.

CALL METHOD grid1->set_table_for_first_display
* EXPORTING
* i_structure_name = ‘SFLIGHT’
CHANGING
it_fieldcatalog = gt_fcat
it_outtab = gt_sflight.

* Set event handler for event TOOLBAR
SET HANDLER:
lcl_eventhandler=>handle_hotspot_click FOR grid1.

else.
CALL METHOD grid1->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
FINISHED = 1
others = 2.
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. “PBO OUTPUT
*———————————————————————*
* MODULE PAI INPUT *
*———————————————————————*
MODULE pai INPUT.
* to react on oi_custom_events:
CALL METHOD cl_gui_cfw=>dispatch.
* CASE ok_code.
CASE sy-ucomm.
WHEN ‘EXIT’.
PERFORM exit_program.
WHEN OTHERS.
* do nothing
ENDCASE.
CLEAR ok_code.
ENDMODULE. “PAI INPUT
*———————————————————————*
* FORM EXIT_PROGRAM *
*———————————————————————*
FORM exit_program.
* CALL METHOD G_CUSTOM_CONTAINER->FREE.
* CALL METHOD CL_GUI_CFW=>FLUSH.
LEAVE PROGRAM.
ENDFORM. “EXIT_PROGRAM

*&———————————————————————*
*& Form BUILD_FIELDCATALOG
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DELETE gt_fcat WHERE ( fieldname ‘EMPHASIZE’ ).

CALL FUNCTION ‘LVC_FIELDCATALOG_MERGE’
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = ‘SFLIGHT’
* I_CLIENT_NEVER_DISPLAY = ‘X’
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_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.

READ TABLE gt_fcat INTO ls_fcat
WITH KEY fieldname = ‘EMPHASIZE’.
IF ( syst-subrc = 0 ).
DELETE gt_fcat INDEX syst-tabix.
ENDIF.

ls_fcat-fieldname = ‘BUTTON4′.
ls_fcat-icon = ‘X’.
ls_fcat-hotspot = ‘X’.
INSERT ls_fcat INTO gt_fcat INDEX 4.
*
ls_fcat-fieldname = ‘BUTTON3′.
INSERT ls_fcat INTO gt_fcat INDEX 4.
*
ls_fcat-fieldname = ‘BUTTON2′.
INSERT ls_fcat INTO gt_fcat INDEX 4.
*
ls_fcat-fieldname = ‘BUTTON1′.
INSERT ls_fcat INTO gt_fcat INDEX 4.

LOOP AT gt_fcat INTO ls_fcat.
ls_fcat-col_pos = syst-tabix.
MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
ENDLOOP.

ENDFORM. ” BUILD_FIELDCATALOG

*&———————————————————————*
*& Form SELECT_DATA
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
*

No comments: