REPORT ZTEST0000.
CLASS GRID_APPL DEFINITION DEFERRED.
CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.
* data for report and dynpro
DATA: INFO(80),
INPUT(20),
OK_CODE LIKE SY-UCOMM.
* data for grid
DATA: GS_LAYOUT TYPE LVC_S_LAYO,
GT_FIELDCAT TYPE LVC_T_FCAT,
GS_FIELDCAT TYPE LVC_S_FCAT.
DATA: RET.
*§10 define data table to handle drop down boxes
DATA: BEGIN OF GT_OUTTAB OCCURS 0.
INCLUDE STRUCTURE SFLIGHT .
DATA: DROP_DOWN_HANDLE TYPE INT4. "dropdown handle for a field
DATA: STYLE TYPE LVC_T_STYL.
DATA: VOLUME TYPE P DECIMALS 2.
DATA: QUANTITY(3) TYPE C. "Color for corresponding line
DATA: END OF GT_OUTTAB,
GS_OUTTAB LIKE LINE OF GT_OUTTAB.
* data for event handling
DATA: GS_F4 TYPE LVC_S_F4,
GT_F4 TYPE LVC_T_F4.
DATA: GT_OUTTAB_TEST TYPE TABLE OF SPFLI.
* custom control and grid_application object
DATA: MY_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
MY_APPLICATION TYPE REF TO GRID_APPL.
DATA: GS_VARIANT TYPE DISVARIANT.
DATA: MY_EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.
*---------------------------------------------------------------------*
* CLASS grid_appl DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
CLASS GRID_APPL DEFINITION.
PUBLIC SECTION.
DATA: MY_GRID TYPE REF TO CL_GUI_ALV_GRID.
METHODS: CONSTRUCTOR,
RESET_TABLE,
TEST_MODUS,
CHECK_INPUT
CHANGING IR_DATA_CHANGED
TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
ENDCLASS. "grid_appl
*---------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
METHODS: ON_F4 FOR EVENT ONF4 OF CL_GUI_ALV_GRID
IMPORTING SENDER
E_FIELDNAME
E_FIELDVALUE
ES_ROW_NO
ER_EVENT_DATA
ET_BAD_CELLS
E_DISPLAY,
ON_DATA_CHANGED FOR EVENT
DATA_CHANGED OF CL_GUI_ALV_GRID
IMPORTING E_ONF4
E_ONF4_BEFORE
E_ONF4_AFTER
ER_DATA_CHANGED
E_UCOMM
SENDER,
ON_DATA_CHANGED_FINISHED FOR EVENT DATA_CHANGED_FINISHED
OF CL_GUI_ALV_GRID
IMPORTING SENDER,
ON_BUTTON_CLICK FOR EVENT
BEFORE_USER_COMMAND OF CL_GUI_ALV_GRID
IMPORTING SENDER.
PRIVATE SECTION.
TYPES: DDSHRETVAL_TABLE TYPE TABLE OF DDSHRETVAL.
DATA : LR_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
METHODS: MY_F4
IMPORTING SENDER TYPE REF TO CL_GUI_ALV_GRID
ET_BAD_CELLS TYPE LVC_T_MODI
ES_ROW_NO TYPE LVC_S_ROID
ER_EVENT_DATA TYPE REF TO CL_ALV_EVENT_DATA
E_DISPLAY TYPE C
E_FIELDNAME TYPE LVC_FNAME
EXPORTING LT_F4 TYPE DDSHRETVAL_TABLE.
ENDCLASS. "lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
* SELECTION-SCREEN *
*----------------------------------------------------------------------*
PARAMETERS: P_MAXROW TYPE I DEFAULT 60.
SELECTION-SCREEN BEGIN OF BLOCK TAB WITH FRAME TITLE TEXT-011.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: NO_INP RADIOBUTTON GROUP TAB1.
SELECTION-SCREEN COMMENT 5(15) TEXT-017.
PARAMETERS USER_INP RADIOBUTTON GROUP TAB1.
SELECTION-SCREEN COMMENT 25(15) TEXT-018.
PARAMETERS DROP_DO RADIOBUTTON GROUP TAB1 DEFAULT 'X'.
SELECTION-SCREEN COMMENT 45(15) TEXT-019.
PARAMETERS TEST_MOD RADIOBUTTON GROUP TAB1.
SELECTION-SCREEN COMMENT 65(15) TEXT-013.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK TAB.
SELECTION-SCREEN BEGIN OF BLOCK V WITH FRAME TITLE TEXT-012.
PARAMETERS: CHECK_BE AS CHECKBOX,
CHN_AFT AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK V.
SELECTION-SCREEN BEGIN OF BLOCK W WITH FRAME TITLE TEXT-014.
PARAMETERS: TEST_TAB AS CHECKBOX,
EXP_DATA AS CHECKBOX,
DATA_TYP AS CHECKBOX,
EXP_FIEL AS CHECKBOX,
CONS_VAL AS CHECKBOX.
SELECTION-SCREEN BEGIN OF BLOCK X WITH FRAME TITLE TEXT-022.
PARAMETERS: INIT_CH AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK X.
SELECTION-SCREEN END OF BLOCK W.
*----------------------------------------------------------------------*
* START-OF-SELECTION *
*----------------------------------------------------------------------*
START-OF-SELECTION.
GS_VARIANT-REPORT = SY-REPID.
*----------------------------------------------------------------------*
* END-OF-SELECTION *
*----------------------------------------------------------------------*
END-OF-SELECTION.
CALL SCREEN 200.
*&---------------------------------------------------------------------*
*& Form fill_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
MODULE FILL_DATA OUTPUT.
CHECK RET EQ SPACE.
CASE 'X'.
WHEN DROP_DO.
INFO = TEXT-008.
WHEN NO_INP.
INFO = TEXT-003.
WHEN USER_INP.
IF CHECK_BE = ' '.
IF CHN_AFT = ' '.
INFO = TEXT-006.
ELSE.
INFO = TEXT-002.
ENDIF.
ELSE.
IF CHN_AFT = 'X'.
INFO = TEXT-007.
ELSE.
INFO = TEXT-005.
ENDIF.
ENDIF.
ENDCASE.
IF TEST_MOD = 'X'.
SELECT * FROM SPFLI INTO TABLE GT_OUTTAB_TEST UP TO P_MAXROW ROWS.
INFO = TEXT-015.
ELSE.
SELECT * FROM SFLIGHT INTO CORRESPONDING FIELDS OF TABLE GT_OUTTAB[]
UP TO P_MAXROW ROWS. "#EC CI_NOWHERE
ENDIF.
ENDMODULE. " fill_data
*---------------------------------------------------------------------*
* MODULE exit2 INPUT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
MODULE EXIT2 INPUT.
RET = ' '.
CASE OK_CODE.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'CANCEL'.
LEAVE PROGRAM.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'OK'.
RET = 'X'.
ENDCASE.
ENDMODULE. "exit2 INPUT
*&---------------------------------------------------------------------*
*& Module set_status2 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE SET_STATUS2 OUTPUT.
SET PF-STATUS 'MAIN200'.
SET TITLEBAR 'MAIN200'.
ENDMODULE. " set_status2 OUTPUT
*&---------------------------------------------------------------------*
*& Module create_objects OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE CREATE_OBJECTS OUTPUT.
IF MY_CONTAINER IS INITIAL.
CREATE OBJECT MY_CONTAINER
EXPORTING
CONTAINER_NAME = 'CONTAINER'.
CREATE OBJECT MY_APPLICATION.
CREATE OBJECT MY_EVENT_RECEIVER.
SET HANDLER MY_EVENT_RECEIVER->ON_F4 FOR ALL INSTANCES.
SET HANDLER MY_EVENT_RECEIVER->ON_DATA_CHANGED
FOR ALL INSTANCES.
SET HANDLER MY_EVENT_RECEIVER->ON_BUTTON_CLICK FOR ALL
INSTANCES.
SET HANDLER MY_EVENT_RECEIVER->ON_DATA_CHANGED_FINISHED FOR ALL
INSTANCES.
ELSEIF TEST_MOD = 'X'.
CALL METHOD MY_APPLICATION->TEST_MODUS.
ELSE.
CALL METHOD MY_APPLICATION->RESET_TABLE.
ENDIF.
ENDMODULE. " create_objects OUTPUT
*&---------------------------------------------------------------------*
*& Class (Implementation) grid_appl
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
CLASS GRID_APPL IMPLEMENTATION.
METHOD CONSTRUCTOR.
* instantiate the grid
CREATE OBJECT MY_GRID
EXPORTING
I_PARENT = MY_CONTAINER.
IF TEST_MOD = 'X'.
CALL METHOD TEST_MODUS.
ELSE.
CALL METHOD RESET_TABLE.
ENDIF.
ENDMETHOD. "constructor
*---------------------------------------------------------------------*
* METHOD test_modus this method is for internal use only *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
METHOD TEST_MODUS.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'SPFLI'
CHANGING
CT_FIELDCAT = GT_FIELDCAT.
LOOP AT GT_FIELDCAT INTO GS_FIELDCAT.
IF GS_FIELDCAT-FIELDNAME = 'FLTYPE'.
GS_FIELDCAT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
MODIFY GT_FIELDCAT FROM GS_FIELDCAT INDEX SY-TABIX.
ENDIF.
IF TEST_TAB = 'X' AND GS_FIELDCAT-FIELDNAME = 'CARRID'.
GS_FIELDCAT-EDIT = 'X'.
* gs_fieldcat-no_init_ch = 'X'.
MODIFY GT_FIELDCAT FROM GS_FIELDCAT INDEX SY-TABIX.
ENDIF.
IF CONS_VAL = 'X' AND GS_FIELDCAT-FIELDNAME = 'FLTYPE'.
GS_FIELDCAT-EDIT = 'X'.
MODIFY GT_FIELDCAT FROM GS_FIELDCAT INDEX SY-TABIX.
ENDIF.
IF INIT_CH = 'X' AND GS_FIELDCAT-FIELDNAME = 'FLTIME'.
GS_FIELDCAT-NO_INIT_CH = 'X'.
MODIFY GT_FIELDCAT FROM GS_FIELDCAT INDEX SY-TABIX.
ENDIF.
IF DATA_TYP = 'X' AND GS_FIELDCAT-FIELDNAME = 'DEPTIME'.
GS_FIELDCAT-EDIT = 'X'.
MODIFY GT_FIELDCAT FROM GS_FIELDCAT INDEX SY-TABIX.
ENDIF.
IF EXP_FIEL = 'X' AND GS_FIELDCAT-FIELDNAME = 'DISTID'.
GS_FIELDCAT-EDIT = 'X'.
MODIFY GT_FIELDCAT FROM GS_FIELDCAT INDEX SY-TABIX.
ENDIF.
IF EXP_DATA = 'X' AND GS_FIELDCAT-FIELDNAME = 'AIRPFROM'.
GS_FIELDCAT-NO_INIT_CH = 'X'.
GS_FIELDCAT-EDIT = 'X'.
MODIFY GT_FIELDCAT FROM GS_FIELDCAT INDEX SY-TABIX.
ENDIF.
IF GS_FIELDCAT-FIELDNAME = 'PERIOD'.
GS_FIELDCAT-TECH = 'X'.
MODIFY GT_FIELDCAT FROM GS_FIELDCAT INDEX SY-TABIX.
ENDIF.
ENDLOOP.
* test for exceptions!
GS_LAYOUT-EXCP_FNAME = 'FLTYPE'.
DATA: LS_FIELD LIKE LINE OF GT_OUTTAB_TEST.
LOOP AT GT_OUTTAB_TEST INTO LS_FIELD.
LS_FIELD-FLTYPE = '1'.
MODIFY GT_OUTTAB_TEST FROM LS_FIELD.
ENDLOOP.
* test for exceptions!
CALL METHOD MY_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME = 'SPFLI'
IS_LAYOUT = GS_LAYOUT
IS_VARIANT = GS_VARIANT
I_SAVE = 'U'
CHANGING
IT_OUTTAB = GT_OUTTAB_TEST
IT_FIELDCATALOG = GT_FIELDCAT.
CALL METHOD MY_GRID->SET_READY_FOR_INPUT
EXPORTING
I_READY_FOR_INPUT = '1'.
DATA: TAB TYPE LVC_T_ROW,
ROW TYPE LVC_S_ROW.
APPEND ROW TO TAB.
APPEND ROW TO TAB.
CALL METHOD MY_GRID->GET_SELECTED_ROWS
IMPORTING
ET_INDEX_ROWS = TAB.
ENDMETHOD. "test_modus
*---------------------------------------------------------------------*
* METHOD reset_table *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
METHOD RESET_TABLE.
CHECK RET EQ SPACE.
* prepare fieldcatalog
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
CHANGING
CT_FIELDCAT = GT_FIELDCAT.
*§4 set those columns editable, for which user input via f4 or drop
* down is allowed.
LOOP AT GT_FIELDCAT INTO GS_FIELDCAT.
IF GS_FIELDCAT-FIELDNAME = 'CONNID'.
GS_FIELDCAT-EDIT = 'X'.
MODIFY GT_FIELDCAT FROM GS_FIELDCAT INDEX SY-TABIX.
ENDIF.
IF CHECK_BE = 'X' AND USER_INP = 'X'
AND GS_FIELDCAT-FIELDNAME = 'CARRID'.
GS_FIELDCAT-EDIT = 'X'.
MODIFY GT_FIELDCAT FROM GS_FIELDCAT INDEX SY-TABIX.
ENDIF.
*§10 Register drop down at fieldcatalog.
IF DROP_DO = 'X' AND GS_FIELDCAT-FIELDNAME = 'PRICE'.
GS_FIELDCAT-EDIT = 'X'.
GS_FIELDCAT-DRDN_FIELD = 'DROP_DOWN_HANDLE'.
GS_FIELDCAT-DRDN_ALIAS = 'X'.
MODIFY GT_FIELDCAT FROM GS_FIELDCAT INDEX SY-TABIX.
ENDIF.
*§10b Register drop down at fieldcatalog for a column wide drop down.
IF DROP_DO = 'X' AND GS_FIELDCAT-FIELDNAME = 'CONNID'.
GS_FIELDCAT-EDIT = 'X'.
GS_FIELDCAT-DRDN_HNDL = '3'.
* gs_fieldcat-drdn_alias = 'X'.
MODIFY GT_FIELDCAT FROM GS_FIELDCAT INDEX SY-TABIX.
ENDIF.
*§8 set parameter F4AVAILABL in the fieldcatalog if you want to define
* an f4-help for a column without standard f4-help.
IF NO_INP = 'X' AND GS_FIELDCAT-FIELDNAME = 'PRICE'.
GS_FIELDCAT-F4AVAILABL = 'X'.
MODIFY GT_FIELDCAT FROM GS_FIELDCAT INDEX SY-TABIX.
ENDIF.
ENDLOOP.
*§11 prepare grid for drop down.
DATA: LT_DROPDOWN TYPE LVC_T_DROP,
LS_DROPDOWN TYPE LVC_S_DROP,
LT_DROPDOWN_AL TYPE LVC_T_DRAL,
LS_DROPDOWN_AL TYPE LVC_S_DRAL.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '9'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '7'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '89'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '99'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '77'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '474'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '79'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '57'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '964'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '94'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '78'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '389'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '399'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '377'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '3474'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '379'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '357'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '3964'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '394'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '378'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = '454'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '3'.
LS_DROPDOWN-VALUE = '17'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN-HANDLE = '3'.
LS_DROPDOWN-VALUE = '33'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
LS_DROPDOWN_AL-HANDLE = '2'.
LS_DROPDOWN_AL-VALUE = 'first'.
LS_DROPDOWN_AL-INT_VALUE = '12345'.
APPEND LS_DROPDOWN_AL TO LT_DROPDOWN_AL.
LS_DROPDOWN_AL-HANDLE = '2'.
LS_DROPDOWN_AL-VALUE = 'second'.
LS_DROPDOWN_AL-INT_VALUE = '23455'.
APPEND LS_DROPDOWN_AL TO LT_DROPDOWN_AL.
* call method my_grid->set_drop_down_table
* exporting
* it_drop_down_alias = lt_dropdown_al.
*
* clear lt_dropdown_al.
*
* ls_dropdown_al-handle = '2'.
* ls_dropdown_al-value = 'first'.
* ls_dropdown_al-int_value = '11111'.
* append ls_dropdown_al to lt_dropdown_al.
* ls_dropdown_al-handle = '2'.
* ls_dropdown_al-value = 'second'.
* ls_dropdown_al-int_value = '22222'.
* append ls_dropdown_al to lt_dropdown_al.
* ls_dropdown_al-handle = '2'.
* ls_dropdown_al-int_value = '33333'.
* ls_dropdown_al-value = 'third'.
* append ls_dropdown_al to lt_dropdown_al.
CALL METHOD MY_GRID->SET_DROP_DOWN_TABLE
EXPORTING
IT_DROP_DOWN = LT_DROPDOWN.
* it_drop_down_alias = lt_dropdown_al.
* sttyletest!!1
GS_LAYOUT-STYLEFNAME = 'STYLE'.
DATA: CELL TYPE LVC_S_STYL,
CELLTAB TYPE LVC_T_STYL.
CELL-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_NO_DELETE_ROW.
APPEND CELL TO CELLTAB.
LOOP AT GT_OUTTAB INTO GS_OUTTAB.
IF SY-TABIX = 1.
GS_OUTTAB-STYLE = CELLTAB.
ENDIF.
IF GS_OUTTAB-CONNID = '0017'.
GS_OUTTAB-DROP_DOWN_HANDLE = 1.
ELSEIF GS_OUTTAB-CONNID = '0064'.
GS_OUTTAB-DROP_DOWN_HANDLE = 3.
ENDIF.
MODIFY GT_OUTTAB FROM GS_OUTTAB INDEX SY-TABIX.
ENDLOOP.
* quantities
CLEAR GS_FIELDCAT.
GS_FIELDCAT-FIELDNAME = 'VOLUME'.
GS_FIELDCAT-INTTYPE = 'P'.
GS_FIELDCAT-INTLEN = 5.
GS_FIELDCAT-REPTEXT = 'Volume'. "#EC NOTEXT
GS_FIELDCAT-DECIMALS = 2.
GS_FIELDCAT-COL_POS = 99.
GS_FIELDCAT-QFIELDNAME = 'QUANTITY'.
GS_FIELDCAT-EDIT = 'X'.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
CLEAR GS_FIELDCAT.
GS_FIELDCAT-FIELDNAME = 'QUANTITY'.
GS_FIELDCAT-INTTYPE = 'C'.
GS_FIELDCAT-REPTEXT = 'Measure'. "#EC NOTEXT
GS_FIELDCAT-INTLEN = 3.
GS_FIELDCAT-COL_POS = 98.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
LOOP AT GT_OUTTAB INTO GS_OUTTAB.
GS_OUTTAB-VOLUME = '0.55'.
IF SY-TABIX < 10.
GS_OUTTAB-QUANTITY = 'STD'.
ELSEIF SY-TABIX < 20.
GS_OUTTAB-QUANTITY = 'C36'.
ELSEIF SY-TABIX < 30.
GS_OUTTAB-QUANTITY = 'KG'.
ENDIF.
MODIFY GT_OUTTAB FROM GS_OUTTAB.
ENDLOOP.
* set table for first display
CALL METHOD MY_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
* i_structure_name = 'SFLIGHT'
IS_LAYOUT = GS_LAYOUT
CHANGING
IT_OUTTAB = GT_OUTTAB[]
IT_FIELDCATALOG = GT_FIELDCAT.
CALL METHOD MY_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.
IF USER_INP = 'X' OR DROP_DO = 'X'.
CALL METHOD MY_GRID->SET_READY_FOR_INPUT
EXPORTING
I_READY_FOR_INPUT = 1.
ELSE.
CALL METHOD MY_GRID->SET_READY_FOR_INPUT
EXPORTING
I_READY_FOR_INPUT = 0.
ENDIF.
*§1 register f4-help, if a user-defined one should be used.
*§7a set parameter getbefore if you want to use values entered
* before raising event on_f4.
*§7b set parameter chngeafter if you want to use the values entered via
* f4 to manipulate other values of your table.
CLEAR GT_F4.
IF USER_INP = 'X'.
GS_F4-FIELDNAME = 'CONNID'.
GS_F4-REGISTER = 'X'.
GS_F4-GETBEFORE = CHECK_BE. "§7a
GS_F4-CHNGEAFTER = CHN_AFT. "§7b
APPEND GS_F4 TO GT_F4.
CALL METHOD MY_GRID->REGISTER_F4_FOR_FIELDS
EXPORTING
IT_F4 = GT_F4.
ELSEIF NO_INP = 'X'.
GS_F4-FIELDNAME = 'PRICE'.
GS_F4-REGISTER = 'X'.
APPEND GS_F4 TO GT_F4.
CALL METHOD MY_GRID->REGISTER_F4_FOR_FIELDS
EXPORTING
IT_F4 = GT_F4.
ENDIF.
ENDMETHOD. "new_table
*---------------------------------------------------------------------*
* METHOD check_input our check_data routine *
*---------------------------------------------------------------------*
* *
*---------------------------------------------------------------------*
METHOD CHECK_INPUT.
ENDMETHOD. "check_input
ENDCLASS. "grid_appl
*---------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
*§2 implement an event handler method
METHOD ON_F4.
DATA: LS_F4 TYPE DDSHRETVAL,
LT_F4 TYPE TABLE OF DDSHRETVAL.
*§8 you can define an f4-help for a column without standard f4-help
IF NO_INP = 'X'.
MESSAGE I087(0K) WITH ES_ROW_NO-ROW_ID E_FIELDVALUE.
*§3 set attribute m_event_handled of er_event_data to avoid standard
* f4-help.
ER_EVENT_DATA->M_EVENT_HANDLED = 'X'.
*§2 implement (a non-trivial) event handler which allows user input
ELSE.
*§5 define fields and field-symbols for data-update
FIELD-SYMBOLS: <ITAB> TYPE LVC_T_MODI.
DATA: LS_MODI TYPE LVC_S_MODI.
* now I call my personal f4-help
CALL METHOD MY_F4
EXPORTING
SENDER = SENDER
ES_ROW_NO = ES_ROW_NO
ER_EVENT_DATA = ER_EVENT_DATA
ET_BAD_CELLS = ET_BAD_CELLS
E_DISPLAY = E_DISPLAY
E_FIELDNAME = E_FIELDNAME
IMPORTING
LT_F4 = LT_F4.
*§6 assign the cell table fieldsymbol to the dereferenced data table and
* fill the table.
ASSIGN ER_EVENT_DATA->M_DATA->* TO <ITAB>.
READ TABLE LT_F4 INTO LS_F4 WITH KEY FIELDNAME = 'CONNID'.
IF NOT LS_F4 IS INITIAL.
LS_MODI-ROW_ID = ES_ROW_NO-ROW_ID.
LS_MODI-FIELDNAME = 'CONNID'.
LS_MODI-VALUE = LS_F4-FIELDVAL.
APPEND LS_MODI TO <ITAB>.
ENDIF.
*§7 in case you set chngeafter (change other values of your table after
* f4-help) when registering your f4-help, column 7 will change,
* depending on your choice for column 2. Notice that in this case
* value change in other columns just happens after f4, not after
* editing the grid directly. For value change after any editing you
* should use your event handler for event data_changed (see §9).
IF CHN_AFT = 'X'.
LS_MODI-ROW_ID = ES_ROW_NO-ROW_ID.
LS_MODI-FIELDNAME = 'SEATSMAX'.
CASE LS_F4-FIELDVAL.
WHEN '0017'.
LS_MODI-VALUE = 280.
WHEN '0026'.
LS_MODI-VALUE = 385.
WHEN '0064'.
LS_MODI-VALUE = 385.
WHEN '0555'.
LS_MODI-VALUE = 220.
WHEN OTHERS.
LS_MODI-VALUE = 999.
ENDCASE.
APPEND LS_MODI TO <ITAB>.
ENDIF.
ER_EVENT_DATA->M_EVENT_HANDLED = 'X'.
ENDIF.
ENDMETHOD. "on_f4
*---------------------------------------------------------------------*
* METHOD on_data_changed *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
*§9 catch event data_changed and check where it was raised for an
* appropriate action. We just have to check the case when users can
* put in the airline and f4-help is used for connection id.
METHOD ON_DATA_CHANGED.
DATA: IS_CELLS TYPE LVC_S_MODI.
DATA: LT_DROPDOWN TYPE LVC_T_DROP,
LS_DROPDOWN TYPE LVC_S_DROP,
LT_DROPDOWN_AL TYPE LVC_T_DRAL,
LS_DROPDOWN_AL TYPE LVC_S_DRAL.
LS_DROPDOWN-HANDLE = 1.
LS_DROPDOWN-VALUE = '89989'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.
* er_data_changed->refresh_protocol( ).
CALL METHOD SENDER->SET_DROP_DOWN_TABLE
EXPORTING
IT_DROP_DOWN = LT_DROPDOWN.
* call method er_data_changed->modify_cell
* exporting i_row_id = 1
* i_fieldname = 'PRICE'
* i_value = '3'
* i_tabix = 1.
IF E_ONF4 = ' '.
MESSAGE I084(0K).
ELSE.
CASE 'X'.
WHEN E_ONF4_AFTER.
MESSAGE I086(0K).
WHEN E_ONF4_BEFORE.
MESSAGE I085(0K).
CALL METHOD MY_APPLICATION->CHECK_INPUT
CHANGING
IR_DATA_CHANGED = ER_DATA_CHANGED.
WHEN OTHERS.
READ TABLE ER_DATA_CHANGED->MT_GOOD_CELLS INTO IS_CELLS INDEX 1.
IF SY-SUBRC EQ 0.
CALL METHOD ER_DATA_CHANGED->ADD_PROTOCOL_ENTRY
EXPORTING
I_MSGID = '0K'
I_MSGTY = 'E'
I_MSGNO = 000
I_MSGV1 = 'Error!' "#EC NOTEXT
I_FIELDNAME = IS_CELLS-FIELDNAME
I_ROW_ID = IS_CELLS-ROW_ID.
ER_DATA_CHANGED->DISPLAY_PROTOCOL( ).
ENDIF.
* message i088(0k).
ENDCASE.
ENDIF.
LR_DATA_CHANGED = ER_DATA_CHANGED.
ENDMETHOD. "on_data_changed
METHOD ON_BUTTON_CLICK.
DATA: LS_ROW_NO TYPE LVC_S_ROID,
LT_ROW_NO TYPE LVC_T_ROID,
LS_COL TYPE LVC_S_COL,
LS_ROW TYPE LVC_S_ROW.
LS_ROW_NO-ROW_ID = 2.
APPEND LS_ROW_NO TO LT_ROW_NO.
* my_application->my_grid->append_rows( 3 ).
ENDMETHOD. "on_button_click
METHOD ON_DATA_CHANGED_FINISHED.
DATA: LS_ROW_NO TYPE LVC_S_ROID,
LT_ROW_NO TYPE LVC_T_ROID,
LS_COL TYPE LVC_S_COL,
LS_ROW TYPE LVC_S_ROW.
LS_ROW_NO-ROW_ID = 2.
APPEND LS_ROW_NO TO LT_ROW_NO.
CALL METHOD SENDER->SET_SELECTED_ROWS
EXPORTING
IT_ROW_NO = LT_ROW_NO.
* data: lt_dropdown type lvc_t_drop,
* ls_dropdown type lvc_s_drop,
* lt_dropdown_al type lvc_t_dral,
* ls_dropdown_al type lvc_s_dral.
*
* ls_dropdown-handle = 1.
* ls_dropdown-value = '89989'.
* append ls_dropdown to lt_dropdown.
*
*
*
* call method sender->set_drop_down_table
* exporting
* it_drop_down = lt_dropdown.
* loop at gt_outtab into gs_outtab.
*
* gs_outtab-drop_down_handle = 3.
*
* modify gt_outtab from gs_outtab index sy-tabix.
* endloop.
ENDMETHOD. "on_data_changed_finished
*---------------------------------------------------------------------*
* METHOD my_f4 insert here your own f4-help *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
METHOD MY_F4.
DATA: WA_TAB LIKE LINE OF GT_OUTTAB,
LT_FCAT TYPE LVC_T_FCAT,
LS_FIELDCAT TYPE LVC_S_FCAT,
L_TABNAME TYPE DD03V-TABNAME,
L_FIELDNAME TYPE DD03V-FIELDNAME,
L_HELP_VALU TYPE HELP_INFO-FLDVALUE,
LT_BAD_CELL TYPE LVC_T_MODI,
LP_WA TYPE REF TO DATA.
FIELD-SYMBOLS: <L_FIELD_VALUE> TYPE ANY,
<LS_WA> TYPE ANY.
CALL METHOD SENDER->GET_FRONTEND_FIELDCATALOG
IMPORTING
ET_FIELDCATALOG = LT_FCAT.
READ TABLE GT_OUTTAB INDEX ES_ROW_NO-ROW_ID INTO WA_TAB.
CREATE DATA LP_WA LIKE LINE OF GT_OUTTAB.
ASSIGN LP_WA->* TO <LS_WA>.
<LS_WA> = WA_TAB.
READ TABLE LT_FCAT
WITH KEY FIELDNAME = E_FIELDNAME INTO LS_FIELDCAT.
MOVE LS_FIELDCAT-REF_TABLE TO L_TABNAME.
MOVE LS_FIELDCAT-FIELDNAME TO L_FIELDNAME.
ASSIGN COMPONENT LS_FIELDCAT-FIELDNAME
OF STRUCTURE WA_TAB
TO <L_FIELD_VALUE>.
WRITE <L_FIELD_VALUE> TO L_HELP_VALU.
PERFORM F4_SET IN PROGRAM BCALV_F4
USING SENDER
LT_FCAT
LT_BAD_CELL
ES_ROW_NO-ROW_ID
<LS_WA>.
CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
EXPORTING
TABNAME = L_TABNAME
FIELDNAME = L_FIELDNAME
DISPLAY = E_DISPLAY
CALLBACK_PROGRAM = 'BCALV_F4'
VALUE = L_HELP_VALU
CALLBACK_FORM = 'F4'
TABLES
RETURN_TAB = LT_F4.
ENDMETHOD. "my_f4
ENDCLASS. "lcl_event_receiver IMPLEMENTATION