Skip to Content
avatar image
Former Member

user-defined values as f4 help in alv grid

hello,

how can we get user-defined values as f4 help in alv grid....

i gone thru BCALV_GRID_F4_HELP.....but didn't get...

kindly help..

Thanks

Swaminathan.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • avatar image
    Former Member
    Jan 18, 2007 at 02:10 PM

    Hi,

    Yes. You can have user defined F4 help in ALV.

    For this you need to

    1.Set the flag for F4 in Layout for that field

    2. Populate the field that requires user defined help in table of type lvc_t_f4.

    3. handle the event onf4 of cl_gui_alv_grid in your program.

    4. handle event datachanged of cl_gui_alv_grid to get the selected values into the field.

    The demo program gives the code for this.

    Hope this helps,

    Thanks.

    Rashmi.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 18, 2007 at 03:55 PM

    Hi there. Will the field on your ALV be referring to a customized field? If it is then its easier to just put a reference check table to the field, or you could explicitly define the allowed values in the domain of the field, or you could attach a search help to the field. Any one of these methods will give you an automatic drop down when you generate the fieldcatalog using REUSE_ALV_FIELDCATALOG_MERGE(for the function module REUSE_ALG_GRID_DISPLAY) or LVC_FIELDCATALOG MERGE(for class CLGUI_ALV_GRID). If it's not a customized field you can change the attributes of the field in the fieldcatalog to point to your check table, domain or search help.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 19, 2007 at 05:10 AM

    Hello Swami

    I have simplified the sample report BCALV_GRID_F4_HELP in order to make the different options a bit more clearer. The variant

    ZUS_SDN_BCALV_TEST_GRID_F4_2

    shows how to define a user-defined search help.

    *&---------------------------------------------------------------------
    *& Report  BCALV_GRID_F4_HELP                                          *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    *&                                                                     *
    *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    * Purpose:
    * ~~~~~~~~
    * This report illustrates the use of f4-Help in an alv grid control.
    *-----------------------------------------------------------------
    * Background:
    * ~~~~~~~~~~~
    * There a two possibilities to implement an f4-Help in the alv grid
    * control: one can either use standard f4-help or write one by Hand.
    * For the former there is nothing to do at all. This report shows how
    * to implement user-defined f4-help.
    *-----------------------------------------------------------------
    * The user should look at the definition of classes grid_application
    * and lcl_event_receiver:
    * all the grid-specific things happen there, while the rest
    * of the program is concerned with dynpro programming
    *---------------------------------------------------------------------
    * To check program behavior
    * ~~~~~~~~~~~~~~~~~~~~~~~~~
    * For each choice it is explained in detail which functionality the
    * f4-help dispalys. Just try out different modes at the start-dynpro.
    * We also included a message signaling when datatable update actually
    * occurs.
    *-----------------------------------------------------------------
    * Essential steps (search for '§')
    * ~~~~~~~~~~~~~~~
    * First you must define and set an event handler for event onf4
    * of class cl_gui_alv_grid, just as with any event in the object
    * model. In our case, its method on_f4 of (the local) class
    * lcl_event_receiver (definition see below).
    * We set the handler in PBO-module create_object of dynpro 100.
    *
    * For the easiest case where you don't want to make changes do step
    * 1. Register all columns for which you want to define an f4-help.
    * 1a.You can deregister columns during run-time to use standard f4-help.
    * 1b.Or register additional columns during run-time.
    * 2. Implement your event handler method.
    * 3. Set attribute m_event_handled of er_event_data to avoid standard
    *    f4-help.
    * If you want to allow the user to change data via f4-help you have to
    * 4. set in the fieldcatalog the corresponding column editable (see
    *    Documentation). It does not suffice to set the complete grid
    *    editable.
    * 5. Declare data and field-symbols for values to be changed.
    * 6. Assign the values for the corresponding cells you want to edit:
    *    you can edit any cells. Do not refresh your table!
    * 7. If your f4-help relates to other values of your table, you must
    *    set parameters getbefore and/or chngeafter during registration.
    * 8. In case the column you want to define an f4-help has no standard
    *    f4-help defined, you must set parameter F4AVAILABL in the field
    *    catalog.
    * 9. If you want to check the data yourself, you can register for the
    *    events data_changed and/or data_changed_finished. For the former
    *    you can check where the event was raised and act accordingly.
    *10. Often one uses drop down boxes instead of f4-help. To do so, you
    *    first have to extend your datatable by one field and set the
    *    fieldcatalog parameter drdn_field accordingly.
    *11. Then you have to prepare a drop down table, give it to your grid
    *    and fill in the additional field of your datatable appropritately.
    *!!  If you define a drop down box for a column, you can not define an
    *    f4-help for the same column.
    *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    
    report  ZUS_SDN_BCALV_TEST_GRID_F4_2.
    
    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: 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
              button_click of cl_gui_alv_grid
              importing sender
              es_row_no
              es_col_id.
      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  default 'X'.
    selection-screen comment 25(15) text-018.
    parameters drop_do radiobutton group tab1.
    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.
    
    
    
    *----------------------------------------------------------------------*
    * 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.
    
    
    
    
    
        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.
    
    
    *§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.
    
    
    
    * 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.
    
    
    break-point.
    
    *§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.
    
      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.
    
    
      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.
    
      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

    The variant

    ZUS_SDN_BCALV_TEST_GRID_F4_1

    shows how to use dropdown lists.

    *&---------------------------------------------------------------------
    *& Report  ZUS_SDN_BCALV_TEST_GRID_F4_1                                *
    *&                                                                     *
    *& Copied from: BCALV_TEST_GRID_F4_HELP and simplified for DropDown
    *&---------------------------------------------------------------------*
    *&                                                                     *
    *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    * Purpose:
    * ~~~~~~~~
    * This report illustrates the use of f4-Help in an alv grid control.
    *-----------------------------------------------------------------
    * Background:
    * ~~~~~~~~~~~
    * There a two possibilities to implement an f4-Help in the alv grid
    * control: one can either use standard f4-help or write one by Hand.
    * For the former there is nothing to do at all. This report shows how
    * to implement user-defined f4-help.
    *-----------------------------------------------------------------
    * The user should look at the definition of classes grid_application
    * and lcl_event_receiver:
    * all the grid-specific things happen there, while the rest
    * of the program is concerned with dynpro programming
    *---------------------------------------------------------------------
    * To check program behavior
    * ~~~~~~~~~~~~~~~~~~~~~~~~~
    * For each choice it is explained in detail which functionality the
    * f4-help dispalys. Just try out different modes at the start-dynpro.
    * We also included a message signaling when datatable update actually
    * occurs.
    *-----------------------------------------------------------------
    * Essential steps (search for '§')
    * ~~~~~~~~~~~~~~~
    * First you must define and set an event handler for event onf4
    * of class cl_gui_alv_grid, just as with any event in the object
    * model. In our case, its method on_f4 of (the local) class
    * lcl_event_receiver (definition see below).
    * We set the handler in PBO-module create_object of dynpro 100.
    *
    * For the easiest case where you don't want to make changes do step
    * 1. Register all columns for which you want to define an f4-help.
    * 1a.You can deregister columns during run-time to use standard f4-help.
    * 1b.Or register additional columns during run-time.
    * 2. Implement your event handler method.
    * 3. Set attribute m_event_handled of er_event_data to avoid standard
    *    f4-help.
    * If you want to allow the user to change data via f4-help you have to
    * 4. set in the fieldcatalog the corresponding column editable (see
    *    Documentation). It does not suffice to set the complete grid
    *    editable.
    * 5. Declare data and field-symbols for values to be changed.
    * 6. Assign the values for the corresponding cells you want to edit:
    *    you can edit any cells. Do not refresh your table!
    * 7. If your f4-help relates to other values of your table, you must
    *    set parameters getbefore and/or chngeafter during registration.
    * 8. In case the column you want to define an f4-help has no standard
    *    f4-help defined, you must set parameter F4AVAILABL in the field
    *    catalog.
    * 9. If you want to check the data yourself, you can register for the
    *    events data_changed and/or data_changed_finished. For the former
    *    you can check where the event was raised and act accordingly.
    *10. Often one uses drop down boxes instead of f4-help. To do so, you
    *    first have to extend your datatable by one field and set the
    *    fieldcatalog parameter drdn_field accordingly.
    *11. Then you have to prepare a drop down table, give it to your grid
    *    and fill in the additional field of your datatable appropritately.
    *!!  If you define a drop down box for a column, you can not define an
    *    f4-help for the same column.
    *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    
    REPORT  bcalv_grid_f4_help.
    
    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
    *          button_click OF cl_gui_alv_grid
    *          IMPORTING sender
    *          es_row_no
    *          es_col_id.
    *  PRIVATE SECTION.
    *    TYPES: ddshretval_table TYPE TABLE OF ddshretval.
    *    DATA : lr_data_changed TYPE REF TO cl_alv_changed_data_protocol.
    
    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.
    
    
    
    *----------------------------------------------------------------------*
    * 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.
    
    
      SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE gt_outtab[]
    UP TO p_maxrow ROWS.                                    "#EC CI_NOWHERE
    
    
    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.
      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.
    
    
        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.
    
    
    *§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.
    
    
        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 = '0026'.
            gs_outtab-drop_down_handle = 2.
          ENDIF.
          MODIFY gt_outtab FROM gs_outtab INDEX sy-tabix.
        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.
    
      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.
    
    
    ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION

    Regards

    Uwe

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 22, 2007 at 04:44 AM

    hi uwe,

    Please tel me where u r using user-defined values to update

    the F4 field(not dropdown)...

    Thanks

    Swaminathan.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 22, 2007 at 06:58 AM

    Hello Swami

    The SAP standard sample for user-defined F4 values is somewhat complicated (more than it should be in a sample report). The basic steps are:

    (1) Register and implement event handler method for even ON_F4.

    set handler my_event_receiver->on_f4 for all instances.
    ...
    *§2 implement an event handler method
      method on_f4.
    ...

    The event handler method is triggered as soon as the user call the search help.

    Now look at the steps in the event handler method ON_F4.

    (2) Overrule standard F4 help (if required)

    *§3 set attribute m_event_handled of er_event_data to avoid standard
    *   f4-help.
          er_event_data->m_event_handled = 'X'.

    (3) Call your user-defined F4 help


    Instead of the SAP example you could directly call your own search help (using F4IF_GET_SHLP_DESCR and F4IF_START_VALUE_REQUEST) or use values of an internal table (-> F4IF_INT_TABLE_VALUE_REQUEST).

    Regards

    Uwe

    Add comment
    10|10000 characters needed characters exceeded