Skip to end of metadata
Go to start of metadata
*************************************************************************************************
*GLOBAL DATA DECLARATION
*************************************************************************************************
TYPES: BEGIN OF ty_data,
state    TYPE cnv_10940_relev,
END OF ty_data.
DATA: gv_cont_0100       TYPE REF TO cl_gui_custom_container,
      gv_grid_0100       TYPE REF TO cl_gui_alv_grid,
      gs_f4              TYPE lvc_s_f4,
      gt_f4              TYPE lvc_t_f4,
      gt_data            TYPE TABLE OF ty_data,
      gt_ret             TYPE TABLE OF ddshretval,
      gs_layo_0100       TYPE lvc_s_layo,
      gs_fieldcat_0100   TYPE lvc_s_fcat,
      gt_fieldcat_0100   TYPE lvc_t_fcat,
      gt_exclude_0100    TYPE ui_functions,
      gs_exclude         TYPE ui_func,
      gv_change.
CONSTANTS: gc_x          VALUE 'X'.
FIELD-SYMBOLS: <itab> TYPE lvc_t_modi.
*************************************************************************************************
*LOCAL CLASS DEFINITION
*************************************************************************************************
*Class definition to handle the ONF4 event
CLASS lcl_event_handler DEFINITION.
  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.
  METHODS: data_change FOR EVENT data_changed
  OF cl_gui_alv_grid
  IMPORTING er_data_changed
  e_onf4.
ENDCLASS.                    "lcl_event_handler DEFINITION
*************************************************************************************************
*LOCAL CLASS IMPLEMENTATION
*************************************************************************************************
*Class implementation to handle the ONF4 event
CLASS lcl_event_handler IMPLEMENTATION.
  METHOD on_f4.
    DATA: ls_data         LIKE LINE OF gt_data,
    ls_sel             LIKE LINE OF gt_ret,
    ls_modi          TYPE lvc_s_modi,
    ls_fin_disp      LIKE LINE OF gt_rel_disp.
* Add the custom F4 values; here we are adding 2 values 'Uncertain' and 'Relevant' for the field STATE
    IF gt_data[] IS INITIAL.
      ls_data-state = 'UNCERTAIN'.
      APPEND ls_data TO gt_data.
      CLEAR ls_data.
      ls_data-state = 'RELEVANT'.
      APPEND ls_data TO gt_data.
    ENDIF.
*Call the function module to display the custom F4 values
    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
      EXPORTING
        retfield        = 'STATE'
        window_title    = 'List of State entries'(002)
        value_org       = 'S'
      TABLES
        value_tab       = gt_data[]
        return_tab      = gt_ret[]
      EXCEPTIONS
        parameter_error = 1
        no_values_found = 2
        OTHERS          = 3.
    (note: gt_ret[] contains the row id selected by the user from the list of f4 values)
    if sy-subrc = 0.
    READ TABLE gt_ret INTO ls_sel INDEX 1.
    ASSIGN er_event_data->m_data->* TO <itab>.
    READ TABLE gt_rel_disp INDEX es_row_no-row_id
    INTO ls_fin_disp.
    ls_modi-row_id   = es_row_no-row_id.
    ls_modi-fieldname = 'STATE'.
    ls_modi-value     = ls_sel-fieldval.
    APPEND ls_modi TO <itab>.
    gv_change = gc_x.
  ENDIF.
  er_event_data->m_event_handled = gc_x. (to inform grid that f4 was handled manually)
  endmethod.
  METHOD data_change.
    gv_change = gc_x.
  ENDMETHOD.                    "data_changed
ENDCLASS.                    "lcl_event_handler IMPLEMENTATION
*************************************************************************************************
*START-OF-SELECTION
*************************************************************************************************
START-OF-SELECTION.
  CALL SCREEN '0100'.
*************************************************************************************************
*  pbo -  status_0100
*************************************************************************************************
MODULE status_0100 OUTPUT.
  SET PF-STATUS '0100'.
  SET TITLEBAR  '0100'.
ENDMODULE.                    "data_change
*************************************************************************************************
*PBO -  get_result_data
*************************************************************************************************
MODULE get_result_data_0100 OUTPUT.
  IF gv_cont_0100 IS INITIAL.
*Create an object for the Grid container
    CREATE OBJECT gv_cont_0100
      EXPORTING
        container_name              = gv_container_0100
      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.
* Raise a msg
    ENDIF.
  ENDIF.
  IF gv_grid_0100 IS INITIAL.
*Create an object for the ALV Grid
    CREATE OBJECT gv_grid_0100
      EXPORTING
        i_parent          = gv_cont_0100
      EXCEPTIONS
        error_cntl_create = 1
        error_cntl_init   = 2
        error_cntl_link   = 3
        error_dp_create   = 4
        OTHERS            = 5.
    IF sy-subrc <> 0.
* Raise a msg
    ENDIF.
*Register the field for which the custom F4 has to be displayed
    gs_f4-fieldname  = 'STATE'.
    gs_f4-register   = 'X'.
    gs_f4-getbefore  = space.
    gs_f4-chngeafter = space.
    APPEND gs_f4 TO gt_f4.
*    (note: chngeafter set to 'X' only if any other field value has to be set based
*    on the selected f4 value)
    CALL METHOD gv_grid_0100->register_f4_for_fields
      EXPORTING
        it_f4 = gt_f4.
* Define layout attributes
    gs_layo_0100-cwidth_opt = gc_x.
    gs_layo_0100-sel_mode   = 'D'.
    gs_layo_0100-zebra      = gc_x.
    gs_layo_0100-grid_title = 'Display Result'(001).
* Define the field catalogue attributes
    gs_fieldcat_0100-fieldname  = 'REPORT'.
    gs_fieldcat_0100-coltext     =  'Report'.
    gs_fieldcat_0100-col_pos     = 1.
    gs_fieldcat_0100-outputlen   = 40.
    gs_fieldcat_0100-datatype    = 'CHAR'.
    gs_fieldcat_0100-intlen      = 40.
    gs_fieldcat_0100-hotspot     = gc_x.
    APPEND gs_fieldcat_0100 TO gt_fieldcat_0100.
    CLEAR gs_fieldcat_0100.
    gs_fieldcat_0100-fieldname   = 'STATE'.
    gs_fieldcat_0100-coltext     = 'State'.
    gs_fieldcat_0100-col_pos     = 2.
    gs_fieldcat_0100-outputlen   = 6.
    gs_fieldcat_0100-datatype    = 'CHAR'.
    gs_fieldcat_0100-intlen      = 6.
    gs_fieldcat_0100-f4availabl  = gc_x.
    gs_fieldcat_0100-edit      = gc_x.
    APPEND gs_fieldcat_0100 TO gt_fieldcat_0100.
* Define the functions that has to be excluded
    gs_exclude = cl_gui_alv_grid=>mc_fc_maximum.
    APPEND gs_exclude TO gt_exclude_0100.
    gs_exclude = cl_gui_alv_grid=>mc_fc_select_all.
    APPEND gs_exclude TO gt_exclude_0100.
    gs_exclude = cl_gui_alv_grid=>mc_fc_minimum.
    APPEND gs_exclude TO gt_exclude_0100.
    gs_exclude = cl_gui_alv_grid=>mc_fc_subtot.
    APPEND gs_exclude TO gt_exclude_0100.
* Create an object for the local class
    CREATE OBJECT gref_events_0100.
    SET HANDLER gref_events_0100->on_f4 FOR gv_grid_0100.
    SELECT report state FROM cnv_10940_rep
    INTO TABLE gt_rel_disp
    WHERE runid = '0010'.
* Display data in ALV GRID format.
    CALL METHOD gv_grid_0100->set_table_for_first_display
      EXPORTING
        i_bypassing_buffer            = gc_x
        is_layout                     = gs_layo_0100
        it_toolbar_excluding          = gt_exclude_0100
      CHANGING
        it_outtab                     = gt_rel_disp[]
        it_fieldcatalog               = gt_fieldcat_0100
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        OTHERS                        = 4.
    IF sy-subrc <> 0.
* Raise a message
    ENDIF.
  ENDIF.
ENDMODULE.                    "get_result_data_0100 OUTPUT
*************************************************************************************************
*PAI -  user_command_0100
*************************************************************************************************
MODULE user_command_0100 INPUT.
  CASE sy-ucomm.
    WHEN 'SAVE'.
      CALL METHOD gv_grid_0100->check_changed_data.
      CHECK gv_change EQ 'X'.
      CLEAR gv_change.
      MODIFY cnv_10940_rep FROM TABLE gt_rel_disp.
      COMMIT WORK.
  ENDCASE.
ENDMODULE.                    "user_command_0100 INPUT
 

1 Comment

  1. Hi, Thanks for the example. Could you please tell me if it is possible to fill up more than one field on the UI from the value help? Like I have on the Main ALV grid a filed called ID. I provide a value help for ID. Now on selection of the ID I want a field called Description to also get filled with the corresponding value. Is this possible? Warm Regards, Tiyasha