|
Código fuente -
Utilidades varias
|
|
Domingo, 16 de Mayo de 2004 00:41 |
|
Copia favoritos entre usuarios y sistemas
REPORT Z_COPY_FAVORITES .
*
* HANDLING NOTICE: START THE REPORT IN TARGET CLIENT !!!
*
* Author: Gabriel Waldeyer & Gerhard Schönfelder
* http://www.gabriel-waldeyer.com
* http://www.gschoenfelder.de
*
* Copy of favorites among users and systems (acc.OSS note 389104)
*
tables: usr02, smen_buffc, smen_buffi, smenfavdat.
*
data: source_daten_da(1) type c.
data: begin of i_smen_buffc occurs 10.
include structure smen_buffc.
data: end of i_smen_buffc.
data: begin of i_smen_buffi occurs 10.
include structure smen_buffi.
data: end of i_smen_buffi.
data: begin of i_smenfavdat occurs 10.
include structure smenfavdat.
data: end of i_smenfavdat.
*
parameters:
source like usr02-bname,
mdtsrc like t000-mandt default sy-mandt,
frmsys like sy-sysid default space.
selection-screen skip 1.
parameters:
target like usr02-bname default sy-uname,
mdttrg like t000-mandt default sy-mandt.
*
*
START-OF-SELECTION.
*
if frmsys is initial. " Kopie im gleichen System
* target client = source client ? if yes, stop
if mdtsrc eq mdttrg. stop. endif.
* Authority Check
AUTHORITY-CHECK OBJECT 'S_ADMI_FCD'
ID 'S_ADMI_FCD' FIELD 'PADM'.
if sy-subrc ne 0.
write: / 'missing authorization for this function'.
exit.
endif.
* Does source user exist in source client ? if no, msg+stop
select single * from usr02 client specified
where mandt eq mdtsrc and bname eq source.
if sy-subrc ne 0.
write : / 'User', source ,'in client', mdtsrc ,
'not found'.
exit.
endif.
* Does target user exist in target client ? if no, msg+stop
select single * from usr02 client specified
where mandt eq mdttrg and bname eq target.
if sy-subrc ne 0.
write : / 'User', target ,'in client', mdttrg ,
'not found'.
exit.
endif.
* Delete all existing entries of target user in target client
delete from smen_buffc client specified
where mandt eq mdttrg and uname eq target.
delete from smen_buffi client specified
where mandt eq mdttrg and uname eq target.
delete from smenfavdat client specified
where mandt eq mdttrg and uname eq target.
*
* Copy entries
*
select * from smen_buffc client specified
where mandt eq mdtsrc and uname eq source.
smen_buffc-mandt = mdttrg.
smen_buffc-uname = target.
insert smen_buffc.
endselect.
*
select * from smen_buffi client specified
where mandt eq mdtsrc and uname eq source.
smen_buffi-mandt = mdttrg.
smen_buffi-uname = target.
insert smen_buffi.
endselect.
*
select * from smenfavdat client specified
where mandt eq mdtsrc and uname eq source.
smenfavdat-mandt = mdttrg.
smenfavdat-uname = target.
insert smenfavdat.
endselect.
*
* Success message
write : / 'favorites copied'.
*
else. " copy from a remote client
*
* Does target user exist in target client ? if no, msg+stop
select single * from usr02 client specified
where mandt eq mdttrg and bname eq target.
if sy-subrc ne 0.
write : / 'User', target ,'in client', mdttrg ,
'not found'.
exit.
endif.
* get entries from remote source client/user
move 'N' to source_daten_da.
call function 'Z_RFC_COPY_FAVORITES'
destination frmsys
exporting source = source
mdtsrc = mdtsrc
importing data_found = source_daten_da
tables e_smen_buffc = i_smen_buffc
e_smen_buffi = i_smen_buffi
e_smenfavdat = i_smenfavdat.
* Delete all existing entries of target user in target client
if source_daten_da = 'Y'.
delete from smen_buffc client specified
where mandt eq mdttrg and uname eq target.
delete from smen_buffi client specified
where mandt eq mdttrg and uname eq target.
delete from smenfavdat client specified
where mandt eq mdttrg and uname eq target.
* write new entries
loop at i_smen_buffc.
move i_smen_buffc to smen_buffc.
smen_buffc-mandt = mdttrg.
smen_buffc-uname = target.
insert smen_buffc.
endloop.
loop at i_smen_buffi.
move i_smen_buffi to smen_buffi.
smen_buffi-mandt = mdttrg.
smen_buffi-uname = target.
insert smen_buffi.
endloop.
loop at i_smenfavdat.
move i_smenfavdat to smenfavdat.
smenfavdat-mandt = mdttrg.
smenfavdat-uname = target.
insert smenfavdat.
endloop.
write: / 'favorites copied'.
else.
write: / 'no entries found in remote source client'.
endif.
endif.
|