data: g_par01_type type char255.
data: g_par02_type type char255.
data: g_par03_type type char255.
data: g_par04_type type char255.
data: g_par05_type type char255.
data: g_par06_type type char255.
data: g_par07_type type char255.
data: g_par08_type type char255.
data: g_par09_type type char255.
data: g_par10_type type char255.
data: g_wait type c.
data: gt_rsparams type rsparams_tt.
data: gt_fcat_mass type lvc_t_fcat.
data: gt_mass_sel_columns type lvc_t_col.
data: g_fieldname type string.
data: g_okcode type sy-ucomm.
field-symbols: <fcat> type lvc_s_fcat.
field-symbols: <any> type any.
define add_param_descr.
concatenate 'P_DESC' &1 into g_fieldname.
assign (g_fieldname) to <any>.
if sy-subrc eq 0.
<any> = &2.
endif.
concatenate 'P_WITH' &1 into g_fieldname.
assign (g_fieldname) to <any>.
if sy-subrc eq 0.
<any> = text-s02.
endif.
concatenate 'P_CLEA' &1 into g_fieldname.
assign (g_fieldname) to <any>.
if sy-subrc eq 0.
<any> = text-s03.
endif.
end-of-definition.
define change_parametr_type.
data: f_type type string.
concatenate 'G_PAR' &1 '_TYPE' into g_fieldname.
concatenate &2 '-' &3 into f_type.
assign (g_fieldname) to <any>.
if sy-subrc eq 0.
<any> = f_type.
endif.
end-of-definition.
*--------------------------------------------------------------------*
* begin of selection screens
*--
define add_ss_line.
selection-screen begin of line.
selection-screen comment 1(14) p_clea&1.
parameters: p_parc&1 as checkbox user-command p_parc&1.
selection-screen comment 18(10) p_desc&1.
parameters: p_parf&1 like (g_par&1_type) lower case.
selection-screen comment 77(6) p_with&1.
parameters: p_part&1 like (g_par&1_type) lower case.
"selection-screen comment 51(10) p_with&1.
selection-screen end of line.
end-of-definition.
"mass replace ss
selection-screen begin of screen 1001.
add_ss_line: 01, 02, 03, 04, 05, 06, 07, 08, 09, 10.
selection-screen end of screen 1001.
at selection-screen output.
if sy-dynnr eq 1001.
perform set_ss_status.
loop at screen.
if screen-name cp '*P_*01*' and g_par01_type is initial.
clear: p_parf01, p_part01.
screen-active = 0.
modify screen.
endif.
if screen-name cp '*P_*02*' and g_par02_type is initial.
clear: p_parf02, p_part02.
screen-active = 0.
modify screen.
endif.
if screen-name cp '*P_*03*' and g_par03_type is initial.
clear: p_parf03, p_part03.
screen-active = 0.
modify screen.
endif.
if screen-name cp '*P_*04*' and g_par04_type is initial.
clear: p_parf04, p_part04.
screen-active = 0.
modify screen.
endif.
if screen-name cp '*P_*05*' and g_par05_type is initial.
clear: p_parf05, p_part05.
screen-active = 0.
modify screen.
endif.
if screen-name cp '*P_*06*' and g_par06_type is initial.
clear: p_parf06, p_part06.
screen-active = 0.
modify screen.
endif.
if screen-name cp '*P_*07*' and g_par07_type is initial.
clear: p_parf07, p_part07.
screen-active = 0.
modify screen.
endif.
if screen-name cp '*P_*08*' and g_par08_type is initial.
clear: p_parf08, p_part08.
screen-active = 0.
modify screen.
endif.
if screen-name cp '*P_*09*' and g_par09_type is initial.
clear: p_parf09, p_part09.
screen-active = 0.
modify screen.
endif.
if screen-name cp '*P_*10*' and g_par10_type is initial.
clear: p_parf10, p_part10.
screen-active = 0.
modify screen.
endif.
if screen-name+0(6) eq 'P_PARF'.
concatenate 'P_PARC' screen-name+6(2) into g_fieldname.
assign (g_fieldname) to <any>.
if sy-subrc eq 0 and <any> is not initial.
assign (screen-name) to <any>.
if sy-subrc eq 0.
clear <any>.
endif.
screen-input = 0.
modify screen.
elseif sy-subrc eq 0.
screen-input = 1.
modify screen.
endif.
endif.
endloop.
endif.
if sy-dynnr eq 1001.
g_okcode = sy-ucomm.
clear sy-ucomm.
case g_okcode.
when 'ENTER'.
" return.
when 'CANCEL'.
clear: p_parf01, p_parf02, p_parf03, p_parf04, p_parf05, p_parf06, p_parf07, p_parf08, p_parf09, p_parf10,
p_part01, p_part02, p_part03, p_part04, p_part05, p_part06, p_part07, p_part08, p_part09, p_part10
.
when 'P_PARC01' or 'P_PARC02' or 'P_PARC03' or 'P_PARC04' or 'P_PARC05' or 'P_PARC06' or 'P_PARC07' or 'P_PARC08' or
'P_PARC09' or 'P_PARC10'.
endcase.
endif.
form set_ss_status.
data: ft_exclude type standard table of rsexfcode.
data: fs_exclude like line of ft_exclude.
if sy-dynnr eq 1001.
"Exclude functions which are not used from modal SS
fs_exclude-fcode = 'GET'.
append fs_exclude to ft_exclude.
fs_exclude-fcode = 'SPOS'.
append fs_exclude to ft_exclude.
fs_exclude-fcode = 'NONE'.
append fs_exclude to ft_exclude.
call function 'RS_SET_SELSCREEN_STATUS'
exporting
p_status = space
p_program = sy-repid
tables
p_exclude = ft_exclude.
endif.
endform. "set_ss_status
*&---------------------------------------------------------------------*
*& Form ss1001_call_end
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->TASKNAME text
*----------------------------------------------------------------------*
form ss1001_call_end using taskname.
receive results from function 'Z_AB_CALL_SS_1001'
importing
et_rsparams = gt_rsparams.
g_wait = space.
endform. "ss1001_call_end
function z_ab_call_ss_1001.
*"--------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IT_MASS_SEL_COLUMNS) TYPE LVC_T_COL
*" VALUE(IT_FCAT_MASS) TYPE LVC_T_FCAT
*" EXPORTING
*" VALUE(ET_RSPARAMS) TYPE RSPARAMS_TT
*"--------------------------------------------------------------------
field-symbols: <col> like line of it_mass_sel_columns.
data: ft_mass_sel_columns like it_mass_sel_columns.
data: f_num(2) type n.
ft_mass_sel_columns = it_mass_sel_columns.
loop at it_fcat_mass assigning <fcat>.
read table ft_mass_sel_columns[] with key fieldname = <fcat>-fieldname transporting no fields." binary search.
if sy-subrc eq 0.
add 1 to f_num.
add_param_descr: f_num <fcat>-scrtext_s.
change_parametr_type: f_num <fcat>-ref_table <fcat>-ref_field.
endif.
endloop.
call selection-screen 1001 starting at 1 1.
call function 'RS_REFRESH_FROM_SELECTOPTIONS'
exporting
curr_report = sy-repid
* IMPORTING
* SP = SP
tables
selection_table = et_rsparams
exceptions
not_found = 1
no_report = 2
others = 3
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endfunction.
function z_ab_mass_replace_alv.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(IO_GRID) TYPE REF TO CL_GUI_ALV_GRID
*" CHANGING
*" REFERENCE(CT_OUTTAB) TYPE STANDARD TABLE
*"----------------------------------------------------------------------
data: ft_rsparams type rsparams_tt.
data: f_lines type i.
data: f_num(2) type n.
data: f_index type i.
data: f_field type string.
data: f_changed type flag.
data: f_tabix type i.
data: ft_filtered type lvc_t_fidx.
data: ft_selected_rows type lvc_t_roid.
data: fs_layout type lvc_s_layo.
data: f_space like line of ft_rsparams.
field-symbols: <paramsf> like line of ft_rsparams.
field-symbols: <paramst> like line of ft_rsparams.
field-symbols: <paramsc> like line of ft_rsparams.
field-symbols: <out> type any.
field-symbols: <col> like line of gt_mass_sel_columns.
field-symbols: <value> type lvc_s_modi-value.
field-symbols: <stylet> type lvc_t_styl.
field-symbols: <style> type lvc_s_styl.
if io_grid->is_ready_for_input( ) eq 0.
message s001(00) display like 'W' with 'Grid should be in edit mode in order to use this function!'.
return.
endif.
io_grid->get_frontend_layout(
importing
es_layout = fs_layout " Layout
).
"get fieldcat and selected columns
io_grid->get_frontend_fieldcatalog(
importing
et_fieldcatalog = gt_fcat_mass[]
).
io_grid->get_filtered_entries(
importing
et_filtered_entries = ft_filtered
).
io_grid->get_selected_rows(
importing
* et_index_rows = et_index_rows " Indexes of Selected Rows
et_row_no = ft_selected_rows
).
io_grid->get_selected_columns(
importing
et_index_columns = gt_mass_sel_columns[]
).
sort ft_selected_rows by row_id.
"remove not editable fields
delete gt_fcat_mass where edit eq abap_false.
if gt_fcat_mass[] is initial.
message s001(00) display like 'W' with 'No editable fields in the grid'.
return.
endif.
sort gt_fcat_mass by fieldname.
loop at gt_mass_sel_columns assigning <col>.
f_tabix = sy-tabix.
read table gt_fcat_mass with key fieldname = <col>-fieldname transporting no fields binary search.
if sy-subrc ne 0.
delete gt_mass_sel_columns index f_tabix.
endif.
endloop.
if sy-subrc eq 0.
if gt_mass_sel_columns[] is initial.
message s001(00) display like 'W' with 'Please select editable fields only'.
return.
endif.
endif.
if gt_mass_sel_columns[] is initial.
message s001(00) display like 'W' with 'Please select at least one column!'.
return.
endif.
describe table gt_mass_sel_columns lines f_lines.
if f_lines gt 10.
message s001(00) display like 'W' with 'Maximum number of columns in mass change function is 10'.
return.
endif.
loop at gt_mass_sel_columns[] assigning <col>.
data f_fieldname type string.
concatenate 'G_' <col>-fieldname into f_fieldname.
assign (f_fieldname) to <any>.
if sy-subrc eq 0.
<any> = 'X'.
read table gt_fcat_mass with key fieldname = <col>-fieldname assigning <fcat> binary search.
if sy-subrc eq 0.
concatenate 'PD' <col>-fieldname into f_fieldname.
assign (f_fieldname) to <any>.
if sy-subrc eq 0.
<any> = <fcat>-scrtext_s.
endif.
endif.
endif.
endloop.
refresh gt_rsparams[].
sort gt_fcat_mass by col_pos.
call function 'RM_FREE_SESSION_CHECK'
exceptions
no_free_session = 1
others = 2.
if sy-subrc eq 0.
g_wait = abap_true.
call function 'Z_AB_CALL_SS_1001'
destination 'NONE'
starting new task 'ZABMASSR'
performing ss1001_call_end on end of task
exporting
it_mass_sel_columns = gt_mass_sel_columns
it_fcat_mass = gt_fcat_mass.
else.
message s001(00) display like 'W' with 'No more free sessions. Close one window.'.
return.
endif.
wait until g_wait eq space.
sort gt_rsparams by selname.
clear f_num.
data: f_row type i.
data: ft_delta type lvc_t_modi.
data: fs_delta type lvc_s_modi.
ft_rsparams[] = gt_rsparams[].
sort ft_rsparams by selname.
clear f_num.
loop at gt_fcat_mass assigning <fcat>.
read table gt_mass_sel_columns[] with key fieldname = <fcat>-fieldname transporting no fields." binary search.
if sy-subrc eq 0.
add 1 to f_num.
concatenate 'P_PARC' f_num into f_field.
read table ft_rsparams assigning <paramsc> with key selname = f_field binary search.
if sy-subrc ne 0.
assign f_space to <paramsc>.
endif.
concatenate 'P_PARF' f_num into f_field.
read table ft_rsparams assigning <paramsf> with key selname = f_field binary search.
if sy-subrc eq 0.
concatenate 'P_PART' f_num into f_field.
read table ft_rsparams assigning <paramst> with key selname = f_field binary search.
if sy-subrc eq 0 and ( <paramsf>-low ne <paramst>-low or <paramsc>-low eq abap_true ).
loop at ct_outtab assigning <out>.
f_row = sy-tabix.
if ft_filtered[] is not initial.
read table ft_filtered with key table_line = f_row transporting no fields.
if sy-subrc eq 0.
continue.
endif.
endif.
if ft_selected_rows[] is not initial.
read table ft_selected_rows with key row_id = f_row transporting no fields binary search.
if sy-subrc ne 0. "only selected rows can be changed.
continue.
endif.
endif.
assign component <fcat>-fieldname of structure <out> to <any>.
if sy-subrc eq 0 and ( <any> eq <paramsf>-low or <paramsc>-low eq abap_true ).
"check if field is not disabled in row :)
if fs_layout-stylefname is not initial.
assign component fs_layout-stylefname of structure <out> to <stylet>.
if sy-subrc eq 0.
read table <stylet> with key fieldname = <fcat>-fieldname assigning <style>.
if sy-subrc eq 0 and <style>-style eq cl_gui_alv_grid=>mc_style_disabled.
"do not change that cell as it's not editable.
continue.
endif.
endif.
endif.
<any> = <paramst>-low.
clear fs_delta.
fs_delta-fieldname = <fcat>-fieldname.
fs_delta-row_id = f_row.
fs_delta-value = <paramst>-low.
append fs_delta to ft_delta.
f_changed = abap_true.
endif.
endloop.
endif.
endif.
endif.
endloop.
if f_changed eq abap_true.
sy-ucomm = 'MASSREPL'.
io_grid->set_delta_cells(
exporting
it_delta_cells = ft_delta " Delta Table
i_modified = abap_true " Modified
i_frontend_only = abap_true " Update only at Frontend
).
sy-ucomm = space.
io_grid->check_changed_data( ).
endif.
endfunction.
report zab_mass_replace_demo.
data: ok_code type sy-ucomm.
data: begin of gs_spfli.
include structure spfli.
data: styles type lvc_t_styl,
end of gs_spfli.
data: gt_spfli like standard table of gs_spfli.
data: go_cc type ref to cl_gui_custom_container.
data: go_alv type ref to cl_gui_alv_grid.
data: gs_layout type lvc_s_layo.
data: gt_fieldcat type lvc_t_fcat.
data: g_row type i.
data: g_field type i.
data: gs_style type lvc_s_styl.
field-symbols: <spfli> like gs_spfli.
field-symbols: <fcat> type lvc_s_fcat.
select * up to 250 rows into corresponding fields of table gt_spfli
from spfli.
call function 'LVC_FIELDCATALOG_MERGE'
exporting
* i_buffer_active = i_buffer_active " Buffer active
i_structure_name = 'SPFLI' " Structure name (structure, table, view)
* i_client_never_display = 'X' " Hide client fields
i_bypassing_buffer = abap_true " Ignore buffer while reading
* i_internal_tabname = i_internal_tabname " Table Name
changing
ct_fieldcat = gt_fieldcat " Field Catalog with Field Descriptions
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
if sy-subrc eq 0.
loop at gt_fieldcat assigning <fcat>.
if <fcat>-key is initial.
if sy-tabix mod 2 eq 0.
<fcat>-edit = abap_true.
endif.
endif.
endloop.
loop at gt_spfli assigning <spfli>.
g_row = sy-tabix.
g_field = 0.
loop at gt_fieldcat assigning <fcat> where edit eq abap_true.
add 1 to g_field.
if ( g_row mod 2 eq 0 ) and ( g_field mod 2 eq 0 ).
clear gs_style.
gs_style-fieldname = <fcat>-fieldname.
gs_style-style = cl_gui_alv_grid=>mc_style_disabled.
insert gs_style into table <spfli>-styles.
endif.
endloop.
endloop.
endif.
call screen 0100.
module status_0100 output.
set pf-status 'STATUS_0100'.
set titlebar 'TITLE_0100'.
if go_cc is initial.
create object go_cc
exporting
container_name = 'CC_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 eq 0.
create object go_alv
exporting
i_parent = go_cc
exceptions
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others = 5.
if sy-subrc eq 0.
gs_layout-stylefname = 'STYLES'.
go_alv->set_table_for_first_display(
exporting
i_structure_name = 'SPFLI'
is_layout = gs_layout
changing
it_outtab = gt_spfli
it_fieldcatalog = gt_fieldcat
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4
).
if sy-subrc eq 0.
go_alv->register_edit_event(
exporting
i_event_id = cl_gui_alv_grid=>mc_evt_modified " Event ID
exceptions
error = 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.
endif.
endif.
endif.
endmodule.
module user_command_0100 input.
case ok_code.
when 'BACK' or 'END' or 'EXIT'.
leave program.
when 'MASS_REPLA'.
call function 'Z_AB_MASS_REPLACE_ALV'
exporting
io_grid = go_alv " ALV List Viewer
changing
ct_outtab = gt_spfli. " ALV List Viewer
endcase.
endmodule.