Custom Search Help (CL_GUI_ALV_GRID)

ALV Grid 화면에서, 실제 코딩을 통해 Search Help를 만드는 방법.


 


1. fieldcatalog 추가


 – Edit/f4availabl = ‘X’


 


2. Set Event Handler


[#M_소스코드 보기|접기|

DATA: go_grid              TYPE REF TO lcl_def_grid.
DATA: go_event_receiver TYPE REF TO lcl_def_receiver.


  CALL METHOD go_grid->register_edit_event
    EXPORTING
      i_event_id = cl_gui_alv_grid=>mc_evt_modified.


  CALL METHOD go_grid->register_edit_event
    EXPORTING
      i_event_id = cl_gui_alv_grid=>mc_evt_enter.


* Event Handler 등록
  CREATE OBJECT go_event_receiver.
  SET HANDLER :
   go_event_receiver->handle_on_f4_1st     FOR go_grid.


  PERFORM register_f4_fields.    “set cells with search help



FORM register_f4_fields .
  DATA: lt_f4      TYPE lvc_t_f4 WITH HEADER LINE.
  DATA: lt_f4_data TYPE lvc_s_f4.


  lt_f4_data-fieldname = ‘REPGROUP’. <— Search Help 대상 Itab Field.
  lt_f4_data-register = ‘X’ .
*  lt_f4_data-getbefore = ‘X’ .
  lt_f4_data-chngeafter  =’X’.
  INSERT lt_f4_data INTO TABLE lt_f4.


  CALL METHOD go_grid->register_f4_for_fields
    EXPORTING
      it_f4 = lt_f4[].


ENDFORM.                    ” REGISTER_F4_FIELDS

_M#]

 


3. Implementation


[#M_소스코드 보기|접기|

 

  METHOD handle_on_f4_1st.

    PERFORM handle_on_f4_1st_part USING e_fieldname
                                        e_fieldvalue
                                        es_row_no
                                        er_event_data
                                        et_bad_cells
                                        e_display.



 


FORM handle_on_f4_1st_part  USING pv_fieldname
                                  pv_fieldvalue
                                  ps_row_no     STRUCTURE lvc_s_roid
                                  po_event_data TYPE REF TO cl_alv_event_data
                                  pt_bad_cells  “STRUCTURE lvc_s_modi
                                  p_e_display.



  DATA: BEGIN OF lt_rep OCCURS 0,
        repgroup  TYPE za_auth_rg,
        rg_name   TYPE zb_rgname,
        infoarea  TYPE zb_infoarea,
        txtlg     TYPE zb_infoareatx,
        recommand TYPE zb_recomd,
        END OF lt_rep.
  DATA: lt_return  TYPE TABLE OF ddshretval WITH HEADER LINE.
  DATA: lv_infoarea TYPE zb_infoarea.


  CASE pv_fieldname.
    WHEN ‘REPGROUP’.
      READ TABLE gt_disp INDEX ps_row_no-row_id.


      CLEAR: lt_rep, lt_rep[].
      SELECT a~rg AS repgroup a~rg_text AS rg_name b~infoarea
             c~txtlg
        FROM zta0bipc3130 AS a INNER JOIN zta0bipc3131 AS b
          ON a~rg = b~rg INNER JOIN rsdareat AS c
          ON b~infoarea = c~infoarea
        INTO CORRESPONDING FIELDS OF TABLE lt_rep
       WHERE a~langu   = sy-langu
         AND a~del     = ‘ ‘
         AND b~del     = ‘ ‘
         AND c~langu   = sy-langu
         AND c~objvers = c_a.


      LOOP AT lt_rep.
        SELECT SINGLE infoarea FROM zta0bipc3520
          INTO lv_infoarea
         WHERE pgmid    = gt_disp-pgmid
           AND bocuid   = gt_disp-bocuid
           AND queryid  = gt_disp-queryid
           AND infoarea = lt_rep-infoarea.
        IF sy-subrc = 0.
          lt_rep-recommand = ‘○’.
        ENDIF.


        MODIFY lt_rep INDEX sy-tabix TRANSPORTING recommand.
      ENDLOOP.


      SORT lt_rep DESCENDING BY recommand.”ASCENDING repgroup infoarea .


      CALL FUNCTION ‘F4IF_INT_TABLE_VALUE_REQUEST’
        EXPORTING
          retfield        = ‘REPGROUP’
          value_org       = ‘S’
        TABLES
          value_tab       = lt_rep
          return_tab      = lt_return
        EXCEPTIONS
          parameter_error = 1
          no_values_found = 2
          OTHERS          = 3.


      READ TABLE lt_return INDEX 1.
      IF sy-subrc = 0.
        gt_disp-repgroup = lt_return-fieldval.


      ENDIF.


  ENDCASE.  ” CASE pv_fieldname.


 


  CALL METHOD go_grid->refresh_table_display. 

_M#]

(on_f4 Event 사용시, alv_changed Event는 미발생!)


 


참고 : http://wiki.scn.sap.com/wiki/display/Snippets/How+to+implement+F4+search+help+in+OO+ALV+Grid