Upload
pandu-munagala
View
219
Download
0
Embed Size (px)
Citation preview
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 1/16
class grid_appl definition deferred.class lcl_event_receiver definition deferred.
tables:eban.
*--- ALV Grid instance referencedata gr_alvgrid type ref to cl_gui_alv_grid .*--- Name of the custom control added on the screendata gc_custom_control_name type scrfname value 'CC_ALV' .*--- Custom container instance referencedata gr_ccontainer type ref to cl_gui_custom_container .*--- Field catalog tabledata gt_fieldcat type lvc_t_fcat .data zflag.*--- Layout structuredata gs_layout type lvc_s_layo .
data: ok_code type sy-ucomm.
** data for event handlingdata: gs_f4 type lvc_s_f4,
gt_f4 type lvc_t_f4.
types: begin of it_list, banfn type eban-banfn, bnfpo type eban-bnfpo, bsart type eban-bsart, bstyp type eban-bstyp,
bsakz type eban-bsakz,loekz type eban-loekz,statu type eban-statu,estkz type eban-estkz,frgkz type eban-frgkz,frgzu type eban-frgzu,
end of it_list.
data: gt_list type standard table of it_list, wa_list type it_list.
data: i_selected_rows type lvc_t_row,"Selected Rows w_selected_rows type lvc_s_row,i_modified type table of eban,"For getting modified rows w_modified type eban, wa type eban.
*data: my_event_receiver type ref to lcl_event_receiver.
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 2/16
*---------------------------------------------------------------------** 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_fieldnamee_fieldvaluees_row_noer_event_dataet_bad_cellse_display.
private section.data : lr_data_changed type ref to
cl_alv_changed_data_protocol.
endclass. "lcl_event_receiver DEFINITION
start-of-selection.
select banfn bnfpo bsart
bstyp bsakzloekzstatuestkzfrgkzfrgzu
from eban into table gt_list.
call screen 9000.
*&---------------------------------------------------------------------**& Module DISPLAY_ALV OUTPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 3/16
module display_alv output. perform display_alv.endmodule. " DISPLAY_ALV OUTPUT
*&--------------------------------------------------------------
-------**& Module STATUS_9000 OUTPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------* module status_9000 output.
set pf-status 'ZNEW_STS'.* SET TITLEBAR 'xxx'.
endmodule. " STATUS_9000 OUTPUT
*&---------------------------------------------------------------------**& Module USER_COMMAND_9000 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------* module user_command_9000 input.
ok_code = sy-ucomm.
case ok_code.
when 'BACK'.* call method g_onf4->reset.
leave to screen 0.
when 'EXIT'.leave program.
when 'EDIT'.
zflag = '1'. perform update_field_catalog changing gt_fieldcat. perform register_edit.
when 'DISPLAY'.zflag = '0'. perform update_field_catalog changing gt_fieldcat.
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 4/16
when 'SAVE_IN'. perform save_db.
when 'NEW'.if zflag <> '1'.
message i000(zpm_msgi).else.zflag = '2'. perform update_field_catalog changing gt_fieldcat.append wa_list to gt_list.
endif.endcase.
endmodule. " USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------**& Form DISPLAY_ALV *&---------------------------------------------------------------------** text*----------------------------------------------------------------------*form display_alv.if gr_alvgrid is initial.create object gr_ccontainer
exporting* parent =
container_name = gc_custom_control_name .
if sy-subrc <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
create object gr_alvgrid exportingi_parent = gr_ccontainer.
if sy-subrc <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
*----Preparing field catalog. perform prepare_field_catalog changing gt_fieldcat .
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 5/16
call method gr_alvgrid->set_table_for_first_displayexporting
is_layout = gs_layoutchanging
it_outtab = gt_list[]
it_fieldcatalog = gt_fieldcat* EXCEPTIONS* invalid_parameter_combination = 1* program_error = 2* too_many_lines = 3* others = 4
.if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
create object my_event_receiver.
set handler my_event_receiver->on_f4 for gr_alvgrid. perform register_f4_fields. "set cells with search help
*§3.Optionally register ENTER to raise event DATA_CHANGED.call method gr_alvgrid->register_edit_event
exportingi_event_id = cl_gui_alv_grid=>mc_evt_modified.
else.
call method gr_alvgrid->refresh_table_display* EXPORTING* is_stable =* i_soft_refresh =* EXCEPTIONS* finished = 1* others = 2
.if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endif.endform. "DISPLAY_ALV
*&---------------------------------------------------------------------**& Form prepare_field_catalog
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 6/16
*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*
* -->PT_FIELDCAT text*----------------------------------------------------------------------*form prepare_field_catalog changing pt_fieldcat type lvc_t_fcat.
data ls_fcat type lvc_s_fcat .
ls_fcat-fieldname = 'BANFN' .ls_fcat-inttype = 'C' .
*ls_fcat-outputlen = '10' .ls_fcat-coltext = 'Requisition no' .ls_fcat-seltext = 'Requisition no' .append ls_fcat to pt_fieldcat .
ls_fcat-fieldname = 'BNFPO' .ls_fcat-inttype = 'N' .
*ls_fcat-outputlen = '5' .ls_fcat-coltext = 'Item no' .ls_fcat-seltext = 'Item no' .append ls_fcat to pt_fieldcat .
ls_fcat-fieldname = 'BSART' .
ls_fcat-inttype = 'C' .*ls_fcat-outputlen = '5' .ls_fcat-coltext = 'Doc Type' .ls_fcat-seltext = 'Doc Type' .append ls_fcat to pt_fieldcat .
ls_fcat-fieldname = 'BSTYP' .ls_fcat-inttype = 'C' .
*ls_fcat-outputlen = '1' .ls_fcat-coltext = 'Doc Category' .ls_fcat-seltext = 'Doc Category' .
append ls_fcat to pt_fieldcat .
ls_fcat-fieldname = 'BSAKZ' .ls_fcat-inttype = 'C' .
*ls_fcat-outputlen = '1' .ls_fcat-coltext = 'Control Indicator' .ls_fcat-seltext = 'Control Indicator' .append ls_fcat to pt_fieldcat .
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 7/16
ls_fcat-fieldname = 'LOEKZ' .ls_fcat-inttype = 'C' .
*ls_fcat-outputlen = '1' .ls_fcat-coltext = 'Deletion Indicator' .
ls_fcat-seltext = 'Deletion Indicator' .append ls_fcat to pt_fieldcat .
ls_fcat-fieldname = 'STATU' .ls_fcat-inttype = 'C' .ls_fcat-f4availabl = 'X'.
*ls_fcat-outputlen = '1' .ls_fcat-coltext = 'Processing status' .ls_fcat-seltext = 'Processing Status' .append ls_fcat to pt_fieldcat .
ls_fcat-fieldname = 'ESTKZ' .ls_fcat-inttype = 'C' .
*ls_fcat-outputlen = '1' .ls_fcat-coltext = 'Creation Indicator' .ls_fcat-seltext = 'Creation Indicator' .append ls_fcat to pt_fieldcat .
ls_fcat-fieldname = 'FRGKZ' .ls_fcat-inttype = 'C' .
*ls_fcat-outputlen = '1' .ls_fcat-coltext = 'Release Indicator' .ls_fcat-seltext = 'Release Indicator' .
append ls_fcat to pt_fieldcat .
ls_fcat-fieldname = 'FRGZU' .ls_fcat-inttype = 'C' .
*ls_fcat-outputlen = '8' .ls_fcat-coltext = 'Release Status' .ls_fcat-seltext = 'Release Status' .append ls_fcat to pt_fieldcat .
endform. "prepare_field_catalog
*&---------------------------------------------------------------------**& Form update_field_catalog*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 8/16
* -->PT_FIELDCAT text*----------------------------------------------------------------------*form update_field_catalog changing pt_fieldcat type lvc_t_fcat.
data ls_fcat type lvc_s_fcat .
call method gr_alvgrid->get_frontend_fieldcatalogimporting
et_fieldcatalog = pt_fieldcat[].
loop at pt_fieldcat into ls_fcat .if zflag = '1'.
if ls_fcat-fieldname = 'BSART' .ls_fcat-edit = 'X' .ls_fcat-f4availabl = 'X'.ls_fcat-ref_table = 'T161T'.ls_fcat-ref_field = 'BSART'. modify pt_fieldcat from ls_fcat .endif .
if ls_fcat-fieldname = 'BSTYP' .ls_fcat-edit = 'X' . modify pt_fieldcat from ls_fcat .endif .
if ls_fcat-fieldname = 'BSAKZ' .
ls_fcat-edit = 'X' . modify pt_fieldcat from ls_fcat .endif .
if ls_fcat-fieldname = 'LOEKZ' .ls_fcat-edit = 'X' . modify pt_fieldcat from ls_fcat .endif .
if ls_fcat-fieldname = 'STATU' .ls_fcat-edit = 'X' .
ls_fcat-f4availabl = 'X'.* ls_fcat-drdn_hndl = '1'.* ls_fcat-outputlen = 15.
modify pt_fieldcat from ls_fcat .endif .
if ls_fcat-fieldname = 'ESTKZ' .ls_fcat-edit = 'X' .
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 9/16
modify pt_fieldcat from ls_fcat .endif .
if ls_fcat-fieldname = 'FRGKZ' .ls_fcat-edit = 'X' .
* for laready attcahed search helpls_fcat-f4availabl = 'X'.ls_fcat-ref_table = 'T161U'.ls_fcat-ref_field = 'FRGKZ'. modify pt_fieldcat from ls_fcat .endif.
if ls_fcat-fieldname = 'FRGZU' .ls_fcat-edit = 'X' . modify pt_fieldcat from ls_fcat .endif .
* add customise f4 help on feild STATU
clear gt_f4.
gs_f4-fieldname = 'STATU'.gs_f4-register = 'X'.
* gs_f4-getbefore = check_be. "§7a* gs_f4-chngeafter = chn_aft. "§7b
append gs_f4 to gt_f4.call method gr_alvgrid->register_f4_for_fieldsexportingit_f4 = gt_f4.
elseif zflag = '2'.if ls_fcat-fieldname = 'BANFN' .ls_fcat-edit = 'X' . modify pt_fieldcat from ls_fcat .endif .
if ls_fcat-fieldname = 'BNFPO' .ls_fcat-edit = 'X' . modify pt_fieldcat from ls_fcat .endif .
else.if ls_fcat-fieldname = 'BSART' .ls_fcat-edit = space. modify pt_fieldcat from ls_fcat .endif .
if ls_fcat-fieldname = 'BSTYP' .ls_fcat-edit = space .
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 10/16
modify pt_fieldcat from ls_fcat .endif .
if ls_fcat-fieldname = 'BSAKZ' .ls_fcat-edit = space .
modify pt_fieldcat from ls_fcat .endif .
if ls_fcat-fieldname = 'LOEKZ' .ls_fcat-edit = space . modify pt_fieldcat from ls_fcat .endif .
if ls_fcat-fieldname = 'STATU' .ls_fcat-edit = space . modify pt_fieldcat from ls_fcat .endif .
if ls_fcat-fieldname = 'ESTKZ' .ls_fcat-edit = space . modify pt_fieldcat from ls_fcat .endif .
if ls_fcat-fieldname = 'FRGKZ' .ls_fcat-edit = space . modify pt_fieldcat from ls_fcat .endif .
if ls_fcat-fieldname = 'FRGZU' .ls_fcat-edit = space . modify pt_fieldcat from ls_fcat .endif .
endif.endloop .
call method gr_alvgrid->set_frontend_fieldcatalogexporting
it_fieldcatalog = pt_fieldcat[].
endform. "update_field_catalog
*&---------------------------------------------------------------------**& Form save_DB*&---------------------------------------------------------------------** text
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 11/16
*----------------------------------------------------------------------*form save_db.
clear i_modified.
* data zindex(2) type numc.* Getting the selected rows indexcall method gr_alvgrid->get_selected_rowsimporting
et_index_rows = i_selected_rows.
* Through the index capturing the values of selected rowsloop at i_selected_rows into w_selected_rows.shift w_selected_rows-index left deleting leading '0'.read table gt_list into wa index w_selected_rows-index.if sy-subrc eq 0. w_modified-banfn = wa-banfn. w_modified-bnfpo = wa-bnfpo. w_modified-bsart = wa-bsart. w_modified-bstyp = wa-bstyp. w_modified-bsakz = wa-bsakz. w_modified-loekz = wa-loekz. w_modified-statu = wa-statu. w_modified-estkz = wa-estkz. w_modified-frgkz = wa-frgkz. w_modified-frgzu = wa-frgzu.
* MOVE-CORRESPONDING wa TO w_modified.append w_modified to i_modified.
* MODIFY eban from TABLE i_modified.endif.
endloop. modify eban from table i_modified.* UPDATE eban FROM TABLE i_modified.endform. "save_DB
*&---------------------------------------------------------------------**& Form register_edit*&--------------------------------------------------------------
-------** text*----------------------------------------------------------------------*form register_edit .call method gr_alvgrid->register_edit_eventexporting
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 12/16
endform. "register_edit
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION*----------------------------------------------------------------------***----------------------------------------------------------------------*class lcl_event_receiver implementation.
*§2 implement an event handler method method on_f4. perform on_f4 using e_fieldname
es_row_no-row_id er_event_dataet_bad_cellse_displaylr_data_changed changing gt_fieldcat.
**§3 set attribute m_event_handled of er_event_data to avoid standard ** f4-help.
er_event_data->m_event_handled = 'X'.*
endmethod."on_f4
endclass. "lcl_event_receiver IMPLEMENTATION
*&---------------------------------------------------------------------**& Form register_f4_fields*&---------------------------------------------------------------------*
* text*----------------------------------------------------------------------*form register_f4_fields. "which fields will have F4 searchhelp DATA: lt_f4 TYPE lvc_t_f4 WITH HEADER LINE .data: lt_f4_data type lvc_s_f4.lt_f4_data-fieldname = 'STATU'.lt_f4_data-register = 'X' .
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 13/16
* lt_f4_data-getbefore = 'X' .lt_f4_data-chngeafter ='X'.insert lt_f4_data into table gt_f4.
call method gr_alvgrid->register_f4_for_fields
exportingit_f4 = gt_f4[].endform. "register_f4_fields
*&---------------------------------------------------------------------**& Form on_f4*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** -->P_E_FIELDNAME text* -->ROW_ID text* -->P_ER_EVENT_DATA text* -->P_ET_BAD_CELLS text* -->P_E_DISPLAY text* -->IR_DATA_CHANGED text* -->PT_FIELDCAT text*----------------------------------------------------------------------*form on_f4 using p_e_fieldname
row_id
p_er_event_datatype ref to cl_alv_event_data
p_et_bad_cells p_e_displayir_data_changed
type ref tocl_alv_changed_data_protocolchanging pt_fieldcat type lvc_t_fcat.
data: begin of value_charg occurs 0, "the value table that is passed to F4 fm
statu like eban-statu,* lgort like zpp_kpduzelt-lgort,* clabs like mchb-clabs,
end of value_charg.
data : ls_mod_cell type lvc_s_modi ,ls_del_cell type lvc_s_moce ,ls_good_cell type lvc_s_modi,
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 14/16
lv_value type lvc_value .
data : ls_mod_row like line of gt_list.data return_tab type table of ddshretval with header line.data statu type eban-statu.
*§5 define fields and field-symbols for data-updatefield-symbols: <itab> type lvc_t_modi.data: ls_modi type lvc_s_modi.
create object ir_data_changed.
sort ir_data_changed->mt_mod_cells by row_id .
loop at ir_data_changed->mt_mod_cellsinto ls_mod_cell.endloop.
case p_e_fieldname. "read changed cell when 'STATU'.
......* here must be the code to fill in the possible values table* and the call to fm F4IF_INT_TABLE_VALUE_REQUEST
call function 'F4IF_FIELD_VALUE_REQUEST'exportingtabname = 'EBAN'fieldname = 'STATU'
* SEARCHHELP = ' '
* SHLPPARAM = ' '* DYNPPROG = ' '* DYNPNR = ' '* DYNPROFIELD = ' '* STEPL = 0* VALUE = I_HELP_VALU* MULTIPLE_CHOICE = ' '* DISPLAY = ' '* SUPPRESS_RECORDLIST = ' '* CALLBACK_PROGRAM = 'BCALV4'* CALLBACK_FORM = 'F4'
* SELECTION_SCREEN = ' '* IMPORTING* USER_RESET =
tablesreturn_tab = return_tab
exceptionsfield_not_found = 1no_help_for_field = 2
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 15/16
inconsistent_help = 3no_values_found = 4others = 5
.
if sy-subrc = 0 and return_tab-fieldval <> ''. move return_tab-fieldval to statu.ls_mod_cell-row_id = row_id.ls_mod_cell-fieldname = 'STATU'. move statu to lv_value.ls_mod_cell-value = lv_value.append ls_mod_cell to ir_data_changed->mt_mod_cells.
*******************call method gr_alvgrid->get_frontend_fieldcatalogimportinget_fieldcatalog = gt_fieldcat[].
read table gt_list index row_id into wa_list.
data lp_wa type ref to data.create data lp_wa type it_list.field-symbols <ls_wa> type any.assign lp_wa->* to <ls_wa>. <ls_wa> = wa_list.
data ls_fieldcat type line of lvc_t_fcat .data:l_tabname(30) type c,
l_fieldname(30) type c.
field-symbols <l_field_value> type any.
read table gt_fieldcat with key fieldname = ls_mod_cell-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_listto <l_field_value>.
**§6 assign the cell table fieldsymbol to the dereferenced datatable*and * fill the table.
assign p_er_event_data->m_data->* to <itab>.append ls_mod_cell to <itab>.
endif.
7/28/2019 oops ALV
http://slidepdf.com/reader/full/oops-alv 16/16
endcase.endform."on_f4