03-03-2008 7:16 AM
Hi ,
I am trying to select row from alv and delete them from custom table zrrmm02. structure zrrmm02 and i_d_wa is same. But this below code is not working. pls suggest.
REPORT zrralvcontrol .
TABLES: zrrmm02.
TYPE-POOLS: slis.
DATA: BEGIN OF itab OCCURS 0,
box(1) TYPE c,
matnr LIKE zrrmm02-matnr,
werks LIKE zrrmm02-werks,
ersda LIKE zrrmm02-ersda,
timestamp LIKE zrrmm02-timestamp,
oldval LIKE zrrmm02-oldval,
newval LIKE zrrmm02-newval,
msg LIKE zrrmm02-msg,
END OF itab,
BEGIN OF i_d_wa,
matnr LIKE zrrmm02-matnr,
werks LIKE zrrmm02-werks,
ersda LIKE zrrmm02-ersda,
timestamp LIKE zrrmm02-timestamp,
oldval LIKE zrrmm02-oldval,
newval LIKE zrrmm02-newval,
msg LIKE zrrmm02-msg,
END OF i_d_wa,
g_t_fieldcat TYPE slis_t_fieldcat_alv,
g_r_fieldcat LIKE LINE OF g_t_fieldcat.
START-OF-SELECTION.
SELECT * FROM zrrmm02 INTO CORRESPONDING FIELDS OF TABLE itab.
PERFORM display_data.
END-OF-SELECTION.
*---------------------------------------------------------------------*
* FORM display_data *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM display_data.
DATA: l_f_repid LIKE sy-repid,
l_r_layout TYPE slis_layout_alv.
l_f_repid = sy-repid.
l_r_layout-zebra = 'X'.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = l_f_repid
i_internal_tabname = 'ITAB'
i_client_never_display = 'X'
i_inclname = l_f_repid
CHANGING
ct_fieldcat = g_t_fieldcat.
LOOP AT g_t_fieldcat INTO g_r_fieldcat.
CASE g_r_fieldcat-fieldname.
WHEN 'BOX'.
g_r_fieldcat-checkbox = 'X'.
g_r_fieldcat-col_pos = 0.
g_r_fieldcat-seltext_m = 'Check'.
g_r_fieldcat-seltext_l = 'Check'.
g_r_fieldcat-edit = 'X'.
WHEN 'WERKS'.
g_r_fieldcat-seltext_l =
g_r_fieldcat-seltext_m =
g_r_fieldcat-seltext_s =
g_r_fieldcat-reptext_ddic = 'WERKS'.
WHEN 'ERSDA'.
g_r_fieldcat-seltext_l =
g_r_fieldcat-seltext_m =
g_r_fieldcat-seltext_s =
g_r_fieldcat-reptext_ddic = 'DATE'.
WHEN 'TIMESTAMP'.
g_r_fieldcat-seltext_l =
g_r_fieldcat-seltext_m =
g_r_fieldcat-seltext_s =
g_r_fieldcat-reptext_ddic = 'TIME'.
g_r_fieldcat-edit = 'X'.
WHEN 'NEWVAL'.
g_r_fieldcat-seltext_l =
g_r_fieldcat-seltext_m =
g_r_fieldcat-seltext_s =
g_r_fieldcat-reptext_ddic = 'New Value'.
WHEN 'OLDVAL'.
g_r_fieldcat-seltext_l =
g_r_fieldcat-seltext_m =
g_r_fieldcat-seltext_s =
g_r_fieldcat-reptext_ddic = 'Old Value'.
WHEN 'MSG'.
g_r_fieldcat-seltext_l =
g_r_fieldcat-seltext_m =
g_r_fieldcat-seltext_s =
g_r_fieldcat-reptext_ddic = 'Message'.
ENDCASE.
MODIFY g_t_fieldcat FROM g_r_fieldcat.
CLEAR g_r_fieldcat.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = l_f_repid
is_layout = l_r_layout
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
i_save = 'X'
it_fieldcat = g_t_fieldcat
TABLES
t_outtab = itab[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
*---------------------------------------------------------------------*
* FORM set_pf_status *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM set_pf_status USING extab TYPE slis_t_extab.
SET PF-STATUS 'SET_PF_STATUS'.
ENDFORM.
*---------------------------------------------------------------------*
* FORM user_command *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> UCOMM *
* --> SEL_FIELD *
*---------------------------------------------------------------------*
FORM user_command USING ucomm LIKE sy-ucomm
sel_field TYPE slis_selfield.
CASE ucomm.
WHEN 'SALL'.
LOOP AT itab.
itab-box = 'X'.
MODIFY itab.
CLEAR itab.
ENDLOOP.
sel_field-refresh = 'X'.
WHEN 'DALL' .
LOOP AT itab.
itab-box = ' '.
MODIFY itab.
CLEAR itab.
ENDLOOP.
sel_field-refresh = 'X'.
WHEN 'DELETE'.
LOOP AT itab WHERE box = 'X'.
* i_d_wa-matnr = itab-matnr.
* i_d_wa-werks = itab-werks.
* i_d_wa-ersda = itab-ersda.
* i_d_wa-timestamp = itab-timestamp.
* i_d_wa-oldval = itab-oldval.
* i_d_wa-newval = itab-newval.
* i_d_wa-msg = itab-msg.
MOVE-corresponding itab to i_d_wa.
DELETE zrrmm02 FROM i_d_wa.
CLEAR i_d_wa.
ENDLOOP.
ENDCASE.
ENDFORM.
03-03-2008 8:15 AM
Hi,
Refere the attached program. This program we have developed for the same purpose but the tables are different...
Hope it will work for you too....
Award Points if useful...
&----
*& Report ZINMM_ADTH_MAINTAIN
*&
&----
*&
*&
&----
REPORT ZINMM_ADTH_MAINTAIN.
data: v_filename type localfile. " File Name
types :begin of ty_tab.
include structure ZINMM_ADTH.
types : sel(1).
types : message(25).
types :end of ty_tab.
data : int_tab type table of ty_tab,
wa_tab type ty_tab.
*excel
types :begin of ty_excelformat,
col type kcd_ex_col_n,
field type field,
field_desc(30),
end of ty_excelformat.
data : int_excelformat type table of ty_excelformat,
wa_excelformat type ty_excelformat.
*ALV GRID REQUIREMENTS
type-pools: slis.
*FIELD CATALOG
data: int_fieldcatalog type slis_t_fieldcat_alv.
data: wa_fieldcatalog type slis_fieldcat_alv ,
wa_layout type slis_layout_alv .
*SELECTION SCREEN
tables : ZINMM_ADTH.
selection-screen begin of block a with frame title text-000.
parameters: p_fname type localfile obligatory modif id upd . " File Name
selection-screen comment /1(60) comm1 modif id upd .
selection-screen comment /1(70) comm2 modif id upd .
selection-screen comment /1(50) comm3 modif id upd .
selection-screen comment /1(50) comm4 modif id upd .
selection-screen comment /1(50) comm5 modif id upd .
select-options s_werks for ZINMM_ADTH-werks modif id chd obligatory.
select-options s_budat for ZINMM_ADTH-budat modif id chd.
select-options s_matnr for ZINMM_ADTH-matnr modif id chd.
select-options s_LGORT for ZINMM_ADTH-LGORT modif id chd.
select-options s_ploT for ZINMM_ADTH-ploT modif id chd.
selection-screen end of block a.
at selection-screen on value-request for p_fname.
*GET EXCEL FILE
perform f_getfile.
at selection-screen output.
comm1 = 'Excel File Details :'.
comm2 = '* Row 1 : Field Names of the table ( All Key Fields are Mandatory ) '.
comm3 = '* Row 2 : Field Descriptions'.
comm4 = '* Row 3 and Above : Data '.
comm5 = '* Col 1 : Please start from Col1'.
*SCREEN MODIFICATIONS AS PER TCODE
*UPLOAD DATA
if sy-tcode = 'ZINMM010A'. "UPLOAD
loop at screen.
if screen-group1 = 'CHD'.
screen-active = 0.
modify screen.
endif.
endloop.
endif.
*DISP/MODIFY
if sy-tcode = 'ZINMM010B' "DISP/CHANGE
or sy-tcode = 'ZINMM010C' .
loop at screen.
if screen-group1 = 'UPD'.
screen-active = 0.
modify screen.
endif.
endloop.
endif.
initialization.
*TITLE
if sy-tcode = 'ZINMM010A'. "UPLOAD
sy-title = 'Upload Wood ADT stock'.
elseif sy-tcode = 'ZINMM010B'. "CHANGE
sy-title = 'Change Wood ADT stock'.
elseif sy-tcode = 'ZINMM010C'. "DISP
sy-title = 'Display Wood ADT stock'.
endif.
start-of-selection.
if sy-tcode = 'ZINMM010A'. "UPLOAD
sy-title = 'Upload Wood ADT stock '.
set titlebar 'TITLE' with sy-title.
elseif sy-tcode = 'ZINMM010B'. "CHANGE
sy-title = 'Change Wood ADT stock'.
set titlebar 'TITLE' with sy-title.
elseif sy-tcode = 'ZINMM010C'. "DISP
sy-title = 'Display Wood ADT stock'.
set titlebar 'TITLE' with sy-title.
endif.
if sy-tcode = 'ZINMM010A'. "UPLOAD
v_filename = p_fname.
perform f_getdata.
elseif sy-tcode = 'ZINMM010B'. "CHANGE
perform f_getdata_tab.
elseif sy-tcode = 'ZINMM010C'. "DISP
perform f_getdata_tab.
endif.
end-of-selection.
perform f_create_alv.
perform f_disp_alv.
&----
*& Form F_GETDATA
&----
READ DATA FROM EXCEL AND DO DATA CLEANSING
----
form f_getdata .
data: wa_excel type alsmex_tabline,
int_excel type standard table of alsmex_tabline initial size 0.
data wf_row type kcd_ex_row_n. " Row
data: wf_value(80) type c,
fieldname(20) type c.
field-symbols: <value> type any.
data : wf_date type dats,
wf_time type tims.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = v_filename
i_begin_col = 1
i_begin_row = 1
i_end_col = 50
i_end_row = 65000
tables
intern = int_excel
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
if sy-subrc <> 0.
message 'Error in reading file' type 'I'.
leave list-processing.
else.
GET ALL THE FIELDS
loop at int_excel
into wa_excel
where
row = 1.
wa_excelformat-field = wa_excel-value .
wa_excelformat-col = wa_excel-col.
append wa_excelformat to int_excelformat.
endloop.
GET THE DESCRIPTION
loop at int_excel
into wa_excel
where
row = 2.
read table int_excelformat
into wa_excelformat
with key
col = wa_excel-col.
if sy-subrc = 0.
wa_excelformat-field_desc = wa_excel-value.
modify int_excelformat index sy-tabix from wa_excelformat .
endif.
endloop.
endif.
SORT int_excel
BY row ASCENDING
col ASCENDING.
wf_row = 3.
FETC THE DATA
loop at int_excel into wa_excel.
clear wf_value .
if wf_row = wa_excel-row.
read table int_excelformat
into wa_excelformat
with key
col = wa_excel-col.
if sy-subrc = 0.
if wa_excelformat-field eq 'BUDAT'
or wa_excelformat-field eq 'ERDAT'
or wa_excelformat-field eq 'LCDAT'.
call function 'CONVERT_DATE_TO_INTERNAL'
exporting
date_external = wa_excel-value
importing
date_internal = wf_date.
fieldname = wa_excelformat-field.
concatenate 'WA_TAB-'
fieldname
into wf_value.
assign (wf_value) to <value>.
if sy-subrc = 0.
<value> = wf_date.
else.
unassign <value>.
endif.
elseif wa_excelformat-field eq 'MATNR' .
fieldname = wa_excelformat-field.
concatenate 'WA_TAB-'
fieldname
into wf_value.
assign (wf_value) to <value>.
call function 'CONVERSION_EXIT_MATN1_INPUT'
exporting
input = wa_excel-value
importing
output = <value>
exceptions
length_error = 1
others = 2.
else.
fieldname = wa_excelformat-field.
concatenate 'WA_TAB-'
fieldname
into wf_value.
assign (wf_value) to <value>.
if sy-subrc = 0.
condense wa_excel-value.
<value> = wa_excel-value.
else.
unassign <value>.
endif.
endif.
endif.
at end of row.
wf_row = wf_row + 1.
append wa_tab to int_tab.
clear wa_tab.
endat.
endif.
endloop.
endform. " F_GETDATA
&----
*& Form f_getfile
&----
GET FILE
----
form f_getfile .
call function 'F4_FILENAME'
importing
file_name = p_fname.
endform. " f_getfile
&----
*& Form F_CREATE_ALV
&----
CREATE ALV
----
form f_create_alv .
if sy-tcode eq 'ZINMM010A'.
loop at int_excelformat
into wa_excelformat.
wa_fieldcatalog-fieldname = wa_excelformat-field.
wa_fieldcatalog-tabname = 'INT_TAB'.
wa_fieldcatalog-seltext_l = wa_excelformat-field_desc.
append wa_fieldcatalog to int_fieldcatalog.
clear: wa_fieldcatalog.
endloop.
endif.
if sy-tcode eq 'ZINMM010B' or
sy-tcode eq 'ZINMM010C'.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = sy-repid
i_structure_name = 'ZINMM_ADTH'
changing
ct_fieldcat = int_fieldcatalog.
endif.
if sy-tcode eq 'ZINMM010B'.
loop at int_fieldcatalog into wa_fieldcatalog.
if wa_fieldcatalog-fieldname ne 'WERKS'
and wa_fieldcatalog-fieldname ne 'LGORT'
and wa_fieldcatalog-fieldname ne 'MATNR'
and wa_fieldcatalog-fieldname ne 'BUDAT'
and wa_fieldcatalog-fieldname ne 'PLOT'.
wa_fieldcatalog-edit = 'X'.
wa_fieldcatalog-input = 'X'.
endif.
modify int_fieldcatalog from wa_fieldcatalog.
endloop.
endif.
clear wa_fieldcatalog.
if sy-tcode ne 'ZINMM010C'.
wa_fieldcatalog-fieldname = 'MESSAGE'.
wa_fieldcatalog-col_pos = '28'.
wa_fieldcatalog-seltext_l = 'Message'.
wa_fieldcatalog-edit = ' '.
wa_fieldcatalog-input = ' '.
append wa_fieldcatalog to int_fieldcatalog.
clear: wa_fieldcatalog.
endif.
LAYOUT
wa_layout-colwidth_optimize = 'X'.
wa_layout-zebra = 'X'.
if sy-tcode ne 'ZINMM010C'.
wa_layout-box_fieldname = 'SEL'.
wa_layout-box_tabname = 'INT_TAB'.
endif.
endform. " F_CREATE_ALV
&----
*& Form f_disp_ALV
&----
DISPLAY ALV
----
form f_disp_alv .
data: v_repid type syrepid.
v_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = v_repid
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = int_fieldcatalog
is_layout = wa_layout
tables
t_outtab = int_tab.
endform. " f_disp_ALV
&----
*& Form set_pf_status
&----
SET PF STAT
----
form set_pf_status using rt_extab type slis_t_extab.
if sy-tcode = 'ZINMM010A'. "UPLOAD
set pf-status 'ZINMM_ADTH_010A'.
elseif sy-tcode = 'ZINMM010B'. "CHANGE
set pf-status 'ZINMM_ADTH_010B'.
elseif sy-tcode = 'ZINMM010C'. "DISP
set pf-status 'ZINMM_ADTH_010C'.
endif.
endform. "set_pf_status
&----
*& Form user_command
&----
READ USER SELECTIONS
----
-->R_UCOMM text
-->RS_SELFIELD text
----
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
data ref1 type ref to cl_gui_alv_grid.
if r_ucomm eq 'EXIT'.
leave program.
endif.
if r_ucomm eq 'UPD'.
loop at int_tab into wa_tab
where sel = 'X' .
perform f_update changing wa_tab.
modify int_tab from wa_tab.
endloop.
endif.
if r_ucomm eq 'DEL'.
loop at int_tab into wa_tab
where sel = 'X' .
perform f_delete changing wa_tab.
modify int_tab from wa_tab.
endloop.
endif.
if r_ucomm eq 'SAV'.
call function 'GET_GLOBALS_FROM_SLVC_FULLSCR'
importing
e_grid = ref1.
call method ref1->check_changed_data.
loop at int_tab into wa_tab.
perform f_update changing wa_tab.
modify int_tab from wa_tab.
endloop.
endif.
perform f_disp_alv.
endform. "user_command
&----
*& Form f_update
&----
MODIFY TAB
----
<--P_WA_TAB text
----
form f_update changing p_wa_tab type ty_tab.
data : wa_ZINMM_ADTH type ZINMM_ADTH.
data : wf_matnr type matnr,
wf_werks type werks_d.
move-corresponding p_wa_tab to wa_ZINMM_ADTH.
call function 'ENQUEUE_E_TABLE'
exporting
mode_rstable = 'W'
tabname = 'ZINMM_ADTH'
VARKEY =
X_TABNAME = ' '
X_VARKEY = ' '
_SCOPE = '2'
_WAIT = ' '
_COLLECT = ' '
exceptions
foreign_lock = 1
system_failure = 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.
select single
matnr
werks
into (wf_matnr,wf_werks)
from marc
where
matnr = p_wa_tab-matnr
and werks = p_wa_tab-werks.
if sy-subrc = 0 .
if sy-tcode = 'ZINMM010A'.
insert into ZINMM_ADTH values wa_ZINMM_ADTH.
if sy-subrc <> 0.
p_wa_tab-message = 'Entry Exists'.
else.
p_wa_tab-message = 'Successfull Updation'.
endif.
endif.
if sy-tcode = 'ZINMM010B'.
modify ZINMM_ADTH from wa_ZINMM_ADTH .
if sy-subrc <> 0.
p_wa_tab-message = 'Modification Error'.
else.
p_wa_tab-message = 'Modification Success'.
endif.
endif.
else.
p_wa_tab-message = 'Material / Plant Error'.
endif.
call function 'DEQUEUE_E_TABLE'
exporting
mode_rstable = 'W'
tabname = 'ZINMM_ADTH'
VARKEY =
X_TABNAME = ' '
X_VARKEY = ' '
_SCOPE = '3'
_SYNCHRON = ' '
_COLLECT = ' '
.
endform. "f_update
&----
*& Form f_getdata_TAB
&----
GET DATA FROM TABLE - CHANGE - DISP MODE
----
form f_getdata_tab .
select *
from ZINMM_ADTH
into corresponding fields of table int_tab
where
werks in s_werks
and lgort in s_lgort
and plot in s_plot
and matnr in s_matnr
and budat in s_budat.
if sy-subrc <> 0.
message 'No Data Available' type 'S'.
leave list-processing.
endif.
endform. " f_getdata_TAB
&----
*& Form f_DELETE
&----
text
----
<--P_WA_TAB text
----
form f_delete changing p_wa_tab type ty_tab.
data : wa_ZINMM_ADTH type ZINMM_ADTH.
data w_answer(1).
move-corresponding p_wa_tab to wa_ZINMM_ADTH.
call function 'ENQUEUE_E_TABLE'
exporting
mode_rstable = 'W'
tabname = 'ZINMM_ADTH'
VARKEY =
X_TABNAME = ' '
X_VARKEY = ' '
_SCOPE = '2'
_WAIT = ' '
_COLLECT = ' '
exceptions
foreign_lock = 1
system_failure = 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.
call function 'POPUP_TO_CONFIRM'
exporting
text_question = 'Confirm Deletion of Data ?'
text_button_1 = 'Yes'
text_button_2 = 'No'
display_cancel_button = ' '
importing
answer = w_answer
.
if w_answer = 1.
delete ZINMM_ADTH from wa_ZINMM_ADTH .
if sy-subrc <> 0.
p_wa_tab-message = 'Delete Error'.
else.
p_wa_tab-message = 'Delete Success'.
endif.
endif.
call function 'DEQUEUE_E_TABLE'
exporting
mode_rstable = 'W'
tabname = 'ZINMM_ADTH'
VARKEY =
X_TABNAME = ' '
X_VARKEY = ' '
_SCOPE = '3'
_SYNCHRON = ' '
_COLLECT = ' '
.
endform. " f_DELETE
*Selection texts
*----
P_FNAME File Name
S_BUDAT Posting Date
S_LGORT Storage Location
S_MATNR Material
S_PLOT Plot
S_WERKS Plant
*Messages
*----
*
Message class: Hard coded
Error in reading file
03-03-2008 8:08 AM
03-03-2008 8:15 AM
Hi,
Refere the attached program. This program we have developed for the same purpose but the tables are different...
Hope it will work for you too....
Award Points if useful...
&----
*& Report ZINMM_ADTH_MAINTAIN
*&
&----
*&
*&
&----
REPORT ZINMM_ADTH_MAINTAIN.
data: v_filename type localfile. " File Name
types :begin of ty_tab.
include structure ZINMM_ADTH.
types : sel(1).
types : message(25).
types :end of ty_tab.
data : int_tab type table of ty_tab,
wa_tab type ty_tab.
*excel
types :begin of ty_excelformat,
col type kcd_ex_col_n,
field type field,
field_desc(30),
end of ty_excelformat.
data : int_excelformat type table of ty_excelformat,
wa_excelformat type ty_excelformat.
*ALV GRID REQUIREMENTS
type-pools: slis.
*FIELD CATALOG
data: int_fieldcatalog type slis_t_fieldcat_alv.
data: wa_fieldcatalog type slis_fieldcat_alv ,
wa_layout type slis_layout_alv .
*SELECTION SCREEN
tables : ZINMM_ADTH.
selection-screen begin of block a with frame title text-000.
parameters: p_fname type localfile obligatory modif id upd . " File Name
selection-screen comment /1(60) comm1 modif id upd .
selection-screen comment /1(70) comm2 modif id upd .
selection-screen comment /1(50) comm3 modif id upd .
selection-screen comment /1(50) comm4 modif id upd .
selection-screen comment /1(50) comm5 modif id upd .
select-options s_werks for ZINMM_ADTH-werks modif id chd obligatory.
select-options s_budat for ZINMM_ADTH-budat modif id chd.
select-options s_matnr for ZINMM_ADTH-matnr modif id chd.
select-options s_LGORT for ZINMM_ADTH-LGORT modif id chd.
select-options s_ploT for ZINMM_ADTH-ploT modif id chd.
selection-screen end of block a.
at selection-screen on value-request for p_fname.
*GET EXCEL FILE
perform f_getfile.
at selection-screen output.
comm1 = 'Excel File Details :'.
comm2 = '* Row 1 : Field Names of the table ( All Key Fields are Mandatory ) '.
comm3 = '* Row 2 : Field Descriptions'.
comm4 = '* Row 3 and Above : Data '.
comm5 = '* Col 1 : Please start from Col1'.
*SCREEN MODIFICATIONS AS PER TCODE
*UPLOAD DATA
if sy-tcode = 'ZINMM010A'. "UPLOAD
loop at screen.
if screen-group1 = 'CHD'.
screen-active = 0.
modify screen.
endif.
endloop.
endif.
*DISP/MODIFY
if sy-tcode = 'ZINMM010B' "DISP/CHANGE
or sy-tcode = 'ZINMM010C' .
loop at screen.
if screen-group1 = 'UPD'.
screen-active = 0.
modify screen.
endif.
endloop.
endif.
initialization.
*TITLE
if sy-tcode = 'ZINMM010A'. "UPLOAD
sy-title = 'Upload Wood ADT stock'.
elseif sy-tcode = 'ZINMM010B'. "CHANGE
sy-title = 'Change Wood ADT stock'.
elseif sy-tcode = 'ZINMM010C'. "DISP
sy-title = 'Display Wood ADT stock'.
endif.
start-of-selection.
if sy-tcode = 'ZINMM010A'. "UPLOAD
sy-title = 'Upload Wood ADT stock '.
set titlebar 'TITLE' with sy-title.
elseif sy-tcode = 'ZINMM010B'. "CHANGE
sy-title = 'Change Wood ADT stock'.
set titlebar 'TITLE' with sy-title.
elseif sy-tcode = 'ZINMM010C'. "DISP
sy-title = 'Display Wood ADT stock'.
set titlebar 'TITLE' with sy-title.
endif.
if sy-tcode = 'ZINMM010A'. "UPLOAD
v_filename = p_fname.
perform f_getdata.
elseif sy-tcode = 'ZINMM010B'. "CHANGE
perform f_getdata_tab.
elseif sy-tcode = 'ZINMM010C'. "DISP
perform f_getdata_tab.
endif.
end-of-selection.
perform f_create_alv.
perform f_disp_alv.
&----
*& Form F_GETDATA
&----
READ DATA FROM EXCEL AND DO DATA CLEANSING
----
form f_getdata .
data: wa_excel type alsmex_tabline,
int_excel type standard table of alsmex_tabline initial size 0.
data wf_row type kcd_ex_row_n. " Row
data: wf_value(80) type c,
fieldname(20) type c.
field-symbols: <value> type any.
data : wf_date type dats,
wf_time type tims.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = v_filename
i_begin_col = 1
i_begin_row = 1
i_end_col = 50
i_end_row = 65000
tables
intern = int_excel
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
if sy-subrc <> 0.
message 'Error in reading file' type 'I'.
leave list-processing.
else.
GET ALL THE FIELDS
loop at int_excel
into wa_excel
where
row = 1.
wa_excelformat-field = wa_excel-value .
wa_excelformat-col = wa_excel-col.
append wa_excelformat to int_excelformat.
endloop.
GET THE DESCRIPTION
loop at int_excel
into wa_excel
where
row = 2.
read table int_excelformat
into wa_excelformat
with key
col = wa_excel-col.
if sy-subrc = 0.
wa_excelformat-field_desc = wa_excel-value.
modify int_excelformat index sy-tabix from wa_excelformat .
endif.
endloop.
endif.
SORT int_excel
BY row ASCENDING
col ASCENDING.
wf_row = 3.
FETC THE DATA
loop at int_excel into wa_excel.
clear wf_value .
if wf_row = wa_excel-row.
read table int_excelformat
into wa_excelformat
with key
col = wa_excel-col.
if sy-subrc = 0.
if wa_excelformat-field eq 'BUDAT'
or wa_excelformat-field eq 'ERDAT'
or wa_excelformat-field eq 'LCDAT'.
call function 'CONVERT_DATE_TO_INTERNAL'
exporting
date_external = wa_excel-value
importing
date_internal = wf_date.
fieldname = wa_excelformat-field.
concatenate 'WA_TAB-'
fieldname
into wf_value.
assign (wf_value) to <value>.
if sy-subrc = 0.
<value> = wf_date.
else.
unassign <value>.
endif.
elseif wa_excelformat-field eq 'MATNR' .
fieldname = wa_excelformat-field.
concatenate 'WA_TAB-'
fieldname
into wf_value.
assign (wf_value) to <value>.
call function 'CONVERSION_EXIT_MATN1_INPUT'
exporting
input = wa_excel-value
importing
output = <value>
exceptions
length_error = 1
others = 2.
else.
fieldname = wa_excelformat-field.
concatenate 'WA_TAB-'
fieldname
into wf_value.
assign (wf_value) to <value>.
if sy-subrc = 0.
condense wa_excel-value.
<value> = wa_excel-value.
else.
unassign <value>.
endif.
endif.
endif.
at end of row.
wf_row = wf_row + 1.
append wa_tab to int_tab.
clear wa_tab.
endat.
endif.
endloop.
endform. " F_GETDATA
&----
*& Form f_getfile
&----
GET FILE
----
form f_getfile .
call function 'F4_FILENAME'
importing
file_name = p_fname.
endform. " f_getfile
&----
*& Form F_CREATE_ALV
&----
CREATE ALV
----
form f_create_alv .
if sy-tcode eq 'ZINMM010A'.
loop at int_excelformat
into wa_excelformat.
wa_fieldcatalog-fieldname = wa_excelformat-field.
wa_fieldcatalog-tabname = 'INT_TAB'.
wa_fieldcatalog-seltext_l = wa_excelformat-field_desc.
append wa_fieldcatalog to int_fieldcatalog.
clear: wa_fieldcatalog.
endloop.
endif.
if sy-tcode eq 'ZINMM010B' or
sy-tcode eq 'ZINMM010C'.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = sy-repid
i_structure_name = 'ZINMM_ADTH'
changing
ct_fieldcat = int_fieldcatalog.
endif.
if sy-tcode eq 'ZINMM010B'.
loop at int_fieldcatalog into wa_fieldcatalog.
if wa_fieldcatalog-fieldname ne 'WERKS'
and wa_fieldcatalog-fieldname ne 'LGORT'
and wa_fieldcatalog-fieldname ne 'MATNR'
and wa_fieldcatalog-fieldname ne 'BUDAT'
and wa_fieldcatalog-fieldname ne 'PLOT'.
wa_fieldcatalog-edit = 'X'.
wa_fieldcatalog-input = 'X'.
endif.
modify int_fieldcatalog from wa_fieldcatalog.
endloop.
endif.
clear wa_fieldcatalog.
if sy-tcode ne 'ZINMM010C'.
wa_fieldcatalog-fieldname = 'MESSAGE'.
wa_fieldcatalog-col_pos = '28'.
wa_fieldcatalog-seltext_l = 'Message'.
wa_fieldcatalog-edit = ' '.
wa_fieldcatalog-input = ' '.
append wa_fieldcatalog to int_fieldcatalog.
clear: wa_fieldcatalog.
endif.
LAYOUT
wa_layout-colwidth_optimize = 'X'.
wa_layout-zebra = 'X'.
if sy-tcode ne 'ZINMM010C'.
wa_layout-box_fieldname = 'SEL'.
wa_layout-box_tabname = 'INT_TAB'.
endif.
endform. " F_CREATE_ALV
&----
*& Form f_disp_ALV
&----
DISPLAY ALV
----
form f_disp_alv .
data: v_repid type syrepid.
v_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = v_repid
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = int_fieldcatalog
is_layout = wa_layout
tables
t_outtab = int_tab.
endform. " f_disp_ALV
&----
*& Form set_pf_status
&----
SET PF STAT
----
form set_pf_status using rt_extab type slis_t_extab.
if sy-tcode = 'ZINMM010A'. "UPLOAD
set pf-status 'ZINMM_ADTH_010A'.
elseif sy-tcode = 'ZINMM010B'. "CHANGE
set pf-status 'ZINMM_ADTH_010B'.
elseif sy-tcode = 'ZINMM010C'. "DISP
set pf-status 'ZINMM_ADTH_010C'.
endif.
endform. "set_pf_status
&----
*& Form user_command
&----
READ USER SELECTIONS
----
-->R_UCOMM text
-->RS_SELFIELD text
----
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
data ref1 type ref to cl_gui_alv_grid.
if r_ucomm eq 'EXIT'.
leave program.
endif.
if r_ucomm eq 'UPD'.
loop at int_tab into wa_tab
where sel = 'X' .
perform f_update changing wa_tab.
modify int_tab from wa_tab.
endloop.
endif.
if r_ucomm eq 'DEL'.
loop at int_tab into wa_tab
where sel = 'X' .
perform f_delete changing wa_tab.
modify int_tab from wa_tab.
endloop.
endif.
if r_ucomm eq 'SAV'.
call function 'GET_GLOBALS_FROM_SLVC_FULLSCR'
importing
e_grid = ref1.
call method ref1->check_changed_data.
loop at int_tab into wa_tab.
perform f_update changing wa_tab.
modify int_tab from wa_tab.
endloop.
endif.
perform f_disp_alv.
endform. "user_command
&----
*& Form f_update
&----
MODIFY TAB
----
<--P_WA_TAB text
----
form f_update changing p_wa_tab type ty_tab.
data : wa_ZINMM_ADTH type ZINMM_ADTH.
data : wf_matnr type matnr,
wf_werks type werks_d.
move-corresponding p_wa_tab to wa_ZINMM_ADTH.
call function 'ENQUEUE_E_TABLE'
exporting
mode_rstable = 'W'
tabname = 'ZINMM_ADTH'
VARKEY =
X_TABNAME = ' '
X_VARKEY = ' '
_SCOPE = '2'
_WAIT = ' '
_COLLECT = ' '
exceptions
foreign_lock = 1
system_failure = 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.
select single
matnr
werks
into (wf_matnr,wf_werks)
from marc
where
matnr = p_wa_tab-matnr
and werks = p_wa_tab-werks.
if sy-subrc = 0 .
if sy-tcode = 'ZINMM010A'.
insert into ZINMM_ADTH values wa_ZINMM_ADTH.
if sy-subrc <> 0.
p_wa_tab-message = 'Entry Exists'.
else.
p_wa_tab-message = 'Successfull Updation'.
endif.
endif.
if sy-tcode = 'ZINMM010B'.
modify ZINMM_ADTH from wa_ZINMM_ADTH .
if sy-subrc <> 0.
p_wa_tab-message = 'Modification Error'.
else.
p_wa_tab-message = 'Modification Success'.
endif.
endif.
else.
p_wa_tab-message = 'Material / Plant Error'.
endif.
call function 'DEQUEUE_E_TABLE'
exporting
mode_rstable = 'W'
tabname = 'ZINMM_ADTH'
VARKEY =
X_TABNAME = ' '
X_VARKEY = ' '
_SCOPE = '3'
_SYNCHRON = ' '
_COLLECT = ' '
.
endform. "f_update
&----
*& Form f_getdata_TAB
&----
GET DATA FROM TABLE - CHANGE - DISP MODE
----
form f_getdata_tab .
select *
from ZINMM_ADTH
into corresponding fields of table int_tab
where
werks in s_werks
and lgort in s_lgort
and plot in s_plot
and matnr in s_matnr
and budat in s_budat.
if sy-subrc <> 0.
message 'No Data Available' type 'S'.
leave list-processing.
endif.
endform. " f_getdata_TAB
&----
*& Form f_DELETE
&----
text
----
<--P_WA_TAB text
----
form f_delete changing p_wa_tab type ty_tab.
data : wa_ZINMM_ADTH type ZINMM_ADTH.
data w_answer(1).
move-corresponding p_wa_tab to wa_ZINMM_ADTH.
call function 'ENQUEUE_E_TABLE'
exporting
mode_rstable = 'W'
tabname = 'ZINMM_ADTH'
VARKEY =
X_TABNAME = ' '
X_VARKEY = ' '
_SCOPE = '2'
_WAIT = ' '
_COLLECT = ' '
exceptions
foreign_lock = 1
system_failure = 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.
call function 'POPUP_TO_CONFIRM'
exporting
text_question = 'Confirm Deletion of Data ?'
text_button_1 = 'Yes'
text_button_2 = 'No'
display_cancel_button = ' '
importing
answer = w_answer
.
if w_answer = 1.
delete ZINMM_ADTH from wa_ZINMM_ADTH .
if sy-subrc <> 0.
p_wa_tab-message = 'Delete Error'.
else.
p_wa_tab-message = 'Delete Success'.
endif.
endif.
call function 'DEQUEUE_E_TABLE'
exporting
mode_rstable = 'W'
tabname = 'ZINMM_ADTH'
VARKEY =
X_TABNAME = ' '
X_VARKEY = ' '
_SCOPE = '3'
_SYNCHRON = ' '
_COLLECT = ' '
.
endform. " f_DELETE
*Selection texts
*----
P_FNAME File Name
S_BUDAT Posting Date
S_LGORT Storage Location
S_MATNR Material
S_PLOT Plot
S_WERKS Plant
*Messages
*----
*
Message class: Hard coded
Error in reading file
03-03-2008 8:15 AM
Hi,
Use DELETE zrrmm02 FROM TABLE i_d_wa.
Now it will work.If still it is not working
Use DELETE zrrmm02 .
03-03-2008 8:51 AM
I forgot to use this :-
DATA ref1 TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref1.
CALL METHOD ref1->check_changed_data.
Now is there a way to refresh the alv too . like after clciking the delete i dont want to show those rows anymore..