Search Help F4, no alv oo
Autor: Ricardo Moura Braga | Publicado: 2015-03-31T13:17:00-03:00


Search Help em campo do alv tree OO, pra guardar e não esquecer jamé.......abs.



"eventos do alv de criação da nota de serviço
class lcl_events_ns definition deferred.

"AlV Criação de Nota de Serviço
data: g_container_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type ref to cl_gui_custom_container,
&nbsp; &nbsp; &nbsp; g_container_name_ns &nbsp; &nbsp; type scrfname value 'CONTAINER_NS',
&nbsp; &nbsp; &nbsp; g_grid_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type ref to cl_gui_alv_grid,
&nbsp; &nbsp; &nbsp; gs_layout_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type lvc_s_layo,
&nbsp; &nbsp; &nbsp; g_events_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type ref to lcl_events_ns.

data: lt_fcat_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type table of lvc_s_fcat,
&nbsp; &nbsp; &nbsp; st_fcat_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type lvc_s_fcat,
&nbsp; &nbsp; &nbsp; lt_sort_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type lvc_t_sort,
&nbsp; &nbsp; &nbsp; ls_layo_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type lvc_s_layo,
&nbsp; &nbsp; &nbsp; custom_container_ns type ref to cl_gui_custom_container,
&nbsp; &nbsp; &nbsp; grid_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type ref to cl_gui_alv_grid,
&nbsp; &nbsp; &nbsp; t_disvariant_ns &nbsp; &nbsp; type table of disvariant with header line.

data: t_saida_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type table of zserv_nota,
&nbsp; &nbsp; &nbsp; st_saida_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type zserv_nota.

data: lt_row_no_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type table of lvc_s_roid.
data: lc_row_no_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type lvc_s_roid.

DATA: t_saida_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TYPE TABLE OF zserv_nota,
&nbsp; &nbsp; &nbsp; st_saida_ns &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TYPE zserv_nota.

*Estrutura
*QMNUM Tipo QMNUM CHAR 12 0 Nº da nota
*QMART Tipo QMART CHAR 2 0 Tipo de nota
*QCODE Tipo FECOD CHAR 4 0 Código do problema ou do dano
*QMDAT Tipo QMDAT DATS 8 0 Data da nota

form create_grid_ns .

&nbsp; create object g_grid_ns
&nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; i_parent = g_container_ns.

&nbsp; perform set_grid_fcat_ns.

&nbsp; perform seleciona_nota.




&nbsp; "Elimina botões do alv criação de nota
&nbsp; data: lt_excl_func &nbsp;type ui_functions.
&nbsp; append cl_gui_alv_grid=&gt;mc_fc_excl_all to lt_excl_func.


&nbsp; t_disvariant_ns-report = sy-repid.
&nbsp; call method g_grid_ns-&gt;set_table_for_first_display
&nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; is_variant &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = t_disvariant_ns
&nbsp; &nbsp; &nbsp; is_layout &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= ls_layo_ns
&nbsp; &nbsp; &nbsp; i_save &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'A'
&nbsp; &nbsp; &nbsp; it_toolbar_excluding = lt_excl_func[]
&nbsp; &nbsp; changing
&nbsp; &nbsp; &nbsp; it_outtab &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= t_saida_ns[]
&nbsp; &nbsp; &nbsp; it_fieldcatalog &nbsp; &nbsp; &nbsp;= lt_fcat_ns[]
&nbsp; &nbsp; &nbsp; it_sort &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= lt_sort_ns[].

&nbsp; call method cl_gui_control=&gt;set_focus
&nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; control = g_grid_ns.

&nbsp; call method g_grid_ns-&gt;set_ready_for_input
&nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; i_ready_for_input = 1.

&nbsp; clear gt_f4.
&nbsp; gs_f4-fieldname &nbsp;= 'QCODE'.
&nbsp; gs_f4-register &nbsp; = 'X'.
* &nbsp;gs_f4-getbefore &nbsp;= 'X'.
* &nbsp;gs_f4-chngeafter = 'X'.
&nbsp; append gs_f4 to gt_f4.
&nbsp; call method g_grid_ns-&gt;register_f4_for_fields
&nbsp; &nbsp; exporting
&nbsp; &nbsp; &nbsp; it_f4 = gt_f4.

&nbsp; perform set_grid_events_ns.
endform. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" CREATE_grid_ns

form set_grid_events_ns .
&nbsp; create object g_events_ns.
* &nbsp;SET HANDLER g_events_ns-&gt;double_click &nbsp;FOR g_grid_ns.
&nbsp; set handler g_events_ns-&gt;handle_on_f4 for g_grid_ns.

endform. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" SET_GRID_EVENTS2

FORM set_grid_fcat_ns .
&nbsp; REFRESH lt_fcat_ns.

&nbsp; CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
&nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; i_structure_name &nbsp; &nbsp; &nbsp; = 'zserv_nota'
&nbsp; &nbsp; &nbsp; i_client_never_display = 'X'
&nbsp; &nbsp; CHANGING
&nbsp; &nbsp; &nbsp; ct_fieldcat &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= lt_fcat_ns[]
&nbsp; &nbsp; EXCEPTIONS
&nbsp; &nbsp; &nbsp; inconsistent_interface = 1
&nbsp; &nbsp; &nbsp; program_error &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 2
&nbsp; &nbsp; &nbsp; OTHERS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 3.


&nbsp; LOOP AT lt_fcat_ns INTO st_fcat_ns.
&nbsp; &nbsp; CASE st_fcat_ns-fieldname.
&nbsp; &nbsp; &nbsp; WHEN 'QMNUM'.
&nbsp; &nbsp; &nbsp; &nbsp; st_fcat_ns-reptext = 'Nº da nota'.
&nbsp; &nbsp; &nbsp; &nbsp; st_fcat_ns-outputlen = 15.
&nbsp; &nbsp; &nbsp; WHEN 'QMART'.
&nbsp; &nbsp; &nbsp; &nbsp; st_fcat_ns-reptext = 'Tipo de Nota'.
&nbsp; &nbsp; &nbsp; &nbsp; st_fcat_ns-outputlen = 15.
&nbsp; &nbsp; &nbsp; WHEN 'QCODE'.
&nbsp; &nbsp; &nbsp; &nbsp; st_fcat_ns-reptext = 'Tipo de Serviço'.
&nbsp; &nbsp; &nbsp; &nbsp; st_fcat_ns-outputlen = 15.
&nbsp; &nbsp; &nbsp; &nbsp; st_fcat_ns-edit = 'X'.
&nbsp; &nbsp; &nbsp; &nbsp; st_fcat_ns-ref_table = 'QPCT'.
&nbsp; &nbsp; &nbsp; &nbsp; st_fcat_ns-ref_field = 'CODE'.
&nbsp; &nbsp; &nbsp; &nbsp; st_fcat_ns-f4availabl = 'X'.
&nbsp; &nbsp; &nbsp; WHEN 'QMDAT'.
&nbsp; &nbsp; &nbsp; &nbsp; st_fcat_ns-reptext = 'Data de Processamento'.
&nbsp; &nbsp; &nbsp; &nbsp; st_fcat_ns-edit = 'X'.
&nbsp; &nbsp; &nbsp; &nbsp; st_fcat_ns-outputlen = 15.
&nbsp; &nbsp; ENDCASE.
&nbsp; &nbsp; MODIFY lt_fcat_ns FROM st_fcat_ns.
&nbsp; ENDLOOP.

ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" SET_GRID_FCAT2



*---------------------------------------------------------------------*
* &nbsp; &nbsp; &nbsp; Class LCL_EVENTS_ns
*----------------------------------------------------------------------*
class lcl_events_ns definition .
&nbsp; public section.
&nbsp; &nbsp; methods:handle_on_f4
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for event onf4 of cl_gui_alv_grid
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; importing e_fieldname
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; es_row_no
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; er_event_data.

endclass. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "LCL_EVENTS
*---------------------------------------------------------------------*
* &nbsp; &nbsp; &nbsp; CLASS lcl_events_NS IMPLEMENTATION
*---------------------------------------------------------------------*
class lcl_events_ns implementation.
*--Handle On F4
&nbsp; method handle_on_f4.
&nbsp; &nbsp; perform on_f4
&nbsp; &nbsp; &nbsp; using e_fieldname
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; es_row_no
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; er_event_data.
&nbsp; endmethod. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"handle_on_f4

endclass. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"lcl_events_d0100 IMPLEMENTATION

*&amp;---------------------------------------------------------------------*
*&amp; &nbsp; &nbsp; &nbsp;Form &nbsp;ON_F4
*&amp;---------------------------------------------------------------------*
* &nbsp; &nbsp; &nbsp; text
*----------------------------------------------------------------------*
FORM on_f4 &nbsp;USING e_fieldname &nbsp; TYPE lvc_fname
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; es_row_no &nbsp; &nbsp; TYPE lvc_s_roid
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; er_event_data TYPE REF TO cl_alv_event_data.

&nbsp; DATA: it_qtpc &nbsp; TYPE TABLE OF qpct,
&nbsp; &nbsp; &nbsp; &nbsp; lt_map &nbsp; &nbsp;TYPE TABLE OF dselc,
&nbsp; &nbsp; &nbsp; &nbsp; ls_map &nbsp; &nbsp;TYPE dselc,
&nbsp; &nbsp; &nbsp; &nbsp; lt_return TYPE TABLE OF ddshretval,
&nbsp; &nbsp; &nbsp; &nbsp; ls_return TYPE ddshretval,
&nbsp; &nbsp; &nbsp; &nbsp; ls_stable TYPE lvc_s_stbl.

&nbsp; " Field-symbols
&nbsp; FIELD-SYMBOLS: &lt;l_saida&gt; TYPE zserv_nota. " ALV table line


&nbsp; CASE e_fieldname.
&nbsp; &nbsp; WHEN 'QCODE'.
&nbsp; &nbsp; &nbsp; " Read current line
&nbsp; &nbsp; &nbsp; READ TABLE t_saida_ns ASSIGNING &lt;l_saida&gt;
&nbsp; &nbsp; &nbsp; &nbsp; INDEX es_row_no-row_id.

&nbsp; &nbsp; &nbsp; " Load F4 Data
&nbsp; &nbsp; &nbsp; SELECT *
&nbsp; &nbsp; &nbsp; &nbsp; FROM qpct
&nbsp; &nbsp; &nbsp; &nbsp; INTO TABLE it_qtpc
&nbsp; &nbsp; &nbsp; &nbsp; WHERE katalogart = wa_qmfe-fekat
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND &nbsp;codegruppe = wa_qmfe-fegrp.


&nbsp; &nbsp; &nbsp; " Set return field
&nbsp; &nbsp; &nbsp; CLEAR ls_map.
&nbsp; &nbsp; &nbsp; ls_map-fldname = 'F0004'.
&nbsp; &nbsp; &nbsp; ls_map-dyfldname = 'QCODE'.
&nbsp; &nbsp; &nbsp; APPEND ls_map TO lt_map.

&nbsp; &nbsp; &nbsp; " Call Search Help Popup Function
&nbsp; &nbsp; &nbsp; CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
&nbsp; &nbsp; &nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; retfield &nbsp; &nbsp; &nbsp; &nbsp;= 'QCODE'
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value_org &nbsp; &nbsp; &nbsp; = 'S'
&nbsp; &nbsp; &nbsp; &nbsp; TABLES
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value_tab &nbsp; &nbsp; &nbsp; = it_qtpc
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dynpfld_mapping = lt_map
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return_tab &nbsp; &nbsp; &nbsp;= lt_return
&nbsp; &nbsp; &nbsp; &nbsp; EXCEPTIONS
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parameter_error = 1
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; no_values_found = 2
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OTHERS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 3.


&nbsp; &nbsp; &nbsp; " Read selected f4 value
&nbsp; &nbsp; &nbsp; READ TABLE lt_return INTO ls_return WITH KEY fieldname = 'F0004'.
&nbsp; &nbsp; &nbsp; IF ls_return IS NOT INITIAL.
&nbsp; &nbsp; &nbsp; &nbsp; " Update ALV table
&nbsp; &nbsp; &nbsp; &nbsp; &lt;l_saida&gt;-qcode = ls_return-fieldval.
&nbsp; &nbsp; &nbsp; ENDIF.
&nbsp; ENDCASE.

&nbsp; ls_stable = 'XX'. " Set stable refresh for row and column
&nbsp; " ALV Refresh
&nbsp; CALL METHOD g_grid_ns-&gt;refresh_table_display
&nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; is_stable &nbsp; &nbsp; &nbsp;= ls_stable
&nbsp; &nbsp; &nbsp; i_soft_refresh = 'X'
&nbsp; &nbsp; EXCEPTIONS
&nbsp; &nbsp; &nbsp; finished &nbsp; &nbsp; &nbsp; = 1
&nbsp; &nbsp; &nbsp; OTHERS &nbsp; &nbsp; &nbsp; &nbsp; = 2.

&nbsp; " Avoid possible standard Search Help
&nbsp; er_event_data-&gt;m_event_handled = 'X'.


ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" ON_F4

*&amp;---------------------------------------------------------------------*
*&amp; &nbsp; &nbsp; &nbsp;Form &nbsp;CRIA_NOVA_NOTA
*&amp;---------------------------------------------------------------------*
FORM cria_nova_nota .

&nbsp; DATA: st_qmel &nbsp; &nbsp; TYPE viqmel.
&nbsp; DATA: t_qmfe &nbsp; &nbsp; &nbsp;TYPE TABLE OF qmfe.
&nbsp; DATA: w_qmfe &nbsp; &nbsp; &nbsp;TYPE qmfe.
&nbsp; DATA: y_qmnum &nbsp; &nbsp; TYPE qmel-qmnum.
&nbsp; DATA: wa_kurtztext TYPE qpct-katalogart.

&nbsp; READ TABLE t_saida_ns INTO st_saida_ns INDEX 1.

&nbsp; IF sy-subrc = 0.

&nbsp; &nbsp; SELECT SINGLE *
&nbsp; &nbsp; &nbsp; &nbsp; FROM viqmel
&nbsp; &nbsp; &nbsp; &nbsp; INTO st_qmel
&nbsp; &nbsp; &nbsp; &nbsp; WHERE qmnum = st_saida_ns-qmnum.

&nbsp; &nbsp; st_qmel-strmn = st_saida_ns-qmdat.
&nbsp; &nbsp; st_qmel-qmnam = sy-uname.

&nbsp; &nbsp; SELECT *
&nbsp; &nbsp; &nbsp; FROM qmfe
&nbsp; &nbsp; &nbsp; INTO TABLE t_qmfe
&nbsp; &nbsp; &nbsp; WHERE qmnum = st_saida_ns-qmnum
&nbsp; &nbsp; &nbsp; &nbsp;AND &nbsp;fenum = '0001'.

&nbsp; &nbsp; READ TABLE t_qmfe INTO w_qmfe INDEX 1.

&nbsp; &nbsp; SELECT kurztext
&nbsp; &nbsp; &nbsp; UP TO 1 ROWS
&nbsp; &nbsp; &nbsp; FROM qpct
&nbsp; &nbsp; &nbsp; INTO wa_kurtztext
&nbsp; &nbsp; &nbsp; WHERE katalogart = w_qmfe-fekat
&nbsp; &nbsp; &nbsp; AND &nbsp; codegruppe = w_qmfe-fegrp
&nbsp; &nbsp; &nbsp; AND &nbsp; code &nbsp; &nbsp; &nbsp; = st_saida_ns-qcode.
&nbsp; &nbsp; ENDSELECT.

&nbsp; &nbsp; MOVE wa_kurtztext TO w_qmfe-fetxt.

&nbsp; &nbsp; MODIFY t_qmfe FROM w_qmfe TRANSPORTING fetxt WHERE qmnum = st_saida_ns-qmnum.

&nbsp; &nbsp; CALL FUNCTION 'ZCRIAR_NS'
&nbsp; &nbsp; &nbsp; EXPORTING
&nbsp; &nbsp; &nbsp; &nbsp; x_qmel &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = st_qmel
&nbsp; &nbsp; &nbsp; IMPORTING
&nbsp; &nbsp; &nbsp; &nbsp; y_qmnum &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= y_qmnum
&nbsp; &nbsp; &nbsp; TABLES
&nbsp; &nbsp; &nbsp; &nbsp; ti_qmfe &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= t_qmfe
&nbsp; &nbsp; &nbsp; EXCEPTIONS
&nbsp; &nbsp; &nbsp; &nbsp; spebene_error &nbsp; &nbsp;= 1
&nbsp; &nbsp; &nbsp; &nbsp; abckz_error &nbsp; &nbsp; &nbsp;= 2
&nbsp; &nbsp; &nbsp; &nbsp; wfcid_error &nbsp; &nbsp; &nbsp;= 3
&nbsp; &nbsp; &nbsp; &nbsp; read_table_error = 4
&nbsp; &nbsp; &nbsp; &nbsp; calc_error &nbsp; &nbsp; &nbsp; = 5
&nbsp; &nbsp; &nbsp; &nbsp; OTHERS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 6.

&nbsp; &nbsp; IF sy-subrc EQ 0.
&nbsp; &nbsp; &nbsp; MESSAGE s000 WITH 'Nota' st_saida-qmnum 'criada com sucesso, onde o valor de Y_QMNUM é' y_qmnum.
&nbsp; &nbsp; ENDIF.

&nbsp; ENDIF.

ENDFORM. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" CRIA_NOVA_NOTA